f_dot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +159 -0
- data/LICENSE.txt +21 -0
- data/README.md +18 -0
- data/Rakefile +5 -0
- data/bin/f_dot +17 -0
- data/checksums/f_dot-0.0.1.gem.sha512 +1 -0
- data/craft_setup.sh +9 -0
- data/deserialization_testing.rb +43 -0
- data/f_dot.gemspec +43 -0
- data/lib/f_dot/.DS_Store +0 -0
- data/lib/f_dot/based.rb +85 -0
- data/lib/f_dot/history.rb +157 -0
- data/lib/f_dot/instruction.rb +122 -0
- data/lib/f_dot/interface.rb +180 -0
- data/lib/f_dot/processor.rb +265 -0
- data/lib/f_dot/program.rb +471 -0
- data/lib/f_dot/variable.rb +149 -0
- data/lib/f_dot/version.rb +8 -0
- data/lib/f_dot.rb +35 -0
- data/oss_om_plugin.rb +56 -0
- data/tasks/console.rake +8 -0
- data/tasks/make.rake +4 -0
- metadata +188 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
instruction.rb
|
|
6
|
+
|
|
7
|
+
f_dot instruction.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
|
|
16
|
+
class Instruction
|
|
17
|
+
attr_accessor :uuid
|
|
18
|
+
attr_accessor :program_uuid
|
|
19
|
+
attr_accessor :variable_uuids
|
|
20
|
+
attr_accessor :domain
|
|
21
|
+
attr_accessor :compiled_domain
|
|
22
|
+
attr_accessor :compiler_variable_uuid
|
|
23
|
+
|
|
24
|
+
def initialize(program_uuid, variable_uuids = [])
|
|
25
|
+
self.uuid = FDot::Based.generate_uuid
|
|
26
|
+
self.program_uuid = program_uuid
|
|
27
|
+
self.variable_uuids = variable_uuids
|
|
28
|
+
self.domain = FDot::DOMAINS[:processor]
|
|
29
|
+
self.compiled_domain = nil
|
|
30
|
+
self.compiler_variable_uuid = nil
|
|
31
|
+
program_instance.instructions[self.uuid] = self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def ordinal
|
|
35
|
+
program_instance.variables[variable_uuids.first].ordinal
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def domain_key
|
|
39
|
+
FDot::Based::Variable.domain_key_for(self.domain)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_s
|
|
43
|
+
# todo: unicodeify
|
|
44
|
+
"<#{variable_uuids.map{|v| program_instance.variables[v].to_s}.sort.join(":")}>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def program_instance
|
|
48
|
+
FDot.state[:program].uuid == self.program_uuid ? FDot.state[:program] : FDot.state[:completed_programs][self.program_uuid]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def combine_with_instruction(to_combine_instruction)
|
|
52
|
+
self.variable_uuids += to_combine_instruction.variable_uuids
|
|
53
|
+
to_combine_instruction.variable_uuids = []
|
|
54
|
+
# remove to_combine_instruction from the env
|
|
55
|
+
FDot.state[:instructions].delete(to_combine_instruction.uuid)
|
|
56
|
+
FDot.state[:program].history.delete(to_combine_instruction.uuid)
|
|
57
|
+
FDot.state[:program].instructions.delete(to_combine_instruction.uuid)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def history_menu_options
|
|
61
|
+
[
|
|
62
|
+
:uuid,
|
|
63
|
+
:program_uuid,
|
|
64
|
+
:variable_uuids,
|
|
65
|
+
:domain_key,
|
|
66
|
+
:ordinal,
|
|
67
|
+
:compiled_domain,
|
|
68
|
+
:compiler_variable_uuid
|
|
69
|
+
].each{|attribute|
|
|
70
|
+
implementation_notes = ""
|
|
71
|
+
if [:compiled_domain, :compiler_variable_uuid].include?(attribute)
|
|
72
|
+
implementation_notes = "todo: #{attribute} is not implemented."
|
|
73
|
+
end
|
|
74
|
+
{
|
|
75
|
+
name: "#{attribute}: #{self.send(attribute) || nil.to_s}#{implementation_notes}",
|
|
76
|
+
value: attribute
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def compute_serialized_state!
|
|
82
|
+
serialized_state = {
|
|
83
|
+
name: self.to_s
|
|
84
|
+
}
|
|
85
|
+
FDot::Based::Instruction.serialization_keys.each{|k|
|
|
86
|
+
serialized_state[k] = self.send(k)
|
|
87
|
+
}
|
|
88
|
+
serialized_state
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def self.deserialize_into!(program, serialized_instruction)
|
|
92
|
+
raise "invalid serialized_instruction! #{serialized_instruction}" unless serialization_keys.all?{|k|
|
|
93
|
+
serialized_instruction.keys.include?(k.to_s)
|
|
94
|
+
}
|
|
95
|
+
instruction_instance = self.new(program.uuid, serialized_instruction["variable_uuids"])
|
|
96
|
+
|
|
97
|
+
raise "missing variable uuid!" if serialized_instruction["uuid"].nil? || serialized_instruction["uuid"].empty?
|
|
98
|
+
|
|
99
|
+
program.instructions.delete(instruction_instance.uuid)
|
|
100
|
+
instruction_instance.uuid = serialized_instruction["uuid"]
|
|
101
|
+
instruction_instance.domain = serialized_instruction["domain"].to_i
|
|
102
|
+
instruction_instance.compiled_domain = serialized_instruction["compiled_domain"]
|
|
103
|
+
instruction_instance.compiler_variable_uuid = serialized_instruction["compiler_variable_uuid"]
|
|
104
|
+
program.instructions[serialized_instruction["uuid"]] = instruction_instance
|
|
105
|
+
|
|
106
|
+
instruction_instance
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
def self.serialization_keys
|
|
112
|
+
[
|
|
113
|
+
:uuid,
|
|
114
|
+
:program_uuid,
|
|
115
|
+
:variable_uuids,
|
|
116
|
+
:domain
|
|
117
|
+
]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
interface.rb
|
|
6
|
+
|
|
7
|
+
f_dot interface.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
class Interface
|
|
16
|
+
include Singleton
|
|
17
|
+
|
|
18
|
+
def self.get_variable_uuid_from_file(variable_file_path)
|
|
19
|
+
raise "invalid variable_file_path! #{variable_file_path}" unless File.exist?(variable_file_path)
|
|
20
|
+
variable_uuid = nil
|
|
21
|
+
begin
|
|
22
|
+
variable_json = JSON.parse(File.read(variable_file_path))
|
|
23
|
+
variable_uuid = variable_json["uuid"]
|
|
24
|
+
rescue StandardError => e
|
|
25
|
+
raise e
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
raise "invalid variable file!" if variable_uuid.nil?
|
|
29
|
+
raise "invalid variable!" unless FDot.state[:program].variables.keys.include?(variable_uuid)
|
|
30
|
+
variable_uuid
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.user_input_options(folder_path = nil)
|
|
34
|
+
folder_path = FDot::Based.f_dot_space_path if folder_path.nil? || !Dir.exist?(folder_path)
|
|
35
|
+
|
|
36
|
+
# get listing for path and return sorted tty-prompt options
|
|
37
|
+
[{name: :f_dot_main_menu, value: :f_dot_main_menu}] + Dir[
|
|
38
|
+
File.join(folder_path, "*")
|
|
39
|
+
].map{|d|
|
|
40
|
+
{name: File.basename(d), value: d}
|
|
41
|
+
}.sort_by{|o|
|
|
42
|
+
sorters = [o[:name]]
|
|
43
|
+
unless File.expand_path(o[:value].gsub(o[:name], "")) == FDot::Based.f_dot_space_path
|
|
44
|
+
sorters << FDot.state[:program].variables[get_variable_uuid_from_file(o[:value])].ordinal
|
|
45
|
+
end
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.open_main_menu?(prompt_select_value)
|
|
50
|
+
if prompt_select_value == :f_dot_main_menu
|
|
51
|
+
self.show_main_menu!
|
|
52
|
+
return true
|
|
53
|
+
else
|
|
54
|
+
return false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.show_main_menu!
|
|
60
|
+
main_menu_open = true
|
|
61
|
+
while main_menu_open
|
|
62
|
+
user_selection = FDot::Based.tty_prompt_select(
|
|
63
|
+
"f_dot_main_menu =>",
|
|
64
|
+
self.main_menu_options.map{|k|
|
|
65
|
+
{name: k, value: k}
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
case user_selection
|
|
70
|
+
when :resume_program
|
|
71
|
+
main_menu_open = false
|
|
72
|
+
when :startup_notes
|
|
73
|
+
puts FDot.state[:program].startup_notes
|
|
74
|
+
when :open_history
|
|
75
|
+
FDot.state[:program].show_history_interface!
|
|
76
|
+
when :open_settings
|
|
77
|
+
FDot::Based::Processor.show_settings_menu!
|
|
78
|
+
when :close_program
|
|
79
|
+
exit if FDot::Based.tty_prompt_select(
|
|
80
|
+
"are you sure?",
|
|
81
|
+
[{name: :back, value: :back}, {name: :i_am_sure, value: :i_am_sure}]
|
|
82
|
+
) == :i_am_sure
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def self.reconfigure_user_space!
|
|
88
|
+
# clear user space
|
|
89
|
+
FileUtils.rm_rf(FDot::Based.f_dot_space_path)
|
|
90
|
+
|
|
91
|
+
# build program data
|
|
92
|
+
FDot.state[:program].build_space!
|
|
93
|
+
|
|
94
|
+
# write user space
|
|
95
|
+
compiler_file_path = File.join(
|
|
96
|
+
FDot::Based.f_dot_space_path,
|
|
97
|
+
:compiler.to_s
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
compiler_data = FDot.state[:program].compiler_contents
|
|
101
|
+
compiler_data[:variables] = compiler_data[:variables].sort
|
|
102
|
+
compiler_data[:instructions] = compiler_data[:instructions].sort
|
|
103
|
+
File.open(compiler_file_path, "w+") do |f|
|
|
104
|
+
f.write(compiler_data.to_json)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
unless FDot.state[:based_uuid].nil?
|
|
108
|
+
# write based variable file
|
|
109
|
+
based_variable = FDot.state[:program].variables[
|
|
110
|
+
FDot.state[:based_uuid]
|
|
111
|
+
]
|
|
112
|
+
based_file_path = File.join(
|
|
113
|
+
FDot::Based.f_dot_space_path,
|
|
114
|
+
based_variable.to_s
|
|
115
|
+
)
|
|
116
|
+
File.open(based_file_path, "w+") do |f|
|
|
117
|
+
f.write({
|
|
118
|
+
uuid: based_variable.uuid
|
|
119
|
+
}.to_json)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# write programmer and user domain folders
|
|
124
|
+
[:programmer, :user].each{|domain_key|
|
|
125
|
+
# get domain folder path
|
|
126
|
+
domain_folder_path = File.join(FDot::Based.f_dot_space_path, domain_key.to_s)
|
|
127
|
+
|
|
128
|
+
# ensure domain folder exists
|
|
129
|
+
FileUtils.mkdir_p(domain_folder_path)
|
|
130
|
+
|
|
131
|
+
# create variable file in domain directory for each variable in the domain
|
|
132
|
+
FDot.state[domain_key][:variables].each{|v|
|
|
133
|
+
variable_instance = FDot.state[:program].variables[v]
|
|
134
|
+
variable_file_path = File.join(
|
|
135
|
+
domain_folder_path,
|
|
136
|
+
domain_key == :user ? variable_instance.to_s : variable_instance.uuid
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# write variable identifier into variable file
|
|
140
|
+
File.open(variable_file_path, "w+") do |f|
|
|
141
|
+
f.write({
|
|
142
|
+
uuid: v
|
|
143
|
+
}.to_json)
|
|
144
|
+
end
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# write processor domain folders
|
|
149
|
+
processor_file_path = File.join(FDot::Based.f_dot_space_path, :processor.to_s)
|
|
150
|
+
File.open(processor_file_path, "w+") do |f|
|
|
151
|
+
f.write({
|
|
152
|
+
variables: FDot.state[:f_dot_queue],
|
|
153
|
+
instructions: FDot.state[:instructions]
|
|
154
|
+
}.to_json)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# write processor serialized_state file
|
|
158
|
+
serialized_state_file_path = File.join(FDot::Based.f_dot_space_path, "processor_state.json")
|
|
159
|
+
File.open(serialized_state_file_path, "w+") do |f|
|
|
160
|
+
f.write(FDot::Based::Processor.instance.serialized_state.to_json)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
return true
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
private
|
|
167
|
+
|
|
168
|
+
def self.main_menu_options
|
|
169
|
+
[
|
|
170
|
+
:resume_program,
|
|
171
|
+
:startup_notes,
|
|
172
|
+
:open_history,
|
|
173
|
+
:open_settings,
|
|
174
|
+
:close_program,
|
|
175
|
+
]
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
processor.rb
|
|
6
|
+
|
|
7
|
+
f_dot processor.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
class Processor
|
|
16
|
+
include Singleton
|
|
17
|
+
|
|
18
|
+
attr_accessor :user_settings
|
|
19
|
+
attr_accessor :serialized_state
|
|
20
|
+
attr_accessor :write_state_callback
|
|
21
|
+
attr_accessor :plugin_mutex
|
|
22
|
+
|
|
23
|
+
DEFAULT_SETTINGS = {
|
|
24
|
+
show_history_logging: false,
|
|
25
|
+
auto_compile_enabled: true,
|
|
26
|
+
debug_inspectors_enabled: false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
self.user_settings = FDot::Based::Processor::DEFAULT_SETTINGS.dup
|
|
31
|
+
self.serialized_state = {}
|
|
32
|
+
self.write_state_callback = nil
|
|
33
|
+
self.plugin_mutex = Mutex.new
|
|
34
|
+
|
|
35
|
+
FDot.state[:completed_programs] = {}
|
|
36
|
+
FDot.state[:program] = nil
|
|
37
|
+
FDot.state[:f_dot_queue] = []
|
|
38
|
+
FDot.state[:instructions] = []
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.serialize_state!
|
|
42
|
+
puts "calling #{self.name}.#{__method__}"
|
|
43
|
+
self.instance.serialized_state = {
|
|
44
|
+
based_uuid: FDot.state[:based_uuid],
|
|
45
|
+
completed_programs: FDot.state[:completed_programs].map{|k, v| v.compute_serialized_state!},
|
|
46
|
+
program: FDot.state[:program].compute_serialized_state!,
|
|
47
|
+
f_dot_queue: FDot.state[:f_dot_queue],
|
|
48
|
+
instructions: FDot.state[:instructions],
|
|
49
|
+
user: {
|
|
50
|
+
variables: FDot.state[:user][:variables] || []
|
|
51
|
+
},
|
|
52
|
+
programmer: {
|
|
53
|
+
variables: FDot.state[:programmer][:variables] || []
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
unless self.instance.write_state_callback.nil?
|
|
58
|
+
self.instance.plugin_mutex.synchronize do
|
|
59
|
+
self.instance.write_state_callback.call(
|
|
60
|
+
self.instance.serialized_state
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.initialize_with_data(plugin_data = {})
|
|
67
|
+
return self.run unless plugin_data.kind_of?(Hash) &&
|
|
68
|
+
!plugin_data.empty?
|
|
69
|
+
|
|
70
|
+
new_serialized_state = {}
|
|
71
|
+
|
|
72
|
+
[
|
|
73
|
+
:based_uuid,
|
|
74
|
+
:f_dot_queue,
|
|
75
|
+
:instructions,
|
|
76
|
+
:program,
|
|
77
|
+
:user,
|
|
78
|
+
:programmer,
|
|
79
|
+
:completed_programs
|
|
80
|
+
].each{|k|
|
|
81
|
+
k = k.to_sym
|
|
82
|
+
|
|
83
|
+
new_serialized_state[k] = plugin_data[k.to_s]
|
|
84
|
+
if new_serialized_state[k].nil?
|
|
85
|
+
puts "skipping #{k} because plugin_data[#{k}] is not present."
|
|
86
|
+
next
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
if ![:user, :programmer].include?(k)
|
|
90
|
+
case k
|
|
91
|
+
when :based_uuid
|
|
92
|
+
puts "setting based_uuid from data init: #{new_serialized_state[k]}"
|
|
93
|
+
FDot.state[:based_uuid] = new_serialized_state[k]
|
|
94
|
+
when :completed_programs
|
|
95
|
+
puts :todo_initialize_completed_programs
|
|
96
|
+
when :program
|
|
97
|
+
p_serialized = new_serialized_state[k]
|
|
98
|
+
|
|
99
|
+
program_instance = FDot::Based::Program.new(p_serialized["uuid"])
|
|
100
|
+
puts "#{__method__} init program from serialized data! #{program_instance}"
|
|
101
|
+
program_instance.uuid = p_serialized["uuid"]
|
|
102
|
+
FDot.state[:program] = program_instance
|
|
103
|
+
|
|
104
|
+
p_serialized["variables"].each{|_, serialized|
|
|
105
|
+
FDot::Based::Variable.deserialize_into!(FDot.state[:program], serialized)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
p_serialized["instructions"].each{|_, serialized|
|
|
109
|
+
FDot::Based::Instruction.deserialize_into!(FDot.state[:program], serialized)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
p_serialized["history"].map{|historical_uuid, _|
|
|
113
|
+
p_serialized["history"][historical_uuid].each{|h|
|
|
114
|
+
FDot::Based::History.deserialize_into!(FDot.state[:program], h)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
when :f_dot_queue, :instructions
|
|
118
|
+
FDot.state[k] = new_serialized_state[k]
|
|
119
|
+
end
|
|
120
|
+
else
|
|
121
|
+
new_serialized_state[k][:variables] = new_serialized_state[k]["variables"].dup
|
|
122
|
+
new_serialized_state[k].delete("variables")
|
|
123
|
+
new_serialized_state[k][:variables].each{|variable_uuid|
|
|
124
|
+
FDot.state[:program].variables[variable_uuid].domain = FDot::DOMAINS[k.to_sym]
|
|
125
|
+
}
|
|
126
|
+
FDot.state[k.to_sym] = {
|
|
127
|
+
variables: [],
|
|
128
|
+
instructions: []
|
|
129
|
+
}
|
|
130
|
+
FDot.state[k.to_sym][:variables] = new_serialized_state[k][:variables]
|
|
131
|
+
end
|
|
132
|
+
}
|
|
133
|
+
puts "#{__method__} about to run with FDot.state[:program] set to: #{FDot.state[:program]}"
|
|
134
|
+
self.instance.serialized_state = new_serialized_state
|
|
135
|
+
self.instance.run(true)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def run(force = false)
|
|
139
|
+
raise "already running #{FDot.state[:program].uuid}!" if !force && !FDot.state[:program].nil?
|
|
140
|
+
|
|
141
|
+
FDot.state[:program] ||= FDot::Based::Program.new
|
|
142
|
+
puts "loaded #{FDot.state[:program]}"
|
|
143
|
+
|
|
144
|
+
loop do
|
|
145
|
+
FDot::Based::Interface.reconfigure_user_space!
|
|
146
|
+
# list .f_dot directory
|
|
147
|
+
# Dir[
|
|
148
|
+
# File.join(FDot::Based.f_dot_space_path, "*")
|
|
149
|
+
# ].each{|d|
|
|
150
|
+
# puts d.gsub(FDot::Based.f_dot_space_path, "")
|
|
151
|
+
# }
|
|
152
|
+
FDot::Based.print_large_title!
|
|
153
|
+
user_input = self.get_user_input
|
|
154
|
+
next if FDot::Based::Interface.open_main_menu?(user_input)
|
|
155
|
+
|
|
156
|
+
if Dir.exist?(user_input)
|
|
157
|
+
domain_name = File.basename(user_input)
|
|
158
|
+
if FDot::DOMAINS[domain_name.to_sym] == FDot::DOMAINS[:user]
|
|
159
|
+
selected_variable_file_path = FDot::Based.tty_prompt_select(
|
|
160
|
+
"select a variable: ", FDot::Based::Interface.user_input_options(user_input)
|
|
161
|
+
)
|
|
162
|
+
next if FDot::Based::Interface.open_main_menu?(selected_variable_file_path)
|
|
163
|
+
next if selected_variable_file_path.nil?
|
|
164
|
+
variable_uuid = FDot::Based::Interface.get_variable_uuid_from_file(
|
|
165
|
+
selected_variable_file_path
|
|
166
|
+
)
|
|
167
|
+
raise "invalid variable uuid! #{variable_uuid}" if variable_uuid.nil? ||
|
|
168
|
+
!FDot.state[:program].variables.keys.include?(variable_uuid)
|
|
169
|
+
|
|
170
|
+
if FDot::Based::Processor.user_setting!(:debug_inspectors_enabled)
|
|
171
|
+
debugger_open = true
|
|
172
|
+
while debugger_open
|
|
173
|
+
v = FDot.state[:program].variables[variable_uuid]
|
|
174
|
+
variable_attribute = FDot::Based.tty_prompt_select(
|
|
175
|
+
"select attribute: ",
|
|
176
|
+
[{name: :close_debugger, value: :close_debugger}] + v.history_menu_options
|
|
177
|
+
)
|
|
178
|
+
if variable_attribute == :close_debugger
|
|
179
|
+
debugger_open = false
|
|
180
|
+
else
|
|
181
|
+
puts v.send(variable_attribute)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
# move for the user
|
|
186
|
+
FDot.state[:program].add_move_history(
|
|
187
|
+
FDot.state[:program].variables[variable_uuid],
|
|
188
|
+
:processor
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
# move for the programmer
|
|
192
|
+
programmer_variable_uuid = FDot.state[:programmer][:variables].sample
|
|
193
|
+
FDot.state[:program].add_move_history(
|
|
194
|
+
FDot.state[:program].variables[programmer_variable_uuid],
|
|
195
|
+
:processor
|
|
196
|
+
)
|
|
197
|
+
else
|
|
198
|
+
listing_text = ["listing #{File.basename(user_input)} domain..."]
|
|
199
|
+
Dir[
|
|
200
|
+
File.join(user_input, "*")
|
|
201
|
+
].each{|d|
|
|
202
|
+
listing_text << d.gsub(user_input, "")
|
|
203
|
+
}
|
|
204
|
+
FDot::Based.less(
|
|
205
|
+
listing_text.join("\n")
|
|
206
|
+
)
|
|
207
|
+
end
|
|
208
|
+
elsif File.exist?(user_input)
|
|
209
|
+
file_contents = JSON.parse(File.read(user_input))
|
|
210
|
+
if File.basename(user_input) == :compiler.to_s
|
|
211
|
+
file_contents["variables"] = file_contents["variables"].map{|v_uuid|
|
|
212
|
+
FDot.state[:program].variables[v_uuid].to_s
|
|
213
|
+
}
|
|
214
|
+
file_contents["instructions"] = file_contents["instructions"].map{|i_uuid|
|
|
215
|
+
FDot.state[:program].instructions[i_uuid].to_s
|
|
216
|
+
}
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
puts "reading #{File.basename(user_input)} file..."
|
|
220
|
+
FDot::Based.less(
|
|
221
|
+
JSON.pretty_generate(file_contents)
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def get_user_input
|
|
228
|
+
FDot::Based.tty_prompt_select(
|
|
229
|
+
"#{self.class.name}.#{__method__}: ", FDot::Based::Interface.user_input_options
|
|
230
|
+
)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def self.show_settings_menu!
|
|
234
|
+
|
|
235
|
+
settings_menu_open = true
|
|
236
|
+
while settings_menu_open
|
|
237
|
+
setting_key = FDot::Based.tty_prompt_select(
|
|
238
|
+
"select a setting to toggle",
|
|
239
|
+
[{name: :back, value: :back}] + self.instance.user_settings.map{|k, v|
|
|
240
|
+
{name: "#{k}(#{v})", value: k}
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
break if setting_key == :back
|
|
245
|
+
|
|
246
|
+
set_user_setting(setting_key, !user_setting!(setting_key))
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def self.user_setting!(setting_key)
|
|
251
|
+
setting_key = setting_key.to_sym
|
|
252
|
+
raise "invalid setting_key: #{setting_key}" unless self.instance.user_settings.keys.include?(setting_key)
|
|
253
|
+
|
|
254
|
+
self.instance.user_settings[setting_key]
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def self.set_user_setting(setting_key, setting_value)
|
|
258
|
+
setting_key = setting_key.to_sym
|
|
259
|
+
|
|
260
|
+
self.instance.user_settings[setting_key] = setting_value
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|