diff options
-rw-r--r-- | compiler/ast.nim | 4 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 3 | ||||
-rw-r--r-- | compiler/jsgen.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 4 | ||||
-rw-r--r-- | lib/system.nim | 13 |
5 files changed, 17 insertions, 9 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 7275aceb1..73c99c0b1 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -563,8 +563,8 @@ type mEqEnum, mLeEnum, mLtEnum, mEqCh, mLeCh, mLtCh, mEqB, mLeB, mLtB, - mEqRef, mEqUntracedRef, mLePtr, mLtPtr, mEqCString, - mXor, mEqProc, + mEqRef, mEqUntracedRef, mLePtr, mLtPtr, + mXor, mEqCString, mEqProc, mUnaryMinusI, mUnaryMinusI64, mAbsI, mNot, mUnaryPlusI, mBitnotI, mUnaryPlusF64, mUnaryMinusF64, mAbsF64, diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 9f4beda9e..917f72b16 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -591,7 +591,6 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = "($1 == $2)", # EqPtr "($1 <= $2)", # LePtr "($1 < $2)", # LtPtr - "($1 == $2)", # EqCString "($1 != $2)"] # Xor var a, b: TLoc @@ -1754,7 +1753,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = initLocExpr(p, x, a) initLocExpr(p, e.sons[2], b) genDeepCopy(p, a, b) - of mDotDot: genCall(p, e, d) + of mDotDot, mEqCString: genCall(p, e, d) else: internalError(e.info, "genMagicExpr: " & $op) proc genConstExpr(p: BProc, n: PNode): Rope diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 124459306..41e42b825 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -359,8 +359,8 @@ const # magic checked op; magic unchecked op; checked op; unchecked op ["", "", "($1 == $2)", "($1 == $2)"], # EqUntracedRef ["", "", "($1 <= $2)", "($1 <= $2)"], # LePtr ["", "", "($1 < $2)", "($1 < $2)"], # LtPtr - ["", "", "($1 == $2)", "($1 == $2)"], # EqCString ["", "", "($1 != $2)", "($1 != $2)"], # Xor + ["", "", "($1 == $2)", "($1 == $2)"], # EqCString ["", "", "($1 == $2)", "($1 == $2)"], # EqProc ["negInt", "", "negInt($1)", "-($1)"], # UnaryMinusI ["negInt64", "", "negInt64($1)", "-($1)"], # UnaryMinusI64 diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 675fb2dc2..d4966b3e3 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -817,7 +817,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mLtF64: genBinaryABC(c, n, dest, opcLtFloat) of mLePtr, mLeU, mLeU64: genBinaryABC(c, n, dest, opcLeu) of mLtPtr, mLtU, mLtU64: genBinaryABC(c, n, dest, opcLtu) - of mEqProc, mEqRef, mEqUntracedRef, mEqCString: + of mEqProc, mEqRef, mEqUntracedRef: genBinaryABC(c, n, dest, opcEqRef) of mXor: genBinaryABCnarrowU(c, n, dest, opcXor) of mNot: genUnaryABC(c, n, dest, opcNot) @@ -834,7 +834,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = mToBiggestInt, mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mFloatToStr, mCStrToStr, mStrToStr, mEnumToStr: genConv(c, n, n.sons[1], dest) - of mEqStr: genBinaryABC(c, n, dest, opcEqStr) + of mEqStr, mEqCString: genBinaryABC(c, n, dest, opcEqStr) of mLeStr: genBinaryABC(c, n, dest, opcLeStr) of mLtStr: genBinaryABC(c, n, dest, opcLtStr) of mEqSet: genBinarySet(c, n, dest, opcEqSet) diff --git a/lib/system.nim b/lib/system.nim index 3a5415b87..3abcb9577 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -302,8 +302,7 @@ proc `==` *(x, y: pointer): bool {.magic: "EqRef", noSideEffect.} ## echo (a == b) # true due to the special meaning of `nil`/0 as a pointer proc `==` *(x, y: string): bool {.magic: "EqStr", noSideEffect.} ## Checks for equality between two `string` variables -proc `==` *(x, y: cstring): bool {.magic: "EqCString", noSideEffect.} - ## Checks for equality between two `cstring` variables + proc `==` *(x, y: char): bool {.magic: "EqCh", noSideEffect.} ## Checks for equality between two `char` variables proc `==` *(x, y: bool): bool {.magic: "EqB", noSideEffect.} @@ -3616,6 +3615,16 @@ proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} = ## This is an optimization that rarely makes sense. discard + +proc `==` *(x, y: cstring): bool {.magic: "EqCString", noSideEffect, + inline.} = + ## Checks for equality between two `cstring` variables. + proc strcmp(a, b: cstring): cint {.noSideEffect, + importc, header: "<string.h>".} + if pointer(x) == pointer(y): result = true + elif x.isNil or y.isNil: result = false + else: result = strcmp(x, y) == 0 + {.pop.} #{.push warning[GcMem]: off, warning[Uninit]: off.} when defined(nimconfig): |