Skip to content

Commit

Permalink
Sort compiler files into manageable dir structure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haxscramper committed Jan 20, 2022
1 parent a6fed7b commit a67e45e
Show file tree
Hide file tree
Showing 181 changed files with 2,274 additions and 455 deletions.
27 changes: 19 additions & 8 deletions compiler/ast.nim → compiler/ast/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion compiler/ast_types.nim → compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ropes
import utils/ropes
import std/[hashes]

const
Expand Down
22 changes: 20 additions & 2 deletions compiler/astalgo.nim → compiler/ast/astalgo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion compiler/astmsgs.nim → compiler/ast/astmsgs.nim
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion compiler/enumtostr.nim → compiler/ast/enumtostr.nim
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 13 additions & 3 deletions compiler/errorhandling.nim → compiler/ast/errorhandling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions compiler/filter_tmpl.nim → compiler/ast/filter_tmpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions compiler/filters.nim → compiler/ast/filters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
File renamed without changes.
20 changes: 18 additions & 2 deletions compiler/layouter.nim → compiler/ast/layouter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions compiler/lexer.nim → compiler/ast/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion compiler/lineinfos.nim → compiler/ast/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions compiler/linter.nim → compiler/ast/linter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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', '_'}
Expand Down
4 changes: 2 additions & 2 deletions compiler/llstream.nim → compiler/ast/llstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion compiler/ndi.nim → compiler/ast/ndi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
8 changes: 7 additions & 1 deletion compiler/nimsets.nim → compiler/ast/nimsets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions compiler/parser.nim → compiler/ast/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion compiler/renderer.nim → compiler/ast/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit a67e45e

Please sign in to comment.