-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathrecognizer-ext.fs
70 lines (56 loc) · 2.74 KB
/
recognizer-ext.fs
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
\ Recognizer extensions
\ Authors: Bernd Paysan
\ Copyright (C) 2020,2021,2022,2023,2024 Free Software Foundation, Inc.
\ This file is part of Gforth.
\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.
0 Value translator-offset
#10 cells constant translator-max-offset#
s" No more translator slots free" exception constant translator-overflow
: >translate-method ( xt rectype translate-method -- )
>body @ >body + ;
fold1: ( xt -- ) >body @ lit, postpone >body postpone + ;
' >translate-method defer-table to-class: translate-method-to
' postponing make-latest
' translate-method-to set-to
Create translate-methods
translator-max-offset# 0 [DO] ' noop , [LOOP]
: translate-method: ( "name" -- ) \ gforth-experimental
\G create a new translate method, extending the translator table.
\G You can assign an xt to an existing rectype by using
\G @var{xt rectype} @code{to} @var{translator}.
translator-offset translator-max-offset# u>=
translator-overflow and throw
['] postponing create-from reveal
latestxt translate-methods translator-offset + !
translator-offset , cell +to translator-offset ;
translate-method: interpreting ( translator -- ) \ gforth-experimental
\G perform interpreter action of translator
translate-method: compiling ( translator -- ) \ gforth-experimental
\G perform compile action of translator
\ we already have defined this in the kernel
\ translate-method: postponing ( translator -- ) \ gforth-experimental
\ \G perform postpone action of translator
' postponing translate-methods translator-offset + !
cell +to translator-offset
: set-state ( xt -- ) \ gforth-experimental
\G change the current state of the system so that executing
\G a translator matches the translate-method passed as @var{xt}
dup >does-code [ ' postponing >does-code ] Literal <> #-12 and throw
>body @ cell/ negate state ! ;
opt: lits# 1 u>= IF
lits> dup >does-code [ ' postponing >does-code ] Literal = IF
>body @ cell/ negate lit, postpone state postpone ! drop EXIT
ELSE #-12 throw THEN
THEN :, ;
: get-state ( -- xt ) \ gforth-experimental
\G return the currently used translate-method @var{xt}
state @ abs cells translate-methods + @ ;