diff --git a/fz/paccs/output.pl b/fz/paccs/output.pl index 27c7c8d..ee72783 100644 --- a/fz/paccs/output.pl +++ b/fz/paccs/output.pl @@ -3,16 +3,18 @@ % == Code generation for PaCCS ================================================ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- - cg_prefix(TEXT, PTXT), - 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, []), - cg_suffix(CTXT, []), + cg_emit(PS, VS, CS, G, ST, TEXT, []), format("~s\n", [TEXT]). +cg_emit(PS, VS, CS, G, ST) --> + cg_prefix, + cg_preds(PS, ST), + cg_vars(decl, VS, ST), + cg_vars(init, VS, ST), + %% cg_constrs(CS, ST), + cg_goal(G, VS, ST), + cg_suffix. + % == DCGs for code generation ================================================= % -- predicates --------------------------------------------------------------- @@ -78,7 +80,7 @@ cg_constr(_C, _ST) --> []. % FIXME: temporary % -- goal --------------------------------------------------------------------- -cg_goal(satisfy, VS, ST) --> +cg_goal(solve(satisfy,_), VS, ST) --> "\n", " if (fd_solve()) {\n", cg_var_print(VS, ST, " "), @@ -87,7 +89,7 @@ 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(~w);\n", [PFX, N]) }, S, cg_var_print(Vs, ST, PFX). cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). @@ -95,6 +97,8 @@ cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). % -- prefix and suffix -------------------------------------------------------- cg_prefix --> + "#include \"paccs.h\"\n\n", + "main()\n", "{\n", " int i, j;\n". -- libgit2 0.21.2