|
@@ -201,7 +201,8 @@ class ModelverseKernel(object):
|
|
|
" " * (nested_indent + 2) + "yield [('CD', [_root, 'input', nxt])]\n" + \
|
|
|
" " * (nested_indent + 2) + "_result = val\n" + \
|
|
|
" " * (nested_indent + 2) + "break\n" + \
|
|
|
- " " * (nested_indent + 1)+ "else:\n" + \
|
|
|
+ " " * (nested_indent + 1) + "else:\n" + \
|
|
|
+ " " * (nested_indent + 2) + "print('WAIT FOR INPUT...')\n" + \
|
|
|
" " * (nested_indent + 2) + "yield None\n"
|
|
|
instruction = "_result"
|
|
|
|
|
@@ -217,15 +218,18 @@ class ModelverseKernel(object):
|
|
|
" " * indent + "yield [('DE', [_outputs_e])]\n" + \
|
|
|
" " * indent + "yield [('CD', [_root, 'last_output', _new])]\n"
|
|
|
|
|
|
-
|
|
|
elif inst_type["value"] == "resolve":
|
|
|
value, = yield [("RD", [inst, "var"])]
|
|
|
str_value, = yield [("RV", [value])]
|
|
|
if str_value:
|
|
|
# Is a global
|
|
|
prev = \
|
|
|
- " " * nested_indent + "%s, = yield [('RD', [_globs, '%s'])]\n" % (str_value, str_value) + \
|
|
|
- " " * nested_indent + "%s, = yield [('RD', [%s, 'value'])]\n" % (str_value, str_value)
|
|
|
+ " " * nested_indent + "if '%s' not in _cache:\n" % str_value + \
|
|
|
+ " " * (nested_indent + 1) + "%s, = yield [('RD', [_globs, '%s'])]\n" % (str_value, str_value) + \
|
|
|
+ " " * (nested_indent + 1) + "%s, = yield [('RD', [%s, 'value'])]\n" % (str_value, str_value) + \
|
|
|
+ " " * (nested_indent + 1) + "_cache['%s'] = %s\n" % (str_value, str_value) + \
|
|
|
+ " " * nested_indent + "else:\n" + \
|
|
|
+ " " * (nested_indent + 1) + "%s = _cache['%s']\n" % (str_value, str_value)
|
|
|
instruction = str_value
|
|
|
|
|
|
if self.jit.get_global_body_id(str_value) is None:
|
|
@@ -235,7 +239,6 @@ class ModelverseKernel(object):
|
|
|
val, = yield [("RD", [val, 'value'])]
|
|
|
val, = yield [("RD", [val, 'body'])]
|
|
|
|
|
|
- print("Registering global " + str(str_value) + " using " + str(val))
|
|
|
self.jit.register_global(val, str_value)
|
|
|
else:
|
|
|
# Is a local
|
|
@@ -280,24 +283,24 @@ class ModelverseKernel(object):
|
|
|
computation += prev_res
|
|
|
param_list[name] = instruction_res
|
|
|
|
|
|
+ value = "func_result_" + str(ModelverseKernel.counter)
|
|
|
+ ModelverseKernel.counter += 1
|
|
|
+
|
|
|
if func_name in intrinsics:
|
|
|
- #instruction = " " * indent + intrinsics[func_name](*param_list)
|
|
|
- # TODO
|
|
|
- pass
|
|
|
+ #TODO test and fix
|
|
|
+ actual_computation = value + " = " + intrinsics[func_name](*param_list)
|
|
|
else:
|
|
|
- value = "func_result_" + str(ModelverseKernel.counter)
|
|
|
- ModelverseKernel.counter += 1
|
|
|
param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
|
|
|
actual_computation = "%s, = yield [('CALL_ARGS', [_mvk.execute_jit_internal, (_root, %s, _taskname, %s)])]\n" % (value, func_name, param_list)
|
|
|
|
|
|
- if indent == 0:
|
|
|
- # No indent, meaning that we use it inline
|
|
|
- # Therefore, we output the prev and value individually
|
|
|
- prev, instruction = prev_func_name + computation + " " * nested_indent + actual_computation, value
|
|
|
- else:
|
|
|
- # Some indentation, meaning that we don't even use the return value
|
|
|
- # Therefore, we only do the yield
|
|
|
- prev, instruction = prev_func_name + computation, " " * indent + actual_computation
|
|
|
+ if indent == 0:
|
|
|
+ # No indent, meaning that we use it inline
|
|
|
+ # Therefore, we output the prev and value individually
|
|
|
+ prev, instruction = prev_func_name + computation + " " * nested_indent + actual_computation, value
|
|
|
+ else:
|
|
|
+ # Some indentation, meaning that we don't even use the return value
|
|
|
+ # Therefore, we only do the yield
|
|
|
+ prev, instruction = prev_func_name + computation, " " * indent + actual_computation
|
|
|
|
|
|
elif inst_type["value"] == "access":
|
|
|
value, = yield [("RD", [inst, "var"])]
|
|
@@ -333,24 +336,25 @@ class ModelverseKernel(object):
|
|
|
print("Ignoring mutable or unreadable: %s" % suggested_name)
|
|
|
raise jit.JitCompilationFailedException("FAIL")
|
|
|
|
|
|
- print("Reading function: %s" % suggested_name)
|
|
|
+ #print("Reading function: %s" % suggested_name)
|
|
|
(prev, printed), = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
|
|
|
preamble = " _globs, = yield [('RD', [kwargs['task_root'], 'globals'])]\n" + \
|
|
|
" _root = kwargs['task_root']\n" + \
|
|
|
" _taskname = kwargs['taskname']\n" + \
|
|
|
- " _mvk = kwargs['mvk']\n"
|
|
|
+ " _mvk = kwargs['mvk']\n" + \
|
|
|
+ " _cache = {}\n"
|
|
|
printed = preamble + prev + printed
|
|
|
- print("Total printed function: ")
|
|
|
+ #print("Total printed function: ")
|
|
|
if params:
|
|
|
func = "def " + suggested_name + "(" + ", ".join([chr(ord('a') + i) for i in range(len(params))]) + ", **kwargs):\n" + "".join([" var_%s = %s\n" % (param, chr(ord('a') + i)) for i, param in enumerate(params)]) + printed
|
|
|
else:
|
|
|
func = "def " + suggested_name + "(**kwargs):\n" + printed
|
|
|
|
|
|
- print(func)
|
|
|
+ #print(func)
|
|
|
|
|
|
# To write out all generated functions
|
|
|
- #with open('/tmp/junk/%s' % suggested_name, 'w') as f:
|
|
|
- # f.write(func)
|
|
|
+ with open('/tmp/junk/%s' % suggested_name, 'w') as f:
|
|
|
+ f.write(func)
|
|
|
|
|
|
raise primitive_functions.PrimitiveFinished(func)
|
|
|
|