diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Interpreter.kt b/src/Interpreter.kt
index c2b2424..b507fab 100644
--- a/src/Interpreter.kt
+++ b/src/Interpreter.kt
@@ -1,4 +1,4 @@
-class Interpreter {
+class Interpreter(val code: String) {
class BslFunction(val name: String, val pos: Int)
var error = false
@@ -7,11 +7,13 @@ class Interpreter {
val key_fun = '#'
val key_comment = '?'
+ val key_pattern = '!'
+ val key_pattern_seperator = ':'
val key_opening_bracket = '{'
val key_closing_bracket = '}'
val key_section_marker = '"'
- val fun_typ_pattern = "pattern"
+ val fun_typ_pattern = "fun"
val fun_typ_main = "main"
val fun_stat_place_cube = "Cube"
@@ -21,9 +23,11 @@ class Interpreter {
val args_seperator = ','
- var code = "#pattern test (runs, arg,) {Cube (1.0, 3, 5,)} #main () {test (1, \"Hello there\",) Cube (1.2, 3, 6,)}"
var pos = 0
+ var currentOffset = 0.0
+ var inverted = false
+
fun placeCube(timestamp: Double, type: Int, value: Int) {
System.out.println("Cube placed: " + timestamp + " " + type + " " + value)
}
@@ -80,26 +84,42 @@ class Interpreter {
return argsList.toTypedArray()
}
- fun executeFun(my_pos: Int) {
+ fun executeFun(my_pos: Int, agrsNames: Array, args: Array) {
val old_pos = pos
pos = my_pos
- gotoNext(fun_opening_bracket)
- //This time we just need the names for interpretation purposes
- val agrsNames = popArgs()
-
gotoNext(key_opening_bracket)
-
+ jumpSpaces()
while (code[pos] != key_closing_bracket) {
- jumpSpaces()
-
if (code[pos] == key_comment) {
gotoNext(key_comment)
+ } else if (code[pos] == key_pattern) {
+ pos++
+ val timestamp = popNextWord(key_pattern_seperator)
+ val t_inverted = popNextWord(key_pattern_seperator)
+ val runs = popNextWord(' ').toInt() - 1
+
+ val oldOffset = currentOffset
+ currentOffset += timestamp.toDouble()
+
+ val oldInverted = inverted
+ inverted = t_inverted.toBoolean()
+
+ for (i in 0..runs) {
+ executeFun(pos, arrayOf("p_timestamp", "p_inverted", "p_total_runs", "p_current_run_index"), arrayOf(timestamp, t_inverted, runs.toString(), i.toString()))
+ }
+
+ gotoNext(key_closing_bracket)
+
+ currentOffset = oldOffset
+ inverted = oldInverted
} else {
val fun_call = popNextWord(' ')
gotoNext(fun_opening_bracket)
callFunction(fun_call, popArgs())
}
+
+ jumpSpaces()
}
pos = old_pos
@@ -113,7 +133,14 @@ class Interpreter {
for (this_fun in functions) {
if (this_fun.name == name) {
- executeFun(this_fun.pos)
+ val old_pos = pos
+ pos = this_fun.pos
+
+ val argsNames = popArgs()
+
+ pos = old_pos
+
+ executeFun(this_fun.pos, argsNames, args)
break
}
}
@@ -132,7 +159,8 @@ class Interpreter {
functions.add(BslFunction(functionName, pos))
gotoNext(key_closing_bracket)
} else if (fun_typ == fun_typ_main) {
- executeFun(pos)
+ //We don't need any args for the main function
+ executeFun(pos, Array(0, { i -> ""}), Array(0, { i -> ""}))
return
}
} else if (code[pos] == key_comment) {
diff --git a/src/Main.kt b/src/Main.kt
index 4ca4e3c..4b38c89 100644
--- a/src/Main.kt
+++ b/src/Main.kt
@@ -1,5 +1,17 @@
+import java.io.File
+
fun main(args: Array) {
- val interpreter = Interpreter()
+ val code = StringBuilder()
+ val path = ClassLoader.getSystemResource("test.bml")
+
+ val raw_code = File(path.toURI()).bufferedReader().readLines()
+
+ for (str in raw_code) {
+ code.append(" ")
+ code.append(str)
+ }
+
+ val interpreter = Interpreter(code.toString())
interpreter.interpret()
}
\ No newline at end of file
diff --git a/src/test.bml b/src/test.bml
new file mode 100644
index 0000000..b4f7d85
--- /dev/null
+++ b/src/test.bml
@@ -0,0 +1,15 @@
+#fun test () {
+ Cube (1.0, 3, 5,)
+ Cube (1.1, 2, 3,)
+ Cube (1.4, 5, 3,)
+}
+
+#fun test_two () {
+ Cube (1.2, 6, 6,)
+}
+
+#main () {
+ test_two ()
+ Cube (1.2, 3, 6,)
+ !24.6:false:4 {test ()}
+}
\ No newline at end of file