Skip to content

Commit

Permalink
fix(type_checker,compiler): add support for function assignment + add…
Browse files Browse the repository at this point in the history
…itional checks
  • Loading branch information
JaDogg committed Jul 1, 2023
1 parent 98c94d0 commit 1a5fd71
Show file tree
Hide file tree
Showing 5 changed files with 510 additions and 407 deletions.
11 changes: 9 additions & 2 deletions compiler/src/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,15 @@ void compiler::visit_let_stmt(let_stmt *obj) {
if (obj->data_type_ == nullptr) {
visited_expr = true;
resulting_pair = compile_expression(obj->expression_);
obj->data_type_ =
resulting_pair.second.datatype_; /* set our data type here */
if (resulting_pair.second.is_a_function()) {
obj->data_type_ = function_to_datatype(resulting_pair.second);
} else {
obj->data_type_ =
resulting_pair.second.datatype_; /* set our data type here */
}
}
if (obj->data_type_->is_none()) {
error(obj->name_, "Failed to compile let statement. (Use of non compilable data type)");
}
if (obj->data_type_->is_str()) {
object = ykobject(std::string("str"), dt_pool_);
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/compiler/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ void type_checker::visit_assign_expr(assign_expr *obj) {
if (scope_.is_defined(name)) {
object = scope_.get(name);
} else {
if (rhs.is_a_function()) {
rhs.datatype_ = function_to_datatype(rhs);
}
object = ykobject(rhs.datatype_);
obj->promoted_ = true;
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/test_data/compiler_tests/on_stack_test.yaka
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ struct Friend:
class AnotherFriend:
x: int

def a() -> int:
return 0

def main() -> int:
b = a
d = a
e = "Hello world"
enemies = arrnew("Enemy", 2)
enemies[0].x = 1
enemies[1].x = 2
Expand Down
Loading

0 comments on commit 1a5fd71

Please sign in to comment.