@@ -20,9 +20,9 @@ type pexp' =
20
20
PEXP_call of (pexp * pexp array )
21
21
| PEXP_spawn of (Ast .domain * pexp )
22
22
| PEXP_bind of (pexp * pexp option array )
23
- | PEXP_rec of ((Ast .ident * pexp ) array * pexp option )
24
- | PEXP_tup of (pexp array )
25
- | PEXP_vec of (pexp array )
23
+ | PEXP_rec of ((Ast .ident * Ast .mutability * pexp ) array * pexp option )
24
+ | PEXP_tup of (( Ast .mutability * pexp ) array )
25
+ | PEXP_vec of Ast .mutability * (pexp array )
26
26
| PEXP_port
27
27
| PEXP_chan of (pexp option )
28
28
| PEXP_binop of (Ast .binop * pexp * pexp )
@@ -32,8 +32,7 @@ type pexp' =
32
32
| PEXP_lval of plval
33
33
| PEXP_lit of Ast .lit
34
34
| PEXP_str of string
35
- | PEXP_mutable of pexp
36
- | PEXP_box of pexp
35
+ | PEXP_box of Ast .mutability * pexp
37
36
| PEXP_custom of Ast .name * (pexp array ) * (string option )
38
37
39
38
and plval =
@@ -177,6 +176,11 @@ and parse_effect (ps:pstate) : Ast.effect =
177
176
| UNSAFE -> bump ps; Ast. UNSAFE
178
177
| _ -> Ast. PURE
179
178
179
+ and parse_mutability (ps :pstate ) : Ast.mutability =
180
+ match peek ps with
181
+ MUTABLE -> bump ps; Ast. MUT_mutable
182
+ | _ -> Ast. MUT_immutable
183
+
180
184
and parse_ty_fn
181
185
(effect :Ast.effect )
182
186
(ps :pstate )
@@ -421,13 +425,14 @@ and parse_ty (ps:pstate) : Ast.ty =
421
425
parse_constrained_ty ps
422
426
423
427
424
- and parse_rec_input (ps :pstate ) : (Ast.ident * pexp) =
428
+ and parse_rec_input (ps :pstate ) : (Ast.ident * Ast.mutability * pexp) =
429
+ let mutability = parse_mutability ps in
425
430
let lab = (ctxt " rec input: label" parse_ident ps) in
426
431
match peek ps with
427
432
EQ ->
428
433
bump ps;
429
434
let pexp = ctxt " rec input: expr" parse_pexp ps in
430
- (lab, pexp)
435
+ (lab, mutability, pexp)
431
436
| _ -> raise (unexpected ps)
432
437
433
438
@@ -439,7 +444,7 @@ and parse_rec_body (ps:pstate) : pexp' = (*((Ast.ident * pexp) array) =*)
439
444
| WITH -> raise (err " empty record extension" ps)
440
445
| _ ->
441
446
let inputs = one_or_more COMMA parse_rec_input ps in
442
- let labels = Array. map (fun (l , _ ) -> l) inputs in
447
+ let labels = Array. map (fun (l , _ , _ ) -> l) inputs in
443
448
begin
444
449
check_dup_rec_labels ps labels;
445
450
match peek ps with
@@ -472,21 +477,18 @@ and parse_bottom_pexp (ps:pstate) : pexp =
472
477
let apos = lexpos ps in
473
478
match peek ps with
474
479
475
- MUTABLE ->
476
- bump ps;
477
- let inner = parse_pexp ps in
478
- let bpos = lexpos ps in
479
- span ps apos bpos (PEXP_mutable inner)
480
-
481
- | AT ->
480
+ AT ->
482
481
bump ps;
482
+ let mutability = parse_mutability ps in
483
483
let inner = parse_pexp ps in
484
484
let bpos = lexpos ps in
485
- span ps apos bpos (PEXP_box inner)
485
+ span ps apos bpos (PEXP_box (mutability, inner) )
486
486
487
487
| TUP ->
488
488
bump ps;
489
- let pexps = ctxt " paren pexps(s)" (rstr false parse_pexp_list) ps in
489
+ let pexps =
490
+ ctxt " paren pexps(s)" (rstr false parse_mutable_and_pexp_list) ps
491
+ in
490
492
let bpos = lexpos ps in
491
493
span ps apos bpos (PEXP_tup pexps)
492
494
@@ -498,11 +500,18 @@ and parse_bottom_pexp (ps:pstate) : pexp =
498
500
499
501
| VEC ->
500
502
bump ps;
501
- begin
502
- let pexps = ctxt " vec pexp: exprs" parse_pexp_list ps in
503
- let bpos = lexpos ps in
504
- span ps apos bpos (PEXP_vec pexps)
505
- end
503
+ let mutability =
504
+ match peek ps with
505
+ LBRACKET ->
506
+ bump ps;
507
+ expect ps MUTABLE ;
508
+ expect ps RBRACKET ;
509
+ Ast. MUT_mutable
510
+ | _ -> Ast. MUT_immutable
511
+ in
512
+ let pexps = ctxt " vec pexp: exprs" parse_pexp_list ps in
513
+ let bpos = lexpos ps in
514
+ span ps apos bpos (PEXP_vec (mutability, pexps))
506
515
507
516
508
517
| LIT_STR s ->
@@ -947,6 +956,9 @@ and parse_as_pexp (ps:pstate) : pexp =
947
956
and parse_pexp (ps :pstate ) : pexp =
948
957
parse_as_pexp ps
949
958
959
+ and parse_mutable_and_pexp (ps :pstate ) : (Ast.mutability * pexp) =
960
+ let mutability = parse_mutability ps in
961
+ (mutability, parse_as_pexp ps)
950
962
951
963
and parse_pexp_list (ps :pstate ) : pexp array =
952
964
match peek ps with
@@ -955,6 +967,13 @@ and parse_pexp_list (ps:pstate) : pexp array =
955
967
(ctxt " pexp list" parse_pexp) ps
956
968
| _ -> raise (unexpected ps)
957
969
970
+ and parse_mutable_and_pexp_list (ps :pstate ) : (Ast.mutability * pexp) array =
971
+ match peek ps with
972
+ LPAREN ->
973
+ bracketed_zero_or_more LPAREN RPAREN (Some COMMA )
974
+ (ctxt " mutable-and-pexp list" parse_mutable_and_pexp) ps
975
+ | _ -> raise (unexpected ps)
976
+
958
977
;;
959
978
960
979
(*
@@ -1099,8 +1118,7 @@ and desugar_expr_atom
1099
1118
| PEXP_bind _
1100
1119
| PEXP_spawn _
1101
1120
| PEXP_custom _
1102
- | PEXP_box _
1103
- | PEXP_mutable _ ->
1121
+ | PEXP_box _ ->
1104
1122
let (_, tmp, decl_stmt) = build_tmp ps slot_auto apos bpos in
1105
1123
let stmts = desugar_expr_init ps tmp pexp in
1106
1124
(Array. append [| decl_stmt |] stmts,
@@ -1233,11 +1251,11 @@ and desugar_expr_init
1233
1251
begin
1234
1252
Array. map
1235
1253
begin
1236
- fun (ident , pexp ) ->
1254
+ fun (ident , mutability , pexp ) ->
1237
1255
let (stmts, atom) =
1238
1256
desugar_expr_atom ps pexp
1239
1257
in
1240
- (stmts, (ident, atom))
1258
+ (stmts, (ident, mutability, atom))
1241
1259
end
1242
1260
args
1243
1261
end
@@ -1259,19 +1277,24 @@ and desugar_expr_init
1259
1277
end
1260
1278
1261
1279
| PEXP_tup args ->
1280
+ let muts = Array. to_list (Array. map fst args) in
1262
1281
let (arg_stmts, arg_atoms) =
1263
- desugar_expr_atoms ps args
1282
+ desugar_expr_atoms ps ( Array. map snd args)
1264
1283
in
1265
- let stmt = ss (Ast. STMT_init_tup (dst_lval, arg_atoms)) in
1284
+ let arg_atoms = Array. to_list arg_atoms in
1285
+ let tup_args = Array. of_list (List. combine muts arg_atoms) in
1286
+ let stmt = ss (Ast. STMT_init_tup (dst_lval, tup_args)) in
1266
1287
aa arg_stmts [| stmt |]
1267
1288
1268
1289
| PEXP_str s ->
1269
1290
let stmt = ss (Ast. STMT_init_str (dst_lval, s)) in
1270
1291
[| stmt |]
1271
1292
1272
- | PEXP_vec args ->
1293
+ | PEXP_vec ( mutability , args ) ->
1273
1294
let (arg_stmts, arg_atoms) = desugar_expr_atoms ps args in
1274
- let stmt = ss (Ast. STMT_init_vec (dst_lval, arg_atoms)) in
1295
+ let stmt =
1296
+ ss (Ast. STMT_init_vec (dst_lval, mutability, arg_atoms))
1297
+ in
1275
1298
aa arg_stmts [| stmt |]
1276
1299
1277
1300
| PEXP_port ->
@@ -1296,20 +1319,15 @@ and desugar_expr_init
1296
1319
in
1297
1320
aa port_stmts [| chan_stmt |]
1298
1321
1299
- | PEXP_box arg ->
1322
+ | PEXP_box ( mutability , arg ) ->
1300
1323
let (arg_stmts, arg_mode_atom) =
1301
1324
desugar_expr_atom ps arg
1302
1325
in
1303
- let stmt = ss (Ast. STMT_init_box (dst_lval, arg_mode_atom)) in
1326
+ let stmt =
1327
+ ss (Ast. STMT_init_box (dst_lval, mutability, arg_mode_atom))
1328
+ in
1304
1329
aa arg_stmts [| stmt |]
1305
1330
1306
- | PEXP_mutable arg ->
1307
- (* Initializing a local from a "mutable" atom is the same as
1308
- * initializing it from an immutable one; all locals are mutable
1309
- * anyways. So this is just a fall-through.
1310
- *)
1311
- desugar_expr_init ps dst_lval arg
1312
-
1313
1331
| PEXP_custom (n , a , b ) ->
1314
1332
let (arg_stmts, args) = desugar_expr_atoms ps a in
1315
1333
let stmts =
0 commit comments