12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/hoozuki/vm/evaluator.rb', line 12
def _evaluate(instructions, input, input_pos, pc)
loop do
return false if pc >= instructions.size
inst = instructions[pc]
case inst
when Hoozuki::Instruction::Char
return false if input_pos >= input.size || input[input_pos] != inst.char
input_pos += 1
pc += 1
when Hoozuki::Instruction::Jmp
pc = inst.target
when Hoozuki::Instruction::Split
return true if _evaluate(instructions, input, input_pos, inst.left)
pc = inst.right
when Hoozuki::Instruction::Match
return input_pos == input.length
else
raise "Unknown instruction: #{inst.class}"
end
end
end
|