diff options
| author | Alasdair Armstrong | 2017-07-17 18:46:00 +0100 |
|---|---|---|
| committer | Alasdair Armstrong | 2017-07-17 18:46:00 +0100 |
| commit | 1090d8667193e3bc56bfc7a0d028566b36ad3b96 (patch) | |
| tree | bd7c9d69120df927f4ae3ddf6477345f0c009f4f /src/pretty_print_sail.ml | |
| parent | 6c75d9386a9c179969c22baf1231f1bd7b9a60a3 (diff) | |
Added pattern guards to sail
Introduces a when keyword for case statements, as the Pat_when constructor for pexp's in the AST. This allows us to write things like:
typedef T = const union { int C1; int C2 }
function int test ((int) x, (T) y) =
switch y {
case (C1(z)) when z == 0 -> 0
case (C1(z)) when z != 0 -> x quot z
case (C2(z)) -> z
}
this should make translation from ASL's patterns much more straightforward
Diffstat (limited to 'src/pretty_print_sail.ml')
| -rw-r--r-- | src/pretty_print_sail.ml | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/pretty_print_sail.ml b/src/pretty_print_sail.ml index 6826087a..a484bd1f 100644 --- a/src/pretty_print_sail.ml +++ b/src/pretty_print_sail.ml @@ -364,8 +364,12 @@ let doc_exp, doc_let = and doc_fexp (FE_aux(FE_Fexp(id,e),_)) = doc_op equals (doc_id id) (exp e) - and doc_case (Pat_aux(Pat_exp(pat,e),_)) = - doc_op arrow (separate space [string "case"; doc_atomic_pat pat]) (group (exp e)) + and doc_case (Pat_aux (pexp, _)) = + match pexp with + | Pat_exp(pat, e) -> + doc_op arrow (separate space [string "case"; doc_atomic_pat pat]) (group (exp e)) + | Pat_when(pat, guard, e) -> + doc_op arrow (separate space [string "case"; doc_atomic_pat pat; string "when"; exp guard]) (group (exp e)) (* lexps are parsed as eq_exp - we need to duplicate the precedence * structure for them *) |
