forked from M-Labs/artiq
compiler: handle language.core.int during embedding.
This commit is contained in:
parent
83ebb999c8
commit
c621b1f275
|
@ -74,6 +74,10 @@ class ASTSynthesizer:
|
||||||
typ = builtins.TFloat()
|
typ = builtins.TFloat()
|
||||||
return asttyped.NumT(n=value, ctx=None, type=typ,
|
return asttyped.NumT(n=value, ctx=None, type=typ,
|
||||||
loc=self._add(repr(value)))
|
loc=self._add(repr(value)))
|
||||||
|
elif isinstance(value, language_core.int):
|
||||||
|
typ = builtins.TInt(width=types.TValue(value.width))
|
||||||
|
return asttyped.NumT(n=int(value), ctx=None, type=typ,
|
||||||
|
loc=self._add(repr(value)))
|
||||||
elif isinstance(value, str):
|
elif isinstance(value, str):
|
||||||
return asttyped.StrT(s=value, ctx=None, type=builtins.TStr(),
|
return asttyped.StrT(s=value, ctx=None, type=builtins.TStr(),
|
||||||
loc=self._add(repr(value)))
|
loc=self._add(repr(value)))
|
||||||
|
|
|
@ -6,6 +6,7 @@ into LLVM intermediate representation.
|
||||||
import os
|
import os
|
||||||
from pythonparser import ast, diagnostic
|
from pythonparser import ast, diagnostic
|
||||||
from llvmlite_artiq import ir as ll
|
from llvmlite_artiq import ir as ll
|
||||||
|
from ...language import core as language_core
|
||||||
from .. import types, builtins, ir
|
from .. import types, builtins, ir
|
||||||
|
|
||||||
|
|
||||||
|
@ -1007,8 +1008,8 @@ class LLVMIRGenerator:
|
||||||
assert value in (True, False)
|
assert value in (True, False)
|
||||||
return ll.Constant(lli1, value)
|
return ll.Constant(lli1, value)
|
||||||
elif builtins.is_int(typ):
|
elif builtins.is_int(typ):
|
||||||
assert isinstance(value, int)
|
assert isinstance(value, (int, language_core.int))
|
||||||
return ll.Constant(ll.IntType(builtins.get_int_width(typ)), value)
|
return ll.Constant(ll.IntType(builtins.get_int_width(typ)), int(value))
|
||||||
elif builtins.is_float(typ):
|
elif builtins.is_float(typ):
|
||||||
assert isinstance(value, float)
|
assert isinstance(value, float)
|
||||||
return ll.Constant(lldouble, value)
|
return ll.Constant(lldouble, value)
|
||||||
|
|
|
@ -72,8 +72,8 @@ class int:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def width(width):
|
def width(self):
|
||||||
return width._width
|
return self._width
|
||||||
|
|
||||||
def __int__(self):
|
def __int__(self):
|
||||||
return self._value
|
return self._value
|
||||||
|
|
Loading…
Reference in New Issue