Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Wasm-1.0/2.0 spec #48

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spectec/spec/wasm-1.0/8-reduction.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ rule Step/read:
-- Step_read: z; instr* ~> instr'*


relation Steps: config ~>* config hint(show "E")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move up to other relations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, should I also move rules for Steps above rules for Step?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the relation decl after the others, so the rules can stay here, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, I thought you meant moving Steps relation above other Step relations.


rule Steps/refl:
z; admininstr* ~>* z; admininstr*

rule Steps/trans:
z; admininstr* ~>* z''; admininstr''*
-- Step: z; admininstr* ~> z'; admininstr'*
-- Steps: z'; admininstr' ~>* z''; admininstr''*


;; Expressions

relation Eval_expr: state; expr ~>* state; val* hint(show "E-expr")

rule Eval_expr:
z; instr* ~>* z'; val*
-- Steps: z; instr* ~>* z'; val*


;;
;; Instructions
;;
Expand Down
21 changes: 11 additions & 10 deletions spectec/spec/wasm-1.0/9-module.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,32 @@ def $allocmodule(s, module, externval*, val*) = (s_4, mm)
;; Instantiation
;;

def $concat_instr(instr**) : instr*
def $concat_instr((instr*)*) : instr*
def $concat_instr(epsilon) = epsilon
def $concat_instr(instr* instr'**) = instr* $concat_instr(instr'**)
def $concat_instr((instr*) (instr'*)*) = instr* $concat_instr((instr'*)*)

def $initelem(store, tableaddr, u32*, (funcaddr*)*) : store
def $initelem(s, ta, epsilon, epsilon) = s
def $initelem(s, ta, i i'*, a* (a'*)*) = s[.TABLE[ta].ELEM[i:|a*|] = a*]
def $initelem(s, ta, i i'*, (a*) (a'*)*) = s[.TABLE[ta].ELEM[i:|a*|] = a*]

def $initdata(store, memaddr, u32*, (byte*)*) : store
def $initdata(s, ma, epsilon, epsilon) = s
def $initdata(s, ma, i i'*, b* (b'*)*) = s[.MEM[ma].DATA[i:|b*|] = b*]
def $initdata(s, ma, i i'*, (b*) (b'*)*) = s[.MEM[ma].DATA[i:|b*|] = b*]

