Fix documentation
This commit is contained in:
parent
0d30ea292a
commit
edb10db545
70
README.org
70
README.org
|
|
@ -55,32 +55,33 @@ You can view some examples in the =.ul.ir= files in =/test=
|
|||
**Sample Program: =hello.ul.ir=**
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
global str terminal_namespace = "/dev/term/0"
|
||||
global str new_line = "\n"
|
||||
global str message = "nuqneH 'u'?"
|
||||
global str terminal_namespace = "/dev/term/0";
|
||||
global str new_line = "\n";
|
||||
global str hello = "nuqneH 'u'?";
|
||||
|
||||
function main ()
|
||||
str hello $0;
|
||||
str msg $0;
|
||||
|
||||
load_immediate message -> hello;
|
||||
call pln hello -> void;
|
||||
load_address hello -> msg;
|
||||
call pln (msg);
|
||||
exit 0;
|
||||
|
||||
function pln (str message $0)
|
||||
str ts $1;
|
||||
int mode $5;
|
||||
plex term $1;
|
||||
int msg_length $2;
|
||||
str nl $3;
|
||||
int nl_length $4;
|
||||
int mode $5;
|
||||
str term_ns $6;
|
||||
|
||||
load_immediate terminal_namespace -> ts;
|
||||
load_immediate 0 -> mode;
|
||||
syscall OPEN ts mode -> ts;
|
||||
strlen message -> msg_length;
|
||||
syscall WRITE ts message msg_length;
|
||||
load_immediate new_line -> nl;
|
||||
strlen nl -> nl_length;
|
||||
syscall WRITE ts nl nl_length;
|
||||
load_address terminal_namespace -> term_ns;
|
||||
syscall OPEN term_ns mode term;
|
||||
string_length message -> msg_length;
|
||||
syscall WRITE term message msg_length;
|
||||
load_address new_line -> nl;
|
||||
string_length nl -> nl_length;
|
||||
syscall WRITE term nl nl_length;
|
||||
return;
|
||||
#+END_SRC
|
||||
|
||||
|
|
@ -102,42 +103,43 @@ global str prompt = "Enter a string:";
|
|||
global str new_line = "\n";
|
||||
|
||||
function main ()
|
||||
int mode $11;
|
||||
str term $10;
|
||||
int in_mode $11;
|
||||
str in_term $10;
|
||||
|
||||
load_immediate terminal_namespace -> term;
|
||||
load_immediate 0 -> mode;
|
||||
syscall OPEN term mode -> term; // Terminal term = open("/dev/term/0", 0);
|
||||
load_address terminal_namespace -> in_term;
|
||||
load_immediate 0 -> in_mode;
|
||||
syscall OPEN in_term in_mode in_term; // Terminal term = open("/dev/term/0", 0);
|
||||
|
||||
load_immediate prompt -> $7;
|
||||
load_address prompt -> $7;
|
||||
string_length $7 -> $8;
|
||||
syscall WRITE term $7 $8; // print prompt
|
||||
syscall WRITE in_term $7 $8; // print prompt
|
||||
|
||||
str user_string $9;
|
||||
load_immediate 32 -> $8;
|
||||
malloc $8 -> user_string;
|
||||
syscall READ term user_string $8; // read in max 32 byte string
|
||||
syscall READ in_term user_string $8; // read in max 32 byte string
|
||||
|
||||
call pln user_string -> void;
|
||||
call pln (user_string);
|
||||
exit 0;
|
||||
|
||||
function pln (str message $0)
|
||||
str ts $1;
|
||||
int mode $5;
|
||||
plex term $1;
|
||||
int msg_length $2;
|
||||
str nl $3;
|
||||
int nl_length $4;
|
||||
int mode $5;
|
||||
str term_ns $6;
|
||||
|
||||
load_immediate terminal_namespace -> ts;
|
||||
load_immediate 0 -> mode;
|
||||
syscall OPEN ts mode -> ts;
|
||||
strlen message -> msg_length;
|
||||
syscall WRITE ts message msg_length;
|
||||
load_immediate new_line -> nl;
|
||||
strlen nl -> nl_length;
|
||||
syscall WRITE ts nl nl_length;
|
||||
load_address terminal_namespace -> term_ns;
|
||||
syscall OPEN term_ns mode term;
|
||||
string_length message -> msg_length;
|
||||
syscall WRITE term message msg_length;
|
||||
load_address new_line -> nl;
|
||||
string_length nl -> nl_length;
|
||||
syscall WRITE term nl nl_length;
|
||||
return;
|
||||
|
||||
|
||||
#+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