Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
bd7e162
executing instruction results into InstrunctionResult
RishabhRD Oct 28, 2025
79b3c0c
fix alloc and dealloc instructions
RishabhRD Oct 28, 2025
fc08a71
access instruction returns an address
RishabhRD Oct 28, 2025
8930fc0
make access ad subfield work
RishabhRD Oct 28, 2025
03fae32
register should only store builtin object
RishabhRD Oct 28, 2025
5540797
instruction also provides type
RishabhRD Oct 28, 2025
cd3312f
fix byte offsetting for subfield view
RishabhRD Oct 28, 2025
97df887
feat: implement load instruction
RishabhRD Oct 28, 2025
844594f
no need to store address additionally
RishabhRD Oct 28, 2025
644c565
feat: memory_copy implemented
RishabhRD Oct 28, 2025
e1b3b1d
feat: finally calling function works
RishabhRD Oct 28, 2025
36eb17f
feat: make jump instruction work
RishabhRD Oct 28, 2025
7d5c065
fix: unreal abi type layout calculation for bool
RishabhRD Oct 28, 2025
329a953
feat: store instruction works now
RishabhRD Oct 28, 2025
b70ed18
remove constant_string implementation as it was wrong
RishabhRD Oct 29, 2025
038a88f
Unify stack and heap addresses
RishabhRD Oct 29, 2025
1e258ed
remove unused stack tests
RishabhRD Oct 29, 2025
eb3f50d
remove #expect for checking nothrow
RishabhRD Oct 29, 2025
46f173f
Merge remote-tracking branch 'base/interpreter' into interpreter_func…
RishabhRD Oct 29, 2025
78f918b
moved stackframe to its original location
RishabhRD Oct 31, 2025
c19ee8c
memory operations is independent of stack and heap
RishabhRD Oct 31, 2025
d03877e
document the types properly
RishabhRD Oct 31, 2025
2d8b8aa
store should also get rid of little-endianess
RishabhRD Oct 31, 2025
b003955
update docs to be independent of stack and heap
RishabhRD Oct 31, 2025
605bba1
fix failing CI
RishabhRD Nov 1, 2025
3a78ffd
add relevant dependencies to cmake InterpreterTests
RishabhRD Nov 1, 2025
19ddb56
testing is also a dependency
RishabhRD Nov 1, 2025
22624ed
fix dependencies in package.swift
RishabhRD Nov 1, 2025
9119a7d
add swift-testing as dependency in cmake
RishabhRD Nov 1, 2025
875c1a6
Upgrade cmake modules for finding swift testing
tothambrus11 Nov 1, 2025
8eaaa86
disable interpreter testing target
tothambrus11 Nov 1, 2025
1e740da
remove questionable cmake commands
tothambrus11 Nov 1, 2025
cf5f430
disable cmake testing for interpreter for now
RishabhRD Nov 2, 2025
160255d
every stack allocations should be on different allocation id
RishabhRD Nov 2, 2025
f3085d5
access builtin value using accessors
RishabhRD Nov 2, 2025
5a41037
made asUInt128 initializer as fileprivate
RishabhRD Nov 2, 2025
c0e4e17
migrate to XCTest
RishabhRD Nov 4, 2025
918f632
enable interpreter tests
RishabhRD Nov 4, 2025
2e66e09
Merge branch 'interpreter' into interpreter_function_call
RishabhRD Nov 6, 2025
415c1f9
safe accessors for type stored at offset
RishabhRD Nov 7, 2025
807209d
fix: preconditions on memory tests
RishabhRD Nov 8, 2025
1a89883
added Memory.copy(bytes:,from:,to:) to support copying empty structs
RishabhRD Nov 8, 2025
bf24841
apply jumpTo name suggestion from Dave
RishabhRD Nov 8, 2025
6d1a4b6
Improve naming and documentation
RishabhRD Nov 8, 2025
9e4854c
improve using UntypedBuiltinValue
RishabhRD Nov 8, 2025
e7f854d
Merge branch 'interpreter' into interpreter_function_call
RishabhRD Nov 16, 2025
fbd247c
remove InstructionResult and let it evolve with design
RishabhRD Nov 16, 2025
ceeb73b
stackframe should contain local variables
RishabhRD Nov 16, 2025
9cfa91a
remove untyped builtin value
RishabhRD Nov 16, 2025
c2b44ab
remove the use of denotedBy
RishabhRD Nov 16, 2025
7e76b30
address of subfield in parent field
RishabhRD Nov 16, 2025
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
49 changes: 9 additions & 40 deletions Sources/Interpreter/Interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct StackFrame {
var parameters: [Address]

/// The results of instructions.
var registers: [InstructionID: InstructionResult] = [:]
var registers: [InstructionID: Any] = [:]

/// The program counter to which execution should return when
/// popping this frame.
Expand All @@ -37,37 +37,6 @@ struct Address {

}

/// The value produced by executing an instruction.
enum InstructionResult {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a named type was a good idea. Maybe just an alias?


/// If executing instruction produces an address.
case address(Address)

/// If executing instruction produces a builtin value.
case builtIn(UntypedBuiltinValue)

/// Address, if present.
public var address: Address? {
switch self {
case .address(let x):
return x
default:
return nil
}
}

/// Builtin value, if present.
public var builtIn: UntypedBuiltinValue? {
switch self {
case .builtIn(let x):
return x
default:
return nil
}
}

}

extension UnsafeRawPointer {

/// Returns the number of bytes from `self` to the nearest address
Expand Down Expand Up @@ -143,7 +112,7 @@ public struct Interpreter {
typeLayout = .init(typesIn: p.base, for: UnrealABI())
}

private var currentRegister: InstructionResult? {
private var currentRegister: Any? {
get { topOfStack.registers[programCounter.instructionInModule]! }
set { topOfStack.registers[programCounter.instructionInModule] = newValue }
}
Expand All @@ -153,7 +122,7 @@ public struct Interpreter {
print("\(currentInstruction.site.gnuStandardText): \(currentInstruction)")
switch currentInstruction {
case let x as Access:
currentRegister = .address(address(denotedBy: x.source)!)
currentRegister = address(denotedBy: x.source)!
case let x as AddressToPointer:
_ = x
case let x as AdvancedByBytes:
Expand All @@ -162,7 +131,7 @@ public struct Interpreter {
_ = x

case let x as AllocStack:
currentRegister = .address(allocate(typeLayout[x.allocatedType]))
currentRegister = allocate(typeLayout[x.allocatedType])

case let x as Branch:
jumpTo(x.target)
Expand Down Expand Up @@ -195,7 +164,7 @@ public struct Interpreter {
case let x as ConstantString:
_ = x
case let x as DeallocStack:
try deallocate(topOfStack.registers[x.location.instruction!]!.address!)
try deallocate(topOfStack.registers[x.location.instruction!]! as! Address)
case is EndAccess:
// No effect on program state
break
Expand All @@ -207,7 +176,7 @@ public struct Interpreter {
_ = x
case let x as Load:
let address = address(denotedBy: x.source)!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This denotedBy label isn't working for me.

currentRegister = .builtIn(builtIn(at: address)!)
currentRegister = builtIn(at: address)!
case is MarkState:
// No effect on program state
break
Expand Down Expand Up @@ -239,7 +208,7 @@ public struct Interpreter {
store(builtIn(denotedBy: x.object)!, at: address(denotedBy: x.target)!)
case let x as SubfieldView:
let parent = address(denotedBy: x.recordAddress)!;
currentRegister = .address(address(of: x.subfield, at: parent))
currentRegister = address(of: x.subfield, at: parent)
case let x as Switch:
_ = x
case let x as UnionDiscriminator:
Expand Down Expand Up @@ -328,7 +297,7 @@ public struct Interpreter {
func address(denotedBy operand: Operand) -> Address? {
switch operand {
case .register(let instruction):
return topOfStack.registers[instruction]?.address
return topOfStack.registers[instruction] as? Address
case .parameter(_, let i):
return topOfStack.parameters[i]
case .constant:
Expand All @@ -340,7 +309,7 @@ public struct Interpreter {
func builtIn(denotedBy operand: Operand) -> UntypedBuiltinValue? {
switch operand {
case .register(let instruction):
return topOfStack.registers[instruction]?.builtIn
return topOfStack.registers[instruction] as? UntypedBuiltinValue
case .parameter:
return nil;
case .constant(let c):
Expand Down