Class: Lolcode::VM
Instance Attribute Summary collapse
-
#block_level ⇒ Object
Returns the value of attribute block_level.
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#started ⇒ Object
Returns the value of attribute started.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#flush ⇒ Object
Flush the buffer.
-
#initialize(options = {}) ⇒ VM
constructor
A new instance of VM.
- #run(line) ⇒ Object
- #started? ⇒ Boolean
Methods included from Translator
Constructor Details
#initialize(options = {}) ⇒ VM
Returns a new instance of VM.
9 10 11 12 13 14 |
# File 'lib/lolcode/vm.rb', line 9 def initialize(={}) reset_all $stdout.sync = true $stderr.sync = true self.verbose = [:verbose] || false end |
Instance Attribute Details
#block_level ⇒ Object
Returns the value of attribute block_level.
7 8 9 |
# File 'lib/lolcode/vm.rb', line 7 def block_level @block_level end |
#buffer ⇒ Object
Returns the value of attribute buffer.
7 8 9 |
# File 'lib/lolcode/vm.rb', line 7 def buffer @buffer end |
#started ⇒ Object
Returns the value of attribute started.
7 8 9 |
# File 'lib/lolcode/vm.rb', line 7 def started @started end |
#verbose ⇒ Object
Returns the value of attribute verbose.
7 8 9 |
# File 'lib/lolcode/vm.rb', line 7 def verbose @verbose end |
Instance Method Details
#flush ⇒ Object
Flush the buffer
49 50 51 |
# File 'lib/lolcode/vm.rb', line 49 def flush run('') end |
#run(line) ⇒ Object
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 41 42 43 44 45 46 |
# File 'lib/lolcode/vm.rb', line 16 def run(line) puts "[INFO] Orig line: #{line}" if self.verbose (start; return) if line =~ /^HAI\b.*/ # start VM (halt; return) if line =~ /^KTHXBYE\b.*/ # halt VM return unless started? # TODO: comma in the string shouldn't be splited ruby_line = line.split(',').collect do |l| translate(l) end.join(';') puts "[INFO] Ruby code: #{ruby_line}" if self.verbose self.buffer << ruby_line return if open_block? res = nil begin puts "[INFO] Eval code: #{self.buffer}" if self.verbose res = eval self.buffer reset_buffer rescue puts "[ERROR] Exec Error: #{line}" end $stdout.flush $stderr.flush res end |
#started? ⇒ Boolean
53 54 55 |
# File 'lib/lolcode/vm.rb', line 53 def started? self.started end |