зеркало из https://github.com/microsoft/ivy.git
getting call by reference to work with method calls
This commit is contained in:
Родитель
96885e59d7
Коммит
aaed5702ef
|
@ -206,8 +206,8 @@ module sequence_iterator(range) = {
|
||||||
|
|
||||||
instantiate order_iterator(range)
|
instantiate order_iterator(range)
|
||||||
|
|
||||||
action next(x:t) returns (y:t)
|
action next(x:t) returns (x:t)
|
||||||
action prev(y:t) returns (x:t)
|
action prev(x:t) returns (x:t)
|
||||||
|
|
||||||
object spec = {
|
object spec = {
|
||||||
...
|
...
|
||||||
|
@ -215,18 +215,18 @@ module sequence_iterator(range) = {
|
||||||
assert ~is_end(x)
|
assert ~is_end(x)
|
||||||
}
|
}
|
||||||
after next {
|
after next {
|
||||||
assert X <= val(x) & is_end(y)
|
assert X <= val(old x) & is_end(x)
|
||||||
| ~(val(x) < Y & Y < val(y))
|
| ~(val(old x) < Y & Y < val(x))
|
||||||
& val(x) < val(y) & ~is_end(y)
|
& val(old x) < val(x) & ~is_end(x)
|
||||||
}
|
}
|
||||||
before prev {
|
before prev {
|
||||||
assert is_end(y) | exists X. X < val(y)
|
assert is_end(x) | exists X. X < val(x)
|
||||||
}
|
}
|
||||||
after prev {
|
after prev {
|
||||||
assert ~is_end(x);
|
assert ~is_end(x);
|
||||||
assert X <= val(x) & is_end(y)
|
assert X <= val(x) & is_end(old x)
|
||||||
| ~(val(x) < Y & Y < val(y))
|
| ~(val(x) < Y & Y < val(old x))
|
||||||
& val(x) < val(y) & ~is_end(y)
|
& val(x) < val(old x) & ~is_end(old x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,13 +234,13 @@ module sequence_iterator(range) = {
|
||||||
...
|
...
|
||||||
implement next {
|
implement next {
|
||||||
if range.is_max(val(x)) {
|
if range.is_max(val(x)) {
|
||||||
y := end
|
x := end
|
||||||
} else {
|
} else {
|
||||||
y := create(range.next(val(x)))
|
x := create(range.next(val(x)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
implement prev {
|
implement prev {
|
||||||
x := create(range.prev(val(y)))
|
x := create(range.prev(val(x)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,8 @@ def compile_inline_call(self,args):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def compile_app(self):
|
def compile_app(self):
|
||||||
args = [a.compile() for a in self.args]
|
with ReturnContext(None):
|
||||||
|
args = [a.compile() for a in self.args]
|
||||||
# handle action calls in rhs of assignment
|
# handle action calls in rhs of assignment
|
||||||
if expr_context and top_context and self.rep in top_context.actions:
|
if expr_context and top_context and self.rep in top_context.actions:
|
||||||
return compile_inline_call(self,args)
|
return compile_inline_call(self,args)
|
||||||
|
@ -362,12 +363,12 @@ def compile_local(self):
|
||||||
LocalAction.cmpl = compile_local
|
LocalAction.cmpl = compile_local
|
||||||
|
|
||||||
def compile_assign(self):
|
def compile_assign(self):
|
||||||
rhs = self.args[1]
|
# rhs = self.args[1]
|
||||||
if (isinstance(rhs,ivy_ast.App) or isinstance(rhs,ivy_ast.Atom)):
|
# if (isinstance(rhs,ivy_ast.App) or isinstance(rhs,ivy_ast.Atom)):
|
||||||
if top_context and rhs.rep in top_context.actions:
|
# if top_context and rhs.rep in top_context.actions:
|
||||||
c = CallAction(rhs,self.args[0])
|
# c = CallAction(rhs,self.args[0])
|
||||||
c.lineno = self.lineno
|
# c.lineno = self.lineno
|
||||||
return c.cmpl()
|
# return c.cmpl()
|
||||||
code = []
|
code = []
|
||||||
local_syms = []
|
local_syms = []
|
||||||
with ExprContext(code,local_syms):
|
with ExprContext(code,local_syms):
|
||||||
|
@ -379,17 +380,21 @@ def compile_assign(self):
|
||||||
code.append(AssignAction(lhs,rhs))
|
code.append(AssignAction(lhs,rhs))
|
||||||
else:
|
else:
|
||||||
with top_sort_as_default():
|
with top_sort_as_default():
|
||||||
args = [a.compile() for a in self.args]
|
# args = [a.compile() for a in self.args]
|
||||||
|
args = [self.args[0].compile()]
|
||||||
|
with ReturnContext([args[0]]):
|
||||||
|
args.append(self.args[1].compile())
|
||||||
if isinstance(args[1],ivy_ast.Tuple):
|
if isinstance(args[1],ivy_ast.Tuple):
|
||||||
raise IvyError(self,"wrong number of values in assignment");
|
raise IvyError(self,"wrong number of values in assignment");
|
||||||
asorts = [a.sort for a in args]
|
if args[1] is not None:
|
||||||
with ASTContext(self):
|
asorts = [a.sort for a in args]
|
||||||
if im.module.is_variant(*asorts):
|
with ASTContext(self):
|
||||||
teq = sort_infer(ivy_logic.pto(*asorts)(*args))
|
if im.module.is_variant(*asorts):
|
||||||
else:
|
teq = sort_infer(ivy_logic.pto(*asorts)(*args))
|
||||||
teq = sort_infer(Equals(*args))
|
else:
|
||||||
args = list(teq.args)
|
teq = sort_infer(Equals(*args))
|
||||||
code.append(AssignAction(*args))
|
args = list(teq.args)
|
||||||
|
code.append(AssignAction(*args))
|
||||||
for c in code:
|
for c in code:
|
||||||
c.lineno = self.lineno
|
c.lineno = self.lineno
|
||||||
if len(code) == 1:
|
if len(code) == 1:
|
||||||
|
|
|
@ -969,8 +969,13 @@ def emit_native(header,impl,native,classname):
|
||||||
def annotate_action(action):
|
def annotate_action(action):
|
||||||
def action_assigns(p):
|
def action_assigns(p):
|
||||||
return any(p in sub.modifies() for sub in action.iter_subactions())
|
return any(p in sub.modifies() for sub in action.iter_subactions())
|
||||||
|
|
||||||
|
def is_struct(sort):
|
||||||
|
return (il.is_uninterpreted_sort(sort) and
|
||||||
|
(sort.name in im.module.native_types or sort.name in im.module.sort_destructors))
|
||||||
|
|
||||||
action.param_types = [RefType() if any(p == q for q in action.formal_returns)
|
action.param_types = [RefType() if any(p == q for q in action.formal_returns)
|
||||||
else ValueType() if action_assigns(p) else ConstRefType()
|
else ValueType() if action_assigns(p) or not is_struct(p.sort) else ConstRefType()
|
||||||
for p in action.formal_params]
|
for p in action.formal_params]
|
||||||
def return_type(p):
|
def return_type(p):
|
||||||
for idx,q in enumerate(action.formal_params):
|
for idx,q in enumerate(action.formal_params):
|
||||||
|
@ -3090,8 +3095,9 @@ ia.AssumeAction.emit = emit_assume
|
||||||
|
|
||||||
|
|
||||||
def emit_call(self,header):
|
def emit_call(self,header):
|
||||||
indent(header)
|
if target.get() in ["gen","test"]:
|
||||||
header.append('___ivy_stack.push_back(' + str(self.unique_id) + ');\n')
|
indent(header)
|
||||||
|
header.append('___ivy_stack.push_back(' + str(self.unique_id) + ');\n')
|
||||||
code = []
|
code = []
|
||||||
indent(code)
|
indent(code)
|
||||||
retval = None
|
retval = None
|
||||||
|
@ -3125,8 +3131,9 @@ def emit_call(self,header):
|
||||||
self.args[1].emit(header,code)
|
self.args[1].emit(header,code)
|
||||||
code.append(' = ' + retval + ';\n')
|
code.append(' = ' + retval + ';\n')
|
||||||
header.extend(code)
|
header.extend(code)
|
||||||
indent(header)
|
if target.get() in ["gen","test"]:
|
||||||
header.append('___ivy_stack.pop_back();\n')
|
indent(header)
|
||||||
|
header.append('___ivy_stack.pop_back();\n')
|
||||||
|
|
||||||
ia.CallAction.emit = emit_call
|
ia.CallAction.emit = emit_call
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче