Added list->string primitive to stage2 lisp

This commit is contained in:
Jeremiah Orians 2017-08-18 11:15:59 -04:00
parent f835312b3c
commit 1926a9d6b7
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
4 changed files with 81 additions and 2 deletions

View File

@ -41,6 +41,7 @@ Added string->list primitive to stage2 lisp
Added char? primitive to stage2 lisp Added char? primitive to stage2 lisp
Added string? primitive to stage2 lisp Added string? primitive to stage2 lisp
Added make_string internal function to stage2 lisp Added make_string internal function to stage2 lisp
Added list->string primitive to stage2 lisp
** Changed ** Changed
Minor refactor of stage3 FORTH by reepa Minor refactor of stage3 FORTH by reepa

View File

@ -152,7 +152,7 @@ Then we use our M0 Line macro assembler to convert our assembly into hex2 format
Then we need to assemble that hex into our desired program: Then we need to assemble that hex into our desired program:
./bin/vm --rom roms/stage1_assembler-2 --tape_01 temp2 --tape_02 roms/lisp --memory 48K ./bin/vm --rom roms/stage1_assembler-2 --tape_01 temp2 --tape_02 roms/lisp --memory 48K
roms/lisp should have the sha256sum of 15559882382681aaf9b8b75fa3b1fac2ba4bc30cdf990aefd04f5d59319333af roms/lisp should have the sha256sum of 014cfa78c887d844b3855c6d12b50e170d57214f7b8f04853aec544ebd6ba5cb
Our lisp will first attempt to evaluate any code in tape_01 and then evaluate any code that the user types in. Our lisp will first attempt to evaluate any code in tape_01 and then evaluate any code that the user types in.
It is recommended to run with no less than 4MB of Memory It is recommended to run with no less than 4MB of Memory

View File

@ -2253,6 +2253,77 @@
RET R15 RET R15
;; list_to_string
;; Recieves an index in R0, a String pointer in R1
;; And a list of arguments in R2
;; Alters only R0
:list_to_string
CMPSKIPI.NE R2 $NIL ; If NIL Expression
RET R15 ; Just get the Hell out
PUSHR R1 R15 ; Protect R1
PUSHR R2 R15 ; Protect R2
PUSHR R3 R15 ; Protect R3
PUSHR R4 R15 ; Protect R4
:list_to_string_0
CMPSKIPI.NE R2 $NIL ; If NIL Expression
JUMP @list_to_string_done ; We are done
LOAD32 R4 R2 4 ; Get ARGS->CAR
LOAD32 R3 R4 0 ; Get ARGS->CAR->TYPE
CMPSKIPI.NE R3 128 ; If Type CHAR
CALLI R15 @list_to_string_CHAR ; Process
;; Guess CONS
SWAP R2 R4 ; Put i->CAR in i's spot
CMPSKIPI.NE R3 16 ; If Type CONS
CALLI R15 @list_to_string ; Recurse
SWAP R2 R4 ; Undo the Guess
;; Everything else just iterate
LOAD32 R2 R2 8 ; i = i->CDR
JUMP @list_to_string_0 ; Lets go again
:list_to_string_CHAR
LOAD32 R3 R4 4 ; Get ARGS->CAR->VALUE
STOREX8 R3 R0 R1 ; STRING[INDEX] = i->CAR->VALUE
ADDUI R0 R0 1 ; INDEX = INDEX + 1
RET R15 ; Get back in there
:list_to_string_done
POPR R4 R15 ; Restore R4
POPR R3 R15 ; Restore R3
POPR R2 R15 ; Restore R2
POPR R1 R15 ; Restore R1
RET R15
;; prim_list_to_string
;; Recieves a list in R0
;; Returns a String CELL in R0
:prim_list_to_string_String
"list->string"
:prim_list_to_string
CMPSKIPI.NE R0 $NIL ; If NIL Expression
RET R15 ; Just get the Hell out
PUSHR R1 R15 ; Protect R1
PUSHR R2 R15 ; Protect R2
MOVE R2 R0 ; Put Args in correct location and Zero R0
CALLI R15 @malloc ; Get where space is free
MOVE R1 R0 ; Put String pointer in correct location and Zero R0
CALLI R15 @list_to_string ; Call backing function
ADDUI R0 R0 1 ; NULL Terminate string
CALLI R15 @malloc ; Correct malloc
CALLI R15 @make_string ; Use pointer to make our string CELL
POPR R2 R15 ; Restore R2
POPR R1 R15 ; Restore R1
RET R15
;; prim_halt ;; prim_halt
;; Simply HALTS ;; Simply HALTS
:prim_halt_String :prim_halt_String
@ -2682,6 +2753,13 @@
CALLI R15 @make_sym ; MAKE_SYM CALLI R15 @make_sym ; MAKE_SYM
CALLI R15 @spinup ; SPINUP CALLI R15 @spinup ; SPINUP
LOADUI R0 $prim_list_to_string ; Using PRIM_LIST_TO_STRING
CALLI R15 @make_prim ; MAKE_PRIM
MOVE R1 R0 ; Put Primitive in correct location
LOADUI R0 $prim_list_to_string_String ; Using PRIM_LIST_TO_STRING_STRING
CALLI R15 @make_sym ; MAKE_SYM
CALLI R15 @spinup ; SPINUP
LOADUI R0 $prim_halt ; Using PRIM_HALT LOADUI R0 $prim_halt ; Using PRIM_HALT
CALLI R15 @make_prim ; MAKE_PRIM CALLI R15 @make_prim ; MAKE_PRIM
MOVE R1 R0 ; Put Primitive in correct location MOVE R1 R0 ; Put Primitive in correct location

View File

@ -1,7 +1,7 @@
8f465d3ec1cba00a7d024a1964e74bb6d241f86a73c77d95d8ceb10d09c8f7b9 roms/CAT 8f465d3ec1cba00a7d024a1964e74bb6d241f86a73c77d95d8ceb10d09c8f7b9 roms/CAT
59f0502748af32e3096e026a95e77216179cccfe803a05803317414643e2fcec roms/DEHEX 59f0502748af32e3096e026a95e77216179cccfe803a05803317414643e2fcec roms/DEHEX
d7967248be71937d4fa1f38319a5a8473a842b1f6806b977e5fb184565bde0a4 roms/forth d7967248be71937d4fa1f38319a5a8473a842b1f6806b977e5fb184565bde0a4 roms/forth
15559882382681aaf9b8b75fa3b1fac2ba4bc30cdf990aefd04f5d59319333af roms/lisp 014cfa78c887d844b3855c6d12b50e170d57214f7b8f04853aec544ebd6ba5cb roms/lisp
2b9727381aec15a504c0898189fbc2344209d8e04451e3fa5d743e08e38f64cf roms/M0 2b9727381aec15a504c0898189fbc2344209d8e04451e3fa5d743e08e38f64cf roms/M0
24a4d74eb2eb7a82e68335643855658b27b5a6c3b13db473539f3e08d6f26ceb roms/SET 24a4d74eb2eb7a82e68335643855658b27b5a6c3b13db473539f3e08d6f26ceb roms/SET
0a427b14020354d1c785f5f900677e0059fce8f8d4456e9c19e5528cb17101eb roms/stage0_monitor 0a427b14020354d1c785f5f900677e0059fce8f8d4456e9c19e5528cb17101eb roms/stage0_monitor