summary refs log tree commit diff stats
path: root/compiler/semexprs.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-05-23 08:57:16 +0200
committerAraq <rumpf_a@web.de>2014-05-23 08:57:16 +0200
commitd2dbcf2fa44aa76c6c7ed2c07641560640e6bc6b (patch)
tree86ce8b05f9f73fa637f1c43cbd68aed6a4087a24 /compiler/semexprs.nim
parent417b9f5a1d13f26842b1337395a0f5b57827cc12 (diff)
downloadNim-d2dbcf2fa44aa76c6c7ed2c07641560640e6bc6b.tar.gz
progress with futures
Diffstat (limited to 'compiler/semexprs.nim')
-rw-r--r--compiler/semexprs.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 505c289ea..4e3d2f3ce 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1579,6 +1579,12 @@ proc semShallowCopy(c: PContext, n: PNode, flags: TExprFlags): PNode =
   else:
     result = semDirectOp(c, n, flags)
 
+proc createFuture(c: PContext; t: PType; info: TLineInfo): PType =
+  result = newType(tyGenericInvokation, c.module)
+  addSonSkipIntLit(result, magicsys.getCompilerProc("Future").typ)
+  addSonSkipIntLit(result, t)
+  result = instGenericContainer(c, info, result, allowMetaTypes = false)
+
 proc setMs(n: PNode, s: PSym): PNode = 
   result = n
   n.sons[0] = newSymNode(s)
@@ -1610,6 +1616,12 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
     var x = n.lastSon
     if x.kind == nkDo: x = x.sons[bodyPos]
     result.sons[1] = semStmt(c, x)
+  of mSpawn:
+    result = setMs(n, s)
+    result.sons[1] = semExpr(c, n.sons[1])
+    # later passes may transform the type 'Future[T]' back into 'T'
+    if not result[1].typ.isEmptyType:
+      result.typ = createFuture(c, result[1].typ, n.info)
   else: result = semDirectOp(c, n, flags)
 
 proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =