@@ -114,22 +114,22 @@ and ty_tag = { tag_id: opaque_id;
114
114
(* In closed type terms a constraint may refer to components of the term by
115
115
* anchoring off the "formal symbol" '*', which represents "the term this
116
116
* constraint is attached to".
117
- *
118
- *
117
+ *
118
+ *
119
119
* For example, if I have a tuple type tup(int,int), I may wish to enforce the
120
120
* lt predicate on it; I can write this as a constrained type term like:
121
- *
121
+ *
122
122
* tup(int,int) : lt( *._0, *._1 )
123
- *
123
+ *
124
124
* In fact all tuple types are converted to this form for purpose of
125
125
* type-compatibility testing; the argument tuple in a function
126
- *
126
+ *
127
127
* fn (int x, int y) : lt(x, y) -> int
128
- *
128
+ *
129
129
* desugars to
130
- *
130
+ *
131
131
* fn (tup(int, int) : lt( *._1, *._2 )) -> int
132
- *
132
+ *
133
133
*)
134
134
135
135
and carg_base =
@@ -353,7 +353,7 @@ and plval =
353
353
| PLVAL_ext_pexp of (pexp * pexp)
354
354
| PLVAL_ext_deref of pexp
355
355
356
- and pexp = pexp' Common. identified
356
+ and pexp = pexp' identified
357
357
358
358
and lit =
359
359
| LIT_nil
@@ -481,6 +481,9 @@ and crate' =
481
481
and crate = crate' identified
482
482
;;
483
483
484
+
485
+ (* Utility values and functions. *)
486
+
484
487
let empty_crate' =
485
488
{ crate_items = ({ view_imports = Hashtbl. create 0 ;
486
489
view_exports = Hashtbl. create 0 },
@@ -511,9 +514,82 @@ let sane_name (n:name) : bool =
511
514
| NAME_ext (prefix , _ ) -> sane_prefix prefix
512
515
;;
513
516
517
+ (*
518
+ * We have multiple subset-categories of expression:
519
+ *
520
+ * - Atomic expressions are just atomic-lvals and literals.
521
+ *
522
+ * - Primitive expressions are 1-level, machine-level operations on atomic
523
+ * expressions (so: 1-level binops and unops on atomics)
524
+ * - Constant expressions are those that can be evaluated at compile time,
525
+ * without calling user code or accessing the communication subsystem. So
526
+ * all expressions aside from call, port, chan or spawn, applied to all
527
+ * lvals that are themselves constant.
528
+
529
+ *
530
+ * We similarly have multiple subset-categories of lval:
531
+ *
532
+ * - Name lvals are those that contain no dynamic indices.
533
+ *
534
+ * - Atomic lvals are those indexed by atomic expressions.
535
+ *
536
+ * - Constant lvals are those that are only indexed by constant expressions.
537
+ *
538
+ * Rationales:
539
+ *
540
+ * - The primitives are those that can be evaluated without adjusting
541
+ * reference counts or otherwise perturbing the lifecycle of anything
542
+ * dynamically allocated.
543
+ *
544
+ * - The atomics exist to define the sub-structure of the primitives.
545
+ *
546
+ * - The constants are those we'll compile to read-only memory, either
547
+ * immediates in the code-stream or frags in the .rodata section.
548
+ *
549
+ * Note:
550
+ *
551
+ * - Constant-expression-ness is defined in semant, and can only be judged
552
+ * after resolve has run and connected idents with bindings.
553
+ *)
554
+
555
+ let rec plval_is_atomic (plval :plval ) : bool =
556
+ match plval with
557
+ PLVAL_ident _
558
+ | PLVAL_app _ -> true
559
+
560
+ | PLVAL_ext_name (p , _ ) ->
561
+ pexp_is_atomic p
562
+
563
+ | PLVAL_ext_pexp (a , b ) ->
564
+ (pexp_is_atomic a) &&
565
+ (pexp_is_atomic b)
566
+
567
+ | PLVAL_ext_deref p ->
568
+ pexp_is_atomic p
569
+
570
+ and pexp_is_atomic (pexp :pexp ) : bool =
571
+ match pexp.node with
572
+ PEXP_lval pl -> plval_is_atomic pl
573
+ | PEXP_lit _ -> true
574
+ | _ -> false
575
+ ;;
576
+
577
+
578
+ let pexp_is_primitive (pexp :pexp ) : bool =
579
+ match pexp.node with
580
+ PEXP_binop (_ , a , b ) ->
581
+ (pexp_is_atomic a) &&
582
+ (pexp_is_atomic b)
583
+ | PEXP_unop (_ , p ) ->
584
+ pexp_is_atomic p
585
+ | PEXP_lval pl ->
586
+ plval_is_atomic pl
587
+ | PEXP_lit _ -> true
588
+ | _ -> false
589
+ ;;
514
590
515
- (* **********************************************************************)
516
591
592
+ (* Pretty-printing. *)
517
593
518
594
let fmt_ident (ff :Format.formatter ) (i :ident ) : unit =
519
595
fmt ff " %s" i
0 commit comments