summaryrefslogtreecommitdiff
path: root/src/among_us/program.cr
blob: a54f24b438ddb49abe542da7df0af5318e90ea08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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