isbpl/std.isbpl

547 lines
10 KiB
Text
Raw Normal View History

2022-03-05 20:55:03 +01:00
native dup
native pop
native swap
func # { pop }
native alen
native aget
native aput
native anew
native _array
2022-02-05 21:20:51 +01:00
native _char
2022-03-05 20:55:03 +01:00
native _byte
native _int
native _float
native _long
native _double
2022-02-05 21:20:51 +01:00
native ischar
2022-03-05 20:55:03 +01:00
native isbyte
native isint
native isfloat
native islong
native isdouble
2022-03-05 20:55:03 +01:00
native isarray
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 {
2022-03-05 20:55:03 +01:00
1 _layer_call
2022-02-23 17:18:26 +01:00
}
2022-03-24 15:25:07 +01:00
native subprocess
2022-03-05 20:55:03 +01:00
"This returns the last word as a string, from an index." #
"index has to be <16, index 0 is this call" #
2022-03-04 20:20:46 +01:00
native _last_word
native include
2022-05-04 04:27:44 +02:00
native reload
native getfile
native putchar
native mktype
2022-05-04 02:16:58 +02:00
native mkinstance
2022-03-04 20:20:46 +01:00
native getos
2022-03-05 20:55:03 +01:00
native typename
2022-05-14 16:10:47 +02:00
native typeid
2022-03-05 20:55:03 +01:00
native gettype
native settype
2022-03-05 20:55:03 +01:00
"try and do are keywords, not functions" #
native throw
native exit
2022-02-05 21:20:51 +01:00
native eq
native gt
native lt
native not
2022-03-04 20:20:46 +01:00
native neg
native or
native and
native +
native -
native /
native *
native **
native %
native ^
2022-03-16 00:45:22 +01:00
native fcall
2022-04-16 00:44:52 +02:00
native deffunc
2022-04-16 00:10:51 +02:00
native defmethod
2022-04-16 00:44:52 +02:00
native deffield
2022-05-14 16:10:47 +02:00
native defsuper
2022-04-19 01:49:56 +02:00
native delete "deletes all field values from an object" #
2022-04-17 17:40:25 +02:00
native callmethod
2022-03-16 00:45:22 +01:00
func ++ { 1 + }
func -- { 1 - }
2022-03-04 20:20:46 +01:00
"this looks so wrong" #
func ( { }
func ) { }
2022-03-04 20:20:46 +01:00
2022-05-13 18:05:10 +02:00
func ! { dup }
2022-05-14 16:10:47 +02:00
"The TYPE_ prefix is deprecated, but will be kept for backwards compatibility." #
2022-03-05 20:55:03 +01:00
"int must be registered first." #
def TYPE_INT construct int {
# "no fields needed"
;
2022-05-14 16:10:47 +02:00
construct {
pop 0
}
new {
"int has the new method because all types are ints" #
mkinstance
}
} =TYPE_INT
2022-03-05 20:55:03 +01:00
def TYPE_CHAR "char" mktype =TYPE_CHAR
def TYPE_BYTE "byte" mktype =TYPE_BYTE
2022-03-04 20:20:46 +01:00
def TYPE_FLOAT "float" mktype =TYPE_FLOAT
def TYPE_LONG "long" mktype =TYPE_LONG
def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE
def TYPE_NULL "null" mktype =TYPE_NULL
native null
2022-03-16 00:45:22 +01:00
def TYPE_FUNCTION "func" mktype =TYPE_FUNCTION
2022-05-14 16:10:47 +02:00
def Function TYPE_FUNCTION =Function
2022-05-13 18:05:10 +02:00
def TYPE_ARRAY construct array {
;
2022-05-14 16:10:47 +02:00
construct {
pop anew
}
2022-05-13 18:05:10 +02:00
foreach {
def this =this
def lambda =lambda
def i 0 =i
while { i this alen lt } { this i aget lambda fcall i ++ =i }
}
} =TYPE_ARRAY
2022-05-14 16:10:47 +02:00
def Array TYPE_ARRAY =Array
def TYPE_STRING construct string array {
;
_array {
Array settype
}
} =TYPE_STRING
def String TYPE_STRING =String
2022-03-04 20:20:46 +01:00
2022-05-13 12:18:22 +02:00
def TYPE_JIO construct jio {
2022-05-14 16:10:47 +02:00
jioclass
2022-05-13 12:18:22 +02:00
;
class {
pop
native jio.class
jio.class
}
getclass {
pop
native jio.getclass
jio.getclass
}
context {
pop
native jio.context
jio.context
}
2022-05-13 18:05:10 +02:00
stack {
pop
"java.lang.Thread" JIO class currentThread0 getId0 JIO context debuggerIPC stack get1
}
2022-05-13 12:18:22 +02:00
} =TYPE_JIO
2022-04-16 18:44:07 +02:00
def JIO 0 TYPE_JIO settype =JIO
2022-05-13 18:05:10 +02:00
def TYPE_REFERENCE construct reference {
?
} =TYPE_REFERENCE
2022-04-27 00:02:11 +02:00
"value" TYPE_REFERENCE deffield
func reference {
2022-05-13 18:05:10 +02:00
def this TYPE_REFERENCE mkinstance =this
this =?
2022-04-27 00:02:11 +02:00
this
}
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-03-05 20:55:03 +01:00
1 anew =object
object TYPE_STRING settype
}
object isbyte if {
2022-03-06 16:34:37 +01:00
object itos =object
2022-02-05 21:20:51 +01:00
}
object isint if {
2022-03-06 16:34:37 +01:00
object itos =object
2022-02-05 21:20:51 +01:00
}
object isfloat if {
2022-03-06 16:34:37 +01:00
object ftoi =object
2022-02-05 21:20:51 +01:00
}
object islong if {
2022-03-06 16:34:37 +01:00
object ltoi =object
2022-02-05 21:20:51 +01:00
}
object isdouble if {
2022-03-06 16:34:37 +01:00
object dtoi =object
2022-02-05 21:20:51 +01:00
}
2022-03-05 20:55:03 +01:00
2022-03-05 21:07:29 +01:00
object isarray if {
object TYPE_STRING settype =object
}
2022-03-05 20:55:03 +01:00
object isstring not if {
"IncompatibleTypes" "Incompatible types: " object gettype typename " - string" strconcat strconcat throw
}
2022-03-05 21:07:29 +01:00
object
2022-02-05 21:20:51 +01:00
}
func isstring {
2022-03-05 20:55:03 +01:00
gettype typename "string" eq
2022-02-05 21:20:51 +01:00
}
2022-03-06 16:34:37 +01:00
func stoi {
stol _int
}
func stof {
stod _float
}
2022-02-05 21:20:51 +01:00
func itos {
2022-03-06 15:26:08 +01:00
_long ltos
2022-02-05 21:20:51 +01:00
}
func ftos {
_double dtos
2022-02-05 21:20:51 +01:00
}
func dtos {
2022-03-06 15:26:08 +01:00
"NotImplemented" "dtos is not implemented" throw
2022-02-05 21:20:51 +01:00
}
2022-03-06 16:34:37 +01:00
func stod {
"NotImplemented" "stod is not implemented" throw
}
2022-03-04 20:20:46 +01:00
"Number to string" #
2022-03-06 15:26:08 +01:00
func ltos {
def n =n "bind number" #
def s 0 anew =s "make array" #
def ne n 0 lt dup if { n neg =n } =ne
func rem { 10 _long / }
2022-02-05 21:20:51 +01:00
2022-03-06 15:26:08 +01:00
def c0 "0" char =c0
2022-02-05 21:20:51 +01:00
n 0 gt not if {
"0" =s
}
2022-03-06 15:26:08 +01:00
while { n 0 gt } {
( ( ( n 10 _long % _char ) c0 + ) _char 1 anewput _string ) s strconcat =s
n rem =n "divide by ten to remove last digit" #
2022-02-05 22:16:59 +01:00
}
2022-03-06 15:26:08 +01:00
ne if { "-" s strconcat =s }
2022-02-05 21:20:51 +01:00
2022-03-06 15:26:08 +01:00
s _string
2022-02-05 21:20:51 +01:00
}
2022-03-06 15:26:08 +01:00
func stol {
def s _array =s "bind string" #
def n 0 _long =n "the number to return" #
def ne s 0 aget "-" char eq =ne
def len s alen =len
ne if { s ( len 1 - dup =len anew ) 1 0 len acopy =s }
func rem { dup ( ( def len alen 1 - =len ) len anew ) 1 0 len acopy }
def c0 "0" char =c0
2022-03-05 20:55:03 +01:00
2022-03-06 15:26:08 +01:00
while { s alen 0 eq not } {
def chr s char =chr "extract first char" #
n 10 _long * =n
n ( chr c0 - _long ) + =n
s rem =s "remove first digit" #
2022-03-04 20:20:46 +01:00
}
2022-02-05 21:20:51 +01:00
n ( ne 2 * 1 - neg ) _long *
2022-03-04 20:20:46 +01:00
}
2022-03-06 15:26:08 +01:00
func char { _array 0 aget }
2022-03-04 20:20:46 +01:00
"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-03-06 15:26:08 +01:00
while { ( i ++ =i ) ( i len lt ) } {
arr2 ( i idx2 + ) ( arr1 ( i idx1 + ) aget ) aput
2022-02-05 21:20:51 +01:00
}
2022-03-06 15:26:08 +01:00
arr2
2022-02-05 21:20:51 +01:00
}
func strconcat {
2022-03-04 20:20:46 +01:00
"bind args" #
2022-03-06 15:26:08 +01:00
def str2 _string _array =str2
def str1 _string _array =str1
2022-03-05 20:55:03 +01:00
2022-03-06 15:26:08 +01:00
def str str1 alen str2 alen + anew =str
2022-03-05 20:55:03 +01:00
2022-03-06 15:26:08 +01:00
str1 str 0 0 str1 alen acopy pop
str2 str 0 str1 alen str2 alen acopy pop
2022-02-05 21:20:51 +01:00
2022-03-06 15:26:08 +01:00
str _string
2022-02-05 21:20:51 +01:00
}
func strsplit {
2022-03-04 20:20:46 +01:00
"bind args" #
2022-05-03 11:32:16 +02:00
def splitter _string _array =splitter
def str _string _array =str
2022-02-05 21:20:51 +01:00
2022-05-03 11:32:16 +02:00
def sequences 0 anew =sequences
def sequence 0 anew =sequence
def i 0 =i
def sm 0 =sm
while { i str alen lt } {
def j 0 =j
2022-03-04 20:20:46 +01:00
def chr str i aget =chr
2022-05-03 11:32:16 +02:00
while { j splitter alen lt i j + str alen lt and } {
str i j + aget splitter j aget eq if {
sm inc
sm splitter alen eq if {
sequences [ sequence _string ] aadd =sequences
0 anew =sequence
0 =sm
i splitter alen + =i
4 stop
}
2022-02-05 22:35:14 +01:00
}
2022-05-03 11:32:16 +02:00
j inc
2022-02-05 21:20:51 +01:00
}
2022-05-03 11:32:16 +02:00
sequence [ chr ] aadd =sequence
i inc
2022-02-05 21:20:51 +01:00
}
2022-05-03 11:32:16 +02:00
sequences [ sequence _string ] aadd =sequences
2022-02-05 22:35:14 +01:00
sequences
2022-02-05 21:20:51 +01:00
}
func strjoin {
2022-03-04 20:20:46 +01:00
"bind args" #
def joiner _string =joiner
def arr _array =arr
1 neg =i
2022-03-04 20:20:46 +01:00
def s "" =s
while { ( i 1 + =i ) ( i arr alen lt ) } {
s arr i aget joiner strconcat strconcat =s
}
s
}
2022-05-04 04:27:44 +02:00
func strsub {
def pos2 _int =pos2
def pos1 _int =pos1
_array
pos1 pos2 asub _string
}
func asub {
2022-03-04 20:20:46 +01:00
"bind args" #
def pos2 _int =pos2
def pos1 _int =pos1
2022-05-04 04:27:44 +02:00
def arr =arr
2022-05-04 04:27:44 +02:00
def length pos2 pos1 - =length
2022-05-04 04:27:44 +02:00
arr length anew pos1 0 length acopy
}
2022-02-05 21:20:51 +01:00
func puts {
2022-03-05 20:55:03 +01:00
def str _array =str
def i 1 neg =i
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
2022-03-05 20:55:03 +01:00
2022-02-23 17:18:26 +01:00
def i 0 =i
2022-03-04 20:20:46 +01:00
while { i size lt } {
2022-05-04 02:16:58 +02:00
arr swap i swap aput
2022-03-06 15:26:08 +01:00
i inc
2022-02-23 17:18:26 +01:00
}
arr areverse
}
func areverse {
def arr =arr
2022-05-14 14:42:53 +02:00
def newarr arr alen anew =newarr
2022-02-23 17:18:26 +01:00
def i arr alen 1 - =i
def j 0 =j
2022-03-04 20:20:46 +01:00
while { i 0 lt not } {
2022-05-14 14:42:53 +02:00
newarr j arr i aget aput
2022-02-23 17:18:26 +01:00
j 1 + =j
i 1 - =i
}
2022-05-14 14:42:53 +02:00
newarr
2022-02-23 17:18:26 +01:00
}
2022-05-13 18:05:10 +02:00
func strcontains { acontains }
func acontains {
2022-05-05 17:34:29 +02:00
def check _array =check "bind check" #
2022-05-13 18:05:10 +02:00
def s _array =s "bind array" #
2022-03-04 20:20:46 +01:00
def found 0 =found
def counter 0 =counter
def i 0 =i
while { i s alen lt } {
2022-05-05 17:34:29 +02:00
s i aget check counter aget eq dup if {
2022-03-04 20:20:46 +01:00
counter inc
}
not if {
0 =counter
2022-05-05 17:34:29 +02:00
s i aget check counter aget eq if {
counter inc
}
2022-03-04 20:20:46 +01:00
}
counter check alen eq if {
2022-05-05 17:34:29 +02:00
1 =found
s alen =i
2022-03-04 20:20:46 +01:00
}
i inc
}
2022-05-05 17:34:29 +02:00
found
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 {
2022-03-05 20:55:03 +01:00
def varname 4 _last_word =varname
2022-03-04 20:20:46 +01:00
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-05 20:55:03 +01:00
def varname 4 _last_word =varname
2022-03-04 20:20:46 +01:00
pop
( varname 1 _layer_call ) "Get var" #
1 - "Decrement" #
( "=" varname strconcat 1 _layer_call ) "Store var" #
}
func strlowercase {
2022-03-06 20:07:48 +01:00
def s _array =s "bind string" #
2022-03-04 20:20:46 +01:00
def i 0 =i
while { i s alen lt } {
2022-03-06 20:07:48 +01:00
def chr s i aget =chr
chr "A" char lt not chr "Z" char gt not and if {
s i chr "a" char "A" char - + aput
2022-03-04 20:20:46 +01:00
}
i inc
}
2022-03-06 20:07:48 +01:00
s _string
2022-02-23 17:18:26 +01:00
}
2022-03-04 20:20:46 +01:00
func struppercase {
2022-03-06 20:07:48 +01:00
def s _array =s "bind string" #
2022-03-04 20:20:46 +01:00
def i 0 =i
while { i s alen lt } {
2022-03-06 20:07:48 +01:00
def chr s i aget =chr
chr "a" char lt not chr "z" char gt not and if {
s i chr "a" char "A" char - - aput
2022-03-04 20:20:46 +01:00
}
i inc
}
2022-03-06 20:07:48 +01:00
s _string
2022-03-04 20:20:46 +01:00
}
func main {
pop 0
}
2022-05-02 10:06:35 +02:00
func aadd {
def arr2 =arr2
def arr1 =arr1
2022-05-14 14:42:53 +02:00
def newarr arr1 alen arr2 alen + anew =newarr
arr1 newarr 0 0 arr1 alen acopy =newarr
arr2 newarr 0 arr1 alen arr2 alen acopy =newarr
2022-05-02 10:06:35 +02:00
2022-05-14 14:42:53 +02:00
newarr
2022-05-02 10:06:35 +02:00
}
def TYPE_SHADOW "shadow" mktype =TYPE_SHADOW
func [ {
TYPE_ARRAY TYPE_SHADOW settype
}
2022-05-04 04:27:44 +02:00
"For some reason, this makes objects lose their identity. I do not know, why." #
"Fixed in commit 81eff27, bug was in dup native." #
2022-05-02 10:06:35 +02:00
func ] {
2022-05-02 10:41:53 +02:00
"create an array containing everything on stack until the arrayshadow" #
2022-05-02 10:06:35 +02:00
def array 0 anew =array
while { dup [ eq not } {
1 anewput array aadd =array
}
pop array
}
2022-05-04 19:48:09 +02:00
2022-05-13 18:05:10 +02:00
func astartswith_old {
2022-05-04 19:48:09 +02:00
def match _array =match
def str _array =str
str alen match alen lt if {
0 2 stop
}
str alen match alen eq if {
str match eq 2 stop
}
def i 0 =i
while { i match alen lt } {
str i aget match i aget eq not if {
0 3 stop
}
i inc
}
1
}
2022-05-13 18:05:10 +02:00
func astartswith {
def match _array =match
def val _array =val
val alen match alen lt if {
0
2 stop
}
val alen match alen eq if {
val match eq
2 stop
}
val
0
match alen
asub match eq
}