Skip to content

Commit 438a1b6

Browse files
committed
WIP: linkage 3
1 parent dc39b25 commit 438a1b6

File tree

6 files changed

+9
-7
lines changed

6 files changed

+9
-7
lines changed

include/mcc/ast.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef struct Expr {
102102
struct ConstExpr const_expr;
103103
struct UnaryOpExpr unary_op;
104104
struct BinaryOpExpr binary_op;
105-
const IdentifierInfo* variable;
105+
IdentifierInfo* variable;
106106
struct TernaryExpr ternary;
107107
struct CallExpr call;
108108
};

src/frontend/parser.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static Expr* parse_identifier_expr(Parser* parser, Scope* scope)
180180
Expr* result = ARENA_ALLOC_OBJECT(parser->permanent_arena, Expr);
181181

182182
// If local variable does not exist
183-
const IdentifierInfo* variable_identifier = lookup_identifier(scope, name);
183+
IdentifierInfo* variable_identifier = lookup_identifier(scope, name);
184184
if (!variable_identifier) {
185185
const StringView error_msg = allocate_printf(
186186
parser->permanent_arena, "use of undeclared identifier '%.*s'",

src/frontend/symbol_table.c

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ FunctionIdentifierInfo* add_function_identifer(SymbolTable* symbol_table,
7878
{
7979
MCC_ASSERT(linkage != LINKAGE_NONE);
8080

81+
// check identifier in current scope
82+
if (hashmap_lookup(&scope->identifiers, name) != nullptr) { return nullptr; }
83+
8184
// TODO: proper types
8285
FunctionIdentifierInfo* info =
8386
ARENA_ALLOC_OBJECT(arena, FunctionIdentifierInfo);

src/frontend/symbol_table.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ Scope* new_scope(Scope* parent, Arena* arena);
8787

8888
IdentifierInfo* lookup_identifier(const Scope* scope, StringView name);
8989

90-
// Add information of the function identifier to the current scope
90+
// Return nullptr if an identifier of the same name already exist in the same
91+
// scope. Otherwise we add it to the current scope
9192
FunctionIdentifierInfo* add_function_identifer(SymbolTable* symbol_table,
9293
Scope* scope, StringView name,
9394
Linkage linkage, Arena* arena);

src/ir/ir_generator.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,7 @@ static IRValue emit_ir_instructions_from_expr(const Expr* expr,
359359
}
360360
}
361361
case EXPR_VARIABLE: {
362-
// TODO: fix this
363-
// return ir_variable(expr->variable->rewrote_name);
364-
return ir_variable(str("TODO"));
362+
return ir_variable(as_object_ident(expr->variable)->rewrote_name);
365363
}
366364
case EXPR_TERNARY: {
367365
const StringView true_label =

tests/test_driver/src/test_runner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async fn run_test(database: &TestDatabase, config: &TestConfig) -> Result<(), Te
9595
.args(["-c", &command])
9696
.output();
9797

98-
let timeout_duration = Duration::from_secs(1);
98+
let timeout_duration = Duration::from_secs(10);
9999
let output = timeout(timeout_duration, output).await;
100100
if output.is_err() {
101101
return Err(TestError {

0 commit comments

Comments
 (0)