valeri/src/compiler.cpp

62 lines
1.4 KiB
C++
Raw Normal View History

#include "compiler.hpp"
2024-08-04 19:38:56 +00:00
struct Context {
Context() {}
Context(Value&& env, Array&& constants)
: env(std::move(env)),
constants(std::move(constants)),
maxreg(0),
maxconst(0) {}
2024-08-09 22:45:06 +00:00
static Result<Context> create() {
auto env = TRY(Nil::create());
auto constants = TRY(Array::create());
2024-08-04 19:38:56 +00:00
return Context(std::move(env), std::move(constants));
}
Value env;
Array constants;
uint64_t maxreg;
uint64_t maxconst;
};
2024-08-04 19:38:56 +00:00
bool is_primitive_op(Symbol& sym) {
// return (sym.cmp("+") == 0);
return false;
}
2024-08-04 19:38:56 +00:00
Result<Value> Compiler::compile(Value& expr) {
2024-08-09 22:45:06 +00:00
auto context = TRY(Context::create());
2024-08-04 19:38:56 +00:00
TRY(compile_expr(context, expr));
return ErrorCode::NotImplemented;
}
Result<Expression> Compiler::compile_expr(Context& context, Value& expr) {
switch (expr.tag()) {
case Tag::Pair:
2024-08-04 19:38:56 +00:00
return compile_list(context, *expr.to<Pair>());
case Tag::Nil:
case Tag::Bool:
case Tag::Int64:
case Tag::Float:
case Tag::String:
case Tag::Symbol:
case Tag::Syntax:
case Tag::Array:
case Tag::ByteArray:
case Tag::Dict:
return ErrorCode::TypeMismatch;
}
return ErrorCode::TypeMismatch;
}
2024-08-04 19:38:56 +00:00
Result<Expression> Compiler::compile_list(Context& context, Pair& expr) {
2024-08-09 22:45:06 +00:00
auto first = TRY(expr.first());
2024-08-04 19:38:56 +00:00
if (first.is<Symbol>()) {
Symbol& sym = *first.to<Symbol>();
}
return ErrorCode::TypeMismatch;
}