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)))]), )
def test_declare_wrong_type(self) -> None: with self.assertRaises(pt.TypeCheckError): pt.Program("module").add_func( "foo", (), pt.Int32_t, pt.Block([ pt.DefineVar(z, pt.Int32(2)), pt.Return(pt.Int32(2)), ]), ) with self.assertRaises(pt.TypeCheckError): pt.Program("module").add_func( "foo", (), pt.Int32_t, pt.Block([ pt.DefineVar(x, pt.Int8(2)), pt.Return(pt.Int32(2)), ]), )
a = pt.Symbol(pt.Int8_t, "a") b = pt.Symbol(pt.Int8_t, "b") c = pt.Symbol(pt.Int8_t, "c") d = pt.Symbol(pt.Int8_t, "d") e = pt.Symbol(pt.Int8_t, "e") f = pt.Symbol(pt.Int8_t, "f") g = pt.Symbol(pt.Int8_t, "g") h = pt.Symbol(pt.Int8_t, "h") i = pt.Symbol(pt.Int8_t, "i") program.add_func( "add_i8", (), pt.Int8_t, pt.Block([ pt.DefineVar(a, pt.Add(pt.Int8(-11), pt.Int8(-4))), pt.DefineVar(b, pt.Add(pt.Int8(-11), pt.Int8(0))), pt.DefineVar(c, pt.Add(pt.Int8(-11), pt.Int8(7))), pt.DefineVar(d, pt.Add(pt.Int8(0), pt.Int8(-5))), pt.DefineVar(e, pt.Add(pt.Int8(0), pt.Int8(0))), pt.DefineVar(f, pt.Add(pt.Int8(0), pt.Int8(3))), pt.DefineVar(g, pt.Add(pt.Int8(7), pt.Int8(-8))), pt.DefineVar(h, pt.Add(pt.Int8(7), pt.Int8(0))), pt.DefineVar(i, pt.Add(pt.Int8(7), pt.Int8(8))), pt.Return( pt.Add( pt.Var(a), pt.Add( pt.Var(b), pt.Add( pt.Var(c),
def test_above_bounds_i8(self) -> None: with self.assertRaises(pt.ValidateError): pt.Int8(128)
def test_below_bounds_i8(self) -> None: with self.assertRaises(pt.ValidateError): pt.Int8(-129)
from typing import cast, Callable import petra as pt import unittest from ctypes import CFUNCTYPE, c_int8, c_int16, c_int32, c_int64 program = pt.Program("module") # 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))]))