Showing with 2,245 additions and 884 deletions.
  1. +1 −1 .github/workflows/ci_docs.yml
  2. +1 −1 .github/workflows/ci_packages.yml
  3. +2 −2 azure-pipelines.yml
  4. +1 −1 build_all.bat
  5. +1 −1 build_all.sh
  6. +2 −0 changelog.md
  7. +0 −21 compiler/ast.nim
  8. +15 −0 compiler/ccgexprs.nim
  9. +14 −1 compiler/ccgreset.nim
  10. +65 −31 compiler/cgen.nim
  11. +28 −6 compiler/closureiters.nim
  12. +51 −7 compiler/depends.nim
  13. +7 −9 compiler/docgen.nim
  14. +2 −2 compiler/docgen2.nim
  15. +4 −4 compiler/evalffi.nim
  16. +28 −35 compiler/extccomp.nim
  17. +4 −4 compiler/ic/bitabs.nim
  18. +3 −2 compiler/ic/cbackend.nim
  19. +6 −13 compiler/ic/ic.nim
  20. +1 −2 compiler/ic/rodfiles.nim
  21. +26 −3 compiler/injectdestructors.nim
  22. +3 −0 compiler/liftdestructors.nim
  23. +42 −29 compiler/linter.nim
  24. +88 −26 compiler/modulegraphs.nim
  25. +15 −94 compiler/modulepaths.nim
  26. +3 −48 compiler/modules.nim
  27. +2 −2 compiler/msgs.nim
  28. +1 −0 compiler/nim.cfg
  29. +16 −8 compiler/options.nim
  30. +3 −20 compiler/packagehandling.nim
  31. +49 −0 compiler/packages.nim
  32. +9 −9 compiler/passes.nim
  33. +1 −1 compiler/plugins/locals.nim
  34. +5 −6 compiler/pragmas.nim
  35. +1 −1 compiler/semexprs.nim
  36. +1 −1 compiler/semfold.nim
  37. +1 −1 compiler/semgnrc.nim
  38. +1 −1 compiler/semmagic.nim
  39. +8 −8 compiler/semstmts.nim
  40. +13 −7 compiler/semtempl.nim
  41. +4 −4 compiler/semtypes.nim
  42. +39 −19 compiler/suggest.nim
  43. +1 −1 compiler/varpartitions.nim
  44. +34 −22 compiler/vm.nim
  45. +2 −8 compiler/vmgen.nim
  46. +32 −32 compiler/vmops.nim
  47. +7 −7 compiler/wordrecg.nim
  48. +5 −0 config/config.nims
  49. +3 −0 config/nim.cfg
  50. +21 −8 doc/manual.rst
  51. +2 −2 doc/testament.rst
  52. +2 −2 koch.nim
  53. +3 −1 lib/core/macros.nim
  54. +11 −12 lib/impure/db_mysql.nim
  55. +6 −1 lib/packages/docutils/rst.nim
  56. +14 −5 lib/posix/epoll.nim
  57. +1 −1 lib/posix/posix.nim
  58. +1 −1 lib/posix/posix_linux_amd64.nim
  59. +3 −3 lib/pure/asyncdispatch.nim
  60. +3 −3 lib/pure/asyncnet.nim
  61. +1 −1 lib/pure/collections/sequtils.nim
  62. +1 −1 lib/pure/cookies.nim
  63. +1 −1 lib/pure/ioselects/ioselectors_epoll.nim
  64. +8 −8 lib/pure/ioselects/ioselectors_select.nim
  65. +6 −6 lib/pure/json.nim
  66. +2 −2 lib/pure/nativesockets.nim
  67. +35 −18 lib/pure/net.nim
  68. +8 −4 lib/pure/options.nim
  69. +6 −6 lib/pure/parsesql.nim
  70. +6 −3 lib/pure/pegs.nim
  71. +16 −15 lib/pure/punycode.nim
  72. +1 −1 lib/pure/segfaults.nim
  73. +5 −0 lib/pure/streams.nim
  74. +3 −2 lib/std/jsfetch.nim
  75. +1 −1 lib/std/strbasics.nim
  76. +3 −4 lib/std/sysrand.nim
  77. +3 −3 lib/std/tasks.nim
  78. +1 −1 lib/system.nim
  79. +8 −1 lib/system/ansi_c.nim
  80. +3 −0 lib/system/widestrs.nim
  81. +9 −9 lib/windows/registry.nim
  82. +1 −1 lib/windows/winlean.nim
  83. +234 −14 nimsuggest/nimsuggest.nim
  84. +5 −2 nimsuggest/tester.nim
  85. +31 −0 nimsuggest/tests/tv3.nim
  86. +9 −0 nimsuggest/tests/tv3_definition.nim
  87. +7 −0 nimsuggest/tests/tv3_import.nim
  88. +32 −0 nimsuggest/tests/tv3_typeDefinition.nim
  89. +6 −6 testament/categories.nim
  90. +50 −47 testament/testament.nim
  91. +13 −0 tests/arc/t19862.nim
  92. +13 −0 tests/arc/tarc_orc.nim
  93. +45 −0 tests/arc/tcursorloop.nim
  94. +2 −2 tests/arc/tmovebug.nim
  95. +2 −2 tests/arc/tmovebugcopy.nim
  96. +1 −1 tests/array/tarray.nim
  97. +2 −2 tests/async/tioselectors.nim
  98. +11 −0 tests/casestmt/tcasestmt.nim
  99. +25 −0 tests/ccgbugs/tderefblock.nim
  100. +1 −1 tests/ccgbugs/tforward_decl_only.nim
  101. +2 −2 tests/closure/tclosure.nim
  102. +1 −1 tests/compiles/trecursive_generic_in_compiles.nim
  103. +4 −4 tests/concepts/tconcepts_issues.nim
  104. +2 −0 tests/config.nims
  105. +1 −1 tests/converter/tconverter_with_varargs.nim
  106. +4 −4 tests/cpp/tcovariancerules.nim
  107. +1 −1 tests/destructor/tmove_objconstr.nim
  108. +1 −1 tests/errmsgs/t17460.nim
  109. +1 −1 tests/errmsgs/tproper_stacktrace.nim
  110. +2 −2 tests/errmsgs/tsigmatch.nim
  111. +1 −1 tests/generics/tgenerics_issues.nim
  112. +2 −2 tests/generics/tgenerics_various.nim
  113. +1 −1 tests/iter/titer13.nim
  114. +78 −2 tests/iter/titer_issues.nim
  115. +1 −1 tests/iter/tmoditer.nim
  116. +1 −1 tests/iter/tpermutations.nim
  117. +8 −0 tests/iter/tyieldintry.nim
  118. +2 −2 tests/js/t9410.nim
  119. +1 −1 tests/js/tbasics.nim
  120. +2 −2 tests/js/tbyvar.nim
  121. +1 −1 tests/lent/tbasic_lent_check.nim
  122. +28 −0 tests/macros/t20067.nim
  123. +1 −1 tests/magics/tmagics.nim
  124. +1 −1 tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim
  125. +1 −1 tests/manyloc/named_argument_bug/tri_engine/gfx/gl/primitive.nim
  126. +11 −0 tests/misc/mjsondoc.nim
  127. +1 −1 tests/misc/t9039.nim
  128. +1 −1 tests/misc/theaproots.nim
  129. +1 −0 tests/misc/tlocals.nim
  130. +17 −0 tests/misc/trunner.nim
  131. +1 −1 tests/misc/tsimplesort.nim
  132. +8 −0 tests/modules/a/module_name_clashes.nim
  133. +3 −0 tests/modules/b/module_name_clashes.nim
  134. +16 −0 tests/modules/tmodule_name_clashes.nim
  135. +1 −1 tests/openarray/topena1.nim
  136. +2 −2 tests/openarray/topenarrayrepr.nim
  137. +1 −1 tests/openarray/topenlen.nim
  138. +3 −3 tests/openarray/tptrarrayderef.nim
  139. +2 −2 tests/overload/toverload_various.nim
  140. 0 tests/package/stdlib/stdlib.nimble
  141. +2 −0 tests/package/stdlib/system.nim
  142. +3 −0 tests/package/tstdlib_name_not_special.nim
  143. +7 −0 tests/pragmas/tcustom_pragma.nim
  144. +2 −2 tests/showoff/tdrdobbs_examples.nim
  145. +2 −0 tests/stdlib/config.nims
  146. +2 −2 tests/stdlib/nre/misc.nim
  147. +2 −2 tests/stdlib/talgorithm.nim
  148. +4 −4 tests/stdlib/tasynchttpserver.nim
  149. +3 −3 tests/stdlib/tbase64.nim
  150. +2 −2 tests/stdlib/tbitops.nim
  151. +4 −0 tests/stdlib/tdb_mysql.nim
  152. +1 −1 tests/stdlib/thttpclient.nim
  153. +2 −2 tests/stdlib/tjsonmacro.nim
  154. +1 −1 tests/stdlib/tjsonutils.nim
  155. +1 −1 tests/stdlib/tnet.nim
  156. +1 −1 tests/stdlib/tnetdial.nim
  157. +1 −1 tests/stdlib/tosproc.nim
  158. +2 −2 tests/stdlib/tparseipv6.nim
  159. +43 −43 tests/stdlib/tparsesql.nim
  160. +4 −0 tests/stdlib/tpegs.nim
  161. +201 −1 tests/stdlib/tpunycode.nim
  162. +1 −1 tests/stdlib/trepr.nim
  163. +32 −5 tests/stdlib/trst.nim
  164. +4 −4 tests/stdlib/trstgen.nim
  165. +1 −1 tests/stdlib/tsha1.nim
  166. +2 −2 tests/stdlib/tssl.nim
  167. +1 −1 tests/stdlib/tstrbasics.nim
  168. +11 −1 tests/stdlib/tstreams.nim
  169. +34 −26 tests/stdlib/tstrscans.nim
  170. +1 −1 tests/stdlib/tstrset.nim
  171. +27 −0 tests/stdlib/tsystem.nim
  172. +1 −1 tests/stdlib/ttimes.nim
  173. +1 −1 tests/stdlib/ttypeinfo.nim
  174. +1 −0 tests/stdlib/ttypeinfo.nims
  175. +2 −2 tests/stdlib/tunicode.nim
  176. +1 −1 tests/stdlib/tvarints.nim
  177. +1 −1 tests/system/tostring.nim
  178. +2 −2 tests/system/tsystem_misc.nim
  179. +2 −2 tests/template/otests.nim
  180. +1 −1 tests/template/sunset.nimf
  181. +16 −0 tests/template/t13515.nim
  182. +1 −1 tests/template/template_issues.nim
  183. +2 −2 tests/tuples/tuple_with_nil.nim
  184. +1 −1 tests/typerel/tcommontype.nim
  185. +1 −1 tests/typerel/texplicitcmp.nim
  186. +3 −3 tests/typerel/tstr_as_openarray.nim
  187. +1 −1 tests/views/tviews1.nim
  188. +6 −0 tests/vm/t19199.nim
  189. +49 −1 tests/vm/tissues.nim
  190. +196 −0 tests/vm/tmisc_vm.nim
  191. +1 −1 tests/vm/tyaytypedesc.nim
  192. +1 −1 tools/ci_generate.nim
