aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-03-04 07:02:22 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-03-04 07:02:22 -0500
commita51428cff0b7d16e7e0b5e5bfd05c47ab55e4fa2 (patch)
treef29699ece46316faab4786d8618da34581059231
parent0a294fa8cc8f9f5c491a3aec4ff416a455d6ebef (diff)
evaluate complete
-rw-r--r--core.fth9
-rw-r--r--dictionary.cpp50
-rw-r--r--dictionary.hpp5
-rw-r--r--parser.cpp1
-rw-r--r--test/core.fr34
5 files changed, 52 insertions, 47 deletions
diff --git a/core.fth b/core.fth
index 2d769c2..fd073a8 100644
--- a/core.fth
+++ b/core.fth
@@ -26,7 +26,8 @@
: immediate imm ;
: state 3 cells ;
: _source 4 cells ;
-: >in 5 cells ;
+: _sourceu 5 cells ;
+: >in 6 cells ;
: , here ! 1 cells allot ;
@@ -232,6 +233,6 @@
dup @ _latest ! cell+ @ here swap - allot ;
: :noname 0 , here ] ;
-: evaluate _source @ >r >in @ >r
- 0 >in ! _source ! 5 sys
- r> >in ! r> _source ! ;
+: evaluate _source @ >r _sourceu @ >r >in @ >r
+ 0 >in ! _sourceu ! _source ! 5 sys
+ r> >in ! r> _sourceu ! r> _source ! ;
diff --git a/dictionary.cpp b/dictionary.cpp
index 6432607..48230c4 100644
--- a/dictionary.cpp
+++ b/dictionary.cpp
@@ -95,33 +95,35 @@ Addr Dictionary::getexec(Addr addr) noexcept
Word Dictionary::input() noexcept
{
- auto idx = read(Dictionary::Input);
auto src = read(Dictionary::Source);
- auto ch = readbyte(src + idx);
-
- if (ch) {
- Addr wordstart = src + idx;
- Addr wordend = wordstart;
-
- do {
- ch = readbyte(wordend);
-
- if (isspace(ch) || ch == '\0') {
- if (wordstart != wordend) {
- if (isspace(ch))
- ++idx;
- writebyte(Dictionary::Input, idx);
- return {wordstart, wordend};
- } else if (ch == '\0') {
- return {};
- }
-
- ++wordstart;
+ auto end = read(Dictionary::SourceLen);
+ auto idx = read(Dictionary::Input);
+
+ Addr wordstart = src + idx;
+ Addr wordend = wordstart;
+
+ while (idx < end) {
+ auto ch = readbyte(wordend);
+
+ if (ch == '\0')
+ break;
+
+ if (isspace(ch)) {
+ if (wordstart != wordend) {
+ writebyte(Dictionary::Input, idx + 1);
+ return {wordstart, wordend};
}
- ++wordend;
- ++idx;
- } while (ch);
+ ++wordstart;
+ }
+
+ ++wordend;
+ ++idx;
+ }
+
+ if (wordstart != wordend) {
+ writebyte(Dictionary::Input, idx + 1);
+ return {wordstart, wordend};
}
return {};
diff --git a/dictionary.hpp b/dictionary.hpp
index 20ac7e4..235bd78 100644
--- a/dictionary.hpp
+++ b/dictionary.hpp
@@ -32,9 +32,10 @@ public:
constexpr static Addr Latest = sizeof(Cell) * 2;
constexpr static Addr Compiling = sizeof(Cell) * 3;
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 Begin = sizeof(Cell) * 6 + InputCells;
+ constexpr static Addr Begin = sizeof(Cell) * 7 + InputCells;
void initialize();
diff --git a/parser.cpp b/parser.cpp
index 22c2cc3..44b5cec 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -26,6 +26,7 @@ int Parser::parse(State& state, const char *str)
{
auto addr = Dictionary::Input;
state.dict.write(addr, 0);
+ state.dict.write(Dictionary::SourceLen, std::strlen(str));
addr += sizeof(Cell);
while (*str)
diff --git a/test/core.fr b/test/core.fr
index 9b866a2..2d8b8e4 100644
--- a/test/core.fr
+++ b/test/core.fr
@@ -776,23 +776,23 @@ T{ ' W1 >BODY -> HERE }T
T{ W1 -> HERE 1 + }T
T{ W1 -> HERE 2 + }T
-\ \ ------------------------------------------------------------------------
-\ TESTING EVALUATE
-\
-\ : GE1 S" 123" ; IMMEDIATE
-\ : GE2 S" 123 1+" ; IMMEDIATE
-\ : GE3 S" : GE4 345 ;" ;
-\ : GE5 EVALUATE ; IMMEDIATE
-\
-\ T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE )
-\ T{ GE2 EVALUATE -> 124 }T
-\ T{ GE3 EVALUATE -> }T
-\ T{ GE4 -> 345 }T
-\
-\ T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE )
-\ T{ GE6 -> 123 }T
-\ T{ : GE7 GE2 GE5 ; -> }T
-\ T{ GE7 -> 124 }T
+\ ------------------------------------------------------------------------
+." TESTING EVALUATE" CR
+
+: GE1 S" 123" ; IMMEDIATE
+: GE2 S" 123 1+" ; IMMEDIATE
+: GE3 S" : GE4 345 ;" ;
+: GE5 EVALUATE ; IMMEDIATE
+
+T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE )
+T{ GE2 EVALUATE -> 124 }T
+T{ GE3 EVALUATE -> }T
+T{ GE4 -> 345 }T
+
+T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE )
+T{ GE6 -> 123 }T
+T{ : GE7 GE2 GE5 ; -> }T
+T{ GE7 -> 124 }T
\ ------------------------------------------------------------------------
." TESTING SOURCE >IN WORD" CR