Exemplo n.º 1
0
 def test_mismatch_type_mod(self) -> None:
     with self.assertRaises(pt.TypeCheckError):
         pt.Program("module").add_func(
             "foo",
             (),
             pt.Int32_t,
             pt.Block([pt.Return(pt.Mod(pt.Int8(2), pt.Int32(2)))]),
         )
     with self.assertRaises(pt.TypeCheckError):
         pt.Program("module").add_func(
             "foo",
             (),
             pt.Int32_t,
             pt.Block([pt.Return(pt.Mod(pt.Int32(2), pt.Int8(2)))]),
         )
     with self.assertRaises(pt.TypeCheckError):
         pt.Program("module").add_func(
             "foo",
             (),
             pt.Int64_t,
             pt.Block([pt.Return(pt.Mod(pt.Int16(2), pt.Int64(2)))]),
         )
     with self.assertRaises(pt.TypeCheckError):
         pt.Program("module").add_func(
             "foo",
             (),
             pt.Int64_t,
             pt.Block([pt.Return(pt.Mod(pt.Int64(2), pt.Int16(2)))]),
         )
Exemplo n.º 2
0
a16 = pt.Symbol(pt.Int16_t, "a16")
b16 = pt.Symbol(pt.Int16_t, "b16")
c16 = pt.Symbol(pt.Int16_t, "c16")
d16 = pt.Symbol(pt.Int16_t, "d16")
e16 = pt.Symbol(pt.Int16_t, "e16")
f16 = pt.Symbol(pt.Int16_t, "f16")
g16 = pt.Symbol(pt.Int16_t, "g16")
h16 = pt.Symbol(pt.Int16_t, "h16")
i16 = pt.Symbol(pt.Int16_t, "i16")

program.add_func(
    "add_i16",
    (),
    pt.Int16_t,
    pt.Block([
        pt.DefineVar(a16, pt.Add(pt.Int16(-11), pt.Int16(-4))),
        pt.DefineVar(b16, pt.Add(pt.Int16(-11), pt.Int16(0))),
        pt.DefineVar(c16, pt.Add(pt.Int16(-11), pt.Int16(7))),
        pt.DefineVar(d16, pt.Add(pt.Int16(0), pt.Int16(-5))),
        pt.DefineVar(e16, pt.Add(pt.Int16(0), pt.Int16(0))),
        pt.DefineVar(f16, pt.Add(pt.Int16(0), pt.Int16(3))),
        pt.DefineVar(g16, pt.Add(pt.Int16(7), pt.Int16(-8))),
        pt.DefineVar(h16, pt.Add(pt.Int16(7), pt.Int16(0))),
        pt.DefineVar(i16, pt.Add(pt.Int16(7), pt.Int16(8))),
        pt.Return(
            pt.Add(
                pt.Var(a16),
                pt.Add(
                    pt.Var(b16),
                    pt.Add(
                        pt.Var(c16),
Exemplo n.º 3
0
 def test_below_bounds_i16(self) -> None:
     with self.assertRaises(pt.ValidateError):
         pt.Int16(-(2**15) - 1)
Exemplo n.º 4
0
 def test_above_bounds_i16(self) -> None:
     with self.assertRaises(pt.ValidateError):
         pt.Int16(2**15)
Exemplo n.º 5
0
# Int8_t functions.

program.add_func("return_m2_i8", (), pt.Int8_t,
                 pt.Block([pt.Return(pt.Int8(-2))]))

program.add_func("return_0_i8", (), pt.Int8_t,
                 pt.Block([pt.Return(pt.Int8(0))]))

program.add_func("return_2_i8", (), pt.Int8_t,
                 pt.Block([pt.Return(pt.Int8(2))]))

# Int16_t functions.

program.add_func("return_m2_i16", (), pt.Int16_t,
                 pt.Block([pt.Return(pt.Int16(-2))]))

program.add_func("return_0_i16", (), pt.Int16_t,
                 pt.Block([pt.Return(pt.Int16(0))]))

program.add_func("return_2_i16", (), pt.Int16_t,
                 pt.Block([pt.Return(pt.Int16(2))]))

# Int32_t functions.

program.add_func("return_m2_i32", (), pt.Int32_t,
                 pt.Block([pt.Return(pt.Int32(-2))]))

program.add_func("return_0_i32", (), pt.Int32_t,
                 pt.Block([pt.Return(pt.Int32(0))]))