This is an old revision of the document!
The purpose of the homework is to translate an Alf Langauge provided as an AST file with semantic data into Web Assembly. Your program will receive two parameters: source file (the file from the previous homework, with the symbol table, the AST and the error list) and the output file. You don't need a working version of homework 4! The test files have already been generated and you can find them on github. The programs will have any variable type. String concatenation is not provided (except for a few tests test).
node main.js file.alf.json file.wat
You have to write two files:
Variables are divided in two types:
We will discuss them in detail. Each variable type from ALF has to be translated into a WebAssembly type following the table.
Complex and Strings variables are handled as a pointer value (i32) to the position in memory.
ALF Type | WebAssembly Type |
---|---|
int | i32 |
real | i32 |
character | i32 |
bool | i32 |
string | a 256 bytes memory space |
array (type:[from – to]) | a bytes * length memory space |
struct | a sum of the struct's properties bytes memory space |
All these values are represented as i32.
All these values are represented as f32.
All these values are represented as i32, in ascii.
The bool value is represented:
The representation used for strings is Pascal and has a 256 bytes length:
Variables may be allocated differently based on their type and their position. Allocation types are global
, data
, param
, local
, stack
and relocated
.
Variable Type | Variable Location | Allocation Type |
---|---|---|
simple | script | global |
complex | script | data |
string | script | data |
simple | function parameter | param |
complex | function parameter | param (sent as pointer, see note) |
string | function parameter | param (sent as pointer, see note) |
simple | function | local |
complex | function | stack |
string | function | stack |
simple | if, for, loop | relocated |
complex | if, for, loop | relocated |
string | if, for, loop | relocated |
Global allocated variables are simple variables from the main script. These will be allocated as (global $title type)
statements.
Example: simple.alf simple.wat
Data allocated variables are complex and string variables from the main script. These will be allocated as in the memory space. Each variable of this type will have an address
parameter with the position of the variable in memory.
Example: simple.alf simple.wat
(global $title i32 (i32.const address_of_variable)
variable to be easier to read the code.
Parameter allocation is used for simple type function parameters. These will be allocated as (param $title type)
statements in the function definition.
Example: definition_variables.alf definition_variables.wat
Local allocated variables are simple variables from a function. These will be allocated as (local $title type)
statements in the function definition.
Example: definition_variables.alf definition_variables.wat
Stack allocated variables are complex and string variables from a function script. These will be allocated as in the memory space. Each variable of this type will have an address
parameter with the position of the variable in memory.
Example: simple.alf simple.wat
(global $title i32 (i32.const address_of_variable)
variable to be easier to read the code.
Parameters are allocated using Web Assembly parameters.
To read and write from and to the screen, the following function, that are declared in Alf will not be transformed in WebAssembly but imported:
Implement the homework so that is may use strings.
The homework will be tested automatically using a set of public and private tests.
You can download the public tests from the GitHub repository.
To run the tests, download the contents of the repository in the folder with the homework. Enter the verify folder and run ./run_all.sh.
cd verify ./run_all.sh
You will need bash for that. You can use either Linux or Windows Linux Subsystem.
wget https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-x64.tar.xz tar xvfJ node-v6.10.0-linux-x64.tar.xz cd node-v6.10.0-linux-x64 sudo cp -R * /usr
When uploading the homework, we might have some private tests that it needs to pass. vmchecker will run them.
The homework needs to be uploaded to vmchecker. Login with your moodle user name, select the Automates et Langages Formelles (FILS) course and upload the homework archive.
The readme file has the following format:
Your full name Group An explanation how you wrote your homework, what did you use, what are the main ideas.
To upload your homework, please follow the following:
DO NOT include node_modules.
When the archive is uploaded, vmchecker will run:
unzip archive.zip homework cd homework # if the file yarn.lock exists yarn # else npm install echo '{ "node":true, "esnext":true }' > .jshintrc jshint *.js jison grammar.jison