1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 urword_var
"(CSP)",csp
,0
21 urword_forth
"!CSP",savecsp
25 urword_forth
"?CSP",qcsp
27 UF spget csp @
- errid_unfinished_definition qerror
30 urword_forth
"?COMP",qcomp
31 UF state @
0 equal errid_compilation_only qerror
34 urword_forth
"?EXEC",qexec
35 UF state @ errid_execution_only qerror
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 urword_forth
"LITERAL",literal
49 urword_forth
"COMPILE,",compile_comma
56 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57 ; write 4-byte displacement for CALL/JMP jmpdest instruction to addr
58 ; addr should point after the instruction, at the first displacement byte
59 urword_forth
"(DISP32!)",par_disp32set
61 ;; ( jmpdest addr -- )
62 UF dup cellinc rot swap
- swap
!
65 urword_forth
"(DISP32@)",par_disp32get
67 ;; ( addr -- jumpdest )
68 UF dup @ swap cellinc
+
71 ; write 5-byte CALL calldest machine instruction to addr
72 urword_forth
"(CALL!)",par_callset
74 ;; ( calldest addr -- )
75 UF
0xe8 over cpoke
1inc ; write CALL, advance address
79 ; write 5-byte JMP jmpdest machine instruction to addr
80 urword_forth
"(JMP!)",par_jmpset
82 ;; ( jmpdest addr -- )
83 UF
0xe9 over cpoke
1inc ; write JMP, advance address
87 ; compile 5-byte CALL calldest machine instruction to HERE
88 urword_forth
"(CALL,)",par_callcomma
91 UF
5 n_allot par_callset
94 ; compile 5-byte JMP jmpdest machine instruction to HERE
95 urword_forth
"(JMP,)",par_jmpcomma
98 UF
5 n_allot par_jmpset