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: 73ac153509ee
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: 906db876a68a
Choose a head ref
  • 2 commits
  • 38 files changed
  • 1 contributor

Commits on Jul 6, 2016

  1. Copy the full SHA
    fa71b40 View commit details
  2. language: replace coredevice int with numpy.{int32,int64}.

    Fixes #453.
    whitequark committed Jul 6, 2016
    Copy the full SHA
    906db87 View commit details
Showing with 153 additions and 322 deletions.
  1. +8 −1 artiq/compiler/builtins.py
  2. +7 −3 artiq/compiler/embedding.py
  3. +22 −22 artiq/compiler/transforms/inferencer.py
  4. +2 −2 artiq/compiler/transforms/llvm_ir_generator.py
  5. +5 −1 artiq/compiler/types.py
  6. +3 −3 artiq/coredevice/comm_generic.py
  7. +6 −4 artiq/coredevice/spi.py
  8. +7 −5 artiq/coredevice/ttl.py
  9. +3 −144 artiq/language/core.py
  10. +0 −4 artiq/protocols/pyon.py
  11. +3 −2 artiq/test/coredevice/test_embedding.py
  12. +1 −1 artiq/test/lit/embedding/error_attr_conflict.py
  13. +1 −1 artiq/test/lit/embedding/error_attr_unify.py
  14. +8 −8 artiq/test/lit/inferencer/builtin_calls.py
  15. +4 −4 artiq/test/lit/inferencer/class.py
  16. +13 −13 artiq/test/lit/inferencer/coerce.py
  17. +1 −1 artiq/test/lit/inferencer/error_call.py
  18. +9 −9 artiq/test/lit/inferencer/error_coerce.py
  19. +1 −1 artiq/test/lit/inferencer/error_exception.py
  20. +1 −1 artiq/test/lit/inferencer/error_iterable.py
  21. +1 −1 artiq/test/lit/inferencer/error_method.py
  22. +5 −5 artiq/test/lit/inferencer/error_return.py
  23. +7 −7 artiq/test/lit/inferencer/error_unify.py
  24. +2 −2 artiq/test/lit/inferencer/error_with_exn.py
  25. +2 −2 artiq/test/lit/inferencer/error_with_self.py
  26. +1 −1 artiq/test/lit/inferencer/gcd.py
  27. +1 −1 artiq/test/lit/inferencer/prelude.py
  28. +1 −1 artiq/test/lit/inferencer/scoping.py
  29. +1 −1 artiq/test/lit/inferencer/slice.py
  30. +14 −14 artiq/test/lit/inferencer/unify.py
  31. +1 −1 artiq/test/lit/iodelay/argument.py
  32. +1 −1 artiq/test/lit/iodelay/arith.py
  33. +2 −2 artiq/test/lit/iodelay/interleave.py
  34. +3 −3 artiq/test/lit/iodelay/range.py
  35. +2 −2 artiq/test/lit/iodelay/return.py
  36. +1 −1 artiq/test/lit/iodelay/sequential.py
  37. +3 −3 artiq/test/lit/monomorphism/integers.py
  38. +0 −44 artiq/test/test_language.py
9 changes: 8 additions & 1 deletion artiq/compiler/builtins.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,13 @@ def TInt32():
def TInt64():
return TInt(types.TValue(64))

def _int_printer(typ, depth, max_depth):
if types.is_var(typ["width"]):
return "numpy.int?"
else:
return "numpy.int{}".format(types.get_value(typ.find()["width"]))
types.TypePrinter.custom_printers['int'] = _int_printer

class TFloat(types.TMono):
def __init__(self):
super().__init__("float")
@@ -83,7 +90,7 @@ class TException(types.TMono):
# (which also serves as the EHABI type_info).
# * File, line and column where it was raised (str, int, int).
# * Message, which can contain substitutions {0}, {1} and {2} (str).
# * Three 64-bit integers, parameterizing the message (int(width=64)).
# * Three 64-bit integers, parameterizing the message (numpy.int64).

