Skip to content

Commit

Permalink
Added 7 and 8 parameter native function and call (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksmtownsend authored Jul 1, 2021
1 parent a1a679c commit 3611d65
Show file tree
Hide file tree
Showing 3 changed files with 428 additions and 0 deletions.
108 changes: 108 additions & 0 deletions Sources/WasmInterpreter/NativeFunctionSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,114 @@ func signature<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Ret>(
return signature
}

func signature<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(
arg1: Arg1.Type,
arg2: Arg2.Type,
arg3: Arg3.Type,
arg4: Arg4.Type,
arg5: Arg5.Type,
arg6: Arg6.Type,
arg7: Arg7.Type
) throws -> String
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol, Arg4: WasmTypeProtocol,
Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol, Arg7: WasmTypeProtocol
{
var signature = "v"
signature += "("
signature += try signatureIdentifier(for: arg1.self) + " "
signature += try signatureIdentifier(for: arg2.self) + " "
signature += try signatureIdentifier(for: arg3.self) + " "
signature += try signatureIdentifier(for: arg4.self) + " "
signature += try signatureIdentifier(for: arg5.self) + " "
signature += try signatureIdentifier(for: arg6.self) + " "
signature += try signatureIdentifier(for: arg7.self)
signature += ")"
return signature
}

func signature<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Ret>(
arg1: Arg1.Type,
arg2: Arg2.Type,
arg3: Arg3.Type,
arg4: Arg4.Type,
arg5: Arg5.Type,
arg6: Arg6.Type,
arg7: Arg7.Type,
ret: Ret.Type
) throws -> String
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol, Arg4: WasmTypeProtocol,
Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol, Arg7: WasmTypeProtocol, Ret: WasmTypeProtocol
{
var signature = ""
signature += try signatureIdentifier(for: ret.self)
signature += "("
signature += try signatureIdentifier(for: arg1.self) + " "
signature += try signatureIdentifier(for: arg2.self) + " "
signature += try signatureIdentifier(for: arg3.self) + " "
signature += try signatureIdentifier(for: arg4.self) + " "
signature += try signatureIdentifier(for: arg5.self) + " "
signature += try signatureIdentifier(for: arg6.self) + " "
signature += try signatureIdentifier(for: arg7.self)
signature += ")"
return signature
}

func signature<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(
arg1: Arg1.Type,
arg2: Arg2.Type,
arg3: Arg3.Type,
arg4: Arg4.Type,
arg5: Arg5.Type,
arg6: Arg6.Type,
arg7: Arg7.Type,
arg8: Arg8.Type
) throws -> String
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol, Arg4: WasmTypeProtocol,
Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol, Arg7: WasmTypeProtocol, Arg8: WasmTypeProtocol
{
var signature = "v"
signature += "("
signature += try signatureIdentifier(for: arg1.self) + " "
signature += try signatureIdentifier(for: arg2.self) + " "
signature += try signatureIdentifier(for: arg3.self) + " "
signature += try signatureIdentifier(for: arg4.self) + " "
signature += try signatureIdentifier(for: arg5.self) + " "
signature += try signatureIdentifier(for: arg6.self) + " "
signature += try signatureIdentifier(for: arg7.self) + " "
signature += try signatureIdentifier(for: arg8.self)
signature += ")"
return signature
}

func signature<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Ret>(
arg1: Arg1.Type,
arg2: Arg2.Type,
arg3: Arg3.Type,
arg4: Arg4.Type,
arg5: Arg5.Type,
arg6: Arg6.Type,
arg7: Arg7.Type,
arg8: Arg8.Type,
ret: Ret.Type
) throws -> String
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol, Arg4: WasmTypeProtocol,
Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol, Arg7: WasmTypeProtocol, Arg8: WasmTypeProtocol, Ret: WasmTypeProtocol
{
var signature = ""
signature += try signatureIdentifier(for: ret.self)
signature += "("
signature += try signatureIdentifier(for: arg1.self) + " "
signature += try signatureIdentifier(for: arg2.self) + " "
signature += try signatureIdentifier(for: arg3.self) + " "
signature += try signatureIdentifier(for: arg4.self) + " "
signature += try signatureIdentifier(for: arg5.self) + " "
signature += try signatureIdentifier(for: arg6.self) + " "
signature += try signatureIdentifier(for: arg7.self) + " "
signature += try signatureIdentifier(for: arg8.self)
signature += ")"
return signature
}

func signatureIdentifier<T: WasmTypeProtocol>(for type: T.Type) throws -> String {
if Int32.self == T.self { return "i" }
else if Int64.self == T.self { return "I" }
Expand Down
64 changes: 64 additions & 0 deletions Sources/WasmInterpreter/WasmInterpreter+Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,68 @@ extension WasmInterpreter {
try String(wasmType: arg4), try String(wasmType: arg5), try String(wasmType: arg6)]
)
}

public func call<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7>(
_ name: String, _ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3,
_ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7
) throws
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol,
Arg4: WasmTypeProtocol, Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol,
Arg7: WasmTypeProtocol
{
try _call(
try function(named: name),
args: [try String(wasmType: arg1), try String(wasmType: arg2), try String(wasmType: arg3),
try String(wasmType: arg4), try String(wasmType: arg5), try String(wasmType: arg6),
try String(wasmType: arg7)]
)
}

public func call<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Ret>(
_ name: String, _ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3,
_ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7
) throws -> Ret
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol,
Arg4: WasmTypeProtocol, Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol,
Arg7: WasmTypeProtocol, Ret: WasmTypeProtocol
{
return try _call(
try function(named: name),
args: [try String(wasmType: arg1), try String(wasmType: arg2), try String(wasmType: arg3),
try String(wasmType: arg4), try String(wasmType: arg5), try String(wasmType: arg6),
try String(wasmType: arg7)]
)
}

public func call<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8>(
_ name: String, _ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3,
_ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8
) throws
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol,
Arg4: WasmTypeProtocol, Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol,
Arg7: WasmTypeProtocol, Arg8: WasmTypeProtocol
{
try _call(
try function(named: name),
args: [try String(wasmType: arg1), try String(wasmType: arg2), try String(wasmType: arg3),
try String(wasmType: arg4), try String(wasmType: arg5), try String(wasmType: arg6),
try String(wasmType: arg7), try String(wasmType: arg8)]
)
}

public func call<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Ret>(
_ name: String, _ arg1: Arg1, _ arg2: Arg2, _ arg3: Arg3,
_ arg4: Arg4, _ arg5: Arg5, _ arg6: Arg6, _ arg7: Arg7, _ arg8: Arg8
) throws -> Ret
where Arg1: WasmTypeProtocol, Arg2: WasmTypeProtocol, Arg3: WasmTypeProtocol,
Arg4: WasmTypeProtocol, Arg5: WasmTypeProtocol, Arg6: WasmTypeProtocol,
Arg7: WasmTypeProtocol, Arg8: WasmTypeProtocol, Ret: WasmTypeProtocol
{
return try _call(
try function(named: name),
args: [try String(wasmType: arg1), try String(wasmType: arg2), try String(wasmType: arg3),
try String(wasmType: arg4), try String(wasmType: arg5), try String(wasmType: arg6),
try String(wasmType: arg7), try String(wasmType: arg8)]
)
}
}
Loading

0 comments on commit 3611d65

Please sign in to comment.