Skip to content

Commit 7105e57

Browse files
authored
Merge pull request #1 from archiecobbs/use-native-methods
Java @WasmTextCode methods can/should be declared as native.
2 parents e0204e3 + 0d74d04 commit 7105e57

File tree

3 files changed

+35
-105
lines changed

3 files changed

+35
-105
lines changed

src/de/inetsoftware/jwebassembly/api/java/lang/ReplacementForDouble.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class ReplacementForDouble {
3232
@WasmTextCode( "local.get 0 " //
3333
+ "i64.reinterpret_f64 " //
3434
+ "return" )
35-
static long doubleToRawLongBits(double value) {
36-
return 0; // for Java compiler
37-
}
35+
static native long doubleToRawLongBits(double value);
3836

3937
/**
4038
* Replacement for Double.longBitsToDouble(long)
@@ -43,7 +41,5 @@ static long doubleToRawLongBits(double value) {
4341
@WasmTextCode( "local.get 0 " //
4442
+ "f64.reinterpret_i64 " //
4543
+ "return" )
46-
static double longBitsToDouble(long value) {
47-
return 0; // for Java compiler
48-
}
44+
static native double longBitsToDouble(long value);
4945
}

src/de/inetsoftware/jwebassembly/api/java/lang/ReplacementForFloat.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class ReplacementForFloat {
3232
@WasmTextCode( "local.get 0 " //
3333
+ "i32.reinterpret_f32 " //
3434
+ "return" )
35-
static int floatToRawIntBits(float value) {
36-
return 0; // for Java compiler
37-
}
35+
static native int floatToRawIntBits(float value);
3836

3937
/**
4038
* Replacement for Float.intBitsToFloat(int)
@@ -43,7 +41,5 @@ static int floatToRawIntBits(float value) {
4341
@WasmTextCode( "local.get 0 " //
4442
+ "f32.reinterpret_i32 " //
4543
+ "return" )
46-
static float intBitsToFloat(int value) {
47-
return 0; // for Java compiler
48-
}
44+
static native float intBitsToFloat(int value);
4945
}

src/de/inetsoftware/jwebassembly/api/java/lang/ReplacementForMath.java

Lines changed: 31 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class ReplacementForMath {
3636
*/
3737
@Replace( "java/lang/Math.sin(D)D" )
3838
@Import( module = "Math", name = "sin" )
39-
static double sin( double x ) {
40-
return 0; // for Java compiler
41-
}
39+
static native double sin( double x );
4240

4341
/**
4442
* Replacement for {@link Math#cos(double)}
@@ -49,9 +47,7 @@ static double sin( double x ) {
4947
*/
5048
@Replace( "java/lang/Math.cos(D)D" )
5149
@Import( module = "Math", name = "cos" )
52-
static double cos( double x ) {
53-
return 0; // for Java compiler
54-
}
50+
static native double cos( double x );
5551

5652
/**
5753
* Replacement for {@link Math#tan(double)}
@@ -62,9 +58,7 @@ static double cos( double x ) {
6258
*/
6359
@Replace( "java/lang/Math.tan(D)D" )
6460
@Import( module = "Math", name = "tan" )
65-
static double tan( double x ) {
66-
return 0; // for Java compiler
67-
}
61+
static native double tan( double x );
6862

6963
/**
7064
* Replacement for {@link Math#asin(double)}
@@ -75,9 +69,7 @@ static double tan( double x ) {
7569
*/
7670
@Replace( "java/lang/Math.asin(D)D" )
7771
@Import( module = "Math", name = "asin" )
78-
static double asin( double x ) {
79-
return 0; // for Java compiler
80-
}
72+
static native double asin( double x );
8173

8274
/**
8375
* Replacement for {@link Math#acos(double)}
@@ -88,9 +80,7 @@ static double asin( double x ) {
8880
*/
8981
@Replace( "java/lang/Math.acos(D)D" )
9082
@Import( module = "Math", name = "acos" )
91-
static double acos( double x ) {
92-
return 0; // for Java compiler
93-
}
83+
static native double acos( double x );
9484

9585
/**
9686
* Replacement for {@link Math#atan(double)}
@@ -101,9 +91,7 @@ static double acos( double x ) {
10191
*/
10292
@Replace( "java/lang/Math.atan(D)D" )
10393
@Import( module = "Math", name = "atan" )
104-
static double atan( double x ) {
105-
return 0; // for Java compiler
106-
}
94+
static native double atan( double x );
10795

10896
/**
10997
* Replacement for {@link Math#exp(double)}
@@ -114,9 +102,7 @@ static double atan( double x ) {
114102
*/
115103
@Replace( "java/lang/Math.exp(D)D" )
116104
@Import( module = "Math", name = "exp" )
117-
static double exp( double x ) {
118-
return 0; // for Java compiler
119-
}
105+
static native double exp( double x );
120106

121107
/**
122108
* Replacement for {@link Math#log(double)}
@@ -127,9 +113,7 @@ static double exp( double x ) {
127113
*/
128114
@Replace( "java/lang/Math.log(D)D" )
129115
@Import( module = "Math", name = "log" )
130-
static double log( double x ) {
131-
return 0; // for Java compiler
132-
}
116+
static native double log( double x );
133117

134118
/**
135119
* Replacement for {@link Math#log10(double)}
@@ -140,9 +124,7 @@ static double log( double x ) {
140124
*/
141125
@Replace( "java/lang/Math.log10(D)D" )
142126
@Import( module = "Math", name = "log10" )
143-
static double log10( double x ) {
144-
return 0; // for Java compiler
145-
}
127+
static native double log10( double x );
146128

147129
/**
148130
* Replacement for {@link Math#sqrt(double)}
@@ -155,9 +137,7 @@ static double log10( double x ) {
155137
@WasmTextCode( "local.get 0 " //
156138
+ "f64.sqrt " //
157139
+ "return" )
158-
static double sqrt( double x ) {
159-
return 0; // for Java compiler
160-
}
140+
static native double sqrt( double x );
161141

162142
/**
163143
* Replacement for {@link Math#cbrt(double)}
@@ -168,9 +148,7 @@ static double sqrt( double x ) {
168148
*/
169149
@Replace( "java/lang/Math.cbrt(D)D" )
170150
@Import( module = "Math", name = "cbrt" )
171-
static double cbrt( double x ) {
172-
return 0; // for Java compiler
173-
}
151+
static native double cbrt( double x );
174152

175153
/**
176154
* Replacement for {@link Math#IEEEremainder(double,double)}
@@ -195,9 +173,7 @@ static double IEEEremainder( double f1, double f2 ) {
195173
@WasmTextCode( "local.get 0 " //
196174
+ "f64.ceil " //
197175
+ "return" )
198-
static double ceil( double x ) {
199-
return 0; // for Java compiler
200-
}
176+
static native double ceil( double x );
201177

202178
/**
203179
* Replacement for {@link Math#floor(double)}
@@ -210,9 +186,7 @@ static double ceil( double x ) {
210186
@WasmTextCode( "local.get 0 " //
211187
+ "f64.floor " //
212188
+ "return" )
213-
static double floor( double x ) {
214-
return 0; // for Java compiler
215-
}
189+
static native double floor( double x );
216190

217191
/**
218192
* Replacement for {@link Math#rint(double)}
@@ -225,9 +199,7 @@ static double floor( double x ) {
225199
@WasmTextCode( "local.get 0 " //
226200
+ "f64.nearest " //
227201
+ "return" )
228-
static double rint( double x ) {
229-
return 0; // for Java compiler
230-
}
202+
static native double rint( double x );
231203

232204
/**
233205
* Replacement for {@link Math#atan2(double, double)}
@@ -241,9 +213,7 @@ static double rint( double x ) {
241213
*/
242214
@Replace( "java/lang/Math.atan2(DD)D" )
243215
@Import( module = "Math", name = "atan2" )
244-
static double atan2( double y, double x ) {
245-
return 0; // for Java compiler
246-
}
216+
static native double atan2( double y, double x );
247217

248218
/**
249219
* Replacement for {@link Math#pow(double, double)}
@@ -254,9 +224,7 @@ static double atan2( double y, double x ) {
254224
*/
255225
@Replace( "java/lang/Math.pow(DD)D" )
256226
@Import( module = "Math", name = "pow" )
257-
static double pow( double a, double b ) {
258-
return 0; // for Java compiler
259-
}
227+
static native double pow( double a, double b );
260228

261229
/**
262230
* Replacement for {@link Math#random()}
@@ -265,9 +233,7 @@ static double pow( double a, double b ) {
265233
*/
266234
@Replace( "java/lang/Math.random()D" )
267235
@Import( module = "Math", name = "random" )
268-
static double random() {
269-
return 0; // for Java compiler
270-
}
236+
static native double random();
271237

272238
/**
273239
* Replacement for {@link Math#abs(double)}
@@ -280,9 +246,7 @@ static double random() {
280246
@WasmTextCode( "local.get 0 " //
281247
+ "f64.abs " //
282248
+ "return" )
283-
static double abs( double x ) {
284-
return 0; // for Java compiler
285-
}
249+
static native double abs( double x );
286250

287251
/**
288252
* Replacement for {@link Math#abs(float)}
@@ -295,9 +259,7 @@ static double abs( double x ) {
295259
@WasmTextCode( "local.get 0 " //
296260
+ "f32.abs " //
297261
+ "return" )
298-
static float abs( float x ) {
299-
return 0; // for Java compiler
300-
}
262+
static native float abs( float x );
301263

302264
/**
303265
* Replacement for {@link Math#max(double,double)}
@@ -311,9 +273,7 @@ static float abs( float x ) {
311273
+ "local.get 1 " //
312274
+ "f64.max " //
313275
+ "return" )
314-
static double max( double a, double b ) {
315-
return 0; // for Java compiler
316-
}
276+
static native double max( double a, double b );
317277

318278
/**
319279
* Replacement for {@link Math#max(float,float)}
@@ -327,9 +287,7 @@ static double max( double a, double b ) {
327287
+ "local.get 1 " //
328288
+ "f32.max " //
329289
+ "return" )
330-
static float max( float a, float b ) {
331-
return 0; // for Java compiler
332-
}
290+
static native float max( float a, float b );
333291

334292
/**
335293
* Replacement for {@link Math#min(double,double)}
@@ -343,9 +301,7 @@ static float max( float a, float b ) {
343301
+ "local.get 1 " //
344302
+ "f64.min " //
345303
+ "return" )
346-
static double min( double a, double b ) {
347-
return 0; // for Java compiler
348-
}
304+
static native double min( double a, double b );
349305

350306
/**
351307
* Replacement for {@link Math#min(float,float)}
@@ -359,9 +315,7 @@ static double min( double a, double b ) {
359315
+ "local.get 1 " //
360316
+ "f32.min " //
361317
+ "return" )
362-
static float min( float a, float b ) {
363-
return 0; // for Java compiler
364-
}
318+
static native float min( float a, float b );
365319

366320
/**
367321
* Replacement for {@link Math#sinh(double)}
@@ -372,9 +326,7 @@ static float min( float a, float b ) {
372326
*/
373327
@Replace( "java/lang/Math.sinh(D)D" )
374328
@Import( module = "Math", name = "sinh" )
375-
static double sinh( double x ) {
376-
return 0; // for Java compiler
377-
}
329+
static native double sinh( double x );
378330

379331
/**
380332
* Replacement for {@link Math#cosh(double)}
@@ -385,9 +337,7 @@ static double sinh( double x ) {
385337
*/
386338
@Replace( "java/lang/Math.cosh(D)D" )
387339
@Import( module = "Math", name = "cosh" )
388-
static double cosh( double x ) {
389-
return 0; // for Java compiler
390-
}
340+
static native double cosh( double x );
391341

392342
/**
393343
* Replacement for {@link Math#tanh(double)}
@@ -398,9 +348,7 @@ static double cosh( double x ) {
398348
*/
399349
@Replace( "java/lang/Math.tanh(D)D" )
400350
@Import( module = "Math", name = "tanh" )
401-
static double tanh( double x ) {
402-
return 0; // for Java compiler
403-
}
351+
static native double tanh( double x );
404352

405353
/**
406354
* Replacement for {@link Math#hypot(double, double)}
@@ -413,9 +361,7 @@ static double tanh( double x ) {
413361
*/
414362
@Replace( "java/lang/Math.hypot(DD)D" )
415363
@Import( module = "Math", name = "hypot" )
416-
static double hypot( double a, double b ) {
417-
return 0; // for Java compiler
418-
}
364+
static native double hypot( double a, double b );
419365

420366
/**
421367
* Replacement for {@link Math#expm1(double)}
@@ -426,9 +372,7 @@ static double hypot( double a, double b ) {
426372
*/
427373
@Replace( "java/lang/Math.expm1(D)D" )
428374
@Import( module = "Math", name = "expm1" )
429-
static double expm1( double a, double b ) {
430-
return 0; // for Java compiler
431-
}
375+
static native double expm1( double a, double b );
432376

433377
/**
434378
* Replacement for {@link Math#log1p(double)}
@@ -439,9 +383,7 @@ static double expm1( double a, double b ) {
439383
*/
440384
@Replace( "java/lang/Math.log1p(D)D" )
441385
@Import( module = "Math", name = "log1p" )
442-
static double log1p( double a, double b ) {
443-
return 0; // for Java compiler
444-
}
386+
static native double log1p( double a, double b );
445387

446388
/**
447389
* Replacement for {@link Math#copySign(double,double)}
@@ -455,9 +397,7 @@ static double log1p( double a, double b ) {
455397
+ "local.get 1 " //
456398
+ "f64.copysign " //
457399
+ "return" )
458-
static double copySign( double a, double b ) {
459-
return 0; // for Java compiler
460-
}
400+
static native double copySign( double a, double b );
461401

462402
/**
463403
* Replacement for {@link Math#copySign(float,float)}
@@ -471,8 +411,6 @@ static double copySign( double a, double b ) {
471411
+ "local.get 1 " //
472412
+ "f32.copysign " //
473413
+ "return" )
474-
static float copySign( float a, float b ) {
475-
return 0; // for Java compiler
476-
}
414+
static native float copySign( float a, float b );
477415

478416
}

0 commit comments

Comments
 (0)