summary refs log tree commit diff stats
path: root/tests/accept/run
diff options
context:
space:
mode:
Diffstat (limited to 'tests/accept/run')
-rw-r--r--tests/accept/run/teventemitter.nim23
-rw-r--r--tests/accept/run/tvarres1.nim15
-rw-r--r--tests/accept/run/tvarres2.nim20
3 files changed, 58 insertions, 0 deletions
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]
+