Skip to content

Commit

Permalink
Compiler: fix var initialization with expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrunix00 committed Aug 9, 2024
1 parent 3e31596 commit 0aac2e1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fstream>
#include <sstream>
#include <utility>
#include <memory>

Node::Node(Token token) : token(std::move(token)) {
nodeType = Type::Node;
Expand Down Expand Up @@ -207,7 +208,10 @@ void Declaration::compile(Program &program, Segment &segment) const {
.params = {.i64 = convert<int64_t>(((Node *) value.value())->token.value)},
});
} else {
((Node *) value.value())->compile(program, segment);
auto from = std::unique_ptr<VariableType>(deduceType(program, segment, value.value()));
auto to = std::unique_ptr<VariableType>(varTypeConvert(type.value()));
value.value()->compile(program, segment);
typeCast(segment.instructions, from->type, to->type);
}
segment.declare_variable(identifier.token.value, new VariableType(VariableType::Type::I64));
segment.instructions.push_back({
Expand Down

0 comments on commit 0aac2e1

Please sign in to comment.