Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
forth_tutorial/forth20/forth.f
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (40 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ s11 print printeol ] bind: print-top | |
[ label: .loop | |
call_stack.len pushe: 0 == goto-if: .end | |
call_stack.pop s11 memory.get | |
s21 pushe: 1 + call_stack.push | |
s11 is-primitive push: call-primitive push: call_stack.push if-else | |
goto: .loop | |
label: .end ] bind: main-loop | |
[ call_stack.pop s2 ] bind: return | |
[ is-input-end push: read-stdin if next-char | |
s11 is-whitespace ] bind: next-char-is-space | |
[ push: None | |
label: .space-loop s2 next-char-is-space goto-if: .space-loop | |
strings.len s21 pushe: 0 strings.append | |
label: .word-loop strings.append next-char-is-space not goto-if: .word-loop | |
s2 s11 s11 strings.len s21 - pushe: 1 - s21 strings.set_at | |
] bind: next-input | |
[ names.keys.index names.values.get ] bind: names.get | |
[ names.keys.len ] bind: names.len | |
[ names.keys.append names.values.append ] bind: names.set | |
[ names.len | |
label: .loop | |
pushe: 1 - s1212 names.keys.get strings.address | |
string_equal goto-if: .found | |
s11 goto-if: .loop | |
s2 push: None | |
label: .found s21 s2 ] bind: names.keys.index | |
[ memory.len | |
label: .loop | |
next-input s11 equal-right-bracket goto-if: .end | |
strings.address names.get memory.append | |
goto: .loop | |
label: .end | |
s2 push: return-index memory.append | |
] bind: [ | |
[ label: .loop | |
next-input strings.address names.get pushe: 0 memory.set_at | |
pushe: 0 call_stack.push main-loop | |
goto: .loop ] bind: input-loop | |
[ setup input-loop exit ] bind: _start |