Class: Rpl

Constant Summary collapse

VERSION =
'0.15.2'

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: 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_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
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_dictionaryObject



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