hare

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

commit 8be4df190115c977077b4404c2305dfefcbc7ae3
parent e7418dd2e41303f95c6c1bd5c373e110a59923b4
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 22 Aug 2021 12:10:05 +0200

cmd/harec: improve rtype logic

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mcmd/harec/gen.ha | 7+++++--
Mhare/types/lookup.ha | 12++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/cmd/harec/gen.ha b/cmd/harec/gen.ha @@ -43,8 +43,11 @@ fn gen_func(ctx: *context, decl: *unit::decl) void = { fmt::printf("{}function section \".text.{}\" \"ax\"", if (decl.exported) "export " else "", ident)!; const rtype = fntype.result; - if (!(rtype._type is types::builtin) || - rtype._type as types::builtin != types::builtin::VOID) { + const has_rval = match (types::dealias(rtype)._type) { + bi: types::builtin => bi != types::builtin::VOID, + * => true, + }; + if (has_rval) { abort(); // TODO: Return type }; fmt::printf(" ${}(", ident)!; diff --git a/hare/types/lookup.ha b/hare/types/lookup.ha @@ -1,5 +1,17 @@ use hare::ast; +// Unwraps a type which may be aliased and returns the underlying type. +export fn dealias(t: *_type) const *_type = { + for (true) match (t._type) { + a: alias => { + assert(a._type != null); + t = a._type: const *_type; + }, + * => break, + }; + return t; +}; + // Looks up a built-in type. export fn lookup_builtin( store: *typestore,