summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-06-11 01:05:14 +0300
committerAndreas Rumpf <rumpf_a@web.de>2017-06-20 11:29:42 +0200
commit24966e006a56e25fc1cb5c03d1d8ac12dc69d557 (patch)
tree472fd81528b9fa5447eabf005779327998237ffb
parent36c4f0a89c675ee7c03a265287bde03166b2686b (diff)
downloadNim-24966e006a56e25fc1cb5c03d1d8ac12dc69d557.tar.gz
fix #1082
-rw-r--r--compiler/semfold.nim6
-rw-r--r--tests/metatype/tmatrix4.nim39
-rw-r--r--tests/overload/tstaticoverload.nim2
3 files changed, 44 insertions, 3 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 0aceaac4c..84cb0071f 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -637,9 +637,11 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
         result = newSymNodeTypeDesc(s, n.info)
     of skGenericParam:
       if s.typ.kind == tyStatic:
-        if s.typ.n != nil:
+        if s.typ.n != nil and tfUnresolved notin s.typ.flags:
           result = s.typ.n
-          result.typ = s.typ.sons[0]
+          result.typ = s.typ.base
+      elif s.typ.isIntLit:
+        result = s.typ.n
       else:
         result = newSymNodeTypeDesc(s, n.info)
     else: discard
diff --git a/tests/metatype/tmatrix4.nim b/tests/metatype/tmatrix4.nim
new file mode 100644
index 000000000..207d76fed
--- /dev/null
+++ b/tests/metatype/tmatrix4.nim
@@ -0,0 +1,39 @@
+import math
+
+type
+  TMatrix*[T; R, C: static[int]] = array[R, array[C, T]] ## Row major matrix type.
+  TMat4* = TMatrix[float32, 4, 4]
+  TVector*[T; C: static[int]] = array[C, T]
+  TVec4* = TVector[float32, 4]
+
+template row*[T; R, C: static[int]](m: TMatrix[T, R, C], rowidx: range[0..R-1]): TVector[T, R] =
+  m[rowidx]
+
+proc col*[T; R, C: static[int]](m: TMatrix[T, R, C], colidx: range[0..C-1]): TVector[T, C] {.noSideEffect.} =
+  for i in low(m)..high(m):
+    result[i] = m[i][colidx]
+
+proc dot(lhs, rhs: TVector): float32 =
+  for i in low(rhs)..high(rhs):
+    result += lhs[i] * rhs[i]
+
+proc `*`*[T; R, N, C: static[int]](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] {.noSideEffect.} =
+  for i in low(a)..high(a):
+    for j in low(a[i])..high(a[i]):
+      result[i][j] = dot(a.row(i), b.col(j))
+
+proc translate*(v: TVec4): TMat4 {.noSideEffect.} =
+  result = [[1f32, 0f32, 0f32, 0f32],
+            [0f32, 1f32, 0f32, 0f32],
+            [0f32, 0f32, 1f32, 0f32],
+            [v[0], v[1], v[2], 1f32]]
+
+proc rotatex*(angle: float): TMat4 =
+  result = [[1f32,          0f32,           0f32,           0f32],
+            [0f32, cos(angle).float32, sin(angle).float32,  0f32],
+            [0f32, -sin(angle).float32, cos(angle).float32, 0f32],
+            [0f32,          0f32,           0f32,           1f32]]
+
+proc orbitxAround(point: TVec4, angle: float): TMat4 =
+  result = translate(point)*rotatex(angle)*translate(point)
+
diff --git a/tests/overload/tstaticoverload.nim b/tests/overload/tstaticoverload.nim
index 965ff054f..33ca49e56 100644
--- a/tests/overload/tstaticoverload.nim
+++ b/tests/overload/tstaticoverload.nim
@@ -16,7 +16,7 @@ proc foo(s: static[string]) =
   echo "static: ", s
 
 let l = "let"
-let v = "var"
+var v = "var"
 const c = "const"
 
 type staticString = static[string]