lib/tataru/instruction.rb in tataru-0.1.0 vs lib/tataru/instruction.rb in tataru-0.2.0
- old
+ new
@@ -1,15 +1,60 @@
# frozen_string_literal: true
module Tataru
- # An instruction
+ # a thing to do
class Instruction
- attr_reader :action, :id, :state, :requirements
+ class << self
+ attr_accessor :expected_params
- def initialize(action, id, state, requirements)
- @action = action
- @id = id
- @state = state
- @requirements = requirements
+ def expects(symbol)
+ @expected_params ||= []
+ @expected_params << symbol
+
+ define_method symbol do
+ return nil if @memory&.hash.nil?
+
+ memory.hash[:temp][symbol]
+ end
+ end
end
+
+ attr_accessor :memory
+
+ def execute(memory)
+ @memory = memory
+ self.class.expected_params&.each do |symbol|
+ unless memory.hash[:temp].key? symbol
+ raise "required param #{symbol} not found"
+ end
+ end
+
+ run
+ end
+
+ def run; end
end
end
+
+require 'tataru/instructions/immediate_mode_instruction'
+require 'tataru/instructions/resource_instruction'
+require 'tataru/instructions/check_instruction'
+require 'tataru/instructions/check_delete_instruction'
+require 'tataru/instructions/mark_deletable_instruction'
+require 'tataru/instructions/clear_instruction'
+require 'tataru/instructions/goto_if_instruction'
+require 'tataru/instructions/key_instruction'
+require 'tataru/instructions/value_rom_instruction'
+require 'tataru/instructions/value_update_instruction'
+require 'tataru/instructions/compare_instruction'
+require 'tataru/instructions/delete_instruction'
+require 'tataru/instructions/update_instruction'
+require 'tataru/instructions/create_instruction'
+require 'tataru/instructions/end_instruction'
+require 'tataru/instructions/check_create_instruction'
+require 'tataru/instructions/read_instruction'
+require 'tataru/instructions/check_update_instruction'
+require 'tataru/instructions/rescmp_instruction'
+require 'tataru/instructions/call_instruction'
+require 'tataru/instructions/value_instruction'
+require 'tataru/instructions/return_instruction'
+require 'tataru/instructions/init_instruction'