diff --git a/.gitignore b/.gitignore index 536918ab..5ac24ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ test/regression-tests.cache/ **/*build*/ .idea .vscode +dev/ +.DS_Store zlib/ libsodium/ libmicrohttpd-0.9.77-w32-bin/ diff --git a/crypto/func/func.h b/crypto/func/func.h index 2b95bcbc..7da3f0ad 100644 --- a/crypto/func/func.h +++ b/crypto/func/func.h @@ -149,8 +149,8 @@ class IdSc { */ struct TypeExpr { - enum te_type { te_Unknown, te_Var, te_Indirect, te_Atomic, te_Tensor, te_Tuple, te_Map, te_Type, te_ForAll } constr; - enum { + enum te_type { te_Unknown, te_Var, te_Indirect, te_Atomic, te_Tensor, te_Tuple, te_Map, te_ForAll } constr; + enum AtomicType { _Int = Keyword::_Int, _Cell = Keyword::_Cell, _Slice = Keyword::_Slice, @@ -216,7 +216,7 @@ struct TypeExpr { void compute_width(); bool recompute_width(); void show_width(std::ostream& os); - std::ostream& print(std::ostream& os, int prio = 0); + std::ostream& print(std::ostream& os, int prio = 0) const; void replace_with(TypeExpr* te2); int extract_components(std::vector& comp_list); static int holes, type_vars; @@ -535,7 +535,7 @@ class ListIterator { struct Stack; struct Op { - enum { + enum OpKind { _Undef, _Nop, _Call, @@ -554,10 +554,10 @@ struct Op { _Repeat, _Again, _TryCatch, - _SliceConst + _SliceConst, }; - int cl; - enum { _Disabled = 1, _Reachable = 2, _NoReturn = 4, _ImpureR = 8, _ImpureW = 16, _Impure = 24 }; + OpKind cl; + enum { _Disabled = 1, _NoReturn = 4, _Impure = 24 }; int flags; std::unique_ptr next; SymDef* fun_ref; @@ -568,25 +568,25 @@ struct Op { std::unique_ptr 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 = {}, OpKind _cl = _Undef) : cl(_cl), flags(0), fun_ref(nullptr), where(_where) { } - Op(const SrcLocation& _where, int _cl, const std::vector& _left) + Op(const SrcLocation& _where, OpKind _cl, const std::vector& _left) : cl(_cl), flags(0), fun_ref(nullptr), where(_where), left(_left) { } - Op(const SrcLocation& _where, int _cl, std::vector&& _left) + Op(const SrcLocation& _where, OpKind _cl, std::vector&& _left) : cl(_cl), flags(0), fun_ref(nullptr), where(_where), left(std::move(_left)) { } - Op(const SrcLocation& _where, int _cl, const std::vector& _left, td::RefInt256 _const) + Op(const SrcLocation& _where, OpKind _cl, const std::vector& _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& _left, std::string _const) + Op(const SrcLocation& _where, OpKind _cl, const std::vector& _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& _left, const std::vector& _right, + Op(const SrcLocation& _where, OpKind _cl, const std::vector& _left, const std::vector& _right, SymDef* _fun = nullptr) : cl(_cl), flags(0), fun_ref(_fun), where(_where), left(_left), right(_right) { } - Op(const SrcLocation& _where, int _cl, std::vector&& _left, std::vector&& _right, + Op(const SrcLocation& _where, OpKind _cl, std::vector&& _left, std::vector&& _right, SymDef* _fun = nullptr) : cl(_cl), flags(0), fun_ref(_fun), where(_where), left(std::move(_left)), right(std::move(_right)) { } @@ -599,9 +599,6 @@ struct Op { void disable() { flags |= _Disabled; } - bool unreachable() { - return !(flags & _Reachable); - } void flags_set_clear(int set, int clear); void show(std::ostream& os, const std::vector& vars, std::string pfx = "", int mode = 0) const; void show_var_list(std::ostream& os, const std::vector& idx_list, const std::vector& vars) const; @@ -898,7 +895,7 @@ extern std::stack inclusion_locations; */ struct Expr { - enum { + enum ExprCls { _None, _Apply, _VarApply, @@ -914,11 +911,11 @@ struct Expr { _Hole, _Type, _CondExpr, - _SliceConst + _SliceConst, }; - int cls; + ExprCls cls; int val{0}; - enum { _IsType = 1, _IsRvalue = 2, _IsLvalue = 4, _IsHole = 8, _IsNewVar = 16, _IsImpure = 32 }; + enum { _IsType = 1, _IsRvalue = 2, _IsLvalue = 4, _IsImpure = 32 }; int flags{0}; SrcLocation here; td::RefInt256 intval; @@ -926,19 +923,19 @@ struct Expr { SymDef* sym{nullptr}; TypeExpr* e_type{nullptr}; std::vector args; - Expr(int c = _None) : cls(c) { + explicit Expr(ExprCls c = _None) : cls(c) { } - Expr(int c, const SrcLocation& loc) : cls(c), here(loc) { + Expr(ExprCls c, const SrcLocation& loc) : cls(c), here(loc) { } - Expr(int c, std::vector _args) : cls(c), args(std::move(_args)) { + Expr(ExprCls c, std::vector _args) : cls(c), args(std::move(_args)) { } - Expr(int c, std::initializer_list _arglist) : cls(c), args(std::move(_arglist)) { + Expr(ExprCls c, std::initializer_list _arglist) : cls(c), args(std::move(_arglist)) { } - Expr(int c, SymDef* _sym, std::initializer_list _arglist) : cls(c), sym(_sym), args(std::move(_arglist)) { + Expr(ExprCls c, SymDef* _sym, std::initializer_list _arglist) : cls(c), sym(_sym), args(std::move(_arglist)) { } - Expr(int c, SymDef* _sym, std::vector _arglist) : cls(c), sym(_sym), args(std::move(_arglist)) { + Expr(ExprCls c, SymDef* _sym, std::vector _arglist) : cls(c), sym(_sym), args(std::move(_arglist)) { } - Expr(int c, sym_idx_t name_idx, std::initializer_list _arglist); + Expr(ExprCls c, sym_idx_t name_idx, std::initializer_list _arglist); ~Expr() { for (auto& arg_ptr : args) { delete arg_ptr; @@ -979,7 +976,6 @@ struct Expr { int define_new_vars(CodeBlob& code); int predefine_vars(); std::vector pre_compile(CodeBlob& code, std::vector>* lval_globs = nullptr) const; - static std::vector pre_compile_let(CodeBlob& code, Expr* lhs, Expr* rhs, const SrcLocation& here); var_idx_t new_tmp(CodeBlob& code) const; std::vector new_tmp_vect(CodeBlob& code) const { return {new_tmp(code)}; @@ -1000,9 +996,9 @@ using Const = td::RefInt256; struct AsmOp { enum Type { a_none, a_xchg, a_push, a_pop, a_const, a_custom, a_magic }; - int t{a_none}; + Type t{a_none}; int indent{0}; - int a, b, c; + int a, b; bool gconst{false}; std::string op; td::RefInt256 origin; @@ -1012,26 +1008,22 @@ struct AsmOp { } }; AsmOp() = default; - AsmOp(int _t) : t(_t) { + AsmOp(Type _t) : t(_t) { } - AsmOp(int _t, std::string _op) : t(_t), op(std::move(_op)) { + AsmOp(Type _t, std::string _op) : t(_t), op(std::move(_op)) { } - AsmOp(int _t, int _a) : t(_t), a(_a) { + AsmOp(Type _t, int _a) : t(_t), a(_a) { } - AsmOp(int _t, int _a, std::string _op) : t(_t), a(_a), op(std::move(_op)) { + AsmOp(Type _t, int _a, std::string _op) : t(_t), a(_a), op(std::move(_op)) { } - AsmOp(int _t, int _a, int _b) : t(_t), a(_a), b(_b) { + AsmOp(Type _t, int _a, int _b) : t(_t), a(_a), b(_b) { } - AsmOp(int _t, int _a, int _b, std::string _op) : t(_t), a(_a), b(_b), op(std::move(_op)) { + AsmOp(Type _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) { + AsmOp(Type _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)) { - } void out(std::ostream& os) const; void out_indent_nl(std::ostream& os, bool no_nl = false) const; std::string to_string() const; diff --git a/crypto/func/gen-abscode.cpp b/crypto/func/gen-abscode.cpp index 9989d10c..fe2d1850 100644 --- a/crypto/func/gen-abscode.cpp +++ b/crypto/func/gen-abscode.cpp @@ -37,7 +37,7 @@ Expr* Expr::copy() const { return res; } -Expr::Expr(int c, sym_idx_t name_idx, std::initializer_list _arglist) : cls(c), args(std::move(_arglist)) { +Expr::Expr(ExprCls c, sym_idx_t name_idx, std::initializer_list _arglist) : cls(c), args(std::move(_arglist)) { sym = sym::lookup_symbol(name_idx); if (!sym) { } @@ -233,7 +233,7 @@ void add_set_globs(CodeBlob& code, std::vector>& g } } -std::vector Expr::pre_compile_let(CodeBlob& code, Expr* lhs, Expr* rhs, const SrcLocation& here) { +std::vector pre_compile_let(CodeBlob& code, Expr* lhs, Expr* rhs, const SrcLocation& here) { while (lhs->is_type_apply()) { lhs = lhs->args.at(0); } @@ -249,7 +249,7 @@ std::vector Expr::pre_compile_let(CodeBlob& code, Expr* lhs, Expr* rh auto unpacked_type = rhs->e_type->args.at(0); std::vector tmp{code.create_tmp_var(unpacked_type, &rhs->here)}; code.emplace_back(lhs->here, Op::_UnTuple, tmp, std::move(right)); - auto tvar = new Expr{_Var}; + auto tvar = new Expr{Expr::_Var}; tvar->set_val(tmp[0]); tvar->set_location(rhs->here); tvar->e_type = unpacked_type; diff --git a/crypto/func/parse-func.cpp b/crypto/func/parse-func.cpp index 15794c42..fa2bac02 100644 --- a/crypto/func/parse-func.cpp +++ b/crypto/func/parse-func.cpp @@ -580,7 +580,7 @@ Expr* parse_expr100(Lexer& lex, CodeBlob& code, bool nv) { if (t == '_') { Expr* res = new Expr{Expr::_Hole, lex.cur().loc}; res->val = -1; - res->flags = (Expr::_IsLvalue | Expr::_IsHole | Expr::_IsNewVar); + res->flags = Expr::_IsLvalue; res->e_type = TypeExpr::new_hole(); lex.next(); return res; @@ -642,7 +642,7 @@ Expr* parse_expr100(Lexer& lex, CodeBlob& code, bool nv) { if (nv) { res->val = ~lex.cur().val; res->e_type = TypeExpr::new_hole(); - res->flags = Expr::_IsLvalue | Expr::_IsNewVar; + res->flags = Expr::_IsLvalue; // std::cerr << "defined new variable " << lex.cur().str << " : " << res->e_type << std::endl; } else { if (!sym) { diff --git a/crypto/func/unify-types.cpp b/crypto/func/unify-types.cpp index f9b639c0..22b33281 100644 --- a/crypto/func/unify-types.cpp +++ b/crypto/func/unify-types.cpp @@ -209,7 +209,7 @@ std::ostream& operator<<(std::ostream& os, TypeExpr* type_expr) { return type_expr->print(os); } -std::ostream& TypeExpr::print(std::ostream& os, int lex_level) { +std::ostream& TypeExpr::print(std::ostream& os, int lex_level) const { switch (constr) { case te_Unknown: return os << "??" << value;