2019-10-01 14:34:38 -07:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2019-10-08 23:46:35 -07:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
2019-10-09 22:46:17 -07:00
|
|
|
#include <ostream>
|
|
|
|
#include "binop.hpp"
|
2019-10-01 14:34:38 -07:00
|
|
|
|
|
|
|
struct instruction {
|
|
|
|
virtual ~instruction() = default;
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
virtual void print(int indent, std::ostream& to) const = 0;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
using instruction_ptr = std::unique_ptr<instruction>;
|
|
|
|
|
|
|
|
struct instruction_pushint : public instruction {
|
|
|
|
int value;
|
|
|
|
|
|
|
|
instruction_pushint(int v)
|
|
|
|
: value(v) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_pushglobal : public instruction {
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
instruction_pushglobal(std::string n)
|
|
|
|
: name(std::move(n)) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_push : public instruction {
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
instruction_push(int o)
|
|
|
|
: offset(o) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_mkapp : public instruction {
|
2019-10-09 22:46:17 -07:00
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_update : public instruction {
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
instruction_update(int o)
|
|
|
|
: offset(o) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_pack : public instruction {
|
|
|
|
int tag;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
instruction_pack(int t, int s)
|
|
|
|
: tag(t), size(s) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_split : public instruction {
|
2019-10-09 22:46:17 -07:00
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
2019-10-08 23:46:35 -07:00
|
|
|
struct instruction_jump : public instruction {
|
|
|
|
std::vector<std::vector<instruction_ptr>> branches;
|
|
|
|
std::map<int, int> tag_mappings;
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-08 23:46:35 -07:00
|
|
|
};
|
|
|
|
|
2019-10-01 14:34:38 -07:00
|
|
|
struct instruction_slide : public instruction {
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
instruction_slide(int o)
|
|
|
|
: offset(o) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_binop : public instruction {
|
|
|
|
binop op;
|
|
|
|
|
|
|
|
instruction_binop(binop o)
|
|
|
|
: op(o) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_eval : public instruction {
|
2019-10-09 22:46:17 -07:00
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_alloc : public instruction {
|
|
|
|
int amount;
|
|
|
|
|
|
|
|
instruction_alloc(int a)
|
|
|
|
: amount(a) {}
|
2019-10-09 22:46:17 -07:00
|
|
|
|
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct instruction_unwind : public instruction {
|
2019-10-09 22:46:17 -07:00
|
|
|
void print(int indent, std::ostream& to) const;
|
2019-10-01 14:34:38 -07:00
|
|
|
};
|