mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] Embedded stdlib.tolk, CompilerState, strict includes
Several related changes: - stdlib.tolk is embedded into a distribution (deb package or tolk-js), the user won't have to download it and store as a project file; it's an important step to maintain correct language versioning - stdlib.tolk is auto-included, that's why all its functions are available out of the box - strict includes: you can't use symbol `f` from another file unless you've #include'd this file - drop all C++ global variables holding compilation state, merge them into a single struct CompilerState located at compiler-state.h; for instance, stdlib filename is also there
This commit is contained in:
parent
f0e6470d0b
commit
6c30e5a7eb
21 changed files with 604 additions and 506 deletions
|
@ -15,6 +15,7 @@
|
|||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "tolk.h"
|
||||
#include "compiler-state.h"
|
||||
|
||||
namespace tolk {
|
||||
|
||||
|
@ -324,7 +325,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
if (!used || disabled()) {
|
||||
return true;
|
||||
}
|
||||
std::string name = symbols.get_name(fun_ref->sym_idx);
|
||||
std::string name = G.symbols.get_name(fun_ref->sym_idx);
|
||||
stack.o << AsmOp::Custom(name + " GETGLOB", 0, 1);
|
||||
if (left.size() != 1) {
|
||||
tolk_assert(left.size() <= 15);
|
||||
|
@ -359,7 +360,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
}
|
||||
func->compile(stack.o, res, args0, where); // compile res := f (args0)
|
||||
} else {
|
||||
std::string name = symbols.get_name(fun_ref->sym_idx);
|
||||
std::string name = G.symbols.get_name(fun_ref->sym_idx);
|
||||
stack.o << AsmOp::Custom(name + " CALLDICT", (int)right.size(), (int)left.size());
|
||||
}
|
||||
stack.o.undent();
|
||||
|
@ -497,7 +498,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
} else {
|
||||
auto fv = dynamic_cast<const SymValCodeFunc*>(fun_ref->value);
|
||||
// todo can be fv == nullptr?
|
||||
std::string name = symbols.get_name(fun_ref->sym_idx);
|
||||
std::string name = G.symbols.get_name(fun_ref->sym_idx);
|
||||
if (fv && (fv->is_inline() || fv->is_inline_ref())) {
|
||||
stack.o << AsmOp::Custom(name + " INLINECALLDICT", (int)right.size(), (int)left.size());
|
||||
} else if (fv && fv->code && fv->code->require_callxargs) {
|
||||
|
@ -534,7 +535,7 @@ bool Op::generate_code_step(Stack& stack) {
|
|||
stack.o << AsmOp::Tuple((int)right.size());
|
||||
}
|
||||
if (!right.empty()) {
|
||||
std::string name = symbols.get_name(fun_ref->sym_idx);
|
||||
std::string name = G.symbols.get_name(fun_ref->sym_idx);
|
||||
stack.o << AsmOp::Custom(name + " SETGLOB", 1, 0);
|
||||
}
|
||||
stack.s.resize(k);
|
||||
|
@ -894,14 +895,14 @@ void CodeBlob::generate_code(AsmOpList& out, int mode) {
|
|||
}
|
||||
ops->generate_code_all(stack);
|
||||
stack.apply_wrappers(require_callxargs && (mode & Stack::_InlineAny) ? args : -1);
|
||||
if (!(mode & Stack::_DisableOpt)) {
|
||||
optimize_code(out);
|
||||
}
|
||||
}
|
||||
|
||||
void CodeBlob::generate_code(std::ostream& os, int mode, int indent) {
|
||||
AsmOpList out_list(indent, &vars);
|
||||
generate_code(out_list, mode);
|
||||
if (G.settings.optimization_level >= 2) {
|
||||
optimize_code(out_list);
|
||||
}
|
||||
out_list.out(os, mode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue