Class: Minjs::ECMA262::LexEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/minjs/ecma262/env.rb

Overview

class of Lexical Environment

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LexEnv

Returns a new instance of LexEnv.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/minjs/ecma262/env.rb', line 58

def initialize(options = {})
  @outer = options[:outer]
  @type = (options[:type] || :declarative)
  if options[:record]
    @record = ObjectEnvRecord.new
  elsif options[:type] == :declarative
    @record = DeclarativeEnvRecord.new
  elsif options[:type] == :object or true
    @record = ObjectEnvRecord.new
  end
end

Instance Attribute Details

#outerObject (readonly)

Returns the value of attribute outer.



55
56
57
# File 'lib/minjs/ecma262/env.rb', line 55

def outer
  @outer
end

#recordObject

Returns the value of attribute record.



54
55
56
# File 'lib/minjs/ecma262/env.rb', line 54

def record
  @record
end

#typeObject (readonly)

Returns the value of attribute type.



56
57
58
# File 'lib/minjs/ecma262/env.rb', line 56

def type
  @type
end

Class Method Details

.new_declarative_env(e) ⇒ Object

NewDeclarativeEnvironment(E)

See Also:



80
81
82
# File 'lib/minjs/ecma262/env.rb', line 80

def self.new_declarative_env(e)
  env = LexEnv.new(outer: e, type: :declarative)
end

Instance Method Details

#debugObject

debug



99
100
101
# File 'lib/minjs/ecma262/env.rb', line 99

def debug
  STDERR.puts @record.binding.keys.join(", ")
end

#new_declarative_env(outer = nil) ⇒ Object

NewDeclarativeEnvironment(E)

See Also:



73
74
75
# File 'lib/minjs/ecma262/env.rb', line 73

def new_declarative_env(outer = nil)
  e = LexEnv.new(outer: (outer || self), type: :declarative)
end

#new_object_env(object, outer = nil) ⇒ Object

NewObjectEnvironment(O, E)

See Also:



87
88
89
90
91
92
93
94
95
96
# File 'lib/minjs/ecma262/env.rb', line 87

def new_object_env(object, outer = nil)#TODO
  raise 'TODO'
  e = LexEnv.new(outer: (outer || self), type: :object)
  object.val.each do |k, v|
    if k.id_name?
      e.create_mutable_binding(k)
      e.set_mutable_binding(k, v)
    end
  end
end