hare

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

commit b9767b5e69245766f02618402acf37c0eb2f9ac8
parent 6a45cd8059d00f5eb499129b2814fb79db6a3fca
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  7 Mar 2021 10:38:41 -0500

hare::module: identify input file type

Diffstat:
Mhare/module/scan.ha | 14++++++++++++++
Mhare/module/types.ha | 6++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -18,10 +18,15 @@ export fn scan(ctx: *context, path: path::path) (version | error) = { let deps: []ast::ident = []; let iter = match (fs::iter(ctx.fs, path)) { fs::wrongtype => { + let ft = match (type_for_ext(path)) { + void => return module_not_found, + ft: filetype => ft, + }; let st = fs::stat(ctx.fs, path)?; let in = input { path = path, stat = st, + ft = ft, hash = scan_file(ctx, path, &deps)?, ... }; @@ -47,6 +52,7 @@ export fn scan(ctx: *context, path: path::path) (version | error) = { let in = input { path = p, stat = st, + ft = type_for_ext(ent.name) as filetype, hash = scan_file(ctx, p, &deps)?, ... }; @@ -96,6 +102,14 @@ fn eligible(ctx: *context, name: path::path) bool = { return eligible; }; +fn type_for_ext(name: path::path) (filetype | void) = { + const ext = path::extension(name); + return + if (ext == ".ha") filetype::HARE + else if (ext == ".s") filetype::ASSEMBLY + else void; +}; + fn scan_file( ctx: *context, path: path::path, diff --git a/hare/module/types.ha b/hare/module/types.ha @@ -30,10 +30,16 @@ export type version = struct { inputs: []input, }; +export type filetype = enum { + HARE, + ASSEMBLY, +}; + // An input to a module, generally a source file. export type input = struct { hash: []u8, path: path::path, + ft: filetype, stat: fs::filestat, };