From 4ccdad44a6d38c6fead39331ee431a9f0c9ce8e9 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 5 Feb 2022 21:20:51 +0100 Subject: [PATCH] General update - NONFUNCTIONAL --- bootstrap/isbpl.js | 0 isbpl.isbpl | 26 +++++++ std.isbpl | 183 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 bootstrap/isbpl.js create mode 100644 isbpl.isbpl create mode 100644 std.isbpl diff --git a/bootstrap/isbpl.js b/bootstrap/isbpl.js new file mode 100644 index 0000000..e69de29 diff --git a/isbpl.isbpl b/isbpl.isbpl new file mode 100644 index 0000000..0ac5042 --- /dev/null +++ b/isbpl.isbpl @@ -0,0 +1,26 @@ + +"" =insns + +func main { # entry point returning int + =args # put arg array into args var + args 0 aget =file + + # Start compile + filename _file compile + + 0 +} + +func append { + =str + insns str strconcat "\n" strconcat =insns +} + +func pushElement { + # bind args + =x + =type + + "PUSH " type _string_string strconcat append + "PUSH " x strconcat append +} diff --git a/std.isbpl b/std.isbpl new file mode 100644 index 0000000..1ca198d --- /dev/null +++ b/std.isbpl @@ -0,0 +1,183 @@ +native func alen +native func aget +native func aput +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 +native func type +native func mktype +native func call +native func typename +native func throw +# try and catch are keywords, not functions +native func stlen + +"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 { + 0 _char stlen ~ 0 _char _array =object + } + 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 mkarr { + =o + =size + o stlen 4 + size * 4 + ~ _array +} + +func itos { + ntos +} + +func ltos { + ntos +} + +func ftos { + ntos +} + +func dtos { + ntos +} + +func ntos { + "" =s + =n + + n type =thetype + + while n 0 eq not { + n (n 10 % dup =x) - =n + s (n '0' + _char) strconcat =s + } + + s +} + +func acopy { + # bind args + =len + =idx2 + =idx1 + =arr2 + =arr1 + + 0 =i + while (i len st) (i 1 + =i) { + arr2 i idx2 + (arr1 i idx1 + aget) aput + } +} + +func strconcat { + # bind args + _string =str2 + _string =str1 + + str1 alen str2 alen 0 _char mkarr = str + + 0 =i + while (str1 alen i gt) (i 1 + =i) { + str i (str1 i aget) aput + } + 0 =i + while (str2 alen i gt) (i 1 + =i) { + str (i str1 alen +) (str2 i aget) aput + } + + str +} + +func strsplit { + # bind args + _string =str + _string =splitter + + 0 =i + 0 =j + "" 0 mkarr =sequences + while (i str alen st) (i 1 + =1) { + str i aget =chr + splitter 0 aget =spl + while (chr spl eq) (j 1 + =j) { + (str i j + aget) (splitter j aget) eq not if { + sequences =oldsq + "" (seq dup =lseq 1 + dup =seq) mkarr =sequences + oldsq sequences 0 0 oldsq alen acopy + sequences lseq + } + } + } +} + +func puts { + _string =str + 0 =i + while (i str alen st) (i 1 + =i) { + str i aget putchar + } +}