diff --git a/fz/out-paccs.pl b/fz/out-paccs.pl index a936322..27c7c8d 100644 --- a/fz/out-paccs.pl +++ b/fz/out-paccs.pl @@ -4,9 +4,9 @@ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- cg_prefix(TEXT, PTXT), - cg_preds(PS, ST, PTXT, VTXT), - cg_vars(decl, VS, ST, VTXT, CTXT), - cg_vars(init, VS, ST, VTXT, CTXT), + cg_preds(PS, ST, PTXT, VTXT1), + cg_vars(decl, VS, ST, VTXT1, VTXT2), + cg_vars(init, VS, ST, VTXT2, CTXT), %% cg_constrs(CTXT, GTXT, CS, ST), %% cg_goal(GTXT, STXT, G, VS, ST), %% cg_suffix(STXT, []), @@ -28,21 +28,47 @@ cg_var(OP, var(N,int,I,A), ST) --> cg_var(OP, var(N,int(1,999),I,A), ST). % FIXME cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> - { format_to_codes(S, "fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, + { format_to_codes(S, " fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, S. cg_var(init, var(_,int(_,_),_,_), _) --> []. -cg_var(decl, var(N,array(T,LB,UB),[],_), _ST) --> +% -- array of variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +cg_var(decl, var(N,array(_T,LB,UB),[],_), _ST) --> !, { SZ is UB-LB+1, - format_to_codes(S, "fd_int ~w[~d];\n", [N, SZ]) }, + format_to_codes(S, " fd_int ~w[~d];\n", [N, SZ]) }, S. -cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> +cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, { SZ is AUB-ALB+1, bound(lb, T, LB), bound(ub, T, UB) }, { format_to_codes(S1, " for (i=0; i<~d; ++i)\n", [SZ]) }, S1, { format_to_codes(S2, " ~w[i] = fd_new(~d, ~d);\n", [N, LB, UB]) }, S2. +% -- array of constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +cg_var(decl, var(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> + { nonvar(INIT), INIT=[_|_] }, !, + { SZ is UB-LB+1, + format_to_codes(S, " int ~w[~d] = {\n", [N, SZ]) }, + S, + cg_constant_list(INIT, " "), + " };\n". + +cg_var(init, var(_N,array(_T,_LB,_UB),lit(INIT,array(_)),_), _ST) --> + { nonvar(INIT), INIT=[_|_] }, !, + []. + + +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +cg_constant_list([], _) --> []. +cg_constant_list([C|Cs], PFX) --> + PFX, cg_constant(C), + cg_constant_list(Cs, ", "). + +cg_constant(lit(N,int)) --> { format_to_codes(S, "~w", [N]) }, S. + % -- constraints -------------------------------------------------------------- cg_constrs([C|Cs], ST) --> cg_constr(C, ST), cg_constrs(Cs, ST). -- libgit2 0.21.2