summary refs log tree commit diff stats
path: root/tests/run/toprprec.nim
blob: ce33934b577988e15f39139101c3861c429844b5 (plain) (blame)
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
discard """
  file: "toprprec.nim"
  output: "done"
"""
# Test operator precedence: 

template `@` (x: expr): expr {.immediate.} = self.x
template `@!` (x: expr): expr {.immediate.} = x
template `===` (x: expr): expr {.immediate.} = x

type
  TO = object
    x: int
  TA = tuple[a, b: int, obj: TO]
  
proc init(self: var TA): string =
  @a = 3
  === @b = 4
  @obj.x = 4
  @! === result = "abc"
  result = @b.`$`

assert 3+5*5-2 == 28- -26-28

proc `^-` (x, y: int): int =  
  # now right-associative!
  result = x - y
  
assert 34 ^- 6 ^- 2 == 30
assert 34 - 6 - 2 == 26


var s: TA
assert init(s) == "4"

echo "done"