Class: Klam::Environment
- Inherits:
- BasicObject
- Includes:
- Primitives::Arithmetic, Primitives::Assignments, Primitives::BooleanOperations, Primitives::ErrorHandling, Primitives::GenericFunctions, Primitives::Interop, Primitives::Lists, Primitives::Streams, Primitives::Strings, Primitives::Symbols, Primitives::Time, Primitives::Vectors
- Defined in:
- lib/klam/environment.rb
Constant Summary
Constants included from Primitives::Lists
Class Method Summary collapse
Instance Method Summary collapse
- #__apply(rator, *rands) ⇒ Object
- #__arity(sym) ⇒ Object
- #__method(sym) ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
Methods included from Primitives::Interop
#rb_const, #rb_send, #rb_send_block, uncurry
Methods included from Primitives::Arithmetic
#*, #+, #-, #/, #<, #<=, #>, #>=, #number?
Methods included from Primitives::Time
Methods included from Primitives::Streams
#close, #open, #read_byte, #write_byte
Methods included from Primitives::Vectors
#absvec_read, #absvec_store, #absvector, #absvector?
Methods included from Primitives::GenericFunctions
Methods included from Primitives::Lists
Methods included from Primitives::ErrorHandling
#error_to_string, #simple_error
Methods included from Primitives::Assignments
Methods included from Primitives::Strings
#cn, #n_to_string, #pos, #str, #string?, #string_to_n, #tlstr
Methods included from Primitives::Symbols
Methods included from Primitives::BooleanOperations
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/klam/environment.rb', line 16 def initialize # The global assignments namespace. Errors are thrown here in the # missing element handler rather than in the value primitive in order # to facilitate inlining later. @assignments = ::Hash.new do |_, name| ::Kernel.raise ::Klam::Error, "The variable #{name} is unbound." end @arities = ::Hash.new { |h, k| h[k] = __arity(k) } @curried_methods = ::Hash.new { |h, k| h[k] = __method(k).to_proc.curry } @loop_cache = {} # Grab a handle to this object's eigenclass for use later when the # compiled code needs to reference it. It is used, e.g., when renaming # methods. @eigenclass = class << self; self; end @compiler = ::Klam::Compiler.new(self) # The open primitive depends on having *home-directory* assigned. set(:"*home-directory*", ::Dir.pwd) set(:"*dump-kl*", false) set(:"*dump-rb*", false) set(:"*include-backtrace-in-error-string*", false) end |
Class Method Details
.rename_method(old_name, new_name) ⇒ Object
61 62 63 64 |
# File 'lib/klam/environment.rb', line 61 def rename_method(old_name, new_name) alias_method(new_name, old_name) remove_method(old_name) end |
Instance Method Details
#__apply(rator, *rands) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/klam/environment.rb', line 42 def __apply(rator, *rands) if rator.kind_of?(::Symbol) @curried_methods[rator].call(*rands) else rator.call(*rands) end end |
#__arity(sym) ⇒ Object
54 55 56 57 58 |
# File 'lib/klam/environment.rb', line 54 def __arity(sym) @eigenclass.instance_method(sym).arity rescue ::NameError -1 end |
#__method(sym) ⇒ Object
50 51 52 |
# File 'lib/klam/environment.rb', line 50 def __method(sym) @eigenclass.instance_method(sym).bind(self) end |