Desugar destructuring via builtin

This commit is contained in:
Joscha 2022-11-18 18:28:06 +01:00
parent 64c9ca08d9
commit 53928bdeb5

View file

@ -84,42 +84,23 @@ In the following sections,
### Table destructuring ### Table destructuring
`{ a, b, foo: c } = d` is converted to `{ foo, bar: baz } = a` is converted to
``` ```
'{ 'destructure{
local expr = 'arg()[0], 'scope(),
local scope = 'arg()[1], { "foo", bar: "baz" },
scope.a = expr[0], a,
scope.b = expr[1], }
scope.c = expr.foo,
}{d, 'scope()}
```
which is approximately equal to
```
(function{expr, scope} '{
scope.a = expr[0],
scope.b = expr[1],
scope.c = expr.foo,
}){d, 'scope()}
``` ```
`local { a, b, foo: c } = d` is converted to `local { foo, bar: baz } = a` is converted to
``` ```
'{ 'destructure{
local expr = 'arg()[0], 'scope(),
local scope = 'arg()[1], { "foo", bar: "baz" },
'setraw(scope, "a", expr[0]), a,
'setraw(scope, "b", expr[1]), local: true,
'setraw(scope, "c", expr.foo), }
}{d, 'scope()}
```
which is approximately equal to
```
(function{expr, scope} '{
'setraw(scope, "a", expr[0]),
'setraw(scope, "b", expr[1]),
'setraw(scope, "c", expr.foo),
}){d, 'scope()}
``` ```
### Function definitions ### Function definitions