update examples in readme
This commit is contained in:
parent
5d8688446e
commit
421cceba23
44
README.org
44
README.org
|
|
@ -59,21 +59,19 @@ The Undâr compiler will be written in Sċieppan, as well as core VM tests.
|
|||
((code
|
||||
(label main
|
||||
(load-immediate $1 &hello-str) ; load hello string ptr
|
||||
(push $1)
|
||||
(call &pln)
|
||||
(call &pln ($1) nil)
|
||||
(halt)) ; done
|
||||
(label pln
|
||||
(load-immediate $0 &terminal-namespace) ; get terminal device
|
||||
(load-immediate $1 &terminal-namespace) ; get terminal device
|
||||
(load-immediate $11 0)
|
||||
(syscall OPEN $0 $0 $11)
|
||||
(syscall OPEN $1 $1 $11)
|
||||
(load-immediate $3 &new-line)
|
||||
(pop $1)
|
||||
(load-offset-32 $7 $0 4) ; load handle
|
||||
(string-length $2 $1)
|
||||
(syscall WRITE $7 $1 $2)
|
||||
(load-offset-32 $7 $1 4) ; load handle
|
||||
(string-length $2 $0)
|
||||
(syscall WRITE $7 $0 $2)
|
||||
(string-length $4 $3)
|
||||
(syscall WRITE $7 $3 $4)
|
||||
(return)))
|
||||
(return nil)))
|
||||
(data
|
||||
(label terminal-namespace "/dev/term/0")
|
||||
(label new-line "\n")
|
||||
|
|
@ -94,27 +92,33 @@ heap allocations using the internal malloc opcode push pointers within this fram
|
|||
|
||||
#+BEGIN_SRC lisp
|
||||
((code
|
||||
(label main
|
||||
(load-immediate $1 &hello-str) ; load hello string ptr
|
||||
(push $1)
|
||||
(call &pln)
|
||||
(halt)) ; done
|
||||
(label pln
|
||||
(label main
|
||||
(load-immediate $0 &terminal-namespace) ; get terminal device
|
||||
(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)
|
||||
(pop $1)
|
||||
(load-offset-32 $7 $0 4) ; load handle
|
||||
(string-length $2 $1)
|
||||
(syscall WRITE $7 $1 $2)
|
||||
(string-length $4 $3)
|
||||
(syscall WRITE $7 $3 $4)
|
||||
(return)))
|
||||
(return nil)))
|
||||
(data
|
||||
(label terminal-namespace "/dev/term/0")
|
||||
(label new-line "\n")
|
||||
(label hello-str "nuqneH 'u'?")))
|
||||
(label help "Enter a string: ")
|
||||
(label new-line "\n")))
|
||||
#+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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue