From 501ca28d509bf6f41ed5797fa68f07e37ab9a294 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 9 Feb 2023 18:20:35 -0500 Subject: [PATCH] add more core.fth words --- alee.cpp | 5 ++++- core.fth | 35 ++++++++++++++++++++++++++++++++++- dictionary.hpp | 2 +- parser.cpp | 3 ++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/alee.cpp b/alee.cpp index 1232aa6..f87831f 100644 --- a/alee.cpp +++ b/alee.cpp @@ -50,6 +50,9 @@ int user_sys(State& state) case 0: std::cout << state.pop() << std::endl; break; + case 1: + std::cout << static_cast(state.pop()) << std::endl; + break; } return 0; @@ -63,7 +66,7 @@ void parseLine(Parser& parser, State& state, std::string_view line) } while (r == ParseStatus::Continue); if (r != ParseStatus::Finished) - std::cout << "r " << to_string(r) << std::endl; + std::cout << to_string(r) << ": " << line << std::endl; } void parseFile(Parser& parser, State& state, std::istream& file) diff --git a/core.fth b/core.fth index ab53923..555b126 100644 --- a/core.fth +++ b/core.fth @@ -1,15 +1,48 @@ ( : variable create 0 , ; ) ( : create here const ; ) -: . 0 sys ; +( set decimal numbers ) +10 0 ! + +: . 0 sys ; +: emit 1 sys ; : over 1 pick ; : -rot rot rot ; : nip swap drop ; : tuck swap over ; +: +! swap over @ + swap ! ; + : 1+ 1 + ; : 1- 1 - ; : 0= 0 = ; : >= < 0= ; + +: 2drop drop drop ; +: 2dup over over ; +: 2over 3 pick 3 pick ; +: 2swap rot >r rot r> ; + +: and & ; +: or | ; +: xor ^ ; +: lshift << ; +: rshift >> ; + +: , here ! 1 allot ; +: c! ! ; +: c, , ; +: c@ @ ; +: cell+ 1+ ; +: cells ; +: char+ 1+ ; +: chars ; + +: cr 9 emit ; +: bl 32 ; + +: base 0 ; +: decimal 1 2* base ! 1010 base ! ; + diff --git a/dictionary.hpp b/dictionary.hpp index add7fc3..2a54a5d 100644 --- a/dictionary.hpp +++ b/dictionary.hpp @@ -27,7 +27,7 @@ class Dictionary { public: - Addr here = 1; + Addr here = 1; // address zero will be used for BASE. Addr latest = 0; virtual Cell read(Addr) const = 0; diff --git a/parser.cpp b/parser.cpp index d57365b..99cbc8b 100644 --- a/parser.cpp +++ b/parser.cpp @@ -77,7 +77,8 @@ ParseStatus Parser::parse(State& state, std::string_view& str) } } else { char *p; - const auto l = static_cast(std::strtol(sub.data(), &p, 10)); + const auto base = state.dict.read(0); + const auto l = static_cast(std::strtol(sub.data(), &p, base)); if (p != sub.data()) { if (state.compiling) {