2 changes: 1 addition & 1 deletion .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- target: windows
os: windows-2019
- target: osx
os: macos-10.15
os: macos-11

name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-10.15]
os: [ubuntu-20.04, macos-11]
cpu: [amd64]
batch: ["allowed_failures", "0_3", "1_3", "2_3"] # list of `index_num`
name: '${{ matrix.os }} (batch: ${{ matrix.batch }})'
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
vmImage: 'ubuntu-18.04'
CPU: i386
OSX_amd64:
vmImage: 'macOS-10.15'
vmImage: 'macOS-11'
CPU: amd64
OSX_amd64_cpp:
vmImage: 'macOS-10.15'
vmImage: 'macOS-11'
CPU: amd64
NIM_COMPILE_TO_CPP: true
Windows_amd64_batch0_3:
Expand Down
2 changes: 1 addition & 1 deletion build_all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ if not exist %nim_csources% (
cd ..
copy /y bin\nim.exe %nim_csources%
)
bin\nim.exe c --skipUserCfg --skipParentCfg --hints:off koch
bin\nim.exe c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch
koch boot -d:release --skipUserCfg --skipParentCfg --hints:off
koch tools --skipUserCfg --skipParentCfg --hints:off
2 changes: 1 addition & 1 deletion build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -e # exit on first error
. ci/funs.sh
nimBuildCsourcesIfNeeded "$@"

echo_run bin/nim c --skipUserCfg --skipParentCfg --hints:off koch
echo_run bin/nim c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch
echo_run ./koch boot -d:release --skipUserCfg --skipParentCfg --hints:off
echo_run ./koch tools --skipUserCfg --skipParentCfg --hints:off

2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
- `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
without requiring `-d:nimVersion140` which is now a noop.

- `--styleCheck` now only applies to the current package.


## Tool changes

Expand Down
21 changes: 0 additions & 21 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1105,21 +1105,6 @@ proc getPIdent*(a: PNode): PIdent {.inline.} =
of nkIdent: a.ident
else: nil

proc getnimblePkg*(a: PSym): PSym =
result = a
while result != nil:
case result.kind
of skModule:
result = result.owner
assert result.kind == skPackage
of skPackage:
if result.owner == nil:
break
else:
result = result.owner
else:
assert false, $result.kind

const
moduleShift = when defined(cpu32): 20 else: 24

Expand Down Expand Up @@ -1164,13 +1149,7 @@ when false:
assert dest.ItemId.item <= src.ItemId.item
dest = src

proc getnimblePkgId*(a: PSym): int =
let b = a.getnimblePkg
result = if b == nil: -1 else: b.id

var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things
#var
# gMainPackageId*: int

proc isCallExpr*(n: PNode): bool =
result = n.kind in nkCallKinds
Expand Down
15 changes: 15 additions & 0 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,22 @@ proc isCppRef(p: BProc; typ: PType): bool {.inline.} =
skipTypes(typ, abstractInstOwned).kind in {tyVar} and
tfVarIsPtr notin skipTypes(typ, abstractInstOwned).flags

proc derefBlock(p: BProc, e: PNode, d: var TLoc) =
# We transform (block: x)[] to (block: x[])
let e0 = e[0]
var n = shallowCopy(e0)
n.typ = e.typ
for i in 0 ..< e0.len - 1:
n[i] = e0[i]
n[e0.len-1] = newTreeIT(nkHiddenDeref, e.info, e.typ, e0[e0.len-1])
expr p, n, d

proc genDeref(p: BProc, e: PNode, d: var TLoc) =
if e.kind == nkHiddenDeref and e[0].kind in {nkBlockExpr, nkBlockStmt}:
# bug #20107. Watch out to not deref the pointer too late.
derefBlock(p, e, d)
return

let mt = mapType(p.config, e[0].typ, mapTypeChooser(e[0]))
if mt in {ctArray, ctPtrToArray} and lfEnforceDeref notin d.flags:
# XXX the amount of hacks for C's arrays is incredible, maybe we should
Expand Down
15 changes: 14 additions & 1 deletion compiler/ccgreset.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,20 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) =
lineCg(p, cpsStmts, "$1 = 0;$n", [accessor])
of tyCstring, tyPointer, tyPtr, tyVar, tyLent:
lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [accessor])
else:
of tySet:
case mapSetType(p.config, typ)
of ctArray:
lineCg(p, cpsStmts, "#nimZeroMem($1, sizeof($2));$n",
[accessor, getTypeDesc(p.module, typ)])
of ctInt8, ctInt16, ctInt32, ctInt64:
lineCg(p, cpsStmts, "$1 = 0;$n", [accessor])
else:
doAssert false, "unexpected set type kind"
of {tyNone, tyEmpty, tyNil, tyUntyped, tyTyped, tyGenericInvocation,
tyGenericParam, tyOrdinal, tyRange, tyOpenArray, tyForward, tyVarargs,
tyUncheckedArray, tyProxy, tyBuiltInTypeClass, tyUserTypeClass,
tyUserTypeClassInst, tyCompositeTypeClass, tyAnd, tyOr, tyNot,
tyAnything, tyStatic, tyFromExpr, tyConcept, tyVoid, tyIterable}:
discard

proc specializeReset(p: BProc, a: TLoc) =
Expand Down
96 changes: 65 additions & 31 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import
ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth,
rodutils, renderer, cgendata, aliases,
lowerings, tables, sets, ndi, lineinfos, pathutils, transf,
injectdestructors, astmsgs
injectdestructors, astmsgs, modulepaths

when not defined(leanCompiler):
import spawn, semparallel
Expand Down Expand Up @@ -1302,17 +1302,19 @@ proc getFileHeader(conf: ConfigRef; cfile: Cfile): Rope =
if conf.hcrOn: result.add("#define NIM_HOT_CODE_RELOADING\L")
addNimDefines(result, conf)

proc getSomeNameForModule(m: PSym): Rope =
assert m.kind == skModule
assert m.owner.kind == skPackage
if {sfSystemModule, sfMainModule} * m.flags == {}:
result = m.owner.name.s.mangle.rope
result.add "_"
result.add m.name.s.mangle
proc getSomeNameForModule(conf: ConfigRef, filename: AbsoluteFile): Rope =
## Returns a mangled module name.
result.add mangleModuleName(conf, filename).mangle

proc getSomeNameForModule(m: BModule): Rope =
## Returns a mangled module name.
assert m.module.kind == skModule
assert m.module.owner.kind == skPackage
result.add mangleModuleName(m.g.config, m.filename).mangle

proc getSomeInitName(m: BModule, suffix: string): Rope =
if not m.hcrOn:
result = getSomeNameForModule(m.module)
result = getSomeNameForModule(m)
result.add suffix

proc getInitName(m: BModule): Rope =
Expand Down Expand Up @@ -1363,16 +1365,25 @@ proc genMainProc(m: BModule) =
# The use of a volatile function pointer to call Pre/NimMainInner
# prevents inlining of the NimMainInner function and dependent
# functions, which might otherwise merge their stack frames.
PreMainBody = "$N" &

PreMainVolatileBody =
"\tvoid (*volatile inner)(void);$N" &
"\tinner = PreMainInner;$N" &
"$1" &
"\t(*inner)();$N"

PreMainNonVolatileBody =
"$1" &
"\tPreMainInner();$N"

PreMainBodyStart = "$N" &
"N_LIB_PRIVATE void PreMainInner(void) {$N" &
"$2" &
"}$N$N" &
PosixCmdLine &
"N_LIB_PRIVATE void PreMain(void) {$N" &
"\tvoid (*volatile inner)(void);$N" &
"\tinner = PreMainInner;$N" &
"$1" &
"\t(*inner)();$N" &
"N_LIB_PRIVATE void PreMain(void) {$N"

PreMainBodyEnd =
"}$N$N"

MainProcs =
Expand All @@ -1385,17 +1396,32 @@ proc genMainProc(m: BModule) =
"$1" &
"}$N$N"

NimMainProc =
"N_CDECL(void, $5NimMain)(void) {$N" &
"\tvoid (*volatile inner)(void);$N" &
"$4" &
"\tinner = NimMainInner;$N" &
"$2" &
"\t(*inner)();$N" &
NimMainVolatileBody =
"\tvoid (*volatile inner)(void);$N" &
"$4" &
"\tinner = NimMainInner;$N" &
"$2" &
"\t(*inner)();$N"

NimMainNonVolatileBody =
"$4" &
"$2" &
"\tNimMainInner();$N"

NimMainProcStart =
"N_CDECL(void, $5NimMain)(void) {$N"

NimMainProcEnd =
"}$N$N"

NimMainProc = NimMainProcStart & NimMainVolatileBody & NimMainProcEnd

NimSlimMainProc = NimMainProcStart & NimMainNonVolatileBody & NimMainProcEnd

NimMainBody = NimMainInner & NimMainProc

NimSlimMainBody = NimMainInner & NimSlimMainProc

PosixCMain =
"int main(int argc, char** args, char** env) {$N" &
"\tcmdLine = args;$N" &
Expand Down Expand Up @@ -1456,10 +1482,13 @@ proc genMainProc(m: BModule) =
m.includeHeader("<libc/component.h>")

let initStackBottomCall =
if m.config.target.targetOS == osStandalone or m.config.selectedGC == gcNone: "".rope
if m.config.target.targetOS == osStandalone or m.config.selectedGC in {gcNone, gcArc, gcOrc}: "".rope
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N", [])
inc(m.labels)
appcg(m, m.s[cfsProcs], PreMainBody, [m.g.mainDatInit, m.g.otherModsInit])
if m.config.selectedGC notin {gcNone, gcArc, gcOrc}:
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit])
else:
appcg(m, m.s[cfsProcs], PreMainBodyStart & PreMainNonVolatileBody & PreMainBodyEnd, [m.g.mainDatInit, m.g.otherModsInit])

if m.config.target.targetOS == osWindows and
m.config.globalOptions * {optGenGuiApp, optGenDynLib} != {}:
Expand All @@ -1484,9 +1513,14 @@ proc genMainProc(m: BModule) =
appcg(m, m.s[cfsProcs], nimMain,
[m.g.mainModInit, initStackBottomCall, m.labels, preMainCode, m.config.nimMainPrefix])
else:
const nimMain = NimMainBody
appcg(m, m.s[cfsProcs], nimMain,
[m.g.mainModInit, initStackBottomCall, m.labels, preMainCode, m.config.nimMainPrefix])
if m.config.selectedGC notin {gcNone, gcArc, gcOrc}:
const nimMain = NimMainBody
appcg(m, m.s[cfsProcs], nimMain,
[m.g.mainModInit, initStackBottomCall, m.labels, preMainCode, m.config.nimMainPrefix])
else:
const nimMain = NimSlimMainBody
appcg(m, m.s[cfsProcs], nimMain,
[m.g.mainModInit, initStackBottomCall, m.labels, preMainCode, m.config.nimMainPrefix])

if optNoMain notin m.config.globalOptions:
if m.config.cppCustomNamespace.len > 0:
Expand Down Expand Up @@ -1519,11 +1553,11 @@ proc genMainProc(m: BModule) =
proc registerInitProcs*(g: BModuleList; m: PSym; flags: set[ModuleBackendFlag]) =
## Called from the IC backend.
if HasDatInitProc in flags:
let datInit = getSomeNameForModule(m) & "DatInit000"
let datInit = getSomeNameForModule(g.config, g.config.toFullPath(m.info.fileIndex).AbsoluteFile) & "DatInit000"
g.mainModProcs.addf("N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit])
g.mainDatInit.addf("\t$1();$N", [datInit])
if HasModuleInitProc in flags:
let init = getSomeNameForModule(m) & "Init000"
let init = getSomeNameForModule(g.config, g.config.toFullPath(m.info.fileIndex).AbsoluteFile) & "Init000"
g.mainModProcs.addf("N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init])
let initCall = "\t$1();$N" % [init]
if sfMainModule in m.flags:
Expand Down Expand Up @@ -1904,7 +1938,7 @@ proc getCFile(m: BModule): AbsoluteFile =
if m.compileToCpp: ".nim.cpp"
elif m.config.backend == backendObjc or sfCompileToObjc in m.module.flags: ".nim.m"
else: ".nim.c"
result = changeFileExt(completeCfilePath(m.config, withPackageName(m.config, m.cfilename)), ext)
result = changeFileExt(completeCfilePath(m.config, mangleModuleName(m.config, m.cfilename).AbsoluteFile), ext)

when false:
proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext =
Expand Down Expand Up @@ -2057,7 +2091,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) =
discard cgsym(m, "rawWrite")

# raise dependencies on behalf of genMainProc
if m.config.target.targetOS != osStandalone and m.config.selectedGC != gcNone:
if m.config.target.targetOS != osStandalone and m.config.selectedGC notin {gcNone, gcArc, gcOrc}:
discard cgsym(m, "initStackBottomWith")
if emulatedThreadVars(m.config) and m.config.target.targetOS != osStandalone:
discard cgsym(m, "initThreadVarsEmulation")
Expand Down
34 changes: 28 additions & 6 deletions compiler/closureiters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
# yield 2
# if :unrollFinally: # This node is created by `newEndFinallyNode`
# if :curExc.isNil:
# return :tmpResult
# if nearestFinally == 0:
# return :tmpResult
# else:
# :state = nearestFinally # bubble up
# else:
# closureIterSetupExc(nil)
# raise
Expand Down Expand Up @@ -804,7 +807,10 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
# Generate the following code:
# if :unrollFinally:
# if :curExc.isNil:
# return :tmpResult
# if nearestFinally == 0:
# return :tmpResult
# else:
# :state = nearestFinally # bubble up
# else:
# raise
let curExc = ctx.newCurExcAccess()
Expand All @@ -813,11 +819,20 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
let cmp = newTree(nkCall, newSymNode(ctx.g.getSysMagic(info, "==", mEqRef), info), curExc, nilnode)
cmp.typ = ctx.g.getSysType(info, tyBool)

let asgn = newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
ctx.newTmpResultAccess())
let retStmt =
if ctx.nearestFinally == 0:
# last finally, we can return
let retValue = if ctx.fn.typ[0].isNil:
ctx.g.emptyNode
else:
newTree(nkFastAsgn,
newSymNode(getClosureIterResult(ctx.g, ctx.fn, ctx.idgen), info),
ctx.newTmpResultAccess())
newTree(nkReturnStmt, retValue)
else:
# bubble up to next finally
newTree(nkGotoState, ctx.g.newIntLit(info, ctx.nearestFinally))

let retStmt = newTree(nkReturnStmt, asgn)
let branch = newTree(nkElifBranch, cmp, retStmt)

let nullifyExc = newTree(nkCall, newSymNode(ctx.g.getCompilerProc("closureIterSetupExc")), nilnode)
Expand Down Expand Up @@ -861,6 +876,13 @@ proc transformReturnsInTry(ctx: var Ctx, n: PNode): PNode =

of nkSkip:
discard
of nkTryStmt:
if n.hasYields:
# the inner try will handle these transformations
discard
else:
for i in 0..<n.len:
n[i] = ctx.transformReturnsInTry(n[i])
else:
for i in 0..<n.len:
n[i] = ctx.transformReturnsInTry(n[i])
Expand Down
Loading