Skip to content

Commit 2645c4f

Browse files
full qualify Address to avoid collision with wit record of same name (#960)
* full qualify Address to avoid collision with wit record of same name * add test for fully qualified java address --------- Co-authored-by: Alex Crichton <[email protected]>
1 parent 3ca7739 commit 2645c4f

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

crates/teavm-java/src/lib.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,15 @@ impl Bindgen for FunctionBindgen<'_, '_> {
15691569
// Note that we can only reliably use `Address.ofData` for elements with alignment <= 4 because as
15701570
// of this writing TeaVM does not guarantee 64 bit items are aligned on 8 byte boundaries.
15711571
if realloc.is_none() && size <= 4 {
1572-
results.push(format!("Address.ofData({op}).toInt()"));
1572+
results.push(format!("org.teavm.interop.Address.ofData({op}).toInt()"));
15731573
} else {
15741574
let address = self.locals.tmp("address");
15751575
let ty = ty.to_upper_camel_case();
15761576

15771577
uwrite!(
15781578
self.src,
15791579
"
1580-
Address {address} = Memory.malloc({size} * ({op}).length, {size});
1580+
org.teavm.interop.Address {address} = Memory.malloc({size} * ({op}).length, {size});
15811581
Memory.put{ty}s({address}, {op}, 0, ({op}).length);
15821582
"
15831583
);
@@ -1606,7 +1606,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16061606
self.src,
16071607
"
16081608
{ty}[] {array} = new {ty}[{length}];
1609-
Memory.get{ty_upper}s(Address.fromInt({address}), {array}, 0, ({array}).length);
1609+
Memory.get{ty_upper}s(org.teavm.interop.Address.fromInt({address}), {array}, 0, ({array}).length);
16101610
"
16111611
);
16121612

@@ -1622,14 +1622,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16221622
);
16231623

16241624
if realloc.is_none() {
1625-
results.push(format!("Address.ofData({bytes}).toInt()"));
1625+
results.push(format!("org.teavm.interop.Address.ofData({bytes}).toInt()"));
16261626
} else {
16271627
let address = self.locals.tmp("address");
16281628

16291629
uwrite!(
16301630
self.src,
16311631
"
1632-
Address {address} = Memory.malloc({bytes}.length, 1);
1632+
org.teavm.interop.Address {address} = Memory.malloc({bytes}.length, 1);
16331633
Memory.putBytes({address}, {bytes}, 0, {bytes}.length);
16341634
"
16351635
);
@@ -1648,7 +1648,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
16481648
self.src,
16491649
"
16501650
byte[] {bytes} = new byte[{length}];
1651-
Memory.getBytes(Address.fromInt({address}), {bytes}, 0, {length});
1651+
Memory.getBytes(org.teavm.interop.Address.fromInt({address}), {bytes}, 0, {length});
16521652
"
16531653
);
16541654

@@ -1724,7 +1724,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
17241724
{body}
17251725
{array}.add({result});
17261726
}}
1727-
Memory.free(Address.fromInt({address}), ({length}) * {size}, {align});
1727+
Memory.free(org.teavm.interop.Address.fromInt({address}), ({length}) * {size}, {align});
17281728
"
17291729
);
17301730

@@ -1829,7 +1829,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18291829
{
18301830
uwriteln!(
18311831
self.src,
1832-
"Memory.free(Address.fromInt({address}), {size}, {align});"
1832+
"Memory.free(org.teavm.interop.Address.fromInt({address}), {size}, {align});"
18331833
);
18341834
}
18351835

@@ -1838,7 +1838,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18381838
self.src,
18391839
"
18401840
for ({}Cleanup cleanup : cleanupList) {{
1841-
Memory.free(Address.fromInt(cleanup.address), cleanup.size, cleanup.align);
1841+
Memory.free(org.teavm.interop.Address.fromInt(cleanup.address), cleanup.size, cleanup.align);
18421842
}}
18431843
",
18441844
self.gen.gen.qualifier()
@@ -1862,85 +1862,85 @@ impl Bindgen for FunctionBindgen<'_, '_> {
18621862
Instruction::I32Load { offset }
18631863
| Instruction::PointerLoad { offset }
18641864
| Instruction::LengthLoad { offset } => results.push(format!(
1865-
"Address.fromInt(({}) + {offset}).getInt()",
1865+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getInt()",
18661866
operands[0]
18671867
)),
18681868

18691869
Instruction::I32Load8U { offset } => results.push(format!(
1870-
"(((int) Address.fromInt(({}) + {offset}).getByte()) & 0xFF)",
1870+
"(((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getByte()) & 0xFF)",
18711871
operands[0]
18721872
)),
18731873

18741874
Instruction::I32Load8S { offset } => results.push(format!(
1875-
"((int) Address.fromInt(({}) + {offset}).getByte())",
1875+
"((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getByte())",
18761876
operands[0]
18771877
)),
18781878

18791879
Instruction::I32Load16U { offset } => results.push(format!(
1880-
"(((int) Address.fromInt(({}) + {offset}).getShort()) & 0xFFFF)",
1880+
"(((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getShort()) & 0xFFFF)",
18811881
operands[0]
18821882
)),
18831883

18841884
Instruction::I32Load16S { offset } => results.push(format!(
1885-
"((int) Address.fromInt(({}) + {offset}).getShort())",
1885+
"((int) org.teavm.interop.Address.fromInt(({}) + {offset}).getShort())",
18861886
operands[0]
18871887
)),
18881888

18891889
Instruction::I64Load { offset } => results.push(format!(
1890-
"Address.fromInt(({}) + {offset}).getLong()",
1890+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getLong()",
18911891
operands[0]
18921892
)),
18931893

18941894
Instruction::F32Load { offset } => results.push(format!(
1895-
"Address.fromInt(({}) + {offset}).getFloat()",
1895+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getFloat()",
18961896
operands[0]
18971897
)),
18981898

18991899
Instruction::F64Load { offset } => results.push(format!(
1900-
"Address.fromInt(({}) + {offset}).getDouble()",
1900+
"org.teavm.interop.Address.fromInt(({}) + {offset}).getDouble()",
19011901
operands[0]
19021902
)),
19031903

19041904
Instruction::I32Store { offset }
19051905
| Instruction::PointerStore { offset }
19061906
| Instruction::LengthStore { offset } => uwriteln!(
19071907
self.src,
1908-
"Address.fromInt(({}) + {offset}).putInt({});",
1908+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putInt({});",
19091909
operands[1],
19101910
operands[0]
19111911
),
19121912

19131913
Instruction::I32Store8 { offset } => uwriteln!(
19141914
self.src,
1915-
"Address.fromInt(({}) + {offset}).putByte((byte) ({}));",
1915+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putByte((byte) ({}));",
19161916
operands[1],
19171917
operands[0]
19181918
),
19191919

19201920
Instruction::I32Store16 { offset } => uwriteln!(
19211921
self.src,
1922-
"Address.fromInt(({}) + {offset}).putShort((short) ({}));",
1922+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putShort((short) ({}));",
19231923
operands[1],
19241924
operands[0]
19251925
),
19261926

19271927
Instruction::I64Store { offset } => uwriteln!(
19281928
self.src,
1929-
"Address.fromInt(({}) + {offset}).putLong({});",
1929+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putLong({});",
19301930
operands[1],
19311931
operands[0]
19321932
),
19331933

19341934
Instruction::F32Store { offset } => uwriteln!(
19351935
self.src,
1936-
"Address.fromInt(({}) + {offset}).putFloat({});",
1936+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putFloat({});",
19371937
operands[1],
19381938
operands[0]
19391939
),
19401940

19411941
Instruction::F64Store { offset } => uwriteln!(
19421942
self.src,
1943-
"Address.fromInt(({}) + {offset}).putDouble({});",
1943+
"org.teavm.interop.Address.fromInt(({}) + {offset}).putDouble({});",
19441944
operands[1],
19451945
operands[0]
19461946
),
@@ -1950,14 +1950,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
19501950
Instruction::GuestDeallocate { size, align } => {
19511951
uwriteln!(
19521952
self.src,
1953-
"Memory.free(Address.fromInt({}), {size}, {align});",
1953+
"Memory.free(org.teavm.interop.Address.fromInt({}), {size}, {align});",
19541954
operands[0]
19551955
)
19561956
}
19571957

19581958
Instruction::GuestDeallocateString => uwriteln!(
19591959
self.src,
1960-
"Memory.free(Address.fromInt({}), {}, 1);",
1960+
"Memory.free(org.teavm.interop.Address.fromInt({}), {}, 1);",
19611961
operands[0],
19621962
operands[1]
19631963
),
@@ -2023,7 +2023,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
20232023

20242024
uwriteln!(
20252025
self.src,
2026-
"Memory.free(Address.fromInt({address}), ({length}) * {size}, {align});"
2026+
"Memory.free(org.teavm.interop.Address.fromInt({address}), ({length}) * {size}, {align});"
20272027
);
20282028
}
20292029
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package foo:bar;
2+
3+
interface my-import {
4+
record address {
5+
field: u32,
6+
attribute: bool,
7+
}
8+
}
9+
10+
world bindings {
11+
import my-import;
12+
13+
export init: func(baz: string);
14+
}

0 commit comments

Comments
 (0)