From 2f066395baf0dd290bfdbb8ee47a64a17c932b14 Mon Sep 17 00:00:00 2001
From: Araq <rumpf_a@web.de>
Date: Thu, 28 Jul 2011 00:53:52 +0200
Subject: bugfixes; step one for 'var T' as return type support

---
 tests/accept/run/teventemitter.nim | 23 +++++++++++++++++++++++
 tests/accept/run/tvarres1.nim      | 15 +++++++++++++++
 tests/accept/run/tvarres2.nim      | 20 ++++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 tests/accept/run/teventemitter.nim
 create mode 100644 tests/accept/run/tvarres1.nim
 create mode 100644 tests/accept/run/tvarres2.nim

(limited to 'tests/accept')

diff --git a/tests/accept/run/teventemitter.nim b/tests/accept/run/teventemitter.nim
new file mode 100644
index 000000000..6ebe994b1
--- /dev/null
+++ b/tests/accept/run/teventemitter.nim
@@ -0,0 +1,23 @@
+import tables
+import lists
+type
+    TEventArgs = object of TObject
+type
+    TEventEmitter = object of TObject
+        events*: TTable[string, TDoublyLinkedList[proc(e : TEventArgs)]]
+proc on*(emitter : var TEventEmitter, event : string, func : proc(e : TEventArgs)) =
+    if hasKey(emitter.events, event) == false:
+        var list: TDoublyLinkedList[proc(e : TEventArgs)]
+        add(emitter.events,event,list) #if not, add it.
+    append(emitter.events[event], func) #adds the function to the event's list. I get a error here too.
+        
+proc emit*(emitter : TEventEmitter, event : string, args : TEventArgs) =
+    for func in items(emitter.events[event]):
+        func(args) #call function with args.
+proc initEmitter(emitter : TEventEmitter) =
+     emitter.events = initTable[string, TSinglyLinkedList[TObject]]()
+
+var ee : TEventEmitter
+ee.on("print", proc(e : TEventArgs) = echo("pie"))
+ee.emit("print")
+
diff --git a/tests/accept/run/tvarres1.nim b/tests/accept/run/tvarres1.nim
new file mode 100644
index 000000000..a48c961df
--- /dev/null
+++ b/tests/accept/run/tvarres1.nim
@@ -0,0 +1,15 @@
+discard """
+  output: "45"
+"""
+
+var
+  g = 5
+
+proc p(): var int = 
+  var bla = addr(g) #: array [0..7, int]
+  result = bla[]
+  
+p() = 45
+
+echo g
+
diff --git a/tests/accept/run/tvarres2.nim b/tests/accept/run/tvarres2.nim
new file mode 100644
index 000000000..119560e7b
--- /dev/null
+++ b/tests/accept/run/tvarres2.nim
@@ -0,0 +1,20 @@
+discard """
+  output: "45 hallo"
+"""
+
+type
+  TKachel = tuple[i: int, s: string]
+  TSpielwiese = object
+    k: seq[TKachel]
+
+var
+  spielwiese: TSpielwiese
+newSeq(spielwiese.k, 64)
+
+proc at*(s: var TSpielwiese, x, y: int): var TKachel =
+  result = s.k[y * 8 + x]
+
+spielwiese.at(3, 4) = (45, "hallo")
+
+echo spielwiese.at(3,4)[0], " ", spielwiese.at(3,4)[1]
+
-- 
cgit 1.4.1-2-gfad0