Class: Rpl
- Inherits:
-
Interpreter
- Object
- Interpreter
- Rpl
- Includes:
- RplLang::Words::Branch, RplLang::Words::Display, RplLang::Words::FileSystem, RplLang::Words::General, RplLang::Words::List, RplLang::Words::Logarithm, RplLang::Words::Mode, RplLang::Words::OperationsComplexes, RplLang::Words::OperationsReals, RplLang::Words::OperationsRealsAndComplexes, RplLang::Words::Program, RplLang::Words::REPL, RplLang::Words::Stack, RplLang::Words::Store, RplLang::Words::String, RplLang::Words::StringAndList, RplLang::Words::Test, RplLang::Words::TimeAndDate, RplLang::Words::Trig, Types
- Defined in:
- lib/rpl.rb
Constant Summary collapse
- VERSION =
'0.15.2'
Instance Attribute Summary collapse
-
#live_persistence ⇒ Object
Returns the value of attribute live_persistence.
Attributes inherited from Interpreter
#dictionary, #frame_buffer, #precision, #stack, #version
Instance Method Summary collapse
-
#initialize(stack: [], dictionary: Dictionary.new, persistence_filename: nil, live_persistence: true) ⇒ Rpl
constructor
A new instance of Rpl.
- #load_persisted_state! ⇒ Object
- #persist_state ⇒ Object
- #populate_dictionary ⇒ Object
- #run!(input) ⇒ Object
Methods included from Types
Methods inherited from Interpreter
#export_stack, #export_vars, #initialize_frame_buffer, #stack_extract
Constructor Details
#initialize(stack: [], dictionary: Dictionary.new, persistence_filename: nil, live_persistence: true) ⇒ Rpl
Returns a new instance of Rpl.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rpl.rb', line 14 def initialize( stack: [], dictionary: Dictionary.new, persistence_filename: nil, live_persistence: true ) super( stack: stack, dictionary: dictionary ) @persistence_filename = persistence_filename @live_persistence = live_persistence populate_dictionary if @dictionary.words.empty? load_persisted_state! end |
Instance Attribute Details
#live_persistence ⇒ Object
Returns the value of attribute live_persistence.
12 13 14 |
# File 'lib/rpl.rb', line 12 def live_persistence @live_persistence end |
Instance Method Details
#load_persisted_state! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/rpl.rb', line 28 def load_persisted_state! return if @persistence_filename.nil? FileUtils.mkdir_p( File.dirname( @persistence_filename ) ) FileUtils.touch( @persistence_filename ) run!( "\"#{@persistence_filename}\" feval" ) end |
#persist_state ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rpl.rb', line 37 def persist_state return if @persistence_filename.nil? File.open( @persistence_filename, 'w' ) do |persistence_file| persistence_file.write "#{export_vars}\n#{export_stack}" end end |
#populate_dictionary ⇒ Object
73 |
# File 'lib/rpl.rb', line 73 def populate_dictionary; end |
#run!(input) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rpl.rb', line 45 def run!( input ) stack = super persist_state if @live_persistence stack end |