mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add constants and string literals to funC
* Add special string literals "..."? (s,a,u,h,) * Add string literal H (256-bit hash) * Add string literal c (crc32) * Use td::hex_encode instead of homebrew function and add test * Fix error codes and use more generic address * Add support for int and slice constants * Add support for strongly typed constants * Add support for precompiled constant expressions (hard!) Co-authored-by: starlightduck <starlightduck@gmail.com>
This commit is contained in:
parent
0e955793ed
commit
0c772185ef
14 changed files with 397 additions and 26 deletions
|
@ -109,6 +109,7 @@ enum Keyword {
|
|||
_Infix,
|
||||
_Infixl,
|
||||
_Infixr,
|
||||
_Const,
|
||||
_PragmaHashtag
|
||||
};
|
||||
|
||||
|
@ -336,6 +337,8 @@ struct VarDescr {
|
|||
static constexpr int FiniteUInt = FiniteInt | _Pos;
|
||||
int val;
|
||||
td::RefInt256 int_const;
|
||||
std::string str_const;
|
||||
|
||||
VarDescr(var_idx_t _idx = -1, int _flags = 0, int _val = 0) : idx(_idx), flags(_flags), val(_val) {
|
||||
}
|
||||
bool operator<(var_idx_t other_idx) const {
|
||||
|
@ -406,6 +409,7 @@ struct VarDescr {
|
|||
}
|
||||
void set_const(long long value);
|
||||
void set_const(td::RefInt256 value);
|
||||
void set_const(std::string value);
|
||||
void set_const_nan();
|
||||
void operator+=(const VarDescr& y) {
|
||||
flags &= y.flags;
|
||||
|
@ -530,7 +534,8 @@ struct Op {
|
|||
_While,
|
||||
_Until,
|
||||
_Repeat,
|
||||
_Again
|
||||
_Again,
|
||||
_SliceConst
|
||||
};
|
||||
int cl;
|
||||
enum { _Disabled = 1, _Reachable = 2, _NoReturn = 4, _ImpureR = 8, _ImpureW = 16, _Impure = 24 };
|
||||
|
@ -543,6 +548,7 @@ struct Op {
|
|||
std::vector<var_idx_t> left, right;
|
||||
std::unique_ptr<Op> block0, block1;
|
||||
td::RefInt256 int_const;
|
||||
std::string str_const;
|
||||
Op(const SrcLocation& _where = {}, int _cl = _Undef) : cl(_cl), flags(0), fun_ref(nullptr), where(_where) {
|
||||
}
|
||||
Op(const SrcLocation& _where, int _cl, const std::vector<var_idx_t>& _left)
|
||||
|
@ -554,6 +560,9 @@ struct Op {
|
|||
Op(const SrcLocation& _where, int _cl, const std::vector<var_idx_t>& _left, td::RefInt256 _const)
|
||||
: cl(_cl), flags(0), fun_ref(nullptr), where(_where), left(_left), int_const(_const) {
|
||||
}
|
||||
Op(const SrcLocation& _where, int _cl, const std::vector<var_idx_t>& _left, std::string _const)
|
||||
: cl(_cl), flags(0), fun_ref(nullptr), where(_where), left(_left), str_const(_const) {
|
||||
}
|
||||
Op(const SrcLocation& _where, int _cl, const std::vector<var_idx_t>& _left, const std::vector<var_idx_t>& _right,
|
||||
SymDef* _fun = nullptr)
|
||||
: cl(_cl), flags(0), fun_ref(_fun), where(_where), left(_left), right(_right) {
|
||||
|
@ -784,6 +793,30 @@ struct SymValGlobVar : sym::SymValBase {
|
|||
}
|
||||
};
|
||||
|
||||
struct SymValConst : sym::SymValBase {
|
||||
td::RefInt256 intval;
|
||||
std::string strval;
|
||||
Keyword type;
|
||||
SymValConst(int idx, td::RefInt256 value)
|
||||
: sym::SymValBase(_Const, idx), intval(value) {
|
||||
type = _Int;
|
||||
}
|
||||
SymValConst(int idx, std::string value)
|
||||
: sym::SymValBase(_Const, idx), strval(value) {
|
||||
type = _Slice;
|
||||
}
|
||||
~SymValConst() override = default;
|
||||
td::RefInt256 get_int_value() const {
|
||||
return intval;
|
||||
}
|
||||
std::string get_str_value() const {
|
||||
return strval;
|
||||
}
|
||||
Keyword get_type() const {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
||||
extern int glob_func_cnt, undef_func_cnt, glob_var_cnt;
|
||||
extern std::vector<SymDef*> glob_func, glob_vars;
|
||||
|
||||
|
@ -820,7 +853,8 @@ struct Expr {
|
|||
_LetFirst,
|
||||
_Hole,
|
||||
_Type,
|
||||
_CondExpr
|
||||
_CondExpr,
|
||||
_SliceConst
|
||||
};
|
||||
int cls;
|
||||
int val{0};
|
||||
|
@ -828,6 +862,7 @@ struct Expr {
|
|||
int flags{0};
|
||||
SrcLocation here;
|
||||
td::RefInt256 intval;
|
||||
std::string strval;
|
||||
SymDef* sym{nullptr};
|
||||
TypeExpr* e_type{nullptr};
|
||||
std::vector<Expr*> args;
|
||||
|
@ -910,6 +945,7 @@ struct AsmOp {
|
|||
int a, b, c;
|
||||
bool gconst{false};
|
||||
std::string op;
|
||||
td::RefInt256 origin;
|
||||
struct SReg {
|
||||
int idx;
|
||||
SReg(int _idx) : idx(_idx) {
|
||||
|
@ -929,6 +965,9 @@ struct AsmOp {
|
|||
AsmOp(int _t, int _a, int _b, std::string _op) : t(_t), a(_a), b(_b), op(std::move(_op)) {
|
||||
compute_gconst();
|
||||
}
|
||||
AsmOp(int _t, int _a, int _b, std::string _op, td::RefInt256 x) : t(_t), a(_a), b(_b), op(std::move(_op)), origin(x) {
|
||||
compute_gconst();
|
||||
}
|
||||
AsmOp(int _t, int _a, int _b, int _c) : t(_t), a(_a), b(_b), c(_c) {
|
||||
}
|
||||
AsmOp(int _t, int _a, int _b, int _c, std::string _op) : t(_t), a(_a), b(_b), c(_c), op(std::move(_op)) {
|
||||
|
@ -1047,10 +1086,10 @@ struct AsmOp {
|
|||
static AsmOp make_stk3(int a, int b, int c, const char* str, int delta);
|
||||
static AsmOp IntConst(td::RefInt256 value);
|
||||
static AsmOp BoolConst(bool f);
|
||||
static AsmOp Const(std::string push_op) {
|
||||
return AsmOp(a_const, 0, 1, std::move(push_op));
|
||||
static AsmOp Const(std::string push_op, td::RefInt256 origin = {}) {
|
||||
return AsmOp(a_const, 0, 1, std::move(push_op), origin);
|
||||
}
|
||||
static AsmOp Const(int arg, std::string push_op);
|
||||
static AsmOp Const(int arg, std::string push_op, td::RefInt256 origin = {});
|
||||
static AsmOp Comment(std::string comment) {
|
||||
return AsmOp(a_none, std::string{"// "} + comment);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue