File: viper_error.py

package info (click to toggle)
giac 1.9.0.93%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 117,732 kB
  • sloc: cpp: 404,272; ansic: 205,462; python: 30,548; javascript: 28,788; makefile: 17,997; yacc: 2,690; lex: 2,464; sh: 705; perl: 314; lisp: 216; asm: 62; java: 41; xml: 36; sed: 16; csh: 7; pascal: 6
file content (78 lines) | stat: -rw-r--r-- 1,912 bytes parent folder | download | duplicates (3)
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
# test syntax and type errors specific to viper code generation

def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))

# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")
test("@micropython.viper\ndef f() -> 1: pass")

# unknown type
test("@micropython.viper\ndef f(x:unknown_type): pass")

# local used before type known
test("""
@micropython.viper
def f():
    print(x)
    x = 1
""")

# type mismatch storing to local
test("""
@micropython.viper
def f():
    x = 1
    y = []
    x = y
""")

# can't implicitly convert type to bool
test("""
@micropython.viper
def f():
    x = ptr(0)
    if x:
        pass
""")

# incorrect return type
test("@micropython.viper\ndef f() -> int: return []")

# can't do binary op between incompatible types
test("@micropython.viper\ndef f(): 1 + []")

# can't load
test("@micropython.viper\ndef f(): 1[0]")
test("@micropython.viper\ndef f(): 1[x]")

# can't store
test("@micropython.viper\ndef f(): 1[0] = 1")
test("@micropython.viper\ndef f(): 1[x] = 1")
test("@micropython.viper\ndef f(x:int): x[0] = x")
test("@micropython.viper\ndef f(x:ptr32): x[0] = None")
test("@micropython.viper\ndef f(x:ptr32): x[x] = None")

# must raise an object
test("@micropython.viper\ndef f(): raise 1")

# unary ops not implemented
test("@micropython.viper\ndef f(x:int): +x")
test("@micropython.viper\ndef f(x:int): -x")
test("@micropython.viper\ndef f(x:int): ~x")

# binary op not implemented
test("@micropython.viper\ndef f(x:int): res = x in x")

# yield (from) not implemented
test("@micropython.viper\ndef f(): yield")
test("@micropython.viper\ndef f(): yield from f")

# passing a ptr to a Python function not implemented
test("@micropython.viper\ndef f(): print(ptr(1))")

# cast of a casting identifier not implemented
test("@micropython.viper\ndef f(): int(int)")