Commit f5d333f0 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Ada backend supports procedure call with return

parent 8609173c
......@@ -148,6 +148,7 @@ Changelog
while sdl92 only supported variable!field)
- Sequence of literals now support field selectors
(i.e. { variable.field } is now a valid statement)
- Support inner procedure call with return statement
1.5.19 (11/2016)
- Fix integer cast in Ada
......
......@@ -1323,6 +1323,7 @@ def _primary_variable(prim):
@expression.register(ogAST.PrimCall)
def _prim_call(prim):
''' Cover all built-in functions and inner procedures with RETURN stmt '''
stmts, ada_string, local_decl = [], '', []
ident = prim.value[0].lower()
......@@ -1461,7 +1462,8 @@ def _prim_call(prim):
ada_string += "{sort}'Truncation({p})".format(sort=exp_typename,
p=param_str)
else:
ada_string += '('
# inner procedure call (with a RETURN statement)
ada_string += u'p{}{}('.format(UNICODE_SEP, ident)
# Take all params and join them with commas
list_of_params = []
for param in params:
......
......@@ -27,16 +27,16 @@ dcl res path;
/* CIF ENDTEXT */
/* CIF PROCEDURE (460, 209), (75, 35) */
PROCEDURE findpath;
/* CIF TEXT (107, 140), (272, 140) */
dcl result Path := { cost 0, elem {} };
dcl elem Path_elem := {};
/* CIF ENDTEXT */
/* CIF TEXT (108, 55), (183, 68) */
/* CIF TEXT (104, 47), (183, 68) */
fpar
in startnode letter,
in endnode letter,
in/out best_path Path;
in endnode letter;
returns Path;
/* CIF ENDTEXT */
/* CIF TEXT (107, 140), (304, 53) */
dcl result, best_path Path := { cost 0, elem {} };
dcl elem Path_elem := {};
/* CIF ENDTEXT */
/* CIF START (626, 64), (70, 35) */
START;
......@@ -51,32 +51,28 @@ dcl elem Path_elem := {};
(true):
/* CIF TASK (398, 320), (136, 23) */
TASK best_path.cost :=0;
/* CIF RETURN (448, 363), (35, 35) */
RETURN ;
/* CIF ANSWER (820, 277), (70, 23) */
(false):
/* CIF DECISION (759, 320), (193, 50) */
/* CIF DECISION (758, 320), (193, 50) */
DECISION length(my_tree(startnode))
= 0;
/* CIF ANSWER (547, 390), (70, 23) */
(true):
/* CIF RETURN (565, 433), (35, 35) */
RETURN ;
/* CIF ANSWER (918, 390), (70, 23) */
(false):
/* CIF TASK (714, 433), (478, 113) */
TASK for each in my_tree(startnode):
call findpath(each.son, endnode, result);
result := findpath(each.son, endnode)
result.cost := result.cost + each.cost
elem := { each.son } // elem
best_path := if result.cost < best_path.cost then result else best_path fi
endfor;
/* CIF TASK (883, 561), (141, 35) */
/* CIF TASK (882, 561), (141, 35) */
TASK result.elem := elem;
/* CIF RETURN (936, 611), (35, 35) */
RETURN ;
ENDDECISION;
ENDDECISION;
/* CIF RETURN (643, 626), (35, 35) */
RETURN best_path;
ENDPROCEDURE;
/* CIF START (155, 216), (70, 35) */
START;
......@@ -89,11 +85,11 @@ my_tree(e) := {{cost 7, son h}},
my_tree(f) := {{cost 1, son g}},
my_tree(g) := {},
my_tree(h) := {{cost 5, son g}};
/* CIF PROCEDURECALL (97, 419), (186, 35) */
CALL findpath(a, g, res);
/* CIF PROCEDURECALL (88, 474), (204, 35) */
/* CIF TASK (120, 419), (139, 35) */
TASK res := findpath(a, g);
/* CIF PROCEDURECALL (88, 469), (204, 35) */
CALL writeln('best cost:', res.cost);
/* CIF NEXTSTATE (155, 529), (70, 35) */
/* CIF NEXTSTATE (155, 524), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (296, 231), (70, 35) */
STATE wait;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment