ballercat / walt

:zap: Walt is a JavaScript-like syntax for WebAssembly text format :zap:
https://ballercat.github.io/walt/
MIT License
4.64k stars 122 forks source link

tee_local, select fixes and other improvements #175

Closed ballercat closed 5 years ago

ballercat commented 5 years ago

New features

tee_local

Support tee_local. Converts assignments in expressions (not top level statements) to return the local that is being set.

The change also makes the grammar a bit more granular, creating a distinction between assignments in expressions vs top-level statements.

// These are tee_local(s)
while (i -= 1) { ... }
const x : i32 =  2 * (i += 10); 

// These are NOT tee_locals(s)
x += 10;
i = 1;
// obj.x is a syntax error, only identifiers can be tee-ed
const y : i32 = obj.x += 2; 
// for loops do not support tee_local either, these are vanilla set_local
for (i = 0; i < 10; i += 1) { ... }

Fixes

select

Ternary statements were not encoded as selects, they should have been.

Negation encoding of constants

The generator was treating variable negation the same as constant negation. This meant that a - preceding anything was always a binary operation of 0 - value. Now negative constants are encoded as such.

coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 246


Totals Coverage Status
Change from base Build 238: 0.04%
Covered Lines: 1931
Relevant Lines: 1931

💛 - Coveralls