Sha256: ee8d91bfcc1ddbbd9b881f9ccaed45cb3f5fea48db075406b433dd30c3b16af3

Contents?: true

Size: 468 Bytes

Versions: 4

Compression:

Stored size: 468 Bytes

Contents

# Represents a method defined in the runtime.
class SweetMethod
  def initialize(params, body)
    @params = params
    @body = body
  end
  
  def call(receiver, arguments)
    # Create a context of evaluation in which the method will execute.
    context = Context.new(receiver)
    
    # Assign arguments to local variables
    @params.each_with_index do |param, index|
      context.locals[param] = arguments[index]
    end
    
    @body.eval(context)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sweet-lang-0.3.7 lib/runtime/method.rb
sweet-lang-0.2.2 lib/runtime/method.rb
sweet-lang-0.1.9 lib/runtime/method.rb
sweet-lang-0.1.0 lib/runtime/method.rb