Commit 5a2822a62f484985a7f0e873502dd3c05655c638
1 parent
65f52800
Exists in
master
variable declaration and constant initializers functioning
Showing
1 changed file
with
33 additions
and
7 deletions
Show diff stats
fz/out-paccs.pl
... | ... | @@ -4,9 +4,9 @@ |
4 | 4 | |
5 | 5 | cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- |
6 | 6 | cg_prefix(TEXT, PTXT), |
7 | - cg_preds(PS, ST, PTXT, VTXT), | |
8 | - cg_vars(decl, VS, ST, VTXT, CTXT), | |
9 | - cg_vars(init, VS, ST, VTXT, CTXT), | |
7 | + cg_preds(PS, ST, PTXT, VTXT1), | |
8 | + cg_vars(decl, VS, ST, VTXT1, VTXT2), | |
9 | + cg_vars(init, VS, ST, VTXT2, CTXT), | |
10 | 10 | %% cg_constrs(CTXT, GTXT, CS, ST), |
11 | 11 | %% cg_goal(GTXT, STXT, G, VS, ST), |
12 | 12 | %% cg_suffix(STXT, []), |
... | ... | @@ -28,21 +28,47 @@ cg_var(OP, var(N,int,I,A), ST) --> |
28 | 28 | cg_var(OP, var(N,int(1,999),I,A), ST). % FIXME |
29 | 29 | |
30 | 30 | cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> |
31 | - { format_to_codes(S, "fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, | |
31 | + { format_to_codes(S, " fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, | |
32 | 32 | S. |
33 | 33 | |
34 | 34 | cg_var(init, var(_,int(_,_),_,_), _) --> []. |
35 | 35 | |
36 | -cg_var(decl, var(N,array(T,LB,UB),[],_), _ST) --> | |
36 | +% -- array of variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
37 | + | |
38 | +cg_var(decl, var(N,array(_T,LB,UB),[],_), _ST) --> !, | |
37 | 39 | { SZ is UB-LB+1, |
38 | - format_to_codes(S, "fd_int ~w[~d];\n", [N, SZ]) }, | |
40 | + format_to_codes(S, " fd_int ~w[~d];\n", [N, SZ]) }, | |
39 | 41 | S. |
40 | 42 | |
41 | -cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> | |
43 | +cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, | |
42 | 44 | { SZ is AUB-ALB+1, bound(lb, T, LB), bound(ub, T, UB) }, |
43 | 45 | { format_to_codes(S1, " for (i=0; i<~d; ++i)\n", [SZ]) }, S1, |
44 | 46 | { format_to_codes(S2, " ~w[i] = fd_new(~d, ~d);\n", [N, LB, UB]) }, S2. |
45 | 47 | |
48 | +% -- array of constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
49 | + | |
50 | +cg_var(decl, var(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> | |
51 | + { nonvar(INIT), INIT=[_|_] }, !, | |
52 | + { SZ is UB-LB+1, | |
53 | + format_to_codes(S, " int ~w[~d] = {\n", [N, SZ]) }, | |
54 | + S, | |
55 | + cg_constant_list(INIT, " "), | |
56 | + " };\n". | |
57 | + | |
58 | +cg_var(init, var(_N,array(_T,_LB,_UB),lit(INIT,array(_)),_), _ST) --> | |
59 | + { nonvar(INIT), INIT=[_|_] }, !, | |
60 | + []. | |
61 | + | |
62 | + | |
63 | +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
64 | + | |
65 | +cg_constant_list([], _) --> []. | |
66 | +cg_constant_list([C|Cs], PFX) --> | |
67 | + PFX, cg_constant(C), | |
68 | + cg_constant_list(Cs, ", "). | |
69 | + | |
70 | +cg_constant(lit(N,int)) --> { format_to_codes(S, "~w", [N]) }, S. | |
71 | + | |
46 | 72 | % -- constraints -------------------------------------------------------------- |
47 | 73 | |
48 | 74 | cg_constrs([C|Cs], ST) --> cg_constr(C, ST), cg_constrs(Cs, ST). | ... | ... |