QuISP
Loading...
Searching...
No Matches
RuleSet.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <vector>
6
7#include "opcode.h"
8#include "types.h"
9
10namespace quisp::runtime {
11
17class Program {
18 public:
19 Program(const std::string& name, const std::vector<InstructionTypes>& opcodes, bool debugging = false);
20
21 std::vector<InstructionTypes> opcodes;
22
29
31 std::string name;
32
34 bool debugging = false;
35};
36
40class Rule {
41 public:
42 Rule(const Program& condition, const Program& action, bool debugging = false) : Rule("", -1, -1, condition, action, debugging) {}
45
47 std::string name;
48
50 int id = -1;
51
53 int send_tag = -1;
54 int receive_tag = -1;
55
64
67
69 bool debugging = false;
70};
71
80class RuleSet {
81 public:
82 RuleSet(const std::string& name = "", const std::vector<Rule>& rules = std::vector<Rule>(), const Program& termination_cond = Program{"never terminate", {}},
83 bool debugging = false)
84 : name(name), rules(rules), termination_condition(termination_cond), debugging(debugging) {}
85
87 void finalize();
88
90 std::set<QNodeAddr> partners;
91
98 std::unordered_map<QNodeAddr, RuleId> partner_initial_rule_table;
99
104 std::unordered_map<std::pair<QNodeAddr, RuleId>, RuleId> next_rule_table = {};
105
107 unsigned long id;
108
111
113 std::string name;
114
116 std::vector<Rule> rules;
117
120 bool debugging = false;
121
122 protected:
127 static inline void collectPartners(const RuleId rule_id, const InstructionTypes& instr, std::set<QNodeAddr>& partners,
128 std::unordered_map<QNodeAddr, std::vector<RuleId>>& partner_rules);
129};
130} // namespace quisp::runtime
The Program is a list of Instructions with metadata. The Runtime can execute the Program.
Definition RuleSet.h:17
Program(const std::string &name, const std::vector< InstructionTypes > &opcodes, bool debugging=false)
Definition RuleSet.cc:11
bool debugging
if it's true, show instruction and runtime state in each step.
Definition RuleSet.h:34
LabelMap label_map
the map to find instruction index (pc) by label.
Definition RuleSet.h:28
std::string name
the Program name for debugging purpose.
Definition RuleSet.h:31
std::vector< InstructionTypes > opcodes
Definition RuleSet.h:21
The Runtime executable Rule in a RuleSet.
Definition RuleSet.h:40
Rule(const Program &condition, const Program &action, bool debugging=false)
Definition RuleSet.h:42
int send_tag
the shared tag for identify a rule across QNodes in a connection.
Definition RuleSet.h:53
Program action
The action for the Rule in the RuleSet.
Definition RuleSet.h:66
Rule(const std::string &name, int send_tag, int receive_tag, const Program &condition, const Program &action, bool debugging=false)
Definition RuleSet.h:43
int receive_tag
Definition RuleSet.h:54
std::string name
the RuleSet name for debugging
Definition RuleSet.h:47
bool debugging
if it's true, the Runtime shows debug info in each step.
Definition RuleSet.h:69
Program condition
The condition for the Rule. The Runtime executes the following. action if this condition passed....
Definition RuleSet.h:63
The RuleSet.
Definition RuleSet.h:80
std::unordered_map< std::pair< QNodeAddr, RuleId >, RuleId > next_rule_table
contains the next rule ids corresponding to the current partner and rule id like: (partner_addr,...
Definition RuleSet.h:104
Program termination_condition
the Program to check the RuleSet is terminated or not.
Definition RuleSet.h:119
bool debugging
Definition RuleSet.h:120
unsigned long id
the RuleSet id
Definition RuleSet.h:107
RuleSet(const std::string &name="", const std::vector< Rule > &rules=std::vector< Rule >(), const Program &termination_cond=Program{"never terminate", {}}, bool debugging=false)
Definition RuleSet.h:82
std::string name
the RuleSet name for debugging.
Definition RuleSet.h:113
void finalize()
analyzes its rules and instructions to collect informations for execution.
Definition RuleSet.cc:22
static void collectPartners(const RuleId rule_id, const InstructionTypes &instr, std::set< QNodeAddr > &partners, std::unordered_map< QNodeAddr, std::vector< RuleId > > &partner_rules)
an internal method to traverse the given Rule's whole Program to collect their partners.
Definition RuleSet.cc:54
std::set< QNodeAddr > partners
the partner(connection participating nodes) QNodeAddrs used in this RuleSet.
Definition RuleSet.h:90
std::unordered_map< QNodeAddr, RuleId > partner_initial_rule_table
This contains a list of pairs of the rule_id and partner's QNodeAddr.
Definition RuleSet.h:98
std::vector< Rule > rules
the Rules in this RuleSet. Each Rule has Condition and Action.
Definition RuleSet.h:116
int owner_addr
the owner's QNode address.
Definition RuleSet.h:110
Definition InstructionVisitor.cc:7
std::variant< #define INSTR(Opcode,...) #define INSTR_LAST(Opcode,...) # 1 "/github/workspace/quisp/runtime/def_instructions.h" 1 # 87 "/github/workspace/quisp/runtime/opcode.h" 2 > InstructionTypes
a variant that is capable of storing all instructions
Definition opcode.h:84
int RuleId
Definition types.h:18
std::unordered_map< Label, int > LabelMap
utility type for storing a label and corresponding instruction index.
Definition types.h:113
this file contains the definitions of all the user-defined types widely used alongside the runtime::R...
internal class to describe QNode's address.
Definition types.h:70