hare

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

expr.ha (1403B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use hare::ast;
      5 use hare::lex;
      6 use hare::types;
      7 
      8 // A type-checked and validated Hare expression.
      9 export type expr = struct {
     10 	start: lex::location,
     11 	end: lex::location,
     12 	result: const *types::_type,
     13 	terminates: bool,
     14 	expr: (access | bindings | compound | constant | _return),
     15 };
     16 
     17 // An access expression.
     18 export type access = (access_object | access_field | access_index | access_tuple);
     19 
     20 // An access expression for an object.
     21 export type access_object = *object;
     22 
     23 // An access expression for a struct field.
     24 export type access_field = struct {
     25 	object: *expr,
     26 	field: const *types::struct_field,
     27 };
     28 
     29 // An access expression for a slice or array index.
     30 export type access_index = struct {
     31 	object: *expr,
     32 	index: *expr,
     33 };
     34 
     35 // An access expression for a tuple value.
     36 export type access_tuple = struct {
     37 	object: *expr,
     38 	value: const *types::tuple_value,
     39 };
     40 
     41 // A single variable biding.
     42 //
     43 // 	foo: int = bar
     44 export type binding = struct {
     45 	object: *object,
     46 	init: *expr,
     47 };
     48 
     49 // A list of variable bindings.
     50 export type bindings = []binding;
     51 
     52 // A compound expression, i.e. { ... }
     53 export type compound = []*expr;
     54 
     55 // The value of a constant expression.
     56 export type constant = (...ast::value | i64 | u64 | f64); // TODO: composite types
     57 
     58 // A return expression, i.e. return <value>
     59 export type _return = nullable *expr;