Skip to content

Commit

Permalink
Experimental support for ti.func multi-return with scalar values taic…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanming-hu committed Feb 27, 2020
1 parent 8229f03 commit e3c250d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/taichi/lang/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ def visit_block(self, list_stmt):
for i, l in enumerate(list_stmt):
list_stmt[i] = self.visit(l)

def visit_Return(self, node):
ret = self.parse_stmt('__retval.assign(0)')
ret.value.args[0] = node.value
return ret

def visit_If(self, node):
self.generic_visit(node, ['body', 'orelse'])

Expand Down Expand Up @@ -505,9 +510,11 @@ def visit_FunctionDef(self, node):
arg_decls.append(arg_init)
# remove original args
node.args.args = []
ret_stmt = None
else:
# Transform as func (all parameters passed by value)
arg_decls = []
arg_decls.append(self.parse_stmt('__retval = ti.expr_init(0)')) # TODO(archibate): init by ret type
for i, arg in enumerate(args.args):
if i == 0 and self.is_classfunc:
continue
Expand All @@ -517,9 +524,12 @@ def visit_FunctionDef(self, node):
arg_init.value.args[0] = self.parse_expr(arg.arg + '_by_value__')
args.args[i].arg += '_by_value__'
arg_decls.append(arg_init)
ret_stmt = self.parse_stmt('return __retval')
with self.variable_scope():
self.generic_visit(node)
node.body = arg_decls + node.body
if ret_stmt is not None:
node.body.append(ret_stmt)
return node

def visit_UnaryOp(self, node):
Expand Down

0 comments on commit e3c250d

Please sign in to comment.