diff --git a/examples/numbers.slc b/examples/numbers.slc new file mode 100644 index 0000000..e9af34b --- /dev/null +++ b/examples/numbers.slc @@ -0,0 +1,42 @@ +// There are no "types", but we have typed operations + +// Immediates are 31 bit, unsigned when we see a number +// This way we can bytecode topmost bit 1n...n a number! +40 +2 ++ +. // 42 + +// If you want to do negative numbers use "neg" +// This is different from ~ which is bitwise negation as this is two's complement +// To create HUGE immediates - like over 31 bit, but smaller than 32.. just use long pls +// I mean.. values can fit to 32 bit properly on calculation +42 +neg +i. // -42; there is also li. + +// You can also do this: +hex(ffffffff) +1 ++ +. // 0 +// Rem.: Yes, the hex word uses two pushes and first creates the 1.....10 part, then 0....01 part and use '|' on them +// but if you are not using the topmost bits, this can be optimized out in the implementation of course too. + +l(3) +l(2) +l+ +l. // 5 - 64bit calculation + +f(3) +f(2.5) +f+ +f. // 5.5 + + +d(3) +d(2.5) +d+ +d. // 5.5 + +// The +- sign does not count, */ are by default unsigned - use i* and i/ for signd imul, idiv. Also there is li* and li/ diff --git a/examples/strings.slc b/examples/strings.slc index 9ec614b..04f339d 100644 --- a/examples/strings.slc +++ b/examples/strings.slc @@ -1,18 +1,44 @@ -"word_name" gen_str // -> session storage-be - amúgy ez utf8 +// Characters -"abc" "df" strcon +char(a) // hex(00 00 00 00 00 00 00 41) - in case of little-endian machines (in memory: 0x4100000000000000) +char(á) // this leads to the utf8 characters - implying source code text is utf8 too as we care nothing for parsing encodings... + +// Strings + +// Strings are stored similarily with the zero-terminator included and stored in 4byte groups of data padded up with zeroes. +// Then to constitute a string, we also push the number of characters - as seen below (including the terminator, for optimizations) + +"one" +/* + 0xone0 + 0x0004 +*/ + +"alma" +/* + 0xalma + 0x0000 + 0x5 +*/" + +// But to not only work on the stack, we can store a string into session storage +"word_name" gen_str // -> session storage + +// Strings have operations on them, prefixed with "str" and they expect a string on stack otherwise you are in trouble. + +"abc" "df" str+ /* abc0 0004 df00 - 0002 + 0003 */ // TODO: implement as C builtin instead.. but doable this way -:builtin strcon @off1 @mod1 @ +:builtin str+ @off1 @mod1 @ dup 7 + 4 / - strcon@off1(_) // (_) azt jelenti, hogy pop és változóba tesz, (.) means peek and put in var + strcon@off1(_) // (_) means to pop and put to variable while, (.) means peek and put in var dup 4 % strcon@mod1(_)