new concurrency model: first steps; shared is not a keyword anymore

This commit is contained in:
Araq
2014-04-14 08:45:43 +02:00
parent 817337af30
commit b961e47bfe
13 changed files with 67 additions and 22 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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",

View File

@@ -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)

View File

@@ -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, "[")

View File

@@ -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 =

View File

@@ -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:

View File

@@ -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",

View File

@@ -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

View File

@@ -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]

View File

@@ -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`
##

View File

@@ -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

View File

@@ -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>