From 9fc2bfa799ef432c96853d13b4487e99d5028f83 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 24 Feb 2013 03:51:45 +0100 Subject: [PATCH] codegen produces better code for complex assignments --- compiler/c2nim/c2nim.nim | 4 +-- compiler/ccgcalls.nim | 2 +- compiler/ccgexprs.nim | 63 ++++++++++++++++++++++++++++++++++++++-- todo.txt | 9 +++--- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/compiler/c2nim/c2nim.nim b/compiler/c2nim/c2nim.nim index 40fb209c79..029f9ecda4 100755 --- a/compiler/c2nim/c2nim.nim +++ b/compiler/c2nim/c2nim.nim @@ -1,7 +1,7 @@ # # # c2nim - C to Nimrod source converter -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2013 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -15,7 +15,7 @@ const Version = NimrodVersion Usage = """ c2nim - C to Nimrod source converter - (c) 2012 Andreas Rumpf + (c) 2013 Andreas Rumpf Usage: c2nim [options] inputfile [options] Options: -o, --out:FILE set output filename diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 71e4fe39b0..b8b7f4c44d 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2013 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c6efaa7a07..cc97baaa4a 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -195,6 +195,46 @@ proc genRefAssign(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = addrLoc(dest), rdLoc(src)) if needToKeepAlive in flags: keepAlive(p, dest) +proc asgnComplexity(n: PNode): int = + if n != nil: + case n.kind + of nkSym: result = 1 + of nkRecCase: + # 'case objects' are too difficult to inline their assignment operation: + result = 100 + of nkRecList: + for t in items(n): + result += asgnComplexity(t) + else: nil + +proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) + +proc optAsgnLoc(a: TLoc, t: PType, field: PRope): TLoc = + result.k = locField + result.s = a.s + result.t = t + result.r = rdLoc(a).con(".").con(field) + result.heapRoot = a.heapRoot + +proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = + for i in 0 .. 1 +- GC: implement simple generational GC + * first version: mark black in write barrier + * second version: introduce fake roots instead of marking black + * third version: find some clever heuristic which is preferable GC