From 97e3b4a9d7e995848341e53b2c002930c85d5c47 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 7 Sep 2022 00:05:23 +1200 Subject: Parser + boilerplate for Among Us --- src/among_us/program.cr | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/among_us/program.cr (limited to 'src/among_us/program.cr') 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 + -- cgit v1.2.1