-
Notifications
You must be signed in to change notification settings - Fork 58
Interpreter: Make function calls and basic instructions working #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
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 79b3c0c
fix alloc and dealloc instructions
RishabhRD fc08a71
access instruction returns an address
RishabhRD 8930fc0
make access ad subfield work
RishabhRD 03fae32
register should only store builtin object
RishabhRD 5540797
instruction also provides type
RishabhRD cd3312f
fix byte offsetting for subfield view
RishabhRD 97df887
feat: implement load instruction
RishabhRD 844594f
no need to store address additionally
RishabhRD 644c565
feat: memory_copy implemented
RishabhRD e1b3b1d
feat: finally calling function works
RishabhRD 36eb17f
feat: make jump instruction work
RishabhRD 7d5c065
fix: unreal abi type layout calculation for bool
RishabhRD 329a953
feat: store instruction works now
RishabhRD b70ed18
remove constant_string implementation as it was wrong
RishabhRD 038a88f
Unify stack and heap addresses
RishabhRD 1e258ed
remove unused stack tests
RishabhRD eb3f50d
remove #expect for checking nothrow
RishabhRD 46f173f
Merge remote-tracking branch 'base/interpreter' into interpreter_func…
RishabhRD 78f918b
moved stackframe to its original location
RishabhRD c19ee8c
memory operations is independent of stack and heap
RishabhRD d03877e
document the types properly
RishabhRD 2d8b8aa
store should also get rid of little-endianess
RishabhRD b003955
update docs to be independent of stack and heap
RishabhRD 605bba1
fix failing CI
RishabhRD 3a78ffd
add relevant dependencies to cmake InterpreterTests
RishabhRD 19ddb56
testing is also a dependency
RishabhRD 22624ed
fix dependencies in package.swift
RishabhRD 9119a7d
add swift-testing as dependency in cmake
RishabhRD 875c1a6
Upgrade cmake modules for finding swift testing
tothambrus11 8eaaa86
disable interpreter testing target
tothambrus11 1e740da
remove questionable cmake commands
tothambrus11 cf5f430
disable cmake testing for interpreter for now
RishabhRD 160255d
every stack allocations should be on different allocation id
RishabhRD f3085d5
access builtin value using accessors
RishabhRD 5a41037
made asUInt128 initializer as fileprivate
RishabhRD c0e4e17
migrate to XCTest
RishabhRD 918f632
enable interpreter tests
RishabhRD 2e66e09
Merge branch 'interpreter' into interpreter_function_call
RishabhRD 415c1f9
safe accessors for type stored at offset
RishabhRD 807209d
fix: preconditions on memory tests
RishabhRD 1a89883
added Memory.copy(bytes:,from:,to:) to support copying empty structs
RishabhRD bf24841
apply jumpTo name suggestion from Dave
RishabhRD 6d1a4b6
Improve naming and documentation
RishabhRD 9e4854c
improve using UntypedBuiltinValue
RishabhRD e7f854d
Merge branch 'interpreter' into interpreter_function_call
RishabhRD fbd247c
remove InstructionResult and let it evolve with design
RishabhRD ceeb73b
stackframe should contain local variables
RishabhRD 9cfa91a
remove untyped builtin value
RishabhRD c2b44ab
remove the use of denotedBy
RishabhRD 7e76b30
address of subfield in parent field
RishabhRD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -37,37 +37,6 @@ struct Address { | |
|
|
||
| } | ||
|
|
||
| /// The value produced by executing an instruction. | ||
| enum InstructionResult { | ||
|
|
||
| /// 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 | ||
|
|
@@ -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 } | ||
| } | ||
|
|
@@ -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: | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
|
|
@@ -207,7 +176,7 @@ public struct Interpreter { | |
| _ = x | ||
| case let x as Load: | ||
| let address = address(denotedBy: x.source)!; | ||
|
||
| currentRegister = .builtIn(builtIn(at: address)!) | ||
| currentRegister = builtIn(at: address)! | ||
| case is MarkState: | ||
| // No effect on program state | ||
| break | ||
|
|
@@ -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: | ||
|
|
@@ -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: | ||
|
|
@@ -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): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?