Merge remote-tracking branch 'upstream/master' into parser-fix

This commit is contained in:
Daniel Gavin
2022-01-24 16:58:39 +01:00
19 changed files with 130 additions and 1753 deletions

View File

@@ -149,7 +149,7 @@ foreign libc {
putchar :: proc() -> int ---
puts :: proc(s: cstring) -> int ---
ungetc :: proc(c: int, stream: ^FILE) -> int ---
fread :: proc(ptr: rawptr, size: size_t, stream: ^FILE) -> size_t ---
fread :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---
fwrite :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---
// 7.21.9 File positioning functions

View File

@@ -614,6 +614,10 @@ raw_data :: proc{raw_array_data, raw_slice_data, raw_dynamic_array_data, raw_str
@(disabled=ODIN_DISABLE_ASSERT)
assert :: proc(condition: bool, message := "", loc := #caller_location) {
if !condition {
// NOTE(bill): This is wrapped in a procedure call
// to improve performance to make the CPU not
// execute speculatively, making it about an order of
// magnitude faster
proc(message: string, loc: Source_Code_Location) {
p := context.assertion_failure_proc
if p == nil {

View File

@@ -353,6 +353,76 @@ split_after_n_iterator :: proc(s: ^string, sep: string, n: int) -> (string, bool
}
@(private)
_trim_cr :: proc(s: string) -> string {
n := len(s)
if n > 0 {
if s[n-1] == '\r' {
return s[:n-1]
}
}
return s
}
split_lines :: proc(s: string, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, 0, -1, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_n :: proc(s: string, n: int, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, 0, n, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_after :: proc(s: string, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, len(sep), -1, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_after_n :: proc(s: string, n: int, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, len(sep), n, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_iterator :: proc(s: ^string) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, 0, -1) or_return
return _trim_cr(line), true
}
split_lines_n_iterator :: proc(s: ^string, n: int) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, 0, n) or_return
return _trim_cr(line), true
}
split_lines_after_iterator :: proc(s: ^string) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, len(sep), -1) or_return
return _trim_cr(line), true
}
split_lines_after_n_iterator :: proc(s: ^string, n: int) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, len(sep), n) or_return
return _trim_cr(line), true
}

View File

@@ -3419,7 +3419,6 @@ void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_typ
if (operand->value.kind == ExactValue_String) {
String key = operand->value.value_string;
if (is_type_string(operand->type) && is_type_enum(target_type)) {
gb_printf_err("HERE!\n");
Type *et = base_type(target_type);
check_did_you_mean_type(key, et->Enum.fields, ".");
}
@@ -6085,7 +6084,8 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
}
// NOTE(bill): Add type info the parameters
add_type_info_type(c, o->type);
// TODO(bill, 2022-01-23): why was this line added in the first place? I'm commenting it out for the time being
// add_type_info_type(c, o->type);
}
{
@@ -9114,18 +9114,7 @@ gbString string_append_string(gbString str, String string) {
gbString string_append_token(gbString str, Token token) {
if (token.kind == Token_String) {
str = gb_string_append_rune(str, '"');
} else if (token.kind == Token_Rune) {
str = gb_string_append_rune(str, '\'');
}
str = string_append_string(str, token.string);
if (token.kind == Token_String) {
str = gb_string_append_rune(str, '"');
} else if (token.kind == Token_Rune) {
str = gb_string_append_rune(str, '\'');
}
return str;
}

View File

@@ -120,6 +120,8 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
ast_node(p, Field, param);
Ast *type_expr = p->type;
Type *type = nullptr;
CommentGroup *docs = p->docs;
CommentGroup *comment = p->comment;
if (type_expr != nullptr) {
type = check_type_expr(ctx, type_expr, nullptr);
@@ -156,6 +158,14 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
add_entity(ctx, ctx->scope, name, field);
field->Variable.field_group_index = field_group_index;
if (j == 0) {
field->Variable.docs = docs;
}
if (j+1 == p->names.count) {
field->Variable.comment = comment;
}
array_add(&fields_array, field);
String tag = p->tag.string;
if (tag.len != 0 && !unquote_string(permanent_allocator(), &tag, 0, tag.text[0] == '`')) {

View File

@@ -688,12 +688,17 @@ void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) {
ptr_set_add(&d->deps, e);
mutex_unlock(&info->deps_mutex);
}
void add_type_info_dependency(DeclInfo *d, Type *type) {
void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) {
if (d == nullptr) {
return;
}
// NOTE(bill): no mutex is required here because the only procedure calling it is wrapped in a mutex already
if (require_mutex) {
mutex_lock(&info->deps_mutex);
}
ptr_set_add(&d->type_info_deps, type);
if (require_mutex) {
mutex_unlock(&info->deps_mutex);
}
}
AstPackage *get_core_package(CheckerInfo *info, String name) {
@@ -1589,7 +1594,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) {
return;
}
add_type_info_dependency(c->decl, t);
add_type_info_dependency(c->info, c->decl, t, false);
auto found = map_get(&c->info->type_info_map, t);
if (found != nullptr) {
@@ -1718,6 +1723,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) {
} else {
add_type_info_type_internal(c, t_type_info_ptr);
}
add_type_info_type_internal(c, bt->Union.polymorphic_params);
for_array(i, bt->Union.variants) {
add_type_info_type_internal(c, bt->Union.variants[i]);
}
@@ -1741,6 +1747,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) {
}
}
}
add_type_info_type_internal(c, bt->Struct.polymorphic_params);
for_array(i, bt->Struct.fields) {
Entity *f = bt->Struct.fields[i];
add_type_info_type_internal(c, f->type);
@@ -1934,6 +1941,7 @@ void add_min_dep_type_info(Checker *c, Type *t) {
} else {
add_min_dep_type_info(c, t_type_info_ptr);
}
add_min_dep_type_info(c, bt->Union.polymorphic_params);
for_array(i, bt->Union.variants) {
add_min_dep_type_info(c, bt->Union.variants[i]);
}
@@ -1957,6 +1965,7 @@ void add_min_dep_type_info(Checker *c, Type *t) {
}
}
}
add_min_dep_type_info(c, bt->Struct.polymorphic_params);
for_array(i, bt->Struct.fields) {
Entity *f = bt->Struct.fields[i];
add_min_dep_type_info(c, f->type);
@@ -5473,9 +5482,6 @@ void check_parsed_files(Checker *c) {
TIME_SECTION("calculate global init order");
calculate_global_init_order(c);
TIME_SECTION("generate minimum dependency set");
generate_minimum_dependency_set(c, c->info.entry_point);
TIME_SECTION("check test procedures");
check_test_procedures(c);
@@ -5486,6 +5492,9 @@ void check_parsed_files(Checker *c) {
add_type_info_for_type_definitions(c);
check_merge_queues_into_arrays(c);
TIME_SECTION("generate minimum dependency set");
generate_minimum_dependency_set(c, c->info.entry_point);
TIME_SECTION("check entry point");
if (build_context.build_mode == BuildMode_Executable && !build_context.no_entry_point && build_context.command_kind != Command_test) {
Scope *s = c->info.init_scope;

View File

@@ -185,8 +185,8 @@ struct OdinDocEntity {
OdinDocTypeIndex type;
OdinDocString init_string;
u32 reserved_for_init;
OdinDocString comment;
OdinDocString docs;
OdinDocString comment; // line comment
OdinDocString docs; // preceding comment
i32 field_group_index;
OdinDocEntityIndex foreign_library;
OdinDocString link_name;

View File

@@ -811,6 +811,12 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) {
comment = e->decl_info->comment;
docs = e->decl_info->docs;
}
if (!comment && e->kind == Entity_Variable) {
comment = e->Variable.comment;
}
if (!docs && e->kind == Entity_Variable) {
docs = e->Variable.docs;
}
String link_name = {};

View File

@@ -175,6 +175,8 @@ struct Entity {
String link_name;
String link_prefix;
String link_section;
CommentGroup *docs;
CommentGroup *comment;
bool is_foreign;
bool is_export;
} Variable;

View File

@@ -403,6 +403,7 @@ void compiler_error(char const *fmt, ...) {
gb_printf_err("Internal Compiler Error: %s\n",
gb_bprintf_va(fmt, va));
va_end(va);
GB_DEBUG_TRAP();
gb_exit(1);
}

View File

@@ -488,6 +488,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
lbValue ptr = lb_address_from_load_or_generate_local(p, param);
lb_add_entity(p->module, e, ptr);
// lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
}
} else if (arg_type->kind == lbArg_Indirect) {
if (e->token.string.len != 0 && !is_blank_ident(e->token.string)) {
@@ -496,6 +497,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
ptr.type = alloc_type_pointer(e->type);
lb_add_entity(p->module, e, ptr);
// lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
}
}
param_index += 1;

View File

@@ -1,11 +1,10 @@
isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) {
isize index = type_info_index(info, type, false);
auto *set = &info->minimum_dependency_type_info_set;
isize index = type_info_index(info, type, err_on_not_found);
if (index >= 0) {
auto *set = &info->minimum_dependency_type_info_set;
for_array(i, set->entries) {
if (set->entries[i].ptr == index) {
return i+1;
}
isize i = ptr_entry_index(set, index);
if (i >= 0) {
return i+1;
}
}
if (err_on_not_found) {

View File

@@ -944,7 +944,7 @@ Ast *ast_field(AstFile *f, Array<Ast *> const &names, Ast *type, Ast *default_va
result->Field.default_value = default_value;
result->Field.flags = flags;
result->Field.tag = tag;
result->Field.docs = docs;
result->Field.docs = docs;
result->Field.comment = comment;
return result;
}

View File

@@ -138,6 +138,15 @@ gb_inline bool ptr_set_exists(PtrSet<T> *s, T ptr) {
return index != MAP_SENTINEL;
}
template <typename T>
gb_inline isize ptr_entry_index(PtrSet<T> *s, T ptr) {
isize index = ptr_set__find(s, ptr).entry_index;
if (index != MAP_SENTINEL) {
return index;
}
return -1;
}
// Returns true if it already exists
template <typename T>
T ptr_set_add(PtrSet<T> *s, T ptr) {

View File

@@ -1,45 +0,0 @@
</div>
</main>
<footer class="odin-footer">
<div class="container pb-5 pt-5">
<div class="row g-4">
<div class="col">
<a class="navbar-brand" href="https://odin-lang.org">
<img class="mb-3" src="https://odin-lang.org/logo.svg" height="30" alt="Odin"></a>
<p>
The Data-Oriented Language for Sane Software Development.
</p>
</div>
<nav class="col-md-auto">
<h4 class="fw-normal">Resources</h4>
<ul class="list-unstyled">
<li><a href="https://odin-lang.org/docs" class="link-light">Docs</a></li>
<li><a href="https://pkg.odin-lang.org/" class="link-light">Packages</a></li>
<li><a href="https://odin-lang.org/news" class="link-light">News</a></li>
</ul>
</nav>
<nav class="col-md-auto">
<h4 class="fw-normal">Community</h4>
<ul class="list-unstyled">
<li><a href="https://github.com/odin-lang/Odin" target="_blank" class="link-light">GitHub</a></li>
<li><a href="https://discord.com/invite/sVBPHEv" target="_blank" class="link-light">Discord</a></li>
<li><a href="https://www.twitch.tv/ginger_bill" target="_blank" class="link-light">Twitch</a></li>
<li><a href="https://www.youtube.com/channel/UCUSck1dOH7VKmG4lRW7tZXg" target="_blank" class="link-light">YouTube</a></li>
</ul>
</nav>
<nav class="col-md-auto">
<h4 class="fw-normal">Contribute</h4>
<ul class="list-unstyled">
<li><a href="https://github.com/odin-lang/Odin/issues" target="_blank" class="link-light">Issues</a></li>
<li><a href="https://www.patreon.com/gingerbill" target="_blank" class="link-light">Donate</a></li>
</ul>
</nav>
</div>
<div class="mt-4 text-muted">© 20162022 Ginger Bill</div>
</div>
</footer>
<script src="https://odin-lang.org/lib/bootstrap/js/bootstrap.min.js"></script>
<script src="https://odin-lang.org/js/script.js"></script>
<script>hljs.highlightAll()</script>

View File

@@ -1,36 +0,0 @@
<!-- REMEMBER TO REMOVE -->
<script type="text/javascript" src="https://livejs.com/live.js"></script>
<link rel="stylesheet" type="text/css" href="https://odin-lang.org/scss/custom.min.css">
<link rel=stylesheet href=//odin-lang.org/lib/highlight/styles/github-dark.min.css>
<script src=//odin-lang.org/lib/highlight/highlight.min.js></script>
<script>hljs.registerLanguage("odin",function(a){return{aliases:["odin","odinlang","odin-lang"],keywords:{keyword:"auto_cast bit_set break case cast context continue defer distinct do dynamic else enum fallthrough for foreign if import in map not_in or_else or_return package proc return struct switch transmute type_of typeid union using when where",literal:"true false nil",built_in:"abs align_of cap clamp complex conj expand_to_tuple imag jmag kmag len max min offset_of quaternion real size_of soa_unzip soa_zip swizzle type_info_of type_of typeid_of"},illegal:"</",contains:[a.C_LINE_COMMENT_MODE,a.C_BLOCK_COMMENT_MODE,{className:"string",variants:[a.QUOTE_STRING_MODE,{begin:"'",end:"[^\\\\]'"},{begin:"`",end:"`"}]},{className:"number",variants:[{begin:a.C_NUMBER_RE+"[ijk]",relevance:1},a.C_NUMBER_MODE]}]}})</script>
<script>hljs.highlightAll()</script>
<link rel="stylesheet" type="text/css" href="https://odin-lang.org/css/style.css">
<link rel="stylesheet" type="text/css" href="/style.css">
</style>
</head>
<body>
<header class="sticky-top">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary odin-menu">
<div class="container">
<a class="navbar-brand" href="https://odin-lang.org/">
<img src="https://odin-lang.org/logo.svg" height="30" alt="Odin"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#odin-navbar-content" aria-controls="odin-navbar-content" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="odin-navbar-content">
<ul class="navbar-nav ms-md-auto">
<li class="nav-item"><a class="nav-link" href="https://odin-lang.org/">Home</a></li>
<li class="nav-item"><a class="nav-link" href="https://odin-lang.org/docs">Docs</a></li>
<li class="nav-item"><a class="nav-link active" href="/">Packages</a></li>
<li class="nav-item"><a class="nav-link" href="https://odin-lang.org/news">News</a></li>
<li class="nav-item"><a class="nav-link" href="https://odin-lang.org/community">Community</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/odin-lang/Odin" target="_blank">GitHub</a></li>
</ul>
</div>
</div>
</nav>
</header>
<main>
<div class="container">

View File

@@ -1,6 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{0:s}</title>

File diff suppressed because it is too large Load Diff

View File

@@ -1,163 +0,0 @@
/* doc directories */
table.directory {
/*border: 1px solid #ccc!important;*/
table-layout: fixed;
border-collapse: collapse;
}
header.collection-header ul {
margin-top: 1em;
margin-bottom: 0;
padding-left: 0.5em;
list-style-type: none;
}
hr.collection-hr {
margin: 0;
padding: 0;
}
.doc-directory tr {
padding-left: 1em!important;
border-top: 1px solid #ccc!important;
border-bottom: 1px solid #ccc!important;
}
.doc-directory td {
padding: 0.25em 0.5em;
}
.directory-child td {
padding-left: 2em!important;
}
.directory-child td+td {
position: relative;
left: -1.5em!important;
padding-right: 0;
}
.doc-directory tr[aria-expanded=true] td.pkg-name:before {
content: "\2193";
}
.doc-directory tr[aria-expanded=false] td.pkg-name:before {
content: "\2192"!important;
}
.doc-directory tr[aria-hidden=true] {
display: none;
}
/* doc page */
pre.doc-code {
white-space: pre-wrap;
word-break: keep-all;
word-wrap: break-word;
tab-size: 8;
background-color: #f8f8f8;
color: #202224;
border: 1px solid #c6c8ca;
border-radius: 0.25rem;
padding: 0.625rem;
}
pre.doc-code a {
font-family: Consolas,Liberation Mono,Menlo,monospace!important;
text-decoration: none;
color: #2179d8;
font-weight: 800;
}
pre.doc-code a.code-procedure {
color: #047919;
}
.pkg-line-doc {
color: #444;
width: 100%;
}
.doc-source {
display: inline;
float: right;
}
.doc-source a {
text-decoration: none;
color: #666666;
font-size: 0.75em;
}
.doc-source a:hover {
text-decoration: underline;
}
a > .a-hidden {
opacity: 0;
}
a:hover > .a-hidden {
opacity: 100;
}
section.documentation h3 {
font-size: calc(1.1rem + .2vw);
}
.pkg-index h3 {
margin-top: 0 !important;
padding-top: 0 !important;
}
.documentation .pkg-entity {
padding-bottom: 0.75rem;
border-bottom: 1px solid #d0d0d0;
}
details.doc-index > summary {
font-size: 1.75rem;
}
details.doc-index ul {
list-style-type: none;
}
details.odin-doc-toggle > summary.hideme span:before {
content: "Expand description";
}
details.odin-doc-toggle[open] > summary.hideme span:before {
content: "Close description";
opacity: 0.8;
}
details.odin-doc-toggle[open] > summary.hideme {
margin-bottom: 0.5em;
}
details.code-example > summary {
font-weight: 700;
}
@media only screen and (max-width: 991px) {
#pkg-sidebar {
display: none;
}
}
#pkg-sidebar ul {
list-style-type: none;
padding: 0;
}
#pkg-sidebar li:not(:last-child) {
margin-bottom: 0.25rem;
}
#pkg-sidebar li > ul {
padding-left: 1.25rem;
}
#pkg-sidebar a.active {
font-style: italic;
}