summaryrefslogtreecommitdiff
path: root/src/among_us/program.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-07 00:05:23 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-07 00:05:23 +1200
commit97e3b4a9d7e995848341e53b2c002930c85d5c47 (patch)
tree45299ac50115bc3cc87f546cbbc8ba7519813a61 /src/among_us/program.cr
parentb5aecfbd9d32bf894ab82d7b594f91a5f59acb2a (diff)
Parser + boilerplate for Among Us
Diffstat (limited to 'src/among_us/program.cr')
-rw-r--r--src/among_us/program.cr34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/among_us/program.cr b/src/among_us/program.cr
new file mode 100644
index 0000000..a54f24b
--- /dev/null
+++ b/src/among_us/program.cr
@@ -0,0 +1,34 @@
+require "big"
+
+struct AmongUs::Program < Flint::Program
+ def interpret : Nil
+ code = Parser.new(@source_io).parse
+ jumps = find_jumps(code)
+
+ stack = [] of BigInt
+ acc1 = BigInt.new
+ acc2 = BigInt.new
+ color = code.find &.is_a?(Color)
+
+ puts code
+ puts jumps
+ end
+
+ private def find_jumps(code : Array(Instruction)) : Hash(Int32, Int32)
+ jumps = {} of Int32 => Int32
+ stack = [] of Int32
+
+ code.each_index do |i|
+ case code[i]
+ when Command::WHO
+ stack << i
+ when Command::WHERE
+ jumps[i] = stack.pop
+ jumps[jumps[i]] = i
+ end
+ end
+
+ return jumps
+ end
+end
+