diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/condsyms.nim | 3 | ||||
-rw-r--r-- | compiler/lexer.nim | 4 | ||||
-rw-r--r-- | compiler/parser.nim | 3 | ||||
-rw-r--r-- | compiler/renderer.nim | 6 | ||||
-rw-r--r-- | compiler/semtypes.nim | 9 | ||||
-rw-r--r-- | compiler/semtypinst.nim | 16 | ||||
-rw-r--r-- | compiler/wordrecg.nim | 4 |
8 files changed, 31 insertions, 16 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 0652bd3e7..791b73685 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -559,7 +559,7 @@ type mFloat, mFloat32, mFloat64, mFloat128, mBool, mChar, mString, mCstring, mPointer, mEmptySet, mIntSetBaseType, mNil, mExpr, mStmt, mTypeDesc, - mVoidType, mPNimrodNode, + mVoidType, mPNimrodNode, mShared, mGuarded, mIsMainModule, mCompileDate, mCompileTime, mNimrodVersion, mNimrodMajor, mNimrodMinor, mNimrodPatch, mCpuEndian, mHostOS, mHostCPU, mAppType, mNaN, mInf, mNegInf, diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index ddf2075b4..4117fc461 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2013 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -48,6 +48,7 @@ proc initDefines*() = defineSymbol("nimbabel") defineSymbol("nimcomputedgoto") defineSymbol("nimunion") + defineSymbol("nimnewshared") # add platform specific symbols: case targetCPU diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 217e33675..2bfd8d1eb 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -43,7 +43,7 @@ type tkLambda, tkLet, tkMacro, tkMethod, tkMixin, tkMod, tkNil, tkNot, tkNotin, tkObject, tkOf, tkOr, tkOut, - tkProc, tkPtr, tkRaise, tkRef, tkReturn, tkShared, tkShl, tkShr, tkStatic, + tkProc, tkPtr, tkRaise, tkRef, tkReturn, tkShl, tkShr, tkStatic, tkTemplate, tkTry, tkTuple, tkType, tkUsing, tkVar, tkWhen, tkWhile, tkWith, tkWithout, tkXor, @@ -79,7 +79,7 @@ const "macro", "method", "mixin", "mod", "nil", "not", "notin", "object", "of", "or", "out", "proc", "ptr", "raise", "ref", "return", - "shared", "shl", "shr", "static", + "shl", "shr", "static", "template", "try", "tuple", "type", "using", "var", "when", "while", "with", "without", "xor", diff --git a/compiler/parser.nim b/compiler/parser.nim index c68c80b46..5c7b86240 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -967,7 +967,7 @@ proc isExprStart(p: TParser): bool = of tkSymbol, tkAccent, tkOpr, tkNot, tkNil, tkCast, tkIf, tkProc, tkIterator, tkBind, tkAddr, tkParLe, tkBracketLe, tkCurlyLe, tkIntLit..tkCharLit, tkVar, tkRef, tkPtr, - tkTuple, tkObject, tkType, tkWhen, tkCase, tkShared: + tkTuple, tkObject, tkType, tkWhen, tkCase: result = true else: result = false @@ -1040,7 +1040,6 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode = of tkVar: result = parseTypeDescKAux(p, nkVarTy, mode) of tkRef: result = parseTypeDescKAux(p, nkRefTy, mode) of tkPtr: result = parseTypeDescKAux(p, nkPtrTy, mode) - of tkShared: result = parseTypeDescKAux(p, nkSharedTy, mode) of tkDistinct: result = parseTypeDescKAux(p, nkDistinctTy, mode) of tkType: result = parseTypeDescKAux(p, nkTypeOfExpr, mode) of tkTuple: result = parseTuple(p, mode == pmTypeDef) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index fa119eba9..6b62c48c5 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -1082,12 +1082,6 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = gsub(g, n.sons[1]) else: put(g, tkIterator, "iterator") - of nkSharedTy: - if sonsLen(n) > 0: - putWithSpace(g, tkShared, "shared") - gsub(g, n.sons[0]) - else: - put(g, tkShared, "shared") of nkStaticTy: put(g, tkStatic, "static") put(g, tkBracketLe, "[") diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 5e391cc93..384bdc8a3 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1277,6 +1277,15 @@ proc processMagicType(c: PContext, m: PSym) = setMagicType(m, tyOrdinal, 0) rawAddSon(m.typ, newTypeS(tyNone, c)) of mPNimrodNode: discard + of mShared: + setMagicType(m, tyObject, 0) + m.typ.n = newNodeI(nkRecList, m.info) + incl m.typ.flags, tfShared + of mGuarded: + setMagicType(m, tyObject, 0) + m.typ.n = newNodeI(nkRecList, m.info) + incl m.typ.flags, tfShared + rawAddSon(m.typ, sysTypeFromName"shared") else: localError(m.info, errTypeExpected) proc semGenericConstraints(c: PContext, x: PType): PType = diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 4a8a463f5..8b9b7b13b 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -14,11 +14,22 @@ import ast, astalgo, msgs, types, magicsys, semdata, renderer const tfInstClearedFlags = {tfHasMeta} +proc sharedPtrCheck(info: TLineInfo, t: PType) = + if t.kind == tyPtr and t.len > 1: + if t.sons[0].sym.magic in {mShared, mGuarded}: + incl(t.flags, tfShared) + if t.sons[0].sym.magic == mGuarded: incl(t.flags, tfGuarded) + if tfHasGCedMem in t.flags: + localError(info, errGenerated, + "shared memory may not refer to GC'ed thread local memory") + proc checkPartialConstructedType(info: TLineInfo, t: PType) = if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject: localError(info, errInvalidPragmaX, "acyclic") elif t.kind == tyVar and t.sons[0].kind == tyVar: localError(info, errVarVarTypeNotAllowed) + else: + sharedPtrCheck(info, t) proc checkConstructedType*(info: TLineInfo, typ: PType) = var t = typ.skipTypes({tyDistinct}) @@ -29,7 +40,8 @@ proc checkConstructedType*(info: TLineInfo, typ: PType) = localError(info, errVarVarTypeNotAllowed) elif computeSize(t) == szIllegalRecursion: localError(info, errIllegalRecursionInTypeX, typeToString(t)) - + else: + sharedPtrCheck(info, t) when false: if t.kind == tyObject and t.sons[0] != nil: if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index 9fdb3bac6..47ce89789 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -30,7 +30,7 @@ type wInclude, wInterface, wIs, wIsnot, wIterator, wLambda, wLet, wMacro, wMethod, wMixin, wMod, wNil, wNot, wNotin, wObject, wOf, wOr, wOut, wProc, wPtr, wRaise, wRef, wReturn, - wShared, wShl, wShr, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar, + wShl, wShr, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar, wWhen, wWhile, wWith, wWithout, wXor, wYield, wColon, wColonColon, wEquals, wDot, wDotDot, @@ -110,7 +110,7 @@ const "macro", "method", "mixin", "mod", "nil", "not", "notin", "object", "of", "or", "out", "proc", "ptr", "raise", "ref", "return", - "shared", "shl", "shr", "static", + "shl", "shr", "static", "template", "try", "tuple", "type", "using", "var", "when", "while", "with", "without", "xor", "yield", |