|
@@ -41,6 +41,14 @@ module Ast = struct
|
|
|
| Comment of 'a
|
|
|
| Call of 'a * T.keywords * 'a expression list
|
|
|
| Location of 'a * string
|
|
|
+ | For of {
|
|
|
+ loc : 'a;
|
|
|
+ variable : 'a variable;
|
|
|
+ start : 'a expression;
|
|
|
+ to_ : 'a expression;
|
|
|
+ step : 'a expression option;
|
|
|
+ statements : 'a statement list;
|
|
|
+ }
|
|
|
[@@deriving eq, show]
|
|
|
end
|
|
|
|
|
@@ -156,6 +164,25 @@ module Instruction :
|
|
|
fun pos_loc { pos; name; index } op expr ->
|
|
|
(*let index = Option.map (fun i -> fst @@ Expression.observe (i [])) index*)
|
|
|
Ast.Declaration (pos_loc, { pos; name; index }, op, expr)
|
|
|
+
|
|
|
+ let for_ :
|
|
|
+ S.pos ->
|
|
|
+ (S.pos, Expression.t') S.variable ->
|
|
|
+ start:Expression.t' ->
|
|
|
+ to_:Expression.t' ->
|
|
|
+ step:Expression.t' option ->
|
|
|
+ t list ->
|
|
|
+ t =
|
|
|
+ fun loc variable ~start ~to_ ~step statements ->
|
|
|
+ let variable =
|
|
|
+ Ast.
|
|
|
+ {
|
|
|
+ pos = variable.S.pos;
|
|
|
+ name = variable.S.name;
|
|
|
+ index = variable.S.index;
|
|
|
+ }
|
|
|
+ in
|
|
|
+ Ast.For { loc; variable; start; to_; step; statements }
|
|
|
end
|
|
|
|
|
|
module Location = struct
|