first version of java interpreter

This commit is contained in:
Daniella 2022-03-05 20:55:03 +01:00
parent a082ae8729
commit 4e2e425349
4 changed files with 1174 additions and 57 deletions

1114
bootstrap/ISBPL.java Normal file

File diff suppressed because it is too large Load diff

9
errorstream.isbpl Normal file
View file

@ -0,0 +1,9 @@
native eputchar
func eputs {
def str _string =str
1 neg =i
while { ( i 1 + =i ) ( i str alen lt ) } {
str i aget eputchar
}
}

8
file.isbpl Normal file
View file

@ -0,0 +1,8 @@
native _file
native isfile
def TYPE_FILE "file" mktype =TYPE_FILE
native read
native flength
native write

100
std.isbpl
View file

@ -1,39 +1,29 @@
native dup
native pop
native swap
func # { pop }
native alen native alen
native aget native aget
native aput native aput
native anew native anew
native _array native _array
func __array {
"NotImplemented" "Not implemented" throw
}
native _char native _char
native _byte
native _int native _int
native _file
native _float native _float
native _long native _long
native _double native _double
func __char {
_char
}
func __int {
_int
}
func __file {
_file
}
native __float
func __long {
_long
}
native __double
native ischar native ischar
native isbyte
native isint native isint
native isfloat native isfloat
native islong native islong
native isdouble native isdouble
native isarray
"call a dynamically computed function" # "call a dynamically computed function" #
"Please keep in mind that this will throw a native error if" # "Please keep in mind that this will throw a native error if" #
@ -41,27 +31,21 @@ native isdouble
"instantly crash the program." # "instantly crash the program." #
native _layer_call native _layer_call
func call { func call {
0 _layer_call 1 _layer_call
} }
"This returns the last word as a string, from an index." # "This returns the last word as a string, from an index." #
"index has to be <=15, index 0 is this call" # "index has to be <16, index 0 is this call" #
native _last_word native _last_word
native include native include
native putchar native putchar
native read
native flength
native write
native type
native mktype native mktype
native typename
native getos native getos
native istype native typename
native gettype
native settype native settype
"try and catch are keywords, not functions" # "try and do are keywords, not functions" #
native throw native throw
native exit native exit
"storelength" #
native stlen
native eq native eq
native gt native gt
@ -78,22 +62,18 @@ native **
native % native %
native ^ native ^
native dup
native pop
native swap
func ++ { 1 + } func ++ { 1 + }
func -- { 1 - } func -- { 1 - }
"this looks so wrong" # "this looks so wrong" #
func ( { } func ( { }
func ) { } func ) { }
func # { pop } func ; { }
func ; { -1 }
def TYPE_CHAR "char" mktype =TYPE_CHAR "int must be registered first." #
def TYPE_INT "int" mktype =TYPE_INT def TYPE_INT "int" mktype =TYPE_INT
def TYPE_FILE "file" mktype =TYPE_FILE def TYPE_CHAR "char" mktype =TYPE_CHAR
def TYPE_BYTE "byte" mktype =TYPE_BYTE
def TYPE_FLOAT "float" mktype =TYPE_FLOAT def TYPE_FLOAT "float" mktype =TYPE_FLOAT
def TYPE_LONG "long" mktype =TYPE_LONG def TYPE_LONG "long" mktype =TYPE_LONG
def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE
@ -104,7 +84,11 @@ func _string {
def object =object def object =object
object ischar if { object ischar if {
0 _char 1 anew =object 1 anew =object
object TYPE_STRING settype
}
object isbyte if {
itos =object
} }
object isint if { object isint if {
itos =object itos =object
@ -118,14 +102,13 @@ func _string {
object isdouble if { object isdouble if {
dtoi =object dtoi =object
} }
object object isstring not if {
} "IncompatibleTypes" "Incompatible types: " object gettype typename " - string" strconcat strconcat throw
func __string { }
_string
} }
func isstring { func isstring {
isarray gettype typename "string" eq
} }
func itos { func itos {
@ -150,7 +133,7 @@ func ntos {
def n =n def n =n
def negative n 0 lt dup if { n neg =n 1 =negative } =negative def negative n 0 lt dup if { n neg =n 1 =negative } =negative
def thetype n type =thetype def thetype n gettype =thetype
while { n 1 lt not } { while { n 1 lt not } {
n ( n 10 % dup =x ) - =n n ( n 10 % dup =x ) - =n
@ -173,7 +156,7 @@ func ston {
def s =s "bind string" # def s =s "bind string" #
def n 0 =n "the number to return" # def n 0 =n "the number to return" #
def negative def idx s 0 aget '-' eq dup =idx =negative def negative def idx s 0 aget '-' eq dup =idx =negative
while { idx s alen lt } { while { idx s alen lt } {
def chr s idx aget =chr def chr s idx aget =chr
n ( chr ( 10 ( s alen idx - 1 - ) ** ) + =n n ( chr ( 10 ( s alen idx - 1 - ) ** ) + =n
@ -202,9 +185,9 @@ func strconcat {
"bind args" # "bind args" #
def str2 _string =str2 def str2 _string =str2
def str1 _string =str1 def str1 _string =str1
def str 0 _char str1 alen str2 alen + anew =str def str 0 _char str1 alen str2 alen + anew =str
str1 str 0 0 str1 alen acopy str1 str 0 0 str1 alen acopy
str2 str 0 str1 alen str2 alen acopy str2 str 0 str1 alen str2 alen acopy
@ -267,8 +250,8 @@ func strsub {
} }
func puts { func puts {
def str _string =str def str _array =str
1 neg =i def i 1 neg =i
while { ( i 1 + =i ) ( i str alen lt ) } { while { ( i 1 + =i ) ( i str alen lt ) } {
str i aget putchar str i aget putchar
} }
@ -277,7 +260,7 @@ func puts {
func anewput { func anewput {
def size =size def size =size
def arr size anew =arr def arr size anew =arr
def i 0 =i def i 0 =i
while { i size lt } { while { i size lt } {
arr swap i swap aput arr swap i swap aput
@ -328,14 +311,14 @@ func strcontains {
"These functions are magic, they use natives to get recent words and modify the" # "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!" # "variables, do not touch them unless you know exactly what you're doing!" #
func inc { func inc {
def varname 3 _last_word =varname def varname 4 _last_word =varname
pop pop
( varname 1 _layer_call ) "Get var" # ( varname 1 _layer_call ) "Get var" #
1 + "Increment" # 1 + "Increment" #
( "=" varname strconcat 1 _layer_call ) "Store var" # ( "=" varname strconcat 1 _layer_call ) "Store var" #
} }
func dec { func dec {
def varname 3 _last_word =varname def varname 4 _last_word =varname
pop pop
( varname 1 _layer_call ) "Get var" # ( varname 1 _layer_call ) "Get var" #
1 - "Decrement" # 1 - "Decrement" #
@ -343,8 +326,9 @@ func dec {
} }
func random { func random {
getos dup ( "linux" strcontains ) swap ( "macos" strcontains ) or dup if { "file.isbpl" include
"/dev/urandom" _file 1 read getos strlowercase dup ( "linux" strcontains ) swap ( "macos" strcontains ) or dup if {
"/dev/urandom" _file 0 1 read
} }
not if { not if {
"__windows_radom" call "__windows_radom" call
@ -361,6 +345,7 @@ func strlowercase {
} }
i inc i inc
} }
s
} }
func struppercase { func struppercase {
@ -373,4 +358,5 @@ func struppercase {
} }
i inc i inc
} }
s
} }