Skip to content

Commit acb454d

Browse files
committed
%cd: Allow single-string block comments
1 parent a834849 commit acb454d

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

bin/micrograd_demo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let experiment seed ~no_batch_shape_inference ~use_builtin_weight_decay () =
129129
(module Backend)
130130
routine.context IDX.empty
131131
[%cd
132-
~~("moons" "infer";
132+
~~("moons infer";
133133
mlp_result.forward)]
134134
in
135135
Stdio.print_endline "\n******** mlp_result **********";

bin/moons_demo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let demo () =
109109
(module Backend)
110110
routine.context IDX.empty
111111
[%cd
112-
~~("moons" "infer";
112+
~~("moons infer";
113113
mlp_result.forward)]
114114
in
115115
let callback (x, y) =

lib/ppx_cd.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,22 @@ let translate (expr : expression) : result =
767767
Ast_builder.Default.pexp_extension ~loc
768768
@@ Location.error_extensionf ~loc "ppx_ocannl %%cd: repeated .merge not allowed";
769769
})
770+
| [%expr
771+
~~([%e? { pexp_desc = Pexp_constant (Pconst_string _); _ } as comment];
772+
[%e? expr2])] ->
773+
let res2 = loop ~proj_in_scope expr2 in
774+
{
775+
res2 with
776+
expr =
777+
[%expr
778+
let __comment_block = [%e res2.expr] in
779+
{
780+
Arrayjit.Assignments.asgns =
781+
Arrayjit.Assignments.Block_comment
782+
([%e comment], __comment_block.Arrayjit.Assignments.asgns);
783+
embedded_nodes = __comment_block.Arrayjit.Assignments.embedded_nodes;
784+
}];
785+
}
770786
| [%expr
771787
~~([%e? { pexp_desc = Pexp_apply (expr, exprs); pexp_loc; _ }];
772788
[%e? expr2])] ->

test/micrograd_demo.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ let%expect_test "Micrograd half-moons example" =
167167
(module Backend)
168168
sgd_routine.context IDX.empty
169169
[%cd
170-
~~("moons" "infer";
170+
~~("moons infer";
171171
mlp_result.forward)]
172172
in
173173
let callback (x, y) =

0 commit comments

Comments
 (0)