From e5bd3b5b97e473efa90b08a9042a58bc6c9595a0 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Thu, 15 Dec 2011 18:39:44 +0200 Subject: [PATCH] bootstraps fine with overloadable templates --- compiler/ast.nim | 24 ++++++++- compiler/ccgcalls.nim | 3 +- compiler/pragmas.nim | 8 ++- compiler/sem.nim | 29 +++++----- compiler/semcall.nim | 120 ++++++++++++++++++++++-------------------- compiler/semdata.nim | 2 +- compiler/semexprs.nim | 104 +++++++++++++++++++++++++----------- compiler/semtempl.nim | 4 +- compiler/semtypes.nim | 1 + compiler/sigmatch.nim | 54 ++++++++++--------- compiler/suggest.nim | 16 +++--- compiler/wordrecg.nim | 4 +- lib/system/excpt.nim | 2 +- lib/system/gc.nim | 2 +- 14 files changed, 230 insertions(+), 143 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index cfcdb6ea6..2c8ca52d7 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -225,6 +225,9 @@ type sfInnerProc, # proc is an inner proc sfThread, # proc will run as a thread # variable is a thread variable + sfInline # forced-inline procs + sfImmediate, # macro or template is immediately expanded without + # considering any possible overloads sfCompileTime, # proc can be evaluated at compile time sfMerge, # proc can be merged with itself sfDeadCodeElim, # dead code elimination for the module is turned on @@ -570,7 +573,8 @@ type # the poor naming choices in the standard library. const - OverloadableSyms* = {skProc, skMethod, skIterator, skConverter, skModule} + OverloadableSyms* = {skProc, skMethod, skIterator, skConverter, + skModule, skTemplate, skMacro} GenericTypes*: TTypeKinds = {tyGenericInvokation, tyGenericBody, tyGenericParam} @@ -918,6 +922,12 @@ proc delSon(father: PNode, idx: int) = for i in countup(idx, length - 2): father.sons[i] = father.sons[i + 1] setlen(father.sons, length - 1) +proc hasSons*(n: PNode): bool {.inline.} = + result = n.kind notin { nkCharLit..nkInt64Lit, + nkFloatLit..nkFloat64Lit, + nkStrLit..nkTripleStrLit, + nkSym, nkIdent } + proc copyNode(src: PNode): PNode = # does not copy its sons! if src == nil: @@ -949,6 +959,18 @@ proc shallowCopy*(src: PNode): PNode = of nkStrLit..nkTripleStrLit: result.strVal = src.strVal else: newSeq(result.sons, sonsLen(src)) +proc copySons*(src: PNode): Pnode = + # copies a node and its immediate sons + if src == nil: return nil + assert src.hasSons + result = newNode(src.kind) + result.info = src.info + result.typ = src.typ + result.flags = src.flags * PersistentNodeFlags + newSeq(result.sons, src.len) + for i in countup(0, src.len - 1): + result.sons[i] = src.sons[i] + proc copyTree(src: PNode): PNode = # copy a whole syntax tree; performs deep copying if src == nil: diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index fef1b055d..072b2f9fb 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -10,7 +10,8 @@ proc leftAppearsOnRightSide(le, ri: PNode): bool = if le != nil: for i in 1 ..