Skip to content

Commit

Permalink
[interpreter] Directory reorg (WebAssembly#500)
Browse files Browse the repository at this point in the history
Reorganise directory structure of interpreter sources into smaller parts that match structure of spec document. The prior spec/ directory is split into

* `syntax`: the definition of abstract syntax; corresponds to the "Structure" section
* `valid`: validation of code and modules; corresponds to the "Validation" section
* `exec`: execution and module instantiation; corresponds to the "Execution" section
* `binary`: encoding and decoding of binary format; corresponds to the "Binary Format" section
* `text`: parsing and printing of text format; corresponds to the "Text Format" section

Similarly, the former host/ directory is split into

* `script`: abstract syntax and execution of the extended script language
* `main`: main program

The former host/imports becomes just host/.

And finally, the auxiliary directories `findlib`, `jslib`, and `travis` are moved under `meta/`.

Also, bump version of the interpreter to 1.0 and update `wast.js`.
  • Loading branch information
rossberg authored Jun 13, 2017
1 parent 3099b6f commit 20e4bd8
Show file tree
Hide file tree
Showing 59 changed files with 4,012 additions and 4,454 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: c++

sudo: off

install: ./interpreter/travis/install-ocaml.sh
install: ./interpreter/meta/travis/install-ocaml.sh

script: ./interpreter/travis/build-test.sh
script: ./interpreter/meta/travis/build-test.sh

os:
- linux
Expand Down
28 changes: 20 additions & 8 deletions interpreter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ZIP = $(NAME).zip
JSLIB = wast.js
WINMAKE = winmake.bat

DIRS = util spec text host host/import
DIRS = util syntax binary text valid exec script host main
LIBS = bigarray
FLAGS = -cflags '-w +a-4-27-42-44-45 -warn-error +a'
OCB = ocamlbuild $(FLAGS) $(DIRS:%=-I %) $(LIBS:%=-libs %)
Expand All @@ -26,36 +26,48 @@ JS = # set to JS shell command to run JS tests

# Main targets

.PHONY: default opt unopt libopt libunopt all land zip
.PHONY: default opt unopt libopt libunopt jslib all land zip

default: opt
opt: $(OPT)
unopt: $(UNOPT)
libopt: _build/$(LIB).cmx
libunopt: _build/$(LIB).cmo
jslib: $(JSLIB)
all: unopt opt libunopt libopt test
land: all $(WINMAKE)
zip: $(ZIP)


# Building executable

empty =
space = $(empty) $(empty)
comma = ,

.INTERMEDIATE: _tags
_tags:
echo >$@ "true: bin_annot"
echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))"

$(UNOPT): main.d.byte
mv $< $@

$(OPT): main.native
mv $< $@

.PHONY: main.d.byte main.native
main.d.byte:
main.d.byte: _tags
$(OCB) -quiet $@

main.native:
main.native: _tags
$(OCB) -quiet $@


# Building library

PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`)
.INTERMEDIATE: $(LIB).mlpack
$(LIB).mlpack: $(DIRS)
ls $(DIRS:%=%/*.ml*) \
Expand All @@ -76,8 +88,8 @@ _build/$(LIB).cmx: $(LIB).mlpack
.PHONY: $(JSLIB)
$(JSLIB): $(UNOPT)
mkdir -p _build/jslib/src
cp jslib/* _build/jslib
cp $(DIRS:%=_build/%/*.ml*) jslib/*.ml _build/jslib/src
cp meta/jslib/* _build/jslib
cp $(DIRS:%=_build/%/*.ml*) meta/jslib/*.ml _build/jslib/src
rm _build/jslib/src/*.ml[^i]
(cd _build/jslib; ./build.sh ../../$@)
Expand Down Expand Up @@ -124,7 +136,7 @@ $(ZIP): $(WINMAKE)
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
clean:
rm -rf _build/jslib wasm.mlpack
rm -rf _build/jslib wasm.mlpack _tags
$(OCB) -clean
Expand All @@ -138,7 +150,7 @@ check:
ocamlfind query $(LIBS)
install: _build/$(LIB).cmx _build/$(LIB).cmo
ocamlfind install wasm findlib/META _build/wasm.o \
ocamlfind install wasm meta/findlib/META _build/wasm.o \
$(wildcard _build/$(LIB).cm*) \
$(wildcard $(DIRS:%=%/*.mli))
Expand Down
18 changes: 14 additions & 4 deletions interpreter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,23 @@ However, to simplify the implementation, this AST representation represents some

## Implementation

The implementation is split into four directories:
The implementation is split into several directories:

* `spec`: the part of the implementation that corresponds to the actual language specification.
* `syntax`: the definition of abstract syntax; corresponds to the "Structure" section of the language specification

* `text`: parsing and printing the S-expressions text format.
* `valid`: validation of code and modules; corresponds to the "Validation" section of the language specification

* `host`: infrastructure for loading and running scripts and defining host environment modules.
* `exec`: execution and module instantiation; corresponds to the "Execution" section of the language specification

* `binary`: encoding and decoding of the binary format; corresponds to the "Binary Format" section of the language specification

* `text`: parsing and printing the S-expressions text format; corresponds to the "Text Format" section of the language specification

* `script`: abstract syntax and execution of the extended script language

* `host`: definition of host environment modules

* `main`: main program

* `util`: utility libraries.

Expand Down
2 changes: 0 additions & 2 deletions interpreter/_tags

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions interpreter/host/main.ml → interpreter/main/main.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
let name = "wasm"
let version = "0.7"
let version = "1.0"

let configure () =
Import.register (Utf8.decode "spectest") Spectest.lookup;
Import.register (Utf8.decode "env") Env.lookup

let banner () =
print_endline
(name ^ "-" ^ Printf.sprintf "0x%lX" Encode.version ^
" " ^ version ^ " reference interpreter")
print_endline (name ^ " " ^ version ^ " reference interpreter")

let usage = "Usage: " ^ name ^ " [option] [file ...]"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ echo 1>&2 ==== Compiling ====
BSPATH=`which bsb`
BPATH=`dirname $BSPATH`/../lib/js
echo 1>&2 BSPATH = $BSPATH
bsb || exit 1
bsb.exe || exit 1
cp `dirname $BSPATH`/../lib/js/*.js lib/js/src

echo 1>&2 ==== Linking full version ====
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x

# Move to a location relative to the script so it runs
# from anywhere.
cd $(dirname ${BASH_SOURCE[0]})/..
cd $(dirname ${BASH_SOURCE[0]})/../..

export PATH=$PWD/../ocaml/install/bin:$PATH

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
set -e

# Move to a location relative to the script so it runs
# from anywhere. Go two levels down to get out of interpreter/
# from anywhere. Go three levels down to get out of interpreter/
# and into the top-level dir, since we'll run ocamlbuild
# inside of interpreter/ and it goes pear-shaped if it
# encounters ocaml's own build directory.
cd $(dirname ${BASH_SOURCE[0]})/../..
cd $(dirname ${BASH_SOURCE[0]})/../../..

rm -rf ocaml
mkdir ocaml
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 20e4bd8

Please sign in to comment.