add examples - initial examples
This commit is contained in:
parent
b4df642d72
commit
004f916aa3
26
examples/do.slc
Normal file
26
examples/do.slc
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Parses this:
|
||||
|
||||
do {
|
||||
...code...
|
||||
} (...cond...)
|
||||
|
||||
Into this:
|
||||
|
||||
...code...
|
||||
while(...cond...) {
|
||||
...code...
|
||||
}
|
||||
*/
|
||||
|
||||
// -> [bytecodes]
|
||||
::builtin do @body
|
||||
"" parseblock {} // "" means no entry into the symbol table (unnamed function) - equals to 0
|
||||
do@body(.) // (.) does not removes - only (_) no need for gencode because
|
||||
gen(while) // address top bit 1 when builtin from C
|
||||
genopen() // equal to gencode(1)
|
||||
"" parseblock ()
|
||||
genclose()
|
||||
genopen{}
|
||||
do@body
|
||||
genclose{}
|
||||
4
examples/dup.slc
Normal file
4
examples/dup.slc
Normal file
@ -0,0 +1,4 @@
|
||||
:builtin dup @t
|
||||
dup@t(_)
|
||||
dup@t
|
||||
dup@t
|
||||
13
examples/for.slc
Normal file
13
examples/for.slc
Normal file
@ -0,0 +1,13 @@
|
||||
::builtin for
|
||||
parseword drop // TODO: error handling
|
||||
"" ";" parse
|
||||
gen(while)
|
||||
genopen()
|
||||
"" ";" parse
|
||||
genclose()
|
||||
genopen{}
|
||||
"" ")" parse()
|
||||
"" parseblock {}
|
||||
swap
|
||||
genclose{}
|
||||
;
|
||||
8
examples/gen.slc
Normal file
8
examples/gen.slc
Normal file
@ -0,0 +1,8 @@
|
||||
: gen
|
||||
if(1 !=) {
|
||||
dup 1 -
|
||||
gen
|
||||
}
|
||||
;
|
||||
|
||||
5 gen
|
||||
1
examples/gen_str
Normal file
1
examples/gen_str
Normal file
@ -0,0 +1 @@
|
||||
"word_name" gen_str // -> session storage-be
|
||||
12
examples/if.slc
Normal file
12
examples/if.slc
Normal file
@ -0,0 +1,12 @@
|
||||
// prefixed builtins with '#'
|
||||
// when writing a compiler - like a c-like language
|
||||
|
||||
:if
|
||||
()
|
||||
#asm(jz else$)
|
||||
{}
|
||||
#asm(jmp ifend$)
|
||||
#asm(else$:)
|
||||
[]
|
||||
#asm(ifend$:)
|
||||
;
|
||||
23
examples/strings.slc
Normal file
23
examples/strings.slc
Normal file
@ -0,0 +1,23 @@
|
||||
"word_name" gen_str // -> session storage-be - amúgy ez utf8
|
||||
|
||||
"abc" "df" strcon
|
||||
/*
|
||||
abc0
|
||||
0004
|
||||
df00
|
||||
0002
|
||||
*/
|
||||
|
||||
// TODO: implement as C builtin instead.. but doable this way
|
||||
:builtin strcon @off1 @mod1 @
|
||||
dup
|
||||
7 + 4 /
|
||||
strcon@off1(_) // (_) azt jelenti, hogy pop és változóba tesz, (.) means peek and put in var
|
||||
dup
|
||||
4 %
|
||||
strcon@mod1(_)
|
||||
strcon@off1
|
||||
popat
|
||||
|
||||
+
|
||||
;
|
||||
7
examples/swap_builtin.slc
Normal file
7
examples/swap_builtin.slc
Normal file
@ -0,0 +1,7 @@
|
||||
// a b -> b a
|
||||
:builtin swap @tmp1 @tmp2
|
||||
swap@tmp1(_)
|
||||
swap@tmp2(_)
|
||||
swap@tmp1
|
||||
swap@tmp2
|
||||
;
|
||||
2
examples/variable.slc
Normal file
2
examples/variable.slc
Normal file
@ -0,0 +1,2 @@
|
||||
: player_data @xpos @ypos @health
|
||||
;
|
||||
Loading…
x
Reference in New Issue
Block a user