Commit 567a1567b812d6e6e5ec90bd97cb08cffcae3dce
1 parent
e88c58ae
Exists in
master
now doing output
Showing
1 changed file
with
14 additions
and
10 deletions
Show diff stats
fz/paccs/output.pl
@@ -3,16 +3,18 @@ | @@ -3,16 +3,18 @@ | ||
3 | % == Code generation for PaCCS ================================================ | 3 | % == Code generation for PaCCS ================================================ |
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), | ||
7 | - cg_preds(PS, ST, PTXT, VTXT1), | ||
8 | - cg_vars(decl, VS, ST, VTXT1, VTXT2), | ||
9 | - cg_vars(init, VS, ST, VTXT2, CTXT), | ||
10 | - %% cg_constrs(CTXT, GTXT, CS, ST), | ||
11 | - %% cg_goal(GTXT, STXT, G, VS, ST), | ||
12 | - %% cg_suffix(STXT, []), | ||
13 | - cg_suffix(CTXT, []), | 6 | + cg_emit(PS, VS, CS, G, ST, TEXT, []), |
14 | format("~s\n", [TEXT]). | 7 | format("~s\n", [TEXT]). |
15 | 8 | ||
9 | +cg_emit(PS, VS, CS, G, ST) --> | ||
10 | + cg_prefix, | ||
11 | + cg_preds(PS, ST), | ||
12 | + cg_vars(decl, VS, ST), | ||
13 | + cg_vars(init, VS, ST), | ||
14 | + %% cg_constrs(CS, ST), | ||
15 | + cg_goal(G, VS, ST), | ||
16 | + cg_suffix. | ||
17 | + | ||
16 | % == DCGs for code generation ================================================= | 18 | % == DCGs for code generation ================================================= |
17 | 19 | ||
18 | % -- predicates --------------------------------------------------------------- | 20 | % -- predicates --------------------------------------------------------------- |
@@ -78,7 +80,7 @@ cg_constr(_C, _ST) --> []. % FIXME: temporary | @@ -78,7 +80,7 @@ cg_constr(_C, _ST) --> []. % FIXME: temporary | ||
78 | 80 | ||
79 | % -- goal --------------------------------------------------------------------- | 81 | % -- goal --------------------------------------------------------------------- |
80 | 82 | ||
81 | -cg_goal(satisfy, VS, ST) --> | 83 | +cg_goal(solve(satisfy,_), VS, ST) --> |
82 | "\n", | 84 | "\n", |
83 | " if (fd_solve()) {\n", | 85 | " if (fd_solve()) {\n", |
84 | cg_var_print(VS, ST, " "), | 86 | cg_var_print(VS, ST, " "), |
@@ -87,7 +89,7 @@ cg_goal(satisfy, VS, ST) --> | @@ -87,7 +89,7 @@ cg_goal(satisfy, VS, ST) --> | ||
87 | cg_var_print([], _, _) --> []. | 89 | cg_var_print([], _, _) --> []. |
88 | cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> | 90 | cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> |
89 | { member(output, A), ! }, | 91 | { member(output, A), ! }, |
90 | - { format_to_codes(S, "~sfd_println(~s);\n", [PFX, N]) }, S, | 92 | + { format_to_codes(S, "~sfd_println(~w);\n", [PFX, N]) }, S, |
91 | cg_var_print(Vs, ST, PFX). | 93 | cg_var_print(Vs, ST, PFX). |
92 | cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). | 94 | cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). |
93 | 95 | ||
@@ -95,6 +97,8 @@ 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). | ||
95 | % -- prefix and suffix -------------------------------------------------------- | 97 | % -- prefix and suffix -------------------------------------------------------- |
96 | 98 | ||
97 | cg_prefix --> | 99 | cg_prefix --> |
100 | + "#include \"paccs.h\"\n\n", | ||
101 | + "main()\n", | ||
98 | "{\n", | 102 | "{\n", |
99 | " int i, j;\n". | 103 | " int i, j;\n". |
100 | 104 |