Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2381,14 +2381,10 @@ struct IntrinsicJSFragment: Sendable {
if method.returnType == .void {
printer.write("\(callExpr);")
} else {
printer.write("const ret = \(callExpr);")
}

// Lift return value if needed
if method.returnType != .void {
let liftFragment = try IntrinsicJSFragment.liftReturn(type: method.returnType)
let liftArgs = liftFragment.parameters.isEmpty ? [] : ["ret"]
let lifted = try liftFragment.printCode(liftArgs, context)
let returnVariable = context.scope.variable("ret")
printer.write("const \(returnVariable) = \(callExpr);")
let lifted = try liftFragment.printCode([returnVariable], context)
if let liftedValue = lifted.first {
printer.write("return \(liftedValue);")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ extension Vector2D {
@JS func scaled(by factor: Double) -> Vector2D {
return Vector2D(dx: dx * factor, dy: dy * factor)
}

@JS func describe() -> String {
return "Vector2D(\(dx), \(dy))"
}
}

extension DataPoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,23 @@
"_0" : "Vector2D"
}
}
},
{
"abiName" : "bjs_Vector2D_describe",
"effects" : {
"isAsync" : false,
"isStatic" : false,
"isThrows" : false
},
"name" : "describe",
"parameters" : [

],
"returnType" : {
"string" : {

}
}
}
],
"name" : "Vector2D",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,17 @@ public func _bjs_Vector2D_scaled(_ factor: Float64) -> Void {
#endif
}

@_expose(wasm, "bjs_Vector2D_describe")
@_cdecl("bjs_Vector2D_describe")
public func _bjs_Vector2D_describe() -> Void {
#if arch(wasm32)
let ret = Vector2D.bridgeJSLiftParameter().describe()
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_roundtrip")
@_cdecl("bjs_roundtrip")
public func _bjs_roundtrip() -> Void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export async function createInstantiator(options, swift) {
}.bind(instance1);
instance1.multiply = function(a, b) {
structHelpers.MathOperations.lower(this);
const ret = instance.exports.bjs_MathOperations_multiply(a, b);
return ret;
const ret1 = instance.exports.bjs_MathOperations_multiply(a, b);
return ret1;
}.bind(instance1);
return instance1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface Vector2D {
dy: number;
magnitude(): number;
scaled(factor: number): Vector2D;
describe(): string;
}
export type PrecisionObject = typeof PrecisionValues;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,17 @@ export async function createInstantiator(options, swift) {
}.bind(instance1);
instance1.scaled = function(factor) {
structHelpers.Vector2D.lower(this);
const ret = instance.exports.bjs_Vector2D_scaled(factor);
const ret1 = instance.exports.bjs_Vector2D_scaled(factor);
const structValue = structHelpers.Vector2D.lift();
return structValue;
}.bind(instance1);
instance1.describe = function() {
structHelpers.Vector2D.lower(this);
const ret2 = instance.exports.bjs_Vector2D_describe();
const ret3 = tmpRetString;
tmpRetString = undefined;
return ret3;
}.bind(instance1);
return instance1;
}
});
Expand Down
Loading