add more core.fth words

llvm
Clyne 2 years ago
parent 5bc9e4d2ad
commit 501ca28d50
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -50,6 +50,9 @@ int user_sys(State& state)
case 0: case 0:
std::cout << state.pop() << std::endl; std::cout << state.pop() << std::endl;
break; break;
case 1:
std::cout << static_cast<char>(state.pop()) << std::endl;
break;
} }
return 0; return 0;
@ -63,7 +66,7 @@ void parseLine(Parser& parser, State& state, std::string_view line)
} while (r == ParseStatus::Continue); } while (r == ParseStatus::Continue);
if (r != ParseStatus::Finished) 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) void parseFile(Parser& parser, State& state, std::istream& file)

@ -1,15 +1,48 @@
( : variable create 0 , ; ) ( : variable create 0 , ; )
( : create here const ; ) ( : create here const ; )
: . 0 sys ; ( set decimal numbers )
10 0 !
: . 0 sys ;
: emit 1 sys ;
: over 1 pick ; : over 1 pick ;
: -rot rot rot ; : -rot rot rot ;
: nip swap drop ; : nip swap drop ;
: tuck swap over ; : tuck swap over ;
: +! swap over @ + swap ! ;
: 1+ 1 + ; : 1+ 1 + ;
: 1- 1 - ; : 1- 1 - ;
: 0= 0 = ; : 0= 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 ! ;

@ -27,7 +27,7 @@
class Dictionary class Dictionary
{ {
public: public:
Addr here = 1; Addr here = 1; // address zero will be used for BASE.
Addr latest = 0; Addr latest = 0;
virtual Cell read(Addr) const = 0; virtual Cell read(Addr) const = 0;

@ -77,7 +77,8 @@ ParseStatus Parser::parse(State& state, std::string_view& str)
} }
} else { } else {
char *p; char *p;
const auto l = static_cast<Cell>(std::strtol(sub.data(), &p, 10)); const auto base = state.dict.read(0);
const auto l = static_cast<Cell>(std::strtol(sub.data(), &p, base));
if (p != sub.data()) { if (p != sub.data()) {
if (state.compiling) { if (state.compiling) {

Loading…
Cancel
Save