NODE(CompoundType) \
\
NODE(Binding) \
+ NODE(Alias) \
NODE(MemRes) \
NODE(Include) \
NODE(UsePackage) \
Ast_Kind_Memres,
Ast_Kind_Binding,
+ Ast_Kind_Alias,
Ast_Kind_Function,
Ast_Kind_Overloaded_Function,
Ast_Kind_Polymorphic_Proc,
// Top level nodes
struct AstBinding { AstTyped_base; AstNode* node; };
+struct AstAlias { AstTyped_base; AstTyped* alias; };
struct AstMemRes { AstTyped_base; u64 addr; AstTyped *initial_value; };
struct AstInclude { AstNode_base; char* name; };
-struct AstAlias {
- AstNode_base;
- OnyxToken *alias;
-};
struct AstGlobal {
AstTyped_base;
gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
- use package builtin.type_info { offset_of };
+ offset_of :: (package builtin.type_info).offset_of;
+ IV :: Immediate_Vertex;
// Position
gl.enableVertexAttribArray(0);
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "position"));
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, sizeof IV, offset_of(IV, "position"));
// Color
gl.enableVertexAttribArray(1);
- gl.vertexAttribPointer(1, 4, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "color"));
+ gl.vertexAttribPointer(1, 4, gl.FLOAT, false, sizeof IV, offset_of(IV, "color"));
// Texture
gl.enableVertexAttribArray(2);
- gl.vertexAttribPointer(2, 2, gl.FLOAT, false, sizeof Immediate_Vertex, offset_of(Immediate_Vertex, "texture"));
+ gl.vertexAttribPointer(2, 2, gl.FLOAT, false, sizeof IV, offset_of(IV, "texture"));
gl.bindBuffer(gl.ARRAY_BUFFER, -1);
"MEMORY RESERVATION",
"BINDING",
+ "ALIAS",
"FUNCTION",
"OVERLOADED_FUNCTION",
"POLYMORPHIC PROC",
#define REDUCE_UNOP(op) \
if (type_is_small_integer(unop->type) || type_is_bool(unop->type)) { \
- res->value.i = op ((AstNumLit *) unop->expr)->value.i; \
+ res->value.i = op (operand)->value.i; \
} else if (type_is_integer(unop->type) || unop->type->Basic.kind == Basic_Kind_Int_Unsized) { \
- res->value.l = op ((AstNumLit *) unop->expr)->value.l; \
+ res->value.l = op (operand)->value.l; \
} else if (unop->type->Basic.kind == Basic_Kind_F32) { \
- res->value.f = op ((AstNumLit *) unop->expr)->value.f; \
+ res->value.f = op (operand)->value.f; \
} else if (unop->type->Basic.kind == Basic_Kind_F64 || unop->type->Basic.kind == Basic_Kind_Float_Unsized) { \
- res->value.d = op ((AstNumLit *) unop->expr)->value.d; \
+ res->value.d = op (operand)->value.d; \
} \
break;
#define REDUCE_UNOP_INT(op) \
if (type_is_small_integer(unop->type) || type_is_bool(unop->type)) { \
- res->value.i = op ((AstNumLit *) unop->expr)->value.i; \
+ res->value.i = op (operand)->value.i; \
} else if (type_is_integer(unop->type) || res->type->Basic.kind == Basic_Kind_Int_Unsized) { \
- res->value.l = op ((AstNumLit *) unop->expr)->value.l; \
+ res->value.l = op (operand)->value.l; \
}
AstTyped* ast_reduce_unaryop(bh_allocator a, AstUnaryOp* unop) {
- unop->expr = ast_reduce(a, unop->expr);
+ // GROSS
+ AstNumLit* operand = (AstNumLit *) ast_reduce(a, unop->expr);
+ unop->expr = (AstTyped *) operand;
- if (unop->expr->kind != Ast_Kind_NumLit) {
+ // while (operand->kind == Ast_Kind_Alias) operand = (AstNumLit *) ((AstAlias *) operand)->alias;
+
+ if (operand->kind != Ast_Kind_NumLit) {
return (AstTyped *) unop;
}
switch (unop->operation) {
case Unary_Op_Negate: REDUCE_UNOP(-);
case Unary_Op_Not: {
- if (type_is_bool(res->type)) res->value.i = ! ((AstNumLit *) unop->expr)->value.i;
+ if (type_is_bool(res->type)) res->value.i = ! (operand)->value.i;
break;
}
case Unary_Op_Bitwise_Not: REDUCE_UNOP_INT(~);
case Ast_Kind_Binary_Op: return (AstTyped *) ast_reduce_binop(a, (AstBinaryOp *) node);
case Ast_Kind_Unary_Op: return (AstTyped *) ast_reduce_unaryop(a, (AstUnaryOp *) node);
case Ast_Kind_Enum_Value: return (AstTyped *) ((AstEnumValue *) node)->value;
+ case Ast_Kind_Alias: return (AstTyped *) ast_reduce(a, ((AstAlias *) node)->alias);
default: return node;
}
}
return 0;
}
}
+ else if (node->kind == Ast_Kind_Alias) {
+ AstAlias* alias = (AstAlias *) node;
+ return type_check_or_auto_cast(&alias->alias, type);
+ }
return 0;
}
if_expr->type = ltype;
}
+ if (node->kind == Ast_Kind_Alias) {
+ AstAlias* alias = (AstAlias *) node;
+ alias->type = resolve_expression_type(alias->alias);
+ }
+
if (node_is_type((AstNode *) node)) {
return &basic_types[Basic_Kind_Type_Index];
}
return ((AstNumLit *) node)->value.l;
}
+ if (node->kind == Ast_Kind_NumLit && type_is_bool(node->type)) {
+ return ((AstNumLit *) node)->value.i;
+ }
+
if (node->kind == Ast_Kind_Argument) {
return get_expression_integer_value(((AstArgument *) node)->value);
}
return ((AstAlignOf *) node)->alignment;
}
+ if (node->kind == Ast_Kind_Alias) {
+ return get_expression_integer_value(((AstAlias *) node)->alias);
+ }
+
if (node_is_type((AstNode*) node)) {
Type* type = type_build_from_ast(context.ast_alloc, (AstType *) node);
return type->id;
b32 static_if_resolution(AstIf* static_if) {
if (static_if->kind != Ast_Kind_Static_If) return 0;
- AstNumLit* condition_value = (AstNumLit *) static_if->cond;
- assert(condition_value->kind == Ast_Kind_NumLit); // This should be right, right?
+ // assert(condition_value->kind == Ast_Kind_NumLit); // This should be right, right?
+ i64 value = get_expression_integer_value(static_if->cond);
- return condition_value->value.i != 0;
+ return value != 0;
}
CHECK(if_expression, (AstIfExpression *) expr);
break;
+ case Ast_Kind_Alias:
+ CHECK(expression, &((AstAlias *) expr)->alias);
+ expr->flags |= (((AstAlias *) expr)->alias->flags & Ast_Flag_Comptime);
+ expr->type = ((AstAlias *) expr)->alias->type;
+ break;
+
case Ast_Kind_StrLit: break;
case Ast_Kind_File_Contents: break;
case Ast_Kind_Overloaded_Function: break;
case Ast_Kind_Enum_Value:
case Ast_Kind_Overloaded_Function:
case Ast_Kind_Polymorphic_Proc:
+ case Ast_Kind_Alias:
return 0;
default: return 1;
node->token = symbol;
}
+ if (node_is_type((AstNode *) node));
+ else if (node->kind == Ast_Kind_Package);
+ else if (node->kind == Ast_Kind_NumLit);
+ else {
+ AstAlias* alias = make_node(AstAlias, Ast_Kind_Alias);
+ alias->token = node->token;
+ alias->alias = node;
+ node = (AstTyped *) alias;
+ }
+
// HACK: This should maybe be entered elsewhere?
ENTITY_SUBMIT(node);
}
-
+
AstBinding* binding = make_node(AstBinding, Ast_Kind_Binding);
binding->token = symbol;
binding->node = (AstNode *) node;
AstCompoundType* ctype = (AstCompoundType *) *type;
bh_arr_each(AstType *, type, ctype->types) SYMRES(type, type);
+ break;
+ }
+
+ case Ast_Kind_Alias: {
+ AstAlias* alias = (AstAlias *) *type;
+ SYMRES(type, (AstType **) &alias->alias);
+ break;
}
}
case Ast_Kind_Method_Call: SYMRES(method_call, (AstBinaryOp **) expr); break;
case Ast_Kind_Size_Of: SYMRES(size_of, (AstSizeOf *)*expr); break;
case Ast_Kind_Align_Of: SYMRES(align_of, (AstAlignOf *)*expr); break;
+ case Ast_Kind_Alias: SYMRES(expression, &((AstAlias *) *expr)->alias); break;
case Ast_Kind_Range_Literal:
SYMRES(expression, &((AstRangeLiteral *)(*expr))->low);
type_register(comp_type);
return comp_type;
}
+
+ case Ast_Kind_Alias: {
+ AstAlias* alias = (AstAlias *) type_node;
+ return type_build_from_ast(alloc, (AstType *) alias->alias);
+ }
}
return NULL;
switch (node->kind) {
case Ast_Kind_Type_Raw_Alias: node = (AstNode *) ((AstTypeRawAlias *) node)->to->ast_type; break;
case Ast_Kind_Type_Alias: node = (AstNode *) ((AstTypeAlias *) node)->to; break;
+ case Ast_Kind_Alias: node = (AstNode *) ((AstAlias *) node)->alias; break;
case Ast_Kind_Pointer_Type: {
if (used_pointer) goto all_types_peeled_off;
used_pointer = 1;
case Ast_Kind_Intrinsic_Call: emit_intrinsic_call(mod, &code, (AstCall *) expr); break;
case Ast_Kind_Binary_Op: emit_binop(mod, &code, (AstBinaryOp *) expr); break;
case Ast_Kind_Unary_Op: emit_unaryop(mod, &code, (AstUnaryOp *) expr); break;
+ case Ast_Kind_Alias: emit_expression(mod, &code, ((AstAlias *) expr)->alias); break;
case Ast_Kind_Address_Of: {
AstAddressOf* aof = (AstAddressOf *) expr;