/*
* w o r d s . c
* Forth Inspired Command Language
* ANS Forth CORE word-set written in C
* Author: John Sadler (john_sadler@alum.mit.edu)
* Created: 19 July 1997
* $Id: primitives.c,v 1.4 2010/09/13 18:43:04 asau Exp $
*/
/*
* Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
* All rights reserved.
*
* Get the latest Ficl release at http://ficl.sourceforge.net
*
* I am interested in hearing from anyone who uses Ficl. If you have
* a problem, a success story, a defect, an enhancement request, or
* if you would like to contribute to the Ficl release, please
* contact me by email at the address above.
*
* L I C E N S E and D I S C L A I M E R
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "ficl.h"
#include <limits.h>
/*
* Control structure building words use these
* strings' addresses as markers on the stack to
* check for structure completion.
*/
/*
* C O N T R O L S T R U C T U R E B U I L D E R S
*
* Push current dictionary location for later branch resolution.
* The location may be either a branch target or a patch address...
*/
static void
{
}
static void
{
}
static void
{
char *tag;
/*
* Changed the code below to compare the pointers first
* (by popular demand)
*/
"Error -- unmatched control structure \"%s\"", wantTag);
}
}
/*
* Expect a branch target address on the param stack,
* FICL_VM_STATE_COMPILE a literal offset from the current dictionary location
* to the target address
*/
static void
{
}
/*
* Expect a branch patch address on the param stack,
* FICL_VM_STATE_COMPILE a literal offset from the patch location
* to the current dictionary location
*/
static void
{
}
/*
* Match the tag to the top of the stack. If success,
* sopy "here" address into the ficlCell whose address is next
* on the stack. Used by do..leave..loop.
*/
static void
{
char *tag;
/*
* Changed the comparison below to compare the pointers first
* (by popular demand)
*/
}
}
/*
* c o l o n d e f i n i t i o n s
* Code to begin compiling a colon definition
* This function sets the state to FICL_VM_STATE_COMPILE, then creates a
* new word whose name is the next word in the input stream
* and whose code is colonParen.
*/
static void
{
#if FICL_WANT_LOCALS
#endif
}
static void
{
#if FICL_WANT_LOCALS
}
#endif
}
/*
* e x i t
* CORE
* This function simply pops the previous instruction
* pointer and returns to the "next" loop. Used for exiting from within
* a definition. Note that exitParen is identical to semiParen - they
* are in two different functions so that "see" can correctly identify
* the end of a colon definition, even if it uses "exit".
*/
static void
{
#if FICL_WANT_LOCALS
}
#endif
}
/*
* c o n s t a n t
* IMMEDIATE
* Compiles a constant into the dictionary. Constants return their
* value when invoked. Expects a value on top of the parm stack.
*/
static void
{
}
static void
{
}
/*
* d i s p l a y C e l l
* Drop and print the contents of the ficlCell at the top of the param
* stack
*/
static void
{
ficlCell c;
}
static void
{
ficlUnsigned u;
}
static void
{
ficlUnsigned u;
}
/*
* s t r l e n
* Ficl ( c-string -- length )
*
* Returns the length of a C-style (zero-terminated) string.
*
* --lch
*/
static void
{
}
/*
* s p r i n t f
* Ficl ( i*x c-addr-fmt u-fmt c-addr-buffer u-buffer --
* c-addr-buffer u-written success-flag )
* Similar to the C sprintf() function. It formats into a buffer based on
* a "format" string. Each character in the format string is copied verbatim
* to the output buffer, until SPRINTF encounters a percent sign ("%").
* SPRINTF then skips the percent sign, and examines the next character
* (the "format character"). Here are the valid format characters:
* s - read a C-ADDR U-LENGTH string from the stack and copy it to
* the buffer
* d - read a ficlCell from the stack, format it as a string (base-10,
* signed), and copy it to the buffer
* x - same as d, except in base-16
* u - same as d, but unsigned
* % - output a literal percent-sign to the buffer
* SPRINTF returns the c-addr-buffer argument unchanged, the number of bytes
* written, and a flag indicating whether or not it ran out of space while
* writing to the output buffer (FICL_TRUE if it ran out of space).
*
* If SPRINTF runs out of space in the buffer to store the formatted string,
* it still continues parsing, in an effort to preserve your stack (otherwise
* it might leave uneaten arguments behind).
*
* --lch
*/
static void
{
while (format < formatStop) {
char *source;
int actualLength;
int desiredLength;
int leadingZeroes;
if (*format != '%') {
leadingZeroes = 0;
} else {
format++;
if (format == formatStop)
break;
if (leadingZeroes) {
format++;
if (format == formatStop)
break;
}
if (desiredLength) {
if (format == formatStop)
break;
} else if (*format == '*') {
format++;
if (format == formatStop)
break;
}
switch (*format) {
case 's':
case 'S':
source = (char *)
break;
case 'x':
case 'X':
base = 16;
case 'u':
case 'U':
case 'd':
case 'D': {
int integer;
if (unsignedInteger)
else
base = 10;
unsignedInteger = 0; /* false */
break;
}
case '%':
actualLength = 1;
default:
continue;
}
}
if (append) {
if (!desiredLength)
if (desiredLength > bufferLength) {
append = 0; /* false */
}
while (desiredLength > actualLength) {
bufferLength--;
}
buffer += actualLength;
}
format++;
}
}
/*
* d u p & f r i e n d s
*/
static void
{
int i;
}
/*
* e m i t & f r i e n d s
*/
static void
{
int i;
buffer[0] = (char)i;
}
static void
{
}
static void
{
char c = *trace;
c = *++trace;
}
/*
* Cope with DOS or UNIX-style EOLs -
* Check for /r, /n, /r/n, or /n/r end-of-line sequences,
* and point trace to next char. If EOL is \0, we're done.
*/
trace++;
trace++;
}
}
/*
* paren CORE
* Compilation: Perform the execution semantics given below.
* Execution: ( "ccc<paren>" -- )
* Parse ccc delimited by ) (right parenthesis). ( is an immediate word.
* The number of characters in ccc may be zero to the number of characters
* in the parse area.
*/
static void
{
}
/*
* F E T C H & S T O R E
*/
/*
* i f C o I m
* IMMEDIATE
* Compiles code for a conditional branch into the dictionary
* and pushes the branch patch address on the stack for later
*/
static void
{
}
/*
* e l s e C o I m
*
* IMMEDIATE -- compiles an "else"...
* 1) FICL_VM_STATE_COMPILE a branch and a patch address;
* the address gets patched
* by "endif" to point past the "else" code.
* 2) Pop the the "if" patch address
* 3) Patch the "if" branch to point to the current FICL_VM_STATE_COMPILE
* address.
* 4) Push the "else" patch address. ("endif" patches this to jump past
* the "else" code.
*/
static void
{
/* (1) FICL_VM_STATE_COMPILE branch runtime */
/* (2) pop "if" patch addr */
/* (1) FICL_VM_STATE_COMPILE patch placeholder */
}
/*
* e n d i f C o I m
*/
static void
{
}
/*
* c a s e C o I m
* IMMEDIATE FICL_VM_STATE_COMPILE-ONLY
*
*
* At FICL_VM_STATE_COMPILE-time, a CASE-SYS (see DPANS94 6.2.0873) looks
* like this:
* i*addr i caseTag
* and an OF-SYS (see DPANS94 6.2.1950) looks like this:
* i*addr i caseTag addr ofTag
* The integer under caseTag is the count of fixup addresses that branch
* to ENDCASE.
*/
static void
{
}
/*
* e n d c a s eC o I m
* IMMEDIATE FICL_VM_STATE_COMPILE-ONLY
*/
static void
{
/*
* if the last OF ended with FALLTHROUGH,
* just add the FALLTHROUGH fixup to the
* ENDOF fixups
*/
}
while (fixupCount--) {
}
}
/*
* o f C o I m
* IMMEDIATE FICL_VM_STATE_COMPILE-ONLY
*/
static void
{
}
if (fallthroughFixup != NULL) {
(*fallthroughFixup).i = offset;
}
}
/*
* e n d o f C o I m
* IMMEDIATE FICL_VM_STATE_COMPILE-ONLY
*/
static void
{
/* ensure we're in an OF, */
/* grab the address of the branch location after the OF */
/* ensure we're also in a "case" */
/* grab the current number of ENDOF fixups */
/* FICL_VM_STATE_COMPILE branch runtime */
/*
* push a new ENDOF fixup, the updated count of ENDOF fixups,
* and the caseTag
*/
/* reserve space for the ENDOF fixup */
/* and patch the original OF */
}
/*
* f a l l t h r o u g h C o I m
* IMMEDIATE FICL_VM_STATE_COMPILE-ONLY
*/
static void
{
/* ensure we're in an OF, */
/* grab the address of the branch location after the OF */
/* ensure we're also in a "case" */
/* okay, here we go. put the case tag back. */
/* FICL_VM_STATE_COMPILE branch runtime */
/* push a new FALLTHROUGH fixup and the fallthroughTag */
/* reserve space for the FALLTHROUGH fixup */
/* and patch the original OF */
}
/*
* h a s h
* hash ( c-addr u -- code)
* calculates hashcode of specified string and leaves it on the stack
*/
static void
{
ficlString s;
}
/*
* i n t e r p r e t
* This is the "user interface" of a Forth. It does the following:
* while there are words in the VM's Text Input Buffer
* Copy next word into the pad (ficlVmGetWord)
* Attempt to find the word in the dictionary (ficlDictionaryLookup)
* If successful, execute the word.
* Otherwise, attempt to convert the word to a number (isNumber)
* If successful, push the number onto the parameter stack.
* Otherwise, print an error message and exit loop...
* End Loop
*
* From the standard, section 3.4
* Text interpretation (see 6.1.1360 EVALUATE and 6.1.2050 QUIT) shall
* repeat the following steps until either the parse area is empty or an
* ambiguous condition exists:
* a) Skip leading spaces and parse a name (see 3.4.1);
*/
static void
{
ficlString s;
int i;
s = ficlVmGetWord0(vm);
/*
* Get next word...if out of text, we're done.
*/
if (s.length == 0) {
}
/*
* Run the parse chain against the incoming token until somebody
* eats it. Otherwise emit an error message and give up.
*/
for (i = 0; i < FICL_MAX_PARSE_STEPS; i++) {
break;
return;
} else {
return;
}
}
/* back to inner interpreter */
}
/*
* Surrogate precompiled parse step for ficlParseWord
* (this step is hard coded in FICL_VM_STATE_INTERPRET)
*/
static void
{
}
/*
* p a r e n P a r s e S t e p
* (parse-step) ( c-addr u -- flag )
* runtime for a precompiled parse step - pop a counted string off the
* stack, run the parse step against it, and push the result flag (FICL_TRUE
* if success, FICL_FALSE otherwise).
*/
void
{
ficlString s;
}
static void
{
}
/*
* l i t e r a l I m
*
* IMMEDIATE code for "literal". This function gets a value from the stack
* and compiles it into the dictionary preceded by the code for "(literal)".
* IMMEDIATE
*/
void
{
switch (value) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
break;
case 0:
case -1:
case -2:
case -3:
case -4:
case -5:
case -6:
case -7:
case -8:
case -9:
case -10:
case -11:
case -12:
case -13:
case -14:
case -15:
case -16:
break;
default:
break;
}
}
static void
{
}
/*
* D o / L o o p
* do -- IMMEDIATE FICL_VM_STATE_COMPILE ONLY
* Compiles code to initialize a loop: FICL_VM_STATE_COMPILE (do),
* allot space to hold the "leave" address, push a branch
* target address for the loop.
* (do) -- runtime for "do"
* pops index and limit from the p stack and moves them
* to the r stack, then skips to the loop body.
* loop -- IMMEDIATE FICL_VM_STATE_COMPILE ONLY
* +loop
* Compiles code for the test part of a loop:
* FICL_VM_STATE_COMPILE (loop), resolve forward branch from "do", and
* copy "here" address to the "leave" address allotted by "do"
* i,j,k -- FICL_VM_STATE_COMPILE ONLY
* Runtime: Push loop indices on param stack (i is innermost loop...)
* Note: each loop has three values on the return stack:
* ( R: leave limit index )
* "leave" is the absolute address of the next ficlCell after the loop
* limit and index are the loop control variables.
* leave -- FICL_VM_STATE_COMPILE ONLY
* Runtime: pop the loop control variables, then pop the
* "leave" address and jump (absolute) there.
*/
static void
{
/*
* Allot space for a pointer to the end
* of the loop - "leave" uses this...
*/
/*
* Mark location of head of loop...
*/
}
static void
{
/*
* Allot space for a pointer to the end
* of the loop - "leave" uses this...
*/
/*
* Mark location of head of loop...
*/
}
static void
{
}
static void
{
}
/*
* v a r i a b l e
*/
static void
{
}
static void
{
}
/*
* b a s e & f r i e n d s
*/
static void
{
c.p = pBase;
}
static void
{
}
static void
{
}
/*
* a l l o t & f r i e n d s
*/
static void
{
ficlInteger i;
}
static void
{
}
/*
* t i c k
* tick CORE ( "<spaces>name" -- xt )
* Skip leading space delimiters. Parse name delimited by a space. Find
* name and return xt, the execution token for name. An ambiguous condition
* exists if name is not found.
*/
void
{
if (!word)
}
static void
{
}
/*
* p o s t p o n e
* Lookup the next word in the input stream and FICL_VM_STATE_COMPILE code to
* insert it into definitions created by the resulting word
* (defers compilation, even of immediate words)
*/
static void
{
ficlCell c;
if (ficlWordIsImmediate(word)) {
} else {
c.p = pComma;
}
}
/*
* e x e c u t e
* Pop an execution token (pointer to a word) off the stack and
* run it
*/
static void
{
}
/*
* i m m e d i a t e
* Make the most recently compiled word IMMEDIATE -- it executes even
* in FICL_VM_STATE_COMPILE state (most often used for control compiling words
* such as IF, THEN, etc)
*/
static void
{
}
static void
{
}
static void
{
}
static void
{
}
static void
{
/*
* move HERE past string so it doesn't get overwritten. --lch
*/
} else { /* FICL_VM_STATE_COMPILE state */
dictionary->here =
}
}
/*
* d o t Q u o t e
* IMMEDIATE word that compiles a string literal for later display
* FICL_VM_STATE_COMPILE fiStringLiteralParen, then copy the bytes of the
* string from the
* TIB to the dictionary. Backpatch the count byte and align the dictionary.
*/
static void
{
ficlCell c;
dictionary->here =
c.p = pType;
}
static void
{
char c;
/*
* Note: the standard does not want leading spaces skipped.
*/
*to++ = c;
*to = '\0';
from++;
}
/*
* s l i t e r a l
* STRING
* Interpretation: Interpretation semantics for this word are undefined.
* Compilation: ( c-addr1 u -- )
* Append the run-time semantics given below to the current definition.
* Run-time: ( -- c-addr2 u )
* Return c-addr2 u describing a string consisting of the characters
* specified by c-addr1 u during compilation. A program shall not alter
* the returned string.
*/
{
char *from;
char *to;
}
*to++ = 0;
}
/*
* s t a t e
* Return the address of the VM's state member (must be sized the
* same as a ficlCell for this reason)
*/
{
}
/*
* c r e a t e . . . d o e s >
* Make a new word in the dictionary with the run-time effect of
* a variable (push my address), but with extra space allotted
* for use by does> .
*/
static void
{
}
static void
{
#if FICL_WANT_LOCALS
}
#endif
}
/*
* t o b o d y
* to-body CORE ( xt -- a-addr )
* a-addr is the data-field address corresponding to xt. An ambiguous
* condition exists if xt is not for a word defined via CREATE.
*/
static void
{
}
/*
* from-body Ficl ( a-addr -- xt )
* Reverse effect of >body
*/
static void
{
char *ptr;
}
/*
* >name Ficl ( xt -- c-addr u )
* Push the address and length of a word's name given its address
* xt.
*/
static void
{
}
static void
{
ficlCell c;
c.p = wp;
ficlVmPush(vm, c);
}
/*
* l b r a c k e t e t c
*/
static void
{
}
static void
{
}
/*
* p i c t u r e d n u m e r i c w o r d s
*
* less-number-sign CORE ( -- )
* Initialize the pictured numeric output conversion process.
* (clear the pad)
*/
static void
{
}
/*
* number-sign CORE ( ud1 -- ud2 )
* Divide ud1 by the number in BASE giving the quotient ud2 and the remainder
* n. (n is the least-significant digit of ud1.) Convert n to external form
* and add the resulting character to the beginning of the pictured numeric
* output string. An ambiguous condition exists if # executes outside of a
* <# #> delimited number conversion.
*/
static void
{
}
/*
* number-sign-greater CORE ( xd -- c-addr u )
* Drop xd. Make the pictured numeric output string available as a character
* string. c-addr and u specify the resulting character string. A program
* may replace characters within the string.
*/
static void
{
}
/*
* number-sign-s CORE ( ud1 -- ud2 )
* Convert one digit of ud1 according to the rule for #. Continue conversion
* until the quotient is zero. ud2 is zero. An ambiguous condition exists if
* #S executes outside of a <# #> delimited number conversion.
* TO DO: presently does not use ud1 hi ficlCell - use it!
*/
static void
{
do {
} while (FICL_2UNSIGNED_NOT_ZERO(u));
}
/*
* HOLD CORE ( char -- )
* Add char to the beginning of the pictured numeric output string.
* An ambiguous condition exists if HOLD executes outside of a <# #>
* delimited number conversion.
*/
static void
{
int i;
}
/*
* SIGN CORE ( n -- )
* If n is negative, add a minus sign to the beginning of the pictured
* numeric output string. An ambiguous condition exists if SIGN
* executes outside of a <# #> delimited number conversion.
*/
static void
{
int i;
if (i < 0)
}
/*
* t o N u m b e r
* to-number CORE ( ud1 c-addr1 u1 -- ud2 c-addr2 u2 )
* ud2 is the unsigned result of converting the characters within the
* string specified by c-addr1 u1 into digits, using the number in BASE,
* and adding each into ud1 after multiplying ud1 by the number in BASE.
* Conversion continues left-to-right until a character that is not
* convertible, including any + or -, is encountered or the string is
* entirely converted. c-addr2 is the location of the first unconverted
* character or the first character past the end of the string if the string
* was entirely converted. u2 is the number of unconverted characters in the
* string. An ambiguous condition exists if ud2 overflows during the
* conversion.
*/
static void
{
char *trace;
ficlUnsigned c;
if (c < '0')
break;
digit = c - '0';
if (digit > 9)
/*
* Note: following test also catches chars between 9 and a
* because 'digit' is unsigned!
*/
break;
}
}
/*
* q u i t & a b o r t
* quit CORE ( -- ) ( R: i*x -- )
* Empty the return stack, store zero in SOURCE-ID if it is present, make
* the user input device the input source, and enter interpretation state.
* Do not display a message. Repeat the following:
*
* Accept a line from the input source into the input buffer, set >IN to
* zero, and FICL_VM_STATE_INTERPRET.
* Display the implementation-defined system prompt if in
* interpretation state, all processing has been completed, and no
* ambiguous condition exists.
*/
static void
{
}
static void
{
}
/*
* a c c e p t
* accept CORE ( c-addr +n1 -- +n2 )
* Receive a string of at most +n1 characters. An ambiguous condition
* exists if +n1 is zero or greater than 32,767. Display graphic characters
* as they are received. A program that depends on the presence or absence
* of non-graphic characters in the string has an environmental dependency.
* The editing functions, if any, that the system performs in order to
* construct the string are implementation-defined.
*
* (Although the standard text doesn't say so, I assume that the intent
* of 'accept' is to store the string at the address specified on
* the stack.)
*
* NOTE: getchar() is used there as its present both in loader and
* userland; however, the more correct solution would be to set
* terminal to raw mode for userland.
*/
static void
{
char *address;
int c;
c = getchar();
if (c == '\n' || c == '\r')
break;
}
}
/*
* a l i g n
* 6.1.0705 ALIGN CORE ( -- )
* If the data-space pointer is not aligned, reserve enough space to
* align it.
*/
static void
{
}
/*
* a l i g n e d
*/
static void
{
void *addr;
}
/*
* b e g i n & f r i e n d s
* Indefinite loop control structures
* A.6.1.0760 BEGIN
* Typical use:
* : X ... BEGIN ... test UNTIL ;
* or
* : X ... BEGIN ... test WHILE ... REPEAT ;
*/
static void
{
}
static void
{
}
static void
{
/* equivalent to 2swap */
}
static void
{
/* expect "begin" branch marker */
/* expect "while" branch marker */
}
static void
{
/* expect "begin" branch marker */
}
/*
* c h a r & f r i e n d s
* 6.1.0895 CHAR CORE ( "<spaces>name" -- char )
* Skip leading space delimiters. Parse name delimited by a space.
* Put the value of its first character onto the stack.
*
* bracket-char CORE
* Interpretation: Interpretation semantics for this word are undefined.
* Compilation: ( "<spaces>name" -- )
* Skip leading space delimiters. Parse name delimited by a space.
* Append the run-time semantics given below to the current definition.
* Run-time: ( -- char )
* Place char, the value of the first character of name, on the stack.
*/
static void
{
ficlString s;
s = ficlVmGetWord(vm);
}
static void
{
}
/*
* c h a r P l u s
* char-plus CORE ( c-addr1 -- c-addr2 )
* Add the size in address units of a character to c-addr1, giving c-addr2.
*/
static void
{
char *p;
}
/*
* c h a r s
* chars CORE ( n1 -- n2 )
* n2 is the size in address units of n1 characters.
* For most processors, this function can be a no-op. To guarantee
* portability, we'll multiply by sizeof (char).
*/
#if defined(_M_IX86)
#endif
static void
{
if (sizeof (char) > 1) {
ficlInteger i;
}
/* otherwise no-op! */
}
#if defined(_M_IX86)
#pragma warning(default: 4127)
#endif
/*
* c o u n t
* COUNT CORE ( c-addr1 -- c-addr2 u )
* Return the character string specification for the counted string stored
* at c-addr1. c-addr2 is the address of the first character after c-addr1.
* u is the contents of the character at c-addr1, which is the length in
* characters of the string at c-addr2.
*/
static void
{
}
/*
* e n v i r o n m e n t ?
* environment-query CORE ( c-addr u -- FICL_FALSE | i*x FICL_TRUE )
* c-addr is the address of a character string and u is the string's
* character count. u may have a value in the range from zero to an
* implementation-defined maximum which shall not be less than 31. The
* character string should contain a keyword from 3.2.6 Environmental
* queries or the optional word sets to be checked for correspondence
* with an attribute of the present environment. If the system treats the
* attribute as unknown, the returned flag is FICL_FALSE; otherwise, the flag
* is FICL_TRUE and the i*x returned is of the type specified in the table for
* the attribute queried.
*/
static void
{
} else {
}
}
/*
* e v a l u a t e
* EVALUATE CORE ( i*x c-addr u -- j*x )
* Save the current input source specification. Store minus-one (-1) in
* SOURCE-ID if it is present. Make the string described by c-addr and u
* both the input source and input buffer, set >IN to zero, and
* FICL_VM_STATE_INTERPRET.
* When the parse area is empty, restore the prior input source
* specification. Other stack effects are due to the words EVALUATEd.
*/
static void
{
int result;
if (result != FICL_VM_STATUS_OUT_OF_TEXT)
}
/*
* s t r i n g q u o t e
* Interpreting: get string delimited by a quote from the input stream,
* copy to a scratch area, and put its count and address on the stack.
* Compiling: FICL_VM_STATE_COMPILE code to push the address and count
* of a string literal, FICL_VM_STATE_COMPILE the string from the input
* stream, and align the dictionary pointer.
*/
static void
{
} else { /* FICL_VM_STATE_COMPILE state */
'\"'));
}
}
/*
* t y p e
* Pop count and char address from stack and print the designated string.
*/
static void
{
char *s;
return;
/*
* Since we don't have an output primitive for a counted string
* (oops), make sure the string is null terminated. If not, copy
* and terminate it.
*/
if (s[length] != 0) {
if (s != here)
s = here;
}
ficlVmTextOut(vm, s);
}
/*
* w o r d
* word CORE ( char "<chars>ccc<char>" -- c-addr )
* Skip leading delimiters. Parse characters ccc delimited by char. An
* ambiguous condition exists if the length of the parsed string is greater
* than the implementation-defined length of a counted string.
*
* c-addr is the address of a transient region containing the parsed word
* as a counted string. If the parse area was empty or contained no
* characters other than the delimiter, the resulting string has a zero
* length. A space, not included in the length, follows the string. A
* program may replace characters within the string.
* NOTE! Ficl also NULL-terminates the dest string.
*/
static void
{
char delim;
/*
* store an extra space at the end of the primitive...
* why? dunno yet. Guy Carver did it.
*/
}
/*
* p a r s e - w o r d
* Ficl PARSE-WORD ( <spaces>name -- c-addr u )
* Skip leading spaces and parse name delimited by a space. c-addr is the
* address within the input buffer and u is the length of the selected
* string. If the parse area is empty, the resulting string has a zero length.
*/
{
ficlString s;
s = ficlVmGetWord0(vm);
}
/*
* p a r s e
* CORE EXT ( char "ccc<char>" -- c-addr u )
* Parse ccc delimited by the delimiter char.
* c-addr is the address (within the input buffer) and u is the length of
* the parsed string. If the parse area was empty, the resulting string has
* a zero length.
* NOTE! PARSE differs from WORD: it does not skip leading delimiters.
*/
static void
{
ficlString s;
char delim;
}
/*
* f i n d
* FIND CORE ( c-addr -- c-addr 0 | xt 1 | xt -1 )
* Find the definition named in the counted string at c-addr. If the
* definition is not found, return c-addr and zero. If the definition is
* found, return its execution token xt. If the definition is immediate,
* also return one (1), otherwise also return minus-one (-1). For a given
* string, the values returned by FIND while compiling may differ from
* those returned while not compiling.
*/
static void
{
if (word) {
} else {
}
}
/*
* f i n d
* FIND CORE ( c-addr -- c-addr 0 | xt 1 | xt -1 )
* Find the definition named in the counted string at c-addr. If the
* definition is not found, return c-addr and zero. If the definition is
* found, return its execution token xt. If the definition is immediate,
* also return one (1), otherwise also return minus-one (-1). For a given
* string, the values returned by FIND while compiling may differ from
* those returned while not compiling.
*/
static void
{
}
/*
* s f i n d
* Ficl ( c-addr u -- 0 0 | xt 1 | xt -1 )
* Like FIND, but takes "c-addr u" for the string.
*/
static void
{
}
/*
* r e c u r s e
*/
static void
{
ficlCell c;
c.p = dictionary->smudge;
}
/*
* s o u r c e
* CORE ( -- c-addr u )
* c-addr is the address of, and u is the number of characters in, the
* input buffer.
*/
static void
{
}
/*
* v e r s i o n
* non-standard...
*/
static void
{
}
/*
* t o I n
* to-in CORE
*/
static void
{
}
/*
* c o l o n N o N a m e
* CORE EXT ( C: -- colon-sys ) ( S: -- xt )
* Create an unnamed colon definition and push its address.
* Change state to FICL_VM_STATE_COMPILE.
*/
static void
{
}
/*
* u s e r V a r i a b l e
* user ( u -- ) "<spaces>name"
* Get a name from the input stream and create a user variable
* with the name and the index supplied. The run-time effect
* of a user variable is to push the address of the indexed ficlCell
* in the running vm's user array.
*
* User variables are vm local cells. Each vm has an array of
* FICL_USER_CELLS of them when FICL_WANT_USER is nonzero.
* Ficl's user facility is implemented with two primitives,
* "user" and "(user)", a variable ("nUser") (in softcore.c) that
* holds the index of the next free user ficlCell, and a redefinition
* (also in softcore) of "user" that defines a user word and increments
* nUser.
*/
#if FICL_WANT_USER
static void
{
ficlCell c;
if (c.i >= FICL_USER_CELLS) {
}
}
#endif
#if FICL_WANT_LOCALS
/*
* Each local is recorded in a private locals dictionary as a
* word that does doLocalIm at runtime. DoLocalIm compiles code
* into the client definition to fetch the value of the
* corresponding local variable from the return stack.
* The private dictionary gets initialized at the end of each block
* that uses locals (in ; and does> for example).
*/
void
{
#if !FICL_WANT_FLOAT
/* get rid of unused parameter warning */
isFloat = 0;
#endif /* FICL_WANT_FLOAT */
#if FICL_WANT_FLOAT
if (isFloat)
else
#endif /* FICL_WANT_FLOAT */
if (isDouble)
} else {
#if FICL_WANT_FLOAT
if (isFloat) {
} else
#endif /* FICL_WANT_FLOAT */
if (nLocal == 0) {
} else {
}
if (appendLocalOffset)
}
}
static void
{
ficlLocalParenIm(vm, 0, 0);
}
static void
{
}
#if FICL_WANT_FLOAT
static void
{
}
static void
{
}
#endif /* FICL_WANT_FLOAT */
/*
* l o c a l P a r e n
* paren-local-paren LOCAL
* Interpretation: Interpretation semantics for this word are undefined.
* Execution: ( c-addr u -- )
* When executed during compilation, (LOCAL) passes a message to the
* system that has one of two meanings. If u is non-zero,
* the message identifies a new local whose definition name is given by
* the string of characters identified by c-addr u. If u is zero,
* the message is last local and c-addr has no significance.
*
* The result of executing (LOCAL) during compilation of a definition is
* to create a set of named local identifiers, each of which is
* a definition name, that only have execution semantics within the scope
* of that definition's source.
*
* local Execution: ( -- x )
*
* Push the local's value, x, onto the stack. The local's value is
* initialized as described in 13.3.3 Processing locals and may be
* changed by preceding the local's name with TO. An ambiguous condition
* exists when local is executed while in interpretation state.
*/
void
{
if (FICL_STRING_GET_LENGTH(name) > 0) {
/*
* add a local to the **locals** dictionary and
* update localsCount
*/
}
#if !FICL_WANT_FLOAT
/* get rid of unused parameter warning */
isFloat = 0;
#else /* FICL_WANT_FLOAT */
if (isFloat) {
if (isDouble) {
} else {
}
} else
#endif /* FICL_WANT_FLOAT */
if (isDouble) {
} else {
}
/*
* FICL_VM_STATE_COMPILE code to create a local
* stack frame
*/
/* save location in dictionary for #locals */
}
/* write localsCount to (link) param area in dictionary */
}
}
static void
{
ficlLocalParen(vm, 0, 0);
}
static void
{
}
#endif /* FICL_WANT_LOCALS */
/*
* t o V a l u e
* CORE EXT
* Interpretation: ( x "<spaces>name" -- )
* Skip leading spaces and parse name delimited by a space. Store x in
* name. An ambiguous condition exists if name was not defined by VALUE.
* NOTE: In Ficl, VALUE is an alias of CONSTANT
*/
static void
{
#if FICL_WANT_LOCALS
#endif /* FICL_WANT_LOCALS */
#if FICL_WANT_LOCALS
if (!word)
goto TO_GLOBAL;
}
#if FICL_WANT_FLOAT
}
#endif /* FICL_WANT_FLOAT */
else {
"to %.*s : local is of unknown type",
return;
}
#if FICL_WANT_FLOAT
if (!isFloat) {
#endif /* FICL_WANT_FLOAT */
if (nLocal == 0) {
}
#if FICL_WANT_FLOAT
}
#endif /* FICL_WANT_FLOAT */
if (appendLocalOffset)
return;
}
#endif
#if FICL_WANT_LOCALS
#endif /* FICL_WANT_LOCALS */
if (!word)
break;
break;
#if FICL_WANT_FLOAT
break;
break;
#endif /* FICL_WANT_FLOAT */
default:
return;
}
if (isDouble)
} else {
/* FICL_VM_STATE_COMPILE code to store to word's param */
}
}
/*
* f m S l a s h M o d
* f-m-slash-mod CORE ( d1 n1 -- n2 n3 )
* Divide d1 by n1, giving the floored quotient n3 and the remainder n2.
* Input and output stack arguments are signed. An ambiguous condition
* exists if n1 is zero or if the quotient lies outside the range of a
* single-ficlCell signed integer.
*/
static void
{
}
/*
* s m S l a s h R e m
* s-m-slash-remainder CORE ( d1 n1 -- n2 n3 )
* Divide d1 by n1, giving the symmetric quotient n3 and the remainder n2.
* Input and output stack arguments are signed. An ambiguous condition
* exists if n1 is zero or if the quotient lies outside the range of a
* single-ficlCell signed integer.
*/
static void
{
}
static void
{
ficlInteger i;
}
/*
* u m S l a s h M o d
* u-m-slash-mod CORE ( ud u1 -- u2 u3 )
* Divide ud by u1, giving the quotient u3 and the remainder u2.
* All values and arithmetic are unsigned. An ambiguous condition
* exists if u1 is zero or if the quotient lies outside the range of a
* single-ficlCell unsigned integer.
*/
static void
{
}
/*
* m S t a r
* m-star CORE ( n1 n2 -- d )
* d is the signed product of n1 times n2.
*/
static void
{
ficl2Integer d;
}
static void
{
}
/*
* 2 r o t
* DOUBLE ( d1 d2 d3 -- d2 d3 d1 )
*/
static void
{
}
/*
* p a d
* CORE EXT ( -- c-addr )
* c-addr is the address of a transient region that can be used to hold
* data for intermediate processing.
*/
static void
{
}
/*
* s o u r c e - i d
* CORE EXT, FILE ( -- 0 | -1 | fileid )
* Identifies the input source as follows:
*
* SOURCE-ID Input source
* --------- ------------
* fileid Text file fileid
* -1 String (via EVALUATE)
* 0 User input device
*/
static void
{
}
/*
* r e f i l l
* CORE EXT ( -- flag )
* Attempt to fill the input buffer from the input source, returning
* a FICL_TRUE flag if successful.
* When the input source is the user input device, attempt to receive input
* into the terminal input buffer. If successful, make the result the input
* buffer, set >IN to zero, and return FICL_TRUE. Receipt of a line containing
* no characters is considered successful. If there is no input available from
* the current input source, return FICL_FALSE.
* When the input source is a string from EVALUATE, return FICL_FALSE and
* perform no other action.
*/
static void
{
}
/*
* freebsd exception handling words
* Catch, from ANS Forth standard. Installs a safety net, then EXECUTE
* the word in ToS. If an exception happens, restore the state to what
* it was before, and pushes the exception value on the stack. If not,
* push zero.
*
* Notice that Catch implements an inner interpreter. This is ugly,
* but given how Ficl works, it cannot be helped. The problem is that
* colon definitions will be executed *after* the function returns,
* while "code" definitions will be executed immediately. I considered
* other solutions to this problem, but all of them shared the same
* basic problem (with added disadvantages): if Ficl ever changes it's
* inner thread modus operandi, one would have to fix this word.
*
* More comments can be found throughout catch's code.
*
* Daniel C. Sobral Jan 09/1999
* sadler may 2000 -- revised to follow ficl.c:ficlExecXT.
*/
static void
{
int except;
/*
* Get xt.
* We need this *before* we save the stack pointer, or
* we'll have to pop one element out of the stack after
* an exception. I prefer to get done with it up front. :-)
*/
/*
* Save vm's state -- a catch will not back out environmental
* changes.
*
* We are *not* saving dictionary state, since it is
* global instead of per vm, and we are not saving
* stack contents, since we are not required to (and,
* thus, it would be useless). We save vm, and vm
* "stacks" (a structure containing general information
* about it, including the current stack pointer).
*/
sizeof (ficlStack));
/*
* Give vm a jmp_buf
*/
/*
* Safety net
*/
switch (except) {
/*
* Setup condition - push poison pill so that the VM throws
* VM_INNEREXIT if the XT terminates normally, then execute
* the XT
*/
case 0:
/* Open mouth, insert emetic */
ficlVmInnerLoop(vm, 0);
break;
/*
* Normal exit from XT - lose the poison pill,
* restore old setjmp vector and push a zero.
*/
/* Restore just the setjmp vector */
/* Push 0 -- everything is ok */
break;
/*
* Some other exception got thrown - restore pre-existing VM state
* and push the exception code
*/
default:
/* Restore vm's state */
sizeof (ficlStack));
sizeof (ficlStack));
break;
}
}
/*
* t h r o w
* EXCEPTION
* Throw -- From ANS Forth standard.
*
* Throw takes the ToS and, if that's different from zero,
* returns to the last executed catch context. Further throws will
* unstack previously executed "catches", in LIFO mode.
*
* Daniel C. Sobral Jan 09/1999
*/
static void
{
int except;
if (except)
}
/*
* a l l o c a t e
* MEMORY
*/
static void
{
void *p;
p = ficlMalloc(size);
if (p != NULL)
else
}
/*
* f r e e
* MEMORY
*/
static void
{
void *p;
ficlFree(p);
}
/*
* r e s i z e
* MEMORY
*/
static void
{
if (new) {
} else {
}
}
/*
* e x i t - i n n e r
* Signals execXT that an inner loop has completed
*/
static void
{
}
#if 0
static void
{
}
#endif
/*
* f i c l C o m p i l e C o r e
* Builds the primitive wordset and the environment-query namespace.
*/
void
{
#include "ficltokens.h"
/*
* The Core word set
* see softcore.c for definitions of: abs bl space spaces abort"
*/
/*
* The Core Extensions word set...
* see softcore.fr for other definitions
*/
/* "#tib" */
/* ".r" is in softcore */
/*
* query restore-input save-input tib u.r u> unused
* [FICL_VM_STATE_COMPILE]
*/
/*
* Environment query values for the Core word set
*/
{
}
/*
* The optional Double-Number word set (partial)
*/
/*
* D+ D- D. D.R D0< D0= D2* D2/ in softcore
* D< D= D>S DABS DMAX DMIN DNEGATE in softcore
* m-star-slash is TODO
* M+ in softcore
*/
/*
* DOUBLE EXT
*/
/* du< in softcore */
/*
* The optional Exception and Exception Extensions word set
*/
/*
* The optional Locals and Locals Extensions word set
* see softcore.c for implementation of locals|
*/
#if FICL_WANT_LOCALS
#endif
/*
* The optional Memory-Allocation word set
*/
/*
* The optional Search-Order word set
*/
/*
* The optional Programming-Tools and Programming-Tools
* Extensions word set
*/
/*
* The optional File-Access and File-Access Extensions word set
*/
#if FICL_WANT_FILE
#endif
/*
* Ficl extras
*/
#if FICL_WANT_USER
#endif
/*
* internal support words
*/
/*
* Set constants representing the internal instruction words
* If you want all of 'em, turn that "#if 0" to "#if 1".
* By default you only get the numbers (fi0, fiNeg1, etc).
*/
#if 0
#else
#endif /* 0 */
#include "ficltokens.h"
/*
* Set up system's outer interpreter loop - maybe this should
* be in initSystem?
*/
}