blob: b75ad1c5ee51edc0794825ebea60e5e4021f8254 (
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
|
require "./*"
module Brainfuck
DEFAULT_TAPE_SIZE = 30_000
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
|