Skip to content

Commit 5d86807

Browse files
committed
build: fix kotlin and csharp compilation
1 parent b8b3bf8 commit 5d86807

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

src.compiler/csharp/CSharpEmitterContext.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,15 @@ export default class CSharpEmitterContext {
13221322
return true;
13231323
}
13241324

1325+
// no casts to "object"
1326+
if (
1327+
'objectFlags' in contextualType &&
1328+
'intrinsicName' in contextualType &&
1329+
contextualType.intrinsicName === 'object'
1330+
) {
1331+
return true;
1332+
}
1333+
13251334
// some core types
13261335
if (contextualType.symbol) {
13271336
switch (contextualType.symbol.name) {

src.compiler/kotlin/KotlinAstPrinter.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -1279,14 +1279,30 @@ export default class KotlinAstPrinter extends AstPrinterBase {
12791279

12801280
let hasDefault = false;
12811281

1282-
s.caseClauses.forEach(c => {
1282+
for(let i = 0; i < s.caseClauses.length; i++) {
1283+
const c = s.caseClauses[i];
12831284
if (cs.isDefaultClause(c)) {
12841285
hasDefault = true;
12851286
this.writeDefaultClause(c as cs.DefaultClause);
12861287
} else {
1287-
this.writeCaseClause(c as cs.CaseClause);
1288+
// avoid "value", "value2", else ->
1289+
// but write directly else ->
1290+
let hasNonElseStatement = false;
1291+
for(let j = i; j < s.caseClauses.length; j++) {
1292+
const c2 = s.caseClauses[j];
1293+
if(cs.isDefaultClause(c2)) {
1294+
break;
1295+
} else if((c2 as cs.CaseClause).statements.length > 0) {
1296+
hasNonElseStatement = true;
1297+
break;
1298+
}
1299+
}
1300+
1301+
if(hasNonElseStatement) {
1302+
this.writeCaseClause(c as cs.CaseClause);
1303+
}
12881304
}
1289-
});
1305+
}
12901306

12911307
if (!hasDefault) {
12921308
this.writeLine('else -> { }');

src.csharp/AlphaTab/Io/TypeConversions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace AlphaTab.Io;
45

@@ -9,6 +10,16 @@ public static double BytesToFloat32LE(Uint8Array array)
910
return BitConverter.ToSingle(array.Data.Array!, array.Data.Offset);
1011
}
1112

13+
public static Uint8Array Float32BEToBytes(double v)
14+
{
15+
var bytes = BitConverter.GetBytes((float)v);
16+
if (BitConverter.IsLittleEndian)
17+
{
18+
bytes.Reverse();
19+
}
20+
return new Uint8Array(new ArrayBuffer(bytes));
21+
}
22+
1223
public static double BytesToFloat64LE(Uint8Array array)
1324
{
1425
return BitConverter.ToDouble(array.Data.Array!, array.Data.Offset);

src.kotlin/alphaTab/android/src/main/java/alphaTab/io/TypeConversions.kt

+8
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ internal class TypeConversions {
4242
.order(java.nio.ByteOrder.LITTLE_ENDIAN)
4343
return buffer.getInt().toDouble()
4444
}
45+
46+
fun float32BEToBytes(v:Double): Uint8Array {
47+
val buffer = ByteArray(4);
48+
java.nio.ByteBuffer.wrap(buffer)
49+
.order(java.nio.ByteOrder.BIG_ENDIAN)
50+
.putFloat(v.toFloat());
51+
return Uint8Array(buffer.toUByteArray());
52+
}
4553
}
4654
}

0 commit comments

Comments
 (0)