From a67e45ecf7d7d8fa52c7cef7eaa4f6ab360599e9 Mon Sep 17 00:00:00 2001 From: haxscramper Date: Wed, 19 Jan 2022 12:23:05 +0300 Subject: [PATCH] Sort compiler files into manageable dir structure Organized compiler source code into smaller sections - if we plan to untangle implementation parts from each other, we can start small, with simple file organization and later continue to remove unnecessary cross-directory imports and so on. --- compiler/{ => ast}/ast.nim | 27 ++++-- compiler/{ => ast}/ast_types.nim | 2 +- compiler/{ => ast}/astalgo.nim | 22 ++++- compiler/{ => ast}/astmsgs.nim | 9 +- compiler/{ => ast}/enumtostr.nim | 11 ++- compiler/{ => ast}/errorhandling.nim | 16 +++- compiler/{ => ast}/errorreporting.nim | 4 +- compiler/{ => ast}/filter_tmpl.nim | 19 ++++- compiler/{ => ast}/filters.nim | 19 ++++- compiler/{ => ast}/idents.nim | 0 compiler/{ => ast}/layouter.nim | 20 ++++- compiler/{ => ast}/lexer.nim | 23 ++++- compiler/{ => ast}/lineinfos.nim | 4 +- compiler/{ => ast}/linter.nim | 16 +++- compiler/{ => ast}/llstream.nim | 4 +- compiler/{ => ast}/ndi.nim | 13 ++- compiler/{ => ast}/nimlexbase.nim | 0 compiler/{ => ast}/nimsets.nim | 8 +- compiler/{ => ast}/parser.nim | 22 ++++- compiler/{ => ast}/renderer.nim | 16 +++- compiler/{ => ast}/renderverbatim.nim | 8 +- compiler/{ => ast}/reports.nim | 9 +- compiler/{ => ast}/syntaxes.nim | 22 ++++- compiler/{ => ast}/trees.nim | 0 compiler/{ => ast}/treetab.nim | 0 compiler/{ => ast}/types.nim | 29 ++++++- compiler/{ => ast}/typesrenderer.nim | 0 compiler/{ => ast}/wordrecg.nim | 0 compiler/{ => backend}/ccgcalls.nim | 2 +- compiler/{ => backend}/ccgexprs.nim | 2 +- compiler/{ => backend}/ccgliterals.nim | 0 compiler/{ => backend}/ccgmerge_unused.nim | 0 compiler/{ => backend}/ccgreset.nim | 0 compiler/{ => backend}/ccgstmts.nim | 0 compiler/{ => backend}/ccgthreadvars.nim | 0 compiler/{ => backend}/ccgtrav.nim | 0 compiler/{ => backend}/ccgtypes.nim | 2 +- compiler/{ => backend}/ccgutils.nim | 23 ++++- compiler/{ => backend}/cgen.nim | 68 +++++++++++++-- compiler/{ => backend}/cgendata.nim | 23 ++++- compiler/{ => backend}/cgmeth.nim | 23 ++++- compiler/{ => backend}/extccomp.nim | 12 ++- compiler/{ => backend}/jsgen.nim | 55 ++++++++++-- compiler/{ => backend}/jstypes.nim | 0 compiler/{ => backend}/tccgen.nim | 0 compiler/{ => front}/cli_reporter.nim | 55 +++++++----- compiler/{ => front}/cmdlinehelper.nim | 27 +++++- compiler/{ => front}/commands.nim | 39 +++++++-- compiler/{ => front}/condsyms.nim | 6 +- compiler/{ => front}/main.nim | 48 +++++++++-- compiler/{ => front}/msgs.nim | 8 +- compiler/{ => front}/nimconf.nim | 24 +++++- compiler/{ => front}/options.nim | 12 +-- compiler/{ => front}/scriptconfig.nim | 40 +++++++-- compiler/ic/cbackend.nim | 26 +++++- compiler/ic/dce.nim | 15 +++- compiler/ic/ic.nim | 31 +++++-- compiler/ic/integrity.nim | 4 +- compiler/ic/navigator.nim | 20 ++++- compiler/ic/packed_ast.nim | 6 +- compiler/ic/replayer.nim | 23 ++++- compiler/{ => modules}/depends.nim | 20 ++++- compiler/{ => modules}/importer.nim | 29 ++++++- compiler/{ => modules}/magicsys.nim | 22 ++++- compiler/{ => modules}/modulegraphs.nim | 31 ++++++- compiler/{ => modules}/modulepaths.nim | 21 ++++- compiler/{ => modules}/modules.nim | 34 +++++++- compiler/{ => modules}/nimblecmd.nim | 23 ++++- compiler/{ => modules}/nimpaths.nim | 2 +- compiler/{ => modules}/packagehandling.nim | 0 compiler/nim.cfg | 2 + compiler/nim.nim | 34 ++++++-- compiler/nimfix/nimfix.nim | 36 ++++++-- compiler/nimfix/prettybase.nim | 19 ++++- compiler/plugins/active.nim | 12 ++- compiler/plugins/itersgen.nim | 18 +++- compiler/plugins/locals.nim | 16 +++- compiler/{ => sem}/aliases.nim | 11 ++- compiler/{ => sem}/closureiters.nim | 24 +++++- compiler/{ => sem}/concepts.nim | 24 +++++- compiler/{ => sem}/debuginfo.nim | 0 compiler/{ => sem}/dfa.nim | 12 ++- compiler/{ => sem}/evaltempl.nim | 14 +++- compiler/{ => sem}/guards.nim | 28 ++++++- compiler/{ => sem}/hlo.nim | 0 compiler/{ => sem}/injectdestructors.nim | 40 +++++++-- compiler/{ => sem}/isolation_check.nim | 9 +- compiler/{ => sem}/lambdalifting.nim | 30 ++++++- compiler/{ => sem}/liftdestructors.nim | 36 ++++++-- compiler/{ => sem}/liftlocals.nim | 21 ++++- compiler/{ => sem}/lookups.nim | 35 ++++++-- compiler/{ => sem}/lowerings.nim | 19 ++++- compiler/{ => sem}/macrocacheimpl.nim | 10 ++- compiler/{ => sem}/nilcheck.nim | 35 +++++++- compiler/{ => sem}/nilcheck_enums.nim | 0 compiler/{ => sem}/optimizer.nim | 4 +- compiler/{ => sem}/parampatterns.nim | 18 +++- compiler/{ => sem}/passaux.nim | 17 +++- compiler/{ => sem}/passes.nim | 24 +++++- compiler/{ => sem}/patterns.nim | 12 ++- compiler/{ => sem}/pragmas.nim | 48 +++++++++-- compiler/{ => sem}/procfind.nim | 16 +++- compiler/{ => sem}/reorder.nim | 24 +++++- compiler/{ => sem}/rodutils.nim | 0 compiler/{ => sem}/sem.nim | 83 ++++++++++++++++--- compiler/{ => sem}/semcall.nim | 0 compiler/{ => sem}/semdata.nim | 40 +++++++-- compiler/{ => sem}/semexprs.nim | 0 compiler/{ => sem}/semfields.nim | 0 compiler/{ => sem}/semfold.nim | 33 +++++++- compiler/{ => sem}/semgnrc.nim | 0 compiler/{ => sem}/seminst.nim | 0 compiler/{ => sem}/semmacrosanity.nim | 15 +++- compiler/{ => sem}/semmagic.nim | 0 compiler/{ => sem}/semobjconstr.nim | 0 compiler/{ => sem}/semparallel.nim | 31 +++++-- compiler/{ => sem}/sempass2.nim | 41 ++++++++- compiler/{ => sem}/semstmts.nim | 0 compiler/{ => sem}/semtempl.nim | 0 compiler/{ => sem}/semtypes.nim | 0 compiler/{ => sem}/semtypinst.nim | 25 +++++- compiler/{ => sem}/sighashes.nim | 20 ++++- compiler/{ => sem}/sigmatch.nim | 48 +++++++++-- .../{ => sem}/sinkparameter_inference.nim | 0 compiler/{ => sem}/sizealignoffsetimpl.nim | 0 compiler/{ => sem}/sourcemap.nim | 20 +++-- compiler/{ => sem}/spawn.nim | 25 +++++- compiler/{ => sem}/transf.nim | 52 ++++++++---- compiler/{ => sem}/typeallowed.nim | 15 +++- compiler/{ => sem}/varpartitions.nim | 23 ++++- compiler/{ => tools}/docgen.nim | 52 ++++++++++-- compiler/{ => tools}/docgen2.nim | 23 ++++- compiler/{ => tools}/suggest.nim | 19 ++++- compiler/{ => utils}/bitsets.nim | 0 compiler/{ => utils}/btrees.nim | 0 compiler/{ => utils}/debugutils.nim | 9 +- compiler/{ => utils}/int128.nim | 0 compiler/{ => utils}/nodejs.nim | 0 compiler/{ => utils}/nversion.nim | 0 compiler/{ => utils}/pathutils.nim | 0 compiler/{ => utils}/platform.nim | 0 compiler/{ => utils}/pluginsupport.nim | 10 ++- compiler/{ => utils}/prefixmatches.nim | 0 compiler/{ => utils}/ropes.nim | 0 compiler/{ => utils}/saturate.nim | 0 compiler/{ => utils}/strutils2.nim | 0 compiler/{ => vm}/evalffi.nim | 0 compiler/{ => vm}/gorgeimpl.nim | 19 ++++- compiler/{ => vm}/nimeval.nim | 43 ++++++++-- compiler/{ => vm}/vm.nim | 63 +++++++++++--- compiler/{ => vm}/vm_enums.nim | 0 compiler/{ => vm}/vmconv.nim | 2 +- compiler/{ => vm}/vmdef.nim | 18 +++- compiler/{ => vm}/vmdeps.nim | 20 ++++- compiler/{ => vm}/vmgen.nim | 40 +++++++-- compiler/{ => vm}/vmhooks.nim | 2 +- compiler/{ => vm}/vmops.nim | 0 compiler/{ => vm}/vmprofiler.nim | 19 ++++- doc/niminst.rst | 1 - nimpretty/nimpretty.nim | 17 +++- nimpretty/nimpretty.nim.cfg | 1 + nimsuggest/nimsuggest.nim | 35 +++++--- nimsuggest/nimsuggest.nim.cfg | 2 +- testament/testament.nim | 10 +-- testament/testament.nim.cfg | 2 +- tests/compiler/nim.cfg | 3 +- tests/compiler/t12684.nim | 2 +- tests/compiler/tbrees.nim | 4 +- tests/compiler/tint128.nim | 2 +- tests/compiler/tnimblecmd.nim | 2 +- tests/compiler/tpathutils.nim | 4 +- tests/compiler/tprefixmatches.nim | 4 +- tests/compilerapi/tcompilerapi.nim | 22 ++++- tests/compilerapi/tcompilerapi.nim.cfg | 1 + .../confread/treport_filtering.nim | 33 +++++--- tests/compilerunits/nim.cfg | 2 +- tests/misc/trunner.nim | 2 +- tests/stdlib/tstrutils2.nim | 2 +- tools/grammar_nanny.nim | 17 ++-- tools/koch/kochdocs.nim | 3 +- tools/nim.cfg | 1 + 181 files changed, 2274 insertions(+), 455 deletions(-) rename compiler/{ => ast}/ast.nim (99%) rename compiler/{ => ast}/ast_types.nim (99%) rename compiler/{ => ast}/astalgo.nim (99%) rename compiler/{ => ast}/astmsgs.nim (96%) rename compiler/{ => ast}/enumtostr.nim (97%) rename compiler/{ => ast}/errorhandling.nim (98%) rename compiler/{ => ast}/errorreporting.nim (94%) rename compiler/{ => ast}/filter_tmpl.nim (97%) rename compiler/{ => ast}/filters.nim (94%) rename compiler/{ => ast}/idents.nim (100%) rename compiler/{ => ast}/layouter.nim (99%) rename compiler/{ => ast}/lexer.nim (99%) rename compiler/{ => ast}/lineinfos.nim (99%) rename compiler/{ => ast}/linter.nim (97%) rename compiler/{ => ast}/llstream.nim (99%) rename compiler/{ => ast}/ndi.nim (92%) rename compiler/{ => ast}/nimlexbase.nim (100%) rename compiler/{ => ast}/nimsets.nim (97%) rename compiler/{ => ast}/parser.nim (99%) rename compiler/{ => ast}/renderer.nim (99%) rename compiler/{ => ast}/renderverbatim.nim (97%) rename compiler/{ => ast}/reports.nim (99%) rename compiler/{ => ast}/syntaxes.nim (95%) rename compiler/{ => ast}/trees.nim (100%) rename compiler/{ => ast}/treetab.nim (100%) rename compiler/{ => ast}/types.nim (99%) rename compiler/{ => ast}/typesrenderer.nim (100%) rename compiler/{ => ast}/wordrecg.nim (100%) rename compiler/{ => backend}/ccgcalls.nim (99%) rename compiler/{ => backend}/ccgexprs.nim (99%) rename compiler/{ => backend}/ccgliterals.nim (100%) rename compiler/{ => backend}/ccgmerge_unused.nim (100%) rename compiler/{ => backend}/ccgreset.nim (100%) rename compiler/{ => backend}/ccgstmts.nim (100%) rename compiler/{ => backend}/ccgthreadvars.nim (100%) rename compiler/{ => backend}/ccgtrav.nim (100%) rename compiler/{ => backend}/ccgtypes.nim (99%) rename compiler/{ => backend}/ccgutils.nim (95%) rename compiler/{ => backend}/cgen.nim (99%) rename compiler/{ => backend}/cgendata.nim (98%) rename compiler/{ => backend}/cgmeth.nim (98%) rename compiler/{ => backend}/extccomp.nim (99%) rename compiler/{ => backend}/jsgen.nim (99%) rename compiler/{ => backend}/jstypes.nim (100%) rename compiler/{ => backend}/tccgen.nim (100%) rename compiler/{ => front}/cli_reporter.nim (99%) rename compiler/{ => front}/cmdlinehelper.nim (92%) rename compiler/{ => front}/commands.nim (99%) rename compiler/{ => front}/condsyms.nim (98%) rename compiler/{ => front}/main.nim (94%) rename compiler/{ => front}/msgs.nim (99%) rename compiler/{ => front}/nimconf.nim (98%) rename compiler/{ => front}/options.nim (99%) rename compiler/{ => front}/scriptconfig.nim (95%) rename compiler/{ => modules}/depends.nim (91%) rename compiler/{ => modules}/importer.nim (97%) rename compiler/{ => modules}/magicsys.nim (96%) rename compiler/{ => modules}/modulegraphs.nim (98%) rename compiler/{ => modules}/modulepaths.nim (97%) rename compiler/{ => modules}/modules.nim (96%) rename compiler/{ => modules}/nimblecmd.nim (96%) rename compiler/{ => modules}/nimpaths.nim (98%) rename compiler/{ => modules}/packagehandling.nim (100%) rename compiler/{ => sem}/aliases.nim (98%) rename compiler/{ => sem}/closureiters.nim (99%) rename compiler/{ => sem}/concepts.nim (98%) rename compiler/{ => sem}/debuginfo.nim (100%) rename compiler/{ => sem}/dfa.nim (99%) rename compiler/{ => sem}/evaltempl.nim (98%) rename compiler/{ => sem}/guards.nim (99%) rename compiler/{ => sem}/hlo.nim (100%) rename compiler/{ => sem}/injectdestructors.nim (99%) rename compiler/{ => sem}/isolation_check.nim (98%) rename compiler/{ => sem}/lambdalifting.nim (99%) rename compiler/{ => sem}/liftdestructors.nim (99%) rename compiler/{ => sem}/liftlocals.nim (90%) rename compiler/{ => sem}/lookups.nim (99%) rename compiler/{ => sem}/lowerings.nim (98%) rename compiler/{ => sem}/macrocacheimpl.nim (95%) rename compiler/{ => sem}/nilcheck.nim (99%) rename compiler/{ => sem}/nilcheck_enums.nim (100%) rename compiler/{ => sem}/optimizer.nim (98%) rename compiler/{ => sem}/parampatterns.nim (98%) rename compiler/{ => sem}/passaux.nim (86%) rename compiler/{ => sem}/passes.nim (97%) rename compiler/{ => sem}/patterns.nim (98%) rename compiler/{ => sem}/pragmas.nim (99%) rename compiler/{ => sem}/procfind.nim (95%) rename compiler/{ => sem}/reorder.nim (98%) rename compiler/{ => sem}/rodutils.nim (100%) rename compiler/{ => sem}/sem.nim (96%) rename compiler/{ => sem}/semcall.nim (100%) rename compiler/{ => sem}/semdata.nim (98%) rename compiler/{ => sem}/semexprs.nim (100%) rename compiler/{ => sem}/semfields.nim (100%) rename compiler/{ => sem}/semfold.nim (99%) rename compiler/{ => sem}/semgnrc.nim (100%) rename compiler/{ => sem}/seminst.nim (100%) rename compiler/{ => sem}/semmacrosanity.nim (97%) rename compiler/{ => sem}/semmagic.nim (100%) rename compiler/{ => sem}/semobjconstr.nim (100%) rename compiler/{ => sem}/semparallel.nim (98%) rename compiler/{ => sem}/sempass2.nim (99%) rename compiler/{ => sem}/semstmts.nim (100%) rename compiler/{ => sem}/semtempl.nim (100%) rename compiler/{ => sem}/semtypes.nim (100%) rename compiler/{ => sem}/semtypinst.nim (99%) rename compiler/{ => sem}/sighashes.nim (98%) rename compiler/{ => sem}/sigmatch.nim (99%) rename compiler/{ => sem}/sinkparameter_inference.nim (100%) rename compiler/{ => sem}/sizealignoffsetimpl.nim (100%) rename compiler/{ => sem}/sourcemap.nim (98%) rename compiler/{ => sem}/spawn.nim (98%) rename compiler/{ => sem}/transf.nim (98%) rename compiler/{ => sem}/typeallowed.nim (98%) rename compiler/{ => sem}/varpartitions.nim (99%) rename compiler/{ => tools}/docgen.nim (99%) rename compiler/{ => tools}/docgen2.nim (92%) rename compiler/{ => tools}/suggest.nim (99%) rename compiler/{ => utils}/bitsets.nim (100%) rename compiler/{ => utils}/btrees.nim (100%) rename compiler/{ => utils}/debugutils.nim (99%) rename compiler/{ => utils}/int128.nim (100%) rename compiler/{ => utils}/nodejs.nim (100%) rename compiler/{ => utils}/nversion.nim (100%) rename compiler/{ => utils}/pathutils.nim (100%) rename compiler/{ => utils}/platform.nim (100%) rename compiler/{ => utils}/pluginsupport.nim (93%) rename compiler/{ => utils}/prefixmatches.nim (100%) rename compiler/{ => utils}/ropes.nim (100%) rename compiler/{ => utils}/saturate.nim (100%) rename compiler/{ => utils}/strutils2.nim (100%) rename compiler/{ => vm}/evalffi.nim (100%) rename compiler/{ => vm}/gorgeimpl.nim (91%) rename compiler/{ => vm}/nimeval.nim (94%) rename compiler/{ => vm}/vm.nim (99%) rename compiler/{ => vm}/vm_enums.nim (100%) rename compiler/{ => vm}/vmconv.nim (98%) rename compiler/{ => vm}/vmdef.nim (97%) rename compiler/{ => vm}/vmdeps.nim (98%) rename compiler/{ => vm}/vmgen.nim (99%) rename compiler/{ => vm}/vmhooks.nim (98%) rename compiler/{ => vm}/vmops.nim (100%) rename compiler/{ => vm}/vmprofiler.nim (90%) create mode 100644 tests/compilerapi/tcompilerapi.nim.cfg create mode 100644 tools/nim.cfg diff --git a/compiler/ast.nim b/compiler/ast/ast.nim similarity index 99% rename from compiler/ast.nim rename to compiler/ast/ast.nim index d4b6a601431..f7b723a3647 100644 --- a/compiler/ast.nim +++ b/compiler/ast/ast.nim @@ -10,14 +10,25 @@ ## abstract syntax tree + symbol table import - lineinfos, hashes, options, ropes, idents, int128, tables - -from strutils import toLowerAscii - -import ./ast_types -export ast_types - -export int128 + ast/[ + lineinfos, # Positional information + idents, # Ast identifiers + ast_types # Main ast type definitions + ], + front/[ + options + ], + utils/[ + ropes, + int128 # Values for integer nodes + ], + std/[ + hashes, + strutils, + tables # For symbol table mapping + ] + +export ast_types, int128 template nodeId(n: PNode): int = cast[int](n) diff --git a/compiler/ast_types.nim b/compiler/ast/ast_types.nim similarity index 99% rename from compiler/ast_types.nim rename to compiler/ast/ast_types.nim index 24d61a21bbb..79f0ad97800 100644 --- a/compiler/ast_types.nim +++ b/compiler/ast/ast_types.nim @@ -1,4 +1,4 @@ -import ropes +import utils/ropes import std/[hashes] const diff --git a/compiler/astalgo.nim b/compiler/ast/astalgo.nim similarity index 99% rename from compiler/astalgo.nim rename to compiler/ast/astalgo.nim index dcd0d2d861a..97bf905af76 100644 --- a/compiler/astalgo.nim +++ b/compiler/ast/astalgo.nim @@ -12,8 +12,26 @@ # the data structures here are used in various places of the compiler. import - ast, hashes, intsets, strutils, options, lineinfos, ropes, idents, rodutils, - msgs + ast/[ + ast, + idents, + lineinfos, + ], + std/[ + hashes, + intsets, + strutils, + ], + utils/[ + ropes, + ], + sem/[ + rodutils, + ], + front/[ + options, + msgs + ] proc hashNode*(p: RootRef): Hash proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope diff --git a/compiler/astmsgs.nim b/compiler/ast/astmsgs.nim similarity index 96% rename from compiler/astmsgs.nim rename to compiler/ast/astmsgs.nim index 11a8d757f2e..1f5739d774b 100644 --- a/compiler/astmsgs.nim +++ b/compiler/ast/astmsgs.nim @@ -1,6 +1,13 @@ # this module avoids ast depending on msgs or vice versa import std/strutils -import options, ast, msgs +import + ast/[ + ast, + ], + front/[ + options, + msgs + ] proc typSym*(t: PType): PSym = result = t.sym diff --git a/compiler/enumtostr.nim b/compiler/ast/enumtostr.nim similarity index 97% rename from compiler/enumtostr.nim rename to compiler/ast/enumtostr.nim index 9bfa7001a9d..dbed1c78dcb 100644 --- a/compiler/enumtostr.nim +++ b/compiler/ast/enumtostr.nim @@ -1,5 +1,14 @@ +import + ast/[ + ast, + idents, + lineinfos + ], + modules/[ + modulegraphs, + magicsys + ] -import ast, idents, lineinfos, modulegraphs, magicsys proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGenerator): PSym = result = newSym(skProc, getIdent(g.cache, "$"), nextSymId idgen, t.owner, info) diff --git a/compiler/errorhandling.nim b/compiler/ast/errorhandling.nim similarity index 98% rename from compiler/errorhandling.nim rename to compiler/ast/errorhandling.nim index 7ab63dc249d..e283c53086f 100644 --- a/compiler/errorhandling.nim +++ b/compiler/ast/errorhandling.nim @@ -31,9 +31,19 @@ ## * rework internals to store actual error information in a lookup data ## structure on the side instead of directly in the node -import ast, msgs, options -from lineinfos import unknownLineInfo -import reports, debugutils +import + ast/[ + ast, + reports, + lineinfos + ], + utils/[ + debugutils, + ], + front/[ + msgs, + options + ] proc errorSubNode*(n: PNode): PNode = ## find the first error node, or nil, under `n` using a depth first traversal diff --git a/compiler/errorreporting.nim b/compiler/ast/errorreporting.nim similarity index 94% rename from compiler/errorreporting.nim rename to compiler/ast/errorreporting.nim index 0a62b219312..692f1bf3d76 100644 --- a/compiler/errorreporting.nim +++ b/compiler/ast/errorreporting.nim @@ -14,8 +14,8 @@ ## determines which error handling strategy to use doNothing, raise, etc. import ast, errorhandling, renderer, reports -from options import ConfigRef -from msgs import TErrorHandling +from front/options import ConfigRef +from front/msgs import TErrorHandling export compilerInstInfo, walkErrors, errorKind # export because keeping the declaration in `errorhandling` acts as a reminder diff --git a/compiler/filter_tmpl.nim b/compiler/ast/filter_tmpl.nim similarity index 97% rename from compiler/filter_tmpl.nim rename to compiler/ast/filter_tmpl.nim index 41be25c2667..2e5be466e06 100644 --- a/compiler/filter_tmpl.nim +++ b/compiler/ast/filter_tmpl.nim @@ -10,8 +10,23 @@ ## This module implements Nim's standard template filter. import - llstream, strutils, ast, msgs, options, - filters, lineinfos, pathutils, reports + front/[ + msgs, + options, + ], + std/[ + strutils, + ], + utils/[ + pathutils, + ], + ast/[ + llstream, + ast, + filters, + lineinfos, + reports + ] type TParseState = enum diff --git a/compiler/filters.nim b/compiler/ast/filters.nim similarity index 94% rename from compiler/filters.nim rename to compiler/ast/filters.nim index 2fcdb90d072..26c5ab38797 100644 --- a/compiler/filters.nim +++ b/compiler/ast/filters.nim @@ -10,8 +10,23 @@ ## This module implements Nim's simple filters and helpers for filters. import - llstream, strutils, ast, msgs, options, - renderer, pathutils, reports + ast/[ + llstream, + ast, + renderer, + reports + ], + std/[ + strutils, + ], + utils/[ + pathutils, + ], + front/[ + msgs, + options, + ] + proc invalidPragma(conf: ConfigRef; n: PNode) = conf.localReport(n.info, reportAst(rsemNodeNotAllowed, n)) diff --git a/compiler/idents.nim b/compiler/ast/idents.nim similarity index 100% rename from compiler/idents.nim rename to compiler/ast/idents.nim diff --git a/compiler/layouter.nim b/compiler/ast/layouter.nim similarity index 99% rename from compiler/layouter.nim rename to compiler/ast/layouter.nim index bec1a70acf0..9e915285ba7 100644 --- a/compiler/layouter.nim +++ b/compiler/ast/layouter.nim @@ -9,8 +9,24 @@ ## Layouter for nimpretty. -import idents, lexer, lineinfos, llstream, options, msgs, strutils, pathutils, - reports +import + ast/[ + idents, + lexer, + lineinfos, + llstream, + reports + ], + front/[ + options, + msgs, + ], + utils/[ + pathutils, + ], + std/[ + strutils, + ] const MinLineLen = 15 diff --git a/compiler/lexer.nim b/compiler/ast/lexer.nim similarity index 99% rename from compiler/lexer.nim rename to compiler/ast/lexer.nim index 3470105e6ea..06166fbe008 100644 --- a/compiler/lexer.nim +++ b/compiler/ast/lexer.nim @@ -17,8 +17,27 @@ ## format. import - hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream, - wordrecg, lineinfos, pathutils, parseutils, reports + utils/[ + platform, + pathutils, + ], + ast/[ + wordrecg, + nimlexbase, + llstream, + lineinfos, + reports, + idents + ], + std/[ + parseutils, + hashes, + strutils + ], + front/[ + options, + msgs + ] const MaxLineLength* = 80 # lines longer than this lead to a warning diff --git a/compiler/lineinfos.nim b/compiler/ast/lineinfos.nim similarity index 99% rename from compiler/lineinfos.nim rename to compiler/ast/lineinfos.nim index 327cfa7609e..81f80daa9e6 100644 --- a/compiler/lineinfos.nim +++ b/compiler/ast/lineinfos.nim @@ -10,7 +10,9 @@ ## This module contains the ``TMsgKind`` enum as well as the ## ``TLineInfo`` object. -import ropes, tables, pathutils, hashes +import + std/[tables, hashes], + utils/[ropes, pathutils] from ast_types import PSym, # Contextual details of the instantnation stack optionally refer to diff --git a/compiler/linter.nim b/compiler/ast/linter.nim similarity index 97% rename from compiler/linter.nim rename to compiler/ast/linter.nim index 9e51586fe5f..73c03de2a4f 100644 --- a/compiler/linter.nim +++ b/compiler/ast/linter.nim @@ -8,9 +8,21 @@ # ## This module implements the style checker. +import + std/[ + strutils + ], + ast/[ + ast, + lineinfos, + wordrecg, + reports + ], + front/[ + options, + msgs + ] -import std/strutils -import options, ast, msgs, lineinfos, wordrecg, reports const Letters* = {'a'..'z', 'A'..'Z', '0'..'9', '\x80'..'\xFF', '_'} diff --git a/compiler/llstream.nim b/compiler/ast/llstream.nim similarity index 99% rename from compiler/llstream.nim rename to compiler/ast/llstream.nim index 865a98ee0d4..4eb40bdbd50 100644 --- a/compiler/llstream.nim +++ b/compiler/ast/llstream.nim @@ -10,13 +10,13 @@ ## Low-level streams for high performance. import - pathutils + utils/pathutils # support `useGnuReadline`, `useLinenoise` for backwards compatibility const hasRstdin = (defined(nimUseLinenoise) or defined(useLinenoise) or defined(useGnuReadline)) and not defined(windows) -when hasRstdin: import rdstdin +when hasRstdin: import std/rdstdin type TLLRepl* = proc (s: PLLStream, buf: pointer, bufLen: int): int diff --git a/compiler/ndi.nim b/compiler/ast/ndi.nim similarity index 92% rename from compiler/ndi.nim rename to compiler/ast/ndi.nim index 5af87237f94..ff7384076d2 100644 --- a/compiler/ndi.nim +++ b/compiler/ast/ndi.nim @@ -10,7 +10,18 @@ ## This module implements the generation of ``.ndi`` files for better debugging ## support of Nim code. "ndi" stands for "Nim debug info". -import ast, msgs, ropes, options, pathutils +import + ast/[ + ast + ], + front/[ + msgs, + options + ], + utils/[ + ropes, + pathutils + ] type NdiFile* = object diff --git a/compiler/nimlexbase.nim b/compiler/ast/nimlexbase.nim similarity index 100% rename from compiler/nimlexbase.nim rename to compiler/ast/nimlexbase.nim diff --git a/compiler/nimsets.nim b/compiler/ast/nimsets.nim similarity index 97% rename from compiler/nimsets.nim rename to compiler/ast/nimsets.nim index 8683604af2a..e1e2833ac3d 100644 --- a/compiler/nimsets.nim +++ b/compiler/ast/nimsets.nim @@ -10,7 +10,13 @@ # this unit handles Nim sets; it implements symbolic sets import - ast, astalgo, lineinfos, bitsets, types, options + ast/[ast, astalgo, lineinfos, types], + front/[ + options + ], + utils/[ + bitsets + ] proc inSet*(s: PNode, elem: PNode): bool = assert s.kind == nkCurly diff --git a/compiler/parser.nim b/compiler/ast/parser.nim similarity index 99% rename from compiler/parser.nim rename to compiler/ast/parser.nim index b74e9e291a7..044aa287d59 100644 --- a/compiler/parser.nim +++ b/compiler/ast/parser.nim @@ -26,12 +26,28 @@ when isMainModule: outp.write matches[0], "\L" outp.close - import ".." / tools / grammar_nanny + import "../.." / tools / grammar_nanny checkGrammarFile() import - llstream, lexer, idents, strutils, ast, msgs, options, lineinfos, - pathutils, reports + ast/[ + llstream, + lexer, + idents, + ast, + lineinfos, + reports + ], + std/[ + strutils, + ], + front/[ + msgs, + options, + ], + utils/[ + pathutils + ] when defined(nimpretty): import layouter diff --git a/compiler/renderer.nim b/compiler/ast/renderer.nim similarity index 99% rename from compiler/renderer.nim rename to compiler/ast/renderer.nim index c265fb7be0c..c2c7bb6ae95 100644 --- a/compiler/renderer.nim +++ b/compiler/ast/renderer.nim @@ -15,7 +15,21 @@ when defined(nimHasUsed): {.used.} import - lexer, options, idents, strutils, ast, msgs, lineinfos, reports + ast/[ + lexer, + idents, + ast, + lineinfos, + reports + ], + std/[ + strutils, + ], + front/[ + options, + msgs, + ] + type TRenderFlag* = enum diff --git a/compiler/renderverbatim.nim b/compiler/ast/renderverbatim.nim similarity index 97% rename from compiler/renderverbatim.nim rename to compiler/ast/renderverbatim.nim index fc74f2322c8..b751afd7a65 100644 --- a/compiler/renderverbatim.nim +++ b/compiler/ast/renderverbatim.nim @@ -1,11 +1,11 @@ -import strutils +import std/strutils -import ast, options, msgs +import ast/ast, front/options, front/msgs const isDebug = false when isDebug: - import renderer - import astalgo + import ast/renderer + import ast/astalgo proc lastNodeRec(n: PNode): PNode = result = n diff --git a/compiler/reports.nim b/compiler/ast/reports.nim similarity index 99% rename from compiler/reports.nim rename to compiler/ast/reports.nim index 61eb3dd97ac..8c29a4dc5d4 100644 --- a/compiler/reports.nim +++ b/compiler/ast/reports.nim @@ -17,11 +17,10 @@ import std/[options, packedsets] import - ast_types, - vm_enums, - nilcheck_enums, - int128, - platform + vm/vm_enums, + ast/ast_types, + utils/[int128, platform], + sem/nilcheck_enums export ast_types, diff --git a/compiler/syntaxes.nim b/compiler/ast/syntaxes.nim similarity index 95% rename from compiler/syntaxes.nim rename to compiler/ast/syntaxes.nim index 4ef6daeb0de..66a93aeaa66 100644 --- a/compiler/syntaxes.nim +++ b/compiler/ast/syntaxes.nim @@ -10,8 +10,26 @@ ## Implements the dispatcher for the different parsers. import - strutils, llstream, ast, idents, lexer, options, msgs, parser, - filters, filter_tmpl, renderer, lineinfos, pathutils, reports + strutils, + ast/[ + llstream, + ast, + idents, + lexer, + parser, + filters, + filter_tmpl, + renderer, + lineinfos, + reports + ], + front/[ + options, + msgs, + ], + utils/[ + pathutils, + ] export Parser, parseAll, parseTopLevelStmt, closeParser diff --git a/compiler/trees.nim b/compiler/ast/trees.nim similarity index 100% rename from compiler/trees.nim rename to compiler/ast/trees.nim diff --git a/compiler/treetab.nim b/compiler/ast/treetab.nim similarity index 100% rename from compiler/treetab.nim rename to compiler/ast/treetab.nim diff --git a/compiler/types.nim b/compiler/ast/types.nim similarity index 99% rename from compiler/types.nim rename to compiler/ast/types.nim index e11761f5bc4..d411397b1d4 100644 --- a/compiler/types.nim +++ b/compiler/ast/types.nim @@ -10,8 +10,31 @@ # this module contains routines for accessing and iterating over types import - intsets, ast, astalgo, trees, msgs, strutils, platform, renderer, options, - lineinfos, int128, modulegraphs, astmsgs, errorhandling, reports + std/[ + intsets, + strutils, + ], + ast/[ + ast, + astalgo, + trees, + renderer, + lineinfos, + astmsgs, + errorhandling, + reports + ], + front/[ + msgs, + options, + ], + utils/[ + platform, + int128, + ], + modules/[ + modulegraphs, + ] export EffectsCompat, TTypeRelation, ProcConvMismatch @@ -1300,7 +1323,7 @@ proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]], result = a.kind == last -include sizealignoffsetimpl +include sem/sizealignoffsetimpl proc computeSize*(conf: ConfigRef; typ: PType): BiggestInt = computeSizeAlign(conf, typ) diff --git a/compiler/typesrenderer.nim b/compiler/ast/typesrenderer.nim similarity index 100% rename from compiler/typesrenderer.nim rename to compiler/ast/typesrenderer.nim diff --git a/compiler/wordrecg.nim b/compiler/ast/wordrecg.nim similarity index 100% rename from compiler/wordrecg.nim rename to compiler/ast/wordrecg.nim diff --git a/compiler/ccgcalls.nim b/compiler/backend/ccgcalls.nim similarity index 99% rename from compiler/ccgcalls.nim rename to compiler/backend/ccgcalls.nim index 14ec756d30b..0988603572c 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/backend/ccgcalls.nim @@ -306,7 +306,7 @@ proc genArgNoParam(p: BProc, n: PNode, needsTmp = false): Rope = initLocExprSingleUse(p, n, a) result = rdLoc(withTmpIfNeeded(p, a, needsTmp)) -from dfa import aliases, AliasKind +from sem/dfa import aliases, AliasKind proc potentialAlias(n: PNode, potentialWrites: seq[PNode]): bool = for p in potentialWrites: diff --git a/compiler/ccgexprs.nim b/compiler/backend/ccgexprs.nim similarity index 99% rename from compiler/ccgexprs.nim rename to compiler/backend/ccgexprs.nim index aff8418b395..27296f7f07d 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/backend/ccgexprs.nim @@ -2604,7 +2604,7 @@ proc genStmtList(p: BProc, n: PNode) = genStmtListExprImpl: genStmts(p, n[^1]) -from parampatterns import isLValue +from sem/parampatterns import isLValue proc upConv(p: BProc, n: PNode, d: var TLoc) = var a: TLoc diff --git a/compiler/ccgliterals.nim b/compiler/backend/ccgliterals.nim similarity index 100% rename from compiler/ccgliterals.nim rename to compiler/backend/ccgliterals.nim diff --git a/compiler/ccgmerge_unused.nim b/compiler/backend/ccgmerge_unused.nim similarity index 100% rename from compiler/ccgmerge_unused.nim rename to compiler/backend/ccgmerge_unused.nim diff --git a/compiler/ccgreset.nim b/compiler/backend/ccgreset.nim similarity index 100% rename from compiler/ccgreset.nim rename to compiler/backend/ccgreset.nim diff --git a/compiler/ccgstmts.nim b/compiler/backend/ccgstmts.nim similarity index 100% rename from compiler/ccgstmts.nim rename to compiler/backend/ccgstmts.nim diff --git a/compiler/ccgthreadvars.nim b/compiler/backend/ccgthreadvars.nim similarity index 100% rename from compiler/ccgthreadvars.nim rename to compiler/backend/ccgthreadvars.nim diff --git a/compiler/ccgtrav.nim b/compiler/backend/ccgtrav.nim similarity index 100% rename from compiler/ccgtrav.nim rename to compiler/backend/ccgtrav.nim diff --git a/compiler/ccgtypes.nim b/compiler/backend/ccgtypes.nim similarity index 99% rename from compiler/ccgtypes.nim rename to compiler/backend/ccgtypes.nim index a1f61b2df95..4b4b813de86 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/backend/ccgtypes.nim @@ -11,7 +11,7 @@ # ------------------------- Name Mangling -------------------------------- -import sighashes, modulegraphs +import sem/sighashes, modules/modulegraphs proc genProcHeader(m: BModule, prc: PSym, asPtr: bool = false): Rope diff --git a/compiler/ccgutils.nim b/compiler/backend/ccgutils.nim similarity index 95% rename from compiler/ccgutils.nim rename to compiler/backend/ccgutils.nim index 06b75a20fa6..04c70d79b8e 100644 --- a/compiler/ccgutils.nim +++ b/compiler/backend/ccgutils.nim @@ -10,8 +10,27 @@ # This module declares some helpers for the C code generator. import - ast, types, hashes, strutils, msgs, wordrecg, - platform, trees, options, cgendata + std/[ + hashes, strutils + ], + ast/[ + wordrecg, + ast, + types, + trees + ], + front/[ + msgs, + options + ], + utils/[ + platform + ], + sem/[ + ], + backend/[ + cgendata + ] proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode = case n.kind diff --git a/compiler/cgen.nim b/compiler/backend/cgen.nim similarity index 99% rename from compiler/cgen.nim rename to compiler/backend/cgen.nim index 8b416499bf2..cc8fe26bd95 100644 --- a/compiler/cgen.nim +++ b/compiler/backend/cgen.nim @@ -10,17 +10,67 @@ ## This module implements the C code generator. import - ast, astalgo, hashes, trees, platform, magicsys, extccomp, options, intsets, - nversion, nimsets, msgs, bitsets, idents, types, - ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth, - rodutils, renderer, cgendata, aliases, reports, - lowerings, tables, sets, ndi, lineinfos, pathutils, transf, - injectdestructors, astmsgs + std/[ + hashes, + intsets, + os, + math, + tables, + sets + ], + ast/[ + ast, + astalgo, + trees, + nimsets, + idents, + types, + wordrecg, + treetab, + renderer, + reports, + lineinfos, + astmsgs, + ndi + ], + modules/[ + magicsys, + ], + front/[ + options, + msgs + ], + utils/[ + platform, + nversion, + bitsets, + ropes, + pathutils + ], + sem/[ + passes, + rodutils, + aliases, + lowerings, + transf, + injectdestructors + ], + backend/[ + extccomp, + ccgutils, + cgmeth, + cgendata + ], + plugins/[ + ], + vm/[ + ] + when not defined(leanCompiler): - import spawn, semparallel + import sem/[spawn, semparallel] -import strutils except `%` # collides with ropes.`%` +import std/strutils except `%` # collides with ropes.`%` from ic / ic import ModuleBackendFlag import dynlib @@ -39,7 +89,7 @@ when not declared(dynlib.libCandidates): dest.add(s) when options.hasTinyCBackend: - import tccgen + import backend/tccgen proc hcrOn(m: BModule): bool = m.config.hcrOn proc hcrOn(p: BProc): bool = p.module.config.hcrOn diff --git a/compiler/cgendata.nim b/compiler/backend/cgendata.nim similarity index 98% rename from compiler/cgendata.nim rename to compiler/backend/cgendata.nim index 88b8d4090dd..a3c160f9237 100644 --- a/compiler/cgendata.nim +++ b/compiler/backend/cgendata.nim @@ -10,8 +10,27 @@ ## This module contains the data structures for the C code generation phase. import - ast, ropes, options, intsets, - tables, ndi, lineinfos, pathutils, modulegraphs, sets + std/[ + intsets, + tables, + sets + ], + ast/[ + ast, + lineinfos, + ndi + ], + modules/[ + modulegraphs + ], + front/[ + options + ], + utils/[ + ropes, + pathutils + ] + type TLabel* = Rope # for the C generator a label is just a rope diff --git a/compiler/cgmeth.nim b/compiler/backend/cgmeth.nim similarity index 98% rename from compiler/cgmeth.nim rename to compiler/backend/cgmeth.nim index 976a9cbbcd5..d7f175d768b 100644 --- a/compiler/cgmeth.nim +++ b/compiler/backend/cgmeth.nim @@ -10,8 +10,27 @@ ## This module implements code generation for methods. import - intsets, options, ast, msgs, renderer, types, magicsys, - sempass2, modulegraphs, lineinfos, reports + std/[ + intsets, + ], + front/[ + options, + msgs, + ], + ast/[ + ast, + renderer, + types, + lineinfos, + reports + ], + modules/[ + magicsys, + modulegraphs, + ], + sem/[ + sempass2, + ] proc genConv(n: PNode, d: PType, downcast: bool; conf: ConfigRef): PNode = var dest = skipTypes(d, abstractPtrs) diff --git a/compiler/extccomp.nim b/compiler/backend/extccomp.nim similarity index 99% rename from compiler/extccomp.nim rename to compiler/backend/extccomp.nim index 82dffbc00a0..3d468d39cad 100644 --- a/compiler/extccomp.nim +++ b/compiler/backend/extccomp.nim @@ -12,10 +12,18 @@ ## options read from a lineinfos file, to provide generalized procedures to ## compile nim files. -import ropes, platform, condsyms, options, msgs, lineinfos, pathutils, reports +import + utils/[ropes, platform, pathutils], + ast/[lineinfos, reports], + front/[condsyms, options, msgs], + std/[ + os, strutils, osproc, sha1, streams, sequtils, + times, strtabs, json, jsonutils, sugar + ] + +# import ropes, platform, condsyms, options, msgs, lineinfos, pathutils, reports -import std/[os, strutils, osproc, sha1, streams, sequtils, times, strtabs, json, jsonutils, sugar] type TInfoCCProp* = enum ## properties of the C compiler: diff --git a/compiler/jsgen.nim b/compiler/backend/jsgen.nim similarity index 99% rename from compiler/jsgen.nim rename to compiler/backend/jsgen.nim index 7fd2cac12e2..8f87ccebbbf 100644 --- a/compiler/jsgen.nim +++ b/compiler/backend/jsgen.nim @@ -27,15 +27,56 @@ the expressions need to be transformed into statements. `isSimpleExpr` implements the required case distinction. """ - import - ast, trees, magicsys, options, - nversion, msgs, idents, types, - ropes, passes, ccgutils, wordrecg, renderer, - cgmeth, lowerings, sighashes, modulegraphs, lineinfos, rodutils, - transf, injectdestructors, sourcemap, astmsgs, reports + std/[ + json, + sets, + math, + tables, + intsets, + strutils + ], + ast/[ + ast, + trees, + idents, + types, + wordrecg, + renderer, + lineinfos, + astmsgs, + reports + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + options, + msgs + ], + utils/[ + nversion, + ropes + ], + sem/[ + passes, + lowerings, + sighashes, + rodutils, + injectdestructors, + transf, + sourcemap + ], + backend/[ + ccgutils, + cgmeth, + ], + plugins/[ + ], + vm/[ + ] -import json, sets, math, tables, intsets, strutils type TJSGen = object of PPassContext diff --git a/compiler/jstypes.nim b/compiler/backend/jstypes.nim similarity index 100% rename from compiler/jstypes.nim rename to compiler/backend/jstypes.nim diff --git a/compiler/tccgen.nim b/compiler/backend/tccgen.nim similarity index 100% rename from compiler/tccgen.nim rename to compiler/backend/tccgen.nim diff --git a/compiler/cli_reporter.nim b/compiler/front/cli_reporter.nim similarity index 99% rename from compiler/cli_reporter.nim rename to compiler/front/cli_reporter.nim index 5918e81a4e1..aab7936854c 100644 --- a/compiler/cli_reporter.nim +++ b/compiler/front/cli_reporter.nim @@ -9,27 +9,42 @@ ## 3. `reportBody` - generate main report body. Most of the error formatting ## is done in this proc. -import reports, - ast, - types, - renderer, - astmsgs, - astalgo, - msgs, - lineinfos, - nilcheck_enums, - vm_enums, - platform, - nversion - -import options as compiler_options -import std/[ - strutils, terminal, options, algorithm, - sequtils, strformat, tables, intsets, - json -] - +import + std/[ + strutils, + terminal, + options, + algorithm, + sequtils, + strformat, + tables, + intsets, + json + ], + ast/[ + lineinfos, + astalgo, + astmsgs, + renderer, + types, + ast, + reports + ], + utils/[ + platform, + nversion + ], + front/[ + msgs + ], + sem/[ + nilcheck_enums + ], + vm/[ + vm_enums + ] +import front/options as compiler_options func assertKind(r: ReportTypes | Report) = assert r.kind != repNone diff --git a/compiler/cmdlinehelper.nim b/compiler/front/cmdlinehelper.nim similarity index 92% rename from compiler/cmdlinehelper.nim rename to compiler/front/cmdlinehelper.nim index d7f8afcd1b4..bbb48cf4bb3 100644 --- a/compiler/cmdlinehelper.nim +++ b/compiler/front/cmdlinehelper.nim @@ -10,9 +10,30 @@ ## Helpers for binaries that use compiler passes, e.g.: nim, nimsuggest, nimfix import - options, idents, nimconf, extccomp, commands, msgs, - reports, - modulegraphs, condsyms, os, pathutils + std/[ + os + ], + ast/[ + idents, + reports + ], + modules/[ + modulegraphs + ], + front/[ + nimconf, + commands, + msgs, + options, + condsyms + ], + utils/[ + pathutils + ], + backend/[ + extccomp + ] + proc prependCurDir*(f: AbsoluteFile): AbsoluteFile = when defined(unix): diff --git a/compiler/commands.nim b/compiler/front/commands.nim similarity index 99% rename from compiler/commands.nim rename to compiler/front/commands.nim index fbcddc35ebc..a259b7e49c2 100644 --- a/compiler/commands.nim +++ b/compiler/front/commands.nim @@ -24,13 +24,40 @@ bootSwitch(usedMarkAndSweep, defined(gcmarkandsweep), "--gc:markAndSweep") bootSwitch(usedGoGC, defined(gogc), "--gc:go") bootSwitch(usedNoGC, defined(nogc), "--gc:none") -import std/[os, strutils, parseutils, parseopt, sequtils, strtabs] import - msgs, options, nversion, condsyms, extccomp, platform, - wordrecg, nimblecmd, lineinfos, pathutils, pathnorm, - reports - -from ast import setUseIc, eqTypeFlags, tfGcSafe, tfNoSideEffect + std/[ + os, + strutils, + parseutils, + parseopt, + sequtils, + strtabs, + pathnorm + ], + modules/[ + nimblecmd, + ], + ast/[ + lineinfos, + reports, + wordrecg, + ], + front/[ + condsyms, + options, + msgs + ], + backend/[ + extccomp + ], + utils/[ + nversion, + pathutils, + platform + ] + + +from ast/ast import setUseIc, eqTypeFlags, tfGcSafe, tfNoSideEffect bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc") bootSwitch(usedFFI, hasFFI, "-d:nimHasLibFFI") diff --git a/compiler/condsyms.nim b/compiler/front/condsyms.nim similarity index 98% rename from compiler/condsyms.nim rename to compiler/front/condsyms.nim index 9c0d64fc53f..60df248e97c 100644 --- a/compiler/condsyms.nim +++ b/compiler/front/condsyms.nim @@ -10,10 +10,10 @@ # This module handles the conditional symbols. import - strtabs + std/strtabs -from options import Feature -import reports +from front/options import Feature +import ast/reports proc defineSymbol*(symbols: StringTableRef; symbol: string, value: string = "true") = symbols[symbol] = value diff --git a/compiler/main.nim b/compiler/front/main.nim similarity index 94% rename from compiler/main.nim rename to compiler/front/main.nim index 7c891b78d80..cb4511255b3 100644 --- a/compiler/main.nim +++ b/compiler/front/main.nim @@ -14,20 +14,50 @@ when not defined(nimcore): import std/[strutils, os, times, tables, sha1, with, json], - llstream, ast, lexer, syntaxes, options, msgs, - condsyms, - sem, idents, passes, extccomp, - cgen, nversion, - platform, nimconf, passaux, depends, vm, - modules, - reports, - modulegraphs, lineinfos, pathutils, vmprofiler + ast/[ + llstream, # Input data stream + ast, + lexer, + idents, + syntaxes, + reports, # Error report information + lineinfos # Positional data + ], + front/[ + options, + condsyms, + msgs, + nimconf # Configuration file reading + ], + sem/[ + sem, # Implementation of the semantic pass + passes, # Main procs for compilation pass setups + passaux + ], + modules/[ + depends, # Generate dependency information + modules, + modulegraphs # Project module graph + ], + backend/[ + extccomp, # Calling C compiler + cgen, # C code generation + ], + utils/[ + platform, # Target platform data + nversion, + pathutils # Input file handling + ], + vm/[ + vm, # Configuration file evaluation, `nim e` + vmprofiler + ] import ic / [cbackend, integrity, navigator] from ic / ic import rodViewer when not defined(leanCompiler): - import jsgen, docgen, docgen2 + import backend/jsgen, tools/[docgen, docgen2] proc semanticPasses(g: ModuleGraph) = registerPass g, verbosePass diff --git a/compiler/msgs.nim b/compiler/front/msgs.nim similarity index 99% rename from compiler/msgs.nim rename to compiler/front/msgs.nim index 06835c05e11..f3d1b3d34f7 100644 --- a/compiler/msgs.nim +++ b/compiler/front/msgs.nim @@ -15,9 +15,11 @@ import std/options as std_options import - options, ropes, lineinfos, pathutils, strutils2, reports + utils/[ropes, pathutils, strutils2], + ast/[reports, lineinfos], + front/[options] -from ast_types import PSym +from ast/ast_types import PSym export InstantiationInfo export TErrorHandling @@ -84,6 +86,8 @@ proc newFileInfo(fullPath: AbsoluteFile, projPath: RelativeFile): TFileInfo = result.fullContent = "" when defined(nimpretty): + # Wrapped in `when defined()` because `.fullContent` is not defined + # without it. proc fileSection*(conf: ConfigRef; fid: FileIndex; a, b: int): string = substr(conf.m.fileInfos[fid.int].fullContent, a, b) diff --git a/compiler/nimconf.nim b/compiler/front/nimconf.nim similarity index 98% rename from compiler/nimconf.nim rename to compiler/front/nimconf.nim index 50f3289fbc2..a525c26e50f 100644 --- a/compiler/nimconf.nim +++ b/compiler/front/nimconf.nim @@ -10,8 +10,28 @@ # This module handles the reading of the config file. import - llstream, commands, os, strutils, msgs, lexer, ast, reports, - options, idents, wordrecg, strtabs, pathutils, scriptconfig + front/[ + commands, + msgs, + options, + scriptconfig + ], + ast/[ + lexer, + reports, + idents, + wordrecg, + llstream, + ast + ], + std/[ + os, + strutils, + strtabs, + ], + utils/[ + pathutils, + ] # ---------------- configuration file parser ----------------------------- # we use Nim's lexer here to save space and work diff --git a/compiler/options.nim b/compiler/front/options.nim similarity index 99% rename from compiler/options.nim rename to compiler/front/options.nim index 1a4965c2a0d..368c34e8733 100644 --- a/compiler/options.nim +++ b/compiler/front/options.nim @@ -8,12 +8,12 @@ # import - os, strutils, strtabs, sets, lineinfos, platform, - prefixmatches, pathutils, nimpaths, tables, reports + std/[os, strutils, strtabs, sets, tables], + utils/[prefixmatches, pathutils, platform], + ast/[reports, lineinfos], + modules/nimpaths -import std/options as sopt - -from ast_types import TOption, TOptions +from ast/ast_types import TOption, TOptions export TOption, TOptions from terminal import isatty @@ -1092,7 +1092,7 @@ proc clearNimblePath*(conf: ConfigRef) = conf.lazyPaths.setLen(0) conf.nimblePaths.setLen(0) -include packagehandling +include modules/packagehandling proc getOsCacheDir(): string = when defined(posix): diff --git a/compiler/scriptconfig.nim b/compiler/front/scriptconfig.nim similarity index 95% rename from compiler/scriptconfig.nim rename to compiler/front/scriptconfig.nim index d3d2a74e78e..a3acbf6e991 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/front/scriptconfig.nim @@ -11,13 +11,43 @@ ## language. import - ast, modules, idents, passes, condsyms, - options, sem, llstream, vm, vmdef, commands, - os, times, osproc, wordrecg, strtabs, modulegraphs, - pathutils, reports, msgs + ast/[ + ast, + idents, + wordrecg, + reports, + llstream, + ], + std/[ + os, + times, + osproc, + strtabs, + ], + modules/[ + modules, + modulegraphs, + ], + sem/[ + passes, + sem, + ], + vm/[ + vm, + vmdef, + ], + front/[ + msgs, + condsyms, + options, + commands, + ], + utils/[ + pathutils + ] # we support 'cmpIgnoreStyle' natively for efficiency: -from strutils import cmpIgnoreStyle, contains +from std/strutils import cmpIgnoreStyle, contains proc listDirs(a: VmArgs, filter: set[PathComponent]) = let dir = getString(a, 0) diff --git a/compiler/ic/cbackend.nim b/compiler/ic/cbackend.nim index f5811cb3b40..2ce632cd6b9 100644 --- a/compiler/ic/cbackend.nim +++ b/compiler/ic/cbackend.nim @@ -18,10 +18,30 @@ ## also doing cross-module dependency tracking and DCE that we don't need ## anymore. DCE is now done as prepass over the entire packed module graph. -import std/packedsets, algorithm, tables +import + std/[ + packedsets, algorithm, tables + ], + ast/[ + ast, + lineinfos + ], + modules/[ + modulegraphs + ], + front/[ + options, + msgs + ], + utils/[ + pathutils + ], + backend/[ + cgendata, + cgen, + extccomp + ] -import ".."/[ast, options, lineinfos, modulegraphs, cgendata, cgen, - pathutils, extccomp, msgs] import packed_ast, ic, dce, rodfiles diff --git a/compiler/ic/dce.nim b/compiler/ic/dce.nim index 0a436a5d1f6..b3f7eadf93b 100644 --- a/compiler/ic/dce.nim +++ b/compiler/ic/dce.nim @@ -9,8 +9,19 @@ ## Dead code elimination (=DCE) for IC. -import std/[intsets, tables] -import ".." / [ast, options, lineinfos, types] +import + std/[ + intsets, + tables + ], + ast/[ + ast, + lineinfos, + types + ], + front/[ + options + ] import packed_ast, ic, bitabs diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index 818fbe73531..712069390a6 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -7,12 +7,31 @@ # distribution, for details about the copyright. # -import hashes, tables, intsets, std/sha1 -import packed_ast, bitabs, rodfiles -import ".." / [ast, idents, lineinfos, msgs, ropes, options, - pathutils, condsyms, reports] -#import ".." / [renderer, astalgo] -from os import removeFile, isAbsolute +import std/[hashes, tables, intsets, sha1] + +import + ic/[ + packed_ast, + bitabs, + rodfiles + ], + ast/[ + ast, + idents, + lineinfos, + reports + ], + front/[ + msgs, + options, + condsyms + ], + utils/[ + ropes, + pathutils + ] + +from std/os import removeFile, isAbsolute type PackedConfig* = object diff --git a/compiler/ic/integrity.nim b/compiler/ic/integrity.nim index ed367ef610b..f92e114634c 100644 --- a/compiler/ic/integrity.nim +++ b/compiler/ic/integrity.nim @@ -10,8 +10,8 @@ ## Integrity checking for a set of .rod files. ## The set must cover a complete Nim project. -import sets -import ".." / [ast, modulegraphs] +import std/sets +import ast/ast, modules/modulegraphs import packed_ast, bitabs, ic type diff --git a/compiler/ic/navigator.nim b/compiler/ic/navigator.nim index c04f636da4a..899b10409b8 100644 --- a/compiler/ic/navigator.nim +++ b/compiler/ic/navigator.nim @@ -11,12 +11,24 @@ ## IDE-like features. It uses the set of .rod files to accomplish ## its task. The set must cover a complete Nim project. -import sets - -from os import nil +import + ast/[ + ast, + reports + ], + modules/[ + modulegraphs + ], + front/[ + msgs, + options + ], + std/sets + + +from std/os import nil from std/private/miscdollars import toLocation -import ".." / [ast, modulegraphs, msgs, options, reports] import packed_ast, bitabs, ic type diff --git a/compiler/ic/packed_ast.nim b/compiler/ic/packed_ast.nim index 17beda2c18b..61fbb8b61cb 100644 --- a/compiler/ic/packed_ast.nim +++ b/compiler/ic/packed_ast.nim @@ -12,9 +12,9 @@ ## use this representation directly in all the transformations, ## it is superior. -import hashes, tables, strtabs -import bitabs -import ".." / [ast, options] +import std/[hashes, tables, strtabs] +import ic/bitabs +import ast/ast, front/options type SymId* = distinct int32 diff --git a/compiler/ic/replayer.nim b/compiler/ic/replayer.nim index aee20a6c88f..e91196217a3 100644 --- a/compiler/ic/replayer.nim +++ b/compiler/ic/replayer.nim @@ -11,8 +11,27 @@ ## state like ``{.compile: "foo.c".}``. For IC (= Incremental compilation) ## support. -import ".." / [ast, modulegraphs, trees, extccomp, btrees, - msgs, pathutils, options, cgmeth, reports] +import + ast/[ + ast, + trees, + reports, + ], + modules/[ + modulegraphs, + ], + utils/[ + btrees, + pathutils, + ], + front/[ + msgs, + options, + ], + backend/[ + extccomp, + cgmeth + ] import tables diff --git a/compiler/depends.nim b/compiler/modules/depends.nim similarity index 91% rename from compiler/depends.nim rename to compiler/modules/depends.nim index 98a2f723611..d070c81aca3 100644 --- a/compiler/depends.nim +++ b/compiler/modules/depends.nim @@ -10,9 +10,23 @@ # This module implements a dependency file generator. import - options, ast, ropes, passes, modulepaths, pathutils - -from modulegraphs import ModuleGraph, PPassContext + ast/[ + ast + ], + modules/[ + modulepaths, + modulegraphs + ], + front/[ + options + ], + utils/[ + ropes, + pathutils + ], + sem/[ + passes + ] type TGen = object of PPassContext diff --git a/compiler/importer.nim b/compiler/modules/importer.nim similarity index 97% rename from compiler/importer.nim rename to compiler/modules/importer.nim index ccdbf6f6ee7..dd7d34c4fa3 100644 --- a/compiler/importer.nim +++ b/compiler/modules/importer.nim @@ -10,9 +10,32 @@ ## This module implements the symbol importing mechanism. import - intsets, ast, astalgo, msgs, options, idents, lookups, - semdata, modulepaths, sigmatch, lineinfos, sets, - modulegraphs, wordrecg, tables, reports + std/[ + intsets, + sets, + tables + ], + ast/[ + ast, + astalgo, + idents, + lineinfos, + wordrecg, + reports + ], + modules/[ + modulepaths, + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + lookups, + semdata, + sigmatch + ] proc readExceptSet*(c: PContext, n: PNode): IntSet = assert n.kind in {nkImportExceptStmt, nkExportExceptStmt} diff --git a/compiler/magicsys.nim b/compiler/modules/magicsys.nim similarity index 96% rename from compiler/magicsys.nim rename to compiler/modules/magicsys.nim index 620891c7f83..5a6974edab8 100644 --- a/compiler/magicsys.nim +++ b/compiler/modules/magicsys.nim @@ -7,11 +7,27 @@ # distribution, for details about the copyright. # -# Built-in types and compilerprocs are registered here. +## Built-in types and compilerprocs are registered here. import - ast, astalgo, msgs, platform, idents, reports, - modulegraphs, lineinfos, errorhandling, options + utils/[ + platform, + ], + ast/[ + lineinfos, + errorhandling, + idents, + reports, + ast, + astalgo, + ], + modules/[ + modulegraphs, + ], + front/[ + msgs, + options + ] export createMagic diff --git a/compiler/modulegraphs.nim b/compiler/modules/modulegraphs.nim similarity index 98% rename from compiler/modulegraphs.nim rename to compiler/modules/modulegraphs.nim index 4668e1e79d2..eb092035fd0 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modules/modulegraphs.nim @@ -11,10 +11,33 @@ ## represents a complete Nim project. Single modules can either be kept in RAM ## or stored in a rod-file. -import intsets, tables, hashes, md5 -import ast, astalgo, options, lineinfos,idents, - btrees, ropes, msgs, pathutils, reports -import ic / [packed_ast, ic] +import + std/[ + intsets, + tables, + hashes, + md5 + ], + front/[ + options, + msgs, + ], + ast/[ + ast, + astalgo, + lineinfos, + idents, + reports + ], + utils/[ + pathutils, + btrees, + ropes, + ], + ic/[ + packed_ast, + ic + ] type SigHash* = distinct MD5Digest diff --git a/compiler/modulepaths.nim b/compiler/modules/modulepaths.nim similarity index 97% rename from compiler/modulepaths.nim rename to compiler/modules/modulepaths.nim index 2a35a9413df..9848b3eeeb7 100644 --- a/compiler/modulepaths.nim +++ b/compiler/modules/modulepaths.nim @@ -7,8 +7,25 @@ # distribution, for details about the copyright. # -import ast, renderer, strutils, msgs, options, os, lineinfos, - pathutils, reports +import + std/[ + strutils, + os, + ], + ast/[ + ast, + lineinfos, + renderer, + reports, + ], + utils/[ + pathutils, + ], + front/[ + msgs, + options, + ] + when false: const diff --git a/compiler/modules.nim b/compiler/modules/modules.nim similarity index 96% rename from compiler/modules.nim rename to compiler/modules/modules.nim index a5a79cb234e..c39a9166226 100644 --- a/compiler/modules.nim +++ b/compiler/modules/modules.nim @@ -10,11 +10,37 @@ ## Implements the module handling, including the caching of modules. import - ast, astalgo, magicsys, msgs, options, - idents, lexer, passes, syntaxes, llstream, modulegraphs, - lineinfos, pathutils, tables, reports + ast/[ + ast, + astalgo, + idents, + lexer, + llstream, + lineinfos, + reports, + syntaxes, + ], + front/[ + msgs, + options + ], + sem/[ + passes, + ], + modules/[ + modulegraphs, + magicsys, + ], + std/[ + tables + ], + utils/[ + pathutils + ], + ic/[ + replayer + ] -import ic / replayer proc resetSystemArtifacts*(g: ModuleGraph) = magicsys.resetSysTypes(g) diff --git a/compiler/nimblecmd.nim b/compiler/modules/nimblecmd.nim similarity index 96% rename from compiler/nimblecmd.nim rename to compiler/modules/nimblecmd.nim index e00f4d9a38c..51c5c36ccbd 100644 --- a/compiler/nimblecmd.nim +++ b/compiler/modules/nimblecmd.nim @@ -9,10 +9,27 @@ ## Implements some helper procs for Nimble (Nim's package manager) support. -import parseutils, strutils, os, options, msgs, sequtils, lineinfos, pathutils, - std/sha1, tables +import + std/[ + parseutils, + strutils, + os, + sha1, + tables, + sequtils + ], + front/[ + options, + msgs, + ], + ast/[ + lineinfos, + reports + ], + utils/[ + pathutils + ] -import reports proc addPath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) = if not conf.searchPaths.contains(path): diff --git a/compiler/nimpaths.nim b/compiler/modules/nimpaths.nim similarity index 98% rename from compiler/nimpaths.nim rename to compiler/modules/nimpaths.nim index a93b488fdb5..3592feb5a99 100644 --- a/compiler/nimpaths.nim +++ b/compiler/modules/nimpaths.nim @@ -17,7 +17,7 @@ interpolation variables: Unstable API ]## -import os, strutils +import std/os, std/strutils const docCss* = "$nimr/doc/nimdoc.css" diff --git a/compiler/packagehandling.nim b/compiler/modules/packagehandling.nim similarity index 100% rename from compiler/packagehandling.nim rename to compiler/modules/packagehandling.nim diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 4a0287cb5b1..e2720f50bd3 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -30,3 +30,5 @@ define:useStdoutAsStdmsg experimental:strictEffects warningAsError:Effect:on @end + +path:"$config" \ No newline at end of file diff --git a/compiler/nim.nim b/compiler/nim.nim index ddc73a9196b..a7110658a0d 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -24,19 +24,37 @@ when defined(windows) and not defined(nimKochBootstrap): {.link: "../icons/nim-i386-windows-vcc.res".} import - cli_reporter, - commands, options, msgs, extccomp, main, idents, cmdlinehelper, - pathutils, modulegraphs, reports - -from browsers import openDefaultBrowser -from nodejs import findNodeJs + backend/[ + extccomp + ], + front/[ + msgs, main, cmdlinehelper, options, commands, cli_reporter + ], + modules/[ + modulegraphs + ], + utils/[ + pathutils + ], + ast/[ + reports, idents + ] + + +# import +# cli_reporter, +# commands, options, msgs, main, idents, cmdlinehelper, +# pathutils, modulegraphs, reports + +from std/browsers import openDefaultBrowser +from utils/nodejs import findNodeJs when hasTinyCBackend: - import tccgen + import backend/tccgen when defined(profiler) or defined(memProfiler): {.hint: "Profiling support is turned on!".} - import nimprof + import sdt/nimprof proc getNimRunExe(conf: ConfigRef): string = diff --git a/compiler/nimfix/nimfix.nim b/compiler/nimfix/nimfix.nim index 30c138f793d..44b46f18290 100644 --- a/compiler/nimfix/nimfix.nim +++ b/compiler/nimfix/nimfix.nim @@ -9,12 +9,36 @@ ## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code. -import strutils, os, parseopt -import compiler/[options, commands, modules, sem, - passes, passaux, linter, - msgs, nimconf, - extccomp, condsyms, - modulegraphs, idents] +import + std/[ + strutils, + os, + parseopt + ], + ast/[ + idents + ], + modules/[ + modules, + modulegraphs + ], + front/[ + options, + commands, + msgs, + condsyms, + nimconf + ], + sem/[ + sem, + passes, + passaux, + linter + ], + backend/[ + extccomp + ] + const Usage = """ Nimfix - Tool to patch Nim code diff --git a/compiler/nimfix/prettybase.nim b/compiler/nimfix/prettybase.nim index fbc2e3bd185..64d25aa0296 100644 --- a/compiler/nimfix/prettybase.nim +++ b/compiler/nimfix/prettybase.nim @@ -7,8 +7,23 @@ # distribution, for details about the copyright. # -import strutils except Letters -import ".." / [ast, msgs, lineinfos, idents, options, linter] + +import std/strutils except Letters +import + std/[ + ], + ast/[ + ast, + lineinfos, + idents, + linter + ], + front/[ + msgs, + options + ] + + proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) = let line = sourceLine(conf, info) diff --git a/compiler/plugins/active.nim b/compiler/plugins/active.nim index 19c320aae72..a6f5ca97ae5 100644 --- a/compiler/plugins/active.nim +++ b/compiler/plugins/active.nim @@ -10,7 +10,17 @@ ## Include file that imports all plugins that are active. import - ".." / [pluginsupport, idents, ast], locals, itersgen + ast/[ + idents, + ast + ], + utils/[ + pluginsupport + ], + plugins/[ + locals, itersgen + ] + const plugins: array[2, Plugin] = [ diff --git a/compiler/plugins/itersgen.nim b/compiler/plugins/itersgen.nim index 043c3ce6d36..86d634c7c0c 100644 --- a/compiler/plugins/itersgen.nim +++ b/compiler/plugins/itersgen.nim @@ -9,8 +9,22 @@ ## Plugin to transform an inline iterator into a data structure. -import ".." / [ - ast, modulegraphs, lookups, semdata, lambdalifting, msgs, reports] +import + ast/[ + reports, + ast + ], + modules/[ + modulegraphs + ], + front/[ + msgs + ], + sem/[ + lookups, + semdata, + lambdalifting + ] proc iterToProcImpl*(c: PContext, n: PNode): PNode = result = newNodeI(nkStmtList, n.info) diff --git a/compiler/plugins/locals.nim b/compiler/plugins/locals.nim index c03a6986e44..35307d78083 100644 --- a/compiler/plugins/locals.nim +++ b/compiler/plugins/locals.nim @@ -9,8 +9,20 @@ ## The builtin 'system.locals' implemented as a plugin. -import ".." / [ast, astalgo, - magicsys, lookups, semdata, lowerings] +import + ast/[ + ast, + astalgo, + ], + modules/[ + magicsys, + ], + sem/[ + semdata, + lowerings, + lookups + ] + proc semLocals*(c: PContext, n: PNode): PNode = var counter = 0 diff --git a/compiler/aliases.nim b/compiler/sem/aliases.nim similarity index 98% rename from compiler/aliases.nim rename to compiler/sem/aliases.nim index 0006c9fe636..b6381085103 100644 --- a/compiler/aliases.nim +++ b/compiler/sem/aliases.nim @@ -9,8 +9,17 @@ ## Simple alias analysis for the HLO and the code generators. + import - ast, astalgo, types, trees, intsets + std/[ + intsets + ], + ast/[ + ast, + astalgo, + types, + trees + ] type TAnalysisResult* = enum diff --git a/compiler/closureiters.nim b/compiler/sem/closureiters.nim similarity index 99% rename from compiler/closureiters.nim rename to compiler/sem/closureiters.nim index 45539f35c9c..45c689f1059 100644 --- a/compiler/closureiters.nim +++ b/compiler/sem/closureiters.nim @@ -129,9 +129,27 @@ # break :stateLoop import - ast, msgs, idents, - renderer, magicsys, lowerings, lambdalifting, modulegraphs, lineinfos, - tables, options + std/[ + tables + ], + ast/[ + ast, + idents, + renderer, + lineinfos + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + options, + msgs + ], + sem/[ + lowerings, + lambdalifting + ] type Ctx = object diff --git a/compiler/concepts.nim b/compiler/sem/concepts.nim similarity index 98% rename from compiler/concepts.nim rename to compiler/sem/concepts.nim index 384d90377d0..143d6bd4ff9 100644 --- a/compiler/concepts.nim +++ b/compiler/sem/concepts.nim @@ -11,10 +11,28 @@ ## for details. Note this is a first implementation and only the "Concept matching" ## section has been implemented. -import ast, astalgo, semdata, lookups, lineinfos, idents, - msgs, renderer, types, intsets, reports +import + std/[ + intsets + ], + ast/[ + ast, + astalgo, + renderer, + types, + reports, + idents, + lineinfos + ], + front/[ + msgs + ], + sem/[ + lookups, + semdata + ] -from magicsys import addSonSkipIntLit +from modules/magicsys import addSonSkipIntLit const logBindings = false diff --git a/compiler/debuginfo.nim b/compiler/sem/debuginfo.nim similarity index 100% rename from compiler/debuginfo.nim rename to compiler/sem/debuginfo.nim diff --git a/compiler/dfa.nim b/compiler/sem/dfa.nim similarity index 99% rename from compiler/dfa.nim rename to compiler/sem/dfa.nim index 7e7fb4d91f5..5d33aa6a468 100644 --- a/compiler/dfa.nim +++ b/compiler/sem/dfa.nim @@ -29,7 +29,17 @@ ## "A Graph–Free Approach to Data–Flow Analysis" by Markus Mohnen. ## https://link.springer.com/content/pdf/10.1007/3-540-45937-5_6.pdf -import ast, intsets, renderer +import + std/[ + intsets + ], + ast/[ + renderer + ], + ast/[ + ast + ] + import std/private/asciitables type diff --git a/compiler/evaltempl.nim b/compiler/sem/evaltempl.nim similarity index 98% rename from compiler/evaltempl.nim rename to compiler/sem/evaltempl.nim index 5da5456146a..444c218f5a7 100644 --- a/compiler/evaltempl.nim +++ b/compiler/sem/evaltempl.nim @@ -10,8 +10,18 @@ ## Template evaluation engine. Now hygienic. import - options, ast, astalgo, msgs, renderer, lineinfos, idents, - reports + ast/[ + ast, + astalgo, + lineinfos, + idents, + renderer, + reports + ], + front/[ + options, + msgs + ] type TemplCtx = object diff --git a/compiler/guards.nim b/compiler/sem/guards.nim similarity index 99% rename from compiler/guards.nim rename to compiler/sem/guards.nim index 048aefc753f..645231e653f 100644 --- a/compiler/guards.nim +++ b/compiler/sem/guards.nim @@ -9,8 +9,32 @@ ## This module implements the 'implies' relation for guards. -import ast, astalgo, msgs, magicsys, nimsets, trees, types, renderer, idents, - saturate, modulegraphs, options, lineinfos, int128, reports +import + ast/[ + ast, + astalgo, + renderer, + idents, + nimsets, + trees, + types, + lineinfos, + reports + ], + utils/[ + saturate, + int128, + ], + modules/[ + magicsys, + modulegraphs, + ], + front/[ + msgs, + options, + ] + + const someEq = {mEqI, mEqF64, mEqEnum, mEqCh, mEqB, mEqRef, mEqProc, diff --git a/compiler/hlo.nim b/compiler/sem/hlo.nim similarity index 100% rename from compiler/hlo.nim rename to compiler/sem/hlo.nim diff --git a/compiler/injectdestructors.nim b/compiler/sem/injectdestructors.nim similarity index 99% rename from compiler/injectdestructors.nim rename to compiler/sem/injectdestructors.nim index 3ca4483dcf2..3c2eea71ffe 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/sem/injectdestructors.nim @@ -14,12 +14,40 @@ ## See doc/destructors.rst for a spec of the implemented rewrite rules import - intsets, strtabs, ast, astalgo, msgs, renderer, magicsys, types, idents, - strutils, options, dfa, lowerings, tables, modulegraphs, - lineinfos, parampatterns, sighashes, liftdestructors, optimizer, - varpartitions, reports - -from trees import exprStructuralEquivalent, getRoot + std/[ + intsets, + strtabs, + strutils, + tables + ], + ast/[ + ast, + astalgo, + renderer, + types, + idents, + lineinfos, + reports + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + dfa, + lowerings, + parampatterns, + sighashes, + liftdestructors, + optimizer, + varpartitions + ] + +from ast/trees import exprStructuralEquivalent, getRoot type Con = object diff --git a/compiler/isolation_check.nim b/compiler/sem/isolation_check.nim similarity index 98% rename from compiler/isolation_check.nim rename to compiler/sem/isolation_check.nim index 777e7f6ce80..18542e90a23 100644 --- a/compiler/isolation_check.nim +++ b/compiler/sem/isolation_check.nim @@ -11,7 +11,14 @@ ## https://github.com/nim-lang/RFCs/issues/244 for more details. import - ast, types, renderer, intsets + ast/[ + ast, + types, + renderer, + ], + std/[ + intsets + ] proc canAlias(arg, ret: PType; marker: var IntSet): bool diff --git a/compiler/lambdalifting.nim b/compiler/sem/lambdalifting.nim similarity index 99% rename from compiler/lambdalifting.nim rename to compiler/sem/lambdalifting.nim index 4a465a64da9..6cfabcbbef2 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/sem/lambdalifting.nim @@ -10,9 +10,33 @@ # This file implements lambda lifting for the transformator. import - intsets, options, ast, astalgo, msgs, reports, - idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos, - transf, liftdestructors, typeallowed + std/[ + intsets, + tables + ], + ast/[ + ast, + astalgo, + reports, + idents, + renderer, + types, + lineinfos + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + options, + msgs + ], + sem/[ + typeallowed, + liftdestructors, + transf, + lowerings + ] discard """ The basic approach is that captured vars need to be put on the heap and diff --git a/compiler/liftdestructors.nim b/compiler/sem/liftdestructors.nim similarity index 99% rename from compiler/liftdestructors.nim rename to compiler/sem/liftdestructors.nim index 6ae3cf55a65..769b04e8fc7 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/sem/liftdestructors.nim @@ -10,11 +10,37 @@ ## This module implements lifting for type-bound operations ## (``=sink``, ``=``, ``=destroy``, ``=deepCopy``). -import modulegraphs, lineinfos, idents, ast, renderer, semdata, - sighashes, lowerings, options, types, msgs, magicsys, tables, ccgutils, - reports - -from trees import isCaseObj +import + ast/[ + lineinfos, + idents, + ast, + renderer, + types, + reports, + trees + ], + std/[ + tables + ], + modules/[ + modulegraphs, + magicsys + ], + front/[ + options, + msgs + ], + utils/[ + ], + sem/[ + semdata, + sighashes, + lowerings + ], + backend/[ + ccgutils + ] type TLiftCtx = object diff --git a/compiler/liftlocals.nim b/compiler/sem/liftlocals.nim similarity index 90% rename from compiler/liftlocals.nim rename to compiler/sem/liftlocals.nim index d66f9e0d805..30dda4a9e0d 100644 --- a/compiler/liftlocals.nim +++ b/compiler/sem/liftlocals.nim @@ -10,11 +10,24 @@ ## This module implements the '.liftLocals' pragma. import - options, ast, msgs, reports, - idents, renderer, types, lowerings, lineinfos + ast/[ + reports, + idents, + renderer, + types, + lineinfos, + ast + ], + front/[ + options, + msgs + ], + sem/[ + lowerings + ] -from pragmas import getPragmaVal -from wordrecg import wLiftLocals +from sem/pragmas import getPragmaVal +from ast/wordrecg import wLiftLocals type Ctx = object diff --git a/compiler/lookups.nim b/compiler/sem/lookups.nim similarity index 99% rename from compiler/lookups.nim rename to compiler/sem/lookups.nim index 1356fb88ac2..f06de288a32 100644 --- a/compiler/lookups.nim +++ b/compiler/sem/lookups.nim @@ -8,11 +8,36 @@ # # This module implements lookup helpers. -import std/[algorithm, strutils] + import - intsets, ast, astalgo, idents, semdata, msgs, options, - renderer, nimfix/prettybase, lineinfos, modulegraphs, - errorhandling, errorreporting, reports + std/[ + algorithm, + strutils, + intsets + ], + ast/[ + ast, + astalgo, + idents, + renderer, + lineinfos, + errorhandling, + errorreporting, + reports + ], + modules/[ + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + semdata + ], + nimfix/[ + prettybase + ] proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) @@ -385,7 +410,7 @@ proc addDecl*(c: PContext, sym: PSym) {.inline.} = proc addPrelimDecl*(c: PContext, sym: PSym) = discard c.currentScope.addUniqueSym(sym) -from ic / ic import addHidden +from ic/ic import addHidden proc addInterfaceDeclAux(c: PContext, sym: PSym) = ## adds symbol to the module for either private or public access. diff --git a/compiler/lowerings.nim b/compiler/sem/lowerings.nim similarity index 98% rename from compiler/lowerings.nim rename to compiler/sem/lowerings.nim index 2ad35e44356..c1472c0fb6b 100644 --- a/compiler/lowerings.nim +++ b/compiler/sem/lowerings.nim @@ -12,8 +12,23 @@ const genPrefix* = ":tmp" # prefix for generated names -import ast, astalgo, types, idents, magicsys, msgs, options, modulegraphs, - lineinfos, reports +import + ast/[ + ast, + astalgo, + types, + idents, + lineinfos, + reports + ], + modules/[ + modulegraphs, + magicsys + ], + front/[ + msgs, + options + ] proc newDeref*(n: PNode): PNode {.inline.} = result = newNodeIT(nkHiddenDeref, n.info, n.typ[0]) diff --git a/compiler/macrocacheimpl.nim b/compiler/sem/macrocacheimpl.nim similarity index 95% rename from compiler/macrocacheimpl.nim rename to compiler/sem/macrocacheimpl.nim index c869c22894c..14d205a5302 100644 --- a/compiler/macrocacheimpl.nim +++ b/compiler/sem/macrocacheimpl.nim @@ -9,7 +9,15 @@ ## This module implements helpers for the macro cache. -import lineinfos, ast, vmdef +import + ast/[ + lineinfos, + ast + ], + vm/[ + vmdef + ] + proc append(c: PCtx; n: PNode) = c.vmstateDiff.add((c.module, n)) diff --git a/compiler/nilcheck.nim b/compiler/sem/nilcheck.nim similarity index 99% rename from compiler/nilcheck.nim rename to compiler/sem/nilcheck.nim index 92af849fd06..a5d05edeb73 100644 --- a/compiler/nilcheck.nim +++ b/compiler/sem/nilcheck.nim @@ -7,10 +7,39 @@ # distribution, for details about the copyright. # -import ast, renderer, intsets, tables, msgs, options, lineinfos, - strformat, idents, treetab, hashes, reports, nilcheck_enums -import sequtils, strutils, sets +import + ast/[ + ast, + renderer, + lineinfos, + idents, + reports, + treetab, + ], + std/[ + hashes, + intsets, + tables, + strformat, + sequtils, + strutils, + sets + ], + modules/[ + magicsys, + modulegraphs, + ], + front/[ + msgs, + options, + ], + utils/[ + platform, + ], + sem/[ + nilcheck_enums + ] # IMPORTANT: notes not up to date, i'll update this comment again # diff --git a/compiler/nilcheck_enums.nim b/compiler/sem/nilcheck_enums.nim similarity index 100% rename from compiler/nilcheck_enums.nim rename to compiler/sem/nilcheck_enums.nim diff --git a/compiler/optimizer.nim b/compiler/sem/optimizer.nim similarity index 98% rename from compiler/optimizer.nim rename to compiler/sem/optimizer.nim index dbe01d7f40c..ff6bcb81364 100644 --- a/compiler/optimizer.nim +++ b/compiler/sem/optimizer.nim @@ -12,9 +12,9 @@ ## - recognize "all paths lead to 'wasMoved(x)'" import - ast, renderer, intsets + ast/[ast, renderer], std/intsets -from trees import exprStructuralEquivalent +from ast/trees import exprStructuralEquivalent const nfMarkForDeletion = nfNone # faster than a lookup table diff --git a/compiler/parampatterns.nim b/compiler/sem/parampatterns.nim similarity index 98% rename from compiler/parampatterns.nim rename to compiler/sem/parampatterns.nim index e936eca8bd5..abf730a08b1 100644 --- a/compiler/parampatterns.nim +++ b/compiler/sem/parampatterns.nim @@ -10,8 +10,22 @@ ## This module implements the pattern matching features for term rewriting ## macro support. -import strutils, ast, types, msgs, renderer, wordrecg, trees, - options, reports +import + std/[ + strutils + ], + ast/[ + ast, + types, + renderer, + wordrecg, + trees, + reports + ], + front/[ + msgs, + options + ] # we precompile the pattern here for efficiency into some internal # stack based VM :-) Why? Because it's fun; I did no benchmarks to see if that diff --git a/compiler/passaux.nim b/compiler/sem/passaux.nim similarity index 86% rename from compiler/passaux.nim rename to compiler/sem/passaux.nim index 026a11b7242..0657eb316eb 100644 --- a/compiler/passaux.nim +++ b/compiler/sem/passaux.nim @@ -10,9 +10,20 @@ ## implements some little helper passes import - ast, passes, msgs, options, reports - -from modulegraphs import ModuleGraph, PPassContext + ast/[ + ast, + reports + ], + modules/[ + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + passes + ] type VerboseRef = ref object of PPassContext diff --git a/compiler/passes.nim b/compiler/sem/passes.nim similarity index 97% rename from compiler/passes.nim rename to compiler/sem/passes.nim index cd749f1989f..8eaf7e8580d 100644 --- a/compiler/passes.nim +++ b/compiler/sem/passes.nim @@ -11,10 +11,26 @@ ## `TPass` interface. import - options, ast, llstream, msgs, - syntaxes, modulegraphs, reorder, - lineinfos, pathutils, - reports + front/[ + options, + msgs, + ], + modules/[ + modulegraphs, + ], + ast/[ + ast, + llstream, + syntaxes, + reports, + lineinfos, + ], + sem/[ + reorder, + ], + utils/[ + pathutils, + ] type TPassData* = tuple[input: PNode, closeOutput: PNode] diff --git a/compiler/patterns.nim b/compiler/sem/patterns.nim similarity index 98% rename from compiler/patterns.nim rename to compiler/sem/patterns.nim index b2c1a0ea4bb..04a721f486e 100644 --- a/compiler/patterns.nim +++ b/compiler/sem/patterns.nim @@ -11,7 +11,17 @@ ## macro support. import - ast, types, semdata, sigmatch, aliases, parampatterns, trees + ast/[ + ast, + types, + trees + ], + sem/[ + semdata, + sigmatch, + aliases, + parampatterns + ] type TPatternContext = object diff --git a/compiler/pragmas.nim b/compiler/sem/pragmas.nim similarity index 99% rename from compiler/pragmas.nim rename to compiler/sem/pragmas.nim index fd50fa8ffbc..291c8d85e11 100644 --- a/compiler/pragmas.nim +++ b/compiler/sem/pragmas.nim @@ -7,14 +7,50 @@ # distribution, for details about the copyright. # -# This module implements semantic checking for pragmas +## This module implements semantic checking for pragmas import - os, condsyms, ast, astalgo, idents, semdata, msgs, renderer, - wordrecg, ropes, options, strutils, extccomp, math, magicsys, trees, - types, lookups, lineinfos, pathutils, linter, errorhandling, reports - -from ic / ic import addCompilerProc + std/[ + strutils, + math, + os + ], + ast/[ + ast, + astalgo, + idents, + renderer, + wordrecg, + trees, + linter, + errorhandling, + reports, + lineinfos, + types + ], + modules/[ + magicsys + ], + front/[ + msgs, + condsyms, + options + ], + utils/[ + ropes, + pathutils + ], + sem/[ + semdata, + lookups + ], + backend/[ + extccomp + ] + + + +from ic/ic import addCompilerProc const FirstCallConv* = wNimcall diff --git a/compiler/procfind.nim b/compiler/sem/procfind.nim similarity index 95% rename from compiler/procfind.nim rename to compiler/sem/procfind.nim index 647f44bebe5..936a988c90e 100644 --- a/compiler/procfind.nim +++ b/compiler/sem/procfind.nim @@ -11,8 +11,20 @@ # This is needed for proper handling of forward declarations. import - ast, astalgo, msgs, semdata, types, trees, lookups, - reports + ast/[ + ast, + astalgo, + types, + trees, + reports + ], + front/[ + msgs, + ], + sem/[ + semdata, + lookups, + ] proc equalGenericParams(procA, procB: PNode): bool = if procA.len != procB.len: return false diff --git a/compiler/reorder.nim b/compiler/sem/reorder.nim similarity index 98% rename from compiler/reorder.nim rename to compiler/sem/reorder.nim index 6a82b91ebcd..d9a9f93b593 100644 --- a/compiler/reorder.nim +++ b/compiler/sem/reorder.nim @@ -1,8 +1,26 @@ import - intsets, ast, idents, algorithm, renderer, - msgs, modulegraphs, syntaxes, options, modulepaths, - lineinfos, reports + std/[ + intsets, + algorithm, + ], + ast/[ + ast, + idents, + renderer, + syntaxes, + lineinfos, + reports + ], + front/[ + msgs, + options, + ], + modules/[ + modulegraphs, + modulepaths, + ] + type DepN = ref object diff --git a/compiler/rodutils.nim b/compiler/sem/rodutils.nim similarity index 100% rename from compiler/rodutils.nim rename to compiler/sem/rodutils.nim diff --git a/compiler/sem.nim b/compiler/sem/sem.nim similarity index 96% rename from compiler/sem.nim rename to compiler/sem/sem.nim index bd2b0d91d1d..ef3f22d69b4 100644 --- a/compiler/sem.nim +++ b/compiler/sem/sem.nim @@ -10,21 +10,84 @@ # This module implements the semantic checking pass. import - ast, strutils, options, astalgo, trees, - wordrecg, ropes, msgs, idents, renderer, types, platform, math, - magicsys, nversion, nimsets, semfold, modulepaths, importer, - procfind, lookups, pragmas, passes, semdata, semtypinst, sigmatch, - intsets, transf, vmdef, vm, aliases, cgmeth, lambdalifting, - evaltempl, patterns, parampatterns, sempass2, linter, semmacrosanity, - lowerings, plugins/active, lineinfos, strtabs, int128, - isolation_check, typeallowed, modulegraphs, enumtostr, concepts, astmsgs, - errorhandling, errorreporting, reports, debugutils + std/[ + strutils, + math, + strtabs, + intsets + ], + ast/[ + ast, + astalgo, + trees, + wordrecg, + renderer, + types, + nimsets, + errorreporting, + errorhandling, + astmsgs, + reports, + lineinfos, + idents, + enumtostr, + linter + ], + modules/[ + magicsys, + modulepaths, + importer, + modulegraphs + ], + front/[ + options, + msgs + ], + utils/[ + ropes, + platform, + nversion, + debugutils, + int128 + ], + sem/[ + semfold, + concepts, + semmacrosanity, + typeallowed, + isolation_check, + procfind, + lookups, + pragmas, + passes, + semdata, + semtypinst, + sigmatch, + transf, + aliases, + lambdalifting, + sempass2, + patterns, + parampatterns, + evaltempl, + lowerings, + ], + backend/[ + cgmeth + ], + plugins/[ + active + ], + vm/[ + vmdef, + vm + ] when defined(nimfix): import nimfix/prettybase when not defined(leanCompiler): - import spawn + import sem/spawn # implementation diff --git a/compiler/semcall.nim b/compiler/sem/semcall.nim similarity index 100% rename from compiler/semcall.nim rename to compiler/sem/semcall.nim diff --git a/compiler/semdata.nim b/compiler/sem/semdata.nim similarity index 98% rename from compiler/semdata.nim rename to compiler/sem/semdata.nim index df3503de788..503b50a50b2 100644 --- a/compiler/semdata.nim +++ b/compiler/sem/semdata.nim @@ -9,19 +9,41 @@ ## This module contains the data structures for the semantic checking phase. -import tables - import - intsets, options, ast, astalgo, msgs, idents, renderer, - magicsys, vmdef, modulegraphs, lineinfos, sets, pathutils, - reports + std/[ + intsets, + sets, + tables, + strutils + ], + front/[ + options, + msgs, + ], + ast/[ + ast, + astalgo, + idents, + renderer, + lineinfos, + reports + ], + modules/[ + magicsys, + modulegraphs, + ], + vm/[ + vmdef, + ], + ic/[ + ic + ], + utils/[ + pathutils, + ] export TExprFlag, TExprFlags -import std/strutils - -import ic / ic - type TOptionEntry* = object # entries to put on a stack for pragma parsing options*: TOptions diff --git a/compiler/semexprs.nim b/compiler/sem/semexprs.nim similarity index 100% rename from compiler/semexprs.nim rename to compiler/sem/semexprs.nim diff --git a/compiler/semfields.nim b/compiler/sem/semfields.nim similarity index 100% rename from compiler/semfields.nim rename to compiler/sem/semfields.nim diff --git a/compiler/semfold.nim b/compiler/sem/semfold.nim similarity index 99% rename from compiler/semfold.nim rename to compiler/sem/semfold.nim index 4c9c44b9259..0010c9bdd39 100644 --- a/compiler/semfold.nim +++ b/compiler/sem/semfold.nim @@ -11,10 +11,35 @@ ## and evaluation phase import - strutils, options, ast, trees, nimsets, - platform, math, msgs, renderer, types, - commands, magicsys, modulegraphs, strtabs, lineinfos, - reports + ast/[ + renderer, + types, + nimsets, + ast, + trees, + lineinfos, + reports + ], + std/[ + strutils, + strtabs, + math, + ], + modules/[ + magicsys, + modulegraphs, + ], + front/[ + commands, + msgs, + options, + ], + utils/[ + platform, + ] + + + from system/memory import nimCStrLen diff --git a/compiler/semgnrc.nim b/compiler/sem/semgnrc.nim similarity index 100% rename from compiler/semgnrc.nim rename to compiler/sem/semgnrc.nim diff --git a/compiler/seminst.nim b/compiler/sem/seminst.nim similarity index 100% rename from compiler/seminst.nim rename to compiler/sem/seminst.nim diff --git a/compiler/semmacrosanity.nim b/compiler/sem/semmacrosanity.nim similarity index 97% rename from compiler/semmacrosanity.nim rename to compiler/sem/semmacrosanity.nim index d431ced0b97..d33fd52282b 100644 --- a/compiler/semmacrosanity.nim +++ b/compiler/sem/semmacrosanity.nim @@ -9,8 +9,19 @@ ## Implements type sanity checking for ASTs resulting from macros. Lots of ## room for improvement here. - -import ast, msgs, types, options, reports, strutils +import + std/[ + strutils + ], + ast/[ + ast, + types, + reports, + ], + front/[ + msgs, + options, + ] proc ithField(n: PNode, field: var int): PSym = result = nil diff --git a/compiler/semmagic.nim b/compiler/sem/semmagic.nim similarity index 100% rename from compiler/semmagic.nim rename to compiler/sem/semmagic.nim diff --git a/compiler/semobjconstr.nim b/compiler/sem/semobjconstr.nim similarity index 100% rename from compiler/semobjconstr.nim rename to compiler/sem/semobjconstr.nim diff --git a/compiler/semparallel.nim b/compiler/sem/semparallel.nim similarity index 98% rename from compiler/semparallel.nim rename to compiler/sem/semparallel.nim index 380cac589f7..ddccf20ea8c 100644 --- a/compiler/semparallel.nim +++ b/compiler/sem/semparallel.nim @@ -22,12 +22,31 @@ # - output slices need special logic (+) import - ast, astalgo, idents, lowerings, magicsys, guards, msgs, - renderer, types, modulegraphs, options, spawn, - reports - -from trees import getMagic, isTrue, getRoot -from strutils import `%` + ast/[ + ast, + astalgo, + idents, + renderer, + types, + reports + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + lowerings, + guards, + spawn + ] + + +from ast/trees import getMagic, isTrue, getRoot +from std/strutils import `%` discard """ diff --git a/compiler/sempass2.nim b/compiler/sem/sempass2.nim similarity index 99% rename from compiler/sempass2.nim rename to compiler/sem/sempass2.nim index 95e58511b99..364d516a868 100644 --- a/compiler/sempass2.nim +++ b/compiler/sem/sempass2.nim @@ -8,10 +8,43 @@ # import - intsets, ast, astalgo, msgs, renderer, magicsys, types, idents, trees, - wordrecg, strutils, options, guards, lineinfos, semfold, semdata, - modulegraphs, varpartitions, typeallowed, nilcheck, tables, errorreporting, - errorhandling, reports, debugutils + std/[ + strutils, + tables, + intsets, + ], + ast/[ + ast, + renderer, + astalgo, + types, + idents, + wordrecg, + reports, + errorreporting, + errorhandling, + lineinfos, + trees, + ], + front/[ + options, + msgs, + ], + modules/[ + modulegraphs, + magicsys, + ], + utils/[ + debugutils + ], + sem/[ + varpartitions, + typeallowed, + guards, + semfold, + semdata, + nilcheck, + ] when defined(useDfa): import dfa diff --git a/compiler/semstmts.nim b/compiler/sem/semstmts.nim similarity index 100% rename from compiler/semstmts.nim rename to compiler/sem/semstmts.nim diff --git a/compiler/semtempl.nim b/compiler/sem/semtempl.nim similarity index 100% rename from compiler/semtempl.nim rename to compiler/sem/semtempl.nim diff --git a/compiler/semtypes.nim b/compiler/sem/semtypes.nim similarity index 100% rename from compiler/semtypes.nim rename to compiler/sem/semtypes.nim diff --git a/compiler/semtypinst.nim b/compiler/sem/semtypinst.nim similarity index 99% rename from compiler/semtypinst.nim rename to compiler/sem/semtypinst.nim index fb519b66034..d69a12196b0 100644 --- a/compiler/semtypinst.nim +++ b/compiler/sem/semtypinst.nim @@ -9,8 +9,29 @@ # This module does the instantiation of generic types. -import ast, astalgo, msgs, types, magicsys, semdata, renderer, options, - lineinfos, modulegraphs, reports, strutils +import + std/[ + strutils + ], + ast/[ + ast, + astalgo, + types, + renderer, + lineinfos, + reports, + ], + modules/[ + magicsys, + modulegraphs, + ], + front/[ + msgs, + options, + ], + sem/[ + semdata, + ] from concepts import makeTypeDesc diff --git a/compiler/sighashes.nim b/compiler/sem/sighashes.nim similarity index 98% rename from compiler/sighashes.nim rename to compiler/sem/sighashes.nim index d02728627ca..2c454cdeb53 100644 --- a/compiler/sighashes.nim +++ b/compiler/sem/sighashes.nim @@ -8,10 +8,22 @@ # ## Computes hash values for routine (proc, method etc) signatures. - -import ast, tables, ropes, md5, modulegraphs -from hashes import Hash -import types +import + std/[ + tables, + md5, + hashes + ], + ast/[ + ast, + types + ], + modules/[ + modulegraphs + ], + utils/[ + ropes + ] proc `&=`(c: var MD5Context, s: string) = md5Update(c, s, s.len) proc `&=`(c: var MD5Context, ch: char) = diff --git a/compiler/sigmatch.nim b/compiler/sem/sigmatch.nim similarity index 99% rename from compiler/sigmatch.nim rename to compiler/sem/sigmatch.nim index 3e48cff701f..1700312e202 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sem/sigmatch.nim @@ -9,12 +9,44 @@ ## This module implements the signature matching for resolving ## the call to overloaded procs, generic procs and operators. - import - intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst, - magicsys, idents, lexer, options, parampatterns, strutils, trees, - linter, lineinfos, lowerings, modulegraphs, concepts, errorhandling, - reports, debugutils + std/[ + intsets, + strutils, + ], + ast/[ + ast, + astalgo, + types, + renderer, + idents, + lexer, + trees, + linter, + lineinfos, + errorhandling, + reports, + ], + modules/[ + modulegraphs, + magicsys, + ], + front/[ + msgs, + options, + ], + utils/[ + debugutils + ], + sem/[ + semdata, + semtypinst, + lookups, + lowerings, + parampatterns, + concepts, + ] + type MismatchInfo* = object @@ -1623,7 +1655,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, elif a.len > 0 and a.lastSon == f: # Needed for checking `Y` == `Addable` in the following #[ - type + type Addable = concept a, type A a + a is A MyType[T: Addable; Y: static T] = object @@ -1742,7 +1774,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, elif f.base.kind == tyGenericParam: # Handling things like `type A[T; Y: static T] = object`, the reason this is here is the following: # The information is lost in the future steps so eventually it gets `T` vs. `T` which can be solved with a change to the tyTypedesc branch, - # but it then gets typedesc[int] vs. int literal (2) without knowing either side is static. + # but it then gets typedesc[int] vs. int literal (2) without knowing either side is static. # Seems the only place to solve it is here anywhere lower just lacks the knowledge to know to check the children types. if f.base.len > 0: # There is a constraint, handle it result = typeRel(c, f.base.lastSon, a, flags) @@ -2686,7 +2718,7 @@ proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo; if op == attachedDeepCopy: assert sfFromGeneric in result.flags -include suggest +include tools/suggest when not declared(tests): template tests(s: untyped) = discard diff --git a/compiler/sinkparameter_inference.nim b/compiler/sem/sinkparameter_inference.nim similarity index 100% rename from compiler/sinkparameter_inference.nim rename to compiler/sem/sinkparameter_inference.nim diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sem/sizealignoffsetimpl.nim similarity index 100% rename from compiler/sizealignoffsetimpl.nim rename to compiler/sem/sizealignoffsetimpl.nim diff --git a/compiler/sourcemap.nim b/compiler/sem/sourcemap.nim similarity index 98% rename from compiler/sourcemap.nim rename to compiler/sem/sourcemap.nim index b87de75f35e..65635268112 100644 --- a/compiler/sourcemap.nim +++ b/compiler/sem/sourcemap.nim @@ -1,4 +1,10 @@ -import os, strformat, strutils, tables, sets, ropes, json, algorithm +import + std/[ + os, strformat, strutils, tables, sets, json, algorithm + ], + utils/[ + ropes + ] type SourceNode* = ref object @@ -160,7 +166,7 @@ proc parse*(source: string, path: string): SourceNode = let lines = source.splitLines() var lastLocation: SourceNode = nil result = newSourceNode(0, 0, path, @[]) - + # we just use one single parent and add all nim lines # as its children, I guess in typical codegen # that happens recursively on ast level @@ -171,7 +177,7 @@ proc parse*(source: string, path: string): SourceNode = let line = originalLine.strip if line.len == 0: continue - + # this shouldn't be a problem: # jsgen doesn't generate comments # and if you emit // line you probably know what you're doing @@ -181,7 +187,7 @@ proc parse*(source: string, path: string): SourceNode = let pos = line.find(" ", 8) let lineNumber = line[8 .. pos - 1].parseInt let linePath = line[pos + 2 .. ^2] # quotes - + lastLocation = newSourceNode( lineNumber, 0, @@ -194,8 +200,8 @@ proc parse*(source: string, path: string): SourceNode = var name = "" if token[0]: name = token[1].split('_', 1)[0] - - + + if result.children.len > 0: result.children[^1].node.children.add( child( @@ -372,7 +378,7 @@ proc toSourceMap*(node: SourceNode, file: string): SourceMapGenerator = name: original.name)) else: generated.column += 1 - + map diff --git a/compiler/spawn.nim b/compiler/sem/spawn.nim similarity index 98% rename from compiler/spawn.nim rename to compiler/sem/spawn.nim index c9ebfb8d070..7ad2cffee59 100644 --- a/compiler/spawn.nim +++ b/compiler/sem/spawn.nim @@ -8,10 +8,27 @@ # ## This module implements threadpool's ``spawn``. - -import ast, types, idents, magicsys, msgs, options, modulegraphs, - lowerings, liftdestructors, renderer, reports -from trees import getMagic, getRoot +import + ast/[ + trees, + ast, + types, + idents, + renderer, + reports + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + msgs, + options + ], + sem/[ + lowerings, + liftdestructors + ] proc callProc(a: PNode): PNode = result = newNodeI(nkCall, a.info) diff --git a/compiler/transf.nim b/compiler/sem/transf.nim similarity index 98% rename from compiler/transf.nim rename to compiler/sem/transf.nim index 0573a7f0b7e..5d797019b53 100644 --- a/compiler/transf.nim +++ b/compiler/sem/transf.nim @@ -7,23 +7,45 @@ # distribution, for details about the copyright. # -# This module implements the transformator. It transforms the syntax tree -# to ease the work of the code generators. Does some transformations: -# -# * inlines iterators -# * inlines constants -# * performs constant folding -# * converts "continue" to "break"; disambiguates "break" -# * introduces method dispatchers -# * performs lambda lifting for closure support -# * transforms 'defer' into a 'try finally' statement +## This module implements the transformator. It transforms the syntax tree +## to ease the work of the code generators. Does some transformations: +## +## * inlines iterators +## * inlines constants +## * performs constant folding +## * converts "continue" to "break"; disambiguates "break" +## * introduces method dispatchers +## * performs lambda lifting for closure support +## * transforms 'defer' into a 'try finally' statement import - options, ast, astalgo, trees, msgs, reports, - idents, renderer, types, semfold, magicsys, cgmeth, - lowerings, liftlocals, - modulegraphs, lineinfos, - errorreporting + ast/[ + ast, + astalgo, + trees, + reports, + idents, + renderer, + types, + lineinfos, + errorreporting + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + options, + msgs + ], + sem/[ + liftlocals, + semfold, + lowerings + ], + backend/[ + cgmeth + ] proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, cache: bool): PNode diff --git a/compiler/typeallowed.nim b/compiler/sem/typeallowed.nim similarity index 98% rename from compiler/typeallowed.nim rename to compiler/sem/typeallowed.nim index 138b4f27ee6..60c1e11422d 100644 --- a/compiler/typeallowed.nim +++ b/compiler/sem/typeallowed.nim @@ -11,7 +11,20 @@ ## for invalid types like 'openArray[var int]'. import - intsets, ast, renderer, options, semdata, types + std/[ + intsets, + ], + ast/[ + ast, + renderer, + types + ], + front/[ + options, + ], + sem/[ + semdata, + ] export TTypeAllowedFlag, TTypeAllowedFlags diff --git a/compiler/varpartitions.nim b/compiler/sem/varpartitions.nim similarity index 99% rename from compiler/varpartitions.nim rename to compiler/sem/varpartitions.nim index 0da3ea288b8..6c7d0f3c727 100644 --- a/compiler/varpartitions.nim +++ b/compiler/sem/varpartitions.nim @@ -28,9 +28,26 @@ ## See https://nim-lang.github.io/Nim/manual_experimental.html#view-types-algorithm ## for a high-level description of how borrow checking works. -import ast, types, lineinfos, options, msgs, renderer, typeallowed, modulegraphs, - reports -from trees import getMagic, isNoSideEffectPragma, stupidStmtListExpr +import + ast/[ + ast, + lineinfos, + types, + renderer, + reports + ], + front/[ + options, + msgs, + ], + sem/[ + typeallowed, + ], + modules/[ + modulegraphs, + ] + +from ast/trees import getMagic, isNoSideEffectPragma, stupidStmtListExpr from isolation_check import canAlias type diff --git a/compiler/docgen.nim b/compiler/tools/docgen.nim similarity index 99% rename from compiler/docgen.nim rename to compiler/tools/docgen.nim index 0944cc136ce..e6e4679402f 100644 --- a/compiler/docgen.nim +++ b/compiler/tools/docgen.nim @@ -11,18 +11,54 @@ # by knowing how the anchors are going to be named. import - ast, strutils, strtabs, algorithm, sequtils, options, msgs, os, idents, - wordrecg, syntaxes, renderer, lexer, - packages/docutils/rst, packages/docutils/rstgen, - json, xmltree, trees, types, - typesrenderer, astalgo, lineinfos, intsets, - pathutils, tables, nimpaths, renderverbatim, osproc, reports + std/[ + strutils, + strtabs, + algorithm, + sequtils, + os, + json, + xmltree, + intsets, + tables, + osproc + ], + ast/[ + ast, + idents, + wordrecg, + syntaxes, + renderer, + lexer, + trees, + types, + typesrenderer, + astalgo, + lineinfos, + renderverbatim, + reports + ], + modules/[ + nimpaths + ], + front/[ + options, + msgs + ], + utils/[ + pathutils, + ] + + +import + packages/docutils/rst, + packages/docutils/rstgen import packages/docutils/rstast except FileIndex, TLineInfo -from uri import encodeUrl +from std/uri import encodeUrl from std/private/globs import nativeToUnixPath -from nodejs import findNodeJs +from utils/nodejs import findNodeJs const exportSection = skField diff --git a/compiler/docgen2.nim b/compiler/tools/docgen2.nim similarity index 92% rename from compiler/docgen2.nim rename to compiler/tools/docgen2.nim index bfdb4568ca2..e7a3c190acd 100644 --- a/compiler/docgen2.nim +++ b/compiler/tools/docgen2.nim @@ -11,9 +11,26 @@ # semantic checking. import - options, ast, msgs, passes, docgen, lineinfos, pathutils - -from modulegraphs import ModuleGraph, PPassContext + ast/[ + ast, + lineinfos + ], + front/[ + options, + msgs + ], + utils/[ + pathutils + ], + sem/[ + passes + ], + tools/[ + docgen + ] + + +from modules/modulegraphs import ModuleGraph, PPassContext type TGen = object of PPassContext diff --git a/compiler/suggest.nim b/compiler/tools/suggest.nim similarity index 99% rename from compiler/suggest.nim rename to compiler/tools/suggest.nim index 5cf8113e169..1b832d0bd03 100644 --- a/compiler/suggest.nim +++ b/compiler/tools/suggest.nim @@ -32,11 +32,24 @@ # included from sigmatch.nim -import algorithm, sets, prefixmatches, parseutils, tables -from wordrecg import wDeprecated, wError, wAddr, wYield +import + std/[ + algorithm, + parseutils, + sets, + tables + ], + ast/[ + wordrecg + ], + utils/[ + prefixmatches + ] + + when defined(nimsuggest): - import passes, tables, pathutils # importer + import sem/passes, std/tables, utils/pathutils # importer const sep = '\t' diff --git a/compiler/bitsets.nim b/compiler/utils/bitsets.nim similarity index 100% rename from compiler/bitsets.nim rename to compiler/utils/bitsets.nim diff --git a/compiler/btrees.nim b/compiler/utils/btrees.nim similarity index 100% rename from compiler/btrees.nim rename to compiler/utils/btrees.nim diff --git a/compiler/debugutils.nim b/compiler/utils/debugutils.nim similarity index 99% rename from compiler/debugutils.nim rename to compiler/utils/debugutils.nim index ea56b9bb38a..1ef7347ff55 100644 --- a/compiler/debugutils.nim +++ b/compiler/utils/debugutils.nim @@ -12,7 +12,14 @@ useful debugging flags: ]# -import options, reports, msgs +import + front/[ + options, + msgs + ], + ast/[ + reports, + ] proc isCompilerDebug*(conf: ConfigRef): bool {.inline.} = ##[ diff --git a/compiler/int128.nim b/compiler/utils/int128.nim similarity index 100% rename from compiler/int128.nim rename to compiler/utils/int128.nim diff --git a/compiler/nodejs.nim b/compiler/utils/nodejs.nim similarity index 100% rename from compiler/nodejs.nim rename to compiler/utils/nodejs.nim diff --git a/compiler/nversion.nim b/compiler/utils/nversion.nim similarity index 100% rename from compiler/nversion.nim rename to compiler/utils/nversion.nim diff --git a/compiler/pathutils.nim b/compiler/utils/pathutils.nim similarity index 100% rename from compiler/pathutils.nim rename to compiler/utils/pathutils.nim diff --git a/compiler/platform.nim b/compiler/utils/platform.nim similarity index 100% rename from compiler/platform.nim rename to compiler/utils/platform.nim diff --git a/compiler/pluginsupport.nim b/compiler/utils/pluginsupport.nim similarity index 93% rename from compiler/pluginsupport.nim rename to compiler/utils/pluginsupport.nim index a44436f11a6..02bc053e7ba 100644 --- a/compiler/pluginsupport.nim +++ b/compiler/utils/pluginsupport.nim @@ -11,7 +11,15 @@ ## need to be built with the compiler only: plugins using ## DLLs or the FFI will not work. -import ast, semdata, idents +import + ast/[ + ast, + idents + ], + sem/[ + semdata + ] + type Transformation* = proc (c: PContext; n: PNode): PNode {.nimcall.} diff --git a/compiler/prefixmatches.nim b/compiler/utils/prefixmatches.nim similarity index 100% rename from compiler/prefixmatches.nim rename to compiler/utils/prefixmatches.nim diff --git a/compiler/ropes.nim b/compiler/utils/ropes.nim similarity index 100% rename from compiler/ropes.nim rename to compiler/utils/ropes.nim diff --git a/compiler/saturate.nim b/compiler/utils/saturate.nim similarity index 100% rename from compiler/saturate.nim rename to compiler/utils/saturate.nim diff --git a/compiler/strutils2.nim b/compiler/utils/strutils2.nim similarity index 100% rename from compiler/strutils2.nim rename to compiler/utils/strutils2.nim diff --git a/compiler/evalffi.nim b/compiler/vm/evalffi.nim similarity index 100% rename from compiler/evalffi.nim rename to compiler/vm/evalffi.nim diff --git a/compiler/gorgeimpl.nim b/compiler/vm/gorgeimpl.nim similarity index 91% rename from compiler/gorgeimpl.nim rename to compiler/vm/gorgeimpl.nim index d4aeb6a77e4..4849721f1c4 100644 --- a/compiler/gorgeimpl.nim +++ b/compiler/vm/gorgeimpl.nim @@ -9,8 +9,23 @@ ## Module that implements ``gorge`` for the compiler. -import msgs, std / sha1, os, osproc, streams, options, - lineinfos, pathutils +import + std/[ + sha1, + os, + osproc, + streams, + ], + ast/[ + lineinfos + ], + front/[ + msgs, + options + ], + utils/[ + pathutils + ] proc readOutput(p: Process): (string, int) = result[0] = "" diff --git a/compiler/nimeval.nim b/compiler/vm/nimeval.nim similarity index 94% rename from compiler/nimeval.nim rename to compiler/vm/nimeval.nim index 8cb01780228..e50b3095b8b 100644 --- a/compiler/nimeval.nim +++ b/compiler/vm/nimeval.nim @@ -8,12 +8,45 @@ # ## exposes the Nim VM to clients. + import - ast, astalgo, modules, passes, condsyms, - options, sem, llstream, lineinfos, vm, - vmdef, modulegraphs, idents, os, pathutils, - passaux, scriptconfig, std/compilesettings, - reports + std/[ + compilesettings, + os + ], + ast/[ + ast, + astalgo, + llstream, + lineinfos, + idents, + reports + ], + modules/[ + modules, + modulegraphs + ], + front/[ + condsyms, + options, + scriptconfig + ], + utils/[ + pathutils + ], + sem/[ + passes, + sem, + passaux + ], + backend/[ + ], + plugins/[ + ], + vm/[ + vmdef, + vm + ] type Interpreter* = ref object ## Use Nim as an interpreter with this object diff --git a/compiler/vm.nim b/compiler/vm/vm.nim similarity index 99% rename from compiler/vm.nim rename to compiler/vm/vm.nim index 811f7140cdf..3cbec1b3459 100644 --- a/compiler/vm.nim +++ b/compiler/vm/vm.nim @@ -10,20 +10,57 @@ ## This file implements the new evaluation engine for Nim code. ## An instruction is 1-3 int32s in memory, it is a register based VM. - import - std/[strutils, tables, parseutils], - msgs, vmdef, vmgen, nimsets, types, passes, reports, - parser, vmdeps, idents, trees, renderer, options, transf, - gorgeimpl, lineinfos, btrees, macrocacheimpl, - modulegraphs, sighashes, int128, vmprofiler, - debugutils, astalgo, - cli_reporter - -import ast except getstr -from semfold import leValueConv, ordinalValToString -from evaltempl import evalTemplate -from magicsys import getSysType + std/[ + strutils, + tables, + parseutils + ], + ast/[ + astalgo, + lineinfos, + renderer, # toStrLit implementation + trees, + idents, + reports, + types, + nimsets, + parser # `parseExpr()` and `parseStmt()` + ], + modules/[ + modulegraphs, + magicsys + ], + front/[ + options, + msgs, + cli_reporter # Imported to generate literal error message for VM exception + # handling + ], + utils/[ + debugutils, + int128, + btrees + ], + sem/[ + sighashes, + macrocacheimpl, + transf, + passes, + evaltempl, + semfold + ], + vm/[ + vmprofiler, + gorgeimpl, + vmdeps, + vmgen, + vmdef + ] + + +import ast/ast except getstr + const traceCode = defined(nimVMDebug) diff --git a/compiler/vm_enums.nim b/compiler/vm/vm_enums.nim similarity index 100% rename from compiler/vm_enums.nim rename to compiler/vm/vm_enums.nim diff --git a/compiler/vmconv.nim b/compiler/vm/vmconv.nim similarity index 98% rename from compiler/vmconv.nim rename to compiler/vm/vmconv.nim index b82fb2ff319..3a3491012ef 100644 --- a/compiler/vmconv.nim +++ b/compiler/vm/vmconv.nim @@ -1,4 +1,4 @@ -import ast +import ast/ast template elementType*(T: typedesc): typedesc = typeof(block: diff --git a/compiler/vmdef.nim b/compiler/vm/vmdef.nim similarity index 97% rename from compiler/vmdef.nim rename to compiler/vm/vmdef.nim index 1f1615cf7db..c5ba72ac80c 100644 --- a/compiler/vmdef.nim +++ b/compiler/vm/vmdef.nim @@ -12,8 +12,22 @@ import tables -import ast, idents, options, modulegraphs, - lineinfos, reports, debugutils +import + ast/[ + ast, + idents, + lineinfos, + reports, + ], + modules/[ + modulegraphs, + ], + front/[ + options, + ], + utils/[ + debugutils + ] import vm_enums export vm_enums diff --git a/compiler/vmdeps.nim b/compiler/vm/vmdeps.nim similarity index 98% rename from compiler/vmdeps.nim rename to compiler/vm/vmdeps.nim index 11e3b32ff1b..0d742212021 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vm/vmdeps.nim @@ -7,8 +7,24 @@ # distribution, for details about the copyright. # -import ast, types, msgs, os, options, idents, lineinfos, reports -from pathutils import AbsoluteFile +import + std/[ + os + ], + ast/[ + types, + ast, + idents, + lineinfos, + reports + ], + front/[ + msgs, + options + ], + utils/[ + pathutils + ] proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string = try: diff --git a/compiler/vmgen.nim b/compiler/vm/vmgen.nim similarity index 99% rename from compiler/vmgen.nim rename to compiler/vm/vmgen.nim index 746d86f5468..e5245f7e61d 100644 --- a/compiler/vmgen.nim +++ b/compiler/vm/vmgen.nim @@ -27,14 +27,38 @@ # solves the opcLdConst vs opcAsgnConst issue. Of course whether we need # this copy depends on the involved types. -import tables - import - strutils, ast, types, msgs, renderer, vmdef, reports, - intsets, magicsys, options, lowerings, lineinfos, transf, astmsgs, - debugutils - -from modulegraphs import getBody + std/[ + tables, + strutils, + intsets + ], + ast/[ + renderer, + types, + ast, + reports, + lineinfos, + astmsgs + ], + modules/[ + magicsys, + modulegraphs + ], + front/[ + msgs, + options + ], + utils/[ + debugutils + ], + sem/[ + lowerings, + transf + ], + vm/[ + vmdef + ] when defined(nimCompilerStacktraceHints): import std/stackframes @@ -43,7 +67,7 @@ const debugEchoCode* = defined(nimVMDebug) when hasFFI: - import evalffi + import vm/evalffi type TGenFlag = enum diff --git a/compiler/vmhooks.nim b/compiler/vm/vmhooks.nim similarity index 98% rename from compiler/vmhooks.nim rename to compiler/vm/vmhooks.nim index 1ede87e5e54..eab7e8189dc 100644 --- a/compiler/vmhooks.nim +++ b/compiler/vm/vmhooks.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -import pathutils +import utils/pathutils template setX(k, field) {.dirty.} = a.slots[a.ra].ensureKind(k) diff --git a/compiler/vmops.nim b/compiler/vm/vmops.nim similarity index 100% rename from compiler/vmops.nim rename to compiler/vm/vmops.nim diff --git a/compiler/vmprofiler.nim b/compiler/vm/vmprofiler.nim similarity index 90% rename from compiler/vmprofiler.nim rename to compiler/vm/vmprofiler.nim index f586c8ffe3b..9225bdafc1d 100644 --- a/compiler/vmprofiler.nim +++ b/compiler/vm/vmprofiler.nim @@ -1,7 +1,20 @@ - import - options, vmdef, times, lineinfos, strutils, tables, - msgs + std/[ + times, + strutils, + tables + ], + ast/[ + lineinfos, + ], + front/[ + options, + msgs + ], + vm/[ + vmdef + ] + proc enter*(prof: var Profiler, c: PCtx, tos: PStackFrame) {.inline.} = if optProfileVM in c.config.globalOptions: diff --git a/doc/niminst.rst b/doc/niminst.rst index 8fff1f0e813..d0beb372c5f 100644 --- a/doc/niminst.rst +++ b/doc/niminst.rst @@ -194,4 +194,3 @@ look at its configuration file: .. include:: ../compiler/installer.ini :literal: - diff --git a/nimpretty/nimpretty.nim b/nimpretty/nimpretty.nim index c745dea6300..b35a46f87ad 100644 --- a/nimpretty/nimpretty.nim +++ b/nimpretty/nimpretty.nim @@ -12,11 +12,22 @@ when not defined(nimpretty): {.error: "This needs to be compiled with --define:nimPretty".} -import ../compiler / [ - idents, msgs, syntaxes, options, pathutils, layouter, cli_reporter +import + ast/[ + idents, + syntaxes, + layouter + ], + front/[ + msgs, + options, + cli_reporter + ], + utils/[ + pathutils, ] -import parseopt, strutils, os, sequtils +import std/[parseopt, strutils, os, sequtils] const Version = "0.2" diff --git a/nimpretty/nimpretty.nim.cfg b/nimpretty/nimpretty.nim.cfg index 25336d924e1..b840d3d344d 100644 --- a/nimpretty/nimpretty.nim.cfg +++ b/nimpretty/nimpretty.nim.cfg @@ -1 +1,2 @@ --define: nimpretty +path:"$config/../compiler" diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 050bbb91278..2c3460f7d6b 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -20,25 +20,34 @@ import std/options as std_options # suggestionResultHook, because suggest.nim is included by sigmatch. # So we import that one instead. + import - ../compiler/[ - options, - commands, - modules, - sem, - passes, - passaux, - msgs, - sigmatch, - ast, + ast/[ reports, idents, - modulegraphs, - prefixmatches, lineinfos, + ast + ], + modules/[ + modules, + modulegraphs + ], + front/[ + options, + commands, + msgs, cmdlinehelper, - pathutils, cli_reporter + ], + utils/[ + prefixmatches, + pathutils + ], + sem/[ + sem, + passes, + passaux, + sigmatch ] when defined(windows): diff --git a/nimsuggest/nimsuggest.nim.cfg b/nimsuggest/nimsuggest.nim.cfg index 394449740f8..fab3d30c2a8 100644 --- a/nimsuggest/nimsuggest.nim.cfg +++ b/nimsuggest/nimsuggest.nim.cfg @@ -20,5 +20,5 @@ define:nimcore #define:useNodeIds #define:booting #define:noDocgen ---path:"$nim" +--path:"$config/../compiler" --threads:on diff --git a/testament/testament.nim b/testament/testament.nim index a45ea7189c5..747952505d0 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -15,7 +15,7 @@ import std/[ ] import backend, azure, htmlgen, specs from std/sugar import dup -import compiler/nodejs +import utils/nodejs import lib/stdtest/testutils from lib/stdtest/specialpaths import splitTestFile from std/private/gitutils import diffStrings @@ -98,12 +98,12 @@ proc isNimRepoTests(): bool = type Category = distinct string - + TResults = object total, passed, failedButAllowed, skipped: int ## xxx rename passed to passedOrAllowedFailure data: string - + TTest = object name: string cat: Category @@ -792,7 +792,7 @@ proc main() = # action let runtype = if useMegatest: " pcat " else: " cat " cmds.add(myself & runtype & quoteShell(cat) & rest) - + if simulate: # 'see what tests would be run but don't run them (for debugging)' skips = loadSkipFrom(skipFrom) for i, cati in cats: @@ -822,7 +822,7 @@ proc main() = var cat = Category(p.key) p.next processCategory(r, cat, p.cmdLineRest, testsDir, runJoinableTests = false) - of "p", "pat", "pattern": # Run all tests matching the given pattern + of "p", "pat", "pattern": # Run all tests matching the given pattern skips = loadSkipFrom(skipFrom) let pattern = p.key p.next diff --git a/testament/testament.nim.cfg b/testament/testament.nim.cfg index 6466d4607f8..e702f97c3d6 100644 --- a/testament/testament.nim.cfg +++ b/testament/testament.nim.cfg @@ -1,6 +1,6 @@ # don't move this file without updating the logic in `isNimRepoTests` -path = "$nim" # For compiler/nodejs +path = "$config/../compiler" # For utils/nodejs path = "." # to allow for package qualified imports -d:ssl # For azure # my SSL doesn't have this feature and I don't care: diff --git a/tests/compiler/nim.cfg b/tests/compiler/nim.cfg index 6f49473aa01..c6254db264f 100644 --- a/tests/compiler/nim.cfg +++ b/tests/compiler/nim.cfg @@ -4,4 +4,5 @@ # note: without this, tests may succeed locally but fail on CI (it can succeed # locally even when compiling via `./bin/nim` because `$HOME/.nimble` is being # used). ---path:"../../" # so we can `import compiler/foo` in this dir +--path:"../../compiler" # so we can `import front/options` in this dir +--path:"../.." # so we can `import compiler/utils/btrees` in this dir diff --git a/tests/compiler/t12684.nim b/tests/compiler/t12684.nim index a5f33d2c908..b6f2131d729 100644 --- a/tests/compiler/t12684.nim +++ b/tests/compiler/t12684.nim @@ -4,4 +4,4 @@ discard """ """ var x: Undeclared -import compiler/nimeval +import std/strutils diff --git a/tests/compiler/tbrees.nim b/tests/compiler/tbrees.nim index 5f6482ed94e..361641d1d28 100644 --- a/tests/compiler/tbrees.nim +++ b/tests/compiler/tbrees.nim @@ -19,9 +19,9 @@ www.yale.edu: 130.132.143.21 ''' """ -import compiler/btrees +import compiler/utils/btrees -import random, tables +import std/[random, tables] proc main = var st = initBTree[string, string]() diff --git a/tests/compiler/tint128.nim b/tests/compiler/tint128.nim index a30b1b1ccaa..d00be40e70a 100644 --- a/tests/compiler/tint128.nim +++ b/tests/compiler/tint128.nim @@ -1,4 +1,4 @@ -import compiler/int128 +import compiler/utils/int128 let (a,b) = divMod(Ten,Ten) diff --git a/tests/compiler/tnimblecmd.nim b/tests/compiler/tnimblecmd.nim index b3ed9a29779..a2c6b8c8c18 100644 --- a/tests/compiler/tnimblecmd.nim +++ b/tests/compiler/tnimblecmd.nim @@ -1,4 +1,4 @@ -include compiler/[nimblecmd], sets +include modules/[nimblecmd], std/sets proc v(s: string): Version = s.newVersion diff --git a/tests/compiler/tpathutils.nim b/tests/compiler/tpathutils.nim index 47ff0f06a2d..915d9f6abb0 100644 --- a/tests/compiler/tpathutils.nim +++ b/tests/compiler/tpathutils.nim @@ -1,5 +1,5 @@ -import compiler/pathutils -import os, strutils +import compiler/utils/pathutils +import std/[os, strutils] doAssert AbsoluteDir"/Users/me///" / RelativeFile"z.nim" == AbsoluteFile"/Users/me/z.nim" diff --git a/tests/compiler/tprefixmatches.nim b/tests/compiler/tprefixmatches.nim index 6a318672988..8ad8db0e946 100644 --- a/tests/compiler/tprefixmatches.nim +++ b/tests/compiler/tprefixmatches.nim @@ -1,5 +1,5 @@ -import compiler/prefixmatches -import macros +import compiler/utils/prefixmatches +import std/macros macro check(val, body: untyped): untyped = result = newStmtList() diff --git a/tests/compilerapi/tcompilerapi.nim b/tests/compilerapi/tcompilerapi.nim index c8d8e7afc75..fe3bf454394 100644 --- a/tests/compilerapi/tcompilerapi.nim +++ b/tests/compilerapi/tcompilerapi.nim @@ -14,8 +14,26 @@ raising VMQuit ## Example program that demonstrates how to use the ## compiler as an API to embed into your own projects. -import "../../compiler" / [ast, vmdef, vm, nimeval, llstream, lineinfos, options, reports] -import std / [os] + +import + std/[ + os + ], + ast/[ + ast, + lineinfos, + reports, + llstream + ], + front/[ + options + ], + vm/[ + vmdef, + vm, + nimeval, + ] + proc initInterpreter(script: string, hook: ReportHook): Interpreter = let std = findNimStdLibCompileTime() result = createInterpreter( diff --git a/tests/compilerapi/tcompilerapi.nim.cfg b/tests/compilerapi/tcompilerapi.nim.cfg new file mode 100644 index 00000000000..59b5d0310ea --- /dev/null +++ b/tests/compilerapi/tcompilerapi.nim.cfg @@ -0,0 +1 @@ +path="$config/../../compiler/" diff --git a/tests/compilerunits/confread/treport_filtering.nim b/tests/compilerunits/confread/treport_filtering.nim index a1f02cede76..66d37e7a9a0 100644 --- a/tests/compilerunits/confread/treport_filtering.nim +++ b/tests/compilerunits/confread/treport_filtering.nim @@ -12,18 +12,27 @@ discard """ ## 3. Full processing of the CLI flags - integration tests for the ## `nim.handleCmdLine()` logic -import compiler/[ - options, - reports, - commands, - cli_reporter, - idents, - modulegraphs, - nimconf, - cmdlinehelper -] - -import std/[strutils, os, sequtils] + +import + std/[ + strutils, + os, + sequtils + ], + ast/[ + reports, + idents + ], + modules/[ + modulegraphs + ], + front/[ + options, + commands, + cli_reporter, + cmdlinehelper, + nimconf + ] var reported: seq[Report] diff --git a/tests/compilerunits/nim.cfg b/tests/compilerunits/nim.cfg index 363ff72b224..96750698211 100644 --- a/tests/compilerunits/nim.cfg +++ b/tests/compilerunits/nim.cfg @@ -1 +1 @@ ---path:"$config/../.." \ No newline at end of file +--path:"$config/../../compiler" \ No newline at end of file diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim index 2f85b592897..37638fa4918 100644 --- a/tests/misc/trunner.nim +++ b/tests/misc/trunner.nim @@ -15,7 +15,7 @@ import stdtest/[specialpaths, unittest_light] from std/private/globs import nativeToUnixPath from strutils import startsWith, strip, removePrefix from std/sugar import dup -import "$lib/../compiler/nimpaths" +import "$lib/../compiler/modules/nimpaths" proc isDots(a: string): bool = ## test for `hintProcessing` dots diff --git a/tests/stdlib/tstrutils2.nim b/tests/stdlib/tstrutils2.nim index 881817f9043..0b0eb311a0f 100644 --- a/tests/stdlib/tstrutils2.nim +++ b/tests/stdlib/tstrutils2.nim @@ -1,4 +1,4 @@ -import "$lib/.." / compiler/strutils2 +import "$lib/.." / compiler/utils/strutils2 block: # setLen var a = "abc" diff --git a/tools/grammar_nanny.nim b/tools/grammar_nanny.nim index 93af703c2a7..142301eb583 100644 --- a/tools/grammar_nanny.nim +++ b/tools/grammar_nanny.nim @@ -3,9 +3,14 @@ import std / [strutils, sets] -import ".." / compiler / [ - llstream, lexer, options, msgs, idents, - lineinfos, pathutils, reports] +import + ast/[llstream, lexer, idents, lineinfos, reports], + utils/[pathutils], + front/[options, msgs, cli_reporter] + +# import ".." / compiler / [ +# llstream, lexer, options, msgs, idents, +# lineinfos, pathutils, reports] proc checkGrammarFileImpl(cache: IdentCache, config: ConfigRef) = var f = AbsoluteFile"doc/grammar.txt" @@ -46,7 +51,7 @@ proc checkGrammarFileImpl(cache: IdentCache, config: ConfigRef) = closeLexer(L) else: - config.localError InternalReport(kind: rintCannotOpenFile, file: f.string) + config.localReport InternalReport(kind: rintCannotOpenFile, file: f.string) -proc checkGrammarFile* = - checkGrammarFileImpl(newIdentCache(), newConfigRef()) +proc checkGrammarFile*() = + checkGrammarFileImpl(newIdentCache(), newConfigRef(reportHook)) diff --git a/tools/koch/kochdocs.nim b/tools/koch/kochdocs.nim index 9dad5604ab6..f71a48ced29 100644 --- a/tools/koch/kochdocs.nim +++ b/tools/koch/kochdocs.nim @@ -6,7 +6,8 @@ when defined(nimHasCastPragmaBlocks): import std/pegs from std/private/globs import nativeToUnixPath, walkDirRecFilter, PathEntry from packages/docutils/highlite import nimKeywordsSynchronizationCheck -import ".."/".."/compiler/[nversion, nimpaths] +import ".."/".."/compiler/utils/[nversion] +import ".."/".."/compiler/modules/[nimpaths] const # errormax: subsequent errors are probably consequences of 1st one; a simple diff --git a/tools/nim.cfg b/tools/nim.cfg new file mode 100644 index 00000000000..4472c303370 --- /dev/null +++ b/tools/nim.cfg @@ -0,0 +1 @@ +path:"$config/../compiler" \ No newline at end of file