Skip to content

Commit 7211b23

Browse files
author
Adam T. Geller
authored
Merge pull request #6 from wilbowma/canon
Polishing commits
2 parents 4c75b32 + 15ddaa8 commit 7211b23

File tree

9 files changed

+80
-80
lines changed

9 files changed

+80
-80
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ The goal of this model is to provide a starting point for modeling extensions to
66
For example, for a research project we have built an extended type system for WebAssembly on top of this model.
77
There are two straightforward ways to build language extensions using this model:
88

9-
1. The preferred way is to use Redex's `define-extended-*` forms to explicity extend the basic WebAssembly specification. For example, using `define-extended-language` to extend the base WebAssembly syntax with new types or instructions, and then using `define-extended-relation` and `define-extended-judgment` when necessary, or creating new reduction relations and judgement forms.
9+
1. The preferred way is to use Redex's `define-extended-*` forms to explicitly extend the basic WebAssembly specification. For example, using `define-extended-language` to extend the base WebAssembly syntax with new types or instructions, and then using `define-extended-relation` and `define-extended-judgment` when necessary, or creating new reduction relations and judgement forms.
1010
2. Create a fork of this repository, and change the language definition, reduction relation, and judgment forms as needed.
1111

1212
## Syntax
1313
The syntactic representation used in the model is `s-expression` based.
14-
It contains a few more parentheses than are present in the original grammer (to speed up parsing).
14+
It contains a few more parentheses than are present in the original grammar (to simplify parsing).
1515
Other small differences include:
1616
* The removal of the `.` character between types and a number of terminal expressions (e.g., `i32.add` becomes `(i32 add)`).
1717
* The explicit enumeration of the `sx` non-terminal in binops and relops.
1818
* Optional terms are handled via enumeration or faked using lists (there's a hidden low-priority TODO to clean this up).
1919

20-
The WASM Redex language is defined in `Syntax.rkt`. A typeset version can be viewed below and uses similar terminology to the WebAssembly paper.
20+
The WASM Redex syntax is defined in `Syntax.rkt`. A typeset version can be viewed below and uses similar terminology to the WebAssembly paper.
2121

2222
![The WebAssembly language syntax](Syntax.pdf)
2323

2424
## Semantics
2525
WebAssembly introduces several administrative instructions to define the semantics.
2626
Therefore, we extend the base WebAssembly syntax with these forms to create a run-time language, `WASM-Admin`, defined in ![Semantics/AdministrativeSyntax.rkt](Semantics/AdministrativeSyntax.rkt)
2727

28-
The reduction relation is in the form of a small-step operational semantics inside an evaluation context.
29-
The evaluation context, L, keeps track of the list of instructions surrounding the current code block.
28+
The reduction relation is a small-step operational semantics inside an evaluation context.
29+
The evaluation context, `L`, keeps track of the list of instructions surrounding the current code block.
3030
Evaluation contexts can be thought of as being akin to a stack frame.
3131
There are four parameters: `(s v* e*) (-> i) (s v* e*)` with roughly equivalent meaning to the ones in the paper:
3232
* `s`: the store which keeps track of all instances (modules), as well as all function tables and memories.
@@ -46,13 +46,13 @@ The typing rules for instructions are defined in ![Validation/InstructionTyping.
4646
The typing rules for modules and module objects (tables, memories, globals, and functions) are defined in `Validation/ModuleTyping.rkt`,
4747
which provides the `⊢-module-func`, `⊢-module-global`, `⊢-module-table`, `⊢-module-memory`, and `⊢-module` judgment-forms.
4848

49-
In `Validation/Typechecking.rkt` we provide an algorithm for finding a derivation that types a given syntax object.
50-
This algorithm is more complicated than the reference validation algorithm since it needs to synthesize the actual program stacks for instructions after unconditional branches and `unreachable`.
49+
In `Validation/Typechecking.rkt` we provide an inference algorithm for finding a typing derivation over syntax.
50+
This algorithm is more complicated than the reference validation algorithm since it produces a derivation witness, and needs to synthesize the actual program stacks for instructions after unconditional branches and `unreachable`.
5151

5252
The typechecking algorithm is split between typechecking functions for each judgment-form.
5353
* `typecheck-module` produces derivations of `⊢-module` for a given `mod`.
5454
* `typecheck-table` produces derivations of `⊢-module-table` for a given context and `tab`.
5555
* `memory-derivation` produces derivations of `⊢-module-memory` for a given context and `mem`.
5656
* `typecheck-global` produces derivations of `⊢-module-global` for a given context and `glob`.
5757
* `typecheck-func` produces derivations of `⊢-module-func` for a given context and `func`.
58-
* `typecheck-ins` produces derivaitions of `` for a given context, `e*`, and pre- and post-stacks.
58+
* `typecheck-ins` produces derivations of `` for a given context, `e*`, and pre- and post-stacks.

Semantics/SimpleOps.rkt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,59 @@
1414
; equivalent to unop_t(c)
1515
(define-metafunction WASM-Admin
1616
eval-unop : unop t c -> c
17-
17+
1818
[(eval-unop clz t c) ,(sized-clz (term (bit-width t)) (term c))]
1919
[(eval-unop ctz t c) ,(sized-ctz (term (bit-width t)) (term c))]
2020
[(eval-unop popcnt t c) ,(sized-popcnt (term (bit-width t)) (term c))]
2121
[(eval-unop abs t c) ,(abs (term c))]
2222
[(eval-unop neg t c) ,(- (term c))]
23-
23+
2424
[(eval-unop sqrt f32 c)
2525
,(if (negative? (term c))
2626
+nan.0
2727
(flsingle (flsqrt (term c))))]
28-
28+
2929
[(eval-unop sqrt f64 c)
3030
,(if (negative? (term c))
3131
+nan.0
3232
(flsqrt (term c)))]
33-
33+
3434
[(eval-unop ceil t c) ,(ceiling (term c))]
3535
[(eval-unop floor t c) ,(floor (term c))]
3636
[(eval-unop nearest t c) ,(round (term c))])
3737

3838
; equivalent to binop_t(c1, c2)
3939
(define-metafunction WASM-Admin
4040
eval-binop : binop t c c -> (c ...)
41-
41+
4242
[(eval-binop add inn c_1 c_2) (,(sized-add (term (bit-width inn)) (term c_1) (term c_2)))]
4343
[(eval-binop sub inn c_1 c_2) (,(sized-sub (term (bit-width inn)) (term c_1) (term c_2)))]
4444
[(eval-binop mul inn c_1 c_2) (,(sized-mul (term (bit-width inn)) (term c_1) (term c_2)))]
45-
45+
4646
[(eval-binop div-s inn c_1 c_2)
4747
(,(sized-signed-div (term (bit-width inn)) (term c_1) (term c_2)))
4848
(side-condition (not (equal? (term c_2) 0)))
4949
or
5050
()]
51-
51+
5252
[(eval-binop div-u inn c_1 c_2)
5353
(,(sized-unsigned-div (term (bit-width inn)) (term c_1) (term c_2)))
5454
(side-condition (not (equal? (term c_2) 0)))
5555
or
5656
()]
57-
57+
5858
[(eval-binop rem-s inn c_1 c_2)
5959
(,(sized-signed-rem (term (bit-width inn)) (term c_1) (term c_2)))
6060
(side-condition (not (equal? (term c_2) 0)))
6161
or
6262
()]
63-
63+
6464
[(eval-binop rem-u inn c_1 c_2)
6565
(,(sized-unsigned-rem (term (bit-width inn)) (term c_1) (term c_2)))
6666
(side-condition (not (equal? (term c_2) 0)))
6767
or
6868
()]
69-
69+
7070
[(eval-binop and inn c_1 c_2) (,(bitwise-and (term c_1) (term c_2)))]
7171
[(eval-binop or inn c_1 c_2) (,(bitwise-ior (term c_1) (term c_2)))]
7272
[(eval-binop xor inn c_1 c_2) (,(bitwise-xor (term c_1) (term c_2)))]
@@ -75,21 +75,21 @@
7575
[(eval-binop shr-u inn c_1 c_2) (,(sized-unsigned-shr (term (bit-width inn)) (term c_1) (term c_2)))]
7676
[(eval-binop rotl inn c_1 c_2) (,(sized-rotl (term (bit-width inn)) (term c_1) (term c_2)))]
7777
[(eval-binop rotr inn c_1 c_2) (,(sized-rotr (term (bit-width inn)) (term c_1) (term c_2)))]
78-
79-
78+
79+
8080
[(eval-binop add f32 c_1 c_2) (,(flsingle (fl+ (term c_1) (term c_2))))]
8181
[(eval-binop sub f32 c_1 c_2) (,(flsingle (fl- (term c_1) (term c_2))))]
8282
[(eval-binop mul f32 c_1 c_2) (,(flsingle (fl* (term c_1) (term c_2))))]
8383
[(eval-binop div f32 c_1 c_2) (,(flsingle (fl/ (term c_1) (term c_2))))]
84-
84+
8585
[(eval-binop add f64 c_1 c_2) (,(fl+ (term c_1) (term c_2)))]
8686
[(eval-binop sub f64 c_1 c_2) (,(fl- (term c_1) (term c_2)))]
8787
[(eval-binop mul f64 c_1 c_2) (,(fl* (term c_1) (term c_2)))]
8888
[(eval-binop div f64 c_1 c_2) (,(fl/ (term c_1) (term c_2)))]
89-
89+
9090
[(eval-binop min fnn c_1 c_2) (,(flmin (term c_1) (term c_2)))]
9191
[(eval-binop max fnn c_1 c_2) (,(flmax (term c_1) (term c_2)))]
92-
92+
9393
[(eval-binop copysign fnn c_1 c_2)
9494
(,(if (or (negative? (term c_2))
9595
(fl= (term c_2) -0.0))
@@ -105,20 +105,20 @@
105105

106106
(define-metafunction WASM-Admin
107107
eval-relop : relop t c c -> c
108-
108+
109109
[(eval-relop eq t c_1 c_2) (bool ,(= (term c_1) (term c_2)))]
110110
[(eval-relop ne t c_1 c_2) (bool ,(not (= (term c_1) (term c_2))))]
111111

112112
[(eval-relop lt-u t c_1 c_2) (bool ,(< (term c_1) (term c_2)))]
113113
[(eval-relop gt-u t c_1 c_2) (bool ,(> (term c_1) (term c_2)))]
114114
[(eval-relop le-u t c_1 c_2) (bool ,(<= (term c_1) (term c_2)))]
115115
[(eval-relop ge-u t c_1 c_2) (bool ,(>= (term c_1) (term c_2)))]
116-
116+
117117
[(eval-relop lt-s t c_1 c_2) (bool ,(< (term (signed t c_1)) (term (signed t c_2))))]
118118
[(eval-relop gt-s t c_1 c_2) (bool ,(> (term (signed t c_1)) (term (signed t c_2))))]
119119
[(eval-relop le-s t c_1 c_2) (bool ,(<= (term (signed t c_1)) (term (signed t c_2))))]
120120
[(eval-relop ge-s t c_1 c_2) (bool ,(>= (term (signed t c_1)) (term (signed t c_2))))]
121-
121+
122122
[(eval-relop lt t c_1 c_2) (bool ,(fl< (term c_1) (term c_2)))]
123123
[(eval-relop gt t c_1 c_2) (bool ,(fl> (term c_1) (term c_2)))]
124124
[(eval-relop le t c_1 c_2) (bool ,(fl<= (term c_1) (term c_2)))]
@@ -131,7 +131,7 @@
131131
[(do-convert i64 i32 () c) (,(to-unsigned-sized 32 (term c)))]
132132
[(do-convert i32 i64 (signed) c) (,(to-unsigned-sized 64 (to-signed-sized 32 (term c))))]
133133
[(do-convert i32 i64 (unsigned) c) (c)]
134-
134+
135135
[(do-convert f64 f32 () c) (,(flsingle (term c)))]
136136
[(do-convert f32 f64 () c) (c)]
137137

@@ -149,9 +149,9 @@
149149
(expt 2 (sub1 (term (bit-width inn))))))
150150
or
151151
()]
152-
152+
153153
[(do-convert fnn inn (unsigned) c)
154154
(,(fl->exact-integer (truncate (term c))))
155155
(side-condition (< -1 (truncate (term c)) (expt 2 (term (bit-width inn)))))
156156
or
157-
()])
157+
()])

0 commit comments

Comments
 (0)