From 5653912f0e0727ae07a4c1e4649aa81e33a51349 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 19 Jun 2022 13:34:16 -0400 Subject: [PATCH] Fix file loading from REPL --- src/ludus/interpreter.clj | 6 ++++-- src/ludus/loader.clj | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ludus/interpreter.clj b/src/ludus/interpreter.clj index 2a21108..573f4f4 100644 --- a/src/ludus/interpreter.clj +++ b/src/ludus/interpreter.clj @@ -336,11 +336,13 @@ (defn- interpret-import [ast ctx] (let [path (:path ast) - name (:name ast)] + name (:name ast) + file (ludus-resolve :file ctx) + from (if (= ::not-found file) :cwd file)] (if (contains? @ctx name) (throw (ex-info (str "Name " name " is alrady bound") {:ast ast})) (let [source (try - (loader/load-import path (ludus-resolve :file ctx)) + (loader/load-import path from) (catch Exception e (if (::loader/error (ex-data e)) (throw (ex-info (ex-message e) {:ast ast})) diff --git a/src/ludus/loader.clj b/src/ludus/loader.clj index 888682f..f8ba0a0 100644 --- a/src/ludus/loader.clj +++ b/src/ludus/loader.clj @@ -12,5 +12,5 @@ ([file from] (load-import (fs/path - (fs/parent (fs/canonicalize from)) + (if (= from :cwd) (fs/cwd) (fs/parent (fs/canonicalize from))) (fs/path file)))))