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

Add test-recursion

parent 8bd0a1d0
include ../shared.mk
all: test-ada test-llvm
edit:
$(OPENGEODE) og.pr
test-parse:
$(OPENGEODE) og.pr --check
test-ada: dataview-uniq.o test_ada.o
$(OPENGEODE) og.pr --toAda
$(ASN1SCC) -Ada dataview-uniq.asn -typePrefix asn1Scc -equal
$(GNATMAKE) -O$(O) -c *.adb
$(GNATBIND) -n og.ali
$(GNATLINK) -o test_ada test_ada.o dataview-uniq.o og.ali -lgnat
./test_ada
test-c:
$(OPENGEODE) og.pr --toC
$(ASN1SCC) -c dataview-uniq.asn -typePrefix asn1Scc -equal
$(CC) -O$(O) -c *.c
test-llvm:
$(OPENGEODE) og.pr --llvm -O$(O)
$(LLC) *.ll
$(CC) -O$(O) -c *.s
coverage:
coverage run -p $(OPENGEODE) og.pr --toAda
.PHONY: all edit test-parse test-ada test-llvm coverage
TASTE-Dataview DEFINITIONS ::=
BEGIN
-- Named integers to work with letters
Letter ::= INTEGER {
a (0),
b (1),
c (2),
d (3),
e (4),
f (5),
g (6),
h (7),
i (8),
j (9),
k (10),
l (11),
m (12),
n (13),
o (14),
p (15),
q (16),
r (17),
s (18),
t (19),
u (20),
v (21),
w (22),
x (23),
y (24),
z (25) } (0..25)
Cost-ty ::= INTEGER (0..255)
Tree-Elem ::= SEQUENCE {
cost Cost-ty,
son Letter
}
Sons ::= SEQUENCE (SIZE (0..100)) OF Tree-Elem
Tree ::= SEQUENCE (SIZE (26)) OF Sons
Path ::= SEQUENCE {
cost Cost-ty,
elem SEQUENCE (SIZE(0..255)) OF Letter
}
END
#!/usr/bin/env python
# ASN.1 Data model
asn1Files = []
asn1Modules = []
exportedTypes = {}
exportedVariables = {}
importedModules = {}
types = {}
variables = {}
asn1Files.append("dataview-uniq.asn")
asn1Modules.append("TASTE-Dataview")
exportedTypes["TASTE-Dataview"] = ["Letter", "Cost-ty", "Tree-Elem", "Sons", "Tree", "Path", "Path-elem"]
exportedVariables["TASTE-Dataview"] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
importedModules["TASTE-Dataview"] = []
types["Letter"] = type("Letter", (object,), {
"Line": 5, "CharPositionInLine": 0, "type": type("Letter_type", (object,), {
"Line": 5, "CharPositionInLine": 11, "kind": "IntegerType", "Min": "0", "Max": "25"
})
})
types["Cost-ty"] = type("Cost-ty", (object,), {
"Line": 33, "CharPositionInLine": 0, "type": type("Cost-ty_type", (object,), {
"Line": 33, "CharPositionInLine": 12, "kind": "IntegerType", "Min": "0", "Max": "255"
})
})
types["Tree-Elem"] = type("Tree-Elem", (object,), {
"Line": 35, "CharPositionInLine": 0, "type": type("Tree-Elem_type", (object,), {
"Line": 35, "CharPositionInLine": 14, "kind": "SequenceType", "Children": {
"cost": type("cost", (object,), {
"Optional": "False", "Line": 36, "CharPositionInLine": 4, "type": type("cost_type", (object,), {
"Line": 36, "CharPositionInLine": 9, "kind": "ReferenceType", "ReferencedTypeName": "Cost-ty", "Min": "0", "Max": "255"
})
}),
"son": type("son", (object,), {
"Optional": "False", "Line": 37, "CharPositionInLine": 4, "type": type("son_type", (object,), {
"Line": 37, "CharPositionInLine": 9, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
})
})
}
})
})
types["Sons"] = type("Sons", (object,), {
"Line": 39, "CharPositionInLine": 0, "type": type("Sons_type", (object,), {
"Line": 39, "CharPositionInLine": 9, "kind": "SequenceOfType", "Min": "0", "Max": "100", "type": type("SeqOf_type", (object,), {
"Line": 39, "CharPositionInLine": 37, "kind": "ReferenceType", "ReferencedTypeName": "Tree-Elem"
})
})
})
types["Tree"] = type("Tree", (object,), {
"Line": 40, "CharPositionInLine": 0, "type": type("Tree_type", (object,), {
"Line": 40, "CharPositionInLine": 9, "kind": "SequenceOfType", "Min": "26", "Max": "26", "type": type("SeqOf_type", (object,), {
"Line": 40, "CharPositionInLine": 37, "kind": "ReferenceType", "ReferencedTypeName": "Sons", "Min": "0", "Max": "100"
})
})
})
types["Path"] = type("Path", (object,), {
"Line": 42, "CharPositionInLine": 0, "type": type("Path_type", (object,), {
"Line": 42, "CharPositionInLine": 9, "kind": "SequenceType", "Children": {
"cost": type("cost", (object,), {
"Optional": "False", "Line": 43, "CharPositionInLine": 4, "type": type("cost_type", (object,), {
"Line": 43, "CharPositionInLine": 9, "kind": "ReferenceType", "ReferencedTypeName": "Cost-ty", "Min": "0", "Max": "255"
})
}),
"elem": type("elem", (object,), {
"Optional": "False", "Line": 44, "CharPositionInLine": 4, "type": type("elem_type", (object,), {
"Line": 0, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Path-elem", "Min": "0", "Max": "255"
})
})
}
})
})
types["Path-elem"] = type("Path-elem", (object,), {
"Line": 0, "CharPositionInLine": 0, "type": type("Path-elem_type", (object,), {
"Line": 44, "CharPositionInLine": 9, "kind": "SequenceOfType", "Min": "0", "Max": "255", "type": type("SeqOf_type", (object,), {
"Line": 44, "CharPositionInLine": 36, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
})
})
})
variables["a"] = type("a", (object,), {
"Line": 6,
"CharPositionInLine": 2,
"varName": "Letter_a",
"type": type("a_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 0
})
variables["b"] = type("b", (object,), {
"Line": 7,
"CharPositionInLine": 2,
"varName": "Letter_b",
"type": type("b_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 1
})
variables["c"] = type("c", (object,), {
"Line": 8,
"CharPositionInLine": 2,
"varName": "Letter_c",
"type": type("c_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 2
})
variables["d"] = type("d", (object,), {
"Line": 9,
"CharPositionInLine": 2,
"varName": "Letter_d",
"type": type("d_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 3
})
variables["e"] = type("e", (object,), {
"Line": 10,
"CharPositionInLine": 2,
"varName": "Letter_e",
"type": type("e_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 4
})
variables["f"] = type("f", (object,), {
"Line": 11,
"CharPositionInLine": 2,
"varName": "Letter_f",
"type": type("f_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 5
})
variables["g"] = type("g", (object,), {
"Line": 12,
"CharPositionInLine": 2,
"varName": "Letter_g",
"type": type("g_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 6
})
variables["h"] = type("h", (object,), {
"Line": 13,
"CharPositionInLine": 2,
"varName": "Letter_h",
"type": type("h_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 7
})
variables["i"] = type("i", (object,), {
"Line": 14,
"CharPositionInLine": 2,
"varName": "Letter_i",
"type": type("i_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 8
})
variables["j"] = type("j", (object,), {
"Line": 15,
"CharPositionInLine": 2,
"varName": "Letter_j",
"type": type("j_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 9
})
variables["k"] = type("k", (object,), {
"Line": 16,
"CharPositionInLine": 2,
"varName": "Letter_k",
"type": type("k_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 10
})
variables["l"] = type("l", (object,), {
"Line": 17,
"CharPositionInLine": 2,
"varName": "Letter_l",
"type": type("l_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 11
})
variables["m"] = type("m", (object,), {
"Line": 18,
"CharPositionInLine": 2,
"varName": "Letter_m",
"type": type("m_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 12
})
variables["n"] = type("n", (object,), {
"Line": 19,
"CharPositionInLine": 2,
"varName": "Letter_n",
"type": type("n_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 13
})
variables["o"] = type("o", (object,), {
"Line": 20,
"CharPositionInLine": 2,
"varName": "Letter_o",
"type": type("o_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 14
})
variables["p"] = type("p", (object,), {
"Line": 21,
"CharPositionInLine": 2,
"varName": "Letter_p",
"type": type("p_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 15
})
variables["q"] = type("q", (object,), {
"Line": 22,
"CharPositionInLine": 2,
"varName": "Letter_q",
"type": type("q_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 16
})
variables["r"] = type("r", (object,), {
"Line": 23,
"CharPositionInLine": 2,
"varName": "Letter_r",
"type": type("r_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 17
})
variables["s"] = type("s", (object,), {
"Line": 24,
"CharPositionInLine": 2,
"varName": "Letter_s",
"type": type("s_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 18
})
variables["t"] = type("t", (object,), {
"Line": 25,
"CharPositionInLine": 2,
"varName": "Letter_t",
"type": type("t_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 19
})
variables["u"] = type("u", (object,), {
"Line": 26,
"CharPositionInLine": 2,
"varName": "Letter_u",
"type": type("u_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 20
})
variables["v"] = type("v", (object,), {
"Line": 27,
"CharPositionInLine": 2,
"varName": "Letter_v",
"type": type("v_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 21
})
variables["w"] = type("w", (object,), {
"Line": 28,
"CharPositionInLine": 2,
"varName": "Letter_w",
"type": type("w_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 22
})
variables["x"] = type("x", (object,), {
"Line": 29,
"CharPositionInLine": 2,
"varName": "Letter_x",
"type": type("x_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 23
})
variables["y"] = type("y", (object,), {
"Line": 30,
"CharPositionInLine": 2,
"varName": "Letter_y",
"type": type("y_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 24
})
variables["z"] = type("z", (object,), {
"Line": 31,
"CharPositionInLine": 2,
"varName": "Letter_z",
"type": type("z_type", (object,), {
"Line": 5, "CharPositionInLine": 0, "kind": "ReferenceType", "ReferencedTypeName": "Letter", "Min": "0", "Max": "25"
}),
"value": 25
})
SYSTEM og;
/* CIF TEXT (159, 221), (287, 188) */
-- Text area for declarations and comments
use dv comment 'dataview-uniq.asn';
signal dd(Tree);
signal we;
/* CIF ENDTEXT */
CHANNEL c
FROM ENV TO og WITH dd;
FROM og TO ENV WITH we;
ENDCHANNEL;
BLOCK og;
SIGNALROUTE r
FROM ENV TO og WITH dd;
FROM og TO ENV WITH we;
CONNECT c AND r;
/* CIF PROCESS (225, 50), (150, 75) */
PROCESS og;
/* CIF TEXT (57, 58), (287, 140) */
-- Text area for declarations and comments
dcl my_tree Tree;
dcl res path;
/* CIF ENDTEXT */
/* CIF PROCEDURE (460, 209), (75, 35) */
PROCEDURE findpath;
/* CIF TEXT (129, 18), (183, 98) */
fpar
in startnode letter,
in endnode letter,
in my_tree Tree,
in/out best_path Path;
/* CIF ENDTEXT */
/* CIF TEXT (0, 131), (272, 140) */
dcl result Path := { cost 0, elem {} };
dcl elem Path_elem := {};
dcl single Letter;
/* CIF ENDTEXT */
/* CIF START (521, 64), (70, 35) */
START;
/* CIF TASK (503, 119), (106, 68) */
TASK best_path := {
cost 100,
elem {}
};
/* CIF DECISION (480, 207), (151, 50) */
DECISION startnode = endnode;
/* CIF ANSWER (264, 277), (70, 23) */
(true):
/* CIF TASK (246, 320), (106, 68) */
TASK best_path := {
cost 0,
elem {}
};
/* CIF RETURN (281, 408), (35, 35) */
RETURN ;
/* CIF ANSWER (566, 277), (70, 23) */
(false):
/* CIF DECISION (504, 320), (193, 50) */
DECISION length(my_tree(startnode))
= 0;
/* CIF ANSWER (362, 390), (70, 23) */
(true):
/* CIF RETURN (379, 433), (35, 35) */
RETURN ;
/* CIF ANSWER (664, 390), (70, 23) */
(false):
/* CIF TASK (442, 433), (514, 113) */
TASK for each in my_tree(startnode):
call findpath(each!son, endnode, my_tree, result);
task result!cost := result!cost + each!cost;
task single := each!son, elem := {single} // elem ;
task best_path := if result!cost < best_path!cost then result else best_path fi;
endfor;
/* CIF TASK (628, 566), (141, 35) */
TASK result!elem := elem;
/* CIF RETURN (681, 616), (35, 35) */
RETURN ;
ENDDECISION;
ENDDECISION;
ENDPROCEDURE;
/* CIF START (155, 216), (70, 35) */
START;
/* CIF TASK (1, 271), (378, 128) */
TASK my_tree(a) := {{ cost 3, son b}, {cost 4, son c}},
my_tree(b) := {{cost 2, son d}},
my_tree(c) := {{ cost 1, son d}, {cost 1, son e}, {cost 6, son f}},
my_tree(d) := {{cost 1, son h}},
my_tree(e) := {{cost 7, son h}},
my_tree(f) := {{cost 1, son g}},
my_tree(g) := {},
my_tree(h) := {{cost 3, son g}};
/* CIF PROCEDURECALL (97, 419), (186, 35) */
CALL findpath(a, g, my_tree, res);
/* CIF PROCEDURECALL (89, 474), (201, 35) */
CALL writeln('best cost:', res!cost);
/* CIF NEXTSTATE (155, 524), (70, 35) */
NEXTSTATE wait;
/* CIF STATE (296, 231), (70, 35) */
STATE wait;
ENDSTATE;
ENDPROCESS og;
ENDBLOCK;
ENDSYSTEM;
\ No newline at end of file
#include <stdio.h>
#include "dataview-uniq.h"
extern void adainit();
int main() {
adainit();
return 0;
}
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