This commit is contained in:
Zahary Karadjov 2012-10-16 02:12:41 +03:00
commit 2efdf3df81
3 changed files with 25 additions and 13 deletions

View file

@ -223,7 +223,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
# little HACK to support the new 'var T' as return type: # little HACK to support the new 'var T' as return type:
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
return return
var ty = skipTypes(dest.t, abstractVarRange) var ty = skipTypes(dest.t, abstractRange)
case ty.kind case ty.kind
of tyRef: of tyRef:
genRefAssign(p, dest, src, flags) genRefAssign(p, dest, src, flags)
@ -282,7 +282,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
else: else:
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString, of tyPtr, tyPointer, tyChar, tyBool, tyEnum, tyCString,
tyInt..tyUInt64, tyRange: tyInt..tyUInt64, tyRange, tyVar:
lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)]) lineCg(p, cpsStmts, "$1 = $2;$n", [rdLoc(dest), rdLoc(src)])
else: InternalError("genAssignment(" & $ty.kind & ')') else: InternalError("genAssignment(" & $ty.kind & ')')

View file

@ -271,7 +271,7 @@ proc resetLoc(p: BProc, loc: var TLoc) =
genObjectInit(p, cpsStmts, loc.t, loc, true) genObjectInit(p, cpsStmts, loc.t, loc, true)
proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) = proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) =
if not isComplexValueType(skipTypes(loc.t, abstractVarRange)): if not isComplexValueType(skipTypes(loc.t, abstractRange)):
lineF(p, section, "$1 = 0;$n", [rdLoc(loc)]) lineF(p, section, "$1 = 0;$n", [rdLoc(loc)])
else: else:
lineF(p, section, "memset((void*)$1, 0, sizeof($2));$n", lineF(p, section, "memset((void*)$1, 0, sizeof($2));$n",

View file

@ -1,24 +1,36 @@
discard """ discard """
file: "tarray2.nim" file: "tarray2.nim"
output: "[16, 25, 36]" output: "[4, 5, 6]\n\n[16, 25, 36]\n\n[16, 25, 36]"
""" """
# simple check for one dimensional arrays # simple check for one dimensional arrays
type type
TMyArray = array[0..2, int] TMyArray = array[0..2, int]
proc mul(a, b: TMyarray): TMyArray = TObj = object
arr: TMyarray
proc mul(a, b: TMyarray): TMyArray =
result = a result = a
for i in 0..len(a)-1: for i in 0..len(a)-1:
result[i] = a[i] * b[i] result[i] = a[i] * b[i]
var var
x, y, z: TMyArray x, y: TMyArray
o: TObj
proc varArr1(x: var TMyArray): var TMyArray = x
proc varArr2(x: var TObj): var TMyArray = x.arr
x = [ 4, 5, 6 ] x = [ 4, 5, 6 ]
echo repr(varArr1(x))
y = x y = x
echo repr(mul(x, y)) echo repr(mul(x, y))
#OUT [16, 25, 36] o.arr = mul(x, y)
echo repr(varArr2(o))
#OUT [16, 25, 36]