summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-04-16 23:40:08 +0200
committerAraq <rumpf_a@web.de>2012-04-16 23:40:08 +0200
commitcb79bf9f163225680969875d95f78d5f4aac44c0 (patch)
treea82c046f0a3969c436b8211285d0b4d088b603f4
parentd4c2f2509c4ce94929ba9b75c16cf34f982da365 (diff)
downloadNim-cb79bf9f163225680969875d95f78d5f4aac44c0.tar.gz
compiler finally supports 'object {.pragma.}' syntax
-rwxr-xr-xcompiler/semstmts.nim2
-rwxr-xr-xcompiler/semtypes.nim5
-rw-r--r--tests/run/tfinalobj.nim16
-rwxr-xr-xtodo.txt6
4 files changed, 25 insertions, 4 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 9e879ad0b..6b79326fe 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -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)
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 5626da6f9..b9bab5da6 100755
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -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}:
diff --git a/tests/run/tfinalobj.nim b/tests/run/tfinalobj.nim
new file mode 100644
index 000000000..b559980d6
--- /dev/null
+++ b/tests/run/tfinalobj.nim
@@ -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
+
diff --git a/todo.txt b/todo.txt
index 0a17d94e8..5cd7fa2b0 100755
--- a/todo.txt
+++ b/todo.txt
@@ -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