Class: Rpl

Constant Summary collapse

VERSION =
'0.16.1'

Instance Attribute Summary collapse

Attributes inherited from Interpreter

#dictionary, #frame_buffer, #precision, #stack, #version

Instance Method Summary collapse

Methods included from Types

new_object

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:, dictionary: )

  @persistence_filename = persistence_filename
  @live_persistence = live_persistence

  populate_dictionary if @dictionary.words.empty?

  load_persisted_state!
end

Instance Attribute Details

#live_persistenceObject

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_stateObject


37
38
39
40
41
# File 'lib/rpl.rb', line 37

def persist_state
  return if @persistence_filename.nil?

  File.write(@persistence_filename, "#{export_vars}\n#{export_stack}")
end

#populate_dictionaryObject


71
# File 'lib/rpl.rb', line 71

def populate_dictionary; end

#run!(input) ⇒ Object


43
44
45
46
47
48
49
# File 'lib/rpl.rb', line 43

def run!( input )
  stack = super( input )

  persist_state if @live_persistence

  stack
end