-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks great!
I left some comments especially around the restParameter
val typ = TypeTransformer.transformType(param.ptpe) | ||
WasmLocal(WasmLocalName.fromIR(param.name.name), typ, isParameter = true) | ||
} | ||
val resultTyps = TypeTransformer.transformResultType(IRTypes.AnyType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use tree.body.tpe
?
val resultTyps = TypeTransformer.transformResultType(IRTypes.AnyType) | |
val resultTyps = TypeTransformer.transformResultType(tree.body.tpe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the declared result type is implicitly always any
. If the body happens to be a primitive int
, we need to box it to match the declared result type. I expanded a little bit on the comment on generateIRBody
.
closureRest: (f, data, n) => ((...args) => f(data, ...args.slice(0, n), args.slice(n))), | ||
closureThisRest: (f, data, n) => function(...args) { return f(this, data, ...args.slice(0, n), args.slice(n)); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the imported function for closureRest
and closureThisRest
receive two args (f
and data
) but doesn't have third argument (n
). Where this arg comes from?
(import "__scalaJSHelpers" "closureRest" (func $__scalaJSHelpers#closureRest___fun (param (ref func)) (param anyref) (result (ref any))))
(import "__scalaJSHelpers" "closureThisRest" (func $__scalaJSHelpers#closureThisRest___fun (param (ref func)) (param anyref) (result (ref any))))
Also, how can we test these? it seems the test cases doesn't have a restParameter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, good catch! I fixed it in the expression builder.
Also, how can we test these? it seems the test cases doesn't have a
restParameter
.
As the comment in the tests mentions, currently we cannot test the ...rest
parameters. Although the IR does not require it, the source syntax that creates Closure
s with rest params also requires Scala's full-blown Seq
s (for vararags). We'll be able to add tests when we have enough things to support Seq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The comments make sense 💯
/* If there is a ...rest param, the helper requires as third argument the | ||
* number of regular arguments. | ||
*/ | ||
if (hasRestParam) | ||
instrs += I32_CONST(I32(tree.params.size)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Based on #21.