diff options
-rw-r--r-- | compiler/ast.nim | 3 | ||||
-rw-r--r-- | compiler/ccgutils.nim | 4 | ||||
-rw-r--r-- | compiler/pragmas.nim | 6 |
3 files changed, 9 insertions, 4 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 7e92cd140..da9b3898e 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -231,7 +231,7 @@ type TNodeKinds* = set[TNodeKind] type - TSymFlag* = enum # 50 flags! + TSymFlag* = enum # 51 flags! sfUsed, # read access of sym (for warnings) or simply used sfExported, # symbol is exported from module sfFromGeneric, # symbol is instantiation of a generic; this is needed @@ -313,6 +313,7 @@ type # This is disallowed but can cause the typechecking to go into # an infinite loop, this flag is used as a sentinel to stop it. sfVirtual # proc is a C++ virtual function + sfByCopy # param is marked as pass bycopy TSymFlags* = set[TSymFlag] diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index d9aa58c67..ea4f3fe18 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -122,8 +122,10 @@ proc ccgIntroducedPtr*(conf: ConfigRef; s: PSym, retType: PType): bool = var pt = skipTypes(s.typ, typedescInst) assert skResult != s.kind + #note precedence: params override types if optByRef in s.options: return true - if tfByRef in pt.flags: return true + elif sfByCopy in s.flags: return false + elif tfByRef in pt.flags: return true elif tfByCopy in pt.flags: return false case pt.kind of tyObject: diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index bc375b1bc..11305db2a 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -84,7 +84,7 @@ const wGensym, wInject, wIntDefine, wStrDefine, wBoolDefine, wDefine, wCompilerProc, wCore} - paramPragmas* = {wNoalias, wInject, wGensym, wByRef} + paramPragmas* = {wNoalias, wInject, wGensym, wByRef, wByCopy} letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNoSideEffect, wThread, wRaises, wEffectsOf, wLocks, wTags, wForbids, wGcSafe, @@ -1204,7 +1204,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, incl(sym.typ.flags, tfByRef) of wByCopy: noVal(c, it) - if sym.kind != skType or sym.typ == nil: invalidPragma(c, it) + if sym.kind == skParam: + incl(sym.flags, sfByCopy) + elif sym.kind != skType or sym.typ == nil: invalidPragma(c, it) else: incl(sym.typ.flags, tfByCopy) of wPartial: noVal(c, it) |