Created
October 4, 2018 10:15
-
-
Save duangsuse/d8f97d736f0d6366ff101b962507cff4 to your computer and use it in GitHub Desktop.
Useless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BiwaScheme VM Implementation | |
class BiwaVM | |
DEBUG = true | |
def dputs(m) | |
puts(m) if DEBUG | |
end | |
def initialize | |
@value = nil | |
@closureStack = [] | |
@stack = [] | |
@callStack = [] | |
@tcoCounter = [] | |
end | |
def constant(value, opcodes) | |
dputs "Const #{value}" | |
@value = value | |
interpret(opcodes) | |
end | |
def argument(opcodes) | |
dputs "Push #{@value}" | |
stack << @value | |
interpret(opcodes) | |
end | |
def test(thenb, elseb) | |
dputs "Branch if #{@value}" | |
end | |
def close(nfree, body, nextc, dotpos) | |
dputs "Closure #{nfree}, #{dotpos}: #{body}" | |
end | |
def conti(n, nextc) | |
dputs "Continuation popargs #{n}" | |
end | |
def nuate(stack, nextc) | |
dputs "Using state #{stack}" | |
end | |
def halt | |
dputs "Halt" | |
end | |
def frame(nextc, body) | |
dputs "Frame" | |
end | |
def apply | |
dputs "Apply stack #{@stack}" | |
end | |
def tco_hinted_apply | |
dputs "TcoApply stack #{@stack}" | |
end | |
def return | |
dputs "Return" | |
end | |
def shift(nargs, nextc) | |
dputs "Shift #{nargs}" | |
end | |
def refer4local(pos, nextc) | |
end | |
def refer4free(pos, nextc) | |
end | |
def refer4global(name, nextc) | |
end | |
def assign4local(pos, nextc) | |
end | |
def assign4free(pos, nextc) | |
end | |
def assign4global(name, nextc) | |
end | |
def box(pos, nextc) | |
end | |
def indirect(nextc) | |
end | |
def interpret(ary) | |
raise ArgumentError, 'Expression should not be blank' unless ary.any? | |
if DEBUG | |
puts "Sending #{ary[1..ary.size]} to #{ary[0]}..." | |
end | |
return send(ary[0], ary[1..ary.size]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment