This repository was archived by the owner on Jul 12, 2024. It is now read-only.
File tree 6 files changed +34
-14
lines changed
test-suite/src/main/scala/testsuite/core
6 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ object TestSuites {
14
14
TestSuite (" testsuite.core.HijackedClassesDispatchTest" ),
15
15
TestSuite (" testsuite.core.HijackedClassesMonoTest" ),
16
16
TestSuite (" testsuite.core.HijackedClassesUpcastTest" ),
17
+ TestSuite (" testsuite.core.StaticMethodTest" ),
17
18
TestSuite (" testsuite.core.ToStringTest" )
18
19
)
19
20
}
Original file line number Diff line number Diff line change
1
+ package testsuite .core
2
+
3
+ import testsuite .Assert .ok
4
+
5
+ object StaticMethodTest {
6
+ def main (): Unit = {
7
+ ok(java.lang.Integer .sum(5 , 65 ) == 70 )
8
+ ok(java.lang.Integer .reverseBytes(0x01020304 ) == 0x04030201 )
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -22,9 +22,9 @@ object Preprocessor {
22
22
}
23
23
24
24
private def preprocess (clazz : LinkedClass )(implicit ctx : WasmContext ): Unit = {
25
- val infos = clazz.methods.filterNot(_.flags.namespace.isConstructor).map { method =>
26
- makeWasmFunctionInfo(clazz, method )
27
- }
25
+ val infos = clazz.methods
26
+ .filter(_.flags.namespace == IRTrees . MemberNamespace . Public )
27
+ .map(method => makeWasmFunctionInfo(clazz, method))
28
28
29
29
ctx.putClassInfo(
30
30
clazz.name.name,
Original file line number Diff line number Diff line change @@ -441,18 +441,20 @@ class WasmBuilder {
441
441
// Otherwise, vtable can't be a subtype of the supertype's subtype
442
442
// Constructor can use the exact type because it won't be registered to vtables.
443
443
val receiverTyp =
444
- if (clazz.kind == ClassKind .HijackedClass )
445
- transformType(IRTypes .BoxedClassToPrimType (clazz.name.name))
444
+ if (method.flags.namespace.isStatic)
445
+ None
446
+ else if (clazz.kind == ClassKind .HijackedClass )
447
+ Some (transformType(IRTypes .BoxedClassToPrimType (clazz.name.name)))
446
448
else if (method.flags.namespace.isConstructor)
447
- WasmRefNullType (WasmHeapType .Type (WasmTypeName .WasmStructTypeName (clazz.name.name)))
449
+ Some ( WasmRefNullType (WasmHeapType .Type (WasmTypeName .WasmStructTypeName (clazz.name.name) )))
448
450
else
449
- WasmRefType .any
451
+ Some ( WasmRefType .any)
450
452
451
453
// Prepare for function context, set receiver and parameters
452
454
implicit val fctx = WasmFunctionContext (
453
455
Some (clazz.className),
454
456
functionName,
455
- Some ( receiverTyp) ,
457
+ receiverTyp,
456
458
method.args,
457
459
method.resultType
458
460
)
Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ private class WasmExpressionBuilder private (
108
108
case t : IRTrees .This => genThis(t)
109
109
case t : IRTrees .ApplyStatically => genApplyStatically(t)
110
110
case t : IRTrees .Apply => genApply(t)
111
+ case t : IRTrees .ApplyStatic => genApplyStatic(t)
111
112
case t : IRTrees .IsInstanceOf => genIsInstanceOf(t)
112
113
case t : IRTrees .AsInstanceOf => genAsInstanceOf(t)
113
114
case t : IRTrees .GetClass => genGetClass(t)
@@ -599,6 +600,16 @@ private class WasmExpressionBuilder private (
599
600
}
600
601
}
601
602
603
+ private def genApplyStatic (tree : IRTrees .ApplyStatic ): IRTypes .Type = {
604
+ genArgs(tree.args, tree.method.name)
605
+ val namespace = IRTrees .MemberNamespace .forStaticCall(tree.flags)
606
+ val funcName = Names .WasmFunctionName (namespace, tree.className, tree.method.name)
607
+ instrs += CALL (FuncIdx (funcName))
608
+ if (tree.tpe == IRTypes .NothingType )
609
+ instrs += UNREACHABLE
610
+ tree.tpe
611
+ }
612
+
602
613
private def genArgs (args : List [IRTrees .Tree ], methodName : IRNames .MethodName ): Unit = {
603
614
for ((arg, paramTypeRef) <- args.lazyZip(methodName.paramTypeRefs)) {
604
615
val paramType = ctx.inferTypeFromTypeRef(paramTypeRef)
Original file line number Diff line number Diff line change @@ -306,15 +306,11 @@ class WasmContext(val module: WasmModule) extends FunctionTypeWriterWasmContext
306
306
case ModuleInitializerImpl .MainMethodWithArgs (className, encodedMainMethodName, args) =>
307
307
() // TODO: but we don't use args yet in scala-wasm
308
308
case ModuleInitializerImpl .VoidMainMethod (className, encodedMainMethodName) =>
309
- val name = className.withSuffix(" $" )
310
- instrs +=
311
- WasmInstr .CALL (WasmImmediate .FuncIdx (Names .WasmFunctionName .loadModule(name)))
312
- instrs += WasmInstr .REF_AS_NOT_NULL
313
309
instrs +=
314
310
WasmInstr .CALL (
315
311
WasmImmediate .FuncIdx (WasmFunctionName (
316
- IRTrees .MemberNamespace .Public ,
317
- name ,
312
+ IRTrees .MemberNamespace .PublicStatic ,
313
+ className ,
318
314
encodedMainMethodName
319
315
))
320
316
)
You can’t perform that action at this time.
0 commit comments