Skip to content

Commit 5d3bdb5

Browse files
NCF: Move Sp methods to closer to its definition
1 parent d6a66e0 commit 5d3bdb5

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

Sources/WasmKit/Execution/Execution.swift

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,41 @@ typealias Sp = UnsafeMutablePointer<StackSlot>
107107
/// "is compiled" check on the next execution.
108108
typealias Pc = UnsafeMutablePointer<CodeSlot>
109109

110+
extension Sp {
111+
subscript<R: FixedWidthInteger>(_ index: R) -> UntypedValue {
112+
get {
113+
return UntypedValue(storage: self[Int(index)])
114+
}
115+
nonmutating set {
116+
return self[Int(index)] = newValue.storage
117+
}
118+
}
119+
private func read<T: FixedWidthInteger, R: FixedWidthInteger>(_ index: R) -> T {
120+
return self.advanced(by: Int(index)).withMemoryRebound(to: T.self, capacity: 1) {
121+
$0.pointee
122+
}
123+
}
124+
private func write<R: FixedWidthInteger>(_ index: R, _ value: UntypedValue) {
125+
self[Int(index)] = value
126+
}
127+
subscript<R: FixedWidthInteger>(i32 index: R) -> UInt32 {
128+
get { return read(index) }
129+
nonmutating set { write(index, .i32(newValue)) }
130+
}
131+
subscript<R: FixedWidthInteger>(i64 index: R) -> UInt64 {
132+
get { return read(index) }
133+
nonmutating set { write(index, .i64(newValue)) }
134+
}
135+
subscript<R: FixedWidthInteger>(f32 index: R) -> Float32 {
136+
get { return Float32(bitPattern: read(index)) }
137+
nonmutating set { write(index, .f32(newValue)) }
138+
}
139+
subscript<R: FixedWidthInteger>(f64 index: R) -> Float64 {
140+
get { return Float64(bitPattern: read(index)) }
141+
nonmutating set { write(index, .f64(newValue)) }
142+
}
143+
}
144+
110145
extension Pc {
111146
/// Reads a value from the current program counter and advances the pointer.
112147
mutating func read<T>(_: T.Type = T.self) -> T {
@@ -393,38 +428,3 @@ extension Execution {
393428
}
394429
}
395430
}
396-
397-
extension Sp {
398-
subscript<R: FixedWidthInteger>(_ index: R) -> UntypedValue {
399-
get {
400-
return UntypedValue(storage: self[Int(index)])
401-
}
402-
nonmutating set {
403-
return self[Int(index)] = newValue.storage
404-
}
405-
}
406-
private func read<T: FixedWidthInteger, R: FixedWidthInteger>(_ index: R) -> T {
407-
return self.advanced(by: Int(index)).withMemoryRebound(to: T.self, capacity: 1) {
408-
$0.pointee
409-
}
410-
}
411-
private func write<R: FixedWidthInteger>(_ index: R, _ value: UntypedValue) {
412-
self[Int(index)] = value
413-
}
414-
subscript<R: FixedWidthInteger>(i32 index: R) -> UInt32 {
415-
get { return read(index) }
416-
nonmutating set { write(index, .i32(newValue)) }
417-
}
418-
subscript<R: FixedWidthInteger>(i64 index: R) -> UInt64 {
419-
get { return read(index) }
420-
nonmutating set { write(index, .i64(newValue)) }
421-
}
422-
subscript<R: FixedWidthInteger>(f32 index: R) -> Float32 {
423-
get { return Float32(bitPattern: read(index)) }
424-
nonmutating set { write(index, .f32(newValue)) }
425-
}
426-
subscript<R: FixedWidthInteger>(f64 index: R) -> Float64 {
427-
get { return Float64(bitPattern: read(index)) }
428-
nonmutating set { write(index, .f64(newValue)) }
429-
}
430-
}

0 commit comments

Comments
 (0)