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,471 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
program.rb
|
|
6
|
+
|
|
7
|
+
f_dot program.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
|
|
16
|
+
class Program
|
|
17
|
+
attr_accessor :uuid
|
|
18
|
+
attr_accessor :variables
|
|
19
|
+
attr_accessor :instructions
|
|
20
|
+
attr_accessor :history
|
|
21
|
+
|
|
22
|
+
def initialize(state_uuid = nil)
|
|
23
|
+
puts "#{self}.#{__method__}"
|
|
24
|
+
self.uuid = state_uuid || FDot::Based.generate_uuid
|
|
25
|
+
self.variables = {}
|
|
26
|
+
self.instructions = {}
|
|
27
|
+
self.history = {}
|
|
28
|
+
|
|
29
|
+
generate_variables!
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate_variables!
|
|
33
|
+
return unless self.variables.empty?
|
|
34
|
+
FDot::Based::TYPES.each_with_index{|b_type, b_type_index|
|
|
35
|
+
FDot::Based::NUMBERS.each_with_index{|b_number, b_number_index|
|
|
36
|
+
new_variable = FDot::Based::Variable.new(
|
|
37
|
+
self.uuid,
|
|
38
|
+
b_type,
|
|
39
|
+
b_number_index
|
|
40
|
+
)
|
|
41
|
+
self.variables[new_variable.uuid] = new_variable
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
FDot::Based.print_large_title!
|
|
46
|
+
puts startup_notes
|
|
47
|
+
|
|
48
|
+
# start a new program
|
|
49
|
+
exit if :close_program == FDot::Based.tty_prompt_select(
|
|
50
|
+
"press enter to continue",
|
|
51
|
+
[{name: :start, value: :start}, {name: :close_program, value: :close_program}]
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def startup_notes
|
|
56
|
+
[
|
|
57
|
+
"welcome to f_dot. | f_dot is based. | this is a based f_dot program.\n",
|
|
58
|
+
"interface description:\n",
|
|
59
|
+
"based_variable:",
|
|
60
|
+
"\tthe based variable is randomly chosen when the program starts.",
|
|
61
|
+
"\tthe based variable is used as a checksum at the end of the program.",
|
|
62
|
+
"compiler:",
|
|
63
|
+
"\tthe compiler combines equal variables into instructions.",
|
|
64
|
+
"\tthe compiler combines equal instructions.",
|
|
65
|
+
"\tthe compiler runs in the processor domain.",
|
|
66
|
+
"processor:",
|
|
67
|
+
"\tthe processor processes the f_dot_queue of variables.",
|
|
68
|
+
"\tthe processor domain is the root of the program.",
|
|
69
|
+
"programmer:",
|
|
70
|
+
"\tthe programmer is user-like domain that responds to user actions.",
|
|
71
|
+
"\tthe programmer is distributed variables the same way as they are given to users.",
|
|
72
|
+
"user:",
|
|
73
|
+
"\tthe user is a human operating an FDot::Based unix system.",
|
|
74
|
+
"\tthe user only able to move instructions from the user domain to the processor domain.",
|
|
75
|
+
"program operation:\n",
|
|
76
|
+
"\t1) the user and the programmer are each given 11 variables 3 times throughout the program.",
|
|
77
|
+
"\t2) the user and the programmer are each given 5 variables 1 time at the end of the program.",
|
|
78
|
+
"\t3) the program calculates the based checksum.",
|
|
79
|
+
"\t4) a new program starts.\n",
|
|
80
|
+
"user usage:\n",
|
|
81
|
+
"\t=> navigate to the user menu",
|
|
82
|
+
"\t=> select a variable in the user menu to move it to the compiler.",
|
|
83
|
+
"\n"
|
|
84
|
+
].join("\n")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def ready_to_deque?
|
|
88
|
+
[:programmer, :user].map{|k| FDot.state[k].nil? ? [] : FDot.state[k][:variables] }.all?{|a| a.empty?}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def ready_to_based?
|
|
92
|
+
compile_variables = compiler_contents[:variables]
|
|
93
|
+
|
|
94
|
+
ready_to_deque? && (
|
|
95
|
+
(FDot::Based::NUMBERS.count - 1) == compile_variables.count
|
|
96
|
+
) && !compile_variables.any?{|v_uuid|
|
|
97
|
+
self.variables[v_uuid].ordinal == self.variables[FDot.state[:based_uuid]].ordinal
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# primary read of compiler contents
|
|
102
|
+
def compiler_contents
|
|
103
|
+
# a variable or instruction is considered inside of
|
|
104
|
+
# compiler_contents if it is not in any of the
|
|
105
|
+
# following domains:
|
|
106
|
+
#
|
|
107
|
+
# => :based_variable
|
|
108
|
+
# => :f_dot_queue
|
|
109
|
+
# => :processor
|
|
110
|
+
#
|
|
111
|
+
# note => :based_variable is not strictly a domain
|
|
112
|
+
#
|
|
113
|
+
|
|
114
|
+
{
|
|
115
|
+
variables: self.variables.select{|k, v|
|
|
116
|
+
k != FDot.state[:based_uuid] &&
|
|
117
|
+
!FDot.state[:f_dot_queue].include?(k) &&
|
|
118
|
+
!FDot.state[:programmer][:variables].include?(k) &&
|
|
119
|
+
!FDot.state[:user][:variables].include?(k) &&
|
|
120
|
+
!self.instructions.any?{|i_uuid, i_instance| i_instance.variable_uuids.include?(k)}
|
|
121
|
+
}.map{|k, v| k},
|
|
122
|
+
instructions: self.instructions.select{|k, v|
|
|
123
|
+
!FDot.state[:programmer][:instructions].include?(k) &&
|
|
124
|
+
!FDot.state[:user][:instructions].include?(k)
|
|
125
|
+
}.map{|k, v| k},
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# deal out one variable
|
|
130
|
+
def move_next_variable_to(move_to_domain_key)
|
|
131
|
+
return unless FDot.state[:f_dot_queue].any?
|
|
132
|
+
|
|
133
|
+
# get the next var
|
|
134
|
+
next_var = FDot.state[:program].variables[
|
|
135
|
+
FDot.state[:f_dot_queue].delete_at(0)
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
self.add_move_history(next_var, move_to_domain_key)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def build_space!
|
|
142
|
+
initialize_space!
|
|
143
|
+
|
|
144
|
+
f_dot_de_queue!
|
|
145
|
+
|
|
146
|
+
check_for_based_conditions!
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def add_combine_history(instance_one, instance_two)
|
|
150
|
+
raise "cannot combine! #{instance_one.to_s} and #{instance_two.to_s}" unless [
|
|
151
|
+
instance_one.domain,
|
|
152
|
+
instance_two.domain
|
|
153
|
+
].uniq.first == FDot::DOMAINS[:processor]
|
|
154
|
+
|
|
155
|
+
allowed_const_types = [
|
|
156
|
+
FDot::Based::Instruction,
|
|
157
|
+
FDot::Based::Variable
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
const_one = instance_one.class
|
|
161
|
+
const_two = instance_two.class
|
|
162
|
+
|
|
163
|
+
allowed_intersection = (
|
|
164
|
+
allowed_const_types & [const_one, const_two]
|
|
165
|
+
)
|
|
166
|
+
puts allowed_intersection
|
|
167
|
+
unless allowed_intersection.all?{|c| allowed_const_types.map{|c| c.name}.include?(c.name)}
|
|
168
|
+
raise "invalid const(s)! #{const_one}:#{const_two}"
|
|
169
|
+
end
|
|
170
|
+
puts "combining #{const_one.name} with #{const_two.name}" if FDot::Based::Processor.user_setting!(:show_history_logging)
|
|
171
|
+
case const_one.name
|
|
172
|
+
when FDot::Based::Instruction.name
|
|
173
|
+
case const_two.name
|
|
174
|
+
when FDot::Based::Instruction.name
|
|
175
|
+
# combine instruction instance_one with instruction instance_two
|
|
176
|
+
removed_instruction = instance_one.combine_with_instruction(instance_two)
|
|
177
|
+
raise "failed to combine!" unless removed_instruction.variable_uuids.empty?
|
|
178
|
+
self.compile!(instance_one.uuid)
|
|
179
|
+
when FDot::Based::Variable.name
|
|
180
|
+
# combine instruction instance_one with variable instance_two
|
|
181
|
+
instance_one = instance_two.combine_with_instruction(instance_one)
|
|
182
|
+
self.compile!(instance_one.uuid)
|
|
183
|
+
end
|
|
184
|
+
when FDot::Based::Variable.name
|
|
185
|
+
case const_two.name
|
|
186
|
+
when FDot::Based::Instruction.name
|
|
187
|
+
# add variable instance_one to instruction instance_two
|
|
188
|
+
instance_two = instance_one.combine_with_instruction(instance_two)
|
|
189
|
+
self.compile!(instance_two.uuid)
|
|
190
|
+
when FDot::Based::Variable.name
|
|
191
|
+
# create new instruction and add it to history and processor instructions
|
|
192
|
+
new_instruction = instance_one.combine_with_variable(instance_two)
|
|
193
|
+
self.compile!(new_instruction.uuid)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def add_move_history(variable, move_to_domain_key)
|
|
199
|
+
move_to_domain_key = move_to_domain_key.to_sym
|
|
200
|
+
|
|
201
|
+
# remove variable uuid from current domain
|
|
202
|
+
if variable.domain_key == :processor
|
|
203
|
+
FDot.state[:f_dot_queue].delete(variable.uuid)
|
|
204
|
+
else
|
|
205
|
+
FDot.state[variable.domain_key][:variables].delete(variable.uuid)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# add the variable to domain
|
|
209
|
+
if move_to_domain_key != :processor
|
|
210
|
+
FDot.state[move_to_domain_key][:variables] << variable.uuid
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# create a history entry
|
|
214
|
+
history[variable.uuid] ||= []
|
|
215
|
+
history[variable.uuid] << FDot::Based::History.create_variable_history!(
|
|
216
|
+
variable,
|
|
217
|
+
FDot::DOMAINS[move_to_domain_key]
|
|
218
|
+
)
|
|
219
|
+
puts history[variable.uuid].last.to_s if FDot::Based::Processor.user_setting!(:show_history_logging)
|
|
220
|
+
|
|
221
|
+
self.compile!(variable.uuid)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def compile!(lineage_uuid)
|
|
225
|
+
raise "invalid lineage_uuid" unless history.keys.include?(lineage_uuid)
|
|
226
|
+
history_instance = history[lineage_uuid].last
|
|
227
|
+
compile_instructions!(history_instance)
|
|
228
|
+
compile_variables!(history_instance)
|
|
229
|
+
FDot::Based::Processor.serialize_state!
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def show_history_interface!
|
|
233
|
+
history_menu_open = true
|
|
234
|
+
while history_menu_open
|
|
235
|
+
to_show_history_uuid = FDot::Based.tty_prompt_select(
|
|
236
|
+
"which item do you want to view the history for?",
|
|
237
|
+
[{name: :back, value: :back}] + self.history_menu_options
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
break if to_show_history_uuid == :back
|
|
241
|
+
|
|
242
|
+
history_timestamp = FDot::Based.tty_prompt_select(
|
|
243
|
+
"which record would you like to open?",
|
|
244
|
+
[{name: :back, value: :back}] + self.history_menu_options_for(to_show_history_uuid)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
next if history_timestamp == :back
|
|
248
|
+
|
|
249
|
+
history_instance = self.history[to_show_history_uuid].select{|h| h.timestamp == history_timestamp}.first
|
|
250
|
+
|
|
251
|
+
raise "invalid history_instance!" if history_instance.nil?
|
|
252
|
+
|
|
253
|
+
history_instance.show_interface!
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def compute_serialized_state!
|
|
259
|
+
serialized_instructions = {}
|
|
260
|
+
self.instructions.keys.each{|k|
|
|
261
|
+
serialized_instructions[k] = self.instructions[k].compute_serialized_state!
|
|
262
|
+
}
|
|
263
|
+
serialized_variables = {}
|
|
264
|
+
self.variables.keys.each{|k|
|
|
265
|
+
serialized_variables[k] = self.variables[k].compute_serialized_state!
|
|
266
|
+
}
|
|
267
|
+
serialized_history = {}
|
|
268
|
+
self.history.keys.each{|k|
|
|
269
|
+
serialized_history[k] = history[k].map{|h| h.compute_serialized_state!}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
{
|
|
273
|
+
uuid: self.uuid,
|
|
274
|
+
instructions: serialized_instructions,
|
|
275
|
+
variables: serialized_variables,
|
|
276
|
+
history: serialized_history,
|
|
277
|
+
}
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
private
|
|
281
|
+
|
|
282
|
+
def history_menu_options_for(historical_uuid)
|
|
283
|
+
self.history[historical_uuid].map{|history_instance|
|
|
284
|
+
{name: history_instance.to_s, value: history_instance.timestamp}
|
|
285
|
+
}
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def history_menu_options
|
|
289
|
+
all_history = []
|
|
290
|
+
self.history.map{|historical_uuid, history_array|
|
|
291
|
+
all_history += history_array || []
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
all_history.sort_by{|history_instance|
|
|
295
|
+
history_instance.timestamp
|
|
296
|
+
}.reverse.map{|h| {name: "#{h.timestamp}): #{h.historical_instance.to_s}", value: h.historical_instance.uuid }}
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
def issue_variables!
|
|
300
|
+
self.variables.keys.shuffle
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def initialize_space!
|
|
304
|
+
return unless FDot.state[:f_dot_queue].empty? && FDot.state[:based_uuid].nil?
|
|
305
|
+
|
|
306
|
+
FDot::DOMAINS.each{|domain, i|
|
|
307
|
+
case domain
|
|
308
|
+
when :processor
|
|
309
|
+
FDot.state[:f_dot_queue] = self.issue_variables!
|
|
310
|
+
FDot.state[:instructions] = []
|
|
311
|
+
when :programmer, :user
|
|
312
|
+
FDot.state[domain] = {}
|
|
313
|
+
FDot.state[domain][:variables] = []
|
|
314
|
+
FDot.state[domain][:instructions] = []
|
|
315
|
+
end
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
based_variable = FDot.state[:program].variables[
|
|
319
|
+
FDot.state[:f_dot_queue].delete_at(0)
|
|
320
|
+
]
|
|
321
|
+
puts "the based variable is #{based_variable.to_s}"
|
|
322
|
+
# based_variable sets the tone for the process
|
|
323
|
+
FDot.state[:based_uuid] = based_variable.uuid
|
|
324
|
+
# create a history entry for based_variable
|
|
325
|
+
|
|
326
|
+
add_move_history(based_variable, based_variable.domain_key)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def check_for_based_conditions!
|
|
330
|
+
return unless ready_to_based?
|
|
331
|
+
|
|
332
|
+
puts "running based checksum"
|
|
333
|
+
compile_variables = compiler_contents[:variables]
|
|
334
|
+
(compile_variables + [FDot.state[:based_uuid]]).each{|v_uuid|
|
|
335
|
+
variable = self.variables[v_uuid]
|
|
336
|
+
ordinal_instruction = self.instructions.values.select{|v|
|
|
337
|
+
v.ordinal == variable.ordinal
|
|
338
|
+
}.first
|
|
339
|
+
raise "checksum failed!" if ordinal_instruction.nil?
|
|
340
|
+
variable.combine_with_instruction(ordinal_instruction)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
compile_variables = compiler_contents[:variables]
|
|
344
|
+
raise "based failed!" unless compile_variables.count == 0
|
|
345
|
+
|
|
346
|
+
puts "#{self} checksum successful."
|
|
347
|
+
puts "#{self.class.name} completed."
|
|
348
|
+
FDot.state[:completed_programs][self.uuid] = self
|
|
349
|
+
|
|
350
|
+
puts "listing completed programs:"
|
|
351
|
+
puts FDot.state[:completed_programs]
|
|
352
|
+
|
|
353
|
+
FDot.state[:based_uuid] = nil
|
|
354
|
+
FDot.state[:program] = FDot::Based::Program.new
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def f_dot_de_queue!
|
|
358
|
+
return unless !FDot.state[:f_dot_queue].empty? && ready_to_deque?
|
|
359
|
+
|
|
360
|
+
# assign variables to programmer and user domains
|
|
361
|
+
FDot::Based::NUMBERS.each{|n|
|
|
362
|
+
[:programmer, :user].each{|k|
|
|
363
|
+
move_next_variable_to(k)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def compile_variables!(history_instance)
|
|
369
|
+
if history_instance.to_domain == FDot::DOMAINS[:processor]
|
|
370
|
+
if FDot::Based::Processor.user_setting!(:auto_compile_enabled)
|
|
371
|
+
while get_combinable_variables.any?
|
|
372
|
+
combinable_variables = get_combinable_variables
|
|
373
|
+
to_combine_instance = combinable_variables.first
|
|
374
|
+
|
|
375
|
+
with_instance = get_variables_combinable_with(to_combine_instance.uuid).first
|
|
376
|
+
add_combine_history(to_combine_instance, with_instance)
|
|
377
|
+
end
|
|
378
|
+
else
|
|
379
|
+
# manually compile
|
|
380
|
+
while get_combinable_variables.any?
|
|
381
|
+
puts JSON.pretty_generate(get_combinable_variables)
|
|
382
|
+
# prompt user to choose an instruction to combine
|
|
383
|
+
to_combine_variable_uuid = FDot::Based.tty_prompt_select(
|
|
384
|
+
"combinable_variables: ",
|
|
385
|
+
get_combinable_variables.map{|variable_instance|
|
|
386
|
+
{name: variable_instance.to_s, value: variable_instance.uuid}
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
to_combine_instance = self.variables[to_combine_variable_uuid]
|
|
390
|
+
raise "invalid to_combine_instance!" if to_combine_instance.nil?
|
|
391
|
+
|
|
392
|
+
puts "listing variables combinable with #{to_combine_instance.to_s}..."
|
|
393
|
+
with_variable_uuid = FDot::Based.tty_prompt_select(
|
|
394
|
+
"combine #{to_combine_instance.to_s} with?",
|
|
395
|
+
get_variables_combinable_with(to_combine_variable_uuid).map{|variable_instance|
|
|
396
|
+
{name: variable_instance.to_s, value: variable_instance.uuid}
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
with_instance = self.variables[with_variable_uuid]
|
|
400
|
+
|
|
401
|
+
add_combine_history(to_combine_instance, with_instance)
|
|
402
|
+
end
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
def compile_instructions!(history_instance)
|
|
408
|
+
while get_combinable_instructions.any?
|
|
409
|
+
if FDot::Based::Processor.user_setting!(:auto_compile_enabled)
|
|
410
|
+
while get_combinable_instructions.any?
|
|
411
|
+
combinable_instructions = get_combinable_instructions
|
|
412
|
+
to_combine_instance = combinable_instructions.first
|
|
413
|
+
with_instance = get_instructions_combinable_with(to_combine_instance.uuid).first
|
|
414
|
+
add_combine_history(to_combine_instance, with_instance)
|
|
415
|
+
end
|
|
416
|
+
else
|
|
417
|
+
# manually compile
|
|
418
|
+
puts "#{__method__}"
|
|
419
|
+
puts "listing instructions to compile..."
|
|
420
|
+
to_combine_instruction_uuid = FDot::Based.tty_prompt_select(
|
|
421
|
+
"combinable_instructions: ",
|
|
422
|
+
get_combinable_instructions.map{|instruction_instance|
|
|
423
|
+
{name: instruction_instance.to_s, value: instruction_instance.uuid}
|
|
424
|
+
}
|
|
425
|
+
)
|
|
426
|
+
to_combine_instance = self.instructions[to_combine_instruction_uuid]
|
|
427
|
+
raise "invalid to_combine_instance!" if to_combine_instance.nil?
|
|
428
|
+
|
|
429
|
+
puts "listing instructions combinable with #{to_combine_instance.to_s}..."
|
|
430
|
+
with_instruction_uuid = FDot::Based.tty_prompt_select(
|
|
431
|
+
"combine #{to_combine_instance.to_s} with?",
|
|
432
|
+
get_instructions_combinable_with(to_combine_instruction_uuid).map{|instruction_instance|
|
|
433
|
+
{name: instruction_instance.to_s, value: instruction_instance.uuid}
|
|
434
|
+
}
|
|
435
|
+
)
|
|
436
|
+
with_instance = self.instructions[with_instruction_uuid]
|
|
437
|
+
|
|
438
|
+
add_combine_history(to_combine_instance, with_instance)
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def get_combinable_instructions
|
|
444
|
+
compiler_contents[:instructions].select{|i_uuid|
|
|
445
|
+
get_instructions_combinable_with(i_uuid).any?
|
|
446
|
+
}.map{|i_uuid| self.instructions[i_uuid]}
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def get_combinable_variables
|
|
450
|
+
compiler_contents[:variables].select{|v_uuid|
|
|
451
|
+
get_variables_combinable_with(v_uuid).any?
|
|
452
|
+
}.map{|v_uuid| self.variables[v_uuid]}
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
def get_instructions_combinable_with(i1_uuid)
|
|
456
|
+
compiler_contents[:instructions].select{|i2_uuid|
|
|
457
|
+
i1_uuid != i2_uuid &&
|
|
458
|
+
self.instructions[i1_uuid].ordinal == self.instructions[i2_uuid].ordinal
|
|
459
|
+
}.map{|u| self.instructions[u]}
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
def get_variables_combinable_with(v1_uuid)
|
|
463
|
+
compiler_contents[:variables].select{|v2_uuid|
|
|
464
|
+
v1_uuid != v2_uuid &&
|
|
465
|
+
self.variables[v1_uuid].ordinal == self.variables[v2_uuid].ordinal
|
|
466
|
+
}.map{|u| self.variables[u]}
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
end
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
variable.rb
|
|
6
|
+
|
|
7
|
+
f_dot variable.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
|
|
16
|
+
class Variable
|
|
17
|
+
attr_accessor :uuid
|
|
18
|
+
attr_accessor :program_uuid
|
|
19
|
+
attr_accessor :type
|
|
20
|
+
attr_accessor :ordinal
|
|
21
|
+
attr_accessor :domain
|
|
22
|
+
|
|
23
|
+
def initialize(program_uuid, type, ordinal)
|
|
24
|
+
self.uuid = FDot::Based.generate_uuid
|
|
25
|
+
self.program_uuid = program_uuid
|
|
26
|
+
self.type = type.to_sym
|
|
27
|
+
self.ordinal = ordinal
|
|
28
|
+
self.domain = FDot::DOMAINS[:processor]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def number_key
|
|
32
|
+
FDot::Based::NUMBERS[self.ordinal]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def domain_key
|
|
36
|
+
FDot::Based::Variable.domain_key_for(self.domain)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.domain_key_for(domain_int)
|
|
40
|
+
FDot::DOMAINS.keys.select{|k| FDot::DOMAINS[k] == domain_int}.first
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_s
|
|
44
|
+
"#{self.type_display}(#{self.ordinal})"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def type_display
|
|
48
|
+
self.type.to_s.gsub("dot_", "").upcase
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def combine_with_instruction(to_combine_instruction)
|
|
52
|
+
unless to_combine_instruction.kind_of?(FDot::Based::Instruction)
|
|
53
|
+
raise "cannot #{self.inspect} #{__method__} #{to_combine_instruction.inspect}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
raise "already combined with instruction!" if to_combine_instruction.variable_uuids.include?(self.uuid)
|
|
57
|
+
|
|
58
|
+
to_combine_instruction.variable_uuids << self.uuid
|
|
59
|
+
FDot.state[:program].history[to_combine_instruction.uuid] ||= []
|
|
60
|
+
FDot.state[:program].history[to_combine_instruction.uuid] << FDot::Based::History.create_instruction_history!(
|
|
61
|
+
to_combine_instruction,
|
|
62
|
+
to_combine_instruction.domain
|
|
63
|
+
)
|
|
64
|
+
puts FDot.state[:program].history[to_combine_instruction.uuid].last.to_s if FDot::Based::Processor.user_setting!(:show_history_logging)
|
|
65
|
+
to_combine_instruction
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def combine_with_variable(to_combine_variable)
|
|
69
|
+
unless to_combine_variable.kind_of?(FDot::Based::Variable)
|
|
70
|
+
raise "cannot #{self.inspect} #{__method__} #{to_combine_variable.inspect}"
|
|
71
|
+
end
|
|
72
|
+
new_instruction = FDot::Based::Instruction.new(self.program_uuid, [self.uuid, to_combine_variable.uuid])
|
|
73
|
+
|
|
74
|
+
FDot.state[:program].history[new_instruction.uuid] = []
|
|
75
|
+
FDot.state[:program].history[new_instruction.uuid] << FDot::Based::History.create_instruction_history!(
|
|
76
|
+
new_instruction,
|
|
77
|
+
new_instruction.domain
|
|
78
|
+
)
|
|
79
|
+
puts FDot.state[:program].history[new_instruction.uuid].last.to_s if FDot::Based::Processor.user_setting!(:show_history_logging)
|
|
80
|
+
FDot.state[:instructions] << new_instruction.uuid
|
|
81
|
+
|
|
82
|
+
new_instruction
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def history_menu_options
|
|
86
|
+
[
|
|
87
|
+
:uuid,
|
|
88
|
+
:program_uuid,
|
|
89
|
+
:type_display,
|
|
90
|
+
:ordinal,
|
|
91
|
+
:number_key,
|
|
92
|
+
:domain_key
|
|
93
|
+
].each{|attribute|
|
|
94
|
+
{
|
|
95
|
+
name: "#{attribute}: #{self.send(attribute)}",
|
|
96
|
+
value: attribute
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def compute_serialized_state!
|
|
102
|
+
serialized_state = {
|
|
103
|
+
name: self.to_s
|
|
104
|
+
}
|
|
105
|
+
FDot::Based::Variable.serialization_keys.each{|k|
|
|
106
|
+
serialized_state[k] = self.send(k)
|
|
107
|
+
}
|
|
108
|
+
serialized_state
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def self.deserialize_into!(program, serialized_variable)
|
|
112
|
+
raise "invalid serialized_variable! #{serialized_variable}" unless serialization_keys.all?{|k|
|
|
113
|
+
serialized_variable.keys.include?(k.to_s)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# cannot look up by program.variables[variable_uuid] yet
|
|
117
|
+
variable_instance = program.variables.values.select{|v|
|
|
118
|
+
v.type.to_s == serialized_variable["type"] &&
|
|
119
|
+
v.ordinal == serialized_variable["ordinal"]
|
|
120
|
+
}.first
|
|
121
|
+
|
|
122
|
+
raise "missing variable_instance!" if variable_instance.nil?
|
|
123
|
+
raise "missing variable uuid!" if serialized_variable["uuid"].nil? || serialized_variable["uuid"].empty?
|
|
124
|
+
|
|
125
|
+
program.variables.delete(variable_instance.uuid)
|
|
126
|
+
variable_instance.uuid = serialized_variable["uuid"]
|
|
127
|
+
variable_instance.program_uuid = serialized_variable["program_uuid"]
|
|
128
|
+
|
|
129
|
+
variable_instance.domain = serialized_variable["domain"].to_i
|
|
130
|
+
program.variables[serialized_variable["uuid"]] = variable_instance
|
|
131
|
+
|
|
132
|
+
variable_instance
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
private
|
|
136
|
+
|
|
137
|
+
def self.serialization_keys
|
|
138
|
+
[
|
|
139
|
+
:uuid,
|
|
140
|
+
:program_uuid,
|
|
141
|
+
:type,
|
|
142
|
+
:ordinal,
|
|
143
|
+
:domain
|
|
144
|
+
]
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
data/lib/f_dot.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
f_dot.rb
|
|
6
|
+
|
|
7
|
+
f_dot.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require "json"
|
|
14
|
+
require "securerandom"
|
|
15
|
+
require "fileutils"
|
|
16
|
+
require "tty-prompt"
|
|
17
|
+
require "tty-font"
|
|
18
|
+
|
|
19
|
+
[:f_dot].each{|d|
|
|
20
|
+
Dir[
|
|
21
|
+
File.join(__dir__, d.to_s, :"**/**/*.rb".to_s)
|
|
22
|
+
].each { |f| require f }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module FDot
|
|
26
|
+
DOMAINS = {
|
|
27
|
+
processor: 0,
|
|
28
|
+
programmer: 1,
|
|
29
|
+
user: 2
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def self.state
|
|
33
|
+
Thread.main[:f_dot_state] ||= {}
|
|
34
|
+
end
|
|
35
|
+
end
|