update examples in readme

This commit is contained in:
zongor 2025-10-25 12:15:18 -07:00
parent 5d8688446e
commit 421cceba23
1 changed files with 24 additions and 20 deletions

View File

@ -59,21 +59,19 @@ The Undâr compiler will be written in Sċieppan, as well as core VM tests.
((code ((code
(label main (label main
(load-immediate $1 &hello-str) ; load hello string ptr (load-immediate $1 &hello-str) ; load hello string ptr
(push $1) (call &pln ($1) nil)
(call &pln)
(halt)) ; done (halt)) ; done
(label pln (label pln
(load-immediate $0 &terminal-namespace) ; get terminal device (load-immediate $1 &terminal-namespace) ; get terminal device
(load-immediate $11 0) (load-immediate $11 0)
(syscall OPEN $0 $0 $11) (syscall OPEN $1 $1 $11)
(load-immediate $3 &new-line) (load-immediate $3 &new-line)
(pop $1) (load-offset-32 $7 $1 4) ; load handle
(load-offset-32 $7 $0 4) ; load handle (string-length $2 $0)
(string-length $2 $1) (syscall WRITE $7 $0 $2)
(syscall WRITE $7 $1 $2)
(string-length $4 $3) (string-length $4 $3)
(syscall WRITE $7 $3 $4) (syscall WRITE $7 $3 $4)
(return))) (return nil)))
(data (data
(label terminal-namespace "/dev/term/0") (label terminal-namespace "/dev/term/0")
(label new-line "\n") (label new-line "\n")
@ -95,26 +93,32 @@ heap allocations using the internal malloc opcode push pointers within this fram
#+BEGIN_SRC lisp #+BEGIN_SRC lisp
((code ((code
(label main (label main
(load-immediate $1 &hello-str) ; load hello string ptr
(push $1)
(call &pln)
(halt)) ; done
(label pln
(load-immediate $0 &terminal-namespace) ; get terminal device (load-immediate $0 &terminal-namespace) ; get terminal device
(load-immediate $11 0) (load-immediate $11 0)
(syscall OPEN $0 $0 $11) (syscall OPEN $0 $0 $11)
(load-immediate $1 &help) ; print help message
(call &pln ($0 $1) nil)
(load-immediate $1 32) ; read in a string of max 32 char length
(malloc $4 $1) ; allocate memory for the string
(load-offset-32 $7 $0 4) ; load handle
(syscall READ $7 $2 $1 $4) ; read the string
(call &pln ($0 $4) nil) ; print the string
(halt))
(label pln
(load-immediate $3 &new-line) (load-immediate $3 &new-line)
(pop $1)
(load-offset-32 $7 $0 4) ; load handle (load-offset-32 $7 $0 4) ; load handle
(string-length $2 $1) (string-length $2 $1)
(syscall WRITE $7 $1 $2) (syscall WRITE $7 $1 $2)
(string-length $4 $3) (string-length $4 $3)
(syscall WRITE $7 $3 $4) (syscall WRITE $7 $3 $4)
(return))) (return nil)))
(data (data
(label terminal-namespace "/dev/term/0") (label terminal-namespace "/dev/term/0")
(label new-line "\n") (label help "Enter a string: ")
(label hello-str "nuqneH 'u'?"))) (label new-line "\n")))
#+END_SRC #+END_SRC
values passed to functions must be explicitly returned to propagate. heap values are copy on write, so if a value is modified in a child function it will change the parents value, unless the size of the structure changes then it will copy the parents value and append it to its own frame with the modification. this allows for the low resource usage of a C but the convenience of a Java/Go without the garbage collection. values passed to functions must be explicitly returned to propagate. heap values are copy on write, so if a value is modified in a child function it will change the parents value, unless the size of the structure changes then it will copy the parents value and append it to its own frame with the modification. this allows for the low resource usage of a C but the convenience of a Java/Go without the garbage collection.