2022-04-17 12:28:48 +02:00
|
|
|
## COMMENTS ##
|
|
|
|
# one-line comments (from prefix to EOL)
|
|
|
|
mov $a 42 # comment
|
|
|
|
mov $a 42 // comment
|
|
|
|
mov $a 42 ; comment
|
|
|
|
|
|
|
|
# block comments
|
|
|
|
/*
|
|
|
|
Block comment
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Also a block comment */
|
|
|
|
|
|
|
|
mov /* Inline block comment */ $a 42
|
|
|
|
|
|
|
|
|
2022-04-17 13:08:54 +02:00
|
|
|
## ESCAPE SEQUENCES AND INTEGER PREFIXES ##
|
2022-08-13 14:10:43 +02:00
|
|
|
# in strings (only those in double quotes)
|
2022-04-17 13:08:54 +02:00
|
|
|
"\n" # newline
|
|
|
|
"\t" # tab
|
|
|
|
"\u2764\ufe0f" # utf-8 for ❤️
|
|
|
|
...
|
|
|
|
|
|
|
|
# integers
|
|
|
|
0x10 # hexadecimal: 16
|
|
|
|
0o10 # octal: 8
|
|
|
|
0b0100 # binary: 4
|
|
|
|
|
|
|
|
|
2022-04-17 12:28:48 +02:00
|
|
|
|
2021-06-03 20:31:48 +02:00
|
|
|
## VARIABLES ##
|
|
|
|
# $2 => $1
|
2021-06-03 22:41:41 +02:00
|
|
|
mov|set $1 $2
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# load $1 from root scope into current scope
|
2021-06-03 22:41:41 +02:00
|
|
|
glob|global|pub|public $1
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-04-17 12:34:12 +02:00
|
|
|
# vartypes (constants containing string of vartype name)
|
2022-04-17 13:10:01 +02:00
|
|
|
null # null
|
|
|
|
true|false # bool
|
2021-06-03 22:41:41 +02:00
|
|
|
eg. -44 27 287634 # int
|
|
|
|
eg. 4.0 -3.0 0.125 # float
|
|
|
|
eg. "bla" 'blub' # str
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-04-17 12:34:12 +02:00
|
|
|
# vartype($1) => $1
|
|
|
|
typ|type $1
|
|
|
|
|
|
|
|
# cast $1 to type $2 / to int
|
|
|
|
cst|cast $1 $2
|
|
|
|
cst|cast $1 int
|
|
|
|
|
2022-05-10 21:38:38 +02:00
|
|
|
# use contents of a var as var-name (todo: is there a more assembly-like way for this?)
|
|
|
|
${$name}
|
2022-04-17 12:34:12 +02:00
|
|
|
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
## MATH ##
|
2021-06-03 22:41:41 +02:00
|
|
|
# $1 + $2 + ... => $1
|
|
|
|
add $1 $2 ...
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# $1 - ($2 + ...) => $1
|
|
|
|
sub $1 $2 ...
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# $1 * $2 * ... => $1
|
|
|
|
mul $1 $2 ...
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# $1 / ($2 * ...) => $1
|
|
|
|
div $1 $2 ...
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# $1 % $2 % ... => $1
|
|
|
|
mod $1 $2 ...
|
|
|
|
|
|
|
|
# $1 ^ $2 ^ ... => $1
|
2021-06-04 12:46:34 +02:00
|
|
|
pow $1 $2 ...
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-07-17 13:17:16 +02:00
|
|
|
# root of $1 (power = $2; if not given: square-root) => $1
|
|
|
|
root $1 $2
|
|
|
|
|
2022-05-16 19:08:52 +02:00
|
|
|
# log of $1 (base = $2; if not given: base = 2) => $1
|
2021-07-17 13:17:16 +02:00
|
|
|
log $1 $2
|
|
|
|
|
|
|
|
# round to the nearest integer (.000 - .499 => round down; .500 - 0.999 => round up) => $1
|
|
|
|
round $1
|
|
|
|
|
|
|
|
# round up to the next integer => $1
|
|
|
|
ceil $1
|
|
|
|
|
|
|
|
# round down to the last integer => $1
|
|
|
|
floor $1
|
|
|
|
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
## CONDITIONS ##
|
|
|
|
# only execute next line if cond is true
|
|
|
|
ifl cond
|
|
|
|
|
|
|
|
# skip next line if cond is true
|
|
|
|
ifn cond
|
|
|
|
|
|
|
|
# cond:
|
2022-04-17 12:28:48 +02:00
|
|
|
x
|
|
|
|
!x
|
|
|
|
x == y
|
|
|
|
x != y
|
|
|
|
x === y
|
|
|
|
x !== y
|
|
|
|
x < y
|
|
|
|
x <= y
|
|
|
|
x > y
|
|
|
|
x >= y
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## JUMPS ##
|
|
|
|
# jump to line 42 (jumping to lines inside of other scopes is not allowed)
|
2021-06-03 22:41:41 +02:00
|
|
|
jmp|jump|goto 42
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# jump to a flag called "flag1" (flags are stored per-scope)
|
2021-06-03 22:41:41 +02:00
|
|
|
jmp|jump|goto "flag1"
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# set flag called "flag1"
|
|
|
|
:flag1 | :flag1: | flag1:
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-17 12:40:10 +02:00
|
|
|
## TEXT IO ##
|
2021-06-03 20:31:48 +02:00
|
|
|
# print "blabliblub"
|
2021-06-03 22:41:41 +02:00
|
|
|
drw|draw|echo "bla" "bli" "blub"
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-04-17 12:40:10 +02:00
|
|
|
# print "blabliblub", await user response (until newline/enter) and return entered line as $1
|
|
|
|
ask $1 "bla" "bli" "blub"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## GRAPHICAL OUTPUT ##
|
2021-06-03 20:31:48 +02:00
|
|
|
# initialize matrix with 16x16
|
2021-06-03 22:41:41 +02:00
|
|
|
pxl|pixel|canv|canvas size 16 16 | pxl|pixel|canv|canvas size 16
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# set output resolution to 256x256
|
2021-06-03 22:41:41 +02:00
|
|
|
pxl|pixel|canv|canvas res 256 256 | pxl|pixel|canv|canvas res 256
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# enable autodraw
|
2021-06-03 22:41:41 +02:00
|
|
|
pxl|pixel|canv|canvas autodraw true
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# set pixel at 2|12 to color #F6F6F6
|
2021-06-03 22:41:41 +02:00
|
|
|
pxl|pixel|canv|canvas set 2 12 "F6"
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# update matrix to screen
|
2021-06-03 22:41:41 +02:00
|
|
|
pxl|pixel|canv|canvas draw
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## FUNCTIONS ##
|
|
|
|
# - functions have their own scopes
|
|
|
|
# - they can call other functions
|
|
|
|
# - their own vars are private
|
|
|
|
# - they can't acces root-scope's vars (except they were made global using `glob`)
|
2022-05-10 21:55:33 +02:00
|
|
|
# - args are copied into local scope
|
|
|
|
# - args with &-prefix modify corresponding var in global scope
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# the function scope "myfunction1" starts here
|
|
|
|
# argument $1 is readonly; $2 is read/write
|
2022-05-10 21:55:33 +02:00
|
|
|
fcn|def myfunction1 $1 &$2
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# current function scope ends here
|
2021-06-03 22:41:41 +02:00
|
|
|
end
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# call a function called "myfunction1"
|
|
|
|
# arg $1 = 42; arg $2 = $test (returned to parent scope)
|
|
|
|
myfunction1 42 $test
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## RETURN, END, ETC. ##
|
2021-06-03 22:41:41 +02:00
|
|
|
# halt the programm
|
|
|
|
halt
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# return from function to parent scope
|
|
|
|
# halt programm in root scope
|
2021-06-03 22:41:41 +02:00
|
|
|
exit|return|end
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## LISTS ##
|
|
|
|
# set $a to empty list
|
|
|
|
set $a []
|
|
|
|
|
|
|
|
# set $a to list
|
|
|
|
set $a [1, 5, 2345]
|
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# print 2nd element of 4th list
|
|
|
|
echo $a[3][1]
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# remove 2nd element
|
|
|
|
set $a[1] null
|
|
|
|
|
|
|
|
# push element
|
2021-06-03 22:41:41 +02:00
|
|
|
set $a[] "blabla" | add $a "blabla"
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# print last element
|
|
|
|
echo $a[-1]
|
|
|
|
|
|
|
|
# remove (and get) last element
|
|
|
|
pop $a[-1] | pop $a[-1] $b
|
2021-06-03 22:41:41 +02:00
|
|
|
|
|
|
|
# get list length
|
|
|
|
len $list $length_num
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## EXTERNAL VALUES ##
|
|
|
|
# get unix time
|
|
|
|
time $time
|
|
|
|
|
|
|
|
# get formated time
|
|
|
|
time $time "YYYY-MM-DD"
|
|
|
|
|
|
|
|
# get random integer between 0 and 3
|
|
|
|
rnd|rand|random $num 3
|
|
|
|
|
|
|
|
# get random integer between 5 and 13
|
|
|
|
rnd|rand|random $num 5 13
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## STRING MANIPULATION ##
|
2022-04-17 13:08:54 +02:00
|
|
|
# get utf-8 char with id $1
|
|
|
|
chr $1 | cast $1 str
|
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# get string lenght
|
|
|
|
len $string $length_num
|
|
|
|
|
|
|
|
# concat strings => $a
|
|
|
|
add $a $b ...
|
|
|
|
|
|
|
|
# get substr 2(-5)
|
|
|
|
slice|substr $string 2 5 | slice|substr $string 2
|
|
|
|
|
|
|
|
# repeat string
|
|
|
|
mul $string 3
|
|
|
|
|
|
|
|
# get position of first occourance of needle in haystack => $pos
|
|
|
|
# $pos >= 0 if found; $pos = false if nothing found
|
|
|
|
pos|strpos $haystack $needle $pos
|