Conversation
26bd062 to
72f85f9
Compare
|
Export without trailing semicolon is fine, makes sense. About the hoisting support; personally I am no fan of hoisting at all, it is confusing and counterintuitive and, as you've noticed with the compiler implementation, makes single-pass compilation impossible and requires juggling and swapping states. I do agree that function hoisting for enabling mutual recursion is fine but things like let x = foo();
function foo() {
}Just do not feel right (yes I know it is established practise in JS / ECMA Script). function foo;
let x = foo();
function foo() {
}
function is_odd;
function is_even(n) { return n == 0 ? true : is_odd(n - 1); }
function is_odd(n) { return n == 0 ? false : is_even(n - 1); }
print(is_even(4), "\n");
print(is_odd(3), "\n");It is slightly more verbose but simplifies compiler implementation a lot and clearly communicates intent. |
|
Fair enough. So |
|
Yes, a not fully fleshed out proposal is:
|
Like ECMAScript, treat `export function foo() {}` as a complete
statement that does not require a trailing semicolon.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Add `function foo;` as a forward declaration that reserves a constant
slot (initialized to null), later filled by a matching `function foo() {}`
definition. This enables mutual recursion between functions at the same
scope level without the `let foo; foo = function() {};` workaround.
Forward-declared bindings are constant, preventing reassignment and
redeclaration. Duplicate forward declarations, forward declarations
after definitions, and unfilled stubs called at runtime are all handled
with appropriate error messages.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
72f85f9 to
d9e24e4
Compare
|
Does this look like what you wanted? |
|
Yes! I hope to merge it during the weekend, on a first glance it looks really good. |
Bring ucode closer to ECMAScript: