Alpha Chen 2 years ago
parent b23936ade6
commit a944813d0d

@ -0,0 +1,23 @@
require_relative "environment"
module Lox
class Function
def initialize(decl)
@decl = decl
end
def arity = @decl.params.size
def call(interpreter, args)
env = Environment.new(interpreter.globals)
@decl.params.map(&:lexeme).zip(args).each do |name, value|
env.define(name, value)
end
interpreter.execute_block(@decl.body, env)
nil
end
def to_s = "<fn #{@decl.name.lexeme}>"
end
end
Loading…
Cancel
Save