|
|
@ -2,14 +2,14 @@ require_relative "environment"
|
|
|
|
|
|
|
|
|
|
|
|
module Lox
|
|
|
|
module Lox
|
|
|
|
class Function
|
|
|
|
class Function
|
|
|
|
def initialize(decl)
|
|
|
|
def initialize(decl, closure)
|
|
|
|
@decl = decl
|
|
|
|
@decl, @closure = decl, closure
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def arity = @decl.params.size
|
|
|
|
def arity = @decl.params.size
|
|
|
|
|
|
|
|
|
|
|
|
def call(interpreter, args)
|
|
|
|
def call(interpreter, args)
|
|
|
|
env = Environment.new(interpreter.globals)
|
|
|
|
env = Environment.new(@closure)
|
|
|
|
@decl.params.map(&:lexeme).zip(args).each do |name, value|
|
|
|
|
@decl.params.map(&:lexeme).zip(args).each do |name, value|
|
|
|
|
env.define(name, value)
|
|
|
|
env.define(name, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|