2022-02-05 21:20:51 +01:00
|
|
|
native func alen
|
|
|
|
native func aget
|
|
|
|
native func aput
|
2022-02-05 21:43:10 +01:00
|
|
|
native func anew
|
2022-02-05 21:20:51 +01:00
|
|
|
native func _array
|
|
|
|
func __array {
|
|
|
|
"NotImplemented" "Not implemented" throw
|
|
|
|
}
|
|
|
|
|
|
|
|
native func _char
|
|
|
|
native func _int
|
|
|
|
native func _file
|
|
|
|
native func _float
|
|
|
|
native func _long
|
|
|
|
native func _double
|
|
|
|
|
|
|
|
func __char {
|
|
|
|
_char
|
|
|
|
}
|
|
|
|
func __int {
|
|
|
|
_int
|
|
|
|
}
|
|
|
|
func __file {
|
|
|
|
_file
|
|
|
|
}
|
|
|
|
native func __float
|
|
|
|
func __long {
|
|
|
|
_long
|
|
|
|
}
|
|
|
|
native func __double
|
|
|
|
|
|
|
|
native func ischar
|
|
|
|
native func isint
|
|
|
|
native func isfloat
|
|
|
|
native func islong
|
|
|
|
native func isdouble
|
|
|
|
|
|
|
|
native func stop
|
|
|
|
native func include
|
|
|
|
native func putchar
|
|
|
|
native func read
|
2022-02-06 02:12:39 +01:00
|
|
|
native func flength
|
|
|
|
native func write
|
2022-02-05 21:20:51 +01:00
|
|
|
native func type
|
|
|
|
native func mktype
|
2022-02-05 21:43:10 +01:00
|
|
|
# call a dynamically computed function
|
2022-02-05 21:20:51 +01:00
|
|
|
native func call
|
|
|
|
native func typename
|
2022-02-06 02:12:39 +01:00
|
|
|
native func istype
|
|
|
|
native func settype
|
2022-02-05 21:20:51 +01:00
|
|
|
native func throw
|
|
|
|
# try and catch are keywords, not functions
|
2022-02-05 21:43:10 +01:00
|
|
|
# storelength
|
2022-02-05 21:20:51 +01:00
|
|
|
native func stlen
|
|
|
|
|
2022-02-05 22:08:50 +01:00
|
|
|
native func eq
|
|
|
|
native func gt
|
|
|
|
native func lt
|
|
|
|
native func not
|
2022-02-06 02:12:39 +01:00
|
|
|
native func or
|
|
|
|
native func and
|
2022-02-05 22:18:48 +01:00
|
|
|
native func +
|
|
|
|
native func -
|
|
|
|
native func /
|
|
|
|
native func *
|
|
|
|
native func **
|
|
|
|
native func %
|
|
|
|
native func ^
|
2022-02-05 22:08:50 +01:00
|
|
|
|
2022-02-05 22:20:21 +01:00
|
|
|
native func dup
|
|
|
|
native func pop
|
|
|
|
native func swap
|
|
|
|
|
2022-02-05 21:20:51 +01:00
|
|
|
"char" mktype =TYPE_CHAR
|
|
|
|
"int" mktype =TYPE_INT
|
|
|
|
"file" mktype =TYPE_FILE
|
|
|
|
"float" mktype =TYPE_FLOAT
|
|
|
|
"long" mktype =TYPE_LONG
|
|
|
|
"double" mktype =TYPE_DOUBLE
|
|
|
|
"array" mktype =TYPE_ARRAY
|
|
|
|
|
|
|
|
"string" mktype =TYPE_STRING
|
|
|
|
func _string {
|
|
|
|
=object
|
|
|
|
|
|
|
|
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-02-05 21:43:10 +01:00
|
|
|
# Number to string
|
2022-02-05 21:20:51 +01:00
|
|
|
func ntos {
|
|
|
|
"" =s
|
|
|
|
=n
|
|
|
|
|
2022-02-05 22:16:59 +01:00
|
|
|
n 0 lt dup if { n neg =n 1 =negative } =negative
|
2022-02-05 21:20:51 +01:00
|
|
|
n type =thetype
|
|
|
|
|
2022-02-05 22:16:59 +01:00
|
|
|
while n 1 lt not {
|
2022-02-05 21:20:51 +01:00
|
|
|
n (n 10 % dup =x) - =n
|
|
|
|
s (n '0' + _char) strconcat =s
|
|
|
|
}
|
2022-02-05 22:16:59 +01:00
|
|
|
1 =steps
|
|
|
|
while n 0 eq not {
|
|
|
|
n (n (1 (steps dup 10 * =steps) /) % dup =x) - =n
|
|
|
|
s (x '0' + _char) strconcat =s
|
|
|
|
}
|
|
|
|
|
|
|
|
negative if { "-" s strconcat =s }
|
2022-02-05 21:20:51 +01:00
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:43:10 +01:00
|
|
|
# Copy array
|
2022-02-05 21:20:51 +01:00
|
|
|
func acopy {
|
|
|
|
# bind args
|
|
|
|
=len
|
|
|
|
=idx2
|
|
|
|
=idx1
|
|
|
|
=arr2
|
|
|
|
=arr1
|
|
|
|
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =i
|
|
|
|
while (i 1 + =i) (i len lt) {
|
2022-02-05 21:20:51 +01:00
|
|
|
arr2 i idx2 + (arr1 i idx1 + aget) aput
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strconcat {
|
|
|
|
# bind args
|
|
|
|
_string =str2
|
|
|
|
_string =str1
|
|
|
|
|
2022-02-06 02:12:39 +01:00
|
|
|
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 {
|
|
|
|
# bind args
|
|
|
|
_string =splitter
|
2022-02-06 02:12:39 +01:00
|
|
|
_string =str
|
2022-02-05 21:20:51 +01:00
|
|
|
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =i
|
2022-02-05 21:43:10 +01:00
|
|
|
"" 0 anew =sequences
|
2022-02-05 23:16:53 +01:00
|
|
|
"" =sequence
|
2022-02-06 02:12:39 +01:00
|
|
|
while (i 1 + =i) (i str alen lt) {
|
2022-02-05 21:20:51 +01:00
|
|
|
str i aget =chr
|
|
|
|
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
|
|
|
|
while (j 1 + =j) (chr spl eq) {
|
2022-02-05 23:16:53 +01:00
|
|
|
j splitter alen eq if {
|
2022-02-05 21:20:51 +01:00
|
|
|
sequences =oldsq
|
2022-02-05 22:35:14 +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 {
|
|
|
|
# bind args
|
|
|
|
_string =joiner
|
|
|
|
_array =arr
|
|
|
|
|
|
|
|
1 neg =i
|
|
|
|
"" =s
|
|
|
|
while (i 1 + =i) (i arr alen lt) {
|
|
|
|
s arr i aget joiner strconcat strconcat =s
|
|
|
|
}
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
|
|
|
func strsub {
|
|
|
|
# bind args
|
|
|
|
_int =pos2
|
|
|
|
_int =pos1
|
|
|
|
_string =string
|
|
|
|
|
|
|
|
pos2 pos1 - =length
|
|
|
|
|
|
|
|
(o _char length anew dup) string swap pos1 0 length acopy
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:20:51 +01:00
|
|
|
func puts {
|
|
|
|
_string =str
|
2022-02-05 22:35:14 +01:00
|
|
|
1 neg =i
|
|
|
|
while (i 1 + =i) (i str alen lt) {
|
2022-02-05 21:20:51 +01:00
|
|
|
str i aget putchar
|
|
|
|
}
|
|
|
|
}
|