forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:disintar/ton into dev
- Loading branch information
Showing
9 changed files
with
183 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 Disintar LLP / [email protected] | ||
|
||
#include "PyFunc.h" | ||
|
||
class CompilationException : public std::runtime_error { | ||
public: | ||
explicit CompilationException(const std::string& message) | ||
: std::runtime_error(message) {} | ||
}; | ||
|
||
std::string compile_from_sources(const std::vector<std::string>& sources) { | ||
std::ostringstream output; | ||
funC::read_callback = funC::fs_read_callback; | ||
int result = funC::func_proceed(sources, output, std::cerr); | ||
if (result != 0) { | ||
throw CompilationException("Compilation failed!"); | ||
} | ||
return output.str(); | ||
} | ||
|
||
std::string func_to_asm(const std::vector<std::string>& sources, | ||
bool preamble, | ||
int indent, | ||
bool verbosity, | ||
int optimization, | ||
bool envelope, | ||
bool stack_comments, | ||
bool op_comments | ||
) { | ||
funC::asm_preamble = preamble; | ||
funC::indent = indent; | ||
if (verbosity) ++funC::verbosity; | ||
funC::opt_level = optimization; | ||
funC::program_envelope = envelope; | ||
funC::stack_layout_comments = stack_comments; | ||
funC::op_rewrite_comments = op_comments; | ||
|
||
std::ostringstream err; | ||
std::string res = compile_from_sources(sources); | ||
return res; | ||
} | ||
|
||
std::string func_string_to_asm(const std::string& source, | ||
bool preamble, | ||
int indent, | ||
bool verbosity, | ||
int optimization, | ||
bool envelope, | ||
bool stack_comments, | ||
bool op_comments | ||
) { | ||
funC::asm_preamble = preamble; | ||
funC::indent = indent; | ||
if (verbosity) ++funC::verbosity; | ||
funC::opt_level = optimization; | ||
funC::program_envelope = envelope; | ||
funC::stack_layout_comments = stack_comments; | ||
funC::op_rewrite_comments = op_comments; | ||
funC::interactive_from_string = true; | ||
std::string res = compile_from_sources(std::vector<std::string>{source}); | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <string> | ||
#include <stdexcept> | ||
#include "td/utils/Status.h" | ||
#include <utility> | ||
#include "crypto/func/func.h" | ||
#include "crypto/fift/Fift.h" | ||
#include "crypto/fift/utils.h" | ||
#include "PyCell.h" | ||
|
||
|
||
#ifndef TON_FUNC_H | ||
#define TON_FUNC_H | ||
|
||
std::string compile_from_sources(const std::vector<std::string>& sources, std::ostringstream& errors); | ||
std::string func_to_asm(const std::vector<std::string>& sources, | ||
bool preamble = true, | ||
int indent = 0, | ||
bool verbosity = false, | ||
int optimization = 0, | ||
bool envelope = true, | ||
bool stack_comments = true, | ||
bool op_comments = false | ||
); | ||
std::string func_string_to_asm(const std::string& source, | ||
bool preamble = true, | ||
int indent = 0, | ||
bool verbosity = false, | ||
int optimization = 0, | ||
bool envelope = true, | ||
bool stack_comments = true, | ||
bool op_comments = false | ||
); | ||
|
||
#endif //TON_FIFT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters