From 12cb6b9e5607e9db2255afd977814cbb0e3fceae Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 17 Feb 2023 11:14:40 -0500 Subject: [PATCH] fix bad word detection --- core.fth | 18 +++++++++--------- parser.cpp | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core.fth b/core.fth index d9c7a59..7a6e455 100644 --- 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 ! @@ -38,14 +41,6 @@ : 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 ; @@ -55,6 +50,11 @@ : 2! swap over ! cell+ ! ; : 2@ dup cell+ @ swap @ ; +: 0= 0 = ; +: 0< 0 < ; +: <= 2dup - 1- 0< ; +: > <= 0= ; + : cr 9 emit ; : bl 32 ; : space bl emit ; diff --git a/parser.cpp b/parser.cpp index b4c2d1c..b44547f 100644 --- a/parser.cpp +++ b/parser.cpp @@ -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);