Skip to content

Commit

Permalink
Merge pull request #68 from MaxDesiatov/maxd/internalize-guest-function
Browse files Browse the repository at this point in the history
Mark `Function` as `internal` and rename it as `GuestFunction`
  • Loading branch information
kateinoigakukun authored Nov 14, 2023
2 parents ddf4b2f + f8ebe85 commit ff44b0a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sources/WasmKit/Execution/Runtime/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ extension Store {

/// > Note:
/// <https://webassembly.github.io/spec/core/exec/modules.html#alloc-func>
func allocate(function: Function, module: ModuleInstance) -> FunctionAddress {
func allocate(function: GuestFunction, module: ModuleInstance) -> FunctionAddress {
let address = functions.count
let instance = FunctionInstance(function, module: module)
functions.append(instance)
Expand Down
4 changes: 2 additions & 2 deletions Sources/WasmKit/Execution/Types/Instances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public final class ModuleInstance {
public struct FunctionInstance {
public let type: FunctionType
public let module: ModuleInstance
public var code: Function
var code: GuestFunction

init(_ function: Function, module: ModuleInstance) {
init(_ function: GuestFunction, module: ModuleInstance) {
type = module.types[Int(function.type)]
self.module = module
code = function
Expand Down
2 changes: 1 addition & 1 deletion Sources/WasmKit/Parser/Wasm/WasmParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ extension WasmParser {
}

let functions = codes.enumerated().map { [hasDataCount, features] index, code in
Function(
GuestFunction(
type: typeIndices[index], locals: code.locals,
body: {
let stream = StaticByteStream(bytes: Array(code.expression))
Expand Down
8 changes: 4 additions & 4 deletions Sources/WasmKit/Types/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// <https://webassembly.github.io/spec/core/syntax/modules.html#modules>
public struct Module {
public internal(set) var types: [FunctionType]
public internal(set) var functions: [Function]
var functions: [GuestFunction]
public internal(set) var tables: [Table]
public internal(set) var memories: [Memory]
public internal(set) var globals: [Global]
Expand All @@ -16,9 +16,9 @@ public struct Module {
public internal(set) var exports: [Export]
public internal(set) var customSections = [CustomSection]()

public init(
init(
types: [FunctionType] = [],
functions: [Function] = [],
functions: [GuestFunction] = [],
tables: [Table] = [],
memories: [Memory] = [],
globals: [Global] = [],
Expand Down Expand Up @@ -67,7 +67,7 @@ public typealias LabelIndex = UInt32

/// > Note:
/// <https://webassembly.github.io/spec/core/syntax/modules.html#functions>
public struct Function {
struct GuestFunction {
init(type: TypeIndex, locals: [ValueType], body: @escaping () throws -> Expression) {
self.type = type
self.locals = locals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ final class ControlInstructionTests: XCTestCase {
}
}

extension Function {
extension GuestFunction {
init(type: TypeIndex, locals: [ValueType], body: Expression) {
self.init(type: type, locals: locals, body: { body })
}
Expand Down

0 comments on commit ff44b0a

Please sign in to comment.