blob: 819fe8e69b998344ff4962b73195677cde7f5aab (
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 "./*"
module Brainfuck
DEFAULT_TAPE_SIZE = 30_000
class MemoryError < Exception
end
enum Opcode
PtrRight
PtrLeft
Inc
Dec
Out
In
LoopStart
LoopEnd
end
def self.opcode_from_char(c : Char) : Opcode?
case c
when '>' then Opcode::PtrRight
when '<' then Opcode::PtrLeft
when '+' then Opcode::Inc
when '-' then Opcode::Dec
when '.' then Opcode::Out
when ',' then Opcode::In
when '[' then Opcode::LoopStart
when ']' then Opcode::LoopEnd
else nil
end
end
end
|