hare

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

types.ha (2233B)


      1 // SPDX-License-Identifier: GPL-3.0-only
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use crypto::sha256;
      5 use fs;
      6 use hare::ast;
      7 use hare::module;
      8 use io;
      9 use os::exec;
     10 use path;
     11 
     12 export type error = !(exec::error | fs::error | io::error | module::error | path::error);
     13 
     14 export type unknown_platform = !str;
     15 
     16 export type stage = enum {
     17 	TD = 0,
     18 	SSA,
     19 	S,
     20 	O,
     21 	BIN,
     22 };
     23 
     24 def NSTAGES = stage::BIN + 1;
     25 
     26 // file extensions corresponding to each [[stage]]
     27 export const stage_ext = ["td", "ssa", "s", "o", "bin"];
     28 
     29 // a command in the queue to be run
     30 export type task = struct {
     31 	// number of unfinished dependencies
     32 	ndeps: size,
     33 	// tasks to update (by decrementing ndeps) when this task is finished
     34 	rdeps: []*task,
     35 	kind: stage,
     36 	idx: size,
     37 };
     38 
     39 export fn free_task(t: *task) void = {
     40 	for (let rdep &.. t.rdeps) {
     41 		rdep.ndeps -= 1;
     42 	};
     43 	free(t.rdeps);
     44 	free(t);
     45 };
     46 
     47 export type output = enum {
     48 	DEFAULT,
     49 	SILENT,
     50 	VERBOSE,
     51 	VVERBOSE,
     52 };
     53 
     54 export type arch = struct {
     55 	name: str,
     56 	qbe_name: str,
     57 	as_cmd: str,
     58 	cc_cmd: str,
     59 	ld_cmd: str,
     60 };
     61 
     62 export type context = struct {
     63 	ctx: module::context,
     64 	arch: *arch,
     65 	platform: *platform,
     66 	goal: stage,
     67 	defines: []ast::decl_const,
     68 	libdirs: []str,
     69 	libs: []str,
     70 	jobs: size,
     71 	ns: ast::ident,
     72 	// index of the root module within the gathered module slice
     73 	top: size,
     74 	// output of harec -v
     75 	version: []u8,
     76 	// true if invoked as `hare test`
     77 	test: bool,
     78 	// true if building in release mode
     79 	release: bool,
     80 	// whether submodules of the root module should have tests enabled
     81 	submods: bool,
     82 	// if true, the main function won't be checked by harec
     83 	freestanding: bool,
     84 	// if true, we are linking with libc (using cc instead of ld)
     85 	libc: bool,
     86 
     87 	cmds: [NSTAGES]str,
     88 
     89 	mode: output,
     90 	completed: size,
     91 	total: size,
     92 
     93 	mods: []module::module,
     94 	hashes: [][NSTAGES]([sha256::SZ]u8 | void),
     95 };
     96 
     97 export fn ctx_finish(ctx: *context) void = {
     98 	free(ctx.ctx.tags);
     99 	for (let define .. ctx.defines) {
    100 		ast::ident_free(define.ident);
    101 		ast::type_finish(define._type);
    102 		free(define._type);
    103 		ast::expr_finish(define.init);
    104 		free(define.init);
    105 	};
    106 	free(ctx.defines);
    107 	free(ctx.libdirs);
    108 	free(ctx.libs);
    109 	ast::ident_free(ctx.ns);
    110 	free(ctx.version);
    111 	module::free_slice(ctx.mods);
    112 	free(ctx.hashes);
    113 };