diff --git a/shell.nix b/shell.nix index c0ff8bc..0d91a51 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ let - dev = (import ./src/core/importAtom.nix) { } ./src/dev.toml; + dev = (import ./src/core/importAtom.nix) { } ./src/dev.atom; in dev.shell diff --git a/src/core.toml b/src/core.atom similarity index 100% rename from src/core.toml rename to src/core.atom diff --git a/src/core/compose.nix b/src/core/compose.nix index d4c449b..6a1cef7 100644 --- a/src/core/compose.nix +++ b/src/core/compose.nix @@ -55,30 +55,31 @@ */ let l = builtins; - src = import ./mod.nix; + core = import ./mod.nix; in { + src, + root, config, extern ? { }, features ? [ ], # internal features of the composer function - stdFeatures ? src.stdToml.features.default or [ ], - coreFeatures ? src.coreToml.features.default, + stdFeatures ? core.stdToml.features.default or [ ], + coreFeatures ? core.coreToml.features.default, # enable testing code paths __internal__test ? false, __isStd__ ? false, }: -dir': let - par = src.prepDir dir'; + par = (root + "/${src}"); - std = src.importStd { + std = core.importStd { features = stdFeatures; inherit __internal__test; - } ../std.toml; + } ../std.atom; - coreFeatures' = src.features.resolve src.coreToml.features coreFeatures; - stdFeatures' = src.features.resolve src.stdToml.features stdFeatures; + coreFeatures' = core.features.resolve core.coreToml.features coreFeatures; + stdFeatures' = core.features.resolve core.stdToml.features stdFeatures; __atom = config // { features = config.features or { } // { @@ -90,7 +91,7 @@ let }; }; - msg = src.errors.debugMsg config; + msg = core.errors.debugMsg config; f = f: pre: dir: @@ -104,9 +105,9 @@ let scope = let - scope' = with src; { + scope' = with core; { inherit __atom; - mod = self'; + mod = modScope; builtins = std; import = errors.import; scopedImport = errors.import; @@ -119,7 +120,7 @@ let __getFlake = errors.import; }; - scope'' = src.set.inject scope' [ + scope'' = core.set.inject scope' [ preOpt { _if = !__isStd__ && l.elem "std" coreFeatures'; @@ -127,7 +128,7 @@ let } { _if = !__isStd__; - atom = atom'; + atom = atomScope; } { _if = __isStd__; @@ -141,7 +142,8 @@ let # a copy of the global scope, for testing if values exist # for our internal testing functions scope = scope''; - inherit src __isStd__ __internal__test; + inherit __isStd__ __internal__test; + src = core; }; } ]; @@ -153,59 +155,69 @@ let g = name: type: let - path = src.path.make dir name; - file = src.file.parse name; + path = core.path.make dir name; + file = core.file.parse name; member = Import (l.path { inherit path name; }); - module = src.path.make path "mod.nix"; + module = core.path.make path "mod.nix"; in if type == "directory" && l.pathExists module then - { ${name} = f ((src.lowerKeys self) // src.set.when preOpt) path; } + { ${name} = f ((core.lowerKeys mod) // core.set.when preOpt) path; } else if type == "regular" && file.ext or null == "nix" && name != "mod.nix" then { ${file.name} = let - trace = src.errors.modPath par dir; + trace = core.errors.modPath par dir; in - src.errors.context (msg "${trace}.${file.name}") member; + core.errors.context (msg "${trace}.${file.name}") member; } else null # Ignore other file types ; - self' = src.lowerKeys (l.removeAttrs self [ "mod" ] // { outPath = src.rmNixSrcs dir; }); + modScope = core.lowerKeys (l.removeAttrs mod [ "mod" ] // { outPath = core.rmNixSrcs dir; }); - self = + mod = let - path = src.path.make dir "mod.nix"; + path = core.path.make dir "mod.nix"; module = Import ( l.path { inherit path; name = baseNameOf path; } ); - trace = src.errors.modPath par dir; + trace = core.errors.modPath par dir; in - assert src.modIsValid module dir; - src.filterMap g contents // (src.errors.context (msg trace) module); + assert core.modIsValid module dir; + core.filterMap g contents // (core.errors.context (msg trace) module); in - if src.hasMod contents then - src.collectPublic self + if core.hasMod contents then + core.collectPublic mod else # Base case: no module { }; - atom' = l.removeAttrs (extern // atom // { inherit extern; }) [ - "atom" - (baseNameOf par) - ]; + atomScope = + l.removeAttrs + ( + extern + // atom + // { + inherit extern; + outPath = core.rmAtomSrc root config.atom.id src; + } + ) + [ + "atom" + (baseNameOf par) + ]; atom = let - fixed = src.fix f null par; + fixed = core.fix f null par; in - src.set.inject fixed [ - ({ _if = __isStd__; } // src.pureBuiltinsForStd fixed) + core.set.inject fixed [ + ({ _if = __isStd__; } // core.pureBuiltinsForStd fixed) { _if = __isStd__ && l.elem "lib" __atom.features.resolved.atom; inherit (extern) lib; @@ -221,7 +233,7 @@ in assert !__internal__test # older versions of Nix don't have the `warn` builtin - || src.errors.warn '' + || core.errors.warn '' in ${toString ./default.nix}: Internal testing functionality is enabled via the `__test` boolean. This should never be `true` except in internal test runs. diff --git a/src/core/importAtom.nix b/src/core/importAtom.nix index 16306ef..77f6582 100644 --- a/src/core/importAtom.nix +++ b/src/core/importAtom.nix @@ -44,7 +44,13 @@ let backend = config.backend or { }; nix = backend.nix or { }; - root = builtins.seq id (atom.path or id); + root = mod.prepDir (dirOf path); + src = builtins.seq id ( + let + file = mod.parse (baseNameOf path); + in + file.name + ); extern = let fetcher = nix.fetcher or "native"; # native doesn't exist yet @@ -88,7 +94,13 @@ let in mod.compose { - inherit extern __internal__test config; + inherit + extern + __internal__test + config + root + src + ; features = features'; coreFeatures = let @@ -102,4 +114,4 @@ mod.compose { mod.features.resolve mod.stdToml.features feat; __isStd__ = meta.__is_std__ or false; -} (dirOf path + "/${root}") +} diff --git a/src/core/mod.nix b/src/core/mod.nix index 36294fa..8e46fe8 100644 --- a/src/core/mod.nix +++ b/src/core/mod.nix @@ -15,12 +15,13 @@ let std = builtins; mod = scopedImport { inherit std mod; } ../std/string/mod.nix; } ../std/string/toLowerCase.nix; - stdToml = l.fromTOML (l.readFile ../std.toml); - coreToml = l.fromTOML (l.readFile ../core.toml); + stdToml = l.fromTOML (l.readFile ../std.atom); + coreToml = l.fromTOML (l.readFile ../core.atom); in rec { inherit fix + parse filterMap stdFilter stdToml @@ -71,6 +72,18 @@ rec { ); }; + rmAtomSrc = + path: name: src: + l.path { + inherit name path; + filter = + path: type: + let + file = parse path; + in + file.name != src; + }; + importStd = opts: importAtom { inherit (opts) __internal__test features; }; modIsValid = diff --git a/src/dev.toml b/src/dev.atom similarity index 100% rename from src/dev.toml rename to src/dev.atom diff --git a/src/std.toml b/src/std.atom similarity index 100% rename from src/std.toml rename to src/std.atom diff --git a/test/features/recursive-features-loop.toml b/test/features/recursive-features-loop.atom similarity index 100% rename from test/features/recursive-features-loop.toml rename to test/features/recursive-features-loop.atom diff --git a/test/features/recursive-features.toml b/test/features/recursive-features.atom similarity index 100% rename from test/features/recursive-features.toml rename to test/features/recursive-features.atom diff --git a/test/features/resolve.nix b/test/features/resolve.nix index 15b4d30..9e75d42 100644 --- a/test/features/resolve.nix +++ b/test/features/resolve.nix @@ -2,6 +2,6 @@ let f = import ../../src/core/importAtom.nix { __internal__test = true; }; in { - recursive-features = f ./recursive-features.toml; - recursive-features-loop = f ./recursive-features-loop.toml; + recursive-features = f ./recursive-features.atom; + recursive-features-loop = f ./recursive-features-loop.atom; } diff --git a/test/integrity/bld.toml b/test/integrity/bld.atom similarity index 100% rename from test/integrity/bld.toml rename to test/integrity/bld.atom diff --git a/test/integrity/bld.nix b/test/integrity/bld.nix index 966d201..7c2ff07 100644 --- a/test/integrity/bld.nix +++ b/test/integrity/bld.nix @@ -2,7 +2,7 @@ let f = import ../../src/core/importAtom.nix; atom = f { } ( # added to test implicit path conversion when path is a string - builtins.toPath ./bld.toml + builtins.toPath ./bld.atom ); in builtins.deepSeq atom atom diff --git a/test/pre.toml b/test/pre.atom similarity index 100% rename from test/pre.toml rename to test/pre.atom diff --git a/test/pre.nix b/test/pre.nix index 5ceafd6..17b8e70 100644 --- a/test/pre.nix +++ b/test/pre.nix @@ -1 +1 @@ -(import ../src/core/importAtom.nix { }) ./pre.toml +(import ../src/core/importAtom.nix { }) ./pre.atom diff --git a/test/purity/purity.nix b/test/purity/purity.nix index 821b3f1..f999f53 100644 --- a/test/purity/purity.nix +++ b/test/purity/purity.nix @@ -2,7 +2,7 @@ let f = import ../../src/core/importAtom.nix; atom = f { __internal__test = true; } ( # added to test implicit path conversion when path is a string - builtins.toPath ./test.toml + builtins.toPath ./test.atom ); in atom diff --git a/test/purity/test.toml b/test/purity/test.atom similarity index 100% rename from test/purity/test.toml rename to test/purity/test.atom diff --git a/test/std-import/default.toml b/test/std-import/default.atom similarity index 100% rename from test/std-import/default.toml rename to test/std-import/default.atom diff --git a/test/std-import/explicit.toml b/test/std-import/explicit.atom similarity index 100% rename from test/std-import/explicit.toml rename to test/std-import/explicit.atom diff --git a/test/std-import/import.nix b/test/std-import/import.nix index 92b83ae..22dd456 100644 --- a/test/std-import/import.nix +++ b/test/std-import/import.nix @@ -2,8 +2,8 @@ let f = import ../../src/core/importAtom.nix { __internal__test = true; }; in { - default = f ./default.toml; - noStd = f ./no-std.toml; - explicit = f ./explicit.toml; - withLib = f ./with-lib.toml; + default = f ./default.atom; + noStd = f ./no-std.atom; + explicit = f ./explicit.atom; + withLib = f ./with-lib.atom; } diff --git a/test/std-import/no-std.toml b/test/std-import/no-std.atom similarity index 100% rename from test/std-import/no-std.toml rename to test/std-import/no-std.atom diff --git a/test/std-import/with-lib.toml b/test/std-import/with-lib.atom similarity index 100% rename from test/std-import/with-lib.toml rename to test/std-import/with-lib.atom