compiler finally supports 'object {.pragma.}' syntax

This commit is contained in:
Araq
2012-04-16 23:40:08 +02:00
parent d4c2f2509c
commit cb79bf9f16
4 changed files with 25 additions and 4 deletions

View File

@@ -528,7 +528,7 @@ proc typeSectionLeftSidePass(c: PContext, n: PNode) =
s.typ = newTypeS(tyForward, c)
s.typ.sym = s # process pragmas:
if a.sons[0].kind == nkPragmaExpr:
pragma(c, s, a.sons[0].sons[1], typePragmas)
pragma(c, s, a.sons[0].sons[1], typePragmas)
# add it here, so that recursive types are possible:
addInterfaceDecl(c, s)
a.sons[0] = newSymNode(s)

View File

@@ -476,6 +476,11 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
addSon(result, base)
result.n = newNodeI(nkRecList, n.info)
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym)
if n.sons[0].kind != nkEmpty:
# dummy symbol for `pragma`:
var s = newSymS(skType, newIdentNode(getIdent("dummy"), n.info), c)
s.typ = result
pragma(c, s, n.sons[0], typePragmas)
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
if kind == skMacro and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}:

16
tests/run/tfinalobj.nim Normal file
View File

@@ -0,0 +1,16 @@
discard """
outp: "abc"
"""
type
TA = object {.pure, final.}
x: string
var
a: TA
a.x = "abc"
doAssert TA.sizeof == string.sizeof
echo a.x

View File

@@ -10,7 +10,9 @@ version 0.9.0
- deactivate lambda lifting for JS backend
- Test capture of for loop vars; test generics;
- test constant closures
- implement closures that support nesting > 1
- document and fix 'do' notation
- dead code elim for JS backend; 'of' operator for JS backend
- unsigned ints and bignums; requires abstract integer literal type:
use tyInt+node for that
@@ -21,7 +23,6 @@ version 0.9.0
- we need to support iteration of 2 different data structures in parallel
- make exceptions compatible with C++ exceptions
- change how comments are part of the AST
- activate more thread tests
- rethink the syntax: distinction between expr and stmt is unfortunate;
indentation handling is quite complex too; problem with exception handling
is that often the scope of ``try`` is wrong and apart from that ``try`` is
@@ -43,7 +44,6 @@ Bugs
- bug: stress testing basic method example (eval example)
without ``-d:release`` leaks memory?
- bug: object {.pure, final.} does not work again!
- bug: pragma statements in combination with symbol files are evaluated twice
but this can lead to compilation errors
@@ -126,8 +126,8 @@ Low priority
- warning for implicit openArray -> varargs conversion
- implement explicit varargs; **but** ``len(varargs)`` problem remains!
--> solve by implicit conversion from varargs to openarray
- implement closures that support nesting > 1
- optimize method dispatchers
- activate more thread tests
- implement ``--script:sh|bat`` command line option; think about script
generation