Skip to content

Add memory exports #243

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

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ml-proto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ local: ( local <type>* ) | ( local <name> <type> )
module: ( module <type>* <func>* <import>* <export>* <table>* <memory>? <start>? )
type: ( type <name>? ( func <param>* <result>? ) )
import: ( import <name>? "<module_name>" "<func_name>" (param <type>* ) (result <type>)* )
export: ( export "<char>*" <var> )
export: ( export "<char>*" <var> ) | ( export "<char>*" memory)
start: ( start <var> )
table: ( table <var>* )
memory: ( memory <int> <int>? <segment>* )
Expand Down
4 changes: 3 additions & 1 deletion ml-proto/host/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ import :

export :
| LPAR EXPORT TEXT var RPAR
{ let at = at () in fun c -> {name = $3; func = $4 c func} @@ at }
{ let at = at () in fun c -> ExportFunc ($3, ($4 c func)) @@ at }
| LPAR EXPORT TEXT MEMORY RPAR
{ let at = at () in fun c -> ExportMemory $3 @@ at }
;

module_fields :
Expand Down
11 changes: 8 additions & 3 deletions ml-proto/host/print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ let print_var_sig prefix i t =
let print_func_sig m prefix i f =
printf "%s %d : %s\n" prefix i (string_of_func_type (func_type m f))

let print_export_sig m prefix n f =
printf "%s \"%s\" : %s\n" prefix n (string_of_func_type (func_type m f))
let print_export_sig m n f =
printf "export \"%s\" : %s\n" n (string_of_func_type (func_type m f))

let print_export_mem n =
printf "export \"%s\" : memory\n" n

let print_table_elem i x =
printf "table [%d] = func %d\n" i x.it
Expand All @@ -36,7 +39,9 @@ let print_func m i f =
print_func_sig m "func" i f

let print_export m i ex =
print_export_sig m "export" ex.it.name (List.nth m.it.funcs ex.it.func.it)
match ex.it with
| ExportFunc (n, x) -> print_export_sig m n (List.nth m.it.funcs x.it)
| ExportMemory n -> print_export_mem n

let print_module m =
let {funcs; start; exports; table} = m.it in
Expand Down
5 changes: 3 additions & 2 deletions ml-proto/spec/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ let check_elem c x =
module NameSet = Set.Make(String)

let check_export c set ex =
let {name; func = x} = ex.it in
ignore (func c x);
let name = match ex.it with
| ExportFunc (n, x) -> ignore (func c x); n
| ExportMemory n -> require (c.has_memory) ex.at "no memory to export"; n in
require (not (NameSet.mem name set)) ex.at
"duplicate export name";
NameSet.add name set
Expand Down
4 changes: 3 additions & 1 deletion ml-proto/spec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ let init_memory {it = {initial; segments; _}} =
mem

let add_export funcs ex =
ExportMap.add ex.it.name (List.nth funcs ex.it.func.it)
match ex.it with
| ExportFunc (n, x) -> ExportMap.add n (List.nth funcs x.it)
| ExportMemory n -> fun x -> x

let init m imports host =
assert (List.length imports = List.length m.it.Kernel.imports);
Expand Down
4 changes: 3 additions & 1 deletion ml-proto/spec/kernel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ and memory' =
and segment = Memory.segment Source.phrase

type export = export' Source.phrase
and export' = {name : string; func : var}
and export' =
| ExportFunc of string * var
| ExportMemory of string

type import = import' Source.phrase
and import' =
Expand Down
4 changes: 4 additions & 0 deletions ml-proto/test/exports.wast
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
)

(assert_return (invoke "e" (i32.const 42)) (i32.const 43))

(module (memory 0 0) (export "a" memory))
(module (memory 0 0) (export "a" memory) (export "b" memory))
(assert_invalid (module (export "a" memory)) "no memory to export")