~remexre/stahlos

ref: 7bf2eb256167be5b7093a32d8819707d1bca1286 stahlos/src/kernel-aarch64/forth/pseudobuiltins.s -rw-r--r-- 4.6 KiB
7bf2eb25Nathan Ringo ... 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
.section .text

.set last_defword, forth.last_builtin_header
.macro defword label, name, flags=0, cfa=forth_impl_colon
.global \label
\label\().padding:
.fill (258 - (\label - \label\().name)) % 4
\label\().header:
	.quad last_defword
	.byte \flags
	.byte \label - \label\().name
\label\().name:
	.ascii "\name"
\label:
	ldr x1, .+8
	br x1
	.quad \cfa
\label\().pfa:
.set last_defword, \label\().header
.endm

defword forth_create, "CREATE"
	.quad forth_parse_name
	.quad forth_dup
	.quad forth_impl_branch_zero, forth_create.error
	.quad forth_dup
	.quad forth_impl_literal, 3
	.quad forth_and
	.quad forth_impl_literal, 2
	.quad forth_swap
	.quad forth_minus
	.quad forth_impl_literal, 3
	.quad forth_and
	.quad forth_allot

	.quad forth_process_table
	.quad forth_load_64
	.quad forth_here
	.quad forth_process_table
	.quad forth_store_64
	.quad forth_comma
	.quad forth_impl_literal, 0
	.quad forth_comma_8

	.quad forth_dup
	.quad forth_comma_8

forth_create.write_name:
	.quad forth_dup
	.quad forth_impl_branch_zero, forth_create.write_cfa
	.quad forth_swap
	.quad forth_dup
	.quad forth_load_8
	.quad forth_comma_8
	.quad forth_one_plus
	.quad forth_swap
	.quad forth_one_minus
	.quad forth_impl_branch, forth_create.write_name

forth_create.write_cfa:
	.quad forth_two_drop
	.quad forth_impl_literal, 16
	.quad forth_allot
	.quad forth_impl_literal, forth_impl_variable
	.quad forth_set_does
	.quad forth_impl_semicolon
forth_create.error:
	.quad forth_impl_literal, -39
	.quad forth_throw

defword forth_evaluate, "EVALUATE"
	.quad forth_source
	.quad forth_to_rstack
	.quad forth_to_rstack
	.quad forth_to_rstack
	.quad forth_set_source

forth_evaluate.loop:
	.quad forth_parse_name
	.quad forth_dup

	.quad forth_impl_branch_zero, forth_evaluate.end

	.quad forth_two_dup
	.quad forth_find_header

	.quad forth_dup
	.quad forth_impl_branch_zero, forth_evaluate.loop.try_as_number

	.quad forth_to_rstack
	.quad forth_two_drop
	.quad forth_from_rstack
	.quad forth_dup
	.quad forth_header_to_xt
	.quad forth_swap
	.quad forth_header_to_immediate
	.quad forth_flags
	.quad forth_impl_literal, 1
	.quad forth_and
	.quad forth_or

	.quad forth_impl_branch_zero, forth_evaluate.loop.compile_word
	.quad forth_execute
	.quad forth_impl_branch, forth_evaluate.loop
forth_evaluate.loop.compile_word:
	.quad forth_compile_comma
	.quad forth_impl_branch, forth_evaluate.loop

forth_evaluate.loop.try_as_number:
	.quad forth_drop
	.quad forth_two_dup
	.quad forth_to_number
	.quad forth_impl_branch_zero, forth_evaluate.loop.number
	.quad forth_drop
	.quad forth_impl_literal, word_not_found
	.quad forth_impl_literal, word_not_found.len
	.quad forth_type
	.quad forth_type
	.quad forth_cr
	.quad forth_impl_literal, -13
	.quad forth_throw

forth_evaluate.loop.number:
	.quad forth_flags
	.quad forth_impl_literal, 1
	.quad forth_and
	.quad forth_impl_branch_zero, forth_evaluate.loop.number.compile

forth_evaluate.loop.number.interpret:
	.quad forth_rot_rev
	.quad forth_two_drop
	.quad forth_impl_branch, forth_evaluate.loop

forth_evaluate.loop.number.compile:
	.quad forth_impl_literal, forth_impl_literal
	.quad forth_compile_comma
	.quad forth_comma
	.quad forth_two_drop
	.quad forth_impl_branch, forth_evaluate.loop

forth_evaluate.end:
	.quad forth_two_drop
	.quad forth_from_rstack
	.quad forth_from_rstack
	.quad forth_from_rstack
	.quad forth_set_source
	.quad forth_impl_semicolon

defword forth_header_to_immediate, "HEADER>IMMEDIATE?"
	.quad forth_header_to_flags
	.quad forth_impl_literal, 1
	.quad forth_and
	.quad forth_nonzero
	.quad forth_impl_semicolon

defword forth_parse_and_find, "PARSE-AND-FIND"
	.quad forth_parse_name
	.quad forth_dup
	.quad forth_impl_branch_zero, forth_parse_and_find.error
	.quad forth_find_header
	.quad forth_impl_semicolon
forth_parse_and_find.error:
	.quad forth_impl_literal, -39
	.quad forth_throw

defword forth_quote, "'"
	.quad forth_parse_and_find
	.quad forth_header_to_xt
	.quad forth_impl_semicolon

defword forth_two_drop, "2DROP"
	.quad forth_drop
	.quad forth_drop
	.quad forth_impl_semicolon

defword forth_two_dup, "2DUP"
	.quad forth_over
	.quad forth_over
	.quad forth_impl_semicolon

defword forth_type, "TYPE"
forth_type.loop:
	.quad forth_dup
	.quad forth_impl_branch_zero, forth_type.end
	.quad forth_swap
	.quad forth_dup
	.quad forth_load_8
	.quad forth_emit
	.quad forth_one_plus
	.quad forth_swap
	.quad forth_one_minus
	.quad forth_impl_branch, forth_type.loop
forth_type.end:
	.quad forth_two_drop
	.quad forth_impl_semicolon

.global forth.last_pseudobuiltin_header
.equiv forth.last_pseudobuiltin_header, last_defword

.section .rodata

word_not_found: .ascii "Word not found: "
.equ word_not_found.len, . - word_not_found

/* vi: set ft=arm64asm : */