diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/jsgen.nim | 5 | ||||
-rw-r--r-- | compiler/lowerings.nim | 26 | ||||
-rw-r--r-- | compiler/main.nim | 5 | ||||
-rw-r--r-- | compiler/modules.nim | 1 | ||||
-rw-r--r-- | compiler/nim.cfg | 1 | ||||
-rw-r--r-- | compiler/scriptconfig.nim | 3 | ||||
-rw-r--r-- | compiler/semdestruct.nim | 5 | ||||
-rw-r--r-- | compiler/semexprs.nim | 8 | ||||
-rw-r--r-- | compiler/semmagic.nim | 2 | ||||
-rw-r--r-- | compiler/vm.nim | 12 | ||||
-rw-r--r-- | compiler/vmdef.nim | 1 | ||||
-rw-r--r-- | compiler/vmgen.nim | 1 |
13 files changed, 60 insertions, 12 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 3a4158204..a0a5d204a 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -602,7 +602,7 @@ type mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal, mNLineInfo, mNNewNimNode, mNCopyNimNode, mNCopyNimTree, mStrToIdent, mIdentToStr, mNBindSym, mLocals, mNCallSite, - mEqIdent, mEqNimrodNode, mSameNodeType, + mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl, mNHint, mNWarning, mNError, mInstantiationInfo, mGetTypeInfo, mNGenSym diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 89a1b84a2..4a0e22db7 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -136,7 +136,7 @@ proc mapType(typ: PType): TJSTypeKind = result = etyBaseIndex of tyPointer: # treat a tyPointer like a typed pointer to an array of bytes - result = etyInt + result = etyBaseIndex of tyRange, tyDistinct, tyOrdinal, tyConst, tyMutable, tyIter, tyProxy: result = mapType(t.sons[0]) of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyChar: result = etyInt @@ -1398,6 +1398,9 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mDotDot: genProcForSymIfNeeded(p, n.sons[0].sym) genCall(p, n, r) + of mParseBiggestFloat: + useMagic(p, "nimParseBiggestFloat") + genCall(p, n, r) else: genCall(p, n, r) #else internalError(e.info, 'genMagic: ' + magicToStr[op]); diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index 647ea59d6..20800b809 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -63,6 +63,32 @@ proc lowerTupleUnpacking*(n: PNode; owner: PSym): PNode = if n.sons[i].kind == nkSym: v.addVar(n.sons[i]) result.add newAsgnStmt(n.sons[i], newTupleAccess(tempAsNode, i)) +proc newTupleAccessRaw*(tup: PNode, i: int): PNode = + result = newNodeI(nkBracketExpr, tup.info) + addSon(result, copyTree(tup)) + var lit = newNodeI(nkIntLit, tup.info) + lit.intVal = i + addSon(result, lit) + +proc lowerTupleUnpackingForAsgn*(n: PNode; owner: PSym): PNode = + let value = n.lastSon + result = newNodeI(nkStmtList, n.info) + + var temp = newSym(skTemp, getIdent(genPrefix), owner, value.info) + var v = newNodeI(nkLetSection, value.info) + let tempAsNode = newIdentNode(getIdent(genPrefix & $temp.id), value.info) + + var vpart = newNodeI(nkIdentDefs, tempAsNode.info, 3) + vpart.sons[0] = tempAsNode + vpart.sons[1] = ast.emptyNode + vpart.sons[2] = value + addSon(v, vpart) + result.add(v) + + let lhs = n.sons[0] + for i in 0 .. lhs.len-1: + result.add newAsgnStmt(lhs.sons[i], newTupleAccessRaw(tempAsNode, i)) + proc lowerSwap*(n: PNode; owner: PSym): PNode = result = newNodeI(nkStmtList, n.info) # note: cannot use 'skTemp' here cause we really need the copy for the VM :-( diff --git a/compiler/main.nim b/compiler/main.nim index 014605cc9..7c043eb72 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -190,7 +190,6 @@ proc resetMemory = resetRopeCache() resetSysTypes() gOwners = @[] - rangeDestructorProc = nil for i in low(buckets)..high(buckets): buckets[i] = nil idAnon = nil @@ -237,7 +236,7 @@ proc mainCommand* = when SimulateCaasMemReset: gGlobalOptions.incl(optCaasEnabled) - # In "nimrod serve" scenario, each command must reset the registered passes + # In "nim serve" scenario, each command must reset the registered passes clearPasses() gLastCmdTime = epochTime() appendStr(searchPaths, options.libpath) @@ -356,7 +355,7 @@ proc mainCommand* = gGlobalOptions.incl(optCaasEnabled) msgs.gErrorMax = high(int) # do not stop after first error serve(mainCommand) - of "nop": discard + of "nop", "help": discard else: rawMessage(errInvalidCommandX, command) diff --git a/compiler/modules.nim b/compiler/modules.nim index ad68e6315..85c99c4ec 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -92,7 +92,6 @@ proc resetAllModulesHard* = magicsys.resetSysTypes() # XXX #gOwners = @[] - #rangeDestructorProc = nil proc checkDepMem(fileIdx: int32): TNeedRecompile = template markDirty = diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 64631a437..4f9962ea8 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -17,5 +17,4 @@ define:useStdoutAsStdmsg cs:partial #define:useNodeIds -symbol:nimfix #gc:markAndSweep diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 1e4fc25af..148a382c2 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -25,7 +25,8 @@ proc listDirs(a: VmArgs, filter: set[PathComponent]) = if kind in filter: result.add path setResult(a, result) -proc setupVM(module: PSym; scriptName: string): PEvalContext = +proc setupVM*(module: PSym; scriptName: string): PEvalContext = + # For Nimble we need to export 'setupVM'. result = newCtx(module) result.mode = emRepl registerAdditionalOps(result) diff --git a/compiler/semdestruct.nim b/compiler/semdestruct.nim index af671f6e0..1261dd460 100644 --- a/compiler/semdestruct.nim +++ b/compiler/semdestruct.nim @@ -24,7 +24,6 @@ var destructorName = getIdent"destroy_" destructorParam = getIdent"this_" destructorPragma = newIdentNode(getIdent"destructor", unknownLineInfo()) - rangeDestructorProc*: PSym proc instantiateDestructor(c: PContext, typ: PType): PType @@ -141,9 +140,7 @@ proc instantiateDestructor(c: PContext, typ: PType): PType = case t.kind of tySequence, tyArray, tyArrayConstr, tyOpenArray, tyVarargs: if instantiateDestructor(c, t.sons[0]) != nil: - if rangeDestructorProc == nil: - rangeDestructorProc = searchInScopes(c, getIdent"nimDestroyRange") - t.destructor = rangeDestructorProc + t.destructor = getCompilerProc"nimDestroyRange" return t else: return nil diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index bb3ec9df0..d6f6e3a2c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1282,6 +1282,14 @@ proc semAsgn(c: PContext, n: PNode): PNode = result = buildOverloadedSubscripts(n.sons[0], getIdent"{}=") add(result, n[1]) return semExprNoType(c, result) + of nkPar: + if a.len >= 2: + # unfortunately we need to rewrite ``(x, y) = foo()`` already here so + # that overloading of the assignment operator still works. Usually we + # prefer to do these rewritings in transf.nim: + return semStmt(c, lowerTupleUnpackingForAsgn(n, c.p.owner)) + else: + a = semExprWithType(c, a, {efLValue}) else: a = semExprWithType(c, a, {efLValue}) n.sons[0] = a diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 0afbf1f07..5d16470b0 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -13,6 +13,8 @@ proc semAddr(c: PContext; n: PNode; isUnsafeAddr=false): PNode = result = newNodeI(nkAddr, n.info) let x = semExprWithType(c, n) + if x.kind == nkSym: + x.sym.flags.incl(sfAddrTaken) if isAssignable(c, x, isUnsafeAddr) notin {arLValue, arLocalLValue}: localError(n.info, errExprHasNoAddress) result.add x diff --git a/compiler/vm.nim b/compiler/vm.nim index 57ed8397c..b7b09f4a3 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -781,6 +781,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = regs[ra].node.add(copyTree(regs[rb].regToNode)) else: stackTrace(c, tos, pc, errNilAccess) + of opcGetImpl: + decodeB(rkNode) + let a = regs[rb].node + if a.kind == nkSym: + regs[ra].node = if a.sym.ast.isNil: newNode(nkNilLit) + else: copyTree(a.sym.ast) + else: + stackTrace(c, tos, pc, errFieldXNotFound, "symbol") of opcEcho: let rb = instr.regB if rb == 1: @@ -1401,6 +1409,10 @@ proc evalExpr*(c: PCtx, n: PNode): PNode = assert c.code[start].opcode != opcEof result = execute(c, start) +proc getGlobalValue*(c: PCtx; s: PSym): PNode = + internalAssert s.kind in {skLet, skVar} and sfGlobal in s.flags + result = c.globals.sons[s.position-1] + include vmops # for now we share the 'globals' environment. XXX Coming soon: An API for diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 6900b17c2..337e4ec8f 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -102,6 +102,7 @@ type opcEqIdent, opcStrToIdent, opcIdentToStr, + opcGetImpl, opcEcho, opcIndCall, # dest = call regStart, n; where regStart = fn, arg1, ... diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 919c38e08..237a44e18 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -948,6 +948,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mSlurp: genUnaryABC(c, n, dest, opcSlurp) of mStaticExec: genBinaryABCD(c, n, dest, opcGorge) of mNLen: genUnaryABI(c, n, dest, opcLenSeq) + of mGetImpl: genUnaryABC(c, n, dest, opcGetImpl) of mNChild: genBinaryABC(c, n, dest, opcNChild) of mNSetChild, mNDel: unused(n, dest) |