hare

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

import.ha (1156B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use hare::lex;
      5 use strings;
      6 
      7 // An imported module.
      8 //
      9 // 	use foo;
     10 // 	use foo = bar;
     11 // 	use foo::{bar, baz};
     12 // 	use foo::*;
     13 export type import = struct {
     14 	start: lex::location,
     15 	end: lex::location,
     16 	ident: ident,
     17 	bindings: (void | import_alias | import_members | import_wildcard),
     18 };
     19 
     20 // An import alias.
     21 //
     22 // 	use foo = bar;
     23 export type import_alias = str;
     24 
     25 // An import members list.
     26 //
     27 // 	use foo::{bar, baz};
     28 export type import_members = []str;
     29 
     30 // An import wildcard.
     31 //
     32 // 	use foo::*;
     33 export type import_wildcard = void;
     34 
     35 // Frees resources associated with an [[import]].
     36 export fn import_finish(import: import) void = {
     37 	ident_free(import.ident);
     38 	match (import.bindings) {
     39 	case let alias: import_alias =>
     40 		free(alias);
     41 	case let objects: import_members =>
     42 		strings::freeall(objects);
     43 	case => void;
     44 	};
     45 };
     46 
     47 // Frees resources associated with each [[import]] in a slice, and then
     48 // frees the slice itself.
     49 export fn imports_finish(imports: []import) void = {
     50 	for (let i = 0z; i < len(imports); i += 1) {
     51 		import_finish(imports[i]);
     52 	};
     53 	free(imports);
     54 };