Sha256: 7facc6edd4e05354d46372656424b487a3fa914427bb3636ee09c1ecccfd899e

Contents?: true

Size: 1000 Bytes

Versions: 3

Compression:

Stored size: 1000 Bytes

Contents

module Nydp
  class AssignmentInstruction
    attr_accessor :name

    def initialize name
      @name = name
    end

    def execute vm
      @name.assign vm.peek_arg, vm.current_context
    end

    def to_s
      "#assign #{@name}"
    end
  end

  class Assignment
    include Helper

    def self.build args, bindings
      name = Compiler.compile args.car, bindings
      raise "can't assign to #{name.inspect} : expression was #{args}" unless name.respond_to?(:assign)
      value_expr = args.cdr.car
      Assignment.new name, Compiler.compile(value_expr, bindings), value_expr
    end

    def initialize name, value, value_src
      @value_src = value_src
      n = AssignmentInstruction.new name
      @instructions = cons(value, cons(n))
    end

    def to_s
      "(assign #{@instructions.cdr.car.name} #{@value_src.inspect})"
    end

    def inspect; to_s ; end

    def execute vm
      vm.instructions.push @instructions
      vm.contexts.push vm.current_context
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nydp-0.3.0 lib/nydp/assignment.rb
nydp-0.2.6 lib/nydp/assignment.rb
nydp-0.2.5 lib/nydp/assignment.rb