Add DECL_TYPE
This commit is contained in:
2
ast.cpp
2
ast.cpp
@@ -485,7 +485,7 @@ ast_const(Token *pos, Intern_String name, Ast_Expr *expr){
|
|||||||
|
|
||||||
function Ast_Decl *
|
function Ast_Decl *
|
||||||
ast_type(Token *pos, Intern_String name, Ast_Resolved_Type *type){
|
ast_type(Token *pos, Intern_String name, Ast_Resolved_Type *type){
|
||||||
AST_NEW(Decl, CONST, pos, AST_DECL);
|
AST_NEW(Decl, TYPE, pos, AST_DECL);
|
||||||
result->type = type_type;
|
result->type = type_type;
|
||||||
result->type_val = type;
|
result->type_val = type;
|
||||||
result->name = name;
|
result->name = name;
|
||||||
|
|||||||
57
ccodegen.cpp
57
ccodegen.cpp
@@ -72,8 +72,9 @@ gen_simple_decl(Ast_Resolved_Type *ast, Intern_String name){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function B32
|
||||||
gen_value(Value a){
|
gen_value(Value a){
|
||||||
|
B32 result = true;
|
||||||
switch(a.type->kind){
|
switch(a.type->kind){
|
||||||
CASE_INT: {
|
CASE_INT: {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
@@ -83,8 +84,9 @@ gen_value(Value a){
|
|||||||
CASE_STRING: gen("LIT(\"%s\")", a.intern_val.str); break;
|
CASE_STRING: gen("LIT(\"%s\")", a.intern_val.str); break;
|
||||||
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
CASE_BOOL: a.bool_val ? gen("true"):gen("false"); break;
|
||||||
CASE_FLOAT: gen("%f", a.f64_val); break;
|
CASE_FLOAT: gen("%f", a.f64_val); break;
|
||||||
invalid_default_case;
|
default: result = false;
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
@@ -96,37 +98,20 @@ gen_expr(Ast_Expr *ast){
|
|||||||
}
|
}
|
||||||
|
|
||||||
CASE(VALUE, Atom){
|
CASE(VALUE, Atom){
|
||||||
gen_value(node->value);
|
B32 written = gen_value(node->value);
|
||||||
|
if(!written) gen("%s", node->value.intern_val.str);
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE(INDEX, Index){
|
CASE(INDEX, Index){
|
||||||
// Sym *sym = resolved_get(node);
|
gen("(");
|
||||||
// if(is_array(sym->type)){
|
gen_expr(node->expr);
|
||||||
// gen("(");
|
gen("[");
|
||||||
// gen("(");
|
gen_expr(node->index);
|
||||||
|
gen("]");
|
||||||
// gen("(");
|
gen(")");
|
||||||
// gen_simple_decl(sym->type->arr.base, {});
|
BREAK();
|
||||||
// gen("*)");
|
}
|
||||||
// gen_expr(node->expr);
|
|
||||||
// gen(".data)");
|
|
||||||
|
|
||||||
|
|
||||||
// gen("[");
|
|
||||||
// gen_expr(node->index);
|
|
||||||
// gen("]");
|
|
||||||
// gen(")");
|
|
||||||
// } else{
|
|
||||||
// gen("(");
|
|
||||||
// gen_expr(node->expr);
|
|
||||||
// gen("[");
|
|
||||||
// gen_expr(node->index);
|
|
||||||
// gen("]");
|
|
||||||
// gen(")");
|
|
||||||
// }
|
|
||||||
// BREAK();
|
|
||||||
// }
|
|
||||||
|
|
||||||
CASE(BINARY, Binary){
|
CASE(BINARY, Binary){
|
||||||
// if(node->op == TK_Dot){
|
// if(node->op == TK_Dot){
|
||||||
@@ -348,6 +333,12 @@ gen_ast(Ast *ast){
|
|||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CASE(TYPE, Decl){
|
||||||
|
gen("// Type %s = ", node->name.str);
|
||||||
|
gen_expr(node->expr);
|
||||||
|
BREAK();
|
||||||
|
}
|
||||||
|
|
||||||
CASE(CONST, Decl){
|
CASE(CONST, Decl){
|
||||||
switch(node->type->kind){
|
switch(node->type->kind){
|
||||||
CASE_FLOAT:{
|
CASE_FLOAT:{
|
||||||
@@ -367,12 +358,6 @@ gen_ast(Ast *ast){
|
|||||||
gen_value(node->value);
|
gen_value(node->value);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case TYPE_LAMBDA:{
|
|
||||||
|
|
||||||
}break;
|
|
||||||
|
|
||||||
case TYPE_TYPE:{
|
|
||||||
}break;
|
|
||||||
// if(sym->type_val->kind == TYPE_STRUCT){
|
// if(sym->type_val->kind == TYPE_STRUCT){
|
||||||
// Ast_Struct *agg = (Ast_Struct *)sym->type_val->ast;
|
// Ast_Struct *agg = (Ast_Struct *)sym->type_val->ast;
|
||||||
// if(node->value->kind == AST_STRUCT){
|
// if(node->value->kind == AST_STRUCT){
|
||||||
|
|||||||
@@ -966,6 +966,7 @@ resolve_decl(Ast_Decl *ast, B32 flags){
|
|||||||
Ast_Resolved_Type *lambda_type = 0;
|
Ast_Resolved_Type *lambda_type = 0;
|
||||||
Ast_Resolved_Type *ret_type = resolve_typespec(lambda->ret, AST_CANT_BE_NULL);
|
Ast_Resolved_Type *ret_type = resolve_typespec(lambda->ret, AST_CANT_BE_NULL);
|
||||||
Array<Ast_Resolved_Type *> args = {scratch};
|
Array<Ast_Resolved_Type *> args = {scratch};
|
||||||
|
|
||||||
For(lambda->args){
|
For(lambda->args){
|
||||||
Ast_Resolved_Type *type = resolve_typespec(it->typespec, AST_CANT_BE_NULL);
|
Ast_Resolved_Type *type = resolve_typespec(it->typespec, AST_CANT_BE_NULL);
|
||||||
Operand default_value = resolve_expr(it->expr, AST_CAN_BE_NULL);
|
Operand default_value = resolve_expr(it->expr, AST_CAN_BE_NULL);
|
||||||
@@ -1008,7 +1009,11 @@ resolve_decl(Ast_Decl *ast, B32 flags){
|
|||||||
if(!op.is_const){
|
if(!op.is_const){
|
||||||
compiler_error(node->pos, "Assigning a value that is not constant to a constant declaration");
|
compiler_error(node->pos, "Assigning a value that is not constant to a constant declaration");
|
||||||
}
|
}
|
||||||
|
|
||||||
node->value = op.value;
|
node->value = op.value;
|
||||||
|
if(op.value.type == type_type){
|
||||||
|
node->kind = AST_TYPE;
|
||||||
|
}
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
CASE(VAR, Decl){
|
CASE(VAR, Decl){
|
||||||
|
|||||||
Reference in New Issue
Block a user