summary refs log tree commit diff stats
path: root/compiler/lowerings.nim
Commit message (Expand)AuthorAgeFilesLines
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-9/+9
* fix #15463 (#15831)flywind2020-11-051-0/+1
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-29/+32
* fixes #15076 (#15329)Andreas Rumpf2020-09-151-1/+1
* Expand hoisted default params in sem (#15270)Clyybber2020-09-051-11/+0
* init checks and 'out' parameters (#14521)Andreas Rumpf2020-06-231-1/+1
* Step2: fixes #13781, fixes #13805 (#13897)cooldome2020-04-161-0/+7
* fixes #13708 (#13711)cooldome2020-03-211-2/+2
* fixes #13368 (#13397)cooldome2020-02-141-2/+3
* make case-object transitions explicit, make unknownLineInfo a const, replace ...Jasper Jenkins2020-01-171-1/+1
* Sink to MemMove optimization in injectdestructors (#13002)cooldome2020-01-021-2/+8
* fixes #12989 (#12992)cooldome2019-12-311-1/+0
* Revert "fixes #12989"Andrii Riabushenko2019-12-311-0/+1
* fixes #12989Andrii Riabushenko2019-12-311-1/+0
* ARC: fixes cycle detection and move the .cursor attribute into closures (#12872)Andreas Rumpf2019-12-111-0/+1
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-76/+76
* ARC: ported the GC tests over to --gc:arcAraq2019-11-261-0/+1
* Revert "ARC: another critical bugfix; temporary tuples we introduce for tuple...narimiran2019-11-241-1/+0
* ARC: another critical bugfix; temporary tuples we introduce for tuple unpacka...Araq2019-11-221-0/+1
* more arc improvements (#12690)Andreas Rumpf2019-11-201-0/+8
* Small ast.nim cleanup (#12156)Clyybber2019-09-091-5/+5
* Support iterators returning lent T (#11938)cooldome2019-08-311-2/+2
* int128 on firstOrd, lastOrd and lengthOrd (#11701)Arne Döring2019-08-071-2/+2
* [refactoring] remove unused imports in the compiler and in some stdlib modulesAraq2019-07-181-1/+0
* [refactoring] moves transformation for 'spawn' into its own spawn.nim impleme...Araq2019-07-141-428/+15
* fixes #7057Andreas Rumpf2019-07-061-1/+1
* [bugfix] owned closures (#11544)Andreas Rumpf2019-06-201-0/+3
* fixes #11215Araq2019-05-121-2/+2
* rename tyExpr/tyStmt to tyUntyped/tyTyped (#11227)Arne Döring2019-05-111-2/+2
* Replace countup(x, y-1) with x ..< yClyybber2019-05-071-2/+2
* added lowerings.evalOnceAraq2019-04-091-0/+16
* more destructor based changes (#10885)Andreas Rumpf2019-03-231-1/+1
* added lowerings.genLen helper procAndreas Rumpf2019-03-141-0/+9
* Tuple unpacking now works for `for` vars (#10152)Neelesh Chandola2019-02-231-6/+14
* Destructors: more moves for tuples (#9808)cooldome2018-11-271-1/+1
* Change the order of compilation passes, transformation is made lazy at code g...cooldome2018-10-181-0/+2
* Field checks for everybody (#8957)LemonBoy2018-10-091-12/+18
* allow referencing other parameters in default parameter valuesZahary Karadjov2018-06-161-0/+12
* refactoring: remove idents.legacy global variable and pass the IdentCache aro...Andreas Rumpf2018-05-271-37/+37
* remove more global variables in the Nim compilerAndreas Rumpf2018-05-271-1/+2
* platform.nim doesn't use globals anymore; prepare msgs.nim for not using globalsAndreas Rumpf2018-05-181-2/+2
* preparations of making compiler/msgs.nim free of global variablesAndreas Rumpf2018-05-171-1/+1
* remove ast.emptyNode global; cleanup configuration.nimAraq2018-05-161-9/+13
* options.nim: no global variables anymoreAndreas Rumpf2018-05-131-20/+24
* lambda lifting compiles againAndreas Rumpf2018-05-121-62/+62
* preparations for language extensions: 'sink' and 'lent' typesAndreas Rumpf2018-01-071-2/+2
* implemented undocumented '.liftLocals' featureAndreas Rumpf2017-11-021-2/+4
* deprecated unary '<'Andreas Rumpf2017-10-291-2/+2
* initial version of the new untested destructor passAndreas Rumpf2017-10-121-0/+11
* first implementation of the 'func' keywordAndreas Rumpf2017-09-231-1/+1
pan class="w"> result = renderTree(n, {renderNoComments}).replace(" ") of nkDotExpr: result = renderTree(n, {renderNoComments}).replace(".", "/") of nkImportAs: result = getModuleName(n.sons[0]) else: localError(n.info, errGenerated, "invalid module name: '$1'" % n.renderTree) result = "" proc checkModuleName*(n: PNode): int32 = # This returns the full canonical path for a given module import let modulename = n.getModuleName let fullPath = findModule(modulename, n.info.toFullPath) if fullPath.len == 0: localError(n.info, errCannotOpenFile, modulename) result = InvalidFileIDX else: result = fullPath.fileInfoIdx proc rawImportSymbol(c: PContext, s: PSym) = # This does not handle stubs, because otherwise loading on demand would be # pointless in practice. So importing stubs is fine here! # check if we have already a symbol of the same name: var check = strTableGet(c.importTable.symbols, s.name) if check != nil and check.id != s.id: if s.kind notin OverloadableSyms: # s and check need to be qualified: incl(c.ambiguousSymbols, s.id) incl(c.ambiguousSymbols, check.id) # thanks to 'export' feature, it could be we import the same symbol from # multiple sources, so we need to call 'StrTableAdd' here: strTableAdd(c.importTable.symbols, s) if s.kind == skType: var etyp = s.typ if etyp.kind in {tyBool, tyEnum} and sfPure notin s.flags: for j in countup(0, sonsLen(etyp.n) - 1): var e = etyp.n.sons[j].sym if e.kind != skEnumField: internalError(s.info, "rawImportSymbol") # BUGFIX: because of aliases for enums the symbol may already # have been put into the symbol table # BUGFIX: but only iff they are the same symbols! var it: TIdentIter check = initIdentIter(it, c.importTable.symbols, e.name) while check != nil: if check.id == e.id: e = nil break check = nextIdentIter(it, c.importTable.symbols) if e != nil: rawImportSymbol(c, e) else: # rodgen assures that converters and patterns are no stubs if s.kind == skConverter: addConverter(c, s) if hasPattern(s): addPattern(c, s) proc importSymbol(c: PContext, n: PNode, fromMod: PSym) = let ident = lookups.considerQuotedIdent(n) let s = strTableGet(fromMod.tab, ident) if s == nil: localError(n.info, errUndeclaredIdentifier, ident.s) else: if s.kind == skStub: loadStub(s) if s.kind notin ExportableSymKinds: internalError(n.info, "importSymbol: 2") # for an enumeration we have to add all identifiers case s.kind of skProcKinds: # for a overloadable syms add all overloaded routines var it: TIdentIter var e = initIdentIter(it, fromMod.tab, s.name) while e != nil: if e.name.id != s.name.id: internalError(n.info, "importSymbol: 3") rawImportSymbol(c, e) e = nextIdentIter(it, fromMod.tab) else: rawImportSymbol(c, s) proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) = var i: TTabIter var s = initTabIter(i, fromMod.tab) while s != nil: if s.kind != skModule: if s.kind != skEnumField: if s.kind notin ExportableSymKinds: internalError(s.info, "importAllSymbols: " & $s.kind) if exceptSet.empty or s.name.id notin exceptSet: rawImportSymbol(c, s) s = nextIter(i, fromMod.tab) proc importAllSymbols*(c: PContext, fromMod: PSym) = var exceptSet: IntSet importAllSymbolsExcept(c, fromMod, exceptSet) proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet) = if n.isNil: return case n.kind of nkExportStmt: for a in n: assert a.kind == nkSym let s = a.sym if s.kind == skModule: importAllSymbolsExcept(c, s, exceptSet) elif exceptSet.empty or s.name.id notin exceptSet: rawImportSymbol(c, s) of nkExportExceptStmt: localError(n.info, errGenerated, "'export except' not implemented") else: for i in 0 ..safeLen(n)-1: importForwarded(c, n.sons[i], exceptSet) proc importModuleAs(n: PNode, realModule: PSym): PSym = result = realModule if n.kind != nkImportAs: discard elif n.len != 2 or n.sons[1].kind != nkIdent: localError(n.info, errGenerated, "module alias must be an identifier") elif n.sons[1].ident.id != realModule.name.id: # some misguided guy will write 'import abc.foo as foo' ... result = createModuleAlias(realModule, n.sons[1].ident, realModule.info) proc myImportModule(c: PContext, n: PNode): PSym = var f = checkModuleName(n) if f != InvalidFileIDX: result = importModuleAs(n, gImportModule(c.module, f)) if result.info.fileIndex == n.info.fileIndex: localError(n.info, errGenerated, "A module cannot import itself") if sfDeprecated in result.flags: message(n.info, warnDeprecated, result.name.s) proc evalImport(c: PContext, n: PNode): PNode = result = n var emptySet: IntSet for i in countup(0, sonsLen(n) - 1): var m = myImportModule(c, n.sons[i]) if m != nil: # ``addDecl`` needs to be done before ``importAllSymbols``! addDecl(c, m) # add symbol to symbol table of module importAllSymbolsExcept(c, m, emptySet) #importForwarded(c, m.ast, emptySet) proc evalFrom(c: PContext, n: PNode): PNode = result = n checkMinSonsLen(n, 2) var m = myImportModule(c, n.sons[0]) if m != nil: n.sons[0] = newSymNode(m) addDecl(c, m) # add symbol to symbol table of module for i in countup(1, sonsLen(n) - 1): if n.sons[i].kind != nkNilLit: importSymbol(c, n.sons[i], m) proc evalImportExcept*(c: PContext, n: PNode): PNode = result = n checkMinSonsLen(n, 2) var m = myImportModule(c, n.sons[0]) if m != nil: n.sons[0] = newSymNode(m) addDecl(c, m) # add symbol to symbol table of module var exceptSet = initIntSet() for i in countup(1, sonsLen(n) - 1): let ident = lookups.considerQuotedIdent(n.sons[i]) exceptSet.incl(ident.id) importAllSymbolsExcept(c, m, exceptSet) #importForwarded(c, m.ast, exceptSet)