-
Notifications
You must be signed in to change notification settings - Fork 54
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
WebAssembly backend #500
Open
romac
wants to merge
14
commits into
epfl-lara:scala-2
Choose a base branch
from
romac:wasm
base: scala-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
WebAssembly backend #500
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
reclang IR
Defines a language, 'reclang', that functions as an intermediate language between stainless trees and wasm code.
The main feature of reclang is that its structured types are extensible record, which are meant to be easily translatable both to the current memory model of wasm (linear memory) and the planned future extension of reference types.
The class
stainless.wasmgen.intermediate.Lowering
is responsible for the lowering to this intermediate language.We now give an informal overview of reclang.
In the following grammars, nonterminal symbols are given in single quotes('), and terminal symbols without quotes.
The types of reclang are defined as follows:
where id refers to the name of a record sort defined in the program.
There is no type polymorphism, including arrays, which always contain boxed values.
A record sort is defined as follows:
There is a single sort, called "anyref", that does not have a parent:
anyref has a single field which represents the type tag of a given runtime value.
anyref is the root of the record hierarchy. All other records have a parent.
There is no subtyping in reclang, but there are operators which can cast one record to another, provided they are connected with the ancestor (transitive reflexive closure of parent) relation.
At runtime, a record's representation contains a list of values corresponding to the fields it defines as well as all fields that its ancestors define.
The order of fields is from the further ancestor until the current field type.
The expressions of reclang are given below:
The notable typing rules are for records: a record constructor takes as arguments expressions of the types of the fields of all the ancestors of the current type.
Also, a selector is allowed with the name of a field of an ancestor.
Casts have to be between compatible record types, i.e., that are related by the ancestor relation.
An upcast is always successful.
A downcast to an incompatible type fails the program.
The only values that can have a function type in reclang are function pointers.
Functions are represented by closures, i.e., records containing a function pointer and the environment captured by the function.
Polymorphism is implemented with type erasure and boxing.
There are boxed versions of the elementary types (which are regular record types).
Boxed types are records containing one additional field named "value" of the corresponding type.
The typetag field (which is defined in anyref, therefore is present in every record) defines the type of a record value at runtime as follows:
and then as many tags as are needed for record sorts that are instantiated in the program.
We differentiate between records which correspond to abstract types (cannot be instantiated, do not possess a tag) and records which correspond to constructors (can be instantiated, possess a tag).
Two record values are equal if their type tags are equal and all fields defined by their tagged type are equal.
Arrays, functions and strings are compared by reference.
All other types are compared by value.
by @manoskouk