From 65f5280014d712150e63a1f621dfd5720423cfff Mon Sep 17 00:00:00 2001 From: Salvador Abreu Date: Fri, 10 Jul 2015 19:17:07 +0900 Subject: [PATCH] paccs output progress --- fz/out-paccs.pl | 54 +++++++++++++++++++++++++++++++++++------------------- fz/types.pl | 10 ++++++++++ 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/fz/out-paccs.pl b/fz/out-paccs.pl index 4af8972..a936322 100644 --- a/fz/out-paccs.pl +++ b/fz/out-paccs.pl @@ -4,12 +4,14 @@ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- cg_prefix(TEXT, PTXT), - cg_preds(PTXT, VTXT, PS, ST), - cg_vars(VTXT, CTXT, VS, ST), - cg_constrs(CTXT, GTXT, CS, ST), - cg_goal(GTXT, STXT, G, VS, ST), - cg_suffix(STXT, []), - format("%s", [TEXT]). + cg_preds(PS, ST, PTXT, VTXT), + cg_vars(decl, VS, ST, VTXT, CTXT), + cg_vars(init, VS, ST, VTXT, CTXT), + %% cg_constrs(CTXT, GTXT, CS, ST), + %% cg_goal(GTXT, STXT, G, VS, ST), + %% cg_suffix(STXT, []), + cg_suffix(CTXT, []), + format("~s\n", [TEXT]). % == DCGs for code generation ================================================= @@ -19,18 +21,27 @@ cg_preds(_PS, _ST) --> []. % -- variables ---------------------------------------------------------------- -cg_vars([V|Vs], ST) --> cg_var(V, ST), cg_vars(Vs, ST). -cg_vars([], _) --> []. +cg_vars(OP, [V|Vs], ST) --> cg_var(OP, V, ST), cg_vars(OP, Vs, ST). +cg_vars(_OP, [], _) --> []. -cg_var(var(N,int(LB,UB),_I,_A), _ST) --> - "fd_int ", - { name(N, NN) }, NN, - { format_to_codes(S, " = fd_new(%d, %d);\n", [LB, UB]) }, S. -cg_var(var(N,int,_I,_A), _ST) --> - "fd_int ", - { name(N, NN) }, NN, - " = fd_new(1, 999);\n". % FIXME: replace with "maxint" +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]) }, + S. + +cg_var(init, var(_,int(_,_),_,_), _) --> []. + +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]) }, + S. + +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. % -- constraints -------------------------------------------------------------- @@ -50,12 +61,17 @@ cg_goal(satisfy, VS, ST) --> cg_var_print([], _, _) --> []. cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> { member(output, A), ! }, - { format_to_codes(S, "%sfd_println(%s);\n", [PFX, N]) }, S, + { format_to_codes(S, "~sfd_println(~s);\n", [PFX, N]) }, S, cg_var_print(Vs, ST, PFX). cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). % -- prefix and suffix -------------------------------------------------------- -cg_prefix --> []. -cg_suffix --> []. +cg_prefix --> + "{\n", + " int i, j;\n". + +cg_suffix --> + "}\n". + diff --git a/fz/types.pl b/fz/types.pl index a06ed22..40c0850 100644 --- a/fz/types.pl +++ b/fz/types.pl @@ -24,3 +24,13 @@ type(float). % floating point type(float(_L,_U)). % floating point interval type(string). % string type(array(T,1,_U)) :- type(T). % array of type + +% bound(lb,T,LB) +% bound(ub,T,UB) + +bound(lb,int(LB,_UB),LB). +bound(lb,int,1). + +bound(ub,int(_LB,UB),UB). +bound(ub,int,999). % FIXME + -- libgit2 0.21.2