mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 03:12:22 -07:00
Win32 Demo: OpenGL Context
This commit is contained in:
@@ -633,14 +633,6 @@ void check_parsed_files(Checker *c) {
|
||||
add_file_entity(c, td->name, e, d);
|
||||
case_end;
|
||||
|
||||
case_ast_node(ad, AliasDecl, decl);
|
||||
ast_node(n, Ident, ad->name);
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->global_scope, n->token, NULL);
|
||||
DeclInfo *d = make_declaration_info(c->allocator, e->parent);
|
||||
d->type_expr = ad->type;
|
||||
add_file_entity(c, ad->name, e, d);
|
||||
case_end;
|
||||
|
||||
case_ast_node(pd, ProcDecl, decl);
|
||||
ast_node(n, Ident, pd->name);
|
||||
Token token = n->token;
|
||||
|
||||
@@ -600,10 +600,10 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
|
||||
if (!is_type_integer(o->type) && is_type_integer(type)) {
|
||||
error(&c->error_collector, ast_node_token(o->expr), "`%s` truncated to `%s`", a, b);
|
||||
} else {
|
||||
error(&c->error_collector, ast_node_token(o->expr), "`%s` overflows `%s`", a, b);
|
||||
error(&c->error_collector, ast_node_token(o->expr), "`%s = %lld` overflows `%s`", a, o->value.value_integer, b);
|
||||
}
|
||||
} else {
|
||||
error(&c->error_collector, ast_node_token(o->expr), "Cannot convert `%s` to `%s`", a, b);
|
||||
error(&c->error_collector, ast_node_token(o->expr), "Cannot convert `%s` to `%s`", a, b);
|
||||
}
|
||||
|
||||
o->mode = Addressing_Invalid;
|
||||
@@ -867,6 +867,11 @@ b32 check_castable_to(Checker *c, Operand *operand, Type *y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// proc <-> proc
|
||||
if (is_type_proc(xb), is_type_proc(yb)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -878,12 +878,5 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
add_entity(c, c->context.scope, td->name, e);
|
||||
check_type_decl(c, e, td->type, NULL);
|
||||
case_end;
|
||||
|
||||
case_ast_node(ad, AliasDecl, node);
|
||||
ast_node(name, Ident, ad->name);
|
||||
Entity *e = make_entity_alias_name(c->allocator, c->context.scope, name->token, NULL);
|
||||
add_entity(c, c->context.scope, ad->name, e);
|
||||
check_alias_decl(c, e, ad->type, NULL);
|
||||
case_end;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +382,9 @@ b32 is_type_u8_slice(Type *t) {
|
||||
b32 is_type_vector(Type *t) {
|
||||
return t->kind == Type_Vector;
|
||||
}
|
||||
b32 is_type_proc(Type *t) {
|
||||
return t->kind == Type_Proc;
|
||||
}
|
||||
Type *base_vector_type(Type *t) {
|
||||
if (is_type_vector(t)) {
|
||||
return t->vector.elem;
|
||||
@@ -747,10 +750,12 @@ gbString write_type_to_string(gbString str, Type *type) {
|
||||
if (type->tuple.variable_count > 0) {
|
||||
for (isize i = 0; i < type->tuple.variable_count; i++) {
|
||||
Entity *var = type->tuple.variables[i];
|
||||
GB_ASSERT(var->kind == Entity_Variable);
|
||||
if (i > 0)
|
||||
str = gb_string_appendc(str, ", ");
|
||||
str = write_type_to_string(str, var->type);
|
||||
if (var != NULL) {
|
||||
GB_ASSERT(var->kind == Entity_Variable);
|
||||
if (i > 0)
|
||||
str = gb_string_appendc(str, ", ");
|
||||
str = write_type_to_string(str, var->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -210,7 +210,15 @@ void ssa_print_exact_value(gbFile *f, ssaModule *m, ExactValue value, Type *type
|
||||
ssa_fprintf(f, "\"");
|
||||
} break;
|
||||
case ExactValue_Integer: {
|
||||
ssa_fprintf(f, "%lld", value.value_integer);
|
||||
if (is_type_pointer(get_base_type(type))) {
|
||||
if (value.value_integer == 0) {
|
||||
ssa_fprintf(f, "null");
|
||||
} else {
|
||||
GB_PANIC("TODO(bill): Pointer constant");
|
||||
}
|
||||
} else {
|
||||
ssa_fprintf(f, "%lld", value.value_integer);
|
||||
}
|
||||
} break;
|
||||
case ExactValue_Float: {
|
||||
u64 u = *cast(u64*)&value.value_float;
|
||||
|
||||
+6
-1
@@ -1355,6 +1355,11 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t) {
|
||||
return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_bitcast, value, src, dst));
|
||||
}
|
||||
|
||||
// proc <-> proc
|
||||
if (is_type_proc(src) && is_type_proc(dst)) {
|
||||
return ssa_emit(proc, ssa_make_instr_conv(proc, ssaConv_bitcast, value, src, dst));
|
||||
}
|
||||
|
||||
|
||||
// []byte/[]u8 <-> string
|
||||
if (is_type_u8_slice(src) && is_type_string(dst)) {
|
||||
@@ -1743,7 +1748,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
|
||||
// NOTE(bill): Regular call
|
||||
ssaValue *value = ssa_build_expr(proc, ce->proc);
|
||||
Type *proc_type_ = ssa_value_type(value);
|
||||
Type *proc_type_ = get_base_type(ssa_value_type(value));
|
||||
GB_ASSERT(proc_type_->kind == Type_Proc);
|
||||
auto *type = &proc_type_->proc;
|
||||
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ int main(int argc, char **argv) {
|
||||
output_name, cast(int)base_name_len, output_name);
|
||||
win32_exec_command_line_app(
|
||||
"clang %.*s.bc -o %.*s.exe -Wno-override-module "
|
||||
"-lkernel32.lib -luser32.lib",
|
||||
"-lkernel32.lib -luser32.lib -lgdi32.lib -lopengl32.lib",
|
||||
cast(int)base_name_len, output_name,
|
||||
cast(int)base_name_len, output_name);
|
||||
|
||||
|
||||
+1
-37
@@ -177,7 +177,6 @@ AST_NODE_KIND(_DeclBegin, struct{}) \
|
||||
String foreign_name; \
|
||||
}) \
|
||||
AST_NODE_KIND(TypeDecl, struct { Token token; AstNode *name, *type; }) \
|
||||
AST_NODE_KIND(AliasDecl, struct { Token token; AstNode *name, *type; }) \
|
||||
AST_NODE_KIND(LoadDecl, struct { Token token, filepath; }) \
|
||||
AST_NODE_KIND(_DeclEnd, struct{}) \
|
||||
AST_NODE_KIND(_TypeBegin, struct{}) \
|
||||
@@ -336,8 +335,6 @@ Token ast_node_token(AstNode *node) {
|
||||
return node->ProcDecl.name->Ident.token;
|
||||
case AstNode_TypeDecl:
|
||||
return node->TypeDecl.token;
|
||||
case AstNode_AliasDecl:
|
||||
return node->AliasDecl.token;
|
||||
case AstNode_LoadDecl:
|
||||
return node->LoadDecl.token;
|
||||
case AstNode_Field: {
|
||||
@@ -759,15 +756,6 @@ gb_inline AstNode *make_type_decl(AstFile *f, Token token, AstNode *name, AstNod
|
||||
return result;
|
||||
}
|
||||
|
||||
gb_inline AstNode *make_alias_decl(AstFile *f, Token token, AstNode *name, AstNode *type) {
|
||||
AstNode *result = make_node(f, AstNode_AliasDecl);
|
||||
result->AliasDecl.token = token;
|
||||
result->AliasDecl.name = name;
|
||||
result->AliasDecl.type = type;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
gb_inline AstNode *make_load_decl(AstFile *f, Token token, Token filepath) {
|
||||
AstNode *result = make_node(f, AstNode_LoadDecl);
|
||||
result->LoadDecl.token = token;
|
||||
@@ -1948,31 +1936,7 @@ AstNode *parse_stmt(AstFile *f) {
|
||||
AstNode *name = parse_identifier(f);
|
||||
expect_token(f, Token_Colon);
|
||||
AstNode *type = parse_type(f);
|
||||
|
||||
AstNode *type_decl = make_type_decl(f, token, name, type);
|
||||
|
||||
if (type->kind != AstNode_StructType &&
|
||||
type->kind != AstNode_ProcType) {
|
||||
expect_token(f, Token_Semicolon);
|
||||
}
|
||||
|
||||
return type_decl;
|
||||
} break;
|
||||
|
||||
case Token_alias: {
|
||||
Token token = expect_token(f, Token_alias);
|
||||
AstNode *name = parse_identifier(f);
|
||||
expect_token(f, Token_Colon);
|
||||
AstNode *type = parse_type(f);
|
||||
|
||||
AstNode *alias_decl = make_alias_decl(f, token, name, type);
|
||||
|
||||
if (type->kind != AstNode_StructType &&
|
||||
type->kind != AstNode_ProcType) {
|
||||
expect_token(f, Token_Semicolon);
|
||||
}
|
||||
|
||||
return alias_decl;
|
||||
return make_type_decl(f, token, name, type);
|
||||
} break;
|
||||
|
||||
// Operands
|
||||
|
||||
@@ -152,14 +152,6 @@ void print_ast(AstNode *node, isize indent) {
|
||||
print_ast(node->TypeDecl.type, indent+1);
|
||||
break;
|
||||
|
||||
case AstNode_AliasDecl:
|
||||
print_indent(indent);
|
||||
gb_printf("(alias)\n");
|
||||
print_ast(node->AliasDecl.name, indent+1);
|
||||
print_ast(node->AliasDecl.type, indent+1);
|
||||
break;
|
||||
|
||||
|
||||
case AstNode_ProcType:
|
||||
print_indent(indent);
|
||||
gb_printf("(type:proc)(%td -> %td)\n", node->ProcType.param_count, node->ProcType.result_count);
|
||||
|
||||
@@ -78,7 +78,6 @@ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
|
||||
\
|
||||
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||
TOKEN_KIND(Token_type, "type"), \
|
||||
TOKEN_KIND(Token_alias, "alias"), \
|
||||
TOKEN_KIND(Token_proc, "proc"), \
|
||||
TOKEN_KIND(Token_match, "match"), \
|
||||
TOKEN_KIND(Token_break, "break"), \
|
||||
|
||||
Reference in New Issue
Block a user