Skip to content
Merged
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
36 changes: 18 additions & 18 deletions Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { _, scope, printer, _ in
let retName = scope.variable("ret")
printer.write(
"const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()));"
)
return [retName]
}
Expand Down Expand Up @@ -699,7 +699,7 @@ struct IntrinsicJSFragment: Sendable {
printer.write("if (\(isSome)) {")
printer.indent {
printer.write(
"\(enumVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(wrappedValue), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(enumVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(wrappedValue));"
)
}
printer.write("}")
Expand All @@ -711,7 +711,7 @@ struct IntrinsicJSFragment: Sendable {
printer.write("if (\(isSome)) {")
printer.indent {
printer.write(
"\(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();"
)
}
printer.write("} else {")
Expand Down Expand Up @@ -944,7 +944,7 @@ struct IntrinsicJSFragment: Sendable {
printer.write("} else {")
printer.indent {
printer.write(
"\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(tagVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(tagVar));"
)
}
printer.write("}")
Expand All @@ -956,7 +956,7 @@ struct IntrinsicJSFragment: Sendable {
printer.write("if (\(isSomeVar)) {")
printer.indent {
printer.write(
"\(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();"
)
}
printer.write("} else {")
Expand Down Expand Up @@ -1283,7 +1283,7 @@ struct IntrinsicJSFragment: Sendable {
let targetVar = arguments[1]
let base = fullName.components(separatedBy: ".").last ?? fullName
printer.write(
"let \(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"let \(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId));"
)
return []
}
Expand Down Expand Up @@ -1354,7 +1354,7 @@ struct IntrinsicJSFragment: Sendable {
case .associatedValueEnum(let fullName):
let base = fullName.components(separatedBy: ".").last ?? fullName
printer.write(
"\(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(value), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(value));"
)
default:
fatalError("Unsupported optional wrapped type in closure parameter lifting: \(wrappedType)")
Expand Down Expand Up @@ -1682,7 +1682,7 @@ struct IntrinsicJSFragment: Sendable {
let base = fullName.components(separatedBy: ".").last ?? fullName
let resultVar = scope.variable("result")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()));"
)
printer.write("return \(resultVar);")
return []
Expand Down Expand Up @@ -1907,7 +1907,7 @@ struct IntrinsicJSFragment: Sendable {
let caseId = arguments[0]
let resultVar = scope.variable("enumValue")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId));"
)
return [resultVar]
}
Expand All @@ -1924,7 +1924,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { arguments, scope, printer, cleanupCode in
let resultVar = scope.variable("structValue")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();"
)
return [resultVar]
}
Expand Down Expand Up @@ -2107,7 +2107,7 @@ struct IntrinsicJSFragment: Sendable {

// Generate lift function
printer.write(
"lift: (tag, \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers)) => {"
"lift: (tag) => {"
)
printer.indent {
printer.write("tag = tag | 0;")
Expand Down Expand Up @@ -2505,7 +2505,7 @@ struct IntrinsicJSFragment: Sendable {
let caseIdVar = scope.variable("caseId")
printer.write("const \(caseIdVar) = \(scope.popI32Return());")
printer.write(
"\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar));"
)
} else {
let wrappedFragment = associatedValuePopPayload(type: wrappedType)
Expand Down Expand Up @@ -2565,7 +2565,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { arguments, scope, printer, cleanupCode in
let resultVar = scope.variable("structValue")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift();"
)
return [resultVar]
}
Expand Down Expand Up @@ -2705,7 +2705,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { arguments, scope, printer, cleanup in
let resultVar = scope.variable("struct")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift();"
)
return [resultVar]
}
Expand Down Expand Up @@ -2765,7 +2765,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { arguments, scope, printer, cleanup in
let resultVar = scope.variable("enumValue")
printer.write(
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), );"
)
return [resultVar]
}
Expand Down Expand Up @@ -3125,7 +3125,7 @@ struct IntrinsicJSFragment: Sendable {
printer.write("},")

printer.write(
"lift: (\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers)) => {"
"lift: () => {"
)
printer.indent {
generateStructLiftCode(
Expand Down Expand Up @@ -3678,7 +3678,7 @@ struct IntrinsicJSFragment: Sendable {
let caseIdVar = scope.variable("enumCaseId")
printer.write("const \(caseIdVar) = \(scope.popI32Return());")
printer.write(
"\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), );"
)
} else {
let wrappedFragment = structFieldLiftFragment(
Expand Down Expand Up @@ -3712,7 +3712,7 @@ struct IntrinsicJSFragment: Sendable {
printCode: { arguments, scope, printer, cleanup in
let structVar = scope.variable("struct")
printer.write(
"const \(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));"
"const \(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lift();"
)
return [structVar]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function createInstantiator(options, swift) {
tmpParamF64s.push(value.y);
return { cleanup: undefined };
},
lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => {
lift: () => {
const f64 = tmpRetF64s.pop();
const f641 = tmpRetF64s.pop();
return { x: f641, y: f64 };
Expand Down Expand Up @@ -481,7 +481,7 @@ export async function createInstantiator(options, swift) {
const arrayLen = tmpRetInts.pop();
const arrayResult = [];
for (let i = 0; i < arrayLen; i++) {
const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
const struct = structHelpers.Point.lift();
arrayResult.push(struct);
}
arrayResult.reverse();
Expand Down Expand Up @@ -544,7 +544,7 @@ export async function createInstantiator(options, swift) {
const matchingBytes = textEncoder.encode(matching);
const matchingId = swift.memory.retain(matchingBytes);
instance.exports.bjs_findFirstPoint(matchingId, matchingBytes.length);
const structValue = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
const structValue = structHelpers.Point.lift();
for (const cleanup of arrayCleanups) { cleanup(); }
swift.memory.release(matchingId);
return structValue;
Expand Down Expand Up @@ -715,7 +715,7 @@ export async function createInstantiator(options, swift) {
if (isSome1 === 0) {
optValue = null;
} else {
const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
const struct = structHelpers.Point.lift();
optValue = struct;
}
arrayResult.push(optValue);
Expand Down Expand Up @@ -873,7 +873,7 @@ export async function createInstantiator(options, swift) {
const arrayLen1 = tmpRetInts.pop();
const arrayResult1 = [];
for (let i1 = 0; i1 < arrayLen1; i1++) {
const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
const struct = structHelpers.Point.lift();
arrayResult1.push(struct);
}
arrayResult1.reverse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function createInstantiator(options, swift) {
};
return { cleanup };
},
lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => {
lift: () => {
const bool = tmpRetInts.pop() !== 0;
const int = tmpRetInts.pop();
const string = tmpRetStrings.pop();
Expand All @@ -68,7 +68,7 @@ export async function createInstantiator(options, swift) {
tmpParamF64s.push(value.baseValue);
return { cleanup: undefined };
},
lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => {
lift: () => {
const f64 = tmpRetF64s.pop();
const instance1 = { baseValue: f64 };
instance1.add = function(a, b = 10.0) {
Expand Down Expand Up @@ -528,7 +528,7 @@ export async function createInstantiator(options, swift) {
const isSome1 = tmpRetInts.pop();
let optResult;
if (isSome1) {
optResult = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
optResult = structHelpers.Config.lift();
} else {
optResult = null;
}
Expand All @@ -546,7 +546,7 @@ export async function createInstantiator(options, swift) {
const isSome1 = tmpRetInts.pop();
let optResult;
if (isSome1) {
optResult = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
optResult = structHelpers.Config.lift();
} else {
optResult = null;
}
Expand Down Expand Up @@ -663,7 +663,7 @@ export async function createInstantiator(options, swift) {
MathOperations: {
init: function(baseValue = 0.0) {
instance.exports.bjs_MathOperations_init(baseValue);
const structValue = structHelpers.MathOperations.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers);
const structValue = structHelpers.MathOperations.lift();
return structValue;
},
subtract: function(a, b) {
Expand Down
Loading