Class: Twostroke::Context
- Inherits:
-
Object
- Object
- Twostroke::Context
- Defined in:
- lib/twostroke/context.rb,
lib/twostroke/context/object_proxy.rb
Defined Under Namespace
Classes: ObjectProxy
Instance Attribute Summary collapse
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
- #[](var) ⇒ Object
- #eval(src) ⇒ Object
- #exec(src) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #inspect ⇒ Object
- #raw_eval(src) ⇒ Object
- #raw_exec(src) ⇒ Object
Constructor Details
Instance Attribute Details
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
3 4 5 |
# File 'lib/twostroke/context.rb', line 3 def vm @vm end |
Instance Method Details
#[](var) ⇒ Object
11 12 13 |
# File 'lib/twostroke/context.rb', line 11 def [](var) vm.global_scope.get_var(var.intern).to_ruby end |
#eval(src) ⇒ Object
24 25 26 |
# File 'lib/twostroke/context.rb', line 24 def eval(src) raw_eval(src + ";").to_ruby end |
#exec(src) ⇒ Object
35 36 37 |
# File 'lib/twostroke/context.rb', line 35 def exec(src) raw_exec(src).to_ruby end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/twostroke/context.rb', line 39 def inspect to_s end |
#raw_eval(src) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/twostroke/context.rb', line 15 def raw_eval(src) prefix = make_prefix bytecode = compile src, prefix main = :"#{prefix}main" bytecode[main][-2] = [:ret] vm.bytecode.merge! bytecode vm.execute main, vm.global_scope.close end |
#raw_exec(src) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/twostroke/context.rb', line 28 def raw_exec(src) prefix = make_prefix bytecode = compile src, prefix vm.bytecode.merge! bytecode vm.execute :"#{prefix}_main" end |