2022-02-08 20:23:05 +01:00
|
|
|
native alen
|
|
|
|
native aget
|
|
|
|
native aput
|
|
|
|
native anew
|
|
|
|
native _array
|
2022-02-05 21:20:51 +01:00
|
|
|
func __array {
|
|
|
|
"NotImplemented" "Not implemented" throw
|
|
|
|
}
|
|
|
|
|
2022-02-08 20:23:05 +01:00
|
|
|
native _char
|
|
|
|
native _int
|
|
|
|
native _file
|
|
|
|
native _float
|
|
|
|
native _long
|
|
|
|
native _double
|
2022-02-05 21:20:51 +01:00
|
|
|
|
|
|
|
func __char {
|
|
|
|
_char
|
|
|
|
}
|
|
|
|
func __int {
|
|
|
|
_int
|
|
|
|
}
|
|
|
|
func __file {
|
|
|
|
_file
|
|
|
|
}
|
2022-02-08 20:23:05 +01:00
|
|
|
native __float
|
2022-02-05 21:20:51 +01:00
|
|
|
func __long {
|
|
|
|
_long
|
|
|
|
}
|
2022-02-08 20:23:05 +01:00
|
|
|
native __double
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-02-08 20:23:05 +01:00
|
|
|
native ischar
|
|
|
|
native isint
|
|
|
|
native isfloat
|
|
|
|
native islong
|
|
|
|
native isdouble
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
"call a dynamically computed function" #
|
|
|
|
"Please keep in mind that this will throw a native error if" #
|
|
|
|
"called incorrectly - this means wrong layer parameter will" #
|
|
|
|
"instantly crash the program." #
|
2022-02-23 17:20:09 +01:00
|
|
|
native _layer_call
|
2022-02-23 17:18:26 +01:00
|
|
|
func call {
|
|
|
|
0 _layer_call
|
|
|
|
}
|
2022-03-04 20:20:46 +01:00
|
|
|
"This returns the last word as a string, from an index." #
|
|
|
|
"index has to be <=15, index 0 is this call" #
|
|
|
|
native _last_word
|
2022-02-08 20:23:05 +01:00
|
|
|
native include
|
|
|
|
native putchar
|
|
|
|
native read
|
|
|
|
native flength
|
|
|
|
native write
|
|
|
|
native type
|
|
|
|
native mktype
|
|
|
|
native typename
|
2022-03-04 20:20:46 +01:00
|
|
|
native getos
|
2022-02-08 20:23:05 +01:00
|
|
|
native istype
|
|
|
|
native settype
|
2022-03-04 20:20:46 +01:00
|
|
|
"try and catch are keywords, not functions" #
|
2022-02-08 20:23:05 +01:00
|
|
|
native throw
|
2022-02-23 18:07:04 +01:00
|
|
|
native exit
|
2022-03-04 20:20:46 +01:00
|
|
|
"storelength" #
|
2022-02-08 20:23:05 +01:00
|
|
|
native stlen
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-02-08 20:23:05 +01:00
|
|
|
native eq
|
|
|
|
native gt
|
|
|
|
native lt
|
|
|
|
native not
|
2022-03-04 20:20:46 +01:00
|
|
|
native neg
|
2022-02-08 20:23:05 +01:00
|
|
|
native or
|
|
|
|
native and
|
|
|
|
native +
|
|
|
|
native -
|
|
|
|
native /
|
|
|
|
native *
|
|
|
|
native **
|
|
|
|
native %
|
|
|
|
native ^
|
2022-02-05 22:08:50 +01:00
|
|
|
|
2022-02-08 20:23:05 +01:00
|
|
|
native dup
|
|
|
|
native pop
|
|
|
|
native swap
|
2022-02-05 22:20:21 +01:00
|
|
|
|
2022-02-23 18:07:04 +01:00
|
|
|
func ++ { 1 + }
|
|
|
|
func -- { 1 - }
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
"this looks so wrong" #
|
2022-02-23 18:07:04 +01:00
|
|
|
func ( { }
|
|
|
|
func ) { }
|
2022-03-04 20:20:46 +01:00
|
|
|
func # { pop }
|
|
|
|
func ; { -1 }
|
|
|
|
|
|
|
|
def TYPE_CHAR "char" mktype =TYPE_CHAR
|
|
|
|
def TYPE_INT "int" mktype =TYPE_INT
|
|
|
|
def TYPE_FILE "file" mktype =TYPE_FILE
|
|
|
|
def TYPE_FLOAT "float" mktype =TYPE_FLOAT
|
|
|
|
def TYPE_LONG "long" mktype =TYPE_LONG
|
|
|
|
def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE
|
|
|
|
def TYPE_ARRAY "array" mktype =TYPE_ARRAY
|
|
|
|
|
|
|
|
def TYPE_STRING "string" mktype =TYPE_STRING
|
2022-02-05 21:20:51 +01:00
|
|
|
func _string {
|
2022-03-04 20:20:46 +01:00
|
|
|
def object =object
|
2022-02-05 21:20:51 +01:00
|
|
|
|
|
|
|
object ischar if {
|
2022-02-05 21:43:10 +01:00
|
|
|
0 _char 1 anew =object
|
2022-02-05 21:20:51 +01:00
|
|
|
}
|
|
|
|
object isint if {
|
|
|
|
itos =object
|
|
|
|
}
|
|
|
|
object isfloat if {
|
|
|
|
ftoi =object
|
|
|
|
}
|
|
|
|
object islong if {
|
|
|
|
ltoi =object
|
|
|
|
}
|
|
|
|
object isdouble if {
|
|
|
|
dtoi =object
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
}
|
|
|
|
func __string {
|
|
|
|
_string
|
|
|
|
}
|
|
|
|
func isstring {
|
|
|
|
isarray
|
|
|
|
}
|
|
|
|
|
|
|
|
func itos {
|
|
|
|
ntos
|
|
|
|
}
|
|
|
|
|
|
|
|
func ltos {
|
|
|
|
ntos
|
|
|
|
}
|
|
|
|
|
|
|
|
func ftos {
|
|
|
|
ntos
|
|
|
|
}
|
|
|
|
|
|
|
|
func dtos {
|
|
|
|
ntos
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
"Number to string" #
|
2022-02-05 21:20:51 +01:00
|
|
|
func ntos {
|
2022-03-04 20:20:46 +01:00
|
|
|
def s "" =s
|
|
|
|
def n =n
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
def negative n 0 lt dup if { n neg =n 1 =negative } =negative
|
|
|
|
def thetype n type =thetype
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-02-23 18:07:04 +01:00
|
|
|
while { n 1 lt not } {
|
|
|
|
n ( n 10 % dup =x ) - =n
|
|
|
|
s ( n '0' + _char ) strconcat =s
|
2022-02-05 21:20:51 +01:00
|
|
|
}
|
2022-03-04 20:20:46 +01:00
|
|
|
def steps 1 =steps
|
2022-02-23 18:07:04 +01:00
|
|
|
while { n 0 eq not } {
|
|
|
|
n ( n ( 1 ( steps dup 10 * =steps ) / ) % dup =x ) - =n
|
|
|
|
s ( x '0' + _char ) strconcat =s
|
2022-02-05 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
negative if {
|
|
|
|
n neg =n
|
|
|
|
}
|
2022-02-05 21:20:51 +01:00
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
func ston {
|
|
|
|
def s =s "bind string" #
|
|
|
|
def n 0 =n "the number to return" #
|
|
|
|
def negative def idx s 0 aget '-' eq dup =idx =negative
|
|
|
|
|
|
|
|
while { idx s alen lt } {
|
|
|
|
def chr s idx aget =chr
|
|
|
|
n ( chr ( 10 ( s alen idx - 1 - ) ** ) + =n
|
|
|
|
idx inc
|
|
|
|
}
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
n
|
|
|
|
}
|
|
|
|
|
|
|
|
"Copy array" #
|
|
|
|
func acopy {
|
|
|
|
"bind args" #
|
|
|
|
def len =len
|
|
|
|
def idx2 =idx2
|
|
|
|
def idx1 =idx1
|
|
|
|
def arr2 =arr2
|
|
|
|
def arr1 =arr1
|
|
|
|
|
|
|
|
def i 1 neg =i
|
2022-02-23 18:07:04 +01:00
|
|
|
while { ( i 1 + =i ) ( i len lt ) } {
|
|
|
|
arr2 i idx2 + ( arr1 i idx1 + aget ) aput
|
2022-02-05 21:20:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strconcat {
|
2022-03-04 20:20:46 +01:00
|
|
|
"bind args" #
|
|
|
|
def str2 _string =str2
|
|
|
|
def str1 _string =str1
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
def str 0 _char str1 alen str2 alen + anew =str
|
2022-02-05 21:43:10 +01:00
|
|
|
|
|
|
|
str1 str 0 0 str1 alen acopy
|
|
|
|
str2 str 0 str1 alen str2 alen acopy
|
2022-02-05 21:20:51 +01:00
|
|
|
|
|
|
|
str
|
|
|
|
}
|
|
|
|
|
|
|
|
func strsplit {
|
2022-03-04 20:20:46 +01:00
|
|
|
"bind args" #
|
|
|
|
def splitter _string =splitter
|
|
|
|
def str _string =str
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =i
|
2022-03-04 20:20:46 +01:00
|
|
|
def sequences "" 0 anew =sequences
|
|
|
|
def sequence "" =sequence
|
2022-02-23 18:07:04 +01:00
|
|
|
while { ( i 1 + =i ) ( i str alen lt ) } {
|
2022-03-04 20:20:46 +01:00
|
|
|
def chr str i aget =chr
|
|
|
|
def spl splitter 0 aget =spl
|
2022-02-05 23:16:53 +01:00
|
|
|
sequence chr strconcat =sequence
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =j
|
2022-02-23 18:07:04 +01:00
|
|
|
while { ( j 1 + =j ) ( chr spl eq ) } {
|
2022-02-05 23:16:53 +01:00
|
|
|
j splitter alen eq if {
|
2022-03-04 20:20:46 +01:00
|
|
|
def oldsq sequences =oldsq
|
2022-02-23 18:07:04 +01:00
|
|
|
"" ( sequences alen dup =seq 1 + ) anew =sequences
|
2022-02-05 21:20:51 +01:00
|
|
|
oldsq sequences 0 0 oldsq alen acopy
|
2022-02-05 22:35:14 +01:00
|
|
|
sequences seq sequence aput
|
2022-02-05 23:16:53 +01:00
|
|
|
"" =sequence
|
2022-02-06 02:12:39 +01:00
|
|
|
2 stop
|
2022-02-05 22:35:14 +01:00
|
|
|
}
|
2022-02-05 23:16:53 +01:00
|
|
|
str i j + aget dup =chr
|
|
|
|
splitter j aget dup =spl
|
2022-02-05 21:20:51 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-05 22:35:14 +01:00
|
|
|
|
|
|
|
sequences
|
2022-02-05 21:20:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-06 02:12:39 +01:00
|
|
|
func strjoin {
|
2022-03-04 20:20:46 +01:00
|
|
|
"bind args" #
|
|
|
|
def joiner _string =joiner
|
|
|
|
def arr _array =arr
|
2022-02-06 02:12:39 +01:00
|
|
|
|
|
|
|
1 neg =i
|
2022-03-04 20:20:46 +01:00
|
|
|
def s "" =s
|
2022-02-23 18:07:04 +01:00
|
|
|
while { ( i 1 + =i ) ( i arr alen lt ) } {
|
2022-02-06 02:12:39 +01:00
|
|
|
s arr i aget joiner strconcat strconcat =s
|
|
|
|
}
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
|
|
|
func strsub {
|
2022-03-04 20:20:46 +01:00
|
|
|
"bind args" #
|
|
|
|
def pos2 _int =pos2
|
|
|
|
def pos1 _int =pos1
|
|
|
|
def string _string =string
|
2022-02-06 02:12:39 +01:00
|
|
|
|
|
|
|
pos2 pos1 - =length
|
|
|
|
|
2022-02-23 18:07:04 +01:00
|
|
|
( o _char length anew dup ) string swap pos1 0 length acopy
|
2022-02-06 02:12:39 +01:00
|
|
|
}
|
|
|
|
|
2022-02-05 21:20:51 +01:00
|
|
|
func puts {
|
2022-03-04 20:20:46 +01:00
|
|
|
def str _string =str
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =i
|
2022-02-23 18:07:04 +01:00
|
|
|
while { ( i 1 + =i ) ( i str alen lt ) } {
|
2022-02-05 21:20:51 +01:00
|
|
|
str i aget putchar
|
|
|
|
}
|
|
|
|
}
|
2022-02-23 17:18:26 +01:00
|
|
|
|
|
|
|
func anewput {
|
|
|
|
def size =size
|
|
|
|
def arr size anew =arr
|
|
|
|
|
|
|
|
def i 0 =i
|
2022-03-04 20:20:46 +01:00
|
|
|
while { i size lt } {
|
2022-02-23 17:18:26 +01:00
|
|
|
arr swap i swap aput
|
|
|
|
i 1 + =i
|
|
|
|
}
|
|
|
|
|
|
|
|
arr areverse
|
|
|
|
}
|
|
|
|
|
|
|
|
func areverse {
|
|
|
|
def arr =arr
|
|
|
|
def new arr alen anew =new
|
|
|
|
|
|
|
|
def i arr alen 1 - =i
|
|
|
|
def j 0 =j
|
2022-03-04 20:20:46 +01:00
|
|
|
while { i 0 lt not } {
|
2022-02-23 17:18:26 +01:00
|
|
|
new j arr i aget aput
|
|
|
|
j 1 + =j
|
|
|
|
i 1 - =i
|
|
|
|
}
|
|
|
|
|
|
|
|
new
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
func strcontains {
|
|
|
|
def check =check "bind check" #
|
|
|
|
def s =s "bind string" #
|
|
|
|
|
|
|
|
def found 0 =found
|
|
|
|
def counter 0 =counter
|
|
|
|
def i 0 =i
|
|
|
|
def j 0 =j
|
|
|
|
while { i s alen lt } {
|
|
|
|
s i aget check j aget eq dup if {
|
|
|
|
counter inc
|
|
|
|
}
|
|
|
|
not if {
|
|
|
|
0 =counter
|
|
|
|
}
|
|
|
|
counter check alen eq if {
|
|
|
|
3 stop
|
|
|
|
}
|
|
|
|
i inc
|
|
|
|
}
|
|
|
|
counter check alen eq
|
2022-02-23 17:18:26 +01:00
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
"These functions are magic, they use natives to get recent words and modify the" #
|
|
|
|
"variables, do not touch them unless you know exactly what you're doing!" #
|
|
|
|
func inc {
|
|
|
|
def varname 3 _last_word =varname
|
|
|
|
pop
|
|
|
|
( varname 1 _layer_call ) "Get var" #
|
|
|
|
1 + "Increment" #
|
|
|
|
( "=" varname strconcat 1 _layer_call ) "Store var" #
|
|
|
|
}
|
2022-02-23 17:18:26 +01:00
|
|
|
func dec {
|
2022-03-04 20:20:46 +01:00
|
|
|
def varname 3 _last_word =varname
|
|
|
|
pop
|
|
|
|
( varname 1 _layer_call ) "Get var" #
|
|
|
|
1 - "Decrement" #
|
|
|
|
( "=" varname strconcat 1 _layer_call ) "Store var" #
|
|
|
|
}
|
|
|
|
|
|
|
|
func random {
|
|
|
|
getos dup ( "linux" strcontains ) swap ( "macos" strcontains ) or dup if {
|
|
|
|
"/dev/urandom" _file 1 read
|
|
|
|
}
|
|
|
|
not if {
|
|
|
|
"__windows_radom" call
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strlowercase {
|
|
|
|
def s =s "bind string" #
|
|
|
|
def i 0 =i
|
|
|
|
while { i s alen lt } {
|
|
|
|
def char s i aget =char
|
|
|
|
char 64 gt char 91 lt and if {
|
|
|
|
s i char 32 + aput
|
|
|
|
}
|
|
|
|
i inc
|
|
|
|
}
|
2022-02-23 17:18:26 +01:00
|
|
|
}
|
|
|
|
|
2022-03-04 20:20:46 +01:00
|
|
|
func struppercase {
|
|
|
|
def s =s "bind string" #
|
|
|
|
def i 0 =i
|
|
|
|
while { i s alen lt } {
|
|
|
|
def char s i aget =char
|
|
|
|
char 89 gt char 123 lt and if {
|
|
|
|
s i char 32 - aput
|
|
|
|
}
|
|
|
|
i inc
|
|
|
|
}
|
|
|
|
}
|