evaluate complete

llvm
Clyne 2 years ago
parent 0a294fa8cc
commit a51428cff0

@ -26,7 +26,8 @@
: immediate imm ; : immediate imm ;
: state 3 cells ; : state 3 cells ;
: _source 4 cells ; : _source 4 cells ;
: >in 5 cells ; : _sourceu 5 cells ;
: >in 6 cells ;
: , here ! 1 cells allot ; : , here ! 1 cells allot ;
@ -232,6 +233,6 @@
dup @ _latest ! cell+ @ here swap - allot ; dup @ _latest ! cell+ @ here swap - allot ;
: :noname 0 , here ] ; : :noname 0 , here ] ;
: evaluate _source @ >r >in @ >r : evaluate _source @ >r _sourceu @ >r >in @ >r
0 >in ! _source ! 5 sys 0 >in ! _sourceu ! _source ! 5 sys
r> >in ! r> _source ! ; r> >in ! r> _sourceu ! r> _source ! ;

@ -95,25 +95,23 @@ Addr Dictionary::getexec(Addr addr) noexcept
Word Dictionary::input() noexcept Word Dictionary::input() noexcept
{ {
auto idx = read(Dictionary::Input);
auto src = read(Dictionary::Source); auto src = read(Dictionary::Source);
auto ch = readbyte(src + idx); auto end = read(Dictionary::SourceLen);
auto idx = read(Dictionary::Input);
if (ch) {
Addr wordstart = src + idx; Addr wordstart = src + idx;
Addr wordend = wordstart; Addr wordend = wordstart;
do { while (idx < end) {
ch = readbyte(wordend); auto ch = readbyte(wordend);
if (isspace(ch) || ch == '\0') { if (ch == '\0')
break;
if (isspace(ch)) {
if (wordstart != wordend) { if (wordstart != wordend) {
if (isspace(ch)) writebyte(Dictionary::Input, idx + 1);
++idx;
writebyte(Dictionary::Input, idx);
return {wordstart, wordend}; return {wordstart, wordend};
} else if (ch == '\0') {
return {};
} }
++wordstart; ++wordstart;
@ -121,7 +119,11 @@ Word Dictionary::input() noexcept
++wordend; ++wordend;
++idx; ++idx;
} while (ch); }
if (wordstart != wordend) {
writebyte(Dictionary::Input, idx + 1);
return {wordstart, wordend};
} }
return {}; return {};

@ -32,9 +32,10 @@ public:
constexpr static Addr Latest = sizeof(Cell) * 2; constexpr static Addr Latest = sizeof(Cell) * 2;
constexpr static Addr Compiling = sizeof(Cell) * 3; constexpr static Addr Compiling = sizeof(Cell) * 3;
constexpr static Addr Source = sizeof(Cell) * 4; constexpr static Addr Source = sizeof(Cell) * 4;
constexpr static Addr Input = sizeof(Cell) * 5; // len data... 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 = 82; // bytes!
constexpr static Addr Begin = sizeof(Cell) * 6 + InputCells; constexpr static Addr Begin = sizeof(Cell) * 7 + InputCells;
void initialize(); void initialize();

@ -26,6 +26,7 @@ int Parser::parse(State& state, const char *str)
{ {
auto addr = Dictionary::Input; auto addr = Dictionary::Input;
state.dict.write(addr, 0); state.dict.write(addr, 0);
state.dict.write(Dictionary::SourceLen, std::strlen(str));
addr += sizeof(Cell); addr += sizeof(Cell);
while (*str) while (*str)

@ -776,23 +776,23 @@ T{ ' W1 >BODY -> HERE }T
T{ W1 -> HERE 1 + }T T{ W1 -> HERE 1 + }T
T{ W1 -> HERE 2 + }T T{ W1 -> HERE 2 + }T
\ \ ------------------------------------------------------------------------ \ ------------------------------------------------------------------------
\ TESTING EVALUATE ." TESTING EVALUATE" CR
\
\ : GE1 S" 123" ; IMMEDIATE : GE1 S" 123" ; IMMEDIATE
\ : GE2 S" 123 1+" ; IMMEDIATE : GE2 S" 123 1+" ; IMMEDIATE
\ : GE3 S" : GE4 345 ;" ; : GE3 S" : GE4 345 ;" ;
\ : GE5 EVALUATE ; IMMEDIATE : GE5 EVALUATE ; IMMEDIATE
\
\ T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE ) T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE )
\ T{ GE2 EVALUATE -> 124 }T T{ GE2 EVALUATE -> 124 }T
\ T{ GE3 EVALUATE -> }T T{ GE3 EVALUATE -> }T
\ T{ GE4 -> 345 }T T{ GE4 -> 345 }T
\
\ T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE ) T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE )
\ T{ GE6 -> 123 }T T{ GE6 -> 123 }T
\ T{ : GE7 GE2 GE5 ; -> }T T{ : GE7 GE2 GE5 ; -> }T
\ T{ GE7 -> 124 }T T{ GE7 -> 124 }T
\ ------------------------------------------------------------------------ \ ------------------------------------------------------------------------
." TESTING SOURCE >IN WORD" CR ." TESTING SOURCE >IN WORD" CR

Loading…
Cancel
Save