started compiler words
[rrq/rrqforth.git] / compile.asm
1 ;;; Words for adding words
2
3         WORD p_here,'HERE',dovariable
4         ;; The heap
5         dq heap_start
6         
7         ;; CREATE ( "[ \t\0]*([^ \t\0]+)" -- tfa )
8         ;; Skip leading whitespace and scan following non-whitespace
9         ;; as being a "word" to add into the current vocabulary. Add
10         ;; that word header, which consisits of:
11         WORD p_create,'CREATE',fasm
12         pushr rsi
13         push p_stdin_DFA        ; ( -- stream )
14         DOFORTH p_read_word     ; ( -- chars* n ) read next word
15         mov rax,qword [p_wordlist_DFA] ; Current word list
16         mov rax,[rax]           ; last word of current wordlist
17         mov rbx,qword [p_here_DFA] 
18         mov [rbx],rax           ; TFA of new word
19         mov qword [rbx+16],0    ; flags field
20         ;; copy pname
21         pop rcx                 ; n
22         mov qword [rbx+24],rcx  ; PFA (length)
23         pop rsi                 ; chars* (source)
24         lea rdi,[rbx+32]        ; (dest)
25         ;; clear DF
26 p_create_COPY:
27         movsb
28         dec rcx
29         jge p_create_COPY
30         mov byte [rdi],0        ; extra NUL
31         inc rdi
32         mov qword [rdi],rbx     ; pTFA
33         add rdi,8
34         mov qword [rdi],rbx     ; OFF
35         add rdi,8
36         mov qword [rbx+8],rdi   ; pCFA
37         add rdi,8
38         mov qword [rdi],dovalue ;CFA
39         add rdi,8
40         mov qword [rax],rbx     ; Install new word
41         mov qword [p_here_DFA],rdi ; allocate the space
42         push rbx
43         popr rsi
44         next
45
46         WORD p_allot,'ALLOT',fasm
47         ;; ( n -- )
48         ;; Allocate n bytes on the heap
49         pop rax
50         add rax,qword [p_here_DFA]
51         mov qword [p_here_DFA],rax
52         next
53         
54         ;; DOES> ( -- )
55         ;; Change DOES offset of latest compilation word to current
56         ;; compilation address.
57         ;; LATEST @ TFA>DOES HERE @ OVER - SWAP !
58         WORD p_does,'DOES>',fasm
59         mov rax,qword [p_wordlist_DFA] 
60         mov rax,[rax]           ; last word of current wordlist
61         add rax,8
62         ;add rax,byte [rax]
63         add rax,1
64         mov rbx,[p_here_DFA]
65         mov qword [rax],rbx
66         mov qword [rax+8],dodoes
67         next
68         
69         WORD p_literal,'LIT',IMMEDIATE
70         dq p_create
71         dq p_does
72         dq p_get
73         dq p_exit
74         
75         WORD p_execute,'EXECUTE'
76