mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
removed compiler internal list implementation (#5371)
This commit is contained in:
committed by
Andreas Rumpf
parent
2ba374f9ab
commit
92c2a51bf7
@@ -10,7 +10,7 @@
|
||||
# abstract syntax tree + symbol table
|
||||
|
||||
import
|
||||
msgs, hashes, nversion, options, strutils, securehash, ropes, idents, lists,
|
||||
msgs, hashes, nversion, options, strutils, securehash, ropes, idents,
|
||||
intsets, idgen
|
||||
|
||||
type
|
||||
@@ -736,13 +736,15 @@ type
|
||||
|
||||
TLibKind* = enum
|
||||
libHeader, libDynamic
|
||||
TLib* = object of lists.TListEntry # also misused for headers!
|
||||
|
||||
TLib* = object # also misused for headers!
|
||||
kind*: TLibKind
|
||||
generated*: bool # needed for the backends:
|
||||
isOverriden*: bool
|
||||
name*: Rope
|
||||
path*: PNode # can be a string literal!
|
||||
|
||||
|
||||
CompilesId* = int ## id that is used for the caching logic within
|
||||
## ``system.compiles``. See the seminst module.
|
||||
TInstantiation* = object
|
||||
|
||||
@@ -944,7 +944,7 @@ proc genEcho(p: BProc, n: PNode) =
|
||||
# this unusal way of implementing it ensures that e.g. ``echo("hallo", 45)``
|
||||
# is threadsafe.
|
||||
internalAssert n.kind == nkBracket
|
||||
discard lists.includeStr(p.module.headerFiles, "<stdio.h>")
|
||||
p.module.includeHeader("<stdio.h>")
|
||||
var args: Rope = nil
|
||||
var a: TLoc
|
||||
for i in countup(0, n.len-1):
|
||||
|
||||
@@ -884,7 +884,7 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) =
|
||||
#
|
||||
if not isEmptyType(t.typ) and d.k == locNone:
|
||||
getTemp(p, t.typ, d)
|
||||
discard lists.includeStr(p.module.headerFiles, "<setjmp.h>")
|
||||
p.module.includeHeader("<setjmp.h>")
|
||||
genLineDir(p, t)
|
||||
var safePoint = getTempName(p.module)
|
||||
if getCompilerProc("Exception") != nil:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# This module declares some helpers for the C code generator.
|
||||
|
||||
import
|
||||
ast, astalgo, ropes, lists, hashes, strutils, types, msgs, wordrecg,
|
||||
ast, astalgo, ropes, hashes, strutils, types, msgs, wordrecg,
|
||||
platform, trees
|
||||
|
||||
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
import
|
||||
ast, astalgo, hashes, trees, platform, magicsys, extccomp, options, intsets,
|
||||
nversion, nimsets, msgs, securehash, bitsets, idents, lists, types,
|
||||
nversion, nimsets, msgs, securehash, bitsets, idents, types,
|
||||
ccgutils, os, ropes, math, passes, rodread, wordrecg, treetab, cgmeth,
|
||||
condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases,
|
||||
lowerings, semparallel, tables, sets, ndi
|
||||
@@ -75,12 +75,13 @@ proc isSimpleConst(typ: PType): bool =
|
||||
proc useStringh(m: BModule) =
|
||||
if includesStringh notin m.flags:
|
||||
incl m.flags, includesStringh
|
||||
discard lists.includeStr(m.headerFiles, "<string.h>")
|
||||
m.includeHeader("<string.h>")
|
||||
|
||||
proc useHeader(m: BModule, sym: PSym) =
|
||||
if lfHeader in sym.loc.flags:
|
||||
assert(sym.annex != nil)
|
||||
discard lists.includeStr(m.headerFiles, getStr(sym.annex.path))
|
||||
let str = getStr(sym.annex.path)
|
||||
m.includeHeader(str)
|
||||
|
||||
proc cgsym(m: BModule, name: string): Rope
|
||||
|
||||
@@ -594,15 +595,14 @@ proc cgsym(m: BModule, name: string): Rope =
|
||||
|
||||
proc generateHeaders(m: BModule) =
|
||||
add(m.s[cfsHeaders], tnl & "#include \"nimbase.h\"" & tnl)
|
||||
var it = PStrEntry(m.headerFiles.head)
|
||||
while it != nil:
|
||||
if it.data[0] == '#':
|
||||
add(m.s[cfsHeaders], rope(it.data.replace('`', '"') & tnl))
|
||||
elif it.data[0] notin {'\"', '<'}:
|
||||
addf(m.s[cfsHeaders], "#include \"$1\"$N", [rope(it.data)])
|
||||
|
||||
for it in m.headerFiles:
|
||||
if it[0] == '#':
|
||||
add(m.s[cfsHeaders], rope(it.replace('`', '"') & tnl))
|
||||
elif it[0] notin {'\"', '<'}:
|
||||
addf(m.s[cfsHeaders], "#include \"$1\"$N", [rope(it)])
|
||||
else:
|
||||
addf(m.s[cfsHeaders], "#include $1$N", [rope(it.data)])
|
||||
it = PStrEntry(it.next)
|
||||
addf(m.s[cfsHeaders], "#include $1$N", [rope(it)])
|
||||
add(m.s[cfsHeaders], "#undef linux" & tnl)
|
||||
|
||||
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
||||
@@ -974,7 +974,7 @@ proc genMainProc(m: BModule) =
|
||||
else:
|
||||
nimMain = WinNimDllMain
|
||||
otherMain = WinCDllMain
|
||||
discard lists.includeStr(m.headerFiles, "<windows.h>")
|
||||
m.includeHeader("<windows.h>")
|
||||
elif optGenDynLib in gGlobalOptions:
|
||||
nimMain = PosixNimDllMain
|
||||
otherMain = PosixCDllMain
|
||||
@@ -1129,7 +1129,7 @@ proc initProcOptions(m: BModule): TOptions =
|
||||
proc rawNewModule(g: BModuleList; module: PSym, filename: string): BModule =
|
||||
new(result)
|
||||
result.tmpBase = rope("TM" & $hashOwner(module) & "_")
|
||||
initLinkedList(result.headerFiles)
|
||||
result.headerFiles = @[]
|
||||
result.declaredThings = initIntSet()
|
||||
result.declaredProtos = initIntSet()
|
||||
result.cfilename = filename
|
||||
@@ -1166,7 +1166,7 @@ proc nullify[T](arr: var T) =
|
||||
proc resetModule*(m: BModule) =
|
||||
# between two compilations in CAAS mode, we can throw
|
||||
# away all the data that was written to disk
|
||||
initLinkedList(m.headerFiles)
|
||||
m.headerFiles = @[]
|
||||
m.declaredProtos = initIntSet()
|
||||
m.forwTypeCache = initTable[SigHash, Rope]()
|
||||
m.initProc = newProc(nil, m)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
## This module contains the data structures for the C code generation phase.
|
||||
|
||||
import
|
||||
ast, astalgo, ropes, passes, options, intsets, lists, platform, sighashes,
|
||||
ast, astalgo, ropes, passes, options, intsets, platform, sighashes,
|
||||
tables, ndi
|
||||
|
||||
from msgs import TLineInfo
|
||||
@@ -130,7 +130,7 @@ type
|
||||
forwTypeCache*: TypeCache # cache for forward declarations of types
|
||||
declaredThings*: IntSet # things we have declared in this .c file
|
||||
declaredProtos*: IntSet # prototypes we have declared in this .c file
|
||||
headerFiles*: TLinkedList # needed headers to include
|
||||
headerFiles*: seq[string] # needed headers to include
|
||||
typeInfoMarker*: TypeCache # needed for generating type information
|
||||
initProc*: BProc # code for init procedure
|
||||
postInitProc*: BProc # code to be executed after the init proc
|
||||
@@ -148,9 +148,13 @@ type
|
||||
g*: BModuleList
|
||||
ndi*: NdiFile
|
||||
|
||||
proc includeHeader*(this: BModule; header: string) =
|
||||
if not this.headerFiles.contains header:
|
||||
this.headerFiles.add header
|
||||
|
||||
proc s*(p: BProc, s: TCProcSection): var Rope {.inline.} =
|
||||
# section in the current block
|
||||
result = p.blocks[p.blocks.len - 1].sections[s]
|
||||
result = p.blocks[^1].sections[s]
|
||||
|
||||
proc procSec*(p: BProc, s: TCProcSection): var Rope {.inline.} =
|
||||
# top level proc sections
|
||||
|
||||
@@ -26,8 +26,8 @@ bootSwitch(usedGoGC, defined(gogc), "--gc:go")
|
||||
bootSwitch(usedNoGC, defined(nogc), "--gc:none")
|
||||
|
||||
import
|
||||
os, msgs, options, nversion, condsyms, strutils, extccomp, platform, lists,
|
||||
wordrecg, parseutils, nimblecmd, idents, parseopt
|
||||
os, msgs, options, nversion, condsyms, strutils, extccomp, platform,
|
||||
wordrecg, parseutils, nimblecmd, idents, parseopt, sequtils
|
||||
|
||||
# but some have deps to imported modules. Yay.
|
||||
bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc")
|
||||
@@ -335,12 +335,14 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||
of "excludepath":
|
||||
expectArg(switch, arg, pass, info)
|
||||
let path = processPath(arg, info)
|
||||
lists.excludePath(options.searchPaths, path)
|
||||
lists.excludePath(options.lazyPaths, path)
|
||||
|
||||
options.searchPaths.keepItIf( cmpPaths(it, path) != 0 )
|
||||
options.lazyPaths.keepItIf( cmpPaths(it, path) != 0 )
|
||||
|
||||
if (len(path) > 0) and (path[len(path) - 1] == DirSep):
|
||||
let strippedPath = path[0 .. (len(path) - 2)]
|
||||
lists.excludePath(options.searchPaths, strippedPath)
|
||||
lists.excludePath(options.lazyPaths, strippedPath)
|
||||
options.searchPaths.keepItIf( cmpPaths(it, strippedPath) != 0 )
|
||||
options.lazyPaths.keepItIf( cmpPaths(it, strippedPath) != 0 )
|
||||
of "nimcache":
|
||||
expectArg(switch, arg, pass, info)
|
||||
options.nimcacheDir = processPath(arg, info, true)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# nim files.
|
||||
|
||||
import
|
||||
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs,
|
||||
ropes, os, strutils, osproc, platform, condsyms, options, msgs,
|
||||
securehash, streams
|
||||
|
||||
#from debuginfo import writeDebugInfo
|
||||
@@ -390,8 +390,8 @@ type
|
||||
CfileList = seq[Cfile]
|
||||
|
||||
var
|
||||
externalToLink: TLinkedList # files to link in addition to the file
|
||||
# we compiled
|
||||
externalToLink: seq[string] = @[] # files to link in addition to the file
|
||||
# we compiled
|
||||
linkOptionsCmd: string = ""
|
||||
compileOptionsCmd: seq[string] = @[]
|
||||
linkOptions: string = ""
|
||||
@@ -486,11 +486,10 @@ proc resetCompilationLists* =
|
||||
# when the module is loaded/unloaded it adds/removes its items
|
||||
# That's because we still need to hash check the external files
|
||||
# Maybe we can do that in checkDep on the other hand?
|
||||
initLinkedList(externalToLink)
|
||||
externalToLink.setLen 0
|
||||
|
||||
proc addExternalFileToLink*(filename: string) =
|
||||
prependStr(externalToLink, filename)
|
||||
# BUGFIX: was ``appendStr``
|
||||
externalToLink.insert(filename, 0)
|
||||
|
||||
proc execWithEcho(cmd: string, msg = hintExecuting): int =
|
||||
rawMessage(msg, cmd)
|
||||
@@ -527,9 +526,6 @@ proc noAbsolutePaths: bool {.inline.} =
|
||||
# `optGenMapping` is included here for niminst.
|
||||
result = gGlobalOptions * {optGenScript, optGenMapping} != {}
|
||||
|
||||
proc add(s: var string, many: openArray[string]) =
|
||||
s.add many.join
|
||||
|
||||
proc cFileSpecificOptions(cfilename: string): string =
|
||||
result = compileOptions
|
||||
for option in compileOptionsCmd:
|
||||
@@ -560,7 +556,7 @@ proc getLinkOptions: string =
|
||||
for linkedLib in items(cLinkedLibs):
|
||||
result.add(CC[cCompiler].linkLibCmd % linkedLib.quoteShell)
|
||||
for libDir in items(cLibs):
|
||||
result.add([CC[cCompiler].linkDirCmd, libDir.quoteShell])
|
||||
result.add(join([CC[cCompiler].linkDirCmd, libDir.quoteShell]))
|
||||
|
||||
proc needsExeExt(): bool {.inline.} =
|
||||
result = (optGenScript in gGlobalOptions and targetOS == osWindows) or
|
||||
@@ -611,7 +607,7 @@ proc getCompileCFileCmd*(cfile: Cfile): string =
|
||||
includeCmd = CC[c].includeCmd & quoteShell(libpath)
|
||||
|
||||
for includeDir in items(cIncludes):
|
||||
includeCmd.add([CC[c].includeCmd, includeDir.quoteShell])
|
||||
includeCmd.add(join([CC[c].includeCmd, includeDir.quoteShell]))
|
||||
|
||||
compilePattern = joinPath(ccompilerpath, exe)
|
||||
else:
|
||||
@@ -786,14 +782,12 @@ proc callCCompiler*(projectfile: string) =
|
||||
rawMessage(errExecutionOfProgramFailed, cmds.join())
|
||||
if optNoLinking notin gGlobalOptions:
|
||||
# call the linker:
|
||||
var it = PStrEntry(externalToLink.head)
|
||||
var objfiles = ""
|
||||
while it != nil:
|
||||
let objFile = if noAbsolutePaths(): it.data.extractFilename else: it.data
|
||||
for it in externalToLink:
|
||||
let objFile = if noAbsolutePaths(): it.extractFilename else: it
|
||||
add(objfiles, ' ')
|
||||
add(objfiles, quoteShell(
|
||||
addFileExt(objFile, CC[cCompiler].objExt)))
|
||||
it = PStrEntry(it.next)
|
||||
for x in toCompile:
|
||||
add(objfiles, ' ')
|
||||
add(objfiles, quoteShell(x.obj))
|
||||
@@ -836,15 +830,14 @@ proc writeJsonBuildInstructions*(projectfile: string) =
|
||||
else:
|
||||
lit "],\L"
|
||||
|
||||
proc linkfiles(f: File; buf, objfiles: var string; toLink: TLinkedList) =
|
||||
var it = PStrEntry(toLink.head)
|
||||
while it != nil:
|
||||
let objfile = addFileExt(it.data, CC[cCompiler].objExt)
|
||||
str objfile
|
||||
proc linkfiles(f: File; buf, objfiles: var string; toLink: seq[string]) =
|
||||
for i, it in toLink:
|
||||
let objfile = addFileExt(it, CC[cCompiler].objExt)
|
||||
str(objfile)
|
||||
add(objfiles, ' ')
|
||||
add(objfiles, quoteShell(objfile))
|
||||
it = PStrEntry(it.next)
|
||||
if it == nil:
|
||||
|
||||
if i == toLink.high:
|
||||
lit "\L"
|
||||
else:
|
||||
lit ",\L"
|
||||
|
||||
@@ -31,7 +31,7 @@ implements the required case distinction.
|
||||
|
||||
import
|
||||
ast, astalgo, strutils, hashes, trees, platform, magicsys, extccomp, options,
|
||||
nversion, nimsets, msgs, securehash, bitsets, idents, lists, types, os,
|
||||
nversion, nimsets, msgs, securehash, bitsets, idents, types, os,
|
||||
times, ropes, math, passes, ccgutils, wordrecg, renderer, rodread, rodutils,
|
||||
intsets, cgmeth, lowerings
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# This include file implements lambda lifting for the transformator.
|
||||
|
||||
import
|
||||
intsets, strutils, lists, options, ast, astalgo, trees, treetab, msgs, os,
|
||||
intsets, strutils, options, ast, astalgo, trees, treetab, msgs, os,
|
||||
idents, renderer, types, magicsys, rodread, lowerings, tables
|
||||
|
||||
discard """
|
||||
|
||||
@@ -7,113 +7,22 @@
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
# This module implements a generic doubled linked list.
|
||||
# TODO Remove this and replace it with something sensible
|
||||
# This module is deprecated, don't use it.
|
||||
# TODO Remove this
|
||||
|
||||
import os
|
||||
type
|
||||
PListEntry* = ref TListEntry
|
||||
TListEntry* = object of RootObj
|
||||
prev*, next*: PListEntry
|
||||
|
||||
TStrEntry* = object of TListEntry
|
||||
data*: string
|
||||
static:
|
||||
echo "WARNING: imported deprecated module compiler/lists.nim, use seq ore lists from the standard library"
|
||||
|
||||
PStrEntry* = ref TStrEntry
|
||||
TLinkedList* = object # for the "find" operation:
|
||||
head*, tail*: PListEntry
|
||||
counter*: int
|
||||
proc appendStr*(list: var seq[string]; data: string) {.deprecated.} =
|
||||
# just use system.add
|
||||
list.add(data)
|
||||
|
||||
TCompareProc* = proc (entry: PListEntry, closure: pointer): bool {.nimcall.}
|
||||
|
||||
proc initLinkedList*(list: var TLinkedList) =
|
||||
list.counter = 0
|
||||
list.head = nil
|
||||
list.tail = nil
|
||||
|
||||
proc append*(list: var TLinkedList, entry: PListEntry) =
|
||||
inc(list.counter)
|
||||
entry.next = nil
|
||||
entry.prev = list.tail
|
||||
if list.tail != nil:
|
||||
assert(list.tail.next == nil)
|
||||
list.tail.next = entry
|
||||
list.tail = entry
|
||||
if list.head == nil: list.head = entry
|
||||
|
||||
proc contains*(list: TLinkedList, data: string): bool =
|
||||
var it = list.head
|
||||
while it != nil:
|
||||
if PStrEntry(it).data == data:
|
||||
return true
|
||||
it = it.next
|
||||
|
||||
proc newStrEntry(data: string): PStrEntry =
|
||||
new(result)
|
||||
result.data = data
|
||||
|
||||
proc appendStr*(list: var TLinkedList, data: string) =
|
||||
append(list, newStrEntry(data))
|
||||
|
||||
proc includeStr*(list: var TLinkedList, data: string): bool =
|
||||
if contains(list, data): return true
|
||||
appendStr(list, data) # else: add to list
|
||||
|
||||
proc prepend*(list: var TLinkedList, entry: PListEntry) =
|
||||
inc(list.counter)
|
||||
entry.prev = nil
|
||||
entry.next = list.head
|
||||
if list.head != nil:
|
||||
assert(list.head.prev == nil)
|
||||
list.head.prev = entry
|
||||
list.head = entry
|
||||
if list.tail == nil: list.tail = entry
|
||||
|
||||
proc prependStr*(list: var TLinkedList, data: string) =
|
||||
prepend(list, newStrEntry(data))
|
||||
|
||||
proc insertBefore*(list: var TLinkedList, pos, entry: PListEntry) =
|
||||
assert(pos != nil)
|
||||
if pos == list.head:
|
||||
prepend(list, entry)
|
||||
proc includeStr(list: var seq[string]; data: string): bool {.deprecated.} =
|
||||
if list.contains(data):
|
||||
result = true
|
||||
else:
|
||||
inc(list.counter)
|
||||
entry.next = pos
|
||||
entry.prev = pos.prev
|
||||
if pos.prev != nil: pos.prev.next = entry
|
||||
pos.prev = entry
|
||||
result = false
|
||||
list.add data
|
||||
|
||||
proc remove*(list: var TLinkedList, entry: PListEntry) =
|
||||
dec(list.counter)
|
||||
if entry == list.tail:
|
||||
list.tail = entry.prev
|
||||
if entry == list.head:
|
||||
list.head = entry.next
|
||||
if entry.next != nil: entry.next.prev = entry.prev
|
||||
if entry.prev != nil: entry.prev.next = entry.next
|
||||
|
||||
proc bringToFront*(list: var TLinkedList, entry: PListEntry) =
|
||||
when true:
|
||||
list.remove entry
|
||||
list.prepend entry
|
||||
else:
|
||||
if entry == list.head: return
|
||||
if entry == list.tail: list.tail = entry.prev
|
||||
if entry.next != nil: entry.next.prev = entry.prev
|
||||
if entry.prev != nil: entry.prev.next = entry.next
|
||||
entry.prev = nil
|
||||
entry.next = list.head
|
||||
list.head = entry
|
||||
|
||||
proc excludePath*(list: var TLinkedList, data: string) =
|
||||
var it = list.head
|
||||
while it != nil:
|
||||
let nxt = it.next
|
||||
if cmpPaths(PStrEntry(it).data, data) == 0:
|
||||
remove(list, it)
|
||||
it = nxt
|
||||
|
||||
proc find*(list: TLinkedList, fn: TCompareProc, closure: pointer): PListEntry =
|
||||
result = list.head
|
||||
while result != nil:
|
||||
if fn(result, closure): return
|
||||
result = result.next
|
||||
|
||||
@@ -15,7 +15,7 @@ import
|
||||
wordrecg, sem, semdata, idents, passes, docgen, extccomp,
|
||||
cgen, jsgen, json, nversion,
|
||||
platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen,
|
||||
docgen2, service, parser, modules, ccgutils, sigmatch, ropes, lists,
|
||||
docgen2, service, parser, modules, ccgutils, sigmatch, ropes,
|
||||
modulegraphs
|
||||
|
||||
from magicsys import systemModule, resetSysTypes
|
||||
@@ -151,7 +151,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||
# In "nim serve" scenario, each command must reset the registered passes
|
||||
clearPasses()
|
||||
gLastCmdTime = epochTime()
|
||||
appendStr(searchPaths, options.libpath)
|
||||
searchPaths.add(options.libpath)
|
||||
when false: # gProjectFull.len != 0:
|
||||
# current path is always looked first for modules
|
||||
prependStr(searchPaths, gProjectPath)
|
||||
@@ -229,7 +229,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||
for s in definedSymbolNames(): definedSymbols.elems.add(%s)
|
||||
|
||||
var libpaths = newJArray()
|
||||
for dir in iterSearchPath(searchPaths): libpaths.elems.add(%dir)
|
||||
for dir in searchPaths: libpaths.elems.add(%dir)
|
||||
|
||||
var dumpdata = % [
|
||||
(key: "version", val: %VersionAsString),
|
||||
@@ -245,7 +245,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||
for s in definedSymbolNames(): msgWriteln(s, {msgStdout, msgSkipHook})
|
||||
msgWriteln("-- end of list --", {msgStdout, msgSkipHook})
|
||||
|
||||
for it in iterSearchPath(searchPaths): msgWriteln(it)
|
||||
for it in searchPaths: msgWriteln(it)
|
||||
of "check":
|
||||
gCmd = cmdCheck
|
||||
commandCheck(graph, cache)
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
## Implements some helper procs for Nimble (Nim's package manager) support.
|
||||
|
||||
import parseutils, strutils, strtabs, os, options, msgs, lists
|
||||
import parseutils, strutils, strtabs, os, options, msgs
|
||||
|
||||
proc addPath*(path: string, info: TLineInfo) =
|
||||
if not contains(options.searchPaths, path):
|
||||
lists.prependStr(options.searchPaths, path)
|
||||
if not options.searchPaths.contains(path):
|
||||
options.searchPaths.insert(path, 0)
|
||||
|
||||
proc versionSplitPos(s: string): int =
|
||||
result = s.len-2
|
||||
@@ -61,7 +61,7 @@ iterator chosen(packages: StringTableRef): string =
|
||||
proc addNimblePath(p: string, info: TLineInfo) =
|
||||
if not contains(options.searchPaths, p):
|
||||
message(info, hintPath, p)
|
||||
lists.prependStr(options.lazyPaths, p)
|
||||
options.lazyPaths.insert(p, 0)
|
||||
|
||||
proc addPathRec(dir: string, info: TLineInfo) =
|
||||
var packages = newStringTable(modeStyleInsensitive)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
## exposes the Nim VM to clients.
|
||||
import
|
||||
ast, modules, passes, passaux, condsyms,
|
||||
options, nimconf, lists, sem, semdata, llstream, vm, modulegraphs, idents
|
||||
options, nimconf, sem, semdata, llstream, vm, modulegraphs, idents
|
||||
|
||||
proc execute*(program: string) =
|
||||
passes.gIncludeFile = includeModule
|
||||
@@ -25,7 +25,7 @@ proc execute*(program: string) =
|
||||
registerPass(semPass)
|
||||
registerPass(evalPass)
|
||||
|
||||
appendStr(searchPaths, options.libpath)
|
||||
searchPaths.add options.libpath
|
||||
var graph = newModuleGraph()
|
||||
var cache = newIdentCache()
|
||||
var m = makeStdinModule(graph)
|
||||
|
||||
@@ -13,7 +13,7 @@ import strutils, os, parseopt
|
||||
import compiler/[options, commands, modules, sem,
|
||||
passes, passaux, nimfix/pretty,
|
||||
msgs, nimconf,
|
||||
extccomp, condsyms, lists,
|
||||
extccomp, condsyms,
|
||||
modulegraphs, idents]
|
||||
|
||||
const Usage = """
|
||||
@@ -39,10 +39,10 @@ proc mainCommand =
|
||||
registerPass verbosePass
|
||||
registerPass semPass
|
||||
gCmd = cmdPretty
|
||||
appendStr(searchPaths, options.libpath)
|
||||
searchPaths.add options.libpath
|
||||
if gProjectFull.len != 0:
|
||||
# current path is always looked first for modules
|
||||
prependStr(searchPaths, gProjectPath)
|
||||
searchPaths.insert(gProjectPath, 0)
|
||||
|
||||
compileProject(newModuleGraph(), newIdentCache())
|
||||
pretty.overwriteFiles()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
import
|
||||
os, lists, strutils, strtabs, osproc, sets
|
||||
os, strutils, strtabs, osproc, sets
|
||||
|
||||
const
|
||||
hasTinyCBackend* = defined(tinyc)
|
||||
@@ -129,7 +129,8 @@ var
|
||||
gExitcode*: int8
|
||||
gCmd*: TCommands = cmdNone # the command
|
||||
gSelectedGC* = gcRefc # the selected GC
|
||||
searchPaths*, lazyPaths*: TLinkedList
|
||||
searchPaths*: seq[string] = @[]
|
||||
lazyPaths*: seq[string] = @[]
|
||||
outFile*: string = ""
|
||||
docSeeSrcUrl*: string = "" # if empty, no seeSrc will be generated. \
|
||||
# The string uses the formatting variables `path` and `line`.
|
||||
@@ -267,9 +268,7 @@ proc removeTrailingDirSep*(path: string): string =
|
||||
|
||||
proc disableNimblePath*() =
|
||||
gNoNimblePath = true
|
||||
lazyPaths.head = nil
|
||||
lazyPaths.tail = nil
|
||||
lazyPaths.counter = 0
|
||||
lazyPaths.setLen(0)
|
||||
|
||||
include packagehandling
|
||||
|
||||
@@ -336,27 +335,22 @@ proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
|
||||
result = joinPath(subdir, tail)
|
||||
#echo "completeGeneratedFilePath(", f, ") = ", result
|
||||
|
||||
iterator iterSearchPath*(searchPaths: TLinkedList): string =
|
||||
var it = PStrEntry(searchPaths.head)
|
||||
while it != nil:
|
||||
yield it.data
|
||||
it = PStrEntry(it.next)
|
||||
|
||||
proc rawFindFile(f: string): string =
|
||||
for it in iterSearchPath(searchPaths):
|
||||
for it in searchPaths:
|
||||
result = joinPath(it, f)
|
||||
if existsFile(result):
|
||||
return result.canonicalizePath
|
||||
result = ""
|
||||
|
||||
proc rawFindFile2(f: string): string =
|
||||
var it = PStrEntry(lazyPaths.head)
|
||||
while it != nil:
|
||||
result = joinPath(it.data, f)
|
||||
for i, it in lazyPaths:
|
||||
result = joinPath(it, f)
|
||||
if existsFile(result):
|
||||
bringToFront(lazyPaths, it)
|
||||
# bring to front
|
||||
for j in countDown(i,1):
|
||||
swap(lazyPaths[j], lazyPaths[j-1])
|
||||
|
||||
return result.canonicalizePath
|
||||
it = PStrEntry(it.next)
|
||||
result = ""
|
||||
|
||||
template patchModule() {.dirty.} =
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# `TPass` interface.
|
||||
|
||||
import
|
||||
strutils, lists, options, ast, astalgo, llstream, msgs, platform, os,
|
||||
strutils, options, ast, astalgo, llstream, msgs, platform, os,
|
||||
condsyms, idents, renderer, types, extccomp, math, magicsys, nversion,
|
||||
nimsets, syntaxes, times, rodread, idgen, modulegraphs
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
import
|
||||
os, platform, condsyms, ast, astalgo, idents, semdata, msgs, renderer,
|
||||
wordrecg, ropes, options, strutils, lists, extccomp, math, magicsys, trees,
|
||||
wordrecg, ropes, options, strutils, extccomp, math, magicsys, trees,
|
||||
rodread, types, lookups
|
||||
|
||||
const
|
||||
@@ -218,20 +218,19 @@ proc processCallConv(c: PContext, n: PNode) =
|
||||
var sw = whichKeyword(n.sons[1].ident)
|
||||
case sw
|
||||
of FirstCallConv..LastCallConv:
|
||||
POptionEntry(c.optionStack.tail).defaultCC = wordToCallConv(sw)
|
||||
c.optionStack[^1].defaultCC = wordToCallConv(sw)
|
||||
else: localError(n.info, errCallConvExpected)
|
||||
else:
|
||||
localError(n.info, errCallConvExpected)
|
||||
|
||||
proc getLib(c: PContext, kind: TLibKind, path: PNode): PLib =
|
||||
var it = PLib(c.libs.head)
|
||||
while it != nil:
|
||||
if it.kind == kind:
|
||||
if trees.exprStructuralEquivalent(it.path, path): return it
|
||||
it = PLib(it.next)
|
||||
for it in c.libs:
|
||||
if it.kind == kind and trees.exprStructuralEquivalent(it.path, path):
|
||||
return it
|
||||
|
||||
result = newLib(kind)
|
||||
result.path = path
|
||||
append(c.libs, result)
|
||||
c.libs.add result
|
||||
if path.kind in {nkStrLit..nkTripleStrLit}:
|
||||
result.isOverriden = options.isDynlibOverride(path.strVal)
|
||||
|
||||
@@ -254,7 +253,7 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
|
||||
if (sym == nil) or (sym.kind == skModule):
|
||||
let lib = getLib(c, libDynamic, expectDynlibNode(c, n))
|
||||
if not lib.isOverriden:
|
||||
POptionEntry(c.optionStack.tail).dynlib = lib
|
||||
c.optionStack[^1].dynlib = lib
|
||||
else:
|
||||
if n.kind == nkExprColonExpr:
|
||||
var lib = getLib(c, libDynamic, expectDynlibNode(c, n))
|
||||
@@ -350,12 +349,12 @@ proc processPush(c: PContext, n: PNode, start: int) =
|
||||
if n.sons[start-1].kind == nkExprColonExpr:
|
||||
localError(n.info, errGenerated, "':' after 'push' not supported")
|
||||
var x = newOptionEntry()
|
||||
var y = POptionEntry(c.optionStack.tail)
|
||||
var y = c.optionStack[^1]
|
||||
x.options = gOptions
|
||||
x.defaultCC = y.defaultCC
|
||||
x.dynlib = y.dynlib
|
||||
x.notes = gNotes
|
||||
append(c.optionStack, x)
|
||||
c.optionStack.add(x)
|
||||
for i in countup(start, sonsLen(n) - 1):
|
||||
if processOption(c, n.sons[i]):
|
||||
# simply store it somewhere:
|
||||
@@ -365,12 +364,12 @@ proc processPush(c: PContext, n: PNode, start: int) =
|
||||
#localError(n.info, errOptionExpected)
|
||||
|
||||
proc processPop(c: PContext, n: PNode) =
|
||||
if c.optionStack.counter <= 1:
|
||||
if c.optionStack.len <= 1:
|
||||
localError(n.info, errAtPopWithoutPush)
|
||||
else:
|
||||
gOptions = POptionEntry(c.optionStack.tail).options
|
||||
gNotes = POptionEntry(c.optionStack.tail).notes
|
||||
remove(c.optionStack, c.optionStack.tail)
|
||||
gOptions = c.optionStack[^1].options
|
||||
gNotes = c.optionStack[^1].notes
|
||||
c.optionStack.setLen(c.optionStack.len - 1)
|
||||
|
||||
proc processDefine(c: PContext, n: PNode) =
|
||||
if (n.kind == nkExprColonExpr) and (n.sons[1].kind == nkIdent):
|
||||
@@ -977,8 +976,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||
proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
|
||||
validPragmas: TSpecialWords) =
|
||||
if sym != nil and sym.kind != skModule:
|
||||
var it = POptionEntry(c.optionStack.head)
|
||||
while it != nil:
|
||||
for it in c.optionStack:
|
||||
let o = it.otherPragmas
|
||||
if not o.isNil:
|
||||
pushInfoContext(n.info)
|
||||
@@ -986,11 +984,10 @@ proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
|
||||
if singlePragma(c, sym, o, i, validPragmas):
|
||||
internalError(n.info, "implicitPragmas")
|
||||
popInfoContext()
|
||||
it = it.next.POptionEntry
|
||||
|
||||
if lfExportLib in sym.loc.flags and sfExportc notin sym.flags:
|
||||
localError(n.info, errDynlibRequiresExportc)
|
||||
var lib = POptionEntry(c.optionStack.tail).dynlib
|
||||
var lib = c.optionStack[^1].dynlib
|
||||
if {lfDynamicLib, lfHeader} * sym.loc.flags == {} and
|
||||
sfImportc in sym.flags and lib != nil:
|
||||
incl(sym.loc.flags, lfDynamicLib)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# This module implements the renderer of the standard Nim representation.
|
||||
|
||||
import
|
||||
lexer, options, idents, strutils, ast, msgs, lists
|
||||
lexer, options, idents, strutils, ast, msgs
|
||||
|
||||
type
|
||||
TRenderFlag* = enum
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
import
|
||||
ast, modules, idents, passes, passaux, condsyms,
|
||||
options, nimconf, lists, sem, semdata, llstream, vm, vmdef, commands, msgs,
|
||||
options, nimconf, sem, semdata, llstream, vm, vmdef, commands, msgs,
|
||||
os, times, osproc, wordrecg, strtabs, modulegraphs
|
||||
|
||||
# we support 'cmpIgnoreStyle' natively for efficiency:
|
||||
@@ -153,7 +153,7 @@ proc runNimScript*(cache: IdentCache; scriptName: string;
|
||||
registerPass(semPass)
|
||||
registerPass(evalPass)
|
||||
|
||||
appendStr(searchPaths, options.libpath)
|
||||
searchPaths.add(options.libpath)
|
||||
|
||||
var m = graph.makeModule(scriptName)
|
||||
incl(m.flags, sfMainModule)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# This module implements the semantic checking pass.
|
||||
|
||||
import
|
||||
ast, strutils, hashes, lists, options, lexer, astalgo, trees, treetab,
|
||||
ast, strutils, hashes, options, lexer, astalgo, trees, treetab,
|
||||
wordrecg, ropes, msgs, os, condsyms, idents, renderer, types, platform, math,
|
||||
magicsys, parser, nversion, nimsets, semfold, importer,
|
||||
procfind, lookups, rodread, pragmas, passes, semdata, semtypinst, sigmatch,
|
||||
|
||||
@@ -10,15 +10,14 @@
|
||||
## This module contains the data structures for the semantic checking phase.
|
||||
|
||||
import
|
||||
strutils, lists, intsets, options, lexer, ast, astalgo, trees, treetab,
|
||||
strutils, intsets, options, lexer, ast, astalgo, trees, treetab,
|
||||
wordrecg,
|
||||
ropes, msgs, platform, os, condsyms, idents, renderer, types, extccomp, math,
|
||||
magicsys, nversion, nimsets, parser, times, passes, rodread, vmdef,
|
||||
modulegraphs
|
||||
|
||||
type
|
||||
TOptionEntry* = object of lists.TListEntry # entries to put on a
|
||||
# stack for pragma parsing
|
||||
TOptionEntry* = object # entries to put on a stack for pragma parsing
|
||||
options*: TOptions
|
||||
defaultCC*: TCallingConvention
|
||||
dynlib*: PLib
|
||||
@@ -79,10 +78,10 @@ type
|
||||
inGenericInst*: int # > 0 if we are instantiating a generic
|
||||
converters*: TSymSeq # sequence of converters
|
||||
patterns*: TSymSeq # sequence of pattern matchers
|
||||
optionStack*: TLinkedList
|
||||
optionStack*: seq[POptionEntry]
|
||||
symMapping*: TIdTable # every gensym'ed symbol needs to be mapped
|
||||
# to some new symbol in a generic instantiation
|
||||
libs*: TLinkedList # all libs used by this module
|
||||
libs*: seq[PLib] # all libs used by this module
|
||||
semConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas
|
||||
semExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
|
||||
semTryExpr*: proc (c: PContext, n: PNode,flags: TExprFlags = {}): PNode {.nimcall.}
|
||||
@@ -133,7 +132,7 @@ proc getCurrOwner*(): PSym =
|
||||
# the documentation comment always gets
|
||||
# assigned to the current owner
|
||||
# BUGFIX: global array is needed!
|
||||
result = gOwners[high(gOwners)]
|
||||
result = gOwners[^1]
|
||||
|
||||
proc pushOwner*(owner: PSym) =
|
||||
add(gOwners, owner)
|
||||
@@ -144,7 +143,7 @@ proc popOwner*() =
|
||||
else: internalError("popOwner")
|
||||
|
||||
proc lastOptionEntry*(c: PContext): POptionEntry =
|
||||
result = POptionEntry(c.optionStack.tail)
|
||||
result = c.optionStack[^1]
|
||||
|
||||
proc popProcCon*(c: PContext) {.inline.} = c.p = c.p.next
|
||||
|
||||
@@ -187,9 +186,9 @@ proc newOptionEntry*(): POptionEntry =
|
||||
proc newContext*(graph: ModuleGraph; module: PSym; cache: IdentCache): PContext =
|
||||
new(result)
|
||||
result.ambiguousSymbols = initIntSet()
|
||||
initLinkedList(result.optionStack)
|
||||
initLinkedList(result.libs)
|
||||
append(result.optionStack, newOptionEntry())
|
||||
result.optionStack = @[]
|
||||
result.libs = @[]
|
||||
result.optionStack.add(newOptionEntry())
|
||||
result.module = module
|
||||
result.friendModules = @[module]
|
||||
result.converters = @[]
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# and evaluation phase
|
||||
|
||||
import
|
||||
strutils, lists, options, ast, astalgo, trees, treetab, nimsets, times,
|
||||
strutils, options, ast, astalgo, trees, treetab, nimsets, times,
|
||||
nversion, platform, math, msgs, os, condsyms, idents, renderer, types,
|
||||
commands, magicsys, saturate
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# * transforms 'defer' into a 'try finally' statement
|
||||
|
||||
import
|
||||
intsets, strutils, lists, options, ast, astalgo, trees, treetab, msgs, os,
|
||||
intsets, strutils, options, ast, astalgo, trees, treetab, msgs, os,
|
||||
idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread,
|
||||
lambdalifting, sempass2, lowerings, lookups
|
||||
|
||||
|
||||
@@ -295,16 +295,14 @@ proc serveTcp(graph: ModuleGraph; cache: IdentCache) =
|
||||
|
||||
stdoutSocket.send("\c\L")
|
||||
stdoutSocket.close()
|
||||
|
||||
|
||||
proc serveEpc(server: Socket; graph: ModuleGraph; cache: IdentCache) =
|
||||
var client = newSocket()
|
||||
# Wait for connection
|
||||
accept(server, client)
|
||||
if gLogging:
|
||||
var it = searchPaths.head
|
||||
while it != nil:
|
||||
logStr(PStrEntry(it).data)
|
||||
it = it.next
|
||||
for it in searchPaths:
|
||||
logStr(it)
|
||||
msgs.writelnHook = proc (line: string) = logStr(line)
|
||||
|
||||
while true:
|
||||
|
||||
Reference in New Issue
Block a user