From 1354f53d02840959b3f70bc8386a188920108d98 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 31 Mar 2019 11:58:54 +0100 Subject: [PATCH] Remove `derived` from `context`; Fix parsing issue for `typeid` specializations in record parameters; Fix runtime printing of types --- core/odin/parser/parser.odin | 4 ++- core/runtime/core.odin | 1 + core/runtime/internal.odin | 56 +++++++++++++++++++----------------- src/parser.cpp | 5 ++-- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index ccae59a7c..2f933a341 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1528,6 +1528,8 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel return ok; } + is_signature := (allowed_flags & Field_Flags_Signature_Params) == Field_Flags_Signature_Params; + any_polymorphic_names := check_procedure_name_list(p, names); set_flags = check_field_flag_prefixes(p, len(names), allowed_flags, set_flags); @@ -1538,7 +1540,7 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel if p.curr_tok.kind != token.Eq { type = parse_var_type(p, allowed_flags); tt := ast.unparen_expr(type); - if !any_polymorphic_names { + if is_signature && !any_polymorphic_names { if ti, ok := tt.derived.(ast.Typeid_Type); ok && ti.specialization != nil { error(p, tt.pos, "specialization of typeid is not allowed without polymorphic names"); } diff --git a/core/runtime/core.odin b/core/runtime/core.odin index a01ad4cf8..8b6fc7319 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -220,6 +220,7 @@ Context :: struct { thread_id: int, user_data: any, + user_ptr: rawptr, user_index: int, derived: any, // May be used for derived data types diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 60110be15..d3ef1f94d 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -223,6 +223,21 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) { print_type(fd, info.underlying); } os.write_byte(fd, ']'); + + case Type_Info_Opaque: + os.write_string(fd, "opaque "); + print_type(fd, info.elem); + + case Type_Info_Simd_Vector: + if info.is_x86_mmx { + os.write_string(fd, "intrinsics.x86_mmx"); + } else { + os.write_string(fd, "intrinsics.vector("); + print_u64(fd, u64(info.count)); + os.write_string(fd, ", "); + print_type(fd, info.elem); + os.write_byte(fd, ')'); + } } } @@ -285,38 +300,27 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index handle_error(file, line, column, index, count); } +slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { + fd := os.stderr; + print_caller_location(fd, Source_Code_Location{file, line, column, "", 0}); + os.write_string(fd, " Invalid slice indices: "); + print_i64(fd, i64(lo)); + os.write_string(fd, ":"); + print_i64(fd, i64(hi)); + os.write_string(fd, ":"); + print_i64(fd, i64(len)); + os.write_byte(fd, '\n'); + debug_trap(); +} + slice_expr_error_hi :: proc "contextless" (file: string, line, column: int, hi: int, len: int) { if 0 <= hi && hi <= len do return; - handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { - fd := os.stderr; - print_caller_location(fd, Source_Code_Location{file, line, column, "", 0}); - os.write_string(fd, " Invalid slice indices: "); - print_i64(fd, i64(lo)); - os.write_string(fd, ":"); - print_i64(fd, i64(hi)); - os.write_string(fd, ":"); - print_i64(fd, i64(len)); - os.write_byte(fd, '\n'); - debug_trap(); - } - handle_error(file, line, column, 0, hi, len); + slice_handle_error(file, line, column, 0, hi, len); } slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { if 0 <= lo && lo <= len && lo <= hi && hi <= len do return; - handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { - fd := os.stderr; - print_caller_location(fd, Source_Code_Location{file, line, column, "", 0}); - os.write_string(fd, " Invalid slice indices: "); - print_i64(fd, i64(lo)); - os.write_string(fd, ":"); - print_i64(fd, i64(hi)); - os.write_string(fd, ":"); - print_i64(fd, i64(len)); - os.write_byte(fd, '\n'); - debug_trap(); - } - handle_error(file, line, column, lo, hi, len); + slice_handle_error(file, line, column, lo, hi, len); } dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) { diff --git a/src/parser.cpp b/src/parser.cpp index 2eee82e22..12b7edb01 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3024,6 +3024,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi isize total_name_count = 0; bool allow_ellipsis = allowed_flags&FieldFlag_ellipsis; bool seen_ellipsis = false; + bool is_signature = (allowed_flags & FieldFlag_Signature) == FieldFlag_Signature; while (f->curr_token.kind != follow && f->curr_token.kind != Token_Colon && @@ -3064,7 +3065,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi if (f->curr_token.kind != Token_Eq) { type = parse_var_type(f, allow_ellipsis, allow_typeid_token); Ast *tt = unparen_expr(type); - if (!any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) { + if (is_signature && !any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) { syntax_error(type, "Specialization of typeid is not allowed without polymorphic names"); } } @@ -3121,7 +3122,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi if (f->curr_token.kind != Token_Eq) { type = parse_var_type(f, allow_ellipsis, allow_typeid_token); Ast *tt = unparen_expr(type); - if (!any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) { + if (is_signature && !any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) { syntax_error(type, "Specialization of typeid is not allowed without polymorphic names"); } }