9std::expected<city::Assembly, CompilationError>
Compiler::Compile(std::string_view program_text, std::vector<bf::Token<ParserGrammarType>> *tokens)
11 auto ast = this->parser_.Parse(program_text, tokens);
14 return std::unexpected(ast.error());
16 auto ast_body = std::get<std::unique_ptr<Node>>(std::move(*ast));
18 this->jit_.RemoveModule(
"__user");
22 city::IRModule
module{"__user"};
28 .
scope = this->scope_,
35 this->jit_.InsertIRModule(std::move(module));
37 catch (std::runtime_error &e)
39 return std::unexpected(
Error{e.what()});
42 return this->jit_.Link();
49 scene->
AddPlot(
"anon", function);
57 city::InterfaceModule stdlib{
"std"};
58 city::Function *std_functions[] = {
59 stdlib.InsertBinding(
"__pow", (
double (*)(
double,
double))std::pow),
60 stdlib.InsertBinding(
"__sqrt", (
double (*)(
double))std::sqrt),
65 for (
auto function: std_functions)
67 this->scope_.
Set(*function->GetName(), function);
70 this->jit_.InsertInterfaceModule(std::move(stdlib));
void unlogic_plot_anon(Scene *scene, Plot2dFunctionType function)
std::expected< city::Assembly, CompilationError > Compile(std::string_view program_text, std::vector< bf::Token< ParserGrammarType > > *tokens=nullptr)
void Set(std::string const &key, city::Value *value)
double(*)(double) Plot2dFunctionType
bf::GrammarDefinition< ParserValueType, SyntaxHighlightingGroup > ParserGrammarType
bf::NonTerminal< ParserGrammarType > & unlogic_program
city::IRModule &Scope & scope
void AddPlot(char const *name, Plot2dFunctionType function)