diff options
-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 | ||||
-rw-r--r-- | doc/keywords.txt | 2 | ||||
-rw-r--r-- | lib/packages/docutils/highlite.nim | 6 | ||||
-rw-r--r-- | lib/system.nim | 10 | ||||
-rw-r--r-- | tests/typerel/tno_gcmem_in_shared.nim | 22 | ||||
-rw-r--r-- | web/ticker.txt | 2 |
13 files changed, 67 insertions, 22 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", diff --git a/doc/keywords.txt b/doc/keywords.txt index 2d18d7969..60b100398 100644 --- a/doc/keywords.txt +++ b/doc/keywords.txt @@ -12,7 +12,7 @@ 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 diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim index c507f5e1c..80fbf3a51 100644 --- a/lib/packages/docutils/highlite.nim +++ b/lib/packages/docutils/highlite.nim @@ -52,7 +52,7 @@ const "finally", "for", "from", "generic", "if", "import", "in", "include", "interface", "is", "isnot", "iterator", "lambda", "let", "macro", "method", "mixin", "mod", "nil", "not", "notin", "object", "of", "or", "out", "proc", - "ptr", "raise", "ref", "return", "shared", "shl", "shr", "static", + "ptr", "raise", "ref", "return", "shl", "shr", "static", "template", "try", "tuple", "type", "using", "var", "when", "while", "with", "without", "xor", "yield"] @@ -61,6 +61,7 @@ proc getSourceLanguage*(name: string): TSourceLanguage = if cmpIgnoreStyle(name, sourceLanguageToStr[i]) == 0: return i result = langNone + proc initGeneralTokenizer*(g: var TGeneralTokenizer, buf: cstring) = g.buf = buf g.kind = low(TTokenClass) @@ -70,6 +71,7 @@ proc initGeneralTokenizer*(g: var TGeneralTokenizer, buf: cstring) = var pos = 0 # skip initial whitespace: while g.buf[pos] in {' ', '\x09'..'\x0D'}: inc(pos) g.pos = pos + proc initGeneralTokenizer*(g: var TGeneralTokenizer, buf: string) = initGeneralTokenizer(g, cstring(buf)) @@ -554,7 +556,7 @@ when isMainModule: let input = string(readFile(filename)) keywords = input.split() break - doAssert (not keywords.isNil, "Couldn't read any keywords.txt file!") + doAssert(not keywords.isNil, "Couldn't read any keywords.txt file!") doAssert keywords.len == nimrodKeywords.len, "No matching lengths" for i in 0..keywords.len-1: #echo keywords[i], " == ", nimrodKeywords[i] diff --git a/lib/system.nim b/lib/system.nim index 3cb6b08d5..dae418b7f 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -77,7 +77,7 @@ type TNumber* = TInteger|TReal ## type class matching all number types - + proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.} ## Special compile-time procedure that checks whether `x` is ## defined. `x` has to be an identifier or a qualified identifier. @@ -188,6 +188,11 @@ when not defined(niminheritable): when not defined(nimunion): {.pragma: unchecked.} +when defined(nimNewShared): + type + `shared`* {.magic: "Shared".} + guarded* {.magic: "Guarded".} + const NoFakeVars* = defined(NimrodVM) ## true if the backend doesn't support \ ## "fake variables" like 'var EBADF {.importc.}: cint'. @@ -784,7 +789,8 @@ proc `is` *[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.} ## assert(test[int](3) == 3) ## assert(test[string]("xyz") == 0) template `isnot` *(x, y: expr): expr {.immediate.} = not (x is y) - ## Negated version of `is`. Equivalent to `not(is(x,y))` + ## Negated version of `is`. Equivalent to ``not(x is y)``. + proc `of` *[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.} ## Checks if `x` has a type of `y` ## diff --git a/tests/typerel/tno_gcmem_in_shared.nim b/tests/typerel/tno_gcmem_in_shared.nim new file mode 100644 index 000000000..8c81e8db6 --- /dev/null +++ b/tests/typerel/tno_gcmem_in_shared.nim @@ -0,0 +1,22 @@ +discard """ + errormsg: "shared memory may not refer to GC'ed thread local memory" + line: 14 +""" + +type + Region = object + Foo = Region ptr int + + MyObject = object + a, b: string + + Bar[T] = shared ptr T + Bzar = Bar[MyObject] + +proc bar(x: Region ptr int) = + discard + +var + s: Foo + +bar s diff --git a/web/ticker.txt b/web/ticker.txt index 716fb90ad..a4ddddbbe 100644 --- a/web/ticker.txt +++ b/web/ticker.txt @@ -1,5 +1,5 @@ <a class="news" href="news.html#Z2014-XX-XX-version-0-9-4-released"> - <h3>April 20, 2014</h3> + <h3>Apr 20, 2014</h3> <p>Nimrod version 0.9.4 has been released!</p> </a> |