compiler: fix monomorphization of coerced integer literals.

Fixes #703.
This commit is contained in:
whitequark 2017-04-12 04:10:08 +00:00 committed by Sebastien Bourdeauducq
parent 90e2e22765
commit be2683e097
3 changed files with 22 additions and 1 deletions

View File

@ -5,6 +5,7 @@
from collections import OrderedDict from collections import OrderedDict
from pythonparser import algorithm, diagnostic, ast from pythonparser import algorithm, diagnostic, ast
from .. import asttyped, types, builtins from .. import asttyped, types, builtins
from .typedtree_printer import TypedtreePrinter
class Inferencer(algorithm.Visitor): class Inferencer(algorithm.Visitor):
""" """

View File

@ -5,7 +5,7 @@ do not.
""" """
from pythonparser import algorithm, diagnostic from pythonparser import algorithm, diagnostic
from .. import types, builtins from .. import types, builtins, asttyped
class IntMonomorphizer(algorithm.Visitor): class IntMonomorphizer(algorithm.Visitor):
def __init__(self, engine): def __init__(self, engine):
@ -35,3 +35,13 @@ class IntMonomorphizer(algorithm.Visitor):
typ = node.type.find() typ = node.type.find()
if types.is_var(typ["width"]): if types.is_var(typ["width"]):
typ["width"].unify(types.TValue(32)) typ["width"].unify(types.TValue(32))
def visit_CoerceT(self, node):
if isinstance(node.value, asttyped.NumT) and \
builtins.is_int(node.type) and \
builtins.is_int(node.value.type) and \
not types.is_var(node.type["width"]) and \
types.is_var(node.value.type["width"]):
node.value.type.unify(node.type)
self.generic_visit(node)

View File

@ -0,0 +1,10 @@
# RUN: %python -m artiq.compiler.testbench.signature %s >%t
# RUN: OutputCheck %s --file-to-check=%t
def f(x):
x = int64(0)
return x
# CHECK-L: g: ()->numpy.int64
def g():
return f(1 + 0)