unsigned array indexes work better; minor cleanups

This commit is contained in:
Araq 2015-02-09 15:12:31 +01:00
commit 865d341b32
2 changed files with 26 additions and 9 deletions

View file

@ -130,8 +130,8 @@ proc skipConvAndClosure*(n: PNode): PNode =
proc sameValue*(a, b: PNode): bool = proc sameValue*(a, b: PNode): bool =
result = false result = false
case a.kind case a.kind
of nkCharLit..nkInt64Lit: of nkCharLit..nkUInt64Lit:
if b.kind in {nkCharLit..nkInt64Lit}: result = a.intVal == b.intVal if b.kind in {nkCharLit..nkUInt64Lit}: result = a.intVal == b.intVal
of nkFloatLit..nkFloat64Lit: of nkFloatLit..nkFloat64Lit:
if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal == b.floatVal if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal == b.floatVal
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
@ -145,13 +145,13 @@ proc leValue*(a, b: PNode): bool =
# a <= b? # a <= b?
result = false result = false
case a.kind case a.kind
of nkCharLit..nkInt64Lit: of nkCharLit..nkUInt32Lit:
if b.kind in {nkCharLit..nkInt64Lit}: result = a.intVal <= b.intVal if b.kind in {nkCharLit..nkUInt32Lit}: result = a.intVal <= b.intVal
of nkFloatLit..nkFloat64Lit: of nkFloatLit..nkFloat64Lit:
if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal <= b.floatVal if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal <= b.floatVal
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
if b.kind in {nkStrLit..nkTripleStrLit}: result = a.strVal <= b.strVal if b.kind in {nkStrLit..nkTripleStrLit}: result = a.strVal <= b.strVal
else: else:
# don't raise an internal error for 'nimrod check': # don't raise an internal error for 'nimrod check':
#InternalError(a.info, "leValue") #InternalError(a.info, "leValue")
discard discard

View file

@ -1,9 +1,10 @@
discard """ discard """
output: "2" output: '''2
88'''
""" """
type type
TValue* {.pure, final.} = object of TObject TValue* {.pure, final.} = object of RootObj
a: int a: int
PValue = ref TValue PValue = ref TValue
PPValue = ptr PValue PPValue = ptr PValue
@ -16,3 +17,19 @@ var sp: PPValue = addr x
sp.a = 2 sp.a = 2
if sp.a == 2: echo 2 # with sp[].a the error is gone if sp.a == 2: echo 2 # with sp[].a the error is gone
# Test the new auto-deref a little
{.experimental.}
proc p(x: var int; y: int) = x += y
block:
var x: ref int
new(x)
x.p(44)
var indirect = p
x.indirect(44)
echo x[]