|
| 1 | +/// > Note: |
| 2 | +/// <https://webassembly.github.io/spec/core/syntax/instructions.html#variable-instructions> |
| 3 | +extension Execution { |
| 4 | + mutating func globalGet(sp: Sp, immediate: Instruction.GlobalAndVRegOperand) { |
| 5 | + immediate.global.withValue{ |
| 6 | + sp[immediate.reg] = $0.rawValue |
| 7 | + } |
| 8 | + } |
| 9 | + mutating func globalSet(sp: Sp, immediate: Instruction.GlobalAndVRegOperand) { |
| 10 | + let value = sp[immediate.reg] |
| 11 | + immediate.global.withValue{ $0.rawValue = value } |
| 12 | + } |
| 13 | + |
| 14 | + mutating func copyStack(sp: Sp, immediate: Instruction.CopyStackOperand) { |
| 15 | + sp[immediate.dest] = sp[immediate.source] |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +/// > Note: |
| 20 | +/// <https://webassembly.github.io/spec/core/exec/instructions.html#reference-instructions> |
| 21 | +extension Execution { |
| 22 | + mutating func refNull(sp: Sp, immediate: Instruction.RefNullOperand) { |
| 23 | + let value: Value |
| 24 | + switch immediate.type { |
| 25 | + case .externRef: |
| 26 | + value = .ref(.extern(nil)) |
| 27 | + case .funcRef: |
| 28 | + value = .ref(.function(nil)) |
| 29 | + } |
| 30 | + sp[immediate.result] = UntypedValue(value) |
| 31 | + } |
| 32 | + mutating func refIsNull(sp: Sp, immediate: Instruction.RefIsNullOperand) { |
| 33 | + let value = sp[immediate.value] |
| 34 | + |
| 35 | + let result: Value |
| 36 | + if value.isNullRef { |
| 37 | + result = .i32(1) |
| 38 | + } else { |
| 39 | + result = .i32(0) |
| 40 | + } |
| 41 | + sp[immediate.result] = UntypedValue(result) |
| 42 | + } |
| 43 | + mutating func refFunc(sp: Sp, immediate: Instruction.RefFuncOperand) { |
| 44 | + let function = currentInstance(sp: sp).functions[Int(immediate.index)] |
| 45 | + sp[immediate.result] = UntypedValue(.ref(.function(from: function))) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/// > Note: |
| 50 | +/// <https://webassembly.github.io/spec/core/exec/instructions.html#numeric-instructions> |
| 51 | +extension Execution { |
| 52 | + @inline(__always) |
| 53 | + mutating func const32(sp: Sp, immediate: Instruction.Const32Operand) { |
| 54 | + sp[immediate.result] = UntypedValue(storage32: immediate.value) |
| 55 | + } |
| 56 | + @inline(__always) |
| 57 | + mutating func const64(sp: Sp, immediate: Instruction.Const64Operand) { |
| 58 | + sp[immediate.result] = immediate.value |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +/// > Note: |
| 63 | +/// <https://webassembly.github.io/spec/core/exec/instructions.html#parametric-instructions> |
| 64 | +extension Execution { |
| 65 | + mutating func select(sp: Sp, immediate: Instruction.SelectOperand) { |
| 66 | + let flag = sp[i32: immediate.condition] |
| 67 | + let selected = flag != 0 ? immediate.onTrue : immediate.onFalse |
| 68 | + let value = sp[selected] |
| 69 | + sp[immediate.result] = value |
| 70 | + } |
| 71 | +} |
0 commit comments