embedding: refactor.

This commit is contained in:
whitequark 2016-05-16 12:33:26 +00:00
parent c94c411fd5
commit d085d5a372
1 changed files with 48 additions and 48 deletions

View File

@ -786,69 +786,69 @@ class Stitcher:
self.functions[function] = function_type self.functions[function] = function_type
return function_type return function_type
def _quote_rpc(self, callee, loc): def _quote_rpc(self, function, loc):
ret_type = builtins.TNone() ret_type = builtins.TNone()
if isinstance(callee, pytypes.BuiltinFunctionType): if isinstance(function, pytypes.BuiltinFunctionType):
pass pass
elif isinstance(callee, pytypes.FunctionType) or isinstance(callee, pytypes.MethodType): elif isinstance(function, pytypes.FunctionType) or isinstance(function, pytypes.MethodType):
if isinstance(callee, pytypes.FunctionType): if isinstance(function, pytypes.FunctionType):
signature = inspect.signature(callee) signature = inspect.signature(function)
else: else:
# inspect bug? # inspect bug?
signature = inspect.signature(callee.__func__) signature = inspect.signature(function.__func__)
if signature.return_annotation is not inspect.Signature.empty: if signature.return_annotation is not inspect.Signature.empty:
ret_type = self._extract_annot(callee, signature.return_annotation, ret_type = self._extract_annot(function, signature.return_annotation,
"return type", loc, is_syscall=False) "return type", loc, is_syscall=False)
else: else:
assert False assert False
function_type = types.TRPC(ret_type, service=self.object_map.store(callee)) function_type = types.TRPC(ret_type, service=self.object_map.store(function))
self.functions[callee] = function_type self.functions[function] = function_type
return function_type return function_type
def _quote_function(self, function, loc): def _quote_function(self, function, loc):
if function not in self.functions: if function in self.functions:
if hasattr(function, "artiq_embedded"): pass
if function.artiq_embedded.function is not None: elif not hasattr(function, "artiq_embedded"):
if function.__name__ == "<lambda>": self._quote_rpc(function, loc)
note = diagnostic.Diagnostic("note", elif function.artiq_embedded.function is not None:
"lambda created here", {}, if function.__name__ == "<lambda>":
self._function_loc(function.artiq_embedded.function)) note = diagnostic.Diagnostic("note",
diag = diagnostic.Diagnostic("fatal", "lambda created here", {},
"lambdas cannot be used as kernel functions", {}, self._function_loc(function.artiq_embedded.function))
loc, diag = diagnostic.Diagnostic("fatal",
notes=[note]) "lambdas cannot be used as kernel functions", {},
self.engine.process(diag) loc,
notes=[note])
self.engine.process(diag)
core_name = function.artiq_embedded.core_name core_name = function.artiq_embedded.core_name
if core_name is not None and self.dmgr.get(core_name) != self.core: if core_name is not None and self.dmgr.get(core_name) != self.core:
note = diagnostic.Diagnostic("note", note = diagnostic.Diagnostic("note",
"called from this function", {}, "called from this function", {},
loc) loc)
diag = diagnostic.Diagnostic("fatal", diag = diagnostic.Diagnostic("fatal",
"this function runs on a different core device '{name}'", "this function runs on a different core device '{name}'",
{"name": function.artiq_embedded.core_name}, {"name": function.artiq_embedded.core_name},
self._function_loc(function.artiq_embedded.function), self._function_loc(function.artiq_embedded.function),
notes=[note]) notes=[note])
self.engine.process(diag) self.engine.process(diag)
self._quote_embedded_function(function, self._quote_embedded_function(function,
flags=function.artiq_embedded.flags) flags=function.artiq_embedded.flags)
elif function.artiq_embedded.syscall is not None: elif function.artiq_embedded.syscall is not None:
# Insert a storage-less global whose type instructs the compiler # Insert a storage-less global whose type instructs the compiler
# to perform a system call instead of a regular call. # to perform a system call instead of a regular call.
self._quote_syscall(function, loc) self._quote_syscall(function, loc)
elif function.artiq_embedded.forbidden is not None: elif function.artiq_embedded.forbidden is not None:
diag = diagnostic.Diagnostic("fatal", diag = diagnostic.Diagnostic("fatal",
"this function cannot be called as an RPC", {}, "this function cannot be called as an RPC", {},
self._function_loc(function), self._function_loc(function),
notes=self._call_site_note(loc, is_syscall=True)) notes=self._call_site_note(loc, is_syscall=True))
self.engine.process(diag) self.engine.process(diag)
else: else:
assert False assert False
else:
self._quote_rpc(function, loc)
return self.functions[function] return self.functions[function]