hare

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

commit f800d506743ae4faa3a17e9f40c02f66cb1a4855
parent a34403b365af8c13f0868901ebfe31f3edbcf250
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat,  9 Dec 2023 21:07:47 -0500

hare::ast: s/constant/literal/g

(except for constant declarations)

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

Diffstat:
Mhare/ast/expr.ha | 44++++++++++++++++++++++----------------------
Mhare/parse/expr.ha | 50+++++++++++++++++++++++++-------------------------
Mhare/types/+test.ha | 4++--
Mhare/unit/process.ha | 12++++++------
Mhare/unparse/decl.ha | 4++--
Mhare/unparse/expr.ha | 28++++++++++++++--------------
6 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/hare/ast/expr.ha b/hare/ast/expr.ha @@ -206,10 +206,10 @@ export type compound_expr = struct { label: label, }; -// An array constant. +// An array literal. // // [foo, bar, ...] -export type array_constant = struct { +export type array_literal = struct { expand: bool, values: []*expr, }; @@ -223,19 +223,19 @@ export type struct_value = struct { init: *expr, }; -// A struct constant. +// A struct literal. // // struct { foo: int = bar, struct { baz = quux }, ... } -export type struct_constant = struct { +export type struct_literal = struct { autofill: bool, alias: ident, // [] for anonymous - fields: [](struct_value | *struct_constant), + fields: [](struct_value | *struct_literal), }; -// A tuple constant. +// A tuple literal. // // (foo, bar, ...) -export type tuple_constant = []*expr; +export type tuple_literal = []*expr; // The value "null". export type _null = void; @@ -243,16 +243,16 @@ export type _null = void; // A scalar value. export type value = (bool | _null | str | rune | void); -// An integer or float constant. -export type number_constant = struct { +// An integer or float literal. +export type number_literal = struct { suff: lex::ltok, value: (i64 | u64 | f64), sign: bool, // true if negative, false otherwise }; -// A constant expression. -export type constant_expr = (value | array_constant | number_constant | - struct_constant | tuple_constant); +// A literal expression. +export type literal_expr = (value | array_literal | number_literal | + struct_literal | tuple_literal); // A continue expression. The label is set to empty string if absent. // @@ -434,7 +434,7 @@ export type expr = struct { end: lex::location, expr: (access_expr | align_expr | alloc_expr | append_expr | assert_expr | assign_expr | binarithm_expr | binding_expr | - break_expr | call_expr | cast_expr | constant_expr | + break_expr | call_expr | cast_expr | literal_expr | continue_expr | defer_expr | delete_expr | for_expr | free_expr | error_assert_expr | if_expr | insert_expr | compound_expr | match_expr | len_expr | size_expr | @@ -539,23 +539,23 @@ case let e: *expr => }; free(c.exprs); free(c.label); - case let c: constant_expr => + case let c: literal_expr => match (c) { - case let a: array_constant => + case let a: array_literal => for (let i = 0z; i < len(a.values); i += 1) { expr_finish(a.values[i]); free(a.values[i]); }; free(a.values); - case let s: struct_constant => - struct_constant_finish(&s); - case let t: tuple_constant => + case let s: struct_literal => + struct_literal_finish(&s); + case let t: tuple_literal => for (let i = 0z; i < len(t); i += 1) { expr_finish(t[i]); free(t[i]); }; free(t); - case (value | number_constant) => void; + case (value | number_literal) => void; }; case let c: continue_expr => free(c); @@ -672,7 +672,7 @@ case let e: *expr => }; }; -fn struct_constant_finish(s: *struct_constant) void = { +fn struct_literal_finish(s: *struct_literal) void = { ident_free(s.alias); for (let i = 0z; i < len(s.fields); i += 1) { match (s.fields[i]) { @@ -682,8 +682,8 @@ fn struct_constant_finish(s: *struct_constant) void = { free(v._type); expr_finish(v.init); free(v.init); - case let c: *struct_constant => - struct_constant_finish(c); + case let c: *struct_literal => + struct_literal_finish(c); free(c); }; }; diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -514,14 +514,14 @@ fn cast(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = { })?; }; -fn constant(lexer: *lex::lexer) (ast::expr | error) = { +fn literal(lexer: *lex::lexer) (ast::expr | error) = { const tok = want(lexer)?; - const expr: ast::constant_expr = switch (tok.0) { + const expr: ast::literal_expr = switch (tok.0) { 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 => - yield ast::number_constant { + yield ast::number_literal { suff = tok.0, value = tok.1 as u64, sign = false, @@ -529,20 +529,20 @@ fn constant(lexer: *lex::lexer) (ast::expr | error) = { case ltok::LIT_I8, ltok::LIT_I16, ltok::LIT_I32, ltok::LIT_I64, ltok::LIT_INT => const n = tok.1 as u64; - yield ast::number_constant { + yield ast::number_literal { suff = tok.0, value = n: i64, sign = false, }; case ltok::LIT_ICONST => const n = tok.1 as u64; - yield ast::number_constant { + yield ast::number_literal { suff = tok.0, value = if (n <= types::I64_MAX: u64) n: i64 else n, sign = false, }; case ltok::LIT_F32, ltok::LIT_F64, ltok::LIT_FCONST => - yield ast::number_constant { + yield ast::number_literal { suff = tok.0, value = tok.1 as f64, sign = false, @@ -556,7 +556,7 @@ fn constant(lexer: *lex::lexer) (ast::expr | error) = { case ltok::NULL => yield ast::_null; case => - return syntaxerr(lex::mkloc(lexer), "Expected constant expression"); + return syntaxerr(lex::mkloc(lexer), "Expected literal expression"); }; return ast::expr { start = tok.2, @@ -817,11 +817,11 @@ fn idxexpr(lexer: *lex::lexer) (ast::expr | error) = { fn plain_expression(lexer: *lex::lexer) (ast::expr | error) = { let tok = peek(lexer)? as lex::token; if (tok.0 >= ltok::LIT_U8 && tok.0 <= ltok::LAST_LITERAL) { - return constant(lexer); + return literal(lexer); }; switch (tok.0) { case ltok::TRUE, ltok::FALSE, ltok::NULL, ltok::VOID => - return constant(lexer); + return literal(lexer); case ltok::LBRACKET => return plain_array(lexer)?; case ltok::STRUCT => @@ -896,7 +896,7 @@ fn plain_array(lexer: *lex::lexer) (ast::expr | error) = { return ast::expr { start = start.2, end = lex::prevloc(lexer), - expr = ast::array_constant { + expr = ast::array_literal { expand = expand, values = values, }, @@ -906,14 +906,14 @@ fn plain_array(lexer: *lex::lexer) (ast::expr | error) = { fn plain_struct( lexer: *lex::lexer, alias: ast::ident, -) (ast::struct_constant | error) = { +) (ast::struct_literal | error) = { if (len(alias) == 0) { want(lexer, ltok::STRUCT)?; }; want(lexer, ltok::LBRACE)?; let autofill = false; - let fields: [](ast::struct_value | *ast::struct_constant) = []; + let fields: [](ast::struct_value | *ast::struct_literal) = []; for (true) { const tok = want(lexer, ltok::ELLIPSIS, ltok::NAME, ltok::STRUCT)?; @@ -940,7 +940,7 @@ fn plain_struct( }; }; - return ast::struct_constant { + return ast::struct_literal { autofill = autofill, alias = alias, fields = fields, @@ -949,7 +949,7 @@ fn plain_struct( fn struct_field( lexer: *lex::lexer, -) (ast::struct_value | *ast::struct_constant | error) = { +) (ast::struct_value | *ast::struct_literal | error) = { const tok = want(lexer, ltok::NAME, ltok::STRUCT)?; switch (tok.0) { case ltok::NAME => @@ -1019,7 +1019,7 @@ fn plain_tuple( return ast::expr { start = start, end = lex::prevloc(lexer), - expr = values: ast::tuple_constant, + expr = values: ast::tuple_literal, }; }; @@ -1079,17 +1079,17 @@ fn postfix_dot( }, }; case void => - let con = constant(lexer)?; - let val = con.expr as ast::constant_expr; - synassert(lex::mkloc(lexer), val is ast::number_constant, - "Expected integer constant")?; - let val = val as ast::number_constant; + let lit = literal(lexer)?; + let val = lit.expr as ast::literal_expr; + synassert(lex::mkloc(lexer), val is ast::number_literal, + "Expected integer literal")?; + let val = val as ast::number_literal; return ast::expr { start = lvalue.start, end = lex::prevloc(lexer), expr = ast::access_tuple { object = alloc(lvalue), - value = alloc(con), + value = alloc(lit), }, }; }; @@ -1282,9 +1282,9 @@ fn unarithm(lexer: *lex::lexer) (ast::expr | error) = { const operand = unarithm(lexer)?; const expr = :blk { if (op == ast::unarithm_op::MINUS) match (operand.expr) { - case let c: ast::constant_expr => + case let c: ast::literal_expr => match (c) { - case let n: ast::number_constant => + case let n: ast::number_literal => let sign = false; const val = match (n.value) { case let i: i64 => @@ -1297,11 +1297,11 @@ fn unarithm(lexer: *lex::lexer) (ast::expr | error) = { }; if (val is void) yield; - yield :blk, ast::number_constant { + yield :blk, ast::number_literal { suff = n.suff, value = val as (i64 | f64), sign = sign, - }: ast::constant_expr; + }: ast::literal_expr; case => void; }; case => void; diff --git a/hare/types/+test.ha b/hare/types/+test.ha @@ -45,8 +45,8 @@ fn resolve( store: *typestore, expr: const *ast::expr, ) (size | deferred | error) = { - let expr = expr.expr as ast::constant_expr; - let n = expr as ast::number_constant; + let expr = expr.expr as ast::literal_expr; + let n = expr as ast::number_literal; let ival = n.value as i64; assert(ival >= 0); return ival: size; diff --git a/hare/unit/process.ha b/hare/unit/process.ha @@ -110,7 +110,7 @@ fn process_expr( abort(); // TODO case ast::compound_expr => return process_compound(ctx, expr); - case ast::constant_expr => + case ast::literal_expr => return process_constant(ctx, expr); case ast::continue_expr => abort(); // TODO @@ -232,7 +232,7 @@ fn process_compound(ctx: *context, aexpr: *ast::expr) (*expr | error) = { }; fn process_constant(ctx: *context, aexpr: *ast::expr) (*expr | error) = { - const constexpr = aexpr.expr as ast::constant_expr; + const constexpr = aexpr.expr as ast::literal_expr; const (result, ex) = match (constexpr) { case let v: ast::value => yield ( @@ -251,9 +251,9 @@ fn process_constant(ctx: *context, aexpr: *ast::expr) (*expr | error) = { }), v: constant, ); - case ast::array_constant => + case ast::array_literal => abort(); // TODO - case let v: ast::number_constant => + case let v: ast::number_literal => yield ( types::lookup_builtin(ctx.store, switch (v.suff) { case lex::ltok::LIT_U8 => @@ -286,9 +286,9 @@ fn process_constant(ctx: *context, aexpr: *ast::expr) (*expr | error) = { }), v.value: constant, ); - case ast::struct_constant => + case ast::struct_literal => abort(); // TODO - case ast::tuple_constant => + case ast::tuple_literal => abort(); // TODO }; return alloc(expr { diff --git a/hare/unparse/decl.ha b/hare/unparse/decl.ha @@ -61,7 +61,7 @@ export fn decl( for (let i = 0z; i < len(g); i += 1) { if (len(g[i].symbol) != 0) { n += syn(&ctx, "@symbol(", synkind::ATTRIBUTE)?; - n += constant(&ctx, syn, g[i].symbol)?; + n += literal(&ctx, syn, g[i].symbol)?; n += syn(&ctx, ")", synkind::ATTRIBUTE)?; n += space(&ctx)?; } else if (g[i].is_threadlocal) { @@ -136,7 +136,7 @@ export fn decl( let p = f.prototype.repr as ast::func_type; if (len(f.symbol) != 0) { n += syn(&ctx, "@symbol(", synkind::ATTRIBUTE)?; - n += constant(&ctx, syn, f.symbol)?; + n += literal(&ctx, syn, f.symbol)?; n += syn(&ctx, ")", synkind::ATTRIBUTE)?; n += space(&ctx)?; }; diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha @@ -314,8 +314,8 @@ fn _expr(ctx: *context, syn: *synfunc, e: *ast::expr) (size | io::error) = { }; z += __type(ctx, syn, e._type)?; return z; - case let e: ast::constant_expr => - return constant(ctx, syn, e)?; + case let e: ast::literal_expr => + return literal(ctx, syn, e)?; case let e: ast::continue_expr => let z = syn(ctx, "continue", synkind::KEYWORD)?; if (e != "") { @@ -593,10 +593,10 @@ fn stmt(ctx: *context, syn: *synfunc, e: *ast::expr) (size | io::error) = { return n; }; -fn constant( +fn literal( ctx: *context, syn: *synfunc, - e: ast::constant_expr, + e: ast::literal_expr, ) (size | io::error) = { match (e) { case void => @@ -627,7 +627,7 @@ fn constant( synkind::RUNE_STRING)?; }; }; - case let ac: ast::array_constant => + case let ac: ast::array_literal => let z = syn(ctx, "[", synkind::PUNCTUATION)?; for (let i = 0z; i < len(ac.values); i += 1) { z += _expr(ctx, syn, ac.values[i])?; @@ -641,7 +641,7 @@ fn constant( }; z += syn(ctx, "]", synkind::PUNCTUATION)?; return z; - case let v: ast::number_constant => + case let v: ast::number_literal => const s = fmt::asprintf("{}{}", v.value, switch (v.suff) { case ltok::LIT_U8 => yield "u8"; @@ -675,9 +675,9 @@ fn constant( }); defer free(s); return syn(ctx, s, synkind::NUMBER)?; - case let sc: ast::struct_constant => - return struct_constant(ctx, syn, sc)?; - case let tu: ast::tuple_constant => + case let sc: ast::struct_literal => + return struct_literal(ctx, syn, sc)?; + case let tu: ast::tuple_literal => let z = syn(ctx, "(", synkind::PUNCTUATION)?; for (let i = 0z; i < len(tu); i += 1) { z += _expr(ctx, syn, tu[i])?; @@ -691,10 +691,10 @@ fn constant( }; }; -fn struct_constant( +fn struct_literal( ctx: *context, syn: *synfunc, - sc: ast::struct_constant, + sc: ast::struct_literal, ) (size | io::error) = { let z = 0z; z += if (len(sc.alias) != 0) { @@ -721,8 +721,8 @@ fn struct_constant( z += syn(ctx, "=", synkind::OPERATOR)?; z += space(ctx)?; z += _expr(ctx, syn, sv.init)?; - case let sc: *ast::struct_constant => - z += constant(ctx, syn, *sc)?; + case let sc: *ast::struct_literal => + z += literal(ctx, syn, *sc)?; }; z += syn(ctx, ",", synkind::PUNCTUATION)?; }; @@ -911,7 +911,7 @@ fn case_exprs( fn is_plain(e: *ast::expr) bool = { match (e.expr) { - case ast::constant_expr => + case ast::literal_expr => return true; case ast::access_identifier => return true;