]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
add case/endcase of/endof
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 4 Mar 2023 14:51:08 +0000 (09:51 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 4 Mar 2023 14:51:08 +0000 (09:51 -0500)
alee.cpp
compat.txt
core.fth
dictionary.hpp

index 633b8d7cf6e95330f58870176bc0b67572f3841d..1be73379ad8d1f20dcf5b61315468d5fe1585fbe 100644 (file)
--- a/alee.cpp
+++ b/alee.cpp
@@ -157,6 +157,7 @@ void parseLine(Parser& parser, State& state, const std::string& line)
         while (state.rsize())
             state.popr();
         state.dict.write(Dictionary::Compiling, 0);
+        state.ip = 0;
     }
 }
 
index 189cfb7c8554867e2d4d7f8aa34c136ff18a36c7..890871a44d73d80a567a9296d77ff76dbc4bb02b 100644 (file)
@@ -150,13 +150,13 @@ yes 6.2.0698 ACTION-OF
 yes 6.2.0700 AGAIN
 yes 6.2.0825 BUFFER:
 yes 6.2.0855 C"
-    6.2.0873 CASE
+yes 6.2.0873 CASE
 yes 6.2.0945 COMPILE,
 yes 6.2.1173 DEFER
 yes 6.2.1175 DEFER!
 yes 6.2.1177 DEFER@
-    6.2.1342 ENDCASE
-    6.2.1343 ENDOF
+yes 6.2.1342 ENDCASE
+yes 6.2.1343 ENDOF
 yes 6.2.1350 ERASE
 yes 6.2.1485 FALSE
 yes 6.2.1660 HEX
@@ -164,7 +164,7 @@ yes 6.2.1660 HEX
 yes 6.2.1725 IS
 yes 6.2.1850 MARKER
 yes 6.2.1930 NIP
-    6.2.1950 OF
+yes 6.2.1950 OF
     6.2.2000 PAD
     6.2.2008 PARSE
     6.2.2020 PARSE-NAME
index fd073a853f6432d723b47ce21f0a42ce11436f28..c5b80b62ceb9fc49bb2745a4f312268ff3332dce 100644 (file)
--- a/core.fth
+++ b/core.fth
 : evaluate _source @ >r _sourceu @ >r >in @ >r
            0 >in ! _sourceu ! _source ! 5 sys
            r> >in ! r> _sourceu ! r> _source ! ;
+
+: case     ['] _lit , 1 here 0 , ['] drop , ; imm
+: of       ['] over , ['] = , postpone if ; imm
+: endof    ['] _jmp , here >r 0 , postpone then
+           swap 1+ swap r> tuck ! ; imm
+: endcase  swap 0 do dup @ swap here swap ! loop drop ['] drop , ; imm
index 235bd78f032795674a884cfb866434177c30b578..4dcae770321b7803a2d4ce26053c2c7f65a26616 100644 (file)
 #include <cstddef>
 #include <cstdint>
 
+/**
+ * Dictionary entry format:
+ *  - 1 information byte
+ *    bits  0..4: Length of name (L)
+ *    bit      5: Immediate?
+ *    bits 6..15: Distance to next entry (negative)
+ *  - L bytes of name
+ *  - 0+ bytes for address alignment
+ *  - 0+ bytes of entry's data...
+ */
+
 class Dictionary
 {
 public:
@@ -34,7 +45,7 @@ public:
     constexpr static Addr Source     = sizeof(Cell) * 4;
     constexpr static Addr SourceLen  = sizeof(Cell) * 5;
     constexpr static Addr Input      = sizeof(Cell) * 6; // len data...
-    constexpr static Addr InputCells = 82; // bytes!
+    constexpr static Addr InputCells = 80; // bytes!
     constexpr static Addr Begin      = sizeof(Cell) * 7 + InputCells;
 
     void initialize();