]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
fix bad word detection
authorClyne Sullivan <clyne@bitgloo.com>
Fri, 17 Feb 2023 16:14:40 +0000 (11:14 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Fri, 17 Feb 2023 16:14:40 +0000 (11:14 -0500)
core.fth
parser.cpp

index d9c7a59a95adcc6a5d466c1dc540916af443f985..7a6e4550b08b63001c2f9f443ba08474d457deec 100644 (file)
--- a/core.fth
+++ b/core.fth
@@ -1,6 +1,9 @@
 ( : variable create 0 , ; )
 ( : create here const ; )
 
+: 1+      1 + ;
+: 1-      1 - ;
+
 : !       2 _! ;
 : @       2 _@ ;
 : ,       here ! 2 allot ;
@@ -14,7 +17,7 @@
 : chars   ;
 
 : align   here 1 & if 1 allot then ;
-: aligned dup 1 & if 1 + then ;
+: aligned dup 1 & if 1+ then ;
 
 ( set decimal numbers )
 10 0 !
 : 2*      2 * ;
 : 2/      2 / ;
 
-: 0=      0 = ;
-: 0<      0 < ;
-: <=      2dup < -rot = and ;
-: >       <= 0= ;
-
-: 1+      1 + ;
-: 1-      1 - ;
-
 : 2drop   drop drop ;
 : 2dup    over over ;
 : 2over   3 pick 3 pick ;
 : 2!      swap over ! cell+ ! ;
 : 2@      dup cell+ @ swap @ ;
 
+: 0=      0 = ;
+: 0<      0 < ;
+: <=      2dup - 1- 0< ;
+: >       <= 0= ;
+
 : cr      9 emit ;
 : bl      32 ;
 : space   bl emit ;
index b4c2d1cecdca31d4d7222c67e71f614e7aa49615..b44547fbf96220f0c8f883e8dcbae304eb8c1b88 100644 (file)
@@ -74,15 +74,16 @@ ParseStatus Parser::parseWord(State& state, Word word)
             state.execute(e);
         }
     } else {
-        char buf[word.size()];
+        char buf[word.size() + 1];
         for (unsigned i = 0; i < word.size(); ++i)
             buf[i] = state.dict.readbyte(word.start + i);
+        buf[word.size()] = '\0';
 
         char *p;
         const auto base = state.dict.read(0);
         const Cell l = std::strtol(buf, &p, base);
 
-        if (p != buf) {
+        if (std::distance(buf, p) == word.size()) {
             if (state.compiling()) {
                 state.dict.add(CoreWords::HiddenWordLiteral);
                 state.dict.add(l);