hare

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

unit.ha (552B)


      1 // License: MPL-2.0
      2 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      3 // (c) 2021 Eyal Sawady <ecs@d2evs.net>
      4 use io;
      5 use fmt;
      6 use hare::ast;
      7 
      8 // Unparses a [[hare::ast::subunit]].
      9 export fn subunit(out: io::handle, s: ast::subunit) (size | io::error) = {
     10 	let n = 0z;
     11 	for (let i = 0z; i < len(s.imports); i += 1) {
     12 		n += import(out, s.imports[i])?;
     13 		n += fmt::fprintln(out)?;
     14 	};
     15 	for (let i = 0z; i < len(s.decls); i += 1) {
     16 		n += decl(out, s.decls[i])?;
     17 		if (i < len(s.decls) - 1) n += fmt::fprintln(out)?;
     18 		n += fmt::fprintln(out)?;
     19 	};
     20 	return n;
     21 };