95 city::IRBlock &parent = this->builder.GetInsertPoint();
98 std::vector<city::Type> argument_types(node.
args.size(), city::Type::Get<double>());
99 city::IRFunction *function = this->builder.CreateFunction(node.
name, city::Type::Get<double>(), argument_types);
101 this->ctx.scope.Set(node.
name, function);
103 ctx.scope.PushLayer();
104 for (
auto const &[value, name]: std::views::zip(function->GetArgumentValues(), node.
args))
106 ctx.scope.Set(name, value);
109 city::Value *retval = std::visit(*
this, *node.
body);
111 this->builder.InsertRetInst(retval);
113 ctx.scope.PopLayer();
116 this->builder.SetInsertPoint(parent);
123 city::Value *scene = *this->ctx.scope.Lookup(
"__scene");
125 auto function = (*this->ctx.scope.Lookup(node.
function_name))->ToFunction();
128 throw std::runtime_error(std::format(
"Function \"{}\" could not be found!", node.
function_name));
131 auto plot_anon = (*this->ctx.scope.Lookup(
"__plot_anon"))->ToFunction();
133 return this->builder.InsertCallInst(plot_anon, {scene, function});
138 city::IRFunction *entry = this->builder.CreateFunction(
"__entry", city::Type::Get<double>(), {city::Type::Get<void *>()});
140 this->ctx.scope.PushLayer();
141 this->ctx.scope.Set(
"__scene", entry->GetArgumentValues()[0]);
143 std::visit(*
this, *node.
body);
145 this->builder.InsertRetInst();
146 this->ctx.scope.PopLayer();