Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
haxscramper committed Jan 19, 2022
1 parent 63b5341 commit 6d9bcb5
Show file tree
Hide file tree
Showing 153 changed files with 1,282 additions and 204 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
compiler/ast/[
lineinfos, # Positional information
idents, # Ast identifiers
ast_types # Main ast type definitions
],
compiler/front/[
options
],
compiler/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 compiler/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
compiler/ast/[
ast,
idents,
lineinfos,
],
std/[
hashes,
intsets,
strutils,
],
compiler/utils/[
ropes,
],
compiler/sem/[
rodutils,
],
compiler/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
compiler/ast/[
ast,
],
compiler/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
compiler/ast/[
ast,
idents,
lineinfos
],
compiler/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
compiler/ast/[
ast,
reports,
lineinfos
],
compiler/utils/[
debugutils,
],
compiler/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 compiler/front/options import ConfigRef
from compiler/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
compiler/front/[
msgs,
options,
],
std/[
strutils,
],
compiler/utils/[
pathutils,
],
compiler/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
compiler/ast/[
llstream,
ast,
renderer,
reports
],
std/[
strutils,
],
compiler/utils/[
pathutils,
],
compiler/front/[
msgs,
options,
]


proc invalidPragma(conf: ConfigRef; n: PNode) =
conf.localReport(n.info, reportAst(rsemNodeNotAllowed, n))
Expand Down
File renamed without changes.
File renamed without changes.
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
compiler/utils/[
platform,
pathutils,
],
compiler/ast/[
wordrecg,
nimlexbase,
llstream,
lineinfos,
reports,
idents
],
std/[
parseutils,
hashes,
strutils
],
compiler/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],
compiler/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
],
compiler/ast/[
ast,
lineinfos,
wordrecg,
reports
],
compiler/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
2 changes: 1 addition & 1 deletion compiler/llstream.nim → compiler/ast/llstream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Low-level streams for high performance.

import
pathutils
compiler/utils/pathutils

# support `useGnuReadline`, `useLinenoise` for backwards compatibility
const hasRstdin = (defined(nimUseLinenoise) or defined(useLinenoise) or defined(useGnuReadline)) and
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
compiler/ast/[
ast
],
compiler/front/[
msgs,
options
],
compiler/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
compiler/ast/[ast, astalgo, lineinfos, types],
compiler/front/[
options
],
compiler/utils/[
bitsets
]

proc inSet*(s: PNode, elem: PNode): bool =
assert s.kind == nkCurly
Expand Down
20 changes: 18 additions & 2 deletions compiler/parser.nim → compiler/ast/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,24 @@ when isMainModule:
checkGrammarFile()

import
llstream, lexer, idents, strutils, ast, msgs, options, lineinfos,
pathutils, reports
compiler/ast/[
llstream,
lexer,
idents,
ast,
lineinfos,
reports
],
std/[
strutils,
],
compiler/front/[
msgs,
options,
],
compiler/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
compiler/ast/[
lexer,
idents,
ast,
lineinfos,
reports
],
std/[
strutils,
],
compiler/front/[
options,
msgs,
]


type
TRenderFlag* = enum
Expand Down
8 changes: 4 additions & 4 deletions compiler/reports.nim → compiler/ast/reports.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import std/[options, packedsets]

import
ast_types,
vm_enums,
nilcheck_enums,
int128
compiler/vm/vm_enums,
compiler/ast/ast_types,
compiler/utils/int128,
compiler/sem/nilcheck_enums

export
ast_types,
Expand Down
22 changes: 20 additions & 2 deletions compiler/syntaxes.nim → compiler/ast/syntaxes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
compiler/ast/[
llstream,
ast,
idents,
lexer,
parser,
filters,
filter_tmpl,
renderer,
lineinfos,
reports
],
compiler/front/[
options,
msgs,
],
compiler/utils/[
pathutils,
]

export Parser, parseAll, parseTopLevelStmt, closeParser

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6d9bcb5

Please sign in to comment.