1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

func/fift: bugfixes

This commit is contained in:
ton 2019-10-09 20:00:54 +04:00
parent f67f5d879b
commit 38c3e39066
41 changed files with 248 additions and 99 deletions

View file

@ -43,6 +43,9 @@ td::Result<std::string> load_TonUtil_fif(std::string dir = "") {
td::Result<std::string> load_Lists_fif(std::string dir = "") {
return load_source("Lists.fif", dir);
}
td::Result<std::string> load_Lisp_fif(std::string dir = "") {
return load_source("Lisp.fif", dir);
}
class MemoryFileLoader : public fift::FileLoader {
public:
@ -91,7 +94,8 @@ class MemoryFileLoader : public fift::FileLoader {
};
td::Result<fift::SourceLookup> create_source_lookup(std::string main, bool need_preamble = true, bool need_asm = true,
bool need_ton_util = true, std::string dir = "") {
bool need_ton_util = true, bool need_lisp = true,
std::string dir = "") {
auto loader = std::make_unique<MemoryFileLoader>();
loader->add_file("/main.fif", std::move(main));
if (need_preamble) {
@ -112,6 +116,10 @@ td::Result<fift::SourceLookup> create_source_lookup(std::string main, bool need_
loader->add_file("/TonUtil.fif", std::move(f));
}
}
if (need_lisp) {
TRY_RESULT(f, load_Lisp_fif(dir));
loader->add_file("/Lisp.fif", std::move(f));
}
auto res = fift::SourceLookup(std::move(loader));
res.add_include_path("/");
return std::move(res);
@ -143,7 +151,7 @@ td::Result<fift::SourceLookup> run_fift(fift::SourceLookup source_lookup, std::o
} // namespace
td::Result<FiftOutput> mem_run_fift(std::string source, std::vector<std::string> args, std::string fift_dir) {
std::stringstream ss;
TRY_RESULT(source_lookup, create_source_lookup(source, true, true, true, fift_dir));
TRY_RESULT(source_lookup, create_source_lookup(source, true, true, true, true, fift_dir));
TRY_RESULT_ASSIGN(source_lookup, run_fift(std::move(source_lookup), &ss, true, std::move(args)));
FiftOutput res;
res.source_lookup = std::move(source_lookup);
@ -159,8 +167,8 @@ td::Result<FiftOutput> mem_run_fift(SourceLookup source_lookup, std::vector<std:
return std::move(res);
}
td::Result<fift::SourceLookup> create_mem_source_lookup(std::string main, std::string fift_dir, bool need_preamble,
bool need_asm, bool need_ton_util) {
return create_source_lookup(main, need_preamble, need_asm, need_ton_util, fift_dir);
bool need_asm, bool need_ton_util, bool need_lisp) {
return create_source_lookup(main, need_preamble, need_asm, need_ton_util, need_lisp, fift_dir);
}
td::Result<td::Ref<vm::Cell>> compile_asm(td::Slice asm_code, std::string fift_dir, bool is_raw) {
@ -168,7 +176,7 @@ td::Result<td::Ref<vm::Cell>> compile_asm(td::Slice asm_code, std::string fift_d
TRY_RESULT(source_lookup,
create_source_lookup(PSTRING() << "\"Asm.fif\" include\n " << (is_raw ? "<{" : "") << asm_code << "\n"
<< (is_raw ? "}>c" : "") << " boc>B \"res\" B>file",
true, true, true, fift_dir));
true, true, true, false, fift_dir));
TRY_RESULT(res, run_fift(std::move(source_lookup), &ss));
TRY_RESULT(boc, res.read_file("res"));
return vm::std_boc_deserialize(std::move(boc.data));