hare

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

commit abb20ec9fcdc1746a861f0ec5306b05a12992708
parent 326cb92683139676524ff4e0a0964c3e49c53fb0
Author: Sebastian <sebastian@sebsite.pw>
Date:   Wed, 23 Aug 2023 23:39:36 -0400

hare::*: add rconst

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mcmd/ioctlgen/main.ha | 2+-
Mhare/ast/type.ha | 2+-
Mhare/lex/+test.ha | 30+++++++++++++++---------------
Mhare/lex/lex.ha | 2+-
Mhare/lex/token.ha | 6+++---
Mhare/parse/expr.ha | 2+-
Mhare/types/store.ha | 3++-
Mhare/types/types.ha | 2+-
Mhare/unparse/type.ha | 5+++--
9 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/cmd/ioctlgen/main.ha b/cmd/ioctlgen/main.ha @@ -106,7 +106,7 @@ fn parseioctl(store: *types::typestore, d: dir, params: str) ioctl = { const buf = memio::fixed(strings::toutf8(params)); const lex = lex::init(&buf, "<ioctl>"); - const rn = expect(&lex, ltok::LIT_RUNE).1 as rune; + const rn = expect(&lex, ltok::LIT_RCONST).1 as rune; expect(&lex, ltok::COMMA); const num = expect(&lex, ltok::LIT_ICONST).1 as u64; diff --git a/hare/ast/type.ha b/hare/ast/type.ha @@ -13,7 +13,7 @@ export type alias_type = struct { // A built-in primitive type (int, bool, str, etc). export type builtin_type = enum { BOOL, F32, F64, FCONST, I16, I32, I64, I8, ICONST, INT, NULL, OPAQUE, - RUNE, SIZE, STR, U16, U32, U64, U8, UINT, UINTPTR, VALIST, VOID, + RCONST, RUNE, SIZE, STR, U16, U32, U64, U8, UINT, UINTPTR, VALIST, VOID, }; // An enumeration field (and optional value). diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha @@ -219,21 +219,21 @@ fn loc(line: uint, col: uint) location = location { const in = "'a' 'b' '\\a' '\\b' '\\f' '\\n' '\\r' '\\t' '\\v' '\\0' " "'\\\\' '\\\'' '\\x0A' '\\u1234' '\\U12345678'"; const expected: [_]token = [ - (ltok::LIT_RUNE, 'a', loc(1, 1)), - (ltok::LIT_RUNE, 'b', loc(1, 5)), - (ltok::LIT_RUNE, '\a', loc(1, 9)), - (ltok::LIT_RUNE, '\b', loc(1, 14)), - (ltok::LIT_RUNE, '\f', loc(1, 19)), - (ltok::LIT_RUNE, '\n', loc(1, 24)), - (ltok::LIT_RUNE, '\r', loc(1, 29)), - (ltok::LIT_RUNE, '\t', loc(1, 34)), - (ltok::LIT_RUNE, '\v', loc(1, 39)), - (ltok::LIT_RUNE, '\0', loc(1, 44)), - (ltok::LIT_RUNE, '\\', loc(1, 49)), - (ltok::LIT_RUNE, '\'', loc(1, 54)), - (ltok::LIT_RUNE, '\x0A', loc(1, 59)), - (ltok::LIT_RUNE, '\u1234', loc(1, 66)), - (ltok::LIT_RUNE, '\U12345678', loc(1, 75)), + (ltok::LIT_RCONST, 'a', loc(1, 1)), + (ltok::LIT_RCONST, 'b', loc(1, 5)), + (ltok::LIT_RCONST, '\a', loc(1, 9)), + (ltok::LIT_RCONST, '\b', loc(1, 14)), + (ltok::LIT_RCONST, '\f', loc(1, 19)), + (ltok::LIT_RCONST, '\n', loc(1, 24)), + (ltok::LIT_RCONST, '\r', loc(1, 29)), + (ltok::LIT_RCONST, '\t', loc(1, 34)), + (ltok::LIT_RCONST, '\v', loc(1, 39)), + (ltok::LIT_RCONST, '\0', loc(1, 44)), + (ltok::LIT_RCONST, '\\', loc(1, 49)), + (ltok::LIT_RCONST, '\'', loc(1, 54)), + (ltok::LIT_RCONST, '\x0A', loc(1, 59)), + (ltok::LIT_RCONST, '\u1234', loc(1, 66)), + (ltok::LIT_RCONST, '\U12345678', loc(1, 75)), ]; lextest(in, expected); }; diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -296,7 +296,7 @@ fn lex_rn_str(lex: *lexer) (token | error) = { }; // Rune literal - let ret: token = (ltok::LIT_RUNE, lex_rune(lex, loc)?, loc); + let ret: token = (ltok::LIT_RCONST, lex_rune(lex, loc)?, loc); match (next(lex)?) { case io::EOF => return syntaxerr(loc, "unexpected EOF"); diff --git a/hare/lex/token.ha b/hare/lex/token.ha @@ -151,7 +151,7 @@ export type ltok = enum uint { LIT_F32, LIT_F64, LIT_FCONST, - LIT_RUNE, + LIT_RCONST, LIT_STR, LAST_LITERAL = LIT_STR, @@ -336,8 +336,8 @@ export fn tokstr(tok: token) const str = { return "f64"; case ltok::LIT_FCONST => return "fconst"; - case ltok::LIT_RUNE => - return "rune"; + case ltok::LIT_RCONST => + return "rconst"; case ltok::LIT_STR => return "str"; case ltok::NAME => diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -554,7 +554,7 @@ fn cast(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = { fn constant(lexer: *lex::lexer) (ast::expr | error) = { const tok = want(lexer)?; const expr: ast::constant_expr = switch (tok.0) { - case ltok::LIT_RUNE, ltok::LIT_STR => + case ltok::LIT_RCONST, ltok::LIT_STR => yield tok.1 as (rune | str); case ltok::LIT_U8, ltok::LIT_U16, ltok::LIT_U32, ltok::LIT_U64, ltok::LIT_UINT, ltok::LIT_SIZE => diff --git a/hare/types/store.ha b/hare/types/store.ha @@ -252,7 +252,8 @@ fn fromast(store: *typestore, atype: *ast::_type) (_type | deferred | error) = { sz = store.arch._pointer; _align = store.arch._pointer; yield builtin::NULL; - case ast::builtin_type::ICONST, ast::builtin_type::FCONST => + case ast::builtin_type::ICONST, ast::builtin_type::FCONST, + ast::builtin_type::RCONST => abort(); // TODO? case ast::builtin_type::OPAQUE => sz = SIZE_UNDEFINED; diff --git a/hare/types/types.ha b/hare/types/types.ha @@ -23,7 +23,7 @@ export type builtin = enum u8 { // Keep me consistent with ast::builtin BOOL, F32, F64, FCONST, I16, I32, I64, I8, ICONST, INT, NULL, OPAQUE, - RUNE, SIZE, STR, U16, U32, U64, U8, UINT, UINTPTR, VALIST, VOID, + RCONST, RUNE, SIZE, STR, U16, U32, U64, U8, UINT, UINTPTR, VALIST, VOID, }; // An enum type, e.g. enum { FOO = 0 } diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha @@ -12,8 +12,9 @@ use strings; // Returns a builtin type as a string. export fn builtin_type(b: ast::builtin_type) str = switch (b) { -case ast::builtin_type::FCONST, ast::builtin_type::ICONST => - abort("ICONST and FCONST have no lexical representation"); +case ast::builtin_type::FCONST, ast::builtin_type::ICONST, + ast::builtin_type::RCONST => + abort("ICONST, FCONST, and RCONST have no lexical representation"); case ast::builtin_type::BOOL => yield "bool"; case ast::builtin_type::F32 =>