def $instantiate(store, module, externval*) : config
def $instantiate(s, module, externval*) = s'; f; (CALL x')?
-- if module = MODULE type* import* func* global* table* mem* elem* data* start? export*
-- if type* = (TYPE functype)*
-- if global* = (GLOBAL globaltype instr_G*)* ;; TODO: expr_G
-- if elem* = (ELEM instr_E* x*)* ;; TODO: expr_E
-- if data* = (DATA instr_D* b*)* ;; TODO: expr_D
-- if global* = (GLOBAL globaltype expr_G)*
-- if elem* = (ELEM expr_E x*)*
-- if data* = (DATA expr_D b*)*
-- if start? = (START x')?
-- if mm_init = {TYPE functype*, FUNC $funcs(externval*), GLOBAL $globals(externval*)}
-- if f_init = { LOCAL epsilon, MODULE mm_init }
-- (Step_read : s; f_init; instr_G* ~> val)*
-- (Step_read : s; f_init; instr_E* ~> (CONST I32 i_E))*
-- (Step_read : s; f_init; instr_D* ~> (CONST I32 i_D))*
-- if z = s; f_init
-- (Eval_expr : z; expr_G ~>* z; val)*
-- (Eval_expr : z; expr_E ~>* z; (CONST I32 i_E))*
-- (Eval_expr : z; expr_D ~>* z; (CONST I32 i_D))*
-- if (s', mm) = $allocmodule(s, module, externval*, val*)
-- if s'' = $initelem(s', mm.TABLE[0], i_E*, mm.FUNC[x]**)
-- if s''' = $initdata(s'', mm.MEM[0], i_D*, b**)
Expand Down
8 changes: 4 additions & 4 deletions spectec/spec/wasm-1.0/A-binary.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ grammar Bf64 : f64 = | p:Bf(64) => p

;; Names

def $concat_bytes(byte**) : byte* hint(show $concat(%))
def $concat_bytes((byte*)*) : byte* hint(show $concat(%))
def $concat_bytes(epsilon) = epsilon
def $concat_bytes(b* b'**) = b* $concat_bytes(b'**)
def $concat_bytes((b*) (b'*)*) = b* $concat_bytes((b'*)*)

def $utf8(name) : byte*
def $utf8(c) = b -- if c < U+0080 /\ c = b
Expand Down Expand Up @@ -496,9 +496,9 @@ grammar Belem : elem =

;; Code section

def $concat_locals(local**) : local* hint(show $concat(%))
def $concat_locals((local*)*) : local* hint(show $concat(%))
def $concat_locals(epsilon) = epsilon
def $concat_locals(loc* loc'**) = loc* $concat_locals(loc'**)
def $concat_locals((loc*) (loc'*)*) = loc* $concat_locals((loc'*)*)


syntax code = (local*, expr)
Expand Down
20 changes: 20 additions & 0 deletions spectec/spec/wasm-2.0/8-reduction.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ rule Step/read:
-- Step_read: z; instr* ~> instr'*


relation Steps: config ~>* config hint(show "E")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


rule Steps/refl:
z; admininstr* ~>* z; admininstr*

rule Steps/trans:
z; admininstr* ~>* z''; admininstr''*
-- Step: z; admininstr* ~> z'; admininstr'*
-- Steps: z'; admininstr' ~>* z''; admininstr''*


;; Expressions

relation Eval_expr: state; expr ~>* state; val* hint(show "E-expr")

rule Eval_expr:
z; instr* ~>* z'; val*
-- Steps: z; instr* ~>* z'; val*


;;
;; Instructions
;;
Expand Down
15 changes: 8 additions & 7 deletions spectec/spec/wasm-2.0/9-module.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def $allocdata(s, byte*) = (s[.DATA =.. di], |s.DATA|)

def $allocdatas(store, (byte*)*) : (store, dataaddr*)
def $allocdatas(s, epsilon) = (s, epsilon)
def $allocdatas(s, byte* byte'**) = (s_2, da da'*)
def $allocdatas(s, (byte*) (byte'*)*) = (s_2, da da'*)
-- if (s_1, da) = $allocdata(s, byte*)
-- if (s_2, da'*) = $allocdatas(s_1, (byte'*)*)

Expand Down Expand Up @@ -151,9 +151,9 @@ def $allocmodule(s, module, externval*, val*, (ref*)*) = (s_6, mm)
;; Instantiation
;;

def $concat_instr(instr**) : instr*
def $concat_instr((instr*)*) : instr*
def $concat_instr(epsilon) = epsilon
def $concat_instr(instr* instr'**) = instr* $concat_instr(instr'**)
def $concat_instr((instr*) (instr'*)*) = instr* $concat_instr((instr'*)*)

def $runelem(elem, idx) : instr*
def $runelem(ELEM reftype expr* (PASSIVE), i) = epsilon
Expand All @@ -172,15 +172,16 @@ def $instantiate(store, module, externval*) : config
def $instantiate(s, module, externval*) = s'; f; instr_E* instr_D* (CALL x)?
-- if module = MODULE type* import* func* global* table* mem* elem* data* start? export*
-- if type* = (TYPE functype)*
-- if global* = (GLOBAL globaltype instr_G*)* ;; TODO: expr_G
-- if elem* = (ELEM reftype instr_E** elemmode)* ;; TODO: expr_E*
-- if global* = (GLOBAL globaltype expr_G)*
-- if elem* = (ELEM reftype expr_E* elemmode)*
-- if start? = (START x)?
-- if n_E = |elem*|
-- if n_D = |data*|
-- if mm_init = {TYPE functype*, FUNC $funcs(externval*), GLOBAL $globals(externval*)}
-- if f_init = { LOCAL epsilon, MODULE mm_init }
-- (Step_read : s; f_init; instr_G* ~> val)*
-- (Step_read : s; f_init; instr_E* ~> ref)**
-- if z = s; f_init
-- (Eval_expr : z; expr_G ~>* z; val)*
-- (Eval_expr : z; expr_E ~>* z; ref)**
-- if (s', mm) = $allocmodule(s, module, externval*, val*, (ref*)*)
-- if f = { LOCAL epsilon, MODULE mm }
-- if instr_E* = $concat_instr($runelem(elem*[i], i)^(i<n_E))
Expand Down
6 changes: 3 additions & 3 deletions spectec/spec/wasm-2.0/A-binary.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ grammar Bf64 : f64 = | p:Bf(64) => p

;; Names

def $concat_bytes(byte**) : byte* hint(show $concat(%))
def $concat_bytes((byte*)*) : byte* hint(show $concat(%))
def $concat_bytes(epsilon) = epsilon
def $concat_bytes(b* b'**) = b* $concat_bytes(b'**)
def $concat_bytes((b*) (b'*)*) = b* $concat_bytes((b'*)*)

def $utf8(name) : byte*
def $utf8(c) = b -- if c < U+0080 /\ c = b
Expand Down Expand Up @@ -576,7 +576,7 @@ grammar Belemkind : reftype hint(desc "element kind") =

def $concat_locals(local**) : local* hint(show $concat(%))
def $concat_locals(epsilon) = epsilon
def $concat_locals(loc* loc'**) = loc* $concat_locals(loc'**)
def $concat_locals((loc*) (loc'*)*) = loc* $concat_locals((loc'*)*)


syntax code = (local*, expr)
Expand Down
22 changes: 12 additions & 10 deletions spectec/spec/wasm-3.0/8-reduction.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ rule Step/read:
-- Step_read: z; instr* ~> instr'*


;; Expressions

relation Eval: config ~>* state; val* hint(show "E-expr")
relation Eval_expr: state; expr ~>* state; val* hint(show "E-expr")
relation Steps: config ~>* config hint(show "E")

rule Eval/done:
z; val* ~>* z; val*
rule Steps/refl:
z; admininstr* ~>* z; admininstr*

rule Eval/step:
z; admininstr* ~>* z''; val*
rule Steps/trans:
z; admininstr* ~>* z''; admininstr''*
-- Step: z; admininstr* ~> z'; admininstr'*
-- Eval: z'; admininstr' ~>* z''; val*
-- Steps: z'; admininstr' ~>* z''; admininstr''*


;; Expressions

relation Eval_expr: state; expr ~>* state; val* hint(show "E-expr")

rule Eval_expr:
z; instr* ~>* z'; val*
-- Eval: z; instr* ~>* z; val*
-- Steps: z; instr* ~>* z'; val*


;;
Expand Down
Loading