commit 0ac9fdde69a7648cd61a1d9f92194bdc6df1b7c5
parent 6f2b7251db176241642f8b4dedc3c779a7c383bc
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 22 Jan 2021 09:32:36 -0500
Add module loading skeleton
Diffstat:
5 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
@@ -12,6 +12,7 @@ harec() {
src/identifier.c \
src/lex.c \
src/main.c \
+ src/mod.c \
src/parse.c \
src/qbe.c \
src/qinstr.c \
diff --git a/docs/env.txt b/docs/env.txt
@@ -0,0 +1,22 @@
+harec uses environment variables to seek out modules to reference in the current
+unit. The user is responsible for building dependencies first and ensuring that
+they appear in the module cache.
+
+The following environment variables are used:
+
+HARECACHE
+ Path to the module cache, defaults to ~/.cache/hare. For each imported
+ module, harec will construct the path $HARECACHE/$modname/$modversion.td
+ to look up the module API.
+
+HARE.$MOD.VERSION
+ Sets the module version to reference for given module $MOD. For example,
+ to specify the version of the 'io' module to link to, set
+ HARE.io.VERSION=da39a3ee5e6b4b0d3255bfef95601890afd80709. Replace
+ namespace delimiters '::' with '.' to form the variable name. In this
+ example, harec will read
+ $HARECACHE/io/da39a3ee5e6b4b0d3255bfef95601890afd80709.td to obtain the
+ type definitions for the 'io' module.
+
+ If this variable is not found, the module's name is used as the version,
+ with the namespace delimiters '::' replaced with '.'.
diff --git a/include/mod.h b/include/mod.h
@@ -0,0 +1,9 @@
+#ifndef HARE_MOD_H
+#define HARE_MOD_H
+#include "identifier.h"
+#include "scope.h"
+#include "type_store.h"
+
+struct scope *module_resolve(struct identifier *ident, struct type_store *store);
+
+#endif
diff --git a/src/check.c b/src/check.c
@@ -7,6 +7,7 @@
#include "check.h"
#include "eval.h"
#include "expr.h"
+#include "mod.h"
#include "scope.h"
#include "trace.h"
#include "type_store.h"
@@ -1551,7 +1552,23 @@ check(struct context *ctx, const struct ast_unit *aunit, struct unit *unit)
su; su = su->next) {
scope_push(&ctx->scope, TR_SCAN);
- assert(!su->imports); // TODO
+ for (struct ast_imports *imports = su->imports;
+ imports; imports = imports->next) {
+ struct scope *mod;
+ switch (imports->mode) {
+ case AST_IMPORT_IDENTIFIER:
+ mod = module_resolve(
+ &imports->ident, &ctx->store);
+ break;
+ case AST_IMPORT_ALIAS:
+ assert(0); // TODO
+ case AST_IMPORT_MEMBERS:
+ assert(0); // TODO
+ }
+
+ (void)mod; // TODO: Populate subunit scope
+ }
+
scan_declarations(ctx, &su->decls);
*next = xcalloc(1, sizeof(struct scopes));
diff --git a/src/mod.c b/src/mod.c
@@ -0,0 +1,12 @@
+#include <assert.h>
+#include "check.h"
+#include "identifier.h"
+#include "mod.h"
+#include "scope.h"
+#include "type_store.h"
+
+struct scope *
+module_resolve(struct identifier *ident, struct type_store *store)
+{
+ assert(0); // TODO
+}