@@ -40,22 +40,34 @@ static std::vector<LocalVarData> define_builtin_parameters(const std::vector<Typ
4040 return parameters;
4141}
4242
43- static void define_builtin_func (const std::string& name, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const simple_compile_func_t & func, int flags) {
44- auto * f_sym = new FunctionData (name, {}, " " , nullptr , return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltin (func), nullptr );
43+ static void define_builtin_func (const std::string& name, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const std::function<FunctionBodyBuiltinAsmOp::CompileToAsmOpImpl> & func, int flags) {
44+ auto * f_sym = new FunctionData (name, {}, " " , nullptr , return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltinAsmOp (func), nullptr );
4545 G.symtable .add_function (f_sym);
4646}
4747
48- static void define_builtin_method (const std::string& name, TypePtr receiver_type, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const simple_compile_func_t & func, int flags,
48+ static void define_builtin_func (const std::string& name, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const std::function<FunctionBodyBuiltinGenerateOps::GenerateOpsImpl>& func, int flags) {
49+ auto * f_sym = new FunctionData (name, {}, " " , nullptr , return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltinGenerateOps (func), nullptr );
50+ G.symtable .add_function (f_sym);
51+ }
52+
53+ static void define_builtin_method (const std::string& name, TypePtr receiver_type, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const std::function<FunctionBodyBuiltinAsmOp::CompileToAsmOpImpl>& func, int flags,
4954 std::initializer_list<int > arg_order = {}, std::initializer_list<int > ret_order = {}) {
5055 std::string method_name = name.substr (name.find (' .' ) + 1 );
51- auto * f_sym = new FunctionData (name, {}, std::move (method_name), receiver_type, return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltin (func), nullptr );
56+ auto * f_sym = new FunctionData (name, {}, std::move (method_name), receiver_type, return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltinAsmOp (func), nullptr );
5257 f_sym->arg_order = arg_order;
5358 f_sym->ret_order = ret_order;
5459 G.symtable .add_function (f_sym);
5560 G.all_methods .push_back (f_sym);
5661}
5762
58- void FunctionBodyBuiltin::compile (AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in,
63+ void define_builtin_method (const std::string& name, TypePtr receiver_type, const std::vector<TypePtr>& params_types, TypePtr return_type, const GenericsDeclaration* genericTs, const std::function<FunctionBodyBuiltinGenerateOps::GenerateOpsImpl>& func, int flags) {
64+ std::string method_name = name.substr (name.find (' .' ) + 1 );
65+ auto * f_sym = new FunctionData (name, {}, std::move (method_name), receiver_type, return_type, define_builtin_parameters (params_types, flags), flags, FunctionInlineMode::notCalculated, genericTs, nullptr , new FunctionBodyBuiltinGenerateOps (func), nullptr );
66+ G.symtable .add_function (f_sym);
67+ G.all_methods .push_back (f_sym);
68+ }
69+
70+ void FunctionBodyBuiltinAsmOp::compile (AsmOpList& dest, std::vector<VarDescr>& out, std::vector<VarDescr>& in,
5971 SrcLocation loc) const {
6072 dest << simple_compile (out, in, loc);
6173}
@@ -1166,7 +1178,7 @@ static AsmOp compile_fetch_slice(std::vector<VarDescr>& res, std::vector<VarDesc
11661178
11671179// fun slice.tryStripPrefix(mutate self, prefix: int, prefixLen: int): bool
11681180// constructs "x{...} SDBEGINSQ" for constant arguments
1169- AsmOp compile_slice_sdbeginsq (std::vector<VarDescr>& res, std::vector<VarDescr>& args, SrcLocation loc) {
1181+ static AsmOp compile_slice_sdbeginsq (std::vector<VarDescr>& res, std::vector<VarDescr>& args, SrcLocation loc) {
11701182 tolk_assert (args.size () == 3 && res.size () == 2 );
11711183 auto & prefix = args[1 ];
11721184 auto & prefix_len = args[2 ];
@@ -1181,7 +1193,7 @@ AsmOp compile_slice_sdbeginsq(std::vector<VarDescr>& res, std::vector<VarDescr>&
11811193}
11821194
11831195// fun slice.skipBits(mutate self, len: int): self "SDSKIPFIRST"
1184- AsmOp compile_skip_bits_in_slice (std::vector<VarDescr>& res, std::vector<VarDescr>& args, SrcLocation loc) {
1196+ static AsmOp compile_skip_bits_in_slice (std::vector<VarDescr>& res, std::vector<VarDescr>& args, SrcLocation loc) {
11851197 tolk_assert (args.size () == 2 && res.size () == 1 );
11861198 auto & len = args[1 ];
11871199 // same technique as for storeUint:
@@ -1268,7 +1280,7 @@ static AsmOp compile_any_object_sizeof(std::vector<VarDescr>& res, std::vector<V
12681280
12691281// fun ton(amount: slice): coins; ton("0.05") replaced by 50000000 at compile-time
12701282// same for stringCrc32(constString: slice) and others
1271- AsmOp compile_time_only_function (std::vector<VarDescr>&, std::vector<VarDescr>&, SrcLocation loc) {
1283+ static AsmOp compile_time_only_function (std::vector<VarDescr>&, std::vector<VarDescr>&, SrcLocation loc) {
12721284 // all ton() invocations are constants, replaced by integers; no dynamic values allowed, no work at runtime
12731285 tolk_assert (false );
12741286 return AsmOp::Nop (loc);
@@ -1292,6 +1304,24 @@ static AsmOp compile_expect_type(std::vector<VarDescr>&, std::vector<VarDescr>&,
12921304 return AsmOp::Nop (loc);
12931305}
12941306
1307+ // implemented in dedicated files
1308+
1309+ using GenerateOpsImpl = FunctionBodyBuiltinGenerateOps::GenerateOpsImpl;
1310+
1311+ GenerateOpsImpl generate_T_toCell;
1312+ GenerateOpsImpl generate_builder_storeAny;
1313+ GenerateOpsImpl generate_T_fromSlice;
1314+ GenerateOpsImpl generate_slice_loadAny;
1315+ GenerateOpsImpl generate_T_fromCell;
1316+ GenerateOpsImpl generate_T_forceLoadLazyObject;
1317+ GenerateOpsImpl generate_slice_skipAny;
1318+ GenerateOpsImpl generate_T_estimatePackSize;
1319+
1320+ GenerateOpsImpl generate_createMessage;
1321+ GenerateOpsImpl generate_createExternalLogMessage;
1322+ GenerateOpsImpl generate_address_buildInAnotherShard;
1323+ GenerateOpsImpl generate_AutoDeployAddress_buildAddress;
1324+ GenerateOpsImpl generate_AutoDeployAddress_addressMatches;
12951325
12961326void define_builtins () {
12971327 using namespace std ::placeholders;
@@ -1546,8 +1576,8 @@ void define_builtins() {
15461576 compile_tuple_set_at,
15471577 FunctionData::flagMarkedAsPure | FunctionData::flagHasMutateParams | FunctionData::flagAcceptsSelf);
15481578 define_builtin_method (" address.buildSameAddressInAnotherShard" , Address, {Address, AddressShardingOptions}, Builder, nullptr ,
1549- compile_time_only_function ,
1550- FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagCompileTimeGen );
1579+ generate_address_buildInAnotherShard ,
1580+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf);
15511581 define_builtin_method (" debug.print" , debug, {typeT}, Unit, declGenericT,
15521582 compile_debug_print_to_string,
15531583 FunctionData::flagAllowAnyWidthT);
@@ -1564,51 +1594,51 @@ void define_builtins() {
15641594 // serialization/deserialization methods to/from cells (or, more low-level, slices/builders)
15651595 // they work with structs (or, more low-level, with arbitrary types)
15661596 define_builtin_method (" T.toCell" , typeT, {typeT, PackOptions}, CellT, declReceiverT,
1567- compile_time_only_function ,
1568- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
1597+ generate_T_toCell ,
1598+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
15691599 define_builtin_method (" T.fromCell" , typeT, {TypeDataCell::create (), UnpackOptions}, typeT, declReceiverT,
1570- compile_time_only_function ,
1571- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAllowAnyWidthT);
1600+ generate_T_fromCell ,
1601+ FunctionData::flagMarkedAsPure | FunctionData::flagAllowAnyWidthT);
15721602 define_builtin_method (" T.fromSlice" , typeT, {Slice, UnpackOptions}, typeT, declReceiverT,
1573- compile_time_only_function ,
1574- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAllowAnyWidthT);
1575- define_builtin_method (" T.estimatePackSize" , typeT, {}, TypeDataBrackets ::create ({TypeDataInt::create (), TypeDataInt::create (), TypeDataInt::create (), TypeDataInt::create ()}), declReceiverT,
1576- compile_time_only_function ,
1577- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAllowAnyWidthT);
1603+ generate_T_fromSlice ,
1604+ FunctionData::flagMarkedAsPure | FunctionData::flagAllowAnyWidthT);
1605+ define_builtin_method (" T.estimatePackSize" , typeT, {}, TypeDataTensor ::create ({TypeDataInt::create (), TypeDataInt::create (), TypeDataInt::create (), TypeDataInt::create ()}), declReceiverT,
1606+ generate_T_estimatePackSize ,
1607+ FunctionData::flagMarkedAsPure | FunctionData::flagAllowAnyWidthT);
15781608 define_builtin_method (" T.getDeclaredPackPrefix" , typeT, {}, Int, declReceiverT,
15791609 compile_time_only_function,
15801610 FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeVal | FunctionData::flagAllowAnyWidthT);
15811611 define_builtin_method (" T.getDeclaredPackPrefixLen" , typeT, {}, Int, declReceiverT,
15821612 compile_time_only_function,
15831613 FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeVal | FunctionData::flagAllowAnyWidthT);
15841614 define_builtin_method (" T.forceLoadLazyObject" , typeT, {typeT}, Slice, declReceiverT,
1585- compile_time_only_function ,
1586- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
1615+ generate_T_forceLoadLazyObject ,
1616+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
15871617 define_builtin_method (" Cell<T>.load" , CellT, {CellT, UnpackOptions}, typeT, declReceiverT,
1588- compile_time_only_function ,
1589- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
1618+ generate_T_fromCell ,
1619+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagAllowAnyWidthT);
15901620 define_builtin_method (" slice.loadAny" , Slice, {Slice, UnpackOptions}, typeT, declGenericT,
1591- compile_time_only_function ,
1592- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
1621+ generate_slice_loadAny ,
1622+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
15931623 define_builtin_method (" slice.skipAny" , Slice, {Slice, UnpackOptions}, Slice, declGenericT,
1594- compile_time_only_function ,
1595- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagReturnsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
1624+ generate_slice_skipAny ,
1625+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagReturnsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
15961626 define_builtin_method (" builder.storeAny" , Builder, {Builder, typeT, PackOptions}, Builder, declGenericT,
1597- compile_time_only_function ,
1598- FunctionData::flagMarkedAsPure | FunctionData::flagCompileTimeGen | FunctionData:: flagAcceptsSelf | FunctionData::flagReturnsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
1627+ generate_builder_storeAny ,
1628+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagReturnsSelf | FunctionData::flagHasMutateParams | FunctionData::flagAllowAnyWidthT);
15991629
16001630 define_builtin_func (" createMessage" , {CreateMessageOptions}, OutMessage, declTBody,
1601- compile_time_only_function ,
1602- FunctionData::flagCompileTimeGen | FunctionData:: flagAllowAnyWidthT);
1631+ generate_createMessage ,
1632+ FunctionData::flagAllowAnyWidthT);
16031633 define_builtin_func (" createExternalLogMessage" , {CreateExternalLogMessageOptions}, OutMessage, declTBody,
1604- compile_time_only_function ,
1605- FunctionData::flagCompileTimeGen | FunctionData:: flagAllowAnyWidthT);
1634+ generate_createExternalLogMessage ,
1635+ FunctionData::flagAllowAnyWidthT);
16061636 define_builtin_method (" AutoDeployAddress.buildAddress" , AutoDeployAddress, {AutoDeployAddress}, Builder, nullptr ,
1607- compile_time_only_function ,
1608- FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagCompileTimeGen );
1637+ generate_AutoDeployAddress_buildAddress ,
1638+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf);
16091639 define_builtin_method (" AutoDeployAddress.addressMatches" , AutoDeployAddress, {AutoDeployAddress, Address}, Bool, nullptr ,
1610- compile_time_only_function ,
1611- FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf | FunctionData::flagCompileTimeGen );
1640+ generate_AutoDeployAddress_addressMatches ,
1641+ FunctionData::flagMarkedAsPure | FunctionData::flagAcceptsSelf);
16121642
16131643 // functions not presented in stdlib at all
16141644 // used in tolk-tester to check/expose internal compiler state
0 commit comments