Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 98bb570aec7f
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c621b1f27507
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 28, 2015

  1. Copy the full SHA
    83ebb99 View commit details
  2. compiler: handle language.core.int during embedding.

    whitequark committed Aug 28, 2015
    Copy the full SHA
    c621b1f View commit details
Showing with 24 additions and 5 deletions.
  1. +5 −0 artiq/compiler/embedding.py
  2. +14 −1 artiq/compiler/transforms/inferencer.py
  3. +3 −2 artiq/compiler/transforms/llvm_ir_generator.py
  4. +2 −2 artiq/language/core.py
5 changes: 5 additions & 0 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

from pythonparser import ast, algorithm, source, diagnostic, parse_buffer

from ..language import core as language_core
from . import types, builtins, asttyped, prelude
from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer

@@ -73,6 +74,10 @@ def quote(self, value):
typ = builtins.TFloat()
return asttyped.NumT(n=value, ctx=None, type=typ,
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):
return asttyped.StrT(s=value, ctx=None, type=builtins.TStr(),
loc=self._add(repr(value)))
15 changes: 14 additions & 1 deletion artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -91,9 +91,22 @@ def visit_AttributeT(self, node):
object_type = node.value.type.find()
if not types.is_var(object_type):
if node.attr in object_type.attributes:
def makenotes(printer, typea, typeb, loca, locb):
return [
diagnostic.Diagnostic("note",
"expression of type {typea}",
{"typea": printer.name(typea)},
loca),
diagnostic.Diagnostic("note",
"expression of type {typeb}",
{"typeb": printer.name(object_type)},
node.value.loc)
]

# Assumes no free type variables in .attributes.
self._unify(node.type, object_type.attributes[node.attr],
node.loc, None)
node.loc, None,
makenotes=makenotes, when=" for attribute '{}'".format(node.attr))
elif types.is_instance(object_type) and \
node.attr in object_type.constructor.attributes:
# Assumes no free type variables in .attributes.
5 changes: 3 additions & 2 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import os
from pythonparser import ast, diagnostic
from llvmlite_artiq import ir as ll
from ...language import core as language_core
from .. import types, builtins, ir


@@ -1007,8 +1008,8 @@ def _quote(self, value, typ, path):
assert value in (True, False)
return ll.Constant(lli1, value)
elif builtins.is_int(typ):
assert isinstance(value, int)
return ll.Constant(ll.IntType(builtins.get_int_width(typ)), value)
assert isinstance(value, (int, language_core.int))
return ll.Constant(ll.IntType(builtins.get_int_width(typ)), int(value))
elif builtins.is_float(typ):
assert isinstance(value, float)
return ll.Constant(lldouble, value)
4 changes: 2 additions & 2 deletions artiq/language/core.py
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ def __new__(cls, value, width=32):
return self

@property
def width(width):
return width._width
def width(self):
return self._width

def __int__(self):
return self._value