forked from M-Labs/artiq
1
0
Fork 0

embedding: treat numpy.{int32,int64,array} specially (#424).

Also, remove them from prelude to not pollute the namespace.
This commit is contained in:
whitequark 2016-07-07 05:00:09 +00:00
parent d2d897a885
commit 7a671fb2fd
3 changed files with 29 additions and 1 deletions

View File

@ -125,6 +125,12 @@ def fn_bool():
def fn_int(): def fn_int():
return types.TConstructor(TInt()) return types.TConstructor(TInt())
def fn_int32():
return types.TConstructor(TInt32())
def fn_int64():
return types.TConstructor(TInt64())
def fn_float(): def fn_float():
return types.TConstructor(TFloat()) return types.TConstructor(TFloat())

View File

@ -158,6 +158,18 @@ class ASTSynthesizer:
typ = builtins.TBool() typ = builtins.TBool()
return asttyped.NameConstantT(value=value, type=typ, return asttyped.NameConstantT(value=value, type=typ,
loc=self._add(repr(value))) loc=self._add(repr(value)))
elif value is numpy.int32:
typ = builtins.fn_int32()
return asttyped.NameConstantT(value=None, type=typ,
loc=self._add("numpy.int32"))
elif value is numpy.int64:
typ = builtins.fn_int64()
return asttyped.NameConstantT(value=None, type=typ,
loc=self._add("numpy.int64"))
elif value is numpy.array:
typ = builtins.fn_array()
return asttyped.NameConstantT(value=None, type=typ,
loc=self._add("numpy.array"))
elif isinstance(value, (int, float)): elif isinstance(value, (int, float)):
if isinstance(value, int): if isinstance(value, int):
typ = builtins.TInt() typ = builtins.TInt()
@ -637,9 +649,13 @@ class Stitcher:
self.name = "" self.name = ""
self.typedtree = [] self.typedtree = []
self.inject_at = 0 self.inject_at = 0
self.globals = {}
# We don't want some things from the prelude as they are provided in
# the host Python namespace and gain special meaning when quoted.
self.prelude = prelude.globals() self.prelude = prelude.globals()
self.prelude.pop("print") self.prelude.pop("print")
self.globals = {} self.prelude.pop("array")
self.functions = {} self.functions = {}

View File

@ -105,6 +105,10 @@ class _RPC(EnvExperiment):
def args1kwargs2(self): def args1kwargs2(self):
return self.kwargs("X", a="A", b=1) return self.kwargs("X", a="A", b=1)
@kernel
def numpy_things(self):
return (numpy.int32(10), numpy.int64(20), numpy.array([42,]))
@kernel @kernel
def builtin(self): def builtin(self):
sleep(1.0) sleep(1.0)
@ -120,6 +124,8 @@ class RPCTest(ExperimentCase):
self.assertEqual(exp.kwargs1(), 1) self.assertEqual(exp.kwargs1(), 1)
self.assertEqual(exp.kwargs2(), 2) self.assertEqual(exp.kwargs2(), 2)
self.assertEqual(exp.args1kwargs2(), 2) self.assertEqual(exp.args1kwargs2(), 2)
self.assertEqual(exp.numpy_things(),
(numpy.int32(10), numpy.int64(20), numpy.array([42,])))
exp.builtin() exp.builtin()