Commit 65f5280014d712150e63a1f621dfd5720423cfff
1 parent
f77dbaf7
Exists in
master
paccs output progress
Showing
2 changed files
with
45 additions
and
19 deletions
Show diff stats
fz/out-paccs.pl
@@ -4,12 +4,14 @@ | @@ -4,12 +4,14 @@ | ||
4 | 4 | ||
5 | cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- | 5 | cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- |
6 | cg_prefix(TEXT, PTXT), | 6 | cg_prefix(TEXT, PTXT), |
7 | - cg_preds(PTXT, VTXT, PS, ST), | ||
8 | - cg_vars(VTXT, CTXT, VS, ST), | ||
9 | - cg_constrs(CTXT, GTXT, CS, ST), | ||
10 | - cg_goal(GTXT, STXT, G, VS, ST), | ||
11 | - cg_suffix(STXT, []), | ||
12 | - format("%s", [TEXT]). | 7 | + cg_preds(PS, ST, PTXT, VTXT), |
8 | + cg_vars(decl, VS, ST, VTXT, CTXT), | ||
9 | + cg_vars(init, VS, ST, VTXT, CTXT), | ||
10 | + %% cg_constrs(CTXT, GTXT, CS, ST), | ||
11 | + %% cg_goal(GTXT, STXT, G, VS, ST), | ||
12 | + %% cg_suffix(STXT, []), | ||
13 | + cg_suffix(CTXT, []), | ||
14 | + format("~s\n", [TEXT]). | ||
13 | 15 | ||
14 | % == DCGs for code generation ================================================= | 16 | % == DCGs for code generation ================================================= |
15 | 17 | ||
@@ -19,18 +21,27 @@ cg_preds(_PS, _ST) --> []. | @@ -19,18 +21,27 @@ cg_preds(_PS, _ST) --> []. | ||
19 | 21 | ||
20 | % -- variables ---------------------------------------------------------------- | 22 | % -- variables ---------------------------------------------------------------- |
21 | 23 | ||
22 | -cg_vars([V|Vs], ST) --> cg_var(V, ST), cg_vars(Vs, ST). | ||
23 | -cg_vars([], _) --> []. | 24 | +cg_vars(OP, [V|Vs], ST) --> cg_var(OP, V, ST), cg_vars(OP, Vs, ST). |
25 | +cg_vars(_OP, [], _) --> []. | ||
24 | 26 | ||
25 | -cg_var(var(N,int(LB,UB),_I,_A), _ST) --> | ||
26 | - "fd_int ", | ||
27 | - { name(N, NN) }, NN, | ||
28 | - { format_to_codes(S, " = fd_new(%d, %d);\n", [LB, UB]) }, S. | ||
29 | -cg_var(var(N,int,_I,_A), _ST) --> | ||
30 | - "fd_int ", | ||
31 | - { name(N, NN) }, NN, | ||
32 | - " = fd_new(1, 999);\n". % FIXME: replace with "maxint" | 27 | +cg_var(OP, var(N,int,I,A), ST) --> |
28 | + cg_var(OP, var(N,int(1,999),I,A), ST). % FIXME | ||
33 | 29 | ||
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]) }, | ||
32 | + S. | ||
33 | + | ||
34 | +cg_var(init, var(_,int(_,_),_,_), _) --> []. | ||
35 | + | ||
36 | +cg_var(decl, var(N,array(T,LB,UB),[],_), _ST) --> | ||
37 | + { SZ is UB-LB+1, | ||
38 | + format_to_codes(S, "fd_int ~w[~d];\n", [N, SZ]) }, | ||
39 | + S. | ||
40 | + | ||
41 | +cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> | ||
42 | + { SZ is AUB-ALB+1, bound(lb, T, LB), bound(ub, T, UB) }, | ||
43 | + { format_to_codes(S1, " for (i=0; i<~d; ++i)\n", [SZ]) }, S1, | ||
44 | + { format_to_codes(S2, " ~w[i] = fd_new(~d, ~d);\n", [N, LB, UB]) }, S2. | ||
34 | 45 | ||
35 | % -- constraints -------------------------------------------------------------- | 46 | % -- constraints -------------------------------------------------------------- |
36 | 47 | ||
@@ -50,12 +61,17 @@ cg_goal(satisfy, VS, ST) --> | @@ -50,12 +61,17 @@ cg_goal(satisfy, VS, ST) --> | ||
50 | cg_var_print([], _, _) --> []. | 61 | cg_var_print([], _, _) --> []. |
51 | cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> | 62 | cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> |
52 | { member(output, A), ! }, | 63 | { member(output, A), ! }, |
53 | - { format_to_codes(S, "%sfd_println(%s);\n", [PFX, N]) }, S, | 64 | + { format_to_codes(S, "~sfd_println(~s);\n", [PFX, N]) }, S, |
54 | cg_var_print(Vs, ST, PFX). | 65 | cg_var_print(Vs, ST, PFX). |
55 | cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). | 66 | cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). |
56 | 67 | ||
57 | 68 | ||
58 | % -- prefix and suffix -------------------------------------------------------- | 69 | % -- prefix and suffix -------------------------------------------------------- |
59 | 70 | ||
60 | -cg_prefix --> []. | ||
61 | -cg_suffix --> []. | 71 | +cg_prefix --> |
72 | + "{\n", | ||
73 | + " int i, j;\n". | ||
74 | + | ||
75 | +cg_suffix --> | ||
76 | + "}\n". | ||
77 | + |
fz/types.pl
@@ -24,3 +24,13 @@ type(float). % floating point | @@ -24,3 +24,13 @@ type(float). % floating point | ||
24 | type(float(_L,_U)). % floating point interval | 24 | type(float(_L,_U)). % floating point interval |
25 | type(string). % string | 25 | type(string). % string |
26 | type(array(T,1,_U)) :- type(T). % array of type | 26 | type(array(T,1,_U)) :- type(T). % array of type |
27 | + | ||
28 | +% bound(lb,T,LB) | ||
29 | +% bound(ub,T,UB) | ||
30 | + | ||
31 | +bound(lb,int(LB,_UB),LB). | ||
32 | +bound(lb,int,1). | ||
33 | + | ||
34 | +bound(ub,int(_LB,UB),UB). | ||
35 | +bound(ub,int,999). % FIXME | ||
36 | + |