summary refs log tree commit diff stats
path: root/compiler/pathutils.nim
Commit message (Expand)AuthorAgeFilesLines
* successX now correctly shows html output for `nim doc`, `nim jsondoc`; fix #1...Timothee Cour2020-01-151-2/+13
* [refactoring] remove unused imports in the compiler and in some stdlib modulesAraq2019-07-181-1/+1
* Initial version of the hot-code reloading support for native targets (#10729)zah2019-02-261-0/+4
* [pathutils] add AnyPath; add `$`; lift arbitrary API restrictions (#10021)Timothee Cour2018-12-181-8/+11
* os.nim: big refactoring, use the new pathnorm that was extracted by compiler/...Araq2018-12-131-161/+10
* pathutils: remove dead codeAraq2018-11-211-17/+0
* fixes #9507Araq2018-10-251-8/+10
* Allow subpaths of names of length 1Jörg Wollenschläger2018-09-151-1/+1
* nim doc: fixes cross-link generation when --out is usedAraq2018-09-101-1/+1
* 'nim doc': fixes index generation regressionAraq2018-09-081-2/+2
* make tests green againAraq2018-09-071-3/+8
* added a test for 'nim doc'Andreas Rumpf2018-09-071-2/+3
* compiler refactoring; use typesafe path handing; docgen: render symbols betwe...Andreas Rumpf2018-09-071-0/+254
ref='/ahoang/Nim/commit/tests/statictypes/tstatictypes.nim?h=devel&id=a49b06a52a3c24258e9eb04593a2f83ae057755f'>a49b06a52 ^
ab9969ed3 ^
a49b06a52 ^












ab9969ed3 ^


a49b06a52 ^











ab9969ed3 ^
a49b06a52 ^


























ab9969ed3 ^














a49b06a52 ^
ab9969ed3 ^



509d6e923 ^
2c98b4943 ^








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

           







                                     


   
             
 








                                 
                                 
 




                                         
          












                                                  


                                 











                                                        
 


























                                                         














                                                    
 



                             
 








                                                                              
discard """
nimout: '''
staticAlialProc instantiated with 358
staticAlialProc instantiated with 368
'''
output: '''
16
16
b is 2 times a
17
'''
"""

import macros

template ok(x) = assert(x)
template no(x) = assert(not x)

template accept(x) =
  static: assert(compiles(x))

template reject(x) =
  static: assert(not compiles(x))

proc plus(a, b: int): int = a + b

template isStatic(x: static): bool = true
template isStatic(x: auto): bool = false

var v = 1

when true:
  # test that `isStatic` works as expected
  const C = 2

  static:
    ok C.isStatic
    ok isStatic(plus(1, 2))
    ok plus(C, 2).isStatic

    no isStatic(v)
    no plus(1, v).isStatic

when true:
  # test that proc instantiation works as expected
  type
    StaticTypeAlias = static[int]

  proc staticAliasProc(a: StaticTypeAlias,
                       b: static[int],
                       c: static int) =
    static:
      assert a.isStatic and b.isStatic and c.isStatic
      assert isStatic(a + plus(b, c))
      echo "staticAlialProc instantiated with ", a, b, c

    when b mod a == 0:
      echo "b is ", b div a, " times a"

    echo a + b + c

  staticAliasProc 1+2, 5, 8
  staticAliasProc 3, 2+3, 9-1
  staticAliasProc 3, 3+3, 4+4

when true:
  # test static coercions. normal cases that should work:
  accept:
    var s1 = static[int] plus(1, 2)
    var s2 = static(plus(1,2))
    var s3 = static plus(1,2)
    var s4 = static[SomeInteger](1 + 2)

  # the sub-script operator can be used only with types:
  reject:
    var just_static3 = static[plus(1,2)]

  # static coercion takes into account the type:
  reject:
    var x = static[string](plus(1, 2))
  reject:
    var x = static[string] plus(1, 2)
  reject:
    var x = static[SomeFloat] plus(3, 4)

  # you cannot coerce a run-time variable
  reject:
    var x = static(v)

when true:
  type
    ArrayWrapper1[S: static int] = object
      data: array[S + 1, int]

    ArrayWrapper2[S: static[int]] = object
      data: array[S.plus(2), int]

    ArrayWrapper3[S: static[(int, string)]] = object
      data: array[S[0], int]

  var aw1: ArrayWrapper1[5]
  var aw2: ArrayWrapper2[5]
  var aw3: ArrayWrapper3[(10, "str")]

  static:
    assert aw1.data.high == 5
    assert aw2.data.high == 6
    assert aw3.data.high == 9

# #6077
block:
  type
    Backend = enum
      Cpu

    Tensor[B: static[Backend]; T] = object

    BackProp[B: static[Backend],T] = proc (gradient: Tensor[B,T]): Tensor[B,T]