Sha256: cc15cfe4fc6641eaf1f7f073c07a408d55d904e0e170a9e43dee4345f3448d03

Contents?: true

Size: 740 Bytes

Versions: 4

Compression:

Stored size: 740 Bytes

Contents

# The evaluation context.
class Context
  attr_reader :locals, :current_self, :current_class
  
  # We store constants as class variable (class variables start with @@ and instance
  # variables start with @ in Ruby) since they are globally accessible. If you want to
  # implement namespacing of constants, you could store it in the instance of this 
  # class.
  @@constants = {}
  
  def initialize(current_self, current_class=current_self.runtime_class)
    @locals = {}
    @current_self = current_self
    @current_class = current_class
  end
  
  # Shortcuts to access constants, Runtime[...] instead of Runtime.constants[...]
  def [](name)
    @@constants[name]
  end
  def []=(name, value)
    @@constants[name] = value
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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