From 3439602c2b356eaef3359b6496a0237f1af55e33 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 26 Oct 2017 21:41:41 -0400 Subject: - Added a new piece of compiler state, just for storing the current-module. --- luxc/src/lux/analyser/module.clj | 3 ++- luxc/src/lux/base.clj | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'luxc/src') diff --git a/luxc/src/lux/analyser/module.clj b/luxc/src/lux/analyser/module.clj index 8c5a2d286..c8a263030 100644 --- a/luxc/src/lux/analyser/module.clj +++ b/luxc/src/lux/analyser/module.clj @@ -279,7 +279,8 @@ (fn [state] (return* (->> state (&/update$ &/$modules #(&/|put name (new-module hash) %)) - (&/set$ &/$scopes (&/|list (&/env name &/$Nil)))) + (&/set$ &/$scopes (&/|list (&/env name &/$Nil))) + (&/set$ &/$current-module (&/$Some name))) nil))) (do-template [ ] diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj index 3bf0eaf08..910bdfadf 100644 --- a/luxc/src/lux/base.clj +++ b/luxc/src/lux/base.clj @@ -151,6 +151,7 @@ ["info" "source" "cursor" + "current-module" "modules" "scopes" "type-context" @@ -819,6 +820,8 @@ $Nil ;; "lux;cursor" (T ["" -1 -1]) + ;; "current-module" + $None ;; "lux;modules" (|table) ;; "lux;scopes" @@ -910,13 +913,13 @@ (def get-module-name (fn [state] - (|case (|reverse (get$ $scopes state)) - ($Nil) + (|case (get$ $current-module state) + ($None) ((fail-with-loc "[Analyser Error] Cannot get the module-name without a module.") state) - ($Cons ?global _) - (return* state (|head (get$ $name ?global)))))) + ($Some module-name) + (return* state module-name)))) (defn find-module [name] "(-> Text (Lux (Module Compiler)))" -- cgit v1.2.3