-
Notifications
You must be signed in to change notification settings - Fork 0
/
term.inc
77 lines (59 loc) · 1.4 KB
/
term.inc
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
TERM_VAR = 0
TERM_NOT = 1
TERM_AND = 2
TERM_OR = 3
TERM_IMP = 4
TERM_EQV = 5
;I will often refer to TERMVAR & TERM1 structs as just TERM
struct TERMVAR
type db TERM_VAR
t1 rb 0 ;string of some length, NULL-terminated
ends
struct TERM1
type rb 1 ;one of TERM_*
t1 rq 1 ;ptr to TERM
ends
struct TERM TERM1
t2 rq 1 ;ptr to TERM
ends
term equ r12
;Free term and child terms
;Does not free TERMVARs
;term
fbound
term_free:
push NULL
push arg1
.loop:
pop rax
test rax,rax ;is NULL?
jz .done
mov cl, [rax+TERM.type]
test cl,cl
jz .loop ;skip vars
push [rax+TERM.t1]
cmp cl, TERM_AND
jb @f
push [rax+TERM.t2]
bt rsp, 3
jc .align_free
frame
mfree rax
endf
jmp .loop
@@: ;TERM1
bt rsp, 3
jc .align_free
frame
mfree rax
endf
jmp .loop
.align_free:
;align stack
frame_odd
mfree rax
endf
jmp .loop
.done:
ret
restore term