Added string->list to stage2 lisp

This commit is contained in:
Jeremiah Orians 2017-07-30 20:38:56 -04:00
parent 7619d6c779
commit ef68ad2d3b
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
4 changed files with 81 additions and 2 deletions

View File

@ -37,6 +37,7 @@ Improved ISA Notes about M0 and hex2 to help bootstrappers
Added rain1's new user forth starting script, which is not actually required for bootstrapping but rather convenience
Added Most primitive raw string support to stage2 lisp
Added integer->char and char->integer to stage2 lisp
Added string->list primitive to stage2 lisp
** Changed
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:
./bin/vm --rom roms/stage1_assembler-2 --tape_01 temp2 --tape_02 roms/lisp --memory 48K
roms/lisp should have the sha256sum of 12da90f95363e93769c5be2034845eb34db56bc92d6726f19cc0953ecbb5fa34
roms/lisp should have the sha256sum of a4f2c8e694da42ce588d2cdc64b7551ceecb18870ae365621631fb0ead6c9769
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

View File

@ -2184,6 +2184,63 @@
RET R15
;; string_to_list
;; Recieves a pointer to string in R0
;; Returns a list of chars
:string_to_list
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 R1 R0 ; Put string safely out of the way
LOAD8 R0 R1 0 ; Get string[0]
JUMP.Z R0 @string_to_list_null
CALLI R15 @make_char ; Make seperate CHAR
SWAP R0 R1 ; Protect RESULT
ADDUI R0 R0 1 ; Increment to next iteration
CALLI R15 @string_to_list ; Recurse down STRING
SWAP R0 R1 ; Put RESULT and TAIL in right spot
CALLI R15 @make_cons ; Combine into a Cons
JUMP @string_to_list_done ; And simply return result
:string_to_list_null
LOADUI R0 $NIL ; Nil terminate list
:string_to_list_done
POPR R2 R15 ; Restore R2
POPR R1 R15 ; Restore R1
RET R15
;; prim_string_to_list
;; Recieves a pointer to a CONS whose CAR should be a STRING
;; Returns a list of CHARs in R0
:prim_string_to_list_String
"string->list"
:prim_string_to_list
CMPSKIPI.NE R0 $NIL ; If NIL Expression
RET R15 ; Just get the Hell out
PUSHR R1 R15 ; Protect R1
LOAD32 R0 R0 4 ; Get ARGS->CAR
LOAD32 R1 R0 0 ; Get ARGS->CAR->TYPE
CMPSKIPI.E R1 256 ; If Not Type STRING
JUMP @prim_string_to_list_fail
LOAD32 R0 R0 4 ; Get ARGS->CAR->STRING
CALLI R15 @string_to_list ; Convert to List
JUMP @prim_string_to_list_done
:prim_string_to_list_fail
LOADUI R0 $NIL ; Nil terminate list
:prim_string_to_list_done
POPR R1 R15 ; Restore R1
RET R15
;; prim_halt
;; Simply HALTS
:prim_halt_String
@ -2599,6 +2656,13 @@
CALLI R15 @make_sym ; MAKE_SYM
CALLI R15 @spinup ; SPINUP
LOADUI R0 $prim_string_to_list ; Using PRIM_STRING_TO_LIST
CALLI R15 @make_prim ; MAKE_PRIM
MOVE R1 R0 ; Put Primitive in correct location
LOADUI R0 $prim_string_to_list_String ; Using PRIM_STRING_TO_LIST_STRING
CALLI R15 @make_sym ; MAKE_SYM
CALLI R15 @spinup ; SPINUP
LOADUI R0 $prim_halt ; Using PRIM_HALT
CALLI R15 @make_prim ; MAKE_PRIM
MOVE R1 R0 ; Put Primitive in correct location
@ -3073,6 +3137,20 @@
RET R15
;; make_char
;; Recieves a CHAR in R0
;; Returns a CELL in R0
:make_char
PUSHR R1 R15 ; Protect R1
MOVE R1 R0 ; Protect Integer
CALLI R15 @pop_cons ; Get a CELL
STORE32 R1 R0 4 ; Set C->CAR
LOADUI R1 128 ; Using CHAR
STORE32 R1 R0 0 ; Set C->TYPE
POPR R1 R15 ; Restore R1
RET R15
;; make_sym
;; Recieves a string pointer in R0
;; Returns a Cell in R0

View File

@ -1,7 +1,7 @@
8f465d3ec1cba00a7d024a1964e74bb6d241f86a73c77d95d8ceb10d09c8f7b9 roms/CAT
59f0502748af32e3096e026a95e77216179cccfe803a05803317414643e2fcec roms/DEHEX
d7967248be71937d4fa1f38319a5a8473a842b1f6806b977e5fb184565bde0a4 roms/forth
12da90f95363e93769c5be2034845eb34db56bc92d6726f19cc0953ecbb5fa34 roms/lisp
a4f2c8e694da42ce588d2cdc64b7551ceecb18870ae365621631fb0ead6c9769 roms/lisp
2b9727381aec15a504c0898189fbc2344209d8e04451e3fa5d743e08e38f64cf roms/M0
24a4d74eb2eb7a82e68335643855658b27b5a6c3b13db473539f3e08d6f26ceb roms/SET
0a427b14020354d1c785f5f900677e0059fce8f8d4456e9c19e5528cb17101eb roms/stage0_monitor