Skip to content

Instantly share code, notes, and snippets.

@jamie
Last active August 29, 2015 14:26
Show Gist options
  • Save jamie/17affafeadbcd2211883 to your computer and use it in GitHub Desktop.
Save jamie/17affafeadbcd2211883 to your computer and use it in GitHub Desktop.
class Um
def initialize(program, key = "")
@array = [] of Array
@register = [0_u32] * 8
@finger = 0_u32
@a = @b = @c = @z = @value = 0_u32
@array << program
end
def spin(stopchar = nil)
loop do
platter = @array[0][@finger] as UInt32
opcode = (platter >> 28) & 0xF
case opcode
when 2; array_amendment
end
end
end
def array_amendment
# $a[$b] = $c
a = @register[@a]
b = @register[@b]
c = @register[@c]
# Array is an array of arrays of UInt32
# puts @array[a].class #=> Array(UInt32)
# puts @array[a][b]class #=> UInt32
# puts c.class #=> UInt32
@array[a][b] = c
# in ./crystal/um.cr:32: no overload matches 'Array(Fiber)#[]=' with types UInt32, UInt32
# Overloads are:
# - Array(Fiber)#[]=(index : Int, value : Fiber)
end
end
program = [0_u32]
Um.new(program).spin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment