hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 73b846f9d8ba7eba10ae719afd1e2a68f00a7123
parent 3688d16c750f789d08488a592e55b6e9bb5db78d
Author: Stacy Harper <contact@stacyharper.net>
Date:   Fri, 23 Dec 2022 15:50:07 +0100

hare::ast: Make struct_type a struct on its own

We prepare this to add @packed later.

Signed-off-by: Stacy Harper <contact@stacyharper.net>

Diffstat:
Mcmd/haredoc/html.ha | 2+-
Mcmd/haredoc/tty.ha | 2+-
Mhare/ast/type.ha | 8++++++--
Mhare/parse/type.ha | 2+-
Mhare/types/store.ha | 14++++++++++----
Mhare/unparse/type.ha | 2+-
6 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha @@ -559,7 +559,7 @@ fn struct_union_html( let members = match (t.repr) { case let t: ast::struct_type => z += fmt::fprint(out, "<span class='keyword'>struct</span> {")?; - yield t: []ast::struct_member; + yield t.members: []ast::struct_member; case let t: ast::union_type => z += fmt::fprint(out, "<span class='keyword'>union</span> {")?; yield t: []ast::struct_member; diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha @@ -361,7 +361,7 @@ fn struct_union_type_tty( n += fmt::fprint(out, "struct")?; n += render(out, syn::PUNCTUATION)?; n += fmt::fprint(out, " {")?; - yield st: []ast::struct_member; + yield st.members: []ast::struct_member; case let ut: ast::union_type => n += render(out, syn::TYPE)?; n += fmt::fprint(out, "union")?; diff --git a/hare/ast/type.ha b/hare/ast/type.ha @@ -107,11 +107,15 @@ export type struct_member = struct { }; // struct { ... } -export type struct_type = []struct_member; +export type struct_type = struct { + members: []struct_member, +}; // union { ... } export type union_type = []struct_member; +export type struct_union_type = (struct_type | union_type); + // (int | bool) export type tagged_type = []*_type; @@ -138,7 +142,7 @@ export type _type = struct { fn struct_type_finish(t: (struct_type | union_type)) void = { let membs = match (t) { case let s: struct_type => - yield s: []struct_member; + yield s.members: []struct_member; case let u: union_type => yield u: []struct_member; }; diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -291,7 +291,7 @@ fn struct_union_type(lexer: *lex::lexer) (ast::_type | error) = { flags = ast::type_flags::NONE, repr = switch (kind.0) { case ltok::STRUCT => - yield membs: ast::struct_type; + yield ast::struct_type { members = membs, ...}; case ltok::UNION => yield membs: ast::union_type; case => abort(); diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -415,12 +415,18 @@ fn list_from_ast( fn _struct_from_ast( store: *typestore, - membs: []ast::struct_member, + atype: ast::struct_union_type, is_union: bool, fields: *[]struct_field, offs: *size, ) (void | deferred | error) = { const nfields = len(fields); + const membs = match(atype) { + case let atype: ast::struct_type => + yield atype.members; + case let atype: ast::union_type => + yield atype: []ast::struct_member; + }; for (let i = 0z; i < len(membs); i += 1) { *offs = match (membs[i]._offset) { case let ex: *ast::expr => @@ -438,7 +444,7 @@ fn _struct_from_ast( case let se: ast::struct_embedded => let membs: []ast::struct_member = match (se.repr) { case let st: ast::struct_type => - yield st; + yield st.members; case let ut: ast::union_type => yield ut; case => @@ -483,12 +489,12 @@ fn _struct_from_ast( fn struct_from_ast( store: *typestore, - membs: []ast::struct_member, + atype: ast::struct_union_type, is_union: bool, ) (_struct | deferred | error) = { let fields: []struct_field = []; let offs = 0z; - _struct_from_ast(store, membs, is_union, &fields, &offs)?; + _struct_from_ast(store, atype, is_union, &fields, &offs)?; sort::sort(fields, size(struct_field), &field_cmp); return _struct { kind = if (is_union) struct_union::UNION else struct_union::STRUCT, diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha @@ -162,7 +162,7 @@ fn struct_union_type( let membs = match (t.repr) { case let st: ast::struct_type => z += fmt::fprint(out, "struct {")?; - yield st: []ast::struct_member; + yield st.members: []ast::struct_member; case let ut: ast::union_type => z += fmt::fprint(out, "union {")?; yield ut: []ast::struct_member;