# Keep this in sync with the function ARTIQIRGenerator.alloc_exn.
attributes = OrderedDict([
10 changes: 7 additions & 3 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
annotated as ``@kernel`` when they are referenced.
"""

import sys, os, re, linecache, inspect, textwrap, types as pytypes
import sys, os, re, linecache, inspect, textwrap, types as pytypes, numpy
from collections import OrderedDict, defaultdict

from pythonparser import ast, algorithm, source, diagnostic, parse_buffer
@@ -165,8 +165,12 @@ 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))
elif isinstance(value, numpy.int32):
typ = builtins.TInt32()
return asttyped.NumT(n=int(value), ctx=None, type=typ,
loc=self._add(repr(value)))
elif isinstance(value, numpy.int64):
typ = builtins.TInt64()
return asttyped.NumT(n=int(value), ctx=None, type=typ,
loc=self._add(repr(value)))
elif isinstance(value, str):
44 changes: 22 additions & 22 deletions artiq/compiler/transforms/inferencer.py
Original file line number Diff line number Diff line change
@@ -579,11 +579,11 @@ def simple_form(info, arg_types=[], return_type=builtins.TNone()):
valid_forms = lambda: [
valid_form("{exn}() -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str) -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str, param1:int(width=64)) -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str, param1:int(width=64), "
"param2:int(width=64)) -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str, param1:int(width=64), "
"param2:int(width=64), param3:int(width=64)) "
valid_form("{exn}(message:str, param1:numpy.int64) -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str, param1:numpy.int64, "
"param2:numpy.int64) -> {exn}".format(exn=typ.name)),
valid_form("{exn}(message:str, param1:numpy.int64, "
"param2:numpy.int64, param3:numpy.int64) "
"-> {exn}".format(exn=typ.name)),
]

@@ -620,9 +620,9 @@ def simple_form(info, arg_types=[], return_type=builtins.TNone()):
node.loc, None)
elif types.is_builtin(typ, "int"):
valid_forms = lambda: [
valid_form("int() -> int(width='a)"),
valid_form("int(x:'a) -> int(width='b) where 'a is numeric"),
valid_form("int(x:'a, width='b:<int literal>) -> int(width='b) where 'a is numeric")
valid_form("int() -> numpy.int?"),
valid_form("int(x:'a) -> numpy.int?"),
valid_form("int(x:'a, width=?) -> numpy.int?")
]

self._unify(node.type, builtins.TInt(),
@@ -715,11 +715,11 @@ def makenotes(printer, typea, typeb, loca, locb):
diagnose(valid_forms())
elif types.is_builtin(typ, "range"):
valid_forms = lambda: [
valid_form("range(max:int(width='a)) -> range(elt=int(width='a))"),
valid_form("range(min:int(width='a), max:int(width='a)) "
"-> range(elt=int(width='a))"),
valid_form("range(min:int(width='a), max:int(width='a), "
"step:int(width='a)) -> range(elt=int(width='a))"),
valid_form("range(max:numpy.int?) -> range(elt=numpy.int?)"),
valid_form("range(min:numpy.int?, max:numpy.int?) "
"-> range(elt=numpy.int?)"),
valid_form("range(min:numpy.int?, max:numpy.int?, "
"step:numpy.int?) -> range(elt=numpy.int?)"),
]

range_elt = builtins.TInt(types.TVar())
@@ -734,7 +734,7 @@ def makenotes(printer, typea, typeb, loca, locb):
diagnose(valid_forms())
elif types.is_builtin(typ, "len"):
valid_forms = lambda: [
valid_form("len(x:'a) -> int(width='b) where 'a is iterable"),
valid_form("len(x:'a) -> numpy.int?"),
]

if len(node.args) == 1 and len(node.keywords) == 0:
@@ -762,8 +762,8 @@ def makenotes(printer, typea, typeb, loca, locb):
diagnose(valid_forms())
elif types.is_builtin(typ, "round"):
valid_forms = lambda: [
valid_form("round(x:float) -> int(width='a)"),
valid_form("round(x:float, width='b:<int literal>) -> int(width='b)")
valid_form("round(x:float) -> numpy.int?"),
valid_form("round(x:float, width=?) -> numpy.int?")
]

self._unify(node.type, builtins.TInt(),
@@ -793,7 +793,7 @@ def makenotes(printer, typea, typeb, loca, locb):
fn = typ.name

valid_forms = lambda: [
valid_form("{}(x:int(width='a), y:int(width='a)) -> int(width='a)".format(fn)),
valid_form("{}(x:numpy.int?, y:numpy.int?) -> numpy.int?".format(fn)),
valid_form("{}(x:float, y:float) -> float".format(fn))
]

@@ -858,19 +858,19 @@ def makenotes(printer, typea, typeb, loca, locb):
simple_form("at(time:float) -> None",
[builtins.TFloat()])
elif types.is_builtin(typ, "now_mu"):
simple_form("now_mu() -> int(width=64)",
simple_form("now_mu() -> numpy.int64",
[], builtins.TInt64())
elif types.is_builtin(typ, "delay_mu"):
simple_form("delay_mu(time_mu:int(width=64)) -> None",
simple_form("delay_mu(time_mu:numpy.int64) -> None",
[builtins.TInt64()])
elif types.is_builtin(typ, "at_mu"):
simple_form("at_mu(time_mu:int(width=64)) -> None",
simple_form("at_mu(time_mu:numpy.int64) -> None",
[builtins.TInt64()])
elif types.is_builtin(typ, "mu_to_seconds"):
simple_form("mu_to_seconds(time_mu:int(width=64)) -> float",
simple_form("mu_to_seconds(time_mu:numpy.int64) -> float",
[builtins.TInt64()], builtins.TFloat())
elif types.is_builtin(typ, "seconds_to_mu"):
simple_form("seconds_to_mu(time:float) -> int(width=64)",
simple_form("seconds_to_mu(time:float) -> numpy.int64",
[builtins.TFloat()], builtins.TInt64())
elif types.is_builtin(typ, "watchdog"):
simple_form("watchdog(time:float) -> [builtin context manager]",
4 changes: 2 additions & 2 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
into LLVM intermediate representation.
"""

import os, re, types as pytypes
import os, re, types as pytypes, numpy
from collections import defaultdict
from pythonparser import ast, diagnostic
from llvmlite_artiq import ir as ll, binding as llvm
@@ -1397,7 +1397,7 @@ def _quote_attributes():
assert value in (True, False)
return ll.Constant(llty, value)
elif builtins.is_int(typ):
assert isinstance(value, (int, language_core.int))
assert isinstance(value, (int, numpy.int32, numpy.int64))
return ll.Constant(llty, int(value))
elif builtins.is_float(typ):
assert isinstance(value, float)
6 changes: 5 additions & 1 deletion artiq/compiler/types.py
Original file line number Diff line number Diff line change
@@ -670,6 +670,8 @@ class TypePrinter(object):
type variables sequential alphabetic names.
"""

custom_printers = {}

def __init__(self):
self.gen = genalnum()
self.map = {}
@@ -694,7 +696,9 @@ def name(self, typ, depth=0, max_depth=1):
self.recurse_guard.add(typ)
return "<instance {} {{}}>".format(typ.name)
elif isinstance(typ, TMono):
if typ.params == {}:
if typ.name in self.custom_printers:
return self.custom_printers[typ.name](typ, depth + 1, max_depth)
elif typ.params == {}:
return typ.name
else:
return "%s(%s)" % (typ.name, ", ".join(
6 changes: 3 additions & 3 deletions artiq/coredevice/comm_generic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import struct
import logging
import traceback
import numpy
from enum import Enum
from fractions import Fraction
from collections import namedtuple

from artiq.coredevice import exceptions
from artiq.language.core import int as wrapping_int
from artiq import __version__ as software_version


@@ -317,9 +317,9 @@ def _receive_rpc_value(self, embedding_map):
elif tag == "b":
return bool(self._read_int8())
elif tag == "i":
return wrapping_int(self._read_int32(), 32)
return numpy.int32(self._read_int32())
elif tag == "I":
return wrapping_int(self._read_int64(), 64)
return numpy.int64(self._read_int64())
elif tag == "f":
return self._read_float64()
elif tag == "F":
10 changes: 6 additions & 4 deletions artiq/coredevice/spi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy

from artiq.language.core import (kernel, portable, seconds_to_mu, now_mu,
delay_mu, int, mu_to_seconds)
delay_mu, mu_to_seconds)
from artiq.language.units import MHz
from artiq.coredevice.rtio import rtio_output, rtio_input_data

@@ -60,9 +62,9 @@ def __init__(self, dmgr, channel, core_device="core"):
self.ref_period_mu = seconds_to_mu(self.core.coarse_ref_period,
self.core)
self.channel = channel
self.write_period_mu = int(0, 64)
self.read_period_mu = int(0, 64)
self.xfer_period_mu = int(0, 64)
self.write_period_mu = numpy.int64(0)
self.read_period_mu = numpy.int64(0)
self.xfer_period_mu = numpy.int64(0)

@portable
def frequency_to_div(self, f):
12 changes: 7 additions & 5 deletions artiq/coredevice/ttl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy

from artiq.language.core import *
from artiq.language.types import *
from artiq.coredevice.rtio import rtio_output, rtio_input_timestamp
@@ -17,7 +19,7 @@ def __init__(self, dmgr, channel, core_device="core"):
self.channel = channel

# in RTIO cycles
self.o_previous_timestamp = int(0, width=64)
self.o_previous_timestamp = numpy.int64(0)

@kernel
def output(self):
@@ -101,8 +103,8 @@ def __init__(self, dmgr, channel, core_device="core"):
self.channel = channel

# in RTIO cycles
self.o_previous_timestamp = int(0, width=64)
self.i_previous_timestamp = int(0, width=64)
self.o_previous_timestamp = numpy.int64(0)
self.i_previous_timestamp = numpy.int64(0)

@kernel
def set_oe(self, oe):
@@ -282,8 +284,8 @@ def __init__(self, dmgr, channel, core_device="core"):
self.channel = channel

# in RTIO cycles
self.previous_timestamp = int(0, width=64)
self.acc_width = int(24, width=64)
self.previous_timestamp = numpy.int64(0)
self.acc_width = numpy.int64(24)

@portable
def frequency_to_ftw(self, frequency):
Loading