feat: error handling, better prelude, double linked lists usage etc

This commit is contained in:
2026-01-02 22:06:56 +01:00
parent a453603b9b
commit 6176d549c1
10 changed files with 148 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include <unordered_map>
#include "parser/nodes.hpp"
#include "prelude/error.hpp"
#include "prelude/string.hpp"
#include "ir/value.hpp"
#include "ir/ops.hpp"
@@ -11,8 +12,8 @@ namespace IR
class IRBuilder
{
public:
IRBuilder(const Node *root)
: m_root(root), m_ops(new OpBuilder()) {}
IRBuilder(const StringView &filename, const Node *root)
: m_root(root), m_ops(new OpBuilder()), m_filename(filename) {}
public:
// TODO: support other literals
@@ -36,8 +37,9 @@ namespace IR
{
if (m_locals.find(var->name()) == m_locals.end())
{
// TODO: throw proper error
assert(0 && "ERROR: variable does not exist");
// TODO: pass line:offset when Node will have them
ErrorLogger::Raise(Error::CompileError(m_filename, StringView::FromFormat("use of undefined variable '%s'", var->name().c_str())));
assert(false);
}
auto dst = AllocateNamed<Instruction>(m_locals[var->name()]->GetValueType());
m_ops->Push(new LoadOp(dst, m_locals[var->name()]));
@@ -189,6 +191,7 @@ namespace IR
private:
const Node *m_root = nullptr;
StringView m_filename;
OpBuilder *m_ops = nullptr;
unsigned int m_value_counter = 0;