Skip to content

Commit

Permalink
Merge remote-tracking branch 'funcref/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Mar 11, 2021
2 parents 332f4f1 + 3e34cb0 commit 8109132
Show file tree
Hide file tree
Showing 22 changed files with 814 additions and 706 deletions.
4 changes: 2 additions & 2 deletions document/core/appendix/algorithm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ In that case, all existing operand types are purged from the value stack, in ord

.. index:: opcode

Validation of Instruction Sequences
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Validation of Opcode Sequences
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following function shows the validation of a number of representative instructions that manipulate the stack.
Other instructions are checked in a similar manner.
Expand Down
2 changes: 1 addition & 1 deletion document/core/appendix/index-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Category Constructor
(reserved) :math:`\hex{6E}` .. :math:`\hex{61}`
:ref:`Function type <syntax-functype>` :math:`[\valtype^\ast] \to [\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
(reserved) :math:`\hex{5F}` .. :math:`\hex{41}`
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)
:ref:`Table type <syntax-tabletype>` :math:`\limits~\reftype` (none)
:ref:`Memory type <syntax-memtype>` :math:`\limits` (none)
:ref:`Global type <syntax-globaltype>` :math:`\mut~\valtype` (none)
Expand Down
2 changes: 1 addition & 1 deletion document/core/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WebAssembly Specification

.. only:: html

| Release |release| + bulk instructions + reference types (Draft, |today|)
| Release |release| + typed references (Draft, |today|)
| Editor: Andreas Rossberg
Expand Down
2 changes: 1 addition & 1 deletion document/core/syntax/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Result Types
~~~~~~~~~~~~

*Result types* classify the result of :ref:`executing <exec-instr>` :ref:`instructions <syntax-instr>` or :ref:`functions <syntax-func>`,
which is a sequence of values written with brackets.
which is a sequence of values, written with brackets.

.. math::
\begin{array}{llll}
Expand Down
4 changes: 2 additions & 2 deletions document/core/valid/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Functions :math:`\func` are classified by :ref:`function types <syntax-functype>

* |CLOCALS| set to the sequence of :ref:`value types <syntax-valtype>` :math:`t_1^\ast~t^\ast`, concatenating parameters and locals,

* |CLABELS| set to the singular sequence containing only :ref:`result type <syntax-valtype>` :math:`[t_2^\ast]`.
* |CLABELS| set to the singular sequence containing only :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]`.

* |CRETURN| set to the :ref:`result type <syntax-valtype>` :math:`[t_2^\ast]`.
* |CRETURN| set to the :ref:`result type <syntax-resulttype>` :math:`[t_2^\ast]`.

* Under the context :math:`C'`,
the expression :math:`\expr` must be valid with type :math:`[t_2^\ast]`.
Expand Down
22 changes: 17 additions & 5 deletions interpreter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ WINMAKE = winmake.bat
DIRS = util syntax binary text valid runtime exec script host main
LIBS = bigarray
FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45 -warn-error +a-3'
OCB = ocamlbuild $(FLAGS) $(DIRS:%=-I %) $(LIBS:%=-libs %)
OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %)
OCB = $(OCBA) $(LIBS:%=-libs %)
JS = # set to JS shell command to run JS tests


Expand All @@ -32,8 +33,8 @@ default: opt
debug: unopt
opt: $(OPT)
unopt: $(UNOPT)
libopt: _build/$(LIB).cmx
libunopt: _build/$(LIB).cmo
libopt: _build/$(LIB).cmx _build/$(LIB).cmxa
libunopt: _build/$(LIB).cmo _build/$(LIB).cma
jslib: $(JSLIB)
all: unopt opt libunopt libopt test
land: $(WINMAKE) all
Expand Down Expand Up @@ -68,6 +69,7 @@ main.native: _tags

# Building library

FILES = $(shell ls $(DIRS:%=%/*.ml*))
PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`)
.INTERMEDIATE: $(LIB).mlpack
Expand All @@ -78,12 +80,22 @@ $(LIB).mlpack: $(DIRS)
| sort | uniq \
>$@
_build/$(LIB).cmo: $(LIB).mlpack _tags
.INTERMEDIATE: $(LIB).mllib
$(LIB).mllib:
echo Wasm >$@
_build/$(LIB).cmo: $(FILES) $(LIB).mlpack _tags Makefile
$(OCB) -quiet $(LIB).cmo
_build/$(LIB).cmx: $(LIB).mlpack _tags
_build/$(LIB).cmx: $(FILES) $(LIB).mlpack _tags Makefile
$(OCB) -quiet $(LIB).cmx
_build/$(LIB).cma: $(FILES) $(LIB).mllib _tags Makefile
$(OCBA) -quiet $(LIB).cma
_build/$(LIB).cmxa: $(FILES) $(LIB).mllib _tags Makefile
$(OCBA) -quiet $(LIB).cmxa
# Building JavaScript library
Expand Down
42 changes: 32 additions & 10 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ let ref_type s =
let value_type s =
either (fun s -> NumType (num_type s)) (fun s -> RefType (ref_type s)) s

let stack_type s = vec value_type s
let result_type s = vec value_type s

let func_type s =
let ins = stack_type s in
let out = stack_type s in
let ins = result_type s in
let out = result_type s in
FuncType (ins, out)

let cont_type s =
Expand Down Expand Up @@ -864,21 +864,28 @@ let data_count_section s =

let custom size s =
let start = pos s in
let _id = name s in
skip (size - (pos s - start)) s;
true
let id = name s in
let bs = get_string (size - (pos s - start)) s in
Some (id, bs)

let custom_section s =
section_with_size `CustomSection custom false s
section_with_size `CustomSection custom None s

let non_custom_section s =
match id s with
| None | Some `CustomSection -> None
| _ -> skip 1 s; sized skip s; Some ()


(* Modules *)

let rec iterate f s = if f s then iterate f s
let rec iterate f s = if f s <> None then iterate f s

let magic = 0x6d736100l

let module_ s =
let magic = u32 s in
require (magic = 0x6d736100l) s 0 "magic header not detected";
let header = u32 s in
require (header = magic) s 0 "magic header not detected";
let version = u32 s in
require (version = Encode.version) s 4 "unknown binary version";
iterate custom_section s;
Expand Down Expand Up @@ -923,3 +930,18 @@ let module_ s =


let decode name bs = at module_ (stream name bs)

let all_custom tag s =
let header = u32 s in
require (header = magic) s 0 "magic header not detected";
let version = u32 s in
require (version = Encode.version) s 4 "unknown binary version";
let rec collect () =
iterate non_custom_section s;
match custom_section s with
| None -> []
| Some (n, s) when n = tag -> s :: collect ()
| Some _ -> collect ()
in collect ()

let decode_custom tag name bs = all_custom tag (stream name bs)
2 changes: 2 additions & 0 deletions interpreter/binary/decode.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exception Code of Source.region * string

val decode : string -> string -> Ast.module_ (* raises Code *)

val decode_custom : Ast.name -> string -> string -> string list (* raises Code *)
Loading

0 comments on commit 8109132

Please sign in to comment.