]> git.mdlowis.com Git - projs/onward.git/commitdiff
Started re-organizing and debugging defined words dictionary
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 Dec 2014 21:27:24 +0000 (16:27 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 Dec 2014 21:27:24 +0000 (16:27 -0500)
source/onward.c
source/onward.ft
source/onward_sys.h
tests/main.c

index 402a2f5a2c4b9ab83c6a763049a4fd967ef792dd..76c72b3099768686bfb5e93d2cfd9a5b1b51277c 100755 (executable)
@@ -651,6 +651,11 @@ static syscall_fn_t System_Calls[7] = {
 #ifdef STANDALONE
 #include <stdbool.h>
 
+static bool Newline_Consumed = false;
+value_t Argument_Stack[ARG_STACK_SZ];
+value_t Return_Stack[RET_STACK_SZ];
+value_t Word_Buffer[WORD_BUF_SZ];
+
 defvar("infile",  infile,  0u, LATEST_BUILTIN);
 defvar("outfile", outfile, 0u, &infile_word);
 defvar("errfile", errfile, 0u, &outfile_word);
@@ -658,8 +663,6 @@ defcode("syscall", syscall, &errfile_word, 0u) {
     System_Calls[onward_aspop()]();
 }
 
-static bool Newline_Consumed = false;
-
 value_t fetch_char(void)
 {
     value_t ch = (value_t)fgetc((FILE*)infile);
index 93b39fd580a2e1744e0145e7415d45fb8da5fe9a..bec0bcb7996df2769a9096197bbd8f1f568b3a6b 100644 (file)
@@ -1,74 +1,99 @@
+\ Compiler Words
+\ -----------------------------------------------------------------------------
 : immediate
    latest @        \ Get the latest word
    CELLSZ +        \ Add offset to get to the flags field
    dup @           \ Fetch the current value
    F_IMMEDIATE | ! \ Set the immediate bit
-; immediate
+; immediate
 
-: [compile] immediate
-    word find ,
-;
+: [compile] immediate
+    word find ,
+;
 
-: #  [compile] \ ;
-: #! [compile] \ ;
+\ : recurse immediate
+\     latest @ ,
+\ ;
 
-: recurse immediate
-    latest @ ,
-;
+\ Conditional Words: if, then, else
+\ -----------------------------------------------------------------------------
+\ : if immediate
+\    ' 0br , \ compile 0branch
+\    here @  \ save location of the offset on the stack
+\    0 ,     \ compile a dummy offset
+\ ;
 
-: if immediate
-   ' 0br , \ compile 0branch
-   here @  \ save location of the offset on the stack
-   0 ,     \ compile a dummy offset
-;
+\ : then immediate
+\     dup
+\     here @ swap -   \ calculate the offset from the address saved on the stack
+\     !
+;
 
-: then immediate
-    dup
-    here @ swap -   \ calculate the offset from the address saved on the stack
-    !
-;
+\ : else immediate
+\     ' br ,          \ definite branch to just over the false-part
+\     here @          \ save location of the offset on the stack
+\     0 ,             \ compile a dummy offset
+\     swap            \ now back-fill the original (if) offset
+\     dup             \ same as for then word above
+\     here @ swap -   \ calculate the offset from the address saved on the stack
+\     !
+\ ;
 
-: else immediate
-    ' br ,          \ definite branch to just over the false-part
-    here @          \ save location of the offset on the stack
-    0 ,             \ compile a dummy offset
-    swap            \ now back-fill the original (if) offset
-    dup             \ same as for then word above
-    here @ swap -   \ calculate the offset from the address saved on the stack
-    !
-;
+\ Looping Words
+\ -----------------------------------------------------------------------------
+\ : begin immediate here @ ;
 
-: begin immediate here @ ;
+\ : until immediate
+\     ' 0br ,   \ compile 0BRANCH
+\     here @ -  \ calculate the offset from the address saved on the stack
+\     ,         \ compile the offset here
+\ ;
 
-: until immediate
-    ' 0br ,   \ compile 0BRANCH
-    here @ -  \ calculate the offset from the address saved on the stack
-    ,         \ compile the offset here
-;
+\ : again immediate
+\     ' br ,   \ compile branch
+\     here @ - \ calculate the offset back
+\     ,        \ compile the offset here
+;
 
-: again immediate
-    ' br ,   \ compile branch
-    here @ - \ calculate the offset back
-    ,        \ compile the offset here
-;
+\ : while immediate
+\     ' 0br , \ compile 0branch
+\     here @  \ save location of the offset2 on the stack
+\     0 ,     \ compile a dummy offset2
+;
 
-: while immediate
-    ' 0br , \ compile 0branch
-    here @  \ save location of the offset2 on the stack
-    0 ,     \ compile a dummy offset2
-;
+\ : repeat immediate
+\     ' br ,         \ compile branch
+\     swap           \ get the original offset (from begin)
+\     here @ - ,     \ and compile it after branch
+\     dup
+\     here @ swap -  \ calculate the offset2
+\     !              \ and back-fill it in the original location
+\ ;
 
-: repeat immediate
-    ' br ,         \ compile branch
-    swap           \ get the original offset (from begin)
-    here @ - ,     \ and compile it after branch
-    dup
-    here @ swap -  \ calculate the offset2
-    !              \ and back-fill it in the original location
-;
+\ : unless immediate
+\     ' not ,         \ compile not (to reverse the test)
+\     [compile] if    \ continue by calling the normal if
+\ ;
+
+\ Comment Words
+\ -----------------------------------------------------------------------------
+\ : #  [compile] \ ;
+\ : #! [compile] \ ;
+
+\ : ( immediate
+\     1                  \ allowed nested parens by keeping track of depth
+\     begin
+\         key            \ read next character
+\         dup 0x28 = if  \ open paren?
+\             drop       \ drop the open paren
+\             1 +        \ depth increases
+\         else
+\             0x29 = if  \ close paren?
+\                 1 -    \ depth decreases
+\             then
+\         then
+\     dup 0 = until      \ continue until we reach matching close paren, depth 0
+\     drop               \ drop the depth counter
+\ ;
 
-: unless immediate
-    ' not ,         \ compile not (to reverse the test)
-    [compile] if    \ continue by calling the normal if
-;
 
index 622c3c94a51a5891efd08b1eae17357d7bd0d904..ea40007064c4724784943df5434d82aaae3bff6e 100644 (file)
 #define WORD_BUF_SZ (8192 / sizeof(value_t))
 #endif
 
-value_t Argument_Stack[ARG_STACK_SZ];
+extern value_t Argument_Stack[ARG_STACK_SZ];
 
-value_t Return_Stack[RET_STACK_SZ];
+extern value_t Return_Stack[RET_STACK_SZ];
 
-value_t Word_Buffer[WORD_BUF_SZ];
+extern value_t Word_Buffer[WORD_BUF_SZ];
 
 value_t fetch_char(void);
 
index 29d725569c820e5e0af012a6d7b17537cb852eb9..f5bf5e38ed85aa0fb2dc201cc110ab8ec74c5a1f 100755 (executable)
@@ -1,8 +1,11 @@
 #include "atf.h"
 #include "onward.h"
+#include "onward_sys.h"
 
 char* input = "";
-value_t Word_Buffer[1024 / sizeof(value_t)];
+value_t Argument_Stack[ARG_STACK_SZ];
+value_t Return_Stack[RET_STACK_SZ];
+value_t Word_Buffer[WORD_BUF_SZ];
 
 value_t fetch_char(void)
 {