started compiler words
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 18 May 2021 14:55:35 +0000 (00:55 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 18 May 2021 14:55:35 +0000 (00:55 +1000)
compile.asm [new file with mode: 0644]
rrqforth.asm

diff --git a/compile.asm b/compile.asm
new file mode 100644 (file)
index 0000000..1e76aee
--- /dev/null
@@ -0,0 +1,76 @@
+;;; Words for adding words
+
+       WORD p_here,'HERE',dovariable
+       ;; The heap
+       dq heap_start
+       
+       ;; CREATE ( "[ \t\0]*([^ \t\0]+)" -- tfa )
+       ;; Skip leading whitespace and scan following non-whitespace
+       ;; as being a "word" to add into the current vocabulary. Add
+       ;; that word header, which consisits of:
+       WORD p_create,'CREATE',fasm
+       pushr rsi
+       push p_stdin_DFA        ; ( -- stream )
+       DOFORTH p_read_word     ; ( -- chars* n ) read next word
+       mov rax,qword [p_wordlist_DFA] ; Current word list
+       mov rax,[rax]           ; last word of current wordlist
+       mov rbx,qword [p_here_DFA] 
+       mov [rbx],rax           ; TFA of new word
+       mov qword [rbx+16],0    ; flags field
+       ;; copy pname
+       pop rcx                 ; n
+       mov qword [rbx+24],rcx  ; PFA (length)
+       pop rsi                 ; chars* (source)
+       lea rdi,[rbx+32]        ; (dest)
+       ;; clear DF
+p_create_COPY:
+       movsb
+       dec rcx
+       jge p_create_COPY
+       mov byte [rdi],0        ; extra NUL
+       inc rdi
+       mov qword [rdi],rbx     ; pTFA
+       add rdi,8
+       mov qword [rdi],rbx     ; OFF
+       add rdi,8
+       mov qword [rbx+8],rdi   ; pCFA
+       add rdi,8
+       mov qword [rdi],dovalue ;CFA
+       add rdi,8
+       mov qword [rax],rbx     ; Install new word
+       mov qword [p_here_DFA],rdi ; allocate the space
+       push rbx
+       popr rsi
+       next
+
+       WORD p_allot,'ALLOT',fasm
+       ;; ( n -- )
+       ;; Allocate n bytes on the heap
+       pop rax
+       add rax,qword [p_here_DFA]
+       mov qword [p_here_DFA],rax
+       next
+       
+       ;; DOES> ( -- )
+       ;; Change DOES offset of latest compilation word to current
+       ;; compilation address.
+       ;; LATEST @ TFA>DOES HERE @ OVER - SWAP !
+       WORD p_does,'DOES>',fasm
+       mov rax,qword [p_wordlist_DFA] 
+       mov rax,[rax]           ; last word of current wordlist
+       add rax,8
+       ;add rax,byte [rax]
+       add rax,1
+       mov rbx,[p_here_DFA]
+       mov qword [rax],rbx
+       mov qword [rax+8],dodoes
+       next
+       
+       WORD p_literal,'LIT',IMMEDIATE
+       dq p_create
+       dq p_does
+       dq p_get
+       dq p_exit
+       
+       WORD p_execute,'EXECUTE'
+
index ba41cbe39021df277ccc6e3343ece77f2cb8e188..16dc7d6ddba4d651702868d72ea62f264464c286 100644 (file)
@@ -119,6 +119,7 @@ include 'memory.asm'
 include 'stack.asm'
 include 'math.asm'
 include 'stdio.asm'
 include 'stack.asm'
 include 'math.asm'
 include 'stdio.asm'
+include 'compile.asm'
 
        WORD p_program_version,'PROGRAM_VERSION',dostring
        STRING 'RRQ Forth version 0.1 - 2021-05-13',10
 
        WORD p_program_version,'PROGRAM_VERSION',dostring
        STRING 'RRQ Forth version 0.1 - 2021-05-13',10
@@ -142,12 +143,17 @@ main:
        pop qword [p_stdin_DFA]
 
        ;; Initial blurb
        pop qword [p_stdin_DFA]
 
        ;; Initial blurb
-       push qword 1                    ; stdout
-       DOFORTH p_program_version       ; version string => ( s n )
-       DOFORTH sys_write               ; printout
-       pop rax                         ; ignore errors
-
-       DOFORTH p_words
+       FORTH
+       dq p_program_version
+       dq p_tell
+       dq p_stdin
+       dq p_read_word
+       dq p_tell
+       dq p_nl
+       dq p_emit
+       ENDFORTH
+       
+       ;; DOFORTH p_words
        
        push 0
        DOFORTH sys_exit
        
        push 0
        DOFORTH sys_exit
@@ -160,3 +166,6 @@ include 'syscalls.asm'
 last_word:
        
 heap_start:
 last_word:
        
 heap_start:
+       rb 1048576              ; +1 Mb heap
+       rb 1048576              ; +1 Mb heap
+       rb 1048576              ; +1 Mb heap