diff --git a/compiler/cbuilderbase.nim b/compiler/cbuilderbase.nim index 163b08b1bac5..c09394670c27 100644 --- a/compiler/cbuilderbase.nim +++ b/compiler/cbuilderbase.nim @@ -120,6 +120,43 @@ proc cIntLiteral*(i: BiggestInt): Snippet = proc cIntLiteral*(i: Int128): Snippet = result = cIntLiteral(toInt64(i)) +const + NimInt* = "NI" + NimInt8* = "NI8" + NimInt16* = "NI16" + NimInt32* = "NI32" + NimInt64* = "NI64" + CInt* = "int" + NimUint* = "NU" + NimUint8* = "NU8" + NimUint16* = "NU16" + NimUint32* = "NU32" + NimUint64* = "NU64" + NimFloat* = "NF" + NimFloat32* = "NF32" + NimFloat64* = "NF64" + NimFloat128* = "NF128" # not actually defined + NimNan* = "NAN" + NimInf* = "INF" + NimBool* = "NIM_BOOL" + NimTrue* = "NIM_TRUE" + NimFalse* = "NIM_FALSE" + NimChar* = "NIM_CHAR" + CChar* = "char" + NimCstring* = "NCSTRING" + NimNil* = "NIM_NIL" + CNil* = "NULL" + NimStrlitFlag* = "NIM_STRLIT_FLAG" + CVoid* = "void" + CPointer* = "void*" + CConstPointer* = "NIM_CONST void*" + +proc cIntType*(bits: int): Snippet = + "NI" & $bits + +proc cUintType*(bits: int): Snippet = + "NU" & $bits + type IfBuilderState* = enum WaitingIf, WaitingElseIf, InBlock diff --git a/compiler/cbuilderdecls.nim b/compiler/cbuilderdecls.nim index f458c160c046..5919ae8a910a 100644 --- a/compiler/cbuilderdecls.nim +++ b/compiler/cbuilderdecls.nim @@ -271,7 +271,7 @@ proc startSimpleStruct(obj: var Builder; m: BModule; name: string; baseType: Sni proc finishSimpleStruct(obj: var Builder; m: BModule; info: StructBuilderInfo) = if info.baseKind == bcNone and info.preFieldsLen == obj.buf.len: # no fields were added, add dummy field - obj.addField(name = "dummy", typ = "char") + obj.addField(name = "dummy", typ = CChar) if info.named: obj.add("};\n") else: @@ -330,7 +330,7 @@ proc startStruct(obj: var Builder; m: BModule; t: PType; name: string; baseType: t.n != nil and t.n.len == 1 and t.n[0].kind == nkSym and t.n[0].sym.typ.skipTypes(abstractInst).kind == tyUncheckedArray: # only consists of flexible array field, add *initial* dummy field - obj.addField(name = "dummy", typ = "char") + obj.addField(name = "dummy", typ = CChar) of bcCppInherit: discard of bcNoneRtti: obj.addField(name = "m_type", typ = ptrType(cgsymValue(m, "TNimType"))) @@ -343,7 +343,7 @@ proc finishStruct(obj: var Builder; m: BModule; t: PType; info: StructBuilderInf if info.baseKind == bcNone and info.preFieldsLen == obj.buf.len and t.itemId notin m.g.graph.memberProcsPerType: # no fields were added, add dummy field - obj.addField(name = "dummy", typ = "char") + obj.addField(name = "dummy", typ = CChar) if info.named: obj.add("};\n") else: diff --git a/compiler/cbuilderexprs.nim b/compiler/cbuilderexprs.nim index da0fba132e89..dce8c65214d9 100644 --- a/compiler/cbuilderexprs.nim +++ b/compiler/cbuilderexprs.nim @@ -1,6 +1,3 @@ -# XXX make complex ones like bitOr use builder instead -# XXX add stuff like NI, NIM_NIL as constants - proc constType(t: Snippet): Snippet = # needs manipulation of `t` in nifc "NIM_CONST " & t @@ -87,9 +84,6 @@ proc dotField(a, b: Snippet): Snippet = proc derefField(a, b: Snippet): Snippet = a & "->" & b -proc bitOr(a, b: Snippet): Snippet = - "(" & a & " | " & b & ")" - type CallBuilder = object needsComma: bool diff --git a/compiler/cbuilderstmts.nim b/compiler/cbuilderstmts.nim index deff4776dcc0..57872be06846 100644 --- a/compiler/cbuilderstmts.nim +++ b/compiler/cbuilderstmts.nim @@ -322,3 +322,8 @@ template addCPragma(builder: var Builder, val: Snippet) = builder.add("#pragma ") builder.add(val) builder.addNewline() + +proc addDiscard(builder: var Builder, val: Snippet) = + builder.add("(void)") + builder.add(val) + builder.addLineEnd(";") diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 36291369ebfd..b18ea017ed37 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -213,20 +213,20 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType; prepareF let ra = rdLoc(a) let rb = rdLoc(b) let rc = rdLoc(c) - let lengthExpr = cOp(Add, "NI", cOp(Sub, "NI", rc, rb), cIntValue(1)) + let lengthExpr = cOp(Add, NimInt, cOp(Sub, NimInt, rc, rb), cIntValue(1)) case ty.kind of tyArray: let first = toInt64(firstOrd(p.config, ty)) if first == 0: - result = (cCast(ptrType(dest), cOp(Add, "NI", ra, rb)), lengthExpr) + result = (cCast(ptrType(dest), cOp(Add, NimInt, ra, rb)), lengthExpr) else: let lit = cIntLiteral(first) - result = (cCast(ptrType(dest), cOp(Add, "NI", ra, cOp(Sub, "NI", rb, lit))), lengthExpr) + result = (cCast(ptrType(dest), cOp(Add, NimInt, ra, cOp(Sub, NimInt, rb, lit))), lengthExpr) of tyOpenArray, tyVarargs: let data = if reifiedOpenArray(q[1]): dotField(ra, "Field0") else: ra - result = (cCast(ptrType(dest), cOp(Add, "NI", data, rb)), lengthExpr) + result = (cCast(ptrType(dest), cOp(Add, NimInt, data, rb)), lengthExpr) of tyUncheckedArray, tyCstring: - result = (cCast(ptrType(dest), cOp(Add, "NI", ra, rb)), lengthExpr) + result = (cCast(ptrType(dest), cOp(Add, NimInt, ra, rb)), lengthExpr) of tyString, tySequence: let atyp = skipTypes(a.t, abstractInst) if formalType.skipTypes(abstractInst).kind in {tyVar} and atyp.kind == tyString and @@ -241,8 +241,8 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType; prepareF val = ra result = ( cIfExpr(dataFieldAccessor(p, val), - cCast(ptrType(dest), cOp(Add, "NI", dataField(p, val), rb)), - "NIM_NIL"), + cCast(ptrType(dest), cOp(Add, NimInt, dataField(p, val), rb)), + NimNil), lengthExpr) else: result = ("", "") @@ -295,13 +295,13 @@ proc openArrayLoc(p: BProc, formalType: PType, n: PNode; result: var Builder) = let ra = a.rdLoc var t = TLoc(snippet: cDeref(ra)) let lt = lenExpr(p, t) - result.add(cIfExpr(dataFieldAccessor(p, t.snippet), dataField(p, t.snippet), "NIM_NIL")) + result.add(cIfExpr(dataFieldAccessor(p, t.snippet), dataField(p, t.snippet), NimNil)) result.addArgumentSeparator() result.add(lt) else: let ra = a.rdLoc let la = lenExpr(p, a) - result.add(cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), "NIM_NIL")) + result.add(cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), NimNil)) result.addArgumentSeparator() result.add(la) of tyArray: @@ -315,7 +315,7 @@ proc openArrayLoc(p: BProc, formalType: PType, n: PNode; result: var Builder) = let ra = a.rdLoc var t = TLoc(snippet: cDeref(ra)) let lt = lenExpr(p, t) - result.add(cIfExpr(dataFieldAccessor(p, t.snippet), dataField(p, t.snippet), "NIM_NIL")) + result.add(cIfExpr(dataFieldAccessor(p, t.snippet), dataField(p, t.snippet), NimNil)) result.addArgumentSeparator() result.add(lt) of tyArray: @@ -767,7 +767,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType; result: var Bu var idx, stars: int = 0 if scanCppGenericSlot(pat, i, idx, stars): var t = resolveStarsInCppType(typ, idx, stars) - if t == nil: result.add("void") + if t == nil: result.add(CVoid) else: result.add(getTypeDesc(p.module, t)) else: let start = i diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index ae9ff60826ab..5600f6842dd5 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -36,8 +36,8 @@ proc genLiteral(p: BProc, n: PNode, ty: PType; result: var Builder) = of tyChar, tyNil: result.addIntLiteral(n.intVal) of tyBool: - if n.intVal != 0: result.add "NIM_TRUE" - else: result.add "NIM_FALSE" + if n.intVal != 0: result.add NimTrue + else: result.add NimFalse of tyInt64: result.addInt64Literal(n.intVal) of tyUInt64: result.addUint64Literal(uint64(n.intVal)) else: @@ -56,14 +56,14 @@ proc genLiteral(p: BProc, n: PNode, ty: PType; result: var Builder) = var closureInit: StructInitializer p.module.s[cfsStrData].addStructInitializer(closureInit, kind = siOrderedStruct): p.module.s[cfsStrData].addField(closureInit, name = "ClP_0"): - p.module.s[cfsStrData].add("NIM_NIL") + p.module.s[cfsStrData].add(NimNil) p.module.s[cfsStrData].addField(closureInit, name = "ClE_0"): - p.module.s[cfsStrData].add("NIM_NIL") + p.module.s[cfsStrData].add(NimNil) result.add tmpName elif k in {tyPointer, tyNil, tyProc}: - result.add rope("NIM_NIL") + result.add NimNil else: - result.add cCast(getTypeDesc(p.module, ty), "NIM_NIL") + result.add cCast(getTypeDesc(p.module, ty), NimNil) of nkStrLit..nkTripleStrLit: let k = if ty == nil: tyString else: skipTypes(ty, abstractVarRange + {tyStatic, tyUserTypeClass, tyUserTypeClassInst}).kind @@ -181,7 +181,7 @@ proc genRefAssign(p: BProc, dest, src: TLoc) = else: cgsymValue(p.module, "unsureAsgnRef") let rad = addrLoc(p.config, dest) let rs = rdLoc(src) - p.s(cpsStmts).addCallStmt(fnName, cCast("void**", rad), rs) + p.s(cpsStmts).addCallStmt(fnName, cCast(ptrType(CPointer), rad), rs) proc asgnComplexity(n: PNode): int = if n != nil: @@ -256,22 +256,22 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let ras = addrLoc(p.config, src) let rd = rdLoc(dest) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"), - cCast("void*", rad), - cCast(ptrConstType("void"), ras), + cCast(CPointer, rad), + cCast(CConstPointer, ras), cSizeof(rd)) else: let rad = addrLoc(p.config, dest) let ras = addrLoc(p.config, src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericShallowAssign"), - cCast("void*", rad), - cCast("void*", ras), + cCast(CPointer, rad), + cCast(CPointer, ras), genTypeInfoV1(p.module, dest.t, dest.lode.info)) else: let rad = addrLoc(p.config, dest) let ras = addrLoc(p.config, src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericAssign"), - cCast("void*", rad), - cCast("void*", ras), + cCast(CPointer, rad), + cCast(CPointer, ras), genTypeInfoV1(p.module, dest.t, dest.lode.info)) proc genOpenArrayConv(p: BProc; d: TLoc; a: TLoc; flags: TAssignmentFlags) = @@ -304,7 +304,7 @@ proc genOpenArrayConv(p: BProc; d: TLoc; a: TLoc; flags: TAssignmentFlags) = let ra = a.rdLoc let la = lenExpr(p, a) p.s(cpsStmts).addFieldAssignment(rd, "Field0", - cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), "NIM_NIL")) + cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), NimNil)) p.s(cpsStmts).addFieldAssignment(rd, "Field1", la) of tyArray: let rd = d.rdLoc @@ -322,7 +322,7 @@ proc genOpenArrayConv(p: BProc; d: TLoc; a: TLoc; flags: TAssignmentFlags) = let rd = d.rdLoc let ra = a.rdLoc p.s(cpsStmts).addFieldAssignment(rd, "Field0", - cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), "NIM_NIL")) + cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), NimNil)) let la = lenExpr(p, a) p.s(cpsStmts).addFieldAssignment(rd, "Field1", la) else: @@ -380,7 +380,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let rad = addrLoc(p.config, dest) let rs = rdLoc(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "unsureAsgnRef"), - cCast("void**", rad), + cCast(ptrType(CPointer), rad), cgCall(p, "copyString", rs)) of tyProc: if containsGarbageCollectedRef(dest.t): @@ -422,8 +422,8 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let rd = rdLoc(dest) let rs = rdLoc(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"), - cCast("void*", rd), - cCast(ptrConstType("void"), rs), + cCast(CPointer, rd), + cCast(CConstPointer, rs), cSizeof(getTypeDesc(p.module, dest.t))) of tyOpenArray, tyVarargs: # open arrays are always on the stack - really? What if a sequence is @@ -435,8 +435,8 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let ras = addrLoc(p.config, src) # XXX: is this correct for arrays? p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericAssignOpenArray"), - cCast("void*", rad), - cCast("void*", ras), + cCast(CPointer, rad), + cCast(CPointer, ras), rad & "Len_0", genTypeInfoV1(p.module, dest.t, dest.lode.info)) else: @@ -449,8 +449,8 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let rd = rdLoc(dest) let rs = rdLoc(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"), - cCast("void*", rd), - cCast(ptrConstType("void"), rs), + cCast(CPointer, rd), + cCast(CConstPointer, rs), cIntValue(getSize(p.config, dest.t))) else: simpleAsgn(p.s(cpsStmts), dest, src) @@ -464,7 +464,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = #echo p.currLineInfo, " requesting" let rad = addrLoc(p.config, dest) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "memTrackerWrite"), - cCast("void*", rad), + cCast(CPointer, rad), cIntValue(getSize(p.config, dest.t)), makeCString(toFullPath(p.config, p.currLineInfo)), cIntValue(p.currLineInfo.safeLineNm)) @@ -485,16 +485,16 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) = let rad = addrLoc(p.config, dest) let rats = addrLocOrTemp(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericDeepCopy"), - cCast("void*", rad), - cCast("void*", rats), + cCast(CPointer, rad), + cCast(CPointer, rats), genTypeInfoV1(p.module, dest.t, dest.lode.info)) of tySequence, tyString: if optTinyRtti in p.config.globalOptions: let rad = addrLoc(p.config, dest) let rats = addrLocOrTemp(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericDeepCopy"), - cCast("void*", rad), - cCast("void*", rats), + cCast(CPointer, rad), + cCast(CPointer, rats), genTypeInfoV1(p.module, dest.t, dest.lode.info)) else: let rad = addrLoc(p.config, dest) @@ -507,8 +507,8 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) = let source = addrLocOrTemp(src) let rad = addrLoc(p.config, dest) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "genericDeepCopyOpenArray"), - cCast("void*", rad), - cCast("void*", source), + cCast(CPointer, rad), + cCast(CPointer, source), derefField(source, "Field1"), genTypeInfoV1(p.module, dest.t, dest.lode.info)) of tySet: @@ -516,8 +516,8 @@ proc genDeepCopy(p: BProc; dest, src: TLoc) = let rd = rdLoc(dest) let rs = rdLoc(src) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimCopyMem"), - cCast("void*", rd), - cCast(ptrConstType("void"), rs), + cCast(CPointer, rd), + cCast(CConstPointer, rs), cIntValue(getSize(p.config, dest.t))) else: simpleAsgn(p.s(cpsStmts), dest, src) @@ -612,7 +612,7 @@ template unaryExprChar(p: BProc, e: PNode, d: var TLoc, frmt: untyped) = template binaryArithOverflowRaw(p: BProc, t: PType, a, b: TLoc; cpname: string): Rope = var size = getSize(p.config, t) - let storage = if size < p.config.target.intSize: rope("NI") + let storage = if size < p.config.target.intSize: NimInt else: getTypeDesc(p.module, t) var result = getTempName(p.module) p.s(cpsLocals).addVar(kind = Local, name = result, typ = storage) @@ -703,7 +703,7 @@ proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) = case m of mUnaryMinusI: - let typ = "NI" & rope(getSize(p.config, t) * 8) + let typ = cIntType(getSize(p.config, t) * 8) putIntoDest(p, d, e, cCast(typ, cOp(Neg, typ, ra))) of mUnaryMinusI64: putIntoDest(p, d, e, cOp(Neg, getTypeDesc(p.module, t), ra)) @@ -747,17 +747,17 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = res = cOp(Div, t, cCast(t, ra), cCast(t, rb)) of mShrI: let t = getType() - let at = "NU" & $k - let bt = "NU" & $s + let at = cUintType(k) + let bt = cUintType(s) res = cCast(t, cOp(Shr, at, cCast(at, ra), cCast(bt, rb))) of mShlI: let t = getType() - let at = "NU" & $s + let at = cUintType(s) res = cCast(t, cOp(Shl, at, cCast(at, ra), cCast(at, rb))) of mAshrI: let t = getType() - let at = "NI" & $s - let bt = "NU" & $s + let at = cIntType(s) + let bt = cUintType(s) res = cCast(t, cOp(Shr, at, cCast(at, ra), cCast(bt, rb))) of mBitandI: let t = getType() @@ -774,23 +774,23 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = res = cIfExpr(cOp(GreaterEqual, ra, rb), ra, rb) of mAddU: let t = getType() - let ot = "NU" & $s + let ot = cUintType(s) res = cCast(t, cOp(Add, ot, cCast(ot, ra), cCast(ot, rb))) of mSubU: let t = getType() - let ot = "NU" & $s + let ot = cUintType(s) res = cCast(t, cOp(Sub, ot, cCast(ot, ra), cCast(ot, rb))) of mMulU: let t = getType() - let ot = "NU" & $s + let ot = cUintType(s) res = cCast(t, cOp(Mul, ot, cCast(ot, ra), cCast(ot, rb))) of mDivU: let t = getType() - let ot = "NU" & $s + let ot = cUintType(s) res = cCast(t, cOp(Div, ot, cCast(ot, ra), cCast(ot, rb))) of mModU: let t = getType() - let ot = "NU" & $s + let ot = cUintType(s) res = cCast(t, cOp(Mod, ot, cCast(ot, ra), cCast(ot, rb))) of mEqI: res = cOp(Equal, ra, rb) @@ -805,10 +805,10 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mLtF64: res = cOp(LessThan, ra, rb) of mLeU: - let ot = "NU" & $s + let ot = cUintType(s) res = cOp(LessEqual, cCast(ot, ra), cCast(ot, rb)) of mLtU: - let ot = "NU" & $s + let ot = cUintType(s) res = cOp(LessThan, cCast(ot, ra), cCast(ot, rb)) of mEqEnum: res = cOp(Equal, ra, rb) @@ -817,11 +817,11 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mLtEnum: res = cOp(LessThan, ra, rb) of mEqCh: - res = cOp(Equal, cCast("NU8", ra), cCast("NU8", rb)) + res = cOp(Equal, cCast(NimUint8, ra), cCast(NimUint8, rb)) of mLeCh: - res = cOp(LessEqual, cCast("NU8", ra), cCast("NU8", rb)) + res = cOp(LessEqual, cCast(NimUint8, ra), cCast(NimUint8, rb)) of mLtCh: - res = cOp(LessThan, cCast("NU8", ra), cCast("NU8", rb)) + res = cOp(LessThan, cCast(NimUint8, ra), cCast(NimUint8, rb)) of mEqB: res = cOp(Equal, ra, rb) of mLeB: @@ -881,7 +881,7 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mUnaryPlusI: res = ra of mBitnotI: - let at = "NU" & $(getSize(p.config, t) * 8) + let at = cUintType(getSize(p.config, t) * 8) let t = getSimpleTypeDesc(p.module, e.typ) res = cCast(t, cCast(at, cOp(BitNot, t, ra))) of mUnaryPlusF64: @@ -1101,7 +1101,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = else: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "raiseFieldError2"), strLit, - cCast("NI", discIndex)) + cCast(NimInt, discIndex)) else: # complication needed for signed types @@ -1115,7 +1115,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) = p.s(cpsStmts).add(strLit) p.s(cpsStmts).addArgument(raiseCall): p.s(cpsStmts).addCall(cgsymValue(p.module, "reprDiscriminant"), - cOp(Add, "NI", cCast("NI", discIndex), cCast("NI", firstLit)), + cOp(Add, NimInt, cCast(NimInt, discIndex), cCast(NimInt, firstLit)), discName) raiseInstr(p, p.s(cpsStmts)) @@ -1160,7 +1160,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = let last = cIntLiteral(lastOrd(p.config, ty)) let rcb = rdCharLoc(b) p.s(cpsStmts).addSingleIfStmt( - cOp(GreaterThan, cCast("NU", rcb), cCast("NU", last))): + cOp(GreaterThan, cCast(NimUint, rcb), cCast(NimUint, last))): p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "raiseIndexError2"), rcb, last) @@ -1183,7 +1183,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = d.inheritLocation(a) let ra = rdLoc(a) let rcb = rdCharLoc(b) - putIntoDest(p, d, n, subscript(ra, cOp(Sub, "NI", rcb, first)), a.storage) + putIntoDest(p, d, n, subscript(ra, cOp(Sub, NimInt, rcb, first)), a.storage) proc genCStringElem(p: BProc, n, x, y: PNode, d: var TLoc) = var a = initLocExpr(p, x) @@ -1206,7 +1206,7 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc; arrTyp: PType) = else: rarr & "Len_0" p.s(cpsStmts).addSingleIfStmt(cOp(And, - cOp(NotEqual, cOp(Sub, "NI", rb, ra), cIntValue(-1)), + cOp(NotEqual, cOp(Sub, NimInt, rb, ra), cIntValue(-1)), cOp(Or, cOp(Or, cOp(LessThan, ra, cIntValue(0)), cOp(GreaterEqual, ra, arrlen)), cOp(Or, cOp(LessThan, rb, cIntValue(0)), cOp(GreaterEqual, rb, arrlen))))): @@ -1220,9 +1220,9 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc; arrTyp: PType) = let rca = rdCharLoc(a) let rcb = rdCharLoc(b) p.s(cpsStmts).addSingleIfStmt(cOp(And, - cOp(NotEqual, cOp(Sub, "NI", rcb, rca), cIntValue(-1)), + cOp(NotEqual, cOp(Sub, NimInt, rcb, rca), cIntValue(-1)), cOp(Or, - cOp(LessThan, cOp(Sub, "NI", rcb, rca), cIntValue(-1)), + cOp(LessThan, cOp(Sub, NimInt, rcb, rca), cIntValue(-1)), cOp(Or, cOp(Or, cOp(LessThan, rca, first), cOp(GreaterThan, rca, last)), cOp(Or, cOp(LessThan, rcb, first), cOp(GreaterThan, rcb, last)))))): @@ -1234,7 +1234,7 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc; arrTyp: PType) = let rb = rdLoc(b) let arrlen = lenExpr(p, arr) p.s(cpsStmts).addSingleIfStmt(cOp(And, - cOp(NotEqual, cOp(Sub, "NI", rb, ra), cIntValue(-1)), + cOp(NotEqual, cOp(Sub, NimInt, rb, ra), cIntValue(-1)), cOp(Or, cOp(Or, cOp(LessThan, ra, cIntValue(0)), cOp(GreaterEqual, ra, arrlen)), cOp(Or, cOp(LessThan, rb, cIntValue(0)), cOp(GreaterEqual, rb, arrlen))))): @@ -1264,7 +1264,7 @@ proc genOpenArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = cOp(GreaterEqual, rcb, arrLen))): # BUGFIX: ``>=`` and not ``>``! p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "raiseIndexError2"), rcb, - cOp(Sub, "NI", arrLen, cIntValue(1))) + cOp(Sub, NimInt, arrLen, cIntValue(1))) raiseInstr(p, p.s(cpsStmts)) inheritLocation(d, a) @@ -1285,7 +1285,7 @@ proc genSeqElem(p: BProc, n, x, y: PNode, d: var TLoc) = cOp(GreaterEqual, rcb, arrLen))): p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "raiseIndexError2"), rcb, - cOp(Sub, "NI", arrLen, cIntValue(1))) + cOp(Sub, NimInt, arrLen, cIntValue(1))) raiseInstr(p, p.s(cpsStmts)) if d.k == locNone: d.storage = OnHeap @@ -1418,7 +1418,7 @@ proc genEcho(p: BProc, n: PNode) = else: if n.len == 0: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "echoBinSafe"), - "NIM_NIL", + NimNil, cIntValue(n.len)) else: var a: TLoc = initLocExpr(p, n) @@ -1479,7 +1479,7 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) = appends.add(cgCall(p, "appendString", rstmp, ra)) var exprL = cIntValue(L) for len in lens: - exprL = cOp(Add, "NI", exprL, len) + exprL = cOp(Add, NimInt, exprL, len) p.s(cpsStmts).addAssignmentWithValue(tmp.snippet): p.s(cpsStmts).addCall(cgsymValue(p.module, "rawNewString"), exprL) for append in appends: @@ -1526,7 +1526,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) = appends.add(cgCall(p, "appendString", rsd, ra)) var exprL = cIntValue(L) for len in lens: - exprL = cOp(Add, "NI", exprL, len) + exprL = cOp(Add, NimInt, exprL, len) if optSeqDestructors in p.config.globalOptions: let brd = byRefLoc(p, dest) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "prepareAdd"), @@ -1605,7 +1605,7 @@ proc rawGenNew(p: BProc, a: var TLoc, sizeExpr: Rope; needsInit: bool) = var f: TLoc = initLocExpr(p, newSymNode(op)) let rf = rdLoc(f) p.module.s[cfsTypeInit3].addDerefFieldAssignment(ti, "finalizer", - cCast("void*", rf)) + cCast(CPointer, rf)) if a.storage == OnHeap and usesWriteBarrier(p.config): let unrefFnName = cgsymValue(p.module, @@ -1616,7 +1616,7 @@ proc rawGenNew(p: BProc, a: var TLoc, sizeExpr: Rope; needsInit: bool) = let ra = a.rdLoc p.s(cpsStmts).addSingleIfStmt(ra): p.s(cpsStmts).addCallStmt(unrefFnName, ra) - p.s(cpsStmts).addAssignment(ra, "NIM_NIL") + p.s(cpsStmts).addAssignment(ra, NimNil) if p.config.selectedGC == gcGo: # newObjRC1() would clash with unsureAsgnRef() - which is used by gcGo to # implement the write barrier @@ -1627,7 +1627,7 @@ proc rawGenNew(p: BProc, a: var TLoc, sizeExpr: Rope; needsInit: bool) = let raa = addrLoc(p.config, a) let rb = b.rdLoc p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "unsureAsgnRef"), - cCast("void**", raa), + cCast(ptrType(CPointer), raa), rb) else: # use newObjRC1 as an optimization @@ -1669,7 +1669,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope; lenIsZero: bool) = let rd = dest.rdLoc p.s(cpsStmts).addSingleIfStmt(rd): p.s(cpsStmts).addCallStmt(unrefFnName, rd) - p.s(cpsStmts).addAssignment(rd, "NIM_NIL") + p.s(cpsStmts).addAssignment(rd, NimNil) if not lenIsZero: let st = getTypeDesc(p.module, seqtype) let typinfo = genTypeInfoV1(p.module, seqtype, dest.lode.info) @@ -1680,7 +1680,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope; lenIsZero: bool) = let rad = addrLoc(p.config, dest) let rc = call.rdLoc p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "unsureAsgnRef"), - cCast("void**", rad), + cCast(ptrType(CPointer), rad), rc) else: call.snippet = cCast(st, @@ -1690,7 +1690,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope; lenIsZero: bool) = p.s(cpsStmts).addAssignment(rd, rc) else: if lenIsZero: - call.snippet = rope"NIM_NIL" + call.snippet = NimNil else: let st = getTypeDesc(p.module, seqtype) let typinfo = genTypeInfoV1(p.module, seqtype, dest.lode.info) @@ -1954,7 +1954,7 @@ proc genNewFinalize(p: BProc, e: PNode) = var f = initLocExpr(p, e[2]) b = initLoc(locExpr, a.lode, OnHeap) ti = genTypeInfo(p.config, p.module, refType, e.info) - p.module.s[cfsTypeInit3].addDerefFieldAssignment(ti, "finalizer", cCast("void*", rdLoc(f))) + p.module.s[cfsTypeInit3].addDerefFieldAssignment(ti, "finalizer", cCast(CPointer, rdLoc(f))) b.snippet = cCast(getTypeDesc(p.module, refType), cgCall(p, "newObj", ti, @@ -2032,7 +2032,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) = case t.kind of tyInt..tyInt64, tyUInt..tyUInt64: let ra = rdLoc(a) - putIntoDest(p, d, e, cgCall("reprInt", cCast("NI64", ra)), a.storage) + putIntoDest(p, d, e, cgCall("reprInt", cCast(NimInt64, ra)), a.storage) of tyFloat..tyFloat128: let ra = rdLoc(a) putIntoDest(p, d, e, cgCall("reprFloat", ra), a.storage) @@ -2045,7 +2045,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) = of tyEnum, tyOrdinal: let ra = rdLoc(a) let rti = genTypeInfoV1(p.module, t, e.info) - putIntoDest(p, d, e, cgCall("reprEnum", cCast("NI", ra), rti), a.storage) + putIntoDest(p, d, e, cgCall("reprEnum", cCast(NimInt, ra), rti), a.storage) of tyString: let ra = rdLoc(a) putIntoDest(p, d, e, cgCall("reprStr", ra), a.storage) @@ -2063,7 +2063,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) = let ra = rdLoc(a) let la = lenExpr(p, a) putIntoDest(p, b, e, - cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), "NIM_NIL") & + cIfExpr(dataFieldAccessor(p, ra), dataField(p, ra), NimNil) & cArgumentSeparator & la, a.storage) of tyArray: @@ -2156,12 +2156,12 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = if optBoundsCheck in p.options: genBoundsCheck(p, m, b, c, skipTypes(m.t, abstractVarRange)) if op == mHigh: - putIntoDest(p, d, e, cOp(Sub, "NI", rdLoc(c), rdLoc(b))) + putIntoDest(p, d, e, cOp(Sub, NimInt, rdLoc(c), rdLoc(b))) else: - putIntoDest(p, d, e, cOp(Add, "NI", cOp(Sub, "NI", rdLoc(c), rdLoc(b)), cIntValue(1))) + putIntoDest(p, d, e, cOp(Add, NimInt, cOp(Sub, NimInt, rdLoc(c), rdLoc(b)), cIntValue(1))) else: if not reifiedOpenArray(a): - if op == mHigh: unaryExpr(p, e, d, cOp(Sub, "NI", ra & "Len_0", cIntValue(1))) + if op == mHigh: unaryExpr(p, e, d, cOp(Sub, NimInt, ra & "Len_0", cIntValue(1))) else: unaryExpr(p, e, d, ra & "Len_0") else: let isDeref = a.kind in {nkHiddenDeref, nkDerefExpr} @@ -2171,25 +2171,25 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) = else: dotField(ra, "Field1") if op == mHigh: - unaryExpr(p, e, d, cOp(Sub, "NI", lenA, cIntValue(1))) + unaryExpr(p, e, d, cOp(Sub, NimInt, lenA, cIntValue(1))) else: unaryExpr(p, e, d, lenA) of tyCstring: if op == mHigh: - unaryExpr(p, e, d, cOp(Sub, "NI", cgCall(p, "nimCStrLen", ra), cIntValue(1))) + unaryExpr(p, e, d, cOp(Sub, NimInt, cgCall(p, "nimCStrLen", ra), cIntValue(1))) else: unaryExpr(p, e, d, cgCall(p, "nimCStrLen", ra)) of tyString: var a: TLoc = initLocExpr(p, e[1]) var x = lenExpr(p, a) - if op == mHigh: x = cOp(Sub, "NI", x, cIntValue(1)) + if op == mHigh: x = cOp(Sub, NimInt, x, cIntValue(1)) putIntoDest(p, d, e, x) of tySequence: # we go through a temporary here because people write bullshit code. var tmp: TLoc = getIntTemp(p) var a = initLocExpr(p, e[1]) var x = lenExpr(p, a) - if op == mHigh: x = cOp(Sub, "NI", x, cIntValue(1)) + if op == mHigh: x = cOp(Sub, NimInt, x, cIntValue(1)) p.s(cpsStmts).addAssignment(tmp.snippet, x) putIntoDest(p, d, e, tmp.snippet) of tyArray: @@ -2217,7 +2217,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) = let rti = genTypeInfoV1(p.module, t.skipTypes(abstractInst), e.info) var pExpr: Snippet if not p.module.compileToCpp: - pExpr = cIfExpr(ra, cAddr(derefField(ra, "Sup")), "NIM_NIL") + pExpr = cIfExpr(ra, cAddr(derefField(ra, "Sup")), NimNil) else: pExpr = ra call.snippet = cCast(rt, cgCall(p, "setLengthSeqV2", pExpr, rti, rb)) @@ -2259,7 +2259,7 @@ proc rdSetElemLoc(conf: ConfigRef; a: TLoc, typ: PType; result: var Snippet) = let setType = typ.skipTypes(abstractPtrs) assert(setType.kind == tySet) if firstOrd(conf, setType) != 0: - result = cOp(Sub, "NU", result, cIntValue(firstOrd(conf, setType))) + result = cOp(Sub, NimUint, result, cIntValue(firstOrd(conf, setType))) proc fewCmps(conf: ConfigRef; s: PNode): bool = # this function estimates whether it is better to emit code @@ -2283,7 +2283,7 @@ proc genInExprAux(p: BProc, e: PNode, a, b, d: var TLoc) = case s of 1, 2, 4, 8: let mask = s * 8 - 1 - let rt = "NU" & $(s * 8) + let rt = cUintType(s * 8) binaryExprIn(p, e, a, b, d, # ((a & ((NU8) 1 << ((NU) elem & 7U))) != 0) # ((a & ((NU16) 1 << ((NU) elem & 15U))) != 0) @@ -2292,18 +2292,18 @@ proc genInExprAux(p: BProc, e: PNode, a, b, d: var TLoc) = cOp(NotEqual, cOp(BitAnd, rt, ra, cOp(Shl, rt, cCast(rt, cIntValue(1)), - cOp(BitAnd, "NU", cCast("NU", elem), cUintValue(mask.uint)))), + cOp(BitAnd, NimUint, cCast(NimUint, elem), cUintValue(mask.uint)))), cIntValue(0))) else: # ((a[(NU)(elem)>>3] &(1U<<((NU)(elem)&7U)))!=0) binaryExprIn(p, e, a, b, d, cOp(NotEqual, - cOp(BitAnd, "NU8", - subscript(ra, cOp(Shr, "NU", cCast("NU", elem), cIntValue(3))), - cOp(Shl, "NU8", + cOp(BitAnd, NimUint8, + subscript(ra, cOp(Shr, NimUint, cCast(NimUint, elem), cIntValue(3))), + cOp(Shl, NimUint8, cUintValue(1), - cOp(BitAnd, "NU", - cCast("NU", elem), + cOp(BitAnd, NimUint, + cCast(NimUint, elem), cUintValue(7)))), cIntValue(0))) @@ -2372,20 +2372,20 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = case size of 1, 2, 4, 8: let bits = size * 8 - let rt = "NU" & $bits + let rt = cUintType(bits) case op of mIncl: let mask = bits - 1 binaryStmtInExcl(p, e, d, cInPlaceOp(BitOr, rt, ra, cOp(Shl, rt, cCast(rt, cIntValue(1)), - cOp(BitAnd, "NU", elem, cIntValue(mask))))) + cOp(BitAnd, NimUint, elem, cIntValue(mask))))) of mExcl: let mask = bits - 1 binaryStmtInExcl(p, e, d, cInPlaceOp(BitAnd, rt, ra, cOp(BitNot, rt, cOp(Shl, rt, cCast(rt, cIntValue(1)), - cOp(BitAnd, "NU", elem, cIntValue(mask)))))) + cOp(BitAnd, NimUint, elem, cIntValue(mask)))))) of mCard: let name = if size <= 4: "countBits32" else: "countBits64" unaryExprChar(p, e, d, cgCall(p, name, ra)) @@ -2407,14 +2407,14 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = else: case op of mIncl: - binaryStmtInExcl(p, e, d, cInPlaceOp(BitOr, "NU8", - subscript(ra, cOp(Shr, "NU", cCast("NU", elem), cIntValue(3))), - cOp(Shl, "NU8", cUintValue(1), cOp(BitAnd, "NU", elem, cUintValue(7))))) + binaryStmtInExcl(p, e, d, cInPlaceOp(BitOr, NimUint8, + subscript(ra, cOp(Shr, NimUint, cCast(NimUint, elem), cIntValue(3))), + cOp(Shl, NimUint8, cUintValue(1), cOp(BitAnd, NimUint, elem, cUintValue(7))))) of mExcl: - binaryStmtInExcl(p, e, d, cInPlaceOp(BitAnd, "NU8", - subscript(ra, cOp(Shr, "NU", cCast("NU", elem), cIntValue(3))), - cOp(BitNot, "NU8", - cOp(Shl, "NU8", cUintValue(1), cOp(BitAnd, "NU", elem, cUintValue(7)))))) + binaryStmtInExcl(p, e, d, cInPlaceOp(BitAnd, NimUint8, + subscript(ra, cOp(Shr, NimUint, cCast(NimUint, elem), cIntValue(3))), + cOp(BitNot, NimUint8, + cOp(Shl, NimUint8, cUintValue(1), cOp(BitAnd, NimUint, elem, cUintValue(7)))))) of mCard: var a: TLoc = initLocExpr(p, e[1]) let rca = rdCharLoc(a) @@ -2433,9 +2433,9 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = let rb = rdLoc(b) p.s(cpsStmts).addForRangeExclusive(ri, cIntValue(0), cIntValue(size)): p.s(cpsStmts).addAssignment(rd, cOp(Equal, - cOp(BitAnd, "NU8", + cOp(BitAnd, NimUint8, subscript(ra, ri), - cOp(BitNot, "NU8", subscript(rb, ri))), + cOp(BitNot, NimUint8, subscript(rb, ri))), cIntValue(0))) p.s(cpsStmts).addSingleIfStmt(cOp(Not, rd)): p.s(cpsStmts).addBreak() @@ -2471,10 +2471,10 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = let y = subscript(rb, ri) let lookup = case op - of mMulSet: cOp(BitAnd, "NU8", x, y) - of mPlusSet: cOp(BitOr, "NU8", x, y) - of mMinusSet: cOp(BitAnd, "NU8", x, cOp(BitNot, "NU8", y)) - of mXorSet: cOp(BitXor, "NU8", x, y) + of mMulSet: cOp(BitAnd, NimUint8, x, y) + of mPlusSet: cOp(BitOr, NimUint8, x, y) + of mMinusSet: cOp(BitAnd, NimUint8, x, cOp(BitNot, NimUint8, y)) + of mXorSet: cOp(BitXor, NimUint8, x, y) else: "" # unreachable p.s(cpsStmts).add(lookup) of mInSet: genInOp(p, e, d) @@ -2606,7 +2606,7 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc) = let rca = rdCharLoc(a) let boundRca = if n0t.skipTypes(abstractVarRange).kind in {tyUInt, tyUInt32, tyUInt64}: - cCast("NI64", rca) + cCast(NimInt64, rca) else: rca let firstVal = extract(first) @@ -2645,7 +2645,7 @@ proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) = if p.module.compileToCpp: # fixes for const qualifier; bug #12703; bug #19588 putIntoDest(p, d, n, - cgCall(p, "cstrToNimstr", cCast("NCSTRING", rdLoc(a))), + cgCall(p, "cstrToNimstr", cCast(NimCstring, rdLoc(a))), a.storage) else: putIntoDest(p, d, n, @@ -2767,9 +2767,9 @@ proc genDestroy(p: BProc; n: PNode) = let rp = dotField(ra, "p") p.s(cpsStmts).addSingleIfStmt( cOp(And, rp, - cOp(Not, cOp(BitAnd, "NI", + cOp(Not, cOp(BitAnd, NimInt, derefField(rp, "cap"), - "NIM_STRLIT_FLAG")))): + NimStrlitFlag)))): let fn = if optThreads in p.config.globalOptions: "deallocShared" else: "dealloc" p.s(cpsStmts).addCallStmt(cgsymValue(p.module, fn), rp) of tySequence: @@ -2779,9 +2779,9 @@ proc genDestroy(p: BProc; n: PNode) = let rt = getTypeDesc(p.module, t.elementType) p.s(cpsStmts).addSingleIfStmt( cOp(And, rp, - cOp(Not, cOp(BitAnd, "NI", + cOp(Not, cOp(BitAnd, NimInt, derefField(rp, "cap"), - "NIM_STRLIT_FLAG")))): + NimStrlitFlag)))): p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "alignedDealloc"), rp, cAlignof(rt)) @@ -2897,7 +2897,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mCStrToStr: if p.module.compileToCpp: # fixes for const qualifier; bug #12703; bug #19588 - genDollarIt(p, e, d, cgCall(p, "cstrToNimstr", cCast("NCSTRING", it))) + genDollarIt(p, e, d, cgCall(p, "cstrToNimstr", cCast(NimCstring, it))) else: genDollarIt(p, e, d, cgCall(p, "cstrToNimstr", it)) of mStrToStr, mUnown: expr(p, e[1], d) @@ -2925,10 +2925,10 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mNewSeqOfCap: genNewSeqOfCap(p, e, d) of mSizeOf: let t = e[1].typ.skipTypes({tyTypeDesc}) - putIntoDest(p, d, e, cCast("NI", cSizeof(getTypeDesc(p.module, t, dkVar)))) + putIntoDest(p, d, e, cCast(NimInt, cSizeof(getTypeDesc(p.module, t, dkVar)))) of mAlignOf: let t = e[1].typ.skipTypes({tyTypeDesc}) - putIntoDest(p, d, e, cCast("NI", cAlignof(getTypeDesc(p.module, t, dkVar)))) + putIntoDest(p, d, e, cCast(NimInt, cAlignof(getTypeDesc(p.module, t, dkVar)))) of mOffsetOf: var dotExpr: PNode if e[1].kind == nkDotExpr: @@ -2944,7 +2944,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = if t.kind == tyTuple: "Field" & rope(dotExpr[1].sym.position) else: dotExpr[1].sym.loc.snippet - putIntoDest(p,d,e, cCast("NI", cOffsetof(tname, member))) + putIntoDest(p,d,e, cCast(NimInt, cOffsetof(tname, member))) of mChr: genSomeCast(p, e, d) of mOrd: genOrd(p, e, d) of mLengthArray, mHigh, mLengthStr, mLengthSeq, mLengthOpenArray: @@ -3073,22 +3073,22 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = let ri = rdLoc(idx) let rd = rdLoc(d) p.s(cpsStmts).addForRangeInclusive(ri, aa, bb): - p.s(cpsStmts).addInPlaceOp(BitOr, "NU8", - subscript(rd, cOp(Shr, "NU", cCast("NU", ri), cIntValue(3))), - cOp(Shl, "NU8", cUintValue(1), - cOp(BitAnd, "NU", cCast("NU", ri), cUintValue(7)))) + p.s(cpsStmts).addInPlaceOp(BitOr, NimUint8, + subscript(rd, cOp(Shr, NimUint, cCast(NimUint, ri), cIntValue(3))), + cOp(Shl, NimUint8, cUintValue(1), + cOp(BitAnd, NimUint, cCast(NimUint, ri), cUintValue(7)))) else: a = initLocExpr(p, it) var aa: Snippet = "" rdSetElemLoc(p.config, a, e.typ, aa) let rd = rdLoc(d) - p.s(cpsStmts).addInPlaceOp(BitOr, "NU8", - subscript(rd, cOp(Shr, "NU", cCast("NU", aa), cIntValue(3))), - cOp(Shl, "NU8", cUintValue(1), - cOp(BitAnd, "NU", cCast("NU", aa), cUintValue(7)))) + p.s(cpsStmts).addInPlaceOp(BitOr, NimUint8, + subscript(rd, cOp(Shr, NimUint, cCast(NimUint, aa), cIntValue(3))), + cOp(Shl, NimUint8, cUintValue(1), + cOp(BitAnd, NimUint, cCast(NimUint, aa), cUintValue(7)))) else: # small set - var ts = "NU" & $(size * 8) + var ts = cUintType(size * 8) p.s(cpsStmts).addAssignment(rdLoc(d), cIntValue(0)) for it in e.sons: if it.kind == nkRange: @@ -3392,9 +3392,9 @@ proc genConstDefinition(q: BModule; p: BProc; sym: PSym) = q.initProc.procSec(cpsLocals).addArgument(registerCall): q.initProc.procSec(cpsLocals).addSizeof(rdLoc(sym.loc)) q.initProc.procSec(cpsLocals).addArgument(registerCall): - q.initProc.procSec(cpsLocals).add("NULL") + q.initProc.procSec(cpsLocals).add(CNil) q.initProc.procSec(cpsLocals).addArgument(registerCall): - q.initProc.procSec(cpsLocals).addCast("void**"): + q.initProc.procSec(cpsLocals).addCast(ptrType(CPointer)): q.initProc.procSec(cpsLocals).add(cAddr(sym.loc.snippet)) # always copy over the contents of the actual constant with the _const # suffix ==> this means that the constant is reloadable & updatable! @@ -3403,9 +3403,9 @@ proc genConstDefinition(q: BModule; p: BProc; sym: PSym) = var copyCall: CallBuilder q.initProc.procSec(cpsLocals).addCall(copyCall, cgsymValue(q, "nimCopyMem")): q.initProc.procSec(cpsLocals).addArgument(copyCall): - q.initProc.procSec(cpsLocals).add(cCast("void*", sym.loc.snippet)) + q.initProc.procSec(cpsLocals).add(cCast(CPointer, sym.loc.snippet)) q.initProc.procSec(cpsLocals).addArgument(copyCall): - q.initProc.procSec(cpsLocals).add(cCast(ptrConstType("void"), cAddr(actualConstName))) + q.initProc.procSec(cpsLocals).add(cCast(CConstPointer, cAddr(actualConstName))) q.initProc.procSec(cpsLocals).addArgument(copyCall): q.initProc.procSec(cpsLocals).addSizeof(rdLoc(sym.loc)) @@ -3465,7 +3465,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = # we never reach this case - as of the time of this comment, # skEnumField is folded to an int in semfold.nim, but this code # remains for robustness - putIntoDest(p, d, n, rope(sym.position)) + putIntoDest(p, d, n, cIntValue(sym.position)) of skVar, skForVar, skResult, skLet: if {sfGlobal, sfThread} * sym.flags != {}: genVarPrototype(p.module, n) @@ -3609,8 +3609,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = if ex.kind != nkEmpty: genLineDir(p, n) var a: TLoc = initLocExprSingleUse(p, ex) - p.s(cpsStmts).addStmt(): - p.s(cpsStmts).add(cCast("void", a.snippet)) + p.s(cpsStmts).addDiscard(a.snippet) of nkAsmStmt: genAsmStmt(p, n) of nkTryStmt, nkHiddenTryStmt: case p.config.exc @@ -3674,12 +3673,12 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo; result: var Builder) = var t = skipTypes(typ, abstractRange+{tyOwned}-{tyTypeDesc}) case t.kind - of tyBool: result.add rope"NIM_FALSE" + of tyBool: result.add NimFalse of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result.addIntValue(0) of tyFloat..tyFloat128: result.addFloatValue(0.0) of tyCstring, tyVar, tyLent, tyPointer, tyPtr, tyUntyped, tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil: - result.add rope"NIM_NIL" + result.add NimNil of tyString, tySequence: if optSeqDestructors in p.config.globalOptions: var seqInit: StructInitializer @@ -3687,19 +3686,19 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo; result: var Builder) result.addField(seqInit, name = "len"): result.addIntValue(0) result.addField(seqInit, name = "p"): - result.add("NIM_NIL") + result.add(NimNil) else: - result.add "NIM_NIL" + result.add NimNil of tyProc: if t.callConv != ccClosure: - result.add "NIM_NIL" + result.add NimNil else: var closureInit: StructInitializer result.addStructInitializer(closureInit, kind = siOrderedStruct): result.addField(closureInit, name = "ClP_0"): - result.add("NIM_NIL") + result.add(NimNil) result.addField(closureInit, name = "ClE_0"): - result.add("NIM_NIL") + result.add(NimNil) of tyObject: var objInit: StructInitializer result.addStructInitializer(objInit, kind = siOrderedStruct): @@ -3724,7 +3723,7 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo; result: var Builder) var openArrInit: StructInitializer result.addStructInitializer(openArrInit, kind = siOrderedStruct): result.addField(openArrInit, name = "Field0"): - result.add("NIM_NIL") + result.add(NimNil) result.addField(openArrInit, name = "Field1"): result.addIntValue(0) of tySet: @@ -3901,9 +3900,9 @@ proc genConstSeq(p: BProc, n: PNode, t: PType; isConst: bool; result: var Builde var supInit: StructInitializer def.addStructInitializer(supInit, kind = siOrderedStruct): def.addField(supInit, name = "len"): - def.add(n.len.rope) + def.addIntValue(n.len) def.addField(supInit, name = "reserved"): - def.add(bitOr(rope(n.len), "NIM_STRLIT_FLAG")) + def.add(cOp(BitOr, NimInt, cIntValue(n.len), NimStrlitFlag)) if n.len > 0: def.addField(structInit, name = "data"): var arrInit: StructInitializer @@ -3925,13 +3924,13 @@ proc genConstSeqV2(p: BProc, n: PNode, t: PType; isConst: bool; result: var Buil if isConst: AlwaysConst else: Global, name = payload): def.addSimpleStruct(p.module, name = "", baseType = ""): - def.addField(name = "cap", typ = "NI") + def.addField(name = "cap", typ = NimInt) def.addArrayField(name = "data", elementType = getTypeDesc(p.module, base), len = n.len) do: var structInit: StructInitializer def.addStructInitializer(structInit, kind = siOrderedStruct): def.addField(structInit, name = "cap"): - def.add(bitOr(rope(n.len), "NIM_STRLIT_FLAG")) + def.add(cOp(BitOr, NimInt, cIntValue(n.len), NimStrlitFlag)) if n.len > 0: def.addField(structInit, name = "data"): var arrInit: StructInitializer @@ -3987,12 +3986,12 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool; optionalType: PType; resul result.addStructInitializer(closureInit, kind = siOrderedStruct): result.addField(closureInit, name = "ClP_0"): if n[0].kind == nkNilLit: - result.add("NIM_NIL") + result.add(NimNil) else: var d: TLoc = initLocExpr(p, n[0]) result.add(cCast(typ = getClosureType(p.module, typ, clHalfWithEnv), value = rdLoc(d))) result.addField(closureInit, name = "ClE_0"): - result.add("NIM_NIL") + result.add(NimNil) else: var d: TLoc = initLocExpr(p, n) result.add rdLoc(d) diff --git a/compiler/ccgliterals.nim b/compiler/ccgliterals.nim index 7d72e27b3424..84f72017cf7e 100644 --- a/compiler/ccgliterals.nim +++ b/compiler/ccgliterals.nim @@ -40,7 +40,7 @@ proc genStringLiteralDataOnlyV1(m: BModule, s: string; result: var Rope) = res.addVarWithTypeAndInitializer(AlwaysConst, name = tmp): res.addSimpleStruct(m, name = "", baseType = ""): res.addField(name = "Sup", typ = "TGenericSeq") - res.addArrayField(name = "data", elementType = "NIM_CHAR", len = s.len + 1) + res.addArrayField(name = "data", elementType = NimChar, len = s.len + 1) do: var strInit: StructInitializer res.addStructInitializer(strInit, kind = siOrderedStruct): @@ -50,14 +50,14 @@ proc genStringLiteralDataOnlyV1(m: BModule, s: string; result: var Rope) = res.addField(seqInit, name = "len"): res.addIntValue(s.len) res.addField(seqInit, name = "reserved"): - res.add(cCast("NI", bitOr(cCast("NU", rope(s.len)), "NIM_STRLIT_FLAG"))) + res.add(cCast(NimInt, cOp(BitOr, NimUint, cCast(NimUint, cIntValue(s.len)), NimStrlitFlag))) res.addField(strInit, name = "data"): res.add(makeCString(s)) m.s[cfsStrData].add(extract(res)) proc genStringLiteralV1(m: BModule; n: PNode; result: var Builder) = if s.isNil: - result.add(cCast(ptrType(cgsymValue(m, "NimStringDesc")), "NIM_NIL")) + result.add(cCast(ptrType(cgsymValue(m, "NimStringDesc")), NimNil)) else: let id = nodeTableTestOrSet(m.dataCache, n, m.labels) var name: string = "" @@ -76,13 +76,13 @@ proc genStringLiteralDataOnlyV2(m: BModule, s: string; result: Rope; isConst: bo if isConst: AlwaysConst else: Global, name = result): res.addSimpleStruct(m, name = "", baseType = ""): - res.addField(name = "cap", typ = "NI") - res.addArrayField(name = "data", elementType = "NIM_CHAR", len = s.len + 1) + res.addField(name = "cap", typ = NimInt) + res.addArrayField(name = "data", elementType = NimChar, len = s.len + 1) do: var structInit: StructInitializer res.addStructInitializer(structInit, kind = siOrderedStruct): res.addField(structInit, name = "cap"): - res.add(bitOr(rope(s.len), "NIM_STRLIT_FLAG")) + res.add(cOp(BitOr, NimInt, cIntValue(s.len), NimStrlitFlag)) res.addField(structInit, name = "data"): res.add(makeCString(s)) m.s[cfsStrData].add(extract(res)) @@ -145,7 +145,7 @@ proc genStringLiteralDataOnly(m: BModule; s: string; info: TLineInfo; localError(m.config, info, "cannot determine how to produce code for string literal") proc genNilStringLiteral(m: BModule; info: TLineInfo; result: var Builder) = - result.add(cCast(ptrType(cgsymValue(m, "NimStringDesc")), "NIM_NIL")) + result.add(cCast(ptrType(cgsymValue(m, "NimStringDesc")), NimNil)) proc genStringLiteral(m: BModule; n: PNode; result: var Builder) = case detectStrVersion(m) diff --git a/compiler/ccgreset.nim b/compiler/ccgreset.nim index b6f5c1e10a39..7b0d61926133 100644 --- a/compiler/ccgreset.nim +++ b/compiler/ccgreset.nim @@ -75,21 +75,21 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) = of tyString, tyRef, tySequence: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "unsureAsgnRef"), - cCast("void**", cAddr(accessor)), - "NIM_NIL") + cCast(ptrType(CPointer), cAddr(accessor)), + NimNil) of tyProc: if typ.callConv == ccClosure: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "unsureAsgnRef"), - cCast("void**", cAddr(dotField(accessor, "ClE_0"))), - "NIM_NIL") - p.s(cpsStmts).addFieldAssignment(accessor, "ClP_0", "NIM_NIL") + cCast(ptrType(CPointer), cAddr(dotField(accessor, "ClE_0"))), + NimNil) + p.s(cpsStmts).addFieldAssignment(accessor, "ClP_0", NimNil) else: - p.s(cpsStmts).addAssignment(accessor, "NIM_NIL") + p.s(cpsStmts).addAssignment(accessor, NimNil) of tyChar, tyBool, tyEnum, tyRange, tyInt..tyUInt64: p.s(cpsStmts).addAssignment(accessor, cIntValue(0)) of tyCstring, tyPointer, tyPtr, tyVar, tyLent: - p.s(cpsStmts).addAssignment(accessor, "NIM_NIL") + p.s(cpsStmts).addAssignment(accessor, NimNil) of tySet: case mapSetType(p.config, typ) of ctArray: diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 5512ed01c8f1..ed840a97a8fa 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -71,11 +71,11 @@ template startBlockWith(p: BProc, body: typed): int = proc blockBody(b: var TBlock; result: var Builder) = result.add extract(b.sections[cpsLocals]) if b.frameLen > 0: - result.addInPlaceOp(Add, "NI", dotField("FR_", "len"), b.frameLen.rope) + result.addInPlaceOp(Add, NimInt, dotField("FR_", "len"), cIntValue(b.frameLen.int)) result.add(extract(b.sections[cpsInit])) result.add(extract(b.sections[cpsStmts])) if b.frameLen > 0: - result.addInPlaceOp(Sub, "NI", dotField("FR_", "len"), b.frameLen.rope) + result.addInPlaceOp(Sub, NimInt, dotField("FR_", "len"), cIntValue(b.frameLen.int)) proc endBlockInside(p: BProc) = let topBlock = p.blocks.len-1 @@ -144,7 +144,7 @@ proc genVarTuple(p: BProc, n: PNode) = field.snippet = dotField(rtup, fieldName) putLocIntoDest(p, v.loc, field) if forHcr or isGlobalInBlock: - hcrGlobals.add((loc: v.loc, tp: "NULL")) + hcrGlobals.add((loc: v.loc, tp: CNil)) if forHcr: # end the block where the tuple gets initialized @@ -158,18 +158,18 @@ proc genVarTuple(p: BProc, n: PNode) = # check if any of them is newly introduced and the initializing code has to be ran p.s(cpsLocals).addVar(kind = Local, name = hcrCond, - typ = "NIM_BOOL", - initializer = "NIM_FALSE") + typ = NimBool, + initializer = NimFalse) for curr in hcrGlobals: let rc = rdLoc(curr.loc) - p.s(cpsLocals).addInPlaceOp(BitOr, "NIM_BOOL", + p.s(cpsLocals).addInPlaceOp(BitOr, NimBool, hcrCond, cCall("hcrRegisterGlobal", getModuleDllPath(p.module, n[0].sym), '"' & curr.loc.snippet & '"', cSizeof(rc), curr.tp, - cCast("void**", cAddr(curr.loc.snippet)))) + cCast(ptrType(CPointer), cAddr(curr.loc.snippet)))) proc loadInto(p: BProc, le, ri: PNode, a: var TLoc) {.inline.} = @@ -294,7 +294,7 @@ proc genBreakState(p: BProc, n: PNode, d: var TLoc) = let ra = a.rdLoc d.snippet = cOp(LessThan, subscript( - cCast(ptrType("NI"), ra), + cCast(ptrType(NimInt), ra), cIntValue(1)), cIntValue(0)) else: @@ -303,7 +303,7 @@ proc genBreakState(p: BProc, n: PNode, d: var TLoc) = # the environment is guaranteed to contain the 'state' field at offset 1: d.snippet = cOp(LessThan, subscript( - cCast(ptrType("NI"), dotField(ra, "ClE_0")), + cCast(ptrType(NimInt), dotField(ra, "ClE_0")), cIntValue(1)), cIntValue(0)) @@ -426,7 +426,7 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = assignLocalVar(p, vn) initLocalVar(p, v, imm) - let traverseProc = "NULL" + let traverseProc = CNil # If the var is in a block (control flow like if/while or a block) in global scope just # register the so called "global" so it can be used later on. There is no need to close # and reopen of if (nim_hcr_do_init_) blocks because we are in one already anyway. @@ -440,7 +440,7 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = '"' & v.loc.snippet & '"', cSizeof(rv), traverseProc, - cCast("void**", cAddr(v.loc.snippet))) + cCast(ptrType(CPointer), cAddr(v.loc.snippet))) # nothing special left to do later on - let's avoid closing and reopening blocks forHcr = false @@ -456,7 +456,7 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = '"' & v.loc.snippet & '"', cSizeof(rdLoc(v.loc)), traverseProc, - cCast("void**", cAddr(v.loc.snippet)))) + cCast(ptrType(CPointer), cAddr(v.loc.snippet)))) if value.kind != nkEmpty and valueAsRope.len == 0: genLineDir(targetProc, vn) if not isCppCtorCall: @@ -623,7 +623,7 @@ proc genComputedGoto(p: BProc; n: PNode) = let tmp = "TMP$1_" % [id.rope] p.s(cpsStmts).addArrayVarWithInitializer(kind = Global, name = tmp, - elementType = "void*", + elementType = CPointer, len = arraySize): var labelsInit: StructInitializer p.s(cpsStmts).addStructInitializer(labelsInit, kind = siArray): @@ -877,7 +877,7 @@ proc genRaiseStmt(p: BProc, t: PNode) = fName, cIntValue(ln)) if optOwnedRefs in p.config.globalOptions: - p.s(cpsStmts).addAssignment(e, "NIM_NIL") + p.s(cpsStmts).addAssignment(e, NimNil) else: finallyActions(p) genLineDir(p, t) @@ -990,7 +990,7 @@ proc genStringCase(p: BProc, t: PNode, stringKind: TTypeKind, d: var TLoc) = let fnName = if stringKind == tyCstring: "hashCstring" else: "hashString" let ra = rdLoc(a) p.s(cpsStmts).addSwitchStmt( - cOp(BitAnd, "NI", + cOp(BitAnd, NimInt, cCall(cgsymValue(p.module, fnName), ra), cIntValue(bitMask))): for j in 0..high(branches): @@ -1483,7 +1483,7 @@ proc genTryGoto(p: BProc; t: PNode; d: var TLoc) = isScope = true innerScope = initScope(p.s(cpsStmts)) # we handled the exception, remember this: - p.s(cpsStmts).addAssignment(cDeref("nimErr_"), "NIM_FALSE") + p.s(cpsStmts).addAssignment(cDeref("nimErr_"), NimFalse) expr(p, t[i][0], d) else: if not innerIsIf: @@ -1518,7 +1518,7 @@ proc genTryGoto(p: BProc; t: PNode; d: var TLoc) = startBlockWith(p): initElifBranch(p.s(cpsStmts), innerIfStmt, orExpr) # we handled the exception, remember this: - p.s(cpsStmts).addAssignment(cDeref("nimErr_"), "NIM_FALSE") + p.s(cpsStmts).addAssignment(cDeref("nimErr_"), NimFalse) expr(p, t[i][^1], d) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "popCurrentException")) @@ -1549,9 +1549,9 @@ proc genTryGoto(p: BProc; t: PNode; d: var TLoc) = genStmts(p, t[i][0]) else: # pretend we did handle the error for the safe execution of the 'finally' section: - p.procSec(cpsLocals).addVar(kind = Local, name = "oldNimErrFin" & $lab & "_", typ = "NIM_BOOL") + p.procSec(cpsLocals).addVar(kind = Local, name = "oldNimErrFin" & $lab & "_", typ = NimBool) p.s(cpsStmts).addAssignment("oldNimErrFin" & $lab & "_", cDeref("nimErr_")) - p.s(cpsStmts).addAssignment(cDeref("nimErr_"), "NIM_FALSE") + p.s(cpsStmts).addAssignment(cDeref("nimErr_"), NimFalse) genStmts(p, t[i][0]) # this is correct for all these cases: # 1. finally is run during ordinary control flow @@ -1886,8 +1886,8 @@ proc genDiscriminantCheck(p: BProc, a, tmp: TLoc, objtype: PType, let rtmp = rdLoc(tmp) let dn = discriminatorTableName(p.module, t, field) p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "FieldDiscriminantCheck"), - cCast("NI", cCast("NU", ra)), - cCast("NI", cCast("NU", rtmp)), + cCast(NimInt, cCast(NimUint, ra)), + cCast(NimInt, cCast(NimUint, rtmp)), dn, lit) if p.config.exc == excGoto: diff --git a/compiler/ccgthreadvars.nim b/compiler/ccgthreadvars.nim index 0bc4414d2297..41a1ce69ba8d 100644 --- a/compiler/ccgthreadvars.nim +++ b/compiler/ccgthreadvars.nim @@ -59,6 +59,6 @@ proc generateThreadVarsSize(m: BModule) = sfCompileToCpp in m.module.flags: ExternC else: None m.s[cfsProcs].addDeclWithVisibility(externc): - m.s[cfsProcs].addProcHeader("NimThreadVarsSize", "NI", cProcParams()) + m.s[cfsProcs].addProcHeader("NimThreadVarsSize", NimInt, cProcParams()) m.s[cfsProcs].finishProcHeaderWithBody(): - m.s[cfsProcs].addReturn(cCast("NI", cSizeof("NimThreadVars"))) + m.s[cfsProcs].addReturn(cCast(NimInt, cSizeof("NimThreadVars"))) diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index b7bbc2e755d0..b45593e77f91 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -23,7 +23,7 @@ proc getTemp(p: BProc, t: PType, needsInit=false): TLoc proc visit(p: BProc, data, visitor: Snippet) = p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimGCvisit"), - cCast("void*", data), + cCast(CPointer, data), visitor) proc genTraverseProc(c: TTraversalClosure, accessor: Rope, n: PNode; @@ -108,7 +108,7 @@ proc genTraverseProc(c: TTraversalClosure, accessor: Rope, typ: PType) = # destructor based seqs are themselves not traced but their data is, if # they contain a GC'ed type: p.s(cpsStmts).addCallStmt(cgsymValue(p.module, "nimGCvisitSeq"), - cCast("void*", accessor), + cCast(CPointer, accessor), c.visitorFrmt) #genTraverseProcSeq(c, accessor, typ) of tyString: @@ -164,11 +164,11 @@ proc genTraverseProc(m: BModule, origTyp: PType; sig: SigHash): Rope = genTraverseProc(c, cDeref("a"), typ.elementType) var headerBuilder = newBuilder("") - headerBuilder.addProcHeaderWithParams(ccNimCall, markerName, "void"): + headerBuilder.addProcHeaderWithParams(ccNimCall, markerName, CVoid): var paramBuilder: ProcParamBuilder headerBuilder.addProcParams(paramBuilder): - headerBuilder.addParam(paramBuilder, name = "p", typ = "void*") - headerBuilder.addParam(paramBuilder, name = "op", typ = "NI") + headerBuilder.addParam(paramBuilder, name = "p", typ = CPointer) + headerBuilder.addParam(paramBuilder, name = "op", typ = NimInt) let header = extract(headerBuilder) m.s[cfsProcHeaders].addDeclWithVisibility(StaticProc): @@ -185,16 +185,16 @@ proc genTraverseProc(m: BModule, origTyp: PType; sig: SigHash): Rope = var desc = newBuilder("") var unnamedParamBuilder: ProcParamBuilder desc.addProcParams(unnamedParamBuilder): - desc.addUnnamedParam(unnamedParamBuilder, "void*") - desc.addUnnamedParam(unnamedParamBuilder, "NI") + desc.addUnnamedParam(unnamedParamBuilder, CPointer) + desc.addUnnamedParam(unnamedParamBuilder, NimInt) let unnamedParams = extract(desc) - m.s[cfsProcHeaders].addProcVar(ccNimCall, result, unnamedParams, "void") + m.s[cfsProcHeaders].addProcVar(ccNimCall, result, unnamedParams, CVoid) m.s[cfsDynLibInit].addAssignmentWithValue(result): - m.s[cfsDynLibInit].addCast(procPtrTypeUnnamed(ccNimCall, "void", unnamedParams)): + m.s[cfsDynLibInit].addCast(procPtrTypeUnnamed(ccNimCall, CVoid, unnamedParams)): m.s[cfsDynLibInit].addCall("hcrRegisterProc", getModuleDllPath(m), '"' & result & '"', - cCast("void*", markerName)) + cCast(CPointer, markerName)) proc genTraverseProcForGlobal(m: BModule, s: PSym; info: TLineInfo): Rope = discard genTypeInfoV1(m, s.loc.t, info) @@ -214,7 +214,7 @@ proc genTraverseProcForGlobal(m: BModule, s: PSym; info: TLineInfo): Rope = genTraverseProc(c, sLoc, s.loc.t) var headerBuilder = newBuilder("") - headerBuilder.addProcHeaderWithParams(ccNimCall, result, "void"): + headerBuilder.addProcHeaderWithParams(ccNimCall, result, CVoid): var paramBuilder: ProcParamBuilder headerBuilder.addProcParams(paramBuilder): # (void) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 3842e60bbb2e..b3e03f57490f 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -316,12 +316,12 @@ proc typeNameOrLiteral(m: BModule; t: PType, literal: string): Rope = proc getSimpleTypeDesc(m: BModule; typ: PType): Rope = const NumericalTypeToStr: array[tyInt..tyUInt64, string] = [ - "NI", "NI8", "NI16", "NI32", "NI64", - "NF", "NF32", "NF64", "NF128", - "NU", "NU8", "NU16", "NU32", "NU64"] + NimInt, NimInt8, NimInt16, NimInt32, NimInt64, + NimFloat, NimFloat32, NimFloat64, NimFloat128, + NimUint, NimUint8, NimUint16, NimUint32, NimUint64] case typ.kind of tyPointer: - result = typeNameOrLiteral(m, typ, "void*") + result = typeNameOrLiteral(m, typ, CPointer) of tyString: case detectStrVersion(m) of 2: @@ -331,10 +331,10 @@ proc getSimpleTypeDesc(m: BModule; typ: PType): Rope = else: cgsym(m, "NimStringDesc") result = typeNameOrLiteral(m, typ, "NimStringDesc*") - of tyCstring: result = typeNameOrLiteral(m, typ, "NCSTRING") - of tyBool: result = typeNameOrLiteral(m, typ, "NIM_BOOL") - of tyChar: result = typeNameOrLiteral(m, typ, "NIM_CHAR") - of tyNil: result = typeNameOrLiteral(m, typ, "void*") + of tyCstring: result = typeNameOrLiteral(m, typ, NimCstring) + of tyBool: result = typeNameOrLiteral(m, typ, NimBool) + of tyChar: result = typeNameOrLiteral(m, typ, NimChar) + of tyNil: result = typeNameOrLiteral(m, typ, CPointer) of tyInt..tyUInt64: result = typeNameOrLiteral(m, typ, NumericalTypeToStr[typ.kind]) of tyRange, tyOrdinal: result = getSimpleTypeDesc(m, typ.skipModifier) @@ -364,7 +364,7 @@ proc pushType(m: BModule; typ: PType) = m.typeStack.add(typ) proc getTypePre(m: BModule; typ: PType; sig: SigHash): Rope = - if typ == nil: result = rope("void") + if typ == nil: result = CVoid else: result = getSimpleTypeDesc(m, typ) if result == "": result = cacheGetType(m.typeCache, sig) @@ -428,7 +428,7 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet; kind: TypeDescKind m.typeCache[sig] = result #echo "adding ", sig, " ", typeToString(t), " ", m.module.name.s m.s[cfsTypes].addSimpleStruct(m, name = result, baseType = ""): - m.s[cfsTypes].addField(name = "len", typ = "NI") + m.s[cfsTypes].addField(name = "len", typ = NimInt) m.s[cfsTypes].addField(name = "p", typ = ptrType(result & "_Content")) pushType(m, t) else: @@ -450,7 +450,7 @@ proc seqV2ContentType(m: BModule; t: PType; check: var IntSet) = else: let dataTyp = getTypeDescAux(m, t.skipTypes(abstractInst)[0], check, dkVar) m.s[cfsTypes].addSimpleStruct(m, name = result & "_Content", baseType = ""): - m.s[cfsTypes].addField(name = "cap", typ = "NI") + m.s[cfsTypes].addField(name = "cap", typ = NimInt) m.s[cfsTypes].addField(name = "data", typ = dataTyp, isFlexArray = true) @@ -514,7 +514,7 @@ proc genMemberProcParams(m: BModule; prc: PSym, superCall, rettype, name, params # destructors can't have void rettype = "" elif t.returnType == nil or isInvalidReturnType(m.config, t): - rettype = "void" + rettype = CVoid else: if rettype == "": rettype = getTypeDescAux(m, t.returnType, check, dkResult) @@ -585,7 +585,7 @@ proc genProcParams(m: BModule; t: PType, rettype: var Rope, params: var Builder, check: var IntSet, declareEnvironment=true; weakDep=false;) = if t.returnType == nil or isInvalidReturnType(m.config, t): - rettype = "void" + rettype = CVoid else: rettype = getTypeDescAux(m, t.returnType, check, dkResult) var paramBuilder: ProcParamBuilder @@ -621,7 +621,7 @@ proc genProcParams(m: BModule; t: PType, rettype: var Rope, params: var Builder, # this fixes the 'sort' bug: if param.typ.kind in {tyVar, tyLent}: param.loc.storage = OnUnknown # need to pass hidden parameter: - params.addParam(paramBuilder, name = param.loc.snippet & "Len_" & $j, typ = "NI") + params.addParam(paramBuilder, name = param.loc.snippet & "Len_" & $j, typ = NimInt) inc(j) arr = arr[0].skipTypes({tySink}) if t.returnType != nil and isInvalidReturnType(m.config, t): @@ -637,7 +637,7 @@ proc genProcParams(m: BModule; t: PType, rettype: var Rope, params: var Builder, typ = getTypeDescAux(m, arr, check, dkResult) params.addParam(paramBuilder, name = "Result", typ = typ) if t.callConv == ccClosure and declareEnvironment: - params.addParam(paramBuilder, name = "ClE_0", typ = "void*") + params.addParam(paramBuilder, name = "ClE_0", typ = CPointer) if tfVarargs in t.flags: params.addVarargsParam(paramBuilder) @@ -830,7 +830,7 @@ proc getOpenArrayDesc(m: BModule; t: PType, check: var IntSet; kind: TypeDescKin m.s[cfsTypes].addTypedef(name = result): m.s[cfsTypes].addSimpleStruct(m, name = "", baseType = ""): m.s[cfsTypes].addField(name = "Field0", typ = ptrType(elemType)) - m.s[cfsTypes].addField(name = "Field1", typ = "NI") + m.s[cfsTypes].addField(name = "Field1", typ = NimInt) proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDescKind): Rope = # returns only the type's name @@ -904,23 +904,23 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes var size: int if firstOrd(m.config, t) < 0: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NI32") + m.s[cfsTypes].add(NimInt32) size = 4 else: size = int(getSize(m.config, t)) case size of 1: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NU8") + m.s[cfsTypes].add(NimUint8) of 2: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NU16") + m.s[cfsTypes].add(NimUint16) of 4: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NI32") + m.s[cfsTypes].add(NimInt32) of 8: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NI64") + m.s[cfsTypes].add(NimInt64) else: internalError(m.config, t.sym.info, "getTypeDescAux: enum") when false: let owner = hashOwner(t.sym) @@ -946,7 +946,7 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes m.s[cfsTypes].addTypedef(name = result): m.s[cfsTypes].addSimpleStruct(m, name = "", baseType = ""): m.s[cfsTypes].addProcField(name = "ClP_0", callConv = ccNimCall, rettype = rettype, params = params) - m.s[cfsTypes].addField(name = "ClE_0", typ = "void*") + m.s[cfsTypes].addField(name = "ClE_0", typ = CPointer) of tySequence: if optSeqDestructors in m.config.globalOptions: result = getTypeDescWeak(m, t, check, kind) @@ -999,7 +999,7 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes template addResultType(ty: untyped) = if ty == nil or ty.kind == tyVoid: - result.add("void") + result.add(CVoid) elif ty.kind == tyStatic: internalAssert m.config, ty.n != nil result.add ty.n.renderTree @@ -1065,10 +1065,10 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes case s of 1, 2, 4, 8: m.s[cfsTypes].addTypedef(name = result): - m.s[cfsTypes].add("NU" & rope(s*8)) + m.s[cfsTypes].add(cUintType(s*8)) else: m.s[cfsTypes].addArrayTypedef(name = result, len = s): - m.s[cfsTypes].add("NU8") + m.s[cfsTypes].add(NimUint8) of tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias, tySink, tyOwned, tyUserTypeClass, tyUserTypeClassInst, tyInferred: result = getTypeDescAux(m, skipModifier(t), check, kind) @@ -1104,7 +1104,7 @@ proc getClosureType(m: BModule; t: PType, kind: TClosureTypeKind): Rope = m.s[cfsTypes].addTypedef(name = result): m.s[cfsTypes].addSimpleStruct(m, name = "", baseType = ""): m.s[cfsTypes].addProcField(name = "ClP_0", callConv = ccNimCall, rettype = rettype, params = params) - m.s[cfsTypes].addField(name = "ClE_0", typ = "void*") + m.s[cfsTypes].addField(name = "ClE_0", typ = CPointer) proc finishTypeDescriptions(m: BModule) = var i = 0 @@ -1256,7 +1256,7 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; var size: Rope if tfIncompleteStruct in typ.flags: - size = rope"void*" + size = CPointer else: size = getTypeDesc(m, origType, dkVar) m.s[cfsTypeInit3].addFieldAssignmentWithValue(nameHcr, "size"): @@ -1296,9 +1296,9 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; m.hcrCreateTypeInfosProc.addArgument(registerHcr): m.hcrCreateTypeInfosProc.addSizeof("TNimType") m.hcrCreateTypeInfosProc.addArgument(registerHcr): - m.hcrCreateTypeInfosProc.add("NULL") + m.hcrCreateTypeInfosProc.add(CNil) m.hcrCreateTypeInfosProc.addArgument(registerHcr): - m.hcrCreateTypeInfosProc.addCast(typ = "void**"): + m.hcrCreateTypeInfosProc.addCast(typ = ptrType(CPointer)): m.hcrCreateTypeInfosProc.add(cAddr(name)) else: m.s[cfsStrData].addDeclWithVisibility(Private): @@ -1348,11 +1348,11 @@ proc genTNimNodeArray(m: BModule; name: Rope, size: int) = m.hcrCreateTypeInfosProc.addArgument(registerHcr): m.hcrCreateTypeInfosProc.add(makeCString(name)) m.hcrCreateTypeInfosProc.addArgument(registerHcr): - m.hcrCreateTypeInfosProc.addOp(Mul, "NI", cSizeof(ptrType("TNimNode")), cIntValue(size)) + m.hcrCreateTypeInfosProc.addOp(Mul, NimInt, cSizeof(ptrType("TNimNode")), cIntValue(size)) m.hcrCreateTypeInfosProc.addArgument(registerHcr): - m.hcrCreateTypeInfosProc.add("NULL") + m.hcrCreateTypeInfosProc.add(CNil) m.hcrCreateTypeInfosProc.addArgument(registerHcr): - m.hcrCreateTypeInfosProc.addCast(typ = "void**"): + m.hcrCreateTypeInfosProc.addCast(typ = ptrType(CPointer)): m.hcrCreateTypeInfosProc.add(cAddr(name)) else: m.s[cfsTypeInit1].addArrayVar(kind = Global, name = name, @@ -1393,7 +1393,7 @@ proc genObjectFields(m: BModule; typ, origType: PType, n: PNode, expr: Rope; m.s[cfsTypeInit3].addOffsetof(getTypeDesc(m, origType, dkVar), field.loc.snippet) m.s[cfsTypeInit3].addFieldAssignment(expr, "typ", fieldTypInfo) m.s[cfsTypeInit3].addFieldAssignment(expr, "name", makeCString(field.name.s)) - m.s[cfsTypeInit3].addFieldAssignment(expr, "sons", cAddr(subscript(tmp, "0"))) + m.s[cfsTypeInit3].addFieldAssignment(expr, "sons", cAddr(subscript(tmp, cIntValue(0)))) m.s[cfsTypeInit3].addFieldAssignment(expr, "len", L) m.s[cfsData].addArrayVar(kind = Local, name = tmp, elementType = ptrType("TNimNode"), len = toInt(L)+1) @@ -1502,18 +1502,18 @@ proc genEnumInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = hasHoles = true var enumArray = getTempName(m) var counter = getTempName(m) - m.s[cfsTypeInit1].addVar(kind = Local, name = counter, typ = "NI") + m.s[cfsTypeInit1].addVar(kind = Local, name = counter, typ = NimInt) m.s[cfsTypeInit1].addArrayVarWithInitializer( kind = Global, name = enumArray, - elementType = constPtrType("char"), + elementType = constPtrType(CChar), len = typ.n.len): m.s[cfsTypeInit1].add(extract(enumNames)) m.s[cfsTypeInit3].addForRangeExclusive(i = counter, start = cIntValue(0), bound = cIntValue(typ.n.len)): let nodeLoc = subscript(m.typeNodesName, - cOp(Add, "NI", counter, cIntValue(firstNimNode))) + cOp(Add, NimInt, counter, cIntValue(firstNimNode))) m.s[cfsTypeInit3].addFieldAssignment(nodeLoc, "kind", cIntValue(1)) m.s[cfsTypeInit3].addFieldAssignment(nodeLoc, "offset", counter) m.s[cfsTypeInit3].addFieldAssignment(nodeLoc, "name", @@ -1530,7 +1530,7 @@ proc genEnumInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = if hasHoles: m.s[cfsTypeInit3].addFieldAssignment(tiNameForHcr(m, name), "flags", # 1 << 2 is {ntfEnumHole} - cOp(Shl, "NU8", cIntValue(1), cIntValue(2))) + cOp(Shl, NimUint8, cIntValue(1), cIntValue(2))) proc genSetInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = assert(typ.elementType != nil) @@ -1559,9 +1559,9 @@ proc genDeepCopyProc(m: BModule; s: PSym; result: Rope) = var desc = newBuilder("") var paramBuilder: ProcParamBuilder desc.addProcParams(paramBuilder): - desc.addUnnamedParam(paramBuilder, typ = "void*") + desc.addUnnamedParam(paramBuilder, typ = CPointer) let params = extract(desc) - let pt = procPtrTypeUnnamedNimCall(rettype = "void*", params = params) + let pt = procPtrTypeUnnamedNimCall(rettype = CPointer, params = params) m.s[cfsTypeInit3].addFieldAssignmentWithValue(result, "deepcopy"): m.s[cfsTypeInit3].add(cCast(pt, s.loc.snippet)) @@ -1674,7 +1674,7 @@ proc genHook(m: BModule; t: PType; info: TLineInfo; op: TTypeAttachedOp; result: # unfortunately this check is wrong for an object type that only contains # .cursor fields like 'Node' inside 'cycleleak'. internalError(m.config, info, "no attached trace proc found") - result.add rope("NIM_NIL") + result.add NimNil proc getObjDepth(t: PType): int16 = var x = t @@ -1713,7 +1713,7 @@ proc genVTable(result: var Builder, seqs: seq[PSym]) = result.addStructInitializer(table, siArray): for i in 0.. 0: g.mainModProcs.addDeclWithVisibility(Private): - g.mainModProcs.addProcHeader(ccNimCall, datInit, "void", cProcParams()) + g.mainModProcs.addProcHeader(ccNimCall, datInit, CVoid, cProcParams()) g.mainModProcs.finishProcHeaderAsProto() g.mainDatInit.addCallStmt(datInit) @@ -2019,11 +2019,11 @@ proc registerModuleToMain(g: BModuleList; m: BModule) = g.mainDatInit.addCallStmt(cgsymValue(m, "initThreadVarsEmulation")) if m.config.target.targetOS != osStandalone and m.config.selectedGC notin {gcNone, gcArc, gcAtomicArc, gcOrc}: g.mainDatInit.addCallStmt(cgsymValue(m, "initStackBottomWith"), - cCast("void*", cAddr("inner"))) + cCast(CPointer, cAddr("inner"))) if m.s[cfsInitProc].buf.len > 0: g.mainModProcs.addDeclWithVisibility(Private): - g.mainModProcs.addProcHeader(ccNimCall, init, "void", cProcParams()) + g.mainModProcs.addProcHeader(ccNimCall, init, CVoid, cProcParams()) g.mainModProcs.finishProcHeaderAsProto() if sfMainModule in m.module.flags: g.mainModInit.addCallStmt(init) @@ -2042,7 +2042,7 @@ proc genDatInitCode(m: BModule) = var prc = newBuilder("") let vis = if m.hcrOn: ExportLib else: Private prc.addDeclWithVisibility(vis): - prc.addProcHeader(ccNimCall, getDatInitName(m), "void", cProcParams()) + prc.addProcHeader(ccNimCall, getDatInitName(m), CVoid, cProcParams()) prc.finishProcHeaderWithBody(): # we don't want to break into such init code - could happen if a line # directive from a function written by the user spills after itself @@ -2093,9 +2093,9 @@ proc genInitCode(m: BModule) = m.s[cfsTypeInit1].addCallStmt("hcrRegisterGlobal", getModuleDllPath(m, m.module), '"' & m.typeNodesName & '_' & $m.typeNodes & '"', - cOp(Mul, "NI", cSizeof("TNimNode"), cIntValue(m.typeNodes)), - "NULL", - cCast("void**", cAddr(m.typeNodesName))) + cOp(Mul, NimInt, cSizeof("TNimNode"), cIntValue(m.typeNodes)), + CNil, + cCast(ptrType(CPointer), cAddr(m.typeNodesName))) else: m.s[cfsTypeInit1].addArrayVar(Global, name = m.typeNodesName, elementType = cgsymValue(m, "TNimNode"), len = m.typeNodes) @@ -2104,14 +2104,14 @@ proc genInitCode(m: BModule) = elementType = cgsymValue(m, "TNimType"), len = m.nimTypes) if m.hcrOn: - prcBody.addVar(name = "nim_hcr_dummy_", typ = ptrType("int"), initializer = cIntValue(0)) - prcBody.addVar(name = "nim_hcr_do_init_", typ = "NIM_BOOL", + prcBody.addVar(name = "nim_hcr_dummy_", typ = ptrType(CInt), initializer = cIntValue(0)) + prcBody.addVar(name = "nim_hcr_do_init_", typ = NimBool, initializer = cCall("hcrRegisterGlobal", getModuleDllPath(m, m.module), "\"module_initialized_\"", cIntValue(1), - "NULL", - cCast("void**", cAddr("nim_hcr_dummy_")))) + CNil, + cCast(ptrType(CPointer), cAddr("nim_hcr_dummy_")))) template writeSection(thing: untyped, section: TCProcSection, addHcrGuards = false) = if m.thing.s(section).buf.len > 0: @@ -2173,7 +2173,7 @@ proc genInitCode(m: BModule) = var procs = newBuilder("") let vis = if m.hcrOn: ExportLib else: Private procs.addDeclWithVisibility(vis): - procs.addProcHeader(ccNimCall, initname, "void", cProcParams()) + procs.addProcHeader(ccNimCall, initname, CVoid, cProcParams()) procs.finishProcHeaderWithBody(): procs.add(extract(prcBody)) @@ -2185,13 +2185,13 @@ proc genInitCode(m: BModule) = var procsToLoad = @["hcrRegisterProc", "hcrGetProc", "hcrRegisterGlobal", "hcrGetGlobal"] m.s[cfsInitProc].addDeclWithVisibility(ExportLib): - m.s[cfsInitProc].addProcHeaderWithParams(ccNimCall, getHcrInitName(m), "void"): + m.s[cfsInitProc].addProcHeaderWithParams(ccNimCall, getHcrInitName(m), CVoid): var hcrInitParams: ProcParamBuilder m.s[cfsInitProc].addProcParams(hcrInitParams): - m.s[cfsInitProc].addParam(hcrInitParams, "handle", "void*") - m.s[cfsInitProc].addProcTypedParam(hcrInitParams, ccNimCall, "getProcAddr", "void*", cProcParams( - (name: "", typ: "void*"), - (name: "", typ: ptrType("char")))) + m.s[cfsInitProc].addParam(hcrInitParams, "handle", CPointer) + m.s[cfsInitProc].addProcTypedParam(hcrInitParams, ccNimCall, "getProcAddr", CPointer, cProcParams( + (name: "", typ: CPointer), + (name: "", typ: ptrType(CChar)))) m.s[cfsInitProc].finishProcHeaderWithBody(): if sfMainModule in m.module.flags: # additional procs to load @@ -2205,7 +2205,7 @@ proc genInitCode(m: BModule) = if el.buf.len != 0: moduleInitRequired = true procs.addDeclWithVisibility(ExternC): - procs.addProcHeader(ccNimCall, "nimLoadProcs" & $(i.ord - '0'.ord), "void", cProcParams()) + procs.addProcHeader(ccNimCall, "nimLoadProcs" & $(i.ord - '0'.ord), CVoid, cProcParams()) procs.finishProcHeaderWithBody(): procs.add(extract(el)) @@ -2217,7 +2217,7 @@ proc genInitCode(m: BModule) = if m.hcrOn: m.s[cfsInitProc].addDeclWithVisibility(ExportLib): - m.s[cfsInitProc].addProcHeader(ccNimCall, "HcrCreateTypeInfos", "void", cProcParams()) + m.s[cfsInitProc].addProcHeader(ccNimCall, "HcrCreateTypeInfos", CVoid, cProcParams()) m.s[cfsInitProc].finishProcHeaderWithBody(): m.s[cfsInitProc].add(extract(m.hcrCreateTypeInfosProc)) m.s[cfsInitProc].addNewline() @@ -2376,7 +2376,7 @@ proc writeHeader(m: BModule) = let vis = if optGenDynLib in m.config.globalOptions: ImportLib else: None result.addDeclWithVisibility(vis): - result.addProcHeader(ccCDecl, m.config.nimMainPrefix & "NimMain", "void", cProcParams()) + result.addProcHeader(ccCDecl, m.config.nimMainPrefix & "NimMain", CVoid, cProcParams()) result.finishProcHeaderAsProto() if m.config.cppCustomNamespace.len > 0: closeNamespaceNim(result) result.addf("#endif /* $1 */$n", [guard])