Skip to content
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

Fix the implementation of print #1095

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions Library/Hylo/Print.hylo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Writes the textual representation of `item` to the standard output.
public fun print(_ item: String, terminator: String = "\n") {
let stream = stdout()
_ = fwrite(CVoidPointer(base: item.utf8.base), 1, item.size, CVoidPointer(base: stream.base))
_ = fwrite(CVoidPointer(base: terminator.utf8.base), 1, 1, CVoidPointer(base: stream.base))
let o = stdout
_ = fwrite(CVoidPointer(base: item.utf8.base), 1, item.size, CVoidPointer(base: o.base))
_ = fwrite(CVoidPointer(base: terminator.utf8.base), 1, terminator.size, CVoidPointer(base: o.base))
}

/// Writes the textual representation of `item` to the standard output.
Expand All @@ -26,13 +26,11 @@ public fun print(_ item: Int, radix: Int = 10, terminator: String = "\n") {
if item < 0 { &a.append(45) }
&a.reverse()

let stream = stdout()
let o = stdout
let buffer = a.contiguous_storage.base
_ = fwrite(CVoidPointer(base: buffer), 1, a.count(), CVoidPointer(base: stream.base))
_ = fwrite(CVoidPointer(base: terminator.utf8.base), 1, 1, CVoidPointer(base: stream.base))
_ = fwrite(CVoidPointer(base: buffer), 1, a.count(), CVoidPointer(base: o.base))
_ = fwrite(CVoidPointer(base: terminator.utf8.base), 1, terminator.size, CVoidPointer(base: o.base))
}

/// The standard output of the current process.
fun stdout() -> MemoryAddress {
.new(base: fdopen(1, CVoidPointer(base: "w".utf8.base)).base)
}
let stdout = MemoryAddress.new(base: fdopen(1, CVoidPointer(base: "w".utf8.base)).base)
12 changes: 12 additions & 0 deletions Sources/Core/AST/Decl/SynthesizedFunctionDecl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public struct SynthesizedFunctionDecl: Hashable {
return RemoteType(r)?.bareType ?? r
}

/// Returns the generic parameters of the declaration.
public var genericParameters: [GenericParameterDecl.ID] {
guard let t = BoundGenericType(receiver) else { return [] }
return t.arguments.compactMap { (k, v) -> GenericParameterDecl.ID? in
if let u = v as? AnyType {
return GenericTypeParameterType(u)?.decl == k ? k : nil
} else {
UNIMPLEMENTED("compile time values")
}
}
}

}

extension SynthesizedFunctionDecl: CustomStringConvertible {
Expand Down
3 changes: 1 addition & 2 deletions Sources/IR/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,11 @@ public struct Module {
d.type.captures, passed: d.type.receiverEffect, to: &inputs, canonicalizedIn: d.scope)
appendParameters(d.type.inputs, to: &inputs, canonicalizedIn: d.scope)

let genericParameters = BoundGenericType(d.receiver).map({ Array($0.arguments.keys) }) ?? []
let entity = Function(
isSubscript: false,
site: .empty(at: program.ast[id].site.first()),
linkage: .external,
genericParameters: genericParameters,
genericParameters: d.genericParameters,
inputs: inputs,
output: output,
blocks: [])
Expand Down
Loading