[swift-evolution] Low-level Swift

Austin Zheng austinzheng at gmail.com
Thu Jan 7 15:27:01 CST 2016


Indeed, that's good to know. Thanks for the clarification!

Austin

On Thu, Jan 7, 2016 at 1:22 PM, Félix Cloutier <felixcca at yahoo.ca> wrote:

> It is. This:
>
> func foo(ptr: UnsafeMutablePointer<Int32>) {
> ptr.memory = 4
> ptr.memory = 5
> }
>
>
> compiles to:
>
> define hidden void
> @_TF4test3fooFGVSs20UnsafeMutablePointerVSs5Int32_T_(i8* nocapture) #1 {
> entry:
>   %.value = bitcast i8* %0 to i32*
>   store i32 5, i32* %.value, align 4
>   ret void
> }
>
>
> Notice how it's "missing" a store.
>
> Félix
>
> Le 7 janv. 2016 à 15:54:36, Austin Zheng via swift-evolution <
> swift-evolution at swift.org> a écrit :
>
> I'd think the hypothetical way in Swift to write to configuration
> registers would be to create an UnsafeMutablePointer<Int64> (or some other
> raw integer type) from a raw memory address, and then get/set the contents
> using the 'memory' property. Not sure if the compiler is "smart" enough to
> optimize out memory accesses made using that mechanism, although I would
> assume no.
>
> Austin
>
> On Thu, Jan 7, 2016 at 3:52 AM, Romain Goyet via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Hi everyone,
>>
>> In the introduction to Swift
>> <https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/>,
>> it is presented as an "industrial-quality systems programming language".
>> According to Wikipedia
>> <https://en.wikipedia.org/wiki/System_programming_language>, this means
>> that I could expect to be able to write device drivers or operating systems
>> in Swift.
>>
>> However it seems like this claim is only partially true, since several
>> important low-level features seem to be completely missing:
>>
>> - Is it possible to generate volatile memory accesses
>> <http://llvm.org/docs/LangRef.html#volatile-memory-accesses> in Swift?
>> Writing device drivers is virtually impossible without a way to guarantee
>> certain memory operations are actually made (and not optimized-out).
>>
>> - Is it possible to embed raw binary data in Swift? For example, an
>> equivalent of the following C code "const int8_t foo[6] =
>> {0x00,0x11,0x22,0x33,0x44,0x55};"? The simple Swift equivalent, "let foo:
>> [Int8] = [0x0,0x1,0x2,0x3,0x4,0x6];" is obviously wildly different. Being
>> able to embed raw binary data is very important in a low-level environment:
>> for example, you may need to feed specific data to a device for an
>> initialization sequence at a point where you don't have a filesystem
>> available yet.
>>
>> There might be other aspects that I'm overlooking right now, but I think
>> that's enough to start a discussion: is Swift really meant to be a systems
>> programming language?
>>
>> Thanks,
>>
>>  - Romain
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>>
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160107/28ffe14f/attachment.html>


More information about the swift-evolution mailing list