Skip to content

Commit 20292e4

Browse files
committed
C backend: make and, or lazy
as would normally be expected ?
1 parent 298f810 commit 20292e4

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

compiler/scalc/to_c.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ let rec format_expression
328328
~pp_sep:(fun fmt () -> Format.fprintf fmt ",@ ")
329329
format_expression)
330330
args
331+
| EAppOp { op = ((And | Or) as op), _; args; _ } ->
332+
Format.fprintf fmt "catala_new_bool(@[<hov 0>%a)@]"
333+
(Format.pp_print_list
334+
~pp_sep:(fun fmt () ->
335+
Format.fprintf fmt " %s@ "
336+
(match op with And -> "&&" | Or -> "||" | _ -> assert false))
337+
(fun fmt e -> Format.fprintf fmt "*(%a)" format_expression e))
338+
args
331339
| EAppOp { op; args; _ } ->
332340
Format.fprintf fmt "%a(@[<hov 0>%a)@]" format_op op
333341
(Format.pp_print_list

runtimes/c/runtime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ static mpz_t zconst_100;
155155
mpq_ptr X = catala_malloc(sizeof(__mpq_struct)); \
156156
mpq_init(X)
157157

158+
CATALA_BOOL catala_new_bool(const int x)
159+
{
160+
return CATALA_NEW_BOOL(x);
161+
}
162+
158163
CATALA_INT catala_new_int(const signed long int val)
159164
{
160165
CATALA_NEW_MPZ(ret);

runtimes/c/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ CATALA_BOOL catala_isnone (const CATALA_OPTION() opt);
126126

127127
/* --- Constructors --- */
128128

129+
CATALA_BOOL catala_new_bool(const int);
130+
129131
CATALA_INT catala_new_int(const signed long int val);
130132

131133
/* Arg is a null-terminated string */

0 commit comments

Comments
 (0)