Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 9ff8601

Browse files
authored
[interpreter] Document spectest (#1280)
1 parent 4339e90 commit 9ff8601

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

interpreter/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,36 @@ The `input` and `output` meta commands determine the requested file format from
363363
The interpreter supports a "dry" mode (flag `-d`), in which modules are only validated. In this mode, all actions and assertions are ignored.
364364
It also supports an "unchecked" mode (flag `-u`), in which module definitions are not validated before use.
365365

366+
367+
### Spectest host module
368+
369+
When running scripts, the interpreter predefines a simple host module named `"spectest"` that has the following module type:
370+
```
371+
(module
372+
(global (export "global_i32") i32)
373+
(global (export "global_i64") i64)
374+
(global (export "global_f32") f32)
375+
(global (export "global_f64") f64)
376+
377+
(table (export "table") 10 20 funcref)
378+
379+
(memory (export "memory") 1 2)
380+
381+
(func (export "print"))
382+
(func (export "print_i32") (param i32))
383+
(func (export "print_i64") (param i64))
384+
(func (export "print_f32") (param f32))
385+
(func (export "print_f64") (param f64))
386+
(func (export "print_i32_f32") (param i32 f32))
387+
(func (export "print_f64_f64") (param f64 f64))
388+
)
389+
```
390+
The `print` functions are assumes to print their respective argument values to stdout (followed by a newline) and can be used to produce observable output.
391+
392+
Note: This module predates the `register` command and should no longer be needed for new tests.
393+
We might remove it in the future, so consider it deprecated.
394+
395+
366396
### Binary Scripts
367397

368398
The grammar of binary scripts is a subset of the grammar for general scripts:

interpreter/host/spectest.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ let lookup name t =
3434
match Utf8.encode name, t with
3535
| "print", _ -> ExternFunc (func print (FuncType ([], [])))
3636
| "print_i32", _ -> ExternFunc (func print (FuncType ([I32Type], [])))
37+
| "print_i64", _ -> ExternFunc (func print (FuncType ([I64Type], [])))
38+
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
39+
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
3740
| "print_i32_f32", _ ->
3841
ExternFunc (func print (FuncType ([I32Type; F32Type], [])))
3942
| "print_f64_f64", _ ->
4043
ExternFunc (func print (FuncType ([F64Type; F64Type], [])))
41-
| "print_f32", _ -> ExternFunc (func print (FuncType ([F32Type], [])))
42-
| "print_f64", _ -> ExternFunc (func print (FuncType ([F64Type], [])))
4344
| "global_i32", _ -> ExternGlobal (global (GlobalType (I32Type, Immutable)))
45+
| "global_i64", _ -> ExternGlobal (global (GlobalType (I64Type, Immutable)))
4446
| "global_f32", _ -> ExternGlobal (global (GlobalType (F32Type, Immutable)))
4547
| "global_f64", _ -> ExternGlobal (global (GlobalType (F64Type, Immutable)))
4648
| "table", _ -> ExternTable table

0 commit comments

Comments
 (0)