diff options
| -rwxr-xr-x | build_odin.sh | 54 | ||||
| -rw-r--r-- | core/odin/parser/parser.odin | 24 | ||||
| -rw-r--r-- | core/runtime/core_builtin.odin | 56 | ||||
| -rw-r--r-- | src/check_type.cpp | 5 | ||||
| -rw-r--r-- | src/docs_format.cpp | 1 | ||||
| -rw-r--r-- | src/parser.cpp | 65 | ||||
| -rw-r--r-- | src/parser.hpp | 5 |
7 files changed, 97 insertions, 113 deletions
diff --git a/build_odin.sh b/build_odin.sh index b00d33323..da7c17a5b 100755 --- a/build_odin.sh +++ b/build_odin.sh @@ -1,12 +1,20 @@ #!/usr/bin/env bash set -eu -GIT_SHA=$(git rev-parse --short HEAD) +: ${CXX=clang++} +: ${CPPFLAGS=} +: ${CXXFLAGS=} +: ${LDFLAGS=} +: ${ODIN_VERSION=dev-$(date +"%Y-%m")} + +CPPFLAGS="$CPPFLAGS -DODIN_VERSION_RAW=\"$ODIN_VERSION\"" +CXXFLAGS="$CXXFLAGS -std=c++14" +LDFLAGS="$LDFLAGS -pthread -lm -lstdc++" + +GIT_SHA=$(git rev-parse --short HEAD || :) +if [ "$GIT_SHA" ]; then CPPFLAGS="$CPPFLAGS -DGIT_SHA=\"$GIT_SHA\""; fi + DISABLED_WARNINGS="-Wno-switch -Wno-macro-redefined -Wno-unused-value" -LDFLAGS="-pthread -lm -lstdc++" -CFLAGS="-std=c++14 -DGIT_SHA=\"$GIT_SHA\"" -CFLAGS="$CFLAGS -DODIN_VERSION_RAW=\"dev-$(date +"%Y-%m")\"" -CC=clang OS=$(uname) panic() { @@ -18,7 +26,7 @@ version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; config_darwin() { ARCH=$(uname -m) - LLVM_CONFIG=llvm-config + : ${LLVM_CONFIG=llvm-config} # allow for arm only llvm's with version 13 if [ ARCH == arm64 ]; then @@ -37,34 +45,38 @@ config_darwin() { fi LDFLAGS="$LDFLAGS -liconv -ldl" - CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" + CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" LDFLAGS="$LDFLAGS -lLLVM-C" } config_freebsd() { - LLVM_CONFIG=/usr/local/bin/llvm-config11 + : ${LLVM_CONFIG=/usr/local/bin/llvm-config11} - CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" + CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)" } config_openbsd() { - LLVM_CONFIG=/usr/local/bin/llvm-config + : ${LLVM_CONFIG=/usr/local/bin/llvm-config} LDFLAGS="$LDFLAGS -liconv" - CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" + CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)" } config_linux() { - if which llvm-config > /dev/null 2>&1; then - LLVM_CONFIG=llvm-config - elif which llvm-config-11 > /dev/null 2>&1; then - LLVM_CONFIG=llvm-config-11 - elif which llvm-config-11-64 > /dev/null 2>&1; then - LLVM_CONFIG=llvm-config-11-64 - else - panic "Unable to find LLVM-config" + : ${LLVM_CONFIG=} + + if [ ! "$LLVM_CONFIG" ]; then + if which llvm-config > /dev/null 2>&1; then + LLVM_CONFIG=llvm-config + elif which llvm-config-11 > /dev/null 2>&1; then + LLVM_CONFIG=llvm-config-11 + elif which llvm-config-11-64 > /dev/null 2>&1; then + LLVM_CONFIG=llvm-config-11-64 + else + panic "Unable to find LLVM-config" + fi fi MIN_LLVM_VERSION=("11.0.0") @@ -74,7 +86,7 @@ config_linux() { fi LDFLAGS="$LDFLAGS -ldl" - CFLAGS="$CFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" + CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)" LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)" } @@ -97,7 +109,7 @@ build_odin() { esac set -x - $CC src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CFLAGS $EXTRAFLAGS $LDFLAGS -o odin + $CXX src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CPPFLAGS $CXXFLAGS $EXTRAFLAGS $LDFLAGS -o odin set +x } diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 320db28c1..69f42b8ec 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1663,19 +1663,20 @@ is_token_field_prefix :: proc(p: ^Parser) -> ast.Field_Flag { advance_token(p) return .Auto_Cast case .Hash: + tok: tokenizer.Token advance_token(p) - defer advance_token(p) - #partial switch p.curr_tok.kind { - case .Ident: + tok = p.curr_tok + advance_token(p) + if tok.kind == .Ident { for kf in ast.field_hash_flag_strings { - if p.curr_tok.text == kf.key { + if kf.key == tok.text { return kf.flag } } } return .Unknown } - return .Unknown + return .Invalid } parse_field_prefixes :: proc(p: ^Parser) -> (flags: ast.Field_Flags) { @@ -2594,7 +2595,6 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { tok := expect_token(p, .Union) poly_params: ^ast.Field_List align: ^ast.Expr - is_maybe: bool is_no_nil: bool is_shared_nil: bool @@ -2619,10 +2619,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { } align = parse_expr(p, true) case "maybe": - if is_maybe { - error(p, tag.pos, "duplicate union tag '#%s'", tag.text) - } - is_maybe = true + error(p, tag.pos, "#%s functionality has now been merged with standard 'union' functionality", tag.text) case "no_nil": if is_no_nil { error(p, tag.pos, "duplicate union tag '#%s'", tag.text) @@ -2639,19 +2636,12 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { } p.expr_level = prev_level - if is_no_nil && is_maybe { - error(p, p.curr_tok.pos, "#maybe and #no_nil cannot be applied together") - } if is_no_nil && is_shared_nil { error(p, p.curr_tok.pos, "#shared_nil and #no_nil cannot be applied together") } - if is_shared_nil && is_maybe { - error(p, p.curr_tok.pos, "#maybe and #shared_nil cannot be applied together") - } union_kind := ast.Union_Type_Kind.Normal switch { - case is_maybe: union_kind = .maybe case is_no_nil: union_kind = .no_nil case is_shared_nil: union_kind = .shared_nil } diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index 4f698a270..e9fc2a91e 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -339,19 +339,22 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) { if array == nil { return } - - if cap(array) < len(array)+1 { - cap := 2 * cap(array) + max(8, 1) - _ = reserve(array, cap, loc) - } - if cap(array)-len(array) > 0 { - a := (^Raw_Dynamic_Array)(array) - when size_of(E) != 0 { - data := ([^]E)(a.data) - assert(condition=data != nil, loc=loc) - data[a.len] = arg - } + when size_of(E) == 0 { a.len += 1 + } else { + if cap(array) < len(array)+1 { + cap := 2 * cap(array) + max(8, 1) + _ = reserve(array, cap, loc) + } + if cap(array)-len(array) > 0 { + a := (^Raw_Dynamic_Array)(array) + when size_of(E) != 0 { + data := ([^]E)(a.data) + assert(condition=data != nil, loc=loc) + data[a.len] = arg + } + a.len += 1 + } } } @@ -366,20 +369,23 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) return } - - if cap(array) < len(array)+arg_len { - cap := 2 * cap(array) + max(8, arg_len) - _ = reserve(array, cap, loc) - } - arg_len = min(cap(array)-len(array), arg_len) - if arg_len > 0 { - a := (^Raw_Dynamic_Array)(array) - when size_of(E) != 0 { - data := ([^]E)(a.data) - assert(condition=data != nil, loc=loc) - intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len) - } + when size_of(E) == 0 { a.len += arg_len + } else { + if cap(array) < len(array)+arg_len { + cap := 2 * cap(array) + max(8, arg_len) + _ = reserve(array, cap, loc) + } + arg_len = min(cap(array)-len(array), arg_len) + if arg_len > 0 { + a := (^Raw_Dynamic_Array)(array) + when size_of(E) != 0 { + data := ([^]E)(a.data) + assert(condition=data != nil, loc=loc) + intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len) + } + a.len += arg_len + } } } diff --git a/src/check_type.cpp b/src/check_type.cpp index dea523599..5d37ff208 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -695,11 +695,6 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op error(ut->align, "A union with #no_nil must have at least 2 variants"); } break; - case UnionType_maybe: - if (variants.count != 1) { - error(ut->align, "A union with #maybe must have at 1 variant, got %lld", cast(long long)variants.count); - } - break; } if (ut->align != nullptr) { diff --git a/src/docs_format.cpp b/src/docs_format.cpp index ee32d0e05..b1c3c87e7 100644 --- a/src/docs_format.cpp +++ b/src/docs_format.cpp @@ -98,7 +98,6 @@ enum OdinDocTypeFlag_Struct : u32 { enum OdinDocTypeFlag_Union : u32 { OdinDocTypeFlag_Union_polymorphic = 1<<0, OdinDocTypeFlag_Union_no_nil = 1<<1, - OdinDocTypeFlag_Union_maybe = 1<<2, OdinDocTypeFlag_Union_shared_nil = 1<<3, }; diff --git a/src/parser.cpp b/src/parser.cpp index b62ec7a74..ac3acef8a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2548,21 +2548,15 @@ Ast *parse_operand(AstFile *f, bool lhs) { syntax_error(tag, "Invalid union tag '#%.*s'", LIT(tag.string)); } } - if (no_nil && maybe) { - syntax_error(f->curr_token, "#maybe and #no_nil cannot be applied together"); - } + if (no_nil && shared_nil) { syntax_error(f->curr_token, "#shared_nil and #no_nil cannot be applied together"); } - if (shared_nil && maybe) { - syntax_error(f->curr_token, "#maybe and #shared_nil cannot be applied together"); - } - if (maybe) { - union_kind = UnionType_maybe; syntax_error(f->curr_token, "#maybe functionality has now been merged with standard 'union' functionality"); - } else if (no_nil) { + } + if (no_nil) { union_kind = UnionType_no_nil; } else if (shared_nil) { union_kind = UnionType_shared_nil; @@ -3550,49 +3544,34 @@ Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_typeid_token) { } -enum FieldPrefixKind : i32 { - FieldPrefix_Unknown = -1, - FieldPrefix_Invalid = 0, - - FieldPrefix_using, // implies #subtype - FieldPrefix_const, - FieldPrefix_no_alias, - FieldPrefix_c_vararg, - FieldPrefix_auto_cast, - FieldPrefix_any_int, - FieldPrefix_subtype, // does not imply `using` semantics - FieldPrefix_by_ptr, -}; - struct ParseFieldPrefixMapping { String name; TokenKind token_kind; - FieldPrefixKind prefix; FieldFlag flag; }; gb_global ParseFieldPrefixMapping parse_field_prefix_mappings[] = { - {str_lit("using"), Token_using, FieldPrefix_using, FieldFlag_using}, - {str_lit("auto_cast"), Token_auto_cast, FieldPrefix_auto_cast, FieldFlag_auto_cast}, - {str_lit("no_alias"), Token_Hash, FieldPrefix_no_alias, FieldFlag_no_alias}, - {str_lit("c_vararg"), Token_Hash, FieldPrefix_c_vararg, FieldFlag_c_vararg}, - {str_lit("const"), Token_Hash, FieldPrefix_const, FieldFlag_const}, - {str_lit("any_int"), Token_Hash, FieldPrefix_any_int, FieldFlag_any_int}, - {str_lit("subtype"), Token_Hash, FieldPrefix_subtype, FieldFlag_subtype}, - {str_lit("by_ptr"), Token_Hash, FieldPrefix_by_ptr, FieldFlag_by_ptr}, + {str_lit("using"), Token_using, FieldFlag_using}, + {str_lit("auto_cast"), Token_auto_cast, FieldFlag_auto_cast}, + {str_lit("no_alias"), Token_Hash, FieldFlag_no_alias}, + {str_lit("c_vararg"), Token_Hash, FieldFlag_c_vararg}, + {str_lit("const"), Token_Hash, FieldFlag_const}, + {str_lit("any_int"), Token_Hash, FieldFlag_any_int}, + {str_lit("subtype"), Token_Hash, FieldFlag_subtype}, + {str_lit("by_ptr"), Token_Hash, FieldFlag_by_ptr}, }; -FieldPrefixKind is_token_field_prefix(AstFile *f) { +FieldFlag is_token_field_prefix(AstFile *f) { switch (f->curr_token.kind) { case Token_EOF: - return FieldPrefix_Invalid; + return FieldFlag_Invalid; case Token_using: - return FieldPrefix_using; + return FieldFlag_using; case Token_auto_cast: - return FieldPrefix_auto_cast; + return FieldFlag_auto_cast; case Token_Hash: advance_token(f); @@ -3602,33 +3581,33 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) { auto const &mapping = parse_field_prefix_mappings[i]; if (mapping.token_kind == Token_Hash) { if (f->curr_token.string == mapping.name) { - return mapping.prefix; + return mapping.flag; } } } break; } - return FieldPrefix_Unknown; + return FieldFlag_Unknown; } - return FieldPrefix_Invalid; + return FieldFlag_Invalid; } u32 parse_field_prefixes(AstFile *f) { i32 counts[gb_count_of(parse_field_prefix_mappings)] = {}; for (;;) { - FieldPrefixKind kind = is_token_field_prefix(f); - if (kind == FieldPrefix_Invalid) { + FieldFlag flag = is_token_field_prefix(f); + if (flag & FieldFlag_Invalid) { break; } - if (kind == FieldPrefix_Unknown) { + if (flag & FieldFlag_Unknown) { syntax_error(f->curr_token, "Unknown prefix kind '#%.*s'", LIT(f->curr_token.string)); advance_token(f); continue; } for (i32 i = 0; i < gb_count_of(parse_field_prefix_mappings); i++) { - if (parse_field_prefix_mappings[i].prefix == kind) { + if (parse_field_prefix_mappings[i].flag == flag) { counts[i] += 1; advance_token(f); break; diff --git a/src/parser.hpp b/src/parser.hpp index 3126e0a02..156991e24 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -308,6 +308,10 @@ enum FieldFlag : u32 { FieldFlag_Tags = 1<<10, FieldFlag_Results = 1<<16, + + FieldFlag_Unknown = 1u<<30, + FieldFlag_Invalid = 1u<<31, + // Parameter List Restrictions FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg|FieldFlag_auto_cast|FieldFlag_const|FieldFlag_any_int|FieldFlag_by_ptr, FieldFlag_Struct = FieldFlag_using|FieldFlag_subtype|FieldFlag_Tags, @@ -335,7 +339,6 @@ char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { enum UnionTypeKind : u8 { UnionType_Normal = 0, - UnionType_maybe = 1, // removed UnionType_no_nil = 2, UnionType_shared_nil = 3, }; |