hare

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

commit 58dd87d6a4baeb26b5ae14e54bc2f4e8c278d40a
parent 5bb8de296052e9a27802142f80a160e0a1b1bb55
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri,  3 Sep 2021 12:37:12 +0200

cmd/haretype: new command

A small utility for working with Hare types.

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

Diffstat:
Acmd/haretype/main.ha | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/cmd/haretype/main.ha b/cmd/haretype/main.ha @@ -0,0 +1,30 @@ +use bufio; +use fmt; +use hare::ast; +use hare::lex; +use hare::parse; +use hare::types; +use hare::unparse; +use io; +use os; +use strings; + +export fn main() void = { + for (let i = 1z; i < len(os::args); i += 1) { + const stream = bufio::fixed( + strings::toutf8(os::args[i]), + io::mode::READ); + defer io::close(stream); + const lexer = lex::init(stream, "-"); + const atype = parse::_type(&lexer)!; + defer ast::type_free(atype); + unparse::_type(os::stdout, 0, atype)!; + fmt::println()!; + const store = types::store(types::x86_64, null, null); + defer types::store_free(store); + const hatype = types::lookup(store, &atype)!; + fmt::printfln("\tid: {}", hatype.id)!; + fmt::printfln("\tsize: {}", hatype.sz)!; + fmt::printfln("\talign: {}", hatype.align)!; + }; +};