File: talias.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (67 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (4)
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
# Test the alias analysis

type
  TAnalysisResult* = enum
    arNo, arMaybe, arYes

proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
  magic: "IsPartOf", noSideEffect.}
  ## not yet exported properly.

template compileTimeAssert(cond) =
  when not cond:
    {.compile: "is false: " & astToStr(cond).}

template `<|` (a, b) =
  compileTimeAssert isPartOf(a, b) == arYes

template `!<|` (a, b) =
  compileTimeAssert isPartOf(a, b) == arNo

template `?<|` (a, b) =
  compileTimeAssert isPartOf(a, b) == arMaybe

type
  TA {.inheritable.} = object
  TC = object of TA
    arr: array[0..3, int]
    le, ri: ref TC
    f: string
    c: char
    se: seq[TA]

proc p(param1, param2: TC, param3: var TC): TC =
  var
    local: TC
    plocal: ptr TC
    plocal2: ptr TA

  local.arr <| local
  local.arr[0] <| local
  local.arr[2] !<| local.arr[1]

  plocal2[] ?<| local

  param1 ?<| param2
  local ?<| param3

  local.arr[0] !<| param1
  local.arr !<| param1
  local.le[] ?<| param1

  param1 !<| local.arr[0]
  param1 !<| local.arr
  param1 ?<| local.le[]

  result !<| local
  result <| result

var
  a, b: int
  x: TC

a <| a
a !<| b

discard p(x, x, x)