diff options
author | Aman Gupta <aman@tmm1.net> | 2015-10-06 11:06:41 -0700 |
---|---|---|
committer | Aman Gupta <aman@tmm1.net> | 2015-10-06 11:06:41 -0700 |
commit | eea8d604d07aae569843ebccc5bd7791cff40567 (patch) | |
tree | dbb652a24acbf0dfd28e2921f72b0d92fe4a858d /compiler | |
parent | a01fd5e93f58a2bf9dea4f577218b8ff7d874bbf (diff) | |
parent | 2e413d3186455bf92ee9bae04304cb34cf1f2557 (diff) | |
download | Nim-eea8d604d07aae569843ebccc5bd7791cff40567.tar.gz |
Merge remote-tracking branch 'origin/devel' into fix-test-failures
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 68 | ||||
-rw-r--r-- | compiler/installer.ini | 3 | ||||
-rw-r--r-- | compiler/magicsys.nim | 38 | ||||
-rw-r--r-- | compiler/modules.nim | 7 | ||||
-rw-r--r-- | compiler/pragmas.nim | 18 | ||||
-rw-r--r-- | compiler/vm.nim | 25 | ||||
-rw-r--r-- | compiler/wordrecg.nim | 5 |
7 files changed, 101 insertions, 63 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 32fc76470..6d69dafa5 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -747,6 +747,17 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) = addf(r, ".Field$1", [rope(i)]) putIntoDest(p, d, ty.sons[i], r, a.s) +proc lookupFieldAgain(p: BProc, ty: PType; field: PSym; r: var Rope): PSym = + var ty = ty + assert r != nil + while ty != nil: + assert(ty.kind in {tyTuple, tyObject}) + result = lookupInRecord(ty.n, field.name) + if result != nil: break + if not p.module.compileToCpp: add(r, ".Sup") + ty = getUniqueType(ty.sons[0]) + if result == nil: internalError(field.info, "genCheckedRecordField") + proc genRecordField(p: BProc, e: PNode, d: var TLoc) = var a: TLoc var ty = genRecordFieldAux(p, e, d, a) @@ -758,15 +769,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) = addf(r, ".Field$1", [rope(f.position)]) putIntoDest(p, d, f.typ, r, a.s) else: - var field: PSym = nil - while ty != nil: - if ty.kind notin {tyTuple, tyObject}: - internalError(e.info, "genRecordField") - field = lookupInRecord(ty.n, f.name) - if field != nil: break - if not p.module.compileToCpp: add(r, ".Sup") - ty = getUniqueType(ty.sons[0]) - if field == nil: internalError(e.info, "genRecordField 2 ") + let field = lookupFieldAgain(p, ty, f, r) if field.loc.r == nil: internalError(e.info, "genRecordField 3") addf(r, ".$1", [field.loc.r]) putIntoDest(p, d, field.typ, r, a.s) @@ -774,7 +777,8 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) = proc genInExprAux(p: BProc, e: PNode, a, b, d: var TLoc) -proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = +proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym; + origTy: PType) = var test, u, v: TLoc for i in countup(1, sonsLen(e) - 1): var it = e.sons[i] @@ -786,8 +790,12 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = assert(disc.kind == nkSym) initLoc(test, locNone, it.typ, OnStack) initLocExpr(p, it.sons[1], u) - initLoc(v, locExpr, disc.typ, OnUnknown) - v.r = "$1.$2" % [obj, disc.sym.loc.r] + var o = obj + let d = lookupFieldAgain(p, origTy, disc.sym, o) + initLoc(v, locExpr, d.typ, OnUnknown) + v.r = o + v.r.add(".") + v.r.add(d.loc.r) genInExprAux(p, it, u, v, test) let id = nodeTableTestOrSet(p.module.dataCache, newStrNode(nkStrLit, field.name.s), gBackendId) @@ -804,25 +812,14 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) = if optFieldCheck in p.options: - var - a: TLoc - f, field: PSym - ty: PType - r: Rope - ty = genRecordFieldAux(p, e.sons[0], d, a) - r = rdLoc(a) - f = e.sons[0].sons[1].sym - field = nil - while ty != nil: - assert(ty.kind in {tyTuple, tyObject}) - field = lookupInRecord(ty.n, f.name) - if field != nil: break - if not p.module.compileToCpp: add(r, ".Sup") - ty = getUniqueType(ty.sons[0]) - if field == nil: internalError(e.info, "genCheckedRecordField") + var a: TLoc + let ty = genRecordFieldAux(p, e.sons[0], d, a) + var r = rdLoc(a) + let f = e.sons[0].sons[1].sym + let field = lookupFieldAgain(p, ty, f, r) if field.loc.r == nil: internalError(e.info, "genCheckedRecordField") # generate the checks: - genFieldCheck(p, e, r, field) + genFieldCheck(p, e, r, field, ty) add(r, rfmt(nil, ".$1", field.loc.r)) putIntoDest(p, d, field.typ, r, a.s) else: @@ -1150,20 +1147,15 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = else: constructLoc(p, tmp) discard getTypeDesc(p.module, t) + let ty = getUniqueType(t) for i in 1 .. <e.len: let it = e.sons[i] var tmp2: TLoc tmp2.r = r - var field: PSym = nil - var ty = getUniqueType(t) - while ty != nil: - field = lookupInRecord(ty.n, it.sons[0].sym.name) - if field != nil: break - if not p.module.compileToCpp: add(tmp2.r, ".Sup") - ty = getUniqueType(ty.sons[0]) - if field == nil or field.loc.r == nil: internalError(e.info, "genObjConstr") + let field = lookupFieldAgain(p, ty, it.sons[0].sym, tmp2.r) + if field.loc.r == nil: internalError(e.info, "genObjConstr") if it.len == 3 and optFieldCheck in p.options: - genFieldCheck(p, it.sons[2], tmp2.r, field) + genFieldCheck(p, it.sons[2], tmp2.r, field, ty) add(tmp2.r, ".") add(tmp2.r, field.loc.r) tmp2.k = locTemp diff --git a/compiler/installer.ini b/compiler/installer.ini index c8af38886..729c13503 100644 --- a/compiler/installer.ini +++ b/compiler/installer.ini @@ -115,6 +115,9 @@ Files: "lib/posix/*.nim" Files: "lib/js/*.nim" Files: "lib/packages/docutils/*.nim" +Files: "lib/deprecated/core/*.nim" +Files: "lib/deprecated/pure/*.nim" +Files: "lib/deprecated/pure/*.cfg" [Other] Files: "examples/*.nim" diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim index 98a4b08bf..40e0728ae 100644 --- a/compiler/magicsys.nim +++ b/compiler/magicsys.nim @@ -14,22 +14,14 @@ import var systemModule*: PSym -proc registerSysType*(t: PType) - # magic symbols in the system module: -proc getSysType*(kind: TTypeKind): PType -proc getCompilerProc*(name: string): PSym -proc registerCompilerProc*(s: PSym) -proc finishSystem*(tab: TStrTable) -proc getSysSym*(name: string): PSym -# implementation - var gSysTypes: array[TTypeKind, PType] compilerprocs: TStrTable + exposed: TStrTable proc nilOrSysInt*: PType = gSysTypes[tyInt] -proc registerSysType(t: PType) = +proc registerSysType*(t: PType) = if gSysTypes[t.kind] == nil: gSysTypes[t.kind] = t proc newSysType(kind: TTypeKind, size: int): PType = @@ -37,7 +29,7 @@ proc newSysType(kind: TTypeKind, size: int): PType = result.size = size result.align = size.int16 -proc getSysSym(name: string): PSym = +proc getSysSym*(name: string): PSym = result = strTableGet(systemModule.tab, getIdent(name)) if result == nil: rawMessage(errSystemNeeds, name) @@ -61,7 +53,7 @@ proc getSysMagic*(name: string, m: TMagic): PSym = proc sysTypeFromName*(name: string): PType = result = getSysSym(name).typ -proc getSysType(kind: TTypeKind): PType = +proc getSysType*(kind: TTypeKind): PType = result = gSysTypes[kind] if result == nil: case kind @@ -97,6 +89,7 @@ var proc resetSysTypes* = systemModule = nil initStrTable(compilerprocs) + initStrTable(exposed) for i in low(gSysTypes)..high(gSysTypes): gSysTypes[i] = nil @@ -163,8 +156,8 @@ proc setIntLitType*(result: PNode) = result.typ = getSysType(tyInt64) else: internalError(result.info, "invalid int size") -proc getCompilerProc(name: string): PSym = - var ident = getIdent(name, hashIgnoreStyle(name)) +proc getCompilerProc*(name: string): PSym = + let ident = getIdent(name) result = strTableGet(compilerprocs, ident) if result == nil: result = strTableGet(rodCompilerprocs, ident) @@ -173,9 +166,22 @@ proc getCompilerProc(name: string): PSym = if result.kind == skStub: loadStub(result) if result.kind == skAlias: result = result.owner -proc registerCompilerProc(s: PSym) = +proc registerCompilerProc*(s: PSym) = strTableAdd(compilerprocs, s) -proc finishSystem(tab: TStrTable) = discard +proc registerNimScriptSymbol*(s: PSym) = + # Nimscript symbols must be al unique: + let conflict = strTableGet(exposed, s.name) + if conflict == nil: + strTableAdd(exposed, s) + else: + localError(s.info, "symbol conflicts with other .exportNims symbol at: " & + $conflict.info) + +proc getNimScriptSymbol*(name: string): PSym = + strTableGet(exposed, getIdent(name)) + +proc resetNimScriptSymbols*() = initStrTable(exposed) initStrTable(compilerprocs) +initStrTable(exposed) diff --git a/compiler/modules.nim b/compiler/modules.nim index 85c99c4ec..3893d377e 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -78,6 +78,13 @@ proc resetModule*(fileIdx: int32) = if fileIdx <% cgendata.gModules.len: cgendata.gModules[fileIdx] = nil +proc resetModule*(module: PSym) = + let conflict = getModule(module.position.int32) + if conflict == nil: return + doAssert conflict == module + resetModule(module.position.int32) + initStrTable(module.tab) + proc resetAllModules* = for i in 0..gCompiledModules.high: if gCompiledModules[i] != nil: diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index ba05b2792..79d7884fa 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -25,18 +25,19 @@ const wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC, wAsmNoStackFrame, wError, wDiscardable, wNoInit, wDestructor, wCodegenDecl, wGensym, wInject, wRaises, wTags, wLocks, wDelegator, wGcSafe, - wOverride, wConstructor} + wOverride, wConstructor, wExportNims} converterPragmas* = procPragmas methodPragmas* = procPragmas+{wBase} templatePragmas* = {wImmediate, wDeprecated, wError, wGensym, wInject, wDirty, - wDelegator} + wDelegator, wExportNims} macroPragmas* = {FirstCallConv..LastCallConv, wImmediate, wImportc, wExportc, wNodecl, wMagic, wNosideeffect, wCompilerproc, wDeprecated, wExtern, - wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wDelegator} + wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wDelegator, + wExportNims} iteratorPragmas* = {FirstCallConv..LastCallConv, wNosideeffect, wSideeffect, wImportc, wExportc, wNodecl, wMagic, wDeprecated, wBorrow, wExtern, wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wRaises, - wTags, wLocks, wGcSafe} + wTags, wLocks, wGcSafe, wExportNims} exprPragmas* = {wLine, wLocks, wNoRewrite} stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints, @@ -54,15 +55,15 @@ const wPure, wHeader, wCompilerproc, wFinal, wSize, wExtern, wShallow, wImportCpp, wImportObjC, wError, wIncompleteStruct, wByCopy, wByRef, wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked, - wBorrow, wGcSafe} + wBorrow, wGcSafe, wExportNims} fieldPragmas* = {wImportc, wExportc, wDeprecated, wExtern, wImportCpp, wImportObjC, wError, wGuard, wBitsize} varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl, wMagic, wHeader, wDeprecated, wCompilerproc, wDynlib, wExtern, wImportCpp, wImportObjC, wError, wNoInit, wCompileTime, wGlobal, - wGensym, wInject, wCodegenDecl, wGuard, wGoto} + wGensym, wInject, wCodegenDecl, wGuard, wGoto, wExportNims} constPragmas* = {wImportc, wExportc, wHeader, wDeprecated, wMagic, wNodecl, - wExtern, wImportCpp, wImportObjC, wError, wGensym, wInject} + wExtern, wImportCpp, wImportObjC, wError, wGensym, wInject, wExportNims} letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect, wThread, wRaises, wLocks, wTags, wGcSafe} @@ -859,6 +860,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int, invalidPragma(it) else: sym.flags.incl sfGoto + of wExportNims: + if sym == nil: invalidPragma(it) + else: magicsys.registerNimScriptSymbol(sym) of wInjectStmt: if it.kind != nkExprColonExpr: localError(it.info, errExprExpected) diff --git a/compiler/vm.nim b/compiler/vm.nim index ad4aa1017..ded66d3d0 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1411,6 +1411,31 @@ proc execute(c: PCtx, start: int): PNode = newSeq(tos.slots, c.prc.maxSlots) result = rawExecute(c, start, tos).regToNode +proc execProc*(c: PCtx; sym: PSym; args: openArray[PNode]): PNode = + if sym.kind in routineKinds: + if sym.typ.len-1 != args.len: + localError(sym.info, + "NimScript: expected $# arguments, but got $#" % [ + $(sym.typ.len-1), $args.len]) + else: + let start = genProc(c, sym) + + var tos = PStackFrame(prc: sym, comesFrom: 0, next: nil) + let maxSlots = sym.offset + newSeq(tos.slots, maxSlots) + + # setup parameters: + if not isEmptyType(sym.typ.sons[0]) or sym.kind == skMacro: + putIntoReg(tos.slots[0], getNullValue(sym.typ.sons[0], sym.info)) + # XXX We could perform some type checking here. + for i in 1.. <sym.typ.len: + putIntoReg(tos.slots[i], args[i-1]) + + result = rawExecute(c, start, tos).regToNode + else: + localError(sym.info, + "NimScript: attempt to call non-routine: " & sym.name.s) + proc evalStmt*(c: PCtx, n: PNode) = let n = transformExpr(c.module, n) let start = genStmt(c, n) diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index d1e5438f3..0a0534118 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -42,7 +42,7 @@ type wImmediate, wConstructor, wDestructor, wDelegator, wOverride, wImportCpp, wImportObjC, wImportCompilerProc, - wImportc, wExportc, wIncompleteStruct, wRequiresInit, + wImportc, wExportc, wExportNims, wIncompleteStruct, wRequiresInit, wAlign, wNodecl, wPure, wSideeffect, wHeader, wNosideeffect, wGcSafe, wNoreturn, wMerge, wLib, wDynlib, wCompilerproc, wProcVar, wBase, @@ -126,7 +126,8 @@ const "immediate", "constructor", "destructor", "delegator", "override", "importcpp", "importobjc", - "importcompilerproc", "importc", "exportc", "incompletestruct", + "importcompilerproc", "importc", "exportc", "exportnims", + "incompletestruct", "requiresinit", "align", "nodecl", "pure", "sideeffect", "header", "nosideeffect", "gcsafe", "noreturn", "merge", "lib", "dynlib", "compilerproc", "procvar", "base", |