add case/endcase of/endof

llvm
Clyne 2 years ago
parent 18a4c6111f
commit a529c15918

@ -157,6 +157,7 @@ void parseLine(Parser& parser, State& state, const std::string& line)
while (state.rsize()) while (state.rsize())
state.popr(); state.popr();
state.dict.write(Dictionary::Compiling, 0); state.dict.write(Dictionary::Compiling, 0);
state.ip = 0;
} }
} }

@ -150,13 +150,13 @@ yes 6.2.0698 ACTION-OF
yes 6.2.0700 AGAIN yes 6.2.0700 AGAIN
yes 6.2.0825 BUFFER: yes 6.2.0825 BUFFER:
yes 6.2.0855 C" yes 6.2.0855 C"
6.2.0873 CASE yes 6.2.0873 CASE
yes 6.2.0945 COMPILE, yes 6.2.0945 COMPILE,
yes 6.2.1173 DEFER yes 6.2.1173 DEFER
yes 6.2.1175 DEFER! yes 6.2.1175 DEFER!
yes 6.2.1177 DEFER@ yes 6.2.1177 DEFER@
6.2.1342 ENDCASE yes 6.2.1342 ENDCASE
6.2.1343 ENDOF yes 6.2.1343 ENDOF
yes 6.2.1350 ERASE yes 6.2.1350 ERASE
yes 6.2.1485 FALSE yes 6.2.1485 FALSE
yes 6.2.1660 HEX yes 6.2.1660 HEX
@ -164,7 +164,7 @@ yes 6.2.1660 HEX
yes 6.2.1725 IS yes 6.2.1725 IS
yes 6.2.1850 MARKER yes 6.2.1850 MARKER
yes 6.2.1930 NIP yes 6.2.1930 NIP
6.2.1950 OF yes 6.2.1950 OF
6.2.2000 PAD 6.2.2000 PAD
6.2.2008 PARSE 6.2.2008 PARSE
6.2.2020 PARSE-NAME 6.2.2020 PARSE-NAME

@ -236,3 +236,9 @@
: evaluate _source @ >r _sourceu @ >r >in @ >r : evaluate _source @ >r _sourceu @ >r >in @ >r
0 >in ! _sourceu ! _source ! 5 sys 0 >in ! _sourceu ! _source ! 5 sys
r> >in ! r> _sourceu ! r> _source ! ; 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

@ -24,6 +24,17 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #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 class Dictionary
{ {
public: public:
@ -34,7 +45,7 @@ public:
constexpr static Addr Source = sizeof(Cell) * 4; constexpr static Addr Source = sizeof(Cell) * 4;
constexpr static Addr SourceLen = sizeof(Cell) * 5; constexpr static Addr SourceLen = sizeof(Cell) * 5;
constexpr static Addr Input = sizeof(Cell) * 6; // len data... 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; constexpr static Addr Begin = sizeof(Cell) * 7 + InputCells;
void initialize(); void initialize();

Loading…
Cancel
Save