summary refs log tree commit diff stats
path: root/tests/vm
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm')
-rw-r--r--tests/vm/tarrayboundeval.nim4
-rw-r--r--tests/vm/tasmparser.nim12
-rw-r--r--tests/vm/tconsteval.nim2
-rw-r--r--tests/vm/tconstobj.nim36
-rw-r--r--tests/vm/tconsttable2.nim81
-rw-r--r--tests/vm/teval1.nim2
-rw-r--r--tests/vm/tforwardproc.nim17
-rw-r--r--tests/vm/tldconst.nim2
-rw-r--r--tests/vm/trgba.nim26
-rw-r--r--tests/vm/tsimpleglobals.nim16
-rw-r--r--tests/vm/tslurp.nim12
-rw-r--r--tests/vm/tstaticprintseq.nim12
-rw-r--r--tests/vm/tswap.nim24
-rw-r--r--tests/vm/twrongconst.nim2
-rw-r--r--tests/vm/tyaytypedesc.nim21
15 files changed, 240 insertions, 29 deletions
diff --git a/tests/vm/tarrayboundeval.nim b/tests/vm/tarrayboundeval.nim
index 07aac4c4e..af9e33339 100644
--- a/tests/vm/tarrayboundeval.nim
+++ b/tests/vm/tarrayboundeval.nim
@@ -15,12 +15,12 @@ type
 
 echo FU.high
 
-type 
+type
   PKeyboard* = ptr object
   TKeyboardState* = object
     display*: pointer
     internal: array[int((KeyMax + 31)/32), cuint]
-    
+
 echo myconst, " ", int((KeyMax + 31) / 32)
 
 #bug 1304 or something:
diff --git a/tests/vm/tasmparser.nim b/tests/vm/tasmparser.nim
index 67313c858..fbacdbc87 100644
--- a/tests/vm/tasmparser.nim
+++ b/tests/vm/tasmparser.nim
@@ -79,23 +79,23 @@ proc asmx64 () {.compileTime} =
 
     case state:
     of leading:
-      
+
       echo "b100 ", start
       start += code.skipWhile (leadingWhiteSpace, start)
       echo "b200 ", start
       let ch = code [start]
       if ch in endOfLine:
         inc (line)
-        #echo "c100 ", start, ' ', code 
+        #echo "c100 ", start, ' ', code
         start += code.skipWhile (endOfline, start)
-        #echo "c200 ", start, ' ', code 
+        #echo "c200 ", start, ' ', code
         continue
       elif ch in symbolStart:
         state = mnemonic
       elif ch in eolComment:
         state = skipToEndOfLine
       elif ch in passthrough_start:
-        get_passthrough ()        
+        get_passthrough ()
         echo "d100 ", start
         start += code.parseUntil (token, end_or_symbol_or_comment_or_passthrough, start)
         echo "d200 ", start
@@ -124,7 +124,7 @@ proc asmx64 () {.compileTime} =
       if codeLen <= start:
         state = endCmd
         continue
-        
+
       let ch = code [start]
       if ch in passthrough_start:
         get_passthrough ()
@@ -148,7 +148,7 @@ proc asmx64 () {.compileTime} =
     of endCmd:
       cpp.add ");\n"
       state = skipToEndOfLine
-    
+
     of skipToEndOfLine:
       echo "a100 ", start
       start += code.skipUntil (endOfLine, start)
diff --git a/tests/vm/tconsteval.nim b/tests/vm/tconsteval.nim
index 4459931c5..f4260495a 100644
--- a/tests/vm/tconsteval.nim
+++ b/tests/vm/tconsteval.nim
@@ -24,7 +24,7 @@ Possible Commands:
   csource [options]        builds the C sources for installation
   zip                      builds the installation ZIP package
   inno                     builds the Inno Setup installer
-""" % [NimVersion & spaces(44-len(NimVersion)), 
+""" % [NimVersion & spaces(44-len(NimVersion)),
        CompileDate, CompileTime]
 
 echo HelpText
diff --git a/tests/vm/tconstobj.nim b/tests/vm/tconstobj.nim
new file mode 100644
index 000000000..51f30fb78
--- /dev/null
+++ b/tests/vm/tconstobj.nim
@@ -0,0 +1,36 @@
+discard """
+  output: '''(name: hello)
+(-1, 0)'''
+"""
+
+# bug #2774, bug #3195
+
+type Foo = object
+  name: string
+
+const fooArray = [
+  Foo(name: "hello")
+]
+
+echo fooArray[0]
+
+
+type
+    Position = object
+        x, y: int
+
+proc `$`(pos: Position): string =
+    result = "(" & $pos.x & ", " & $pos.y & ")"
+
+proc newPos(x, y: int): Position =
+    result = Position(x: x, y: y)
+
+const
+     offset: array[1..4, Position] = [
+         newPos(-1, 0),
+         newPos(1, 0),
+         newPos(0, -1),
+         newPos(0, 1)
+     ]
+
+echo offset[1]
diff --git a/tests/vm/tconsttable2.nim b/tests/vm/tconsttable2.nim
new file mode 100644
index 000000000..e07734eb5
--- /dev/null
+++ b/tests/vm/tconsttable2.nim
@@ -0,0 +1,81 @@
+discard """
+  msg: '''61'''
+"""
+
+# bug #2297
+
+import tables
+
+proc html5tags*(): TableRef[string, string] =
+  var html5tagsCache: Table[string,string]
+  if true:
+    new(result)
+    html5tagsCache = initTable[string, string]()
+    html5tagsCache["a"] = "a"
+    html5tagsCache["abbr"] = "abbr"
+    html5tagsCache["b"] = "b"
+    html5tagsCache["element"] = "element"
+    html5tagsCache["embed"] = "embed"
+    html5tagsCache["fieldset"] = "fieldset"
+    html5tagsCache["figcaption"] = "figcaption"
+    html5tagsCache["figure"] = "figure"
+    html5tagsCache["footer"] = "footer"
+    html5tagsCache["header"] = "header"
+    html5tagsCache["form"] = "form"
+    html5tagsCache["head"] = "head"
+    html5tagsCache["hr"] = "hr"
+    html5tagsCache["html"] = "html"
+    html5tagsCache["iframe"] = "iframe"
+    html5tagsCache["img"] = "img"
+    html5tagsCache["input"] = "input"
+    html5tagsCache["keygen"] = "keygen"
+    html5tagsCache["label"] = "label"
+    html5tagsCache["legend"] = "legend"
+    html5tagsCache["li"] = "li"
+    html5tagsCache["link"] = "link"
+    html5tagsCache["main"] = "main"
+    html5tagsCache["map"] = "map"
+    html5tagsCache["menu"] = "menu"
+    html5tagsCache["menuitem"] = "menuitem"
+    html5tagsCache["meta"] = "meta"
+    html5tagsCache["meter"] = "master"
+    html5tagsCache["noscript"] = "noscript"
+    html5tagsCache["object"] = "object"
+    html5tagsCache["ol"] = "ol"
+    html5tagsCache["optgroup"] = "optgroup"
+    html5tagsCache["option"] = "option"
+    html5tagsCache["output"] = "output"
+    html5tagsCache["p"] = "p"
+    html5tagsCache["pre"] = "pre"
+    html5tagsCache["param"] = "param"
+    html5tagsCache["progress"] = "progress"
+    html5tagsCache["q"] = "q"
+    html5tagsCache["rp"] = "rp"
+    html5tagsCache["rt"] = "rt"
+    html5tagsCache["ruby"] = "ruby"
+    html5tagsCache["s"] = "s"
+    html5tagsCache["script"] = "script"
+    html5tagsCache["select"] = "select"
+    html5tagsCache["source"] = "source"
+    html5tagsCache["style"] = "style"
+    html5tagsCache["summary"] = "summary"
+    html5tagsCache["table"] = "table"
+    html5tagsCache["tbody"] = "tbody"
+    html5tagsCache["thead"] = "thead"
+    html5tagsCache["td"] = "td"
+    html5tagsCache["th"] = "th"
+    html5tagsCache["template"] = "template"
+    html5tagsCache["textarea"] = "textarea"
+    html5tagsCache["time"] = "time"
+    html5tagsCache["title"] = "title"
+    html5tagsCache["tr"] = "tr"
+    html5tagsCache["track"] = "track"
+    html5tagsCache["ul"] = "ul"
+    html5tagsCache["video"] = "video"
+  result[] = html5tagsCache
+
+static:
+  var i = 0
+  for key, value in html5tags().pairs():
+    inc i
+  echo i
diff --git a/tests/vm/teval1.nim b/tests/vm/teval1.nim
index cdb4ad8e2..1d3a68a0d 100644
--- a/tests/vm/teval1.nim
+++ b/tests/vm/teval1.nim
@@ -13,7 +13,7 @@ when true:
 
 const
   x = testProc()
-  
+
 echo "##", x, "##"
 
 # bug #1310
diff --git a/tests/vm/tforwardproc.nim b/tests/vm/tforwardproc.nim
new file mode 100644
index 000000000..727ac6641
--- /dev/null
+++ b/tests/vm/tforwardproc.nim
@@ -0,0 +1,17 @@
+discard """
+  errormsg: "cannot evaluate at compile time: initArray"
+  line: 11
+"""
+
+# bug #3066
+
+proc initArray(): array[10, int]
+
+const
+  someTable = initArray()
+
+proc initArray(): array[10, int] =
+  for f in 0..<10:
+    result[f] = 3
+
+when isMainModule: echo repr(someTable)
diff --git a/tests/vm/tldconst.nim b/tests/vm/tldconst.nim
index 9eabb7525..7df3143c9 100644
--- a/tests/vm/tldconst.nim
+++ b/tests/vm/tldconst.nim
@@ -11,4 +11,4 @@ proc foobar(): int =
         discard
     0
 
-const x = foobar()
\ No newline at end of file
+const x = foobar()
diff --git a/tests/vm/trgba.nim b/tests/vm/trgba.nim
index 22eec4d6e..da1a2d0c5 100644
--- a/tests/vm/trgba.nim
+++ b/tests/vm/trgba.nim
@@ -8,19 +8,19 @@ discard """
 type
   TAggRgba8* = array[4, byte]
 
-template R*(self: TAggRgba8): byte = self[0]   
-template G*(self: TAggRgba8): byte = self[1]   
-template B*(self: TAggRgba8): byte = self[2]   
-template A*(self: TAggRgba8): byte = self[3]   
+template R*(self: TAggRgba8): byte = self[0]
+template G*(self: TAggRgba8): byte = self[1]
+template B*(self: TAggRgba8): byte = self[2]
+template A*(self: TAggRgba8): byte = self[3]
 
-template `R=`*(self: TAggRgba8, val: byte) = 
-  self[0] = val   
-template `G=`*(self: TAggRgba8, val: byte) =   
-  self[1] = val   
-template `B=`*(self: TAggRgba8, val: byte) =   
-  self[2] = val   
-template `A=`*(self: TAggRgba8, val: byte) =   
-  self[3] = val   
+template `R=`*(self: TAggRgba8, val: byte) =
+  self[0] = val
+template `G=`*(self: TAggRgba8, val: byte) =
+  self[1] = val
+template `B=`*(self: TAggRgba8, val: byte) =
+  self[2] = val
+template `A=`*(self: TAggRgba8, val: byte) =
+  self[3] = val
 
 proc ABGR* (val: int| int64): TAggRgba8 =
   var V = val
@@ -32,5 +32,5 @@ proc ABGR* (val: int| int64): TAggRgba8 =
   result.A = (V shr 8) and 0xFF
 
 const
-  c1 = ABGR(0xFF007F7F) 
+  c1 = ABGR(0xFF007F7F)
 echo ABGR(0xFF007F7F).repr, c1.repr
diff --git a/tests/vm/tsimpleglobals.nim b/tests/vm/tsimpleglobals.nim
new file mode 100644
index 000000000..27bfdce50
--- /dev/null
+++ b/tests/vm/tsimpleglobals.nim
@@ -0,0 +1,16 @@
+discard """
+  msg: "abc xyz bb"
+"""
+
+# bug #2473
+type
+  Test = tuple[a,b: string]
+
+static:
+  var s:seq[Test] = @[(a:"a", b:"b")]
+  s[0] = (a:"aa", b:"bb")
+
+  var x: Test
+  x.a = "abc"
+  x.b = "xyz"
+  echo x.a, " ", x.b, " ", s[0].b
diff --git a/tests/vm/tslurp.nim b/tests/vm/tslurp.nim
index f9456ce6b..027db45d6 100644
--- a/tests/vm/tslurp.nim
+++ b/tests/vm/tslurp.nim
@@ -1,6 +1,12 @@
+import os
+
+template getScriptDir(): string =
+  parentDir(instantiationInfo(-1, true).filename)
 
 const
-  myRes = slurp"../../readme.txt"
-  
-echo myRes
+  relRes = slurp"../../readme.txt"
+  absRes = slurp(parentDir(parentDir(getScriptDir())) / "readme.txt")
+
+echo relRes
+echo absRes
 
diff --git a/tests/vm/tstaticprintseq.nim b/tests/vm/tstaticprintseq.nim
index b002d366c..e4a6aa081 100644
--- a/tests/vm/tstaticprintseq.nim
+++ b/tests/vm/tstaticprintseq.nim
@@ -18,7 +18,8 @@ bb
 aa
 bb
 24
-2147483647 2147483647'''
+2147483647 2147483647
+5'''
 """
 
 const s = @[1,2,3]
@@ -80,3 +81,12 @@ static:
 static:
   var foo2 = int32.high
   echo foo2, " ", int32.high
+
+# bug #1329
+
+static:
+    var a: ref int
+    new(a)
+    a[] = 5
+
+    echo a[]
diff --git a/tests/vm/tswap.nim b/tests/vm/tswap.nim
new file mode 100644
index 000000000..2219be9ca
--- /dev/null
+++ b/tests/vm/tswap.nim
@@ -0,0 +1,24 @@
+discard """
+msg: '''
+x.data = @[10]
+y = @[11]
+x.data = @[11]
+y = @[10]'''
+"""
+
+# bug #2946
+
+proc testSwap(): int {.compiletime.} =
+  type T = object
+    data: seq[int]
+  var x: T
+  x.data = @[10]
+  var y = @[11]
+  echo "x.data = ", x.data
+  echo "y = ", y
+  swap(y, x.data)
+  echo "x.data = ", x.data
+  echo "y = ", y
+  result = 99
+
+const something = testSwap()
diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim
index 68ab2757c..424ed080e 100644
--- a/tests/vm/twrongconst.nim
+++ b/tests/vm/twrongconst.nim
@@ -1,6 +1,6 @@
 discard """
   errormsg: "cannot evaluate at compile time: x"
-  line: 9
+  line: 7
 """
 
 var x: array[100, char]
diff --git a/tests/vm/tyaytypedesc.nim b/tests/vm/tyaytypedesc.nim
new file mode 100644
index 000000000..a3ad9b707
--- /dev/null
+++ b/tests/vm/tyaytypedesc.nim
@@ -0,0 +1,21 @@
+discard """
+  output: "ntWhitespace"
+"""
+
+# bug #3357
+
+type NodeType* = enum
+  ntWhitespace
+
+type TokenType* = enum
+  ttWhitespace
+
+proc enumTable*[A, B, C](a: openarray[tuple[key: A, val: B]], ret: typedesc[C]): C =
+  for item in a:
+    result[item.key] = item.val
+
+const tokenTypeToNodeType = {
+  ttWhitespace: ntWhitespace,
+}.enumTable(array[ttWhitespace..ttWhitespace, NodeType])
+
+echo tokenTypeToNodeType[ttWhitespace]