-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1009 from hylo-lang/method-bundles-1
Generate raw IR for calls to method bundles
- Loading branch information
Showing
11 changed files
with
314 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Core | ||
|
||
/// A reference to a method or subscript bundle. | ||
public struct BundleReference<T: BundleDecl>: Hashable { | ||
|
||
/// The ID of the referred bundle. | ||
public let bundle: T.ID | ||
|
||
/// If `bundle` is generic, the arguments to its generic parameter. | ||
public let arguments: GenericArguments | ||
|
||
/// Creates a reference to `s` parameterized by `a`. | ||
public init(to s: T.ID, specializedBy a: GenericArguments) { | ||
self.bundle = s | ||
self.arguments = a | ||
} | ||
|
||
} | ||
|
||
extension BundleReference: CustomStringConvertible { | ||
|
||
public var description: String { | ||
if arguments.isEmpty { | ||
return "@\(bundle)" | ||
} else { | ||
return "@\(bundle)<\(list: arguments.values)>" | ||
} | ||
} | ||
|
||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Core | ||
|
||
/// The callee of a function call in the IR. | ||
enum Callee { | ||
|
||
/// A direct reference to a function, initializer, or method implementation. | ||
case direct(FunctionReference) | ||
|
||
/// A reference to a variant in a method bundle. | ||
case bundle(BundleReference<MethodDecl>) | ||
|
||
/// A lambda. | ||
case lambda(Operand) | ||
|
||
/// Creates an instance representing a reference to the lowered form of `d` in `module`, | ||
/// specialized by`a` in `scopeOfUse`. | ||
init( | ||
_ d: AnyDeclID, specializedBy a: GenericArguments, | ||
in module: inout Module, usedIn scopeOfUse: AnyScopeID | ||
) { | ||
if let m = MethodDecl.ID(d) { | ||
self = .bundle(BundleReference(to: m, specializedBy: a)) | ||
} else { | ||
let r = FunctionReference( | ||
to: FunctionDecl.ID(d)!, in: &module, specializedBy: a, in: scopeOfUse) | ||
self = .direct(r) | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.