2022-04-17 12:28:48 +02:00
|
|
|
## COMMENTS ##
|
|
|
|
# one-line comments (from prefix to EOL)
|
2022-09-01 18:31:39 +02:00
|
|
|
mov $1 42 # comment
|
|
|
|
mov $1 42 // comment
|
2022-04-17 12:28:48 +02:00
|
|
|
|
|
|
|
# block comments
|
|
|
|
/*
|
|
|
|
Block comment
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Also a block comment */
|
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
mov /* Inline block comment */ $1 42
|
2022-04-17 12:28:48 +02:00
|
|
|
|
|
|
|
|
2022-09-08 13:36:00 +02:00
|
|
|
## DELIMITERS ##
|
|
|
|
# `;` acts like a fake newline
|
|
|
|
mov $1 42; typ $1; echo $1
|
|
|
|
|
|
|
|
|
2022-04-17 13:08:54 +02:00
|
|
|
## ESCAPE SEQUENCES AND INTEGER PREFIXES ##
|
2022-09-01 18:53:14 +02:00
|
|
|
# quote escaping
|
|
|
|
"Here comes a quote: \"Lorem ipsum\". This had to be escaped!"
|
|
|
|
"Here comes another quote: 'Lorem ipsum'. This didn't require escaping!"
|
|
|
|
|
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
|
2022-09-01 18:09:18 +02:00
|
|
|
move|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
|
|
|
|
|
2022-09-01 18:11:41 +02:00
|
|
|
# cast $1 to type-string stored in $2 / to int
|
2022-04-17 12:34:12 +02:00
|
|
|
cst|cast $1 $2
|
2022-09-01 18:13:36 +02:00
|
|
|
cst|cast $1 "int"
|
2022-04-17 12:34:12 +02:00
|
|
|
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 ##
|
2022-09-03 20:27:44 +02:00
|
|
|
# only execute next line if <cond> is true
|
|
|
|
if|ifl <cond>
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-09-03 18:39:59 +02:00
|
|
|
# value to bool
|
|
|
|
$1 # same as `$1 == true`
|
|
|
|
!$1 # same as `$1 != true`
|
|
|
|
|
2022-09-08 13:50:37 +02:00
|
|
|
# strongly typed compare
|
2022-09-03 18:39:59 +02:00
|
|
|
$1 == $2
|
|
|
|
$1 != $2
|
|
|
|
|
|
|
|
# numerical / alphabetical compare
|
|
|
|
$1 < $2
|
|
|
|
$1 <= $2
|
|
|
|
$1 > $2
|
|
|
|
$1 >= $2
|
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-09-06 20:21:04 +02:00
|
|
|
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 ##
|
2022-09-01 18:16:10 +02:00
|
|
|
# - if a list index is undefined, its value will be `null`
|
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# set $1 to empty list
|
|
|
|
set $1 []
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# set $1 to list
|
|
|
|
set $1 [1, 5, 2345]
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2021-06-03 22:41:41 +02:00
|
|
|
# print 2nd element of 4th list
|
2022-09-01 18:31:39 +02:00
|
|
|
echo $1[3][1]
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-09-01 18:18:04 +02:00
|
|
|
# remove 2nd element (maintaining key association)
|
2022-09-01 18:31:39 +02:00
|
|
|
set $1[1] null
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# push element
|
2022-09-01 18:31:39 +02:00
|
|
|
set $1[] "blabla" | add $1 "blabla"
|
2021-06-03 20:31:48 +02:00
|
|
|
|
|
|
|
# print last element
|
2022-09-01 18:31:39 +02:00
|
|
|
echo $1[-1]
|
2021-06-03 20:31:48 +02:00
|
|
|
|
2022-09-01 18:18:04 +02:00
|
|
|
# remove (and get) last element (keys will be re-ordered)
|
2022-09-01 18:31:39 +02:00
|
|
|
pop $1[-1] | pop $1[-1] $2
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get length of list $2 => $1
|
|
|
|
len $1 $2
|
2021-06-03 22:41:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## EXTERNAL VALUES ##
|
2022-09-01 18:31:39 +02:00
|
|
|
# get unix time => $1
|
|
|
|
time $1
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get formated time => $1
|
|
|
|
time $1 "YYYY-MM-DD"
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get random integer between 0 and 3 => $1
|
|
|
|
rnd|rand|random $1 3
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get random integer between 5 and 13 => $1
|
|
|
|
rnd|rand|random $1 5 13
|
2021-06-03 22:41:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## STRING MANIPULATION ##
|
2022-09-01 18:26:15 +02:00
|
|
|
# get number $1 as string
|
|
|
|
cast $1 str
|
|
|
|
|
|
|
|
# get utf-8 char with id $1 => $1
|
|
|
|
chr $1
|
2022-04-17 13:08:54 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get length of string $2 => $1
|
|
|
|
len $1 $2
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# concat strings $1 + $2 => $1
|
|
|
|
add $1 $2 ...
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get substr 2(-5) of string $1 => $1
|
|
|
|
slice|substr $1 2 5 | slice|substr $1 2
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# repeat string $1 3 times => $1
|
|
|
|
mul $1 3
|
2021-06-03 22:41:41 +02:00
|
|
|
|
2022-09-01 18:31:39 +02:00
|
|
|
# get position of first occourance of $3 (=needle) in $2 (=haystack) => $1
|
|
|
|
# pos >= 0 if found; pos = false if nothing found
|
|
|
|
pos|strpos $1 $2 $3
|