Home Building DHTML Scripting Using Diaperglu Documention Key Script Commands Reference C Library API Reference Handy References About License Contact Forth Draft Standard
Directory Documentation key   WORDS 2CONSTANT 2LITERAL 2ROT 2VARIABLE 2VALUE D+ D- D0< D0= D2* D2/ D< D= D>S DABS DMAX DMIN DNEGATE DU< M*/ M+  
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthtwoconstant ( 2CONSTANT )
//
// C prototype:
//  void dg_forthtwoconstant (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the 
//                                 other bufferhandles are stored.
//
// Stack action shorthand:
//  ( "<delimiters>name<delimiters>morestuff" 
//     -currentinputbuffer- "<delimiters>morestuff" )
//  ( xd -- )
//
// Data stack in:
//  xd                            128 bit value of constant for new definition
//  
// Current input buffer's current offset in:
//  "<delimiters>word<delimiters>morestuff" 
//
// Current input buffer's current offset out:
//  "<delimiters>morestuff" 
//                                                            
// Action:
//  Moves the current input buffer's current offset to the delimeter after the next 
//   series of non delimeter characters or the end of buffer if that comes first and 
//   then creates a new word in the current new word wordlist using the series of 
//   non delimiter characters at the name that:
//    pushes xd onto the data stack when the process is in execute mode
//    and compiles code that pushes xd onto the data stack when the process is in 
//    compile mode
//
// Forth standard:
//  8.6.1.0360
//
// Failure cases:
//  error getting current input buffer id
//  error gettint a pointer to the current input buffer
//  error popping the data stack
//  next word in input buffer wasn't found (no more non delimiters before the end of 
//   the input buffer)
//  error creating the new constant definition
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthtwoliteral ( 2LITERAL )
//
// C prototype:
//  void dg_forthtwoliteral (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the 
//                                 other bufferhandles are stored.
//
// Stack action shorthand:
//  ( xd1 -- )
//
// Compiles code that does:
//  ( -- xd1 )
//  
// Data stack in:
//  xd1                           number to compile (128 bit integer)
//                                                           
// Action:
//  compiles code to push xd1 to data stack
//
// Forth standard:
//  8.6.1.0390
//
// Failure cases:
//  error getting current compile buffer id
//  error popping xd1 from the data stack
//  error growing the current compile buffer
//  error getting the pointer to the current compile buffer
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthtworot ( 2ROT )
//
// C prototype:
//  void dg_forthtworot (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 xd2 xd3 -- xd2 xd3 xd1 )
//
// Data stack in:
//  xd1, xd2, xd3                 128 bit integers
//
// Data stack out:
//  xd1, xd2, xd3                 128 bit integers
//                                                              
// Action:
//  The top three 128 bit numbers on the data stack are rotated.
//  The second from the top double number is moved to the top, the top is moved to
//  one below the top, and one below the top is moved to two below the top.
//
// Forth standard:
//  8.6.2.0420
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or n1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthtwovariable ( 2VARIABLE )
//
// C prototype:
//  void dg_forthtwovariable (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
//
// Stack action shorthand:
//  ( "<delimiters>word<delimiters>morestuff" 
//     -currentinputbuffer- "<delimiters>morestuff" )
//  ( -currentnewvariablebuffer- +sizeofUINT128 )
//  
// Current input buffer's current offset in:
//  "<delimiters>word<delimiters>morestuff" 
//
// Current input buffer's current offset out:
//  "<delimiters>morestuff"          
// 
// Current data space buffer in:
//  previously allocated variables
// 
// Current data space buffer out:
//  previously allocated variables + a new variable of two address cells size 
//  (sizeof UINT128)
//
// Forth standard:
//  8.6.1.0440
//                                                          
// Action:
//  moves the current offset pointer for the current input buffer to the character 
//   after the next word or to the end of the buffer if no word is found
//  creates a new definition in the current vocabulary that pushes the address of 
//   a variable onto the data stack when the process is in execute mode
//  and compiles code that calculates the address from the variable's bufferid and 
//   offset and pushes it onto the data stack when the process is in compile mode
//  the address of the variable used is the address of the next unused byte in the 
//   current data space buffer
//  then this routine allocates two cells size worth of memory (16 bytes) in the 
//   data space buffer (current new variable buffer)
//
// Note:
//  Please see CREATE for a discussion on the life of the pointer to the VARIABLE
//   
// Failure cases:
//  error calling CREATE
//  error getting the current new variable buffer id
//  error growing the current new variable buffer
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthtwovalue ( 2VALUE )
//
// C prototype:
//  void dg_forthtwovalue (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is used 
//                                 as the bufferhandle for the array where the other 
//                                 bufferhandles are stored.
//
// Stack action shorthand:
//  ( "<delimiters>word<delimiters>morestuff" 
//     -currentinputbuffer- "<delimiters>morestuff" )
//  ( -currentnewvariablebuffer- +sizeofUINT64 )
//  ( ulo uhi -- )
//  
// Current input buffer's current offset in:
//  "<delimiters>word<delimiters>morestuff" 
//
// Current input buffer's current offset out:
//  "<delimiters>morestuff"          
// 
// Current data space buffer in:
//  previously allocated variables
// 
// Current data space buffer out:
//  previously allocated variables + a new variable of two address cell sizes 
//   (sizeof UINT128)
//
// Stack action of the created word
//  ( -- ulo uhi )
//
// Forth standard:
//  8.6.2.0435
//                                                          
// Action:
//  moves the current offset pointer for the current input buffer to the character 
//   after the next word or to the end of the buffer if no word is found
//  creates a new definition in the current vocabulary that pushes the uint64 value
//   at an offset in the current data space buffer to the data stack when the process 
//   is in execute mode
//  and compiles code that calculates the address from the variable's bufferid and 
//   offset and pushes the uint128 value at that address when the process is in 
//   compile mode
//  the offset the value uses is the offset of the next unused byte in the 
//   current data space buffer
//  then this routine allocates two cell sizes worth of memory (16 bytes) in the data 
//   space buffer (current new variable buffer) and puts uhi ulo into it.
//
// Note:
//  The value is stored in memory in hi lo order. The high 64 bits of the 128 bit
//   integer goes into the first 64 bit cell.
//
// Example:
//  37 86 2VALUE x
//  x ( -- 37 86 )
//
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdplus ( D+ )
//
// C prototype:
//  void dg_forthdplus (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 xd2 -- xd3 )
//
// Data stack in:
//  xd1 xd2                       2 128 bit integers to add
//
// Data stack out:
//  xd3                           128 bit integer sum of xd1 and xd2
//                                                              
// Action:
//  xd1 and xd2 are replaced with the sum of xd1 and xd2
//  It does not matter if the intergers are signed or unsigned, the result is the
//   same
//
// Forth standard:
//  8.6.1.1040
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or xd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdminus ( D- )
//
// C prototype:
//  void dg_forthdminus (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 xd2 -- xd3 )
//
// Data stack in:
//  xd1 xd2                       2 128 bit integers to subtract
//
// Data stack out:
//  xd3                           128 bit integer = xd1 - xd2
//                                                              
// Action:
//  xd1 and xd2 are replaced with the difference of xd1 and xd2
//  It does not matter if the intergers are signed or unsigned, the result is the
//   same
//
// Forth standard:
//  8.6.1.1050
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or xd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdzeroless ( D0< )
//
// C prototype:
//  void dg_forthdzeroless (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 -- flag )
//
// Data stack in:
//  xd1                           128 bit integers
//
// Data stack out:
//  flag                          64 bit true false flag
//                                                              
// Action:
//  xd1 is replaced with a flag
//  flag is TRUE (-1) if xd1 is less than 0, FALSE (0) otherwise
//
// Forth standard:
//  8.6.1.1075
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or xd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdzeroequals ( D0= )
//
// C prototype:
//  void dg_forthdzeroequals (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 -- flag )
//
// Data stack in:
//  xd1                           128 bit integers
//
// Data stack out:
//  flag                          64 bit true false flag
//                                                              
// Action:
//  xd1 is replaced with a flag
//  flag is TRUE (-1) if xd1 is 0, FALSE (0) otherwise
//
// Forth standard:
//  8.6.1.1080
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdtwostar ( D2* )
//
// C prototype:
//  void dg_forthdtwostar (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 -- xd2 )
//
// Data stack in:
//  xd1                           128 bit integer
//
// Data stack out:
//  xd2                           128 bit integer
//                                                              
// Action:
//  xd1 is replaced with xd1 shifted to the left one bit
//  It doesn't matter if xd1 is signed or unsigned, the result is the same
//
// Forth standard:
//  8.6.1.1090
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdtwoslash ( D2/ )
//
// C prototype:
//  void dg_forthdtwoslash (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 -- nd2 )
//
// Data stack in:
//  nd1                           128 bit signed integer
//
// Data stack out:
//  nd2                           128 bit signed integer
//                                                              
// Action:
//  xd1 is replaced with xd1 arithmetically shifted to the right one bit
//  A copy of the highest bit is shifted in from the left.
//
// Forth standard:
//  8.6.1.1100
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdlessthan ( D< )
//
// C prototype:
//  void dg_forthdlessthan (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 nd2 -- flag )
//
// Data stack in:
//  nd1 nd2                       2 128 bit signed integers to compare
//
// Data stack out:
//  flag                          nd1 and nd2 are replaced with a 64 bit flag
//                                                              
// Action:
//  nd1 and nd2 are replaced with a flag
//  flag is TRUE (-1) if nd1 is less than nd2, FALSE (0) otherwise
//
// Forth standard:
//  8.6.1.1110
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 or nd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdequals ( D= )
//
// C prototype:
//  void dg_forthdequals (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 xd2 -- flag )
//
// Data stack in:
//  xd1 xd2                       2 128 bit integers to compare
//
// Data stack out:
//  flag                          xd1 and xd2 are replaced with a flag
//                                                              
// Action:
//  xd1 and xd2 are replaced with a flag
//  flag is TRUE (-1) if xd1 and xd2 are bitwise equal, FALSE (0) otherwise
//
// Forth standard:
//  8.6.1.1120
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or xd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdtos ( D>S )
//
// C prototype:
//  void dg_forthdtos (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 -- n2 )
//
// Data stack in:
//  nd1                           128 bit signed integer
//
// Data stack out:
//  n2                            64 bit signed integer
//                                                              
// Action:
//  nd1 is replaced with nd1 converted to it's 64 bit equivalent value
//  if nd1 is greater than the most positive 64 bit integer, the most positive
//   64 bit integer is returned
//  if nd1 is lesser than the most negative 64 bit integer, the most negative
//   64 bit integer is returned
//
// Forth standard:
//  8.6.1.1140
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdabs ( DABS )
//
// C prototype:
//  void dg_forthdabs (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 -- nd2 )
//
// Data stack in:
//  nd1                           128 bit signed integer
//
// Data stack out:
//  nd2                           128 bit signed integer
//                                                              
// Action:
//  nd1 is replaced with the absolute value of nd1
//
// Forth standard:
//  8.6.1.1160
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdmax ( DMAX )
//
// C prototype:
//  void dg_forthdmax (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 nd2 -- nd3 )
//
// Data stack in:
//  nd1 nd2                       2 128 bit signed integers to compare
//
// Data stack out:
//  nd3                           128 bit signed integer
//                                                              
// Action:
//  nd1 and nd2 are replaced the greater of nd1 or nd2
//
// Forth standard:
//  8.6.1.1210
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 or nd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdmin ( DMIN )
//
// C prototype:
//  void dg_forthdmin (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 nd2 -- nd3 )
//
// Data stack in:
//  nd1 nd2                       2 128 bit signed integers to compare
//
// Data stack out:
//  nd3                           128 bit signed integer
//                                                              
// Action:
//  nd1 and nd2 are replaced the lesser of nd1 or nd2
//
// Forth standard:
//  8.6.1.1220
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 or nd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdnegate ( DNEGATE )
//
// C prototype:
//  void dg_forthdnegate (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 -- nd2 )
//
// Data stack in:
//  nd1                           128 bit signed integer
//
// Data stack out:
//  nd2                           128 bit signed integer
//                                                              
// Action:
//  nd1 is replaced with the two's complement of nd1
//  nd2 = 0 - nd1
//
// Forth standard:
//  8.6.1.1230
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthdulessthan ( DU< )
//
// C prototype:
//  void dg_forthdulessthan (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( ud1 ud2 -- flag )
//
// Data stack in:
//  nd1 nd2                       2 128 bit unsigned integers to compare
//
// Data stack out:
//  flag                          ud1 and ud2 are replaced with a 64 bit flag
//                                                              
// Action:
//  ud1 and ud2 are replaced with a flag
//  flag is TRUE (-1) if ud1 is less than ud2, FALSE (0) otherwise
//
// Forth standard:
//  8.6.2.1270
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1 or nd2 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthmstarslash ( M*/ )
//
// C prototype:
//  void dg_forthmstarslash (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( nd1 n1 n2 -- nd2 )
//
// Data stack in:
//  nd1                           128 bit signed integer
//  n1                            64 bit signed integer
//  n2                            64 bit signed integer
//
// Data stack out:
//  nd2                           128 bit signed integer
//                                                              
// Action:
//  nd2 = (nd1 * n1) / n2
//  multiplies nd1 by n1 making a 192 bit signed integer intermediate result
//   then the intermediate result is divided by n2
//  the remainder is thrown away
//  if n2 is 0, or the absolute value of the result is larger than the largest 128
//   bit signed integer, the largest positive 128 bit signed integer is returned
//
// Forth standard:
//  8.6.1.1820
//
// Failure cases:
//  error getting pointer to the data stack
//  nd1, n2, or n3 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////
//
// dg_forthmplus ( M+ )
//
// C prototype:
//  void dg_forthmplus (Bufferhandle* pBHarrayhead)
//
// Inputs:
//  Bufferhandle* pBHarrayhead    pointer to a Bufferhandle structure which is 
//                                 used as the bufferhandle for the array where the  
//                                 other bufferhandles are stored.
// 
// Stack action shorthand:
//  ( xd1 n1 -- xd2 )
//
// Data stack in:
//  xd1                           128 bit integer
//  n1                            64 bit signed integer
//
// Data stack out:
//  nd2                           128 bit integer
//                                                              
// Action:
//  n1 is sign extended to a 128 bit signed integer then added to xd1
//  It does not matter if xd1 is signed or unsigned, the result is the same
//
// Forth standard:
//  8.6.1.1830
//
// Failure cases:
//  error getting pointer to the data stack
//  xd1 or n1 missing from datastack
//  
// //////////////////////////////////////////////////////////////////////////////////////