Skip to content
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
15 changes: 15 additions & 0 deletions stdlib/public/core/EmbeddedRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ func alignedAlloc(size: Int, alignment: Int) -> UnsafeMutableRawPointer? {
return unsafe r
}

@_cdecl("swift_coroFrameAlloc")
public func swift_coroFrameAlloc(_ size: Int, _ type: UInt) -> UnsafeMutableRawPointer? {
return unsafe alignedAlloc(
size: size,
alignment: _swift_MinAllocationAlignment)
}

@_cdecl("swift_slowAlloc")
public func swift_slowAlloc(_ size: Int, _ alignMask: Int) -> UnsafeMutableRawPointer? {
let alignment: Int
Expand Down Expand Up @@ -178,6 +185,14 @@ func swift_allocObject(metadata: UnsafeMutablePointer<ClassMetadata>, requiredSi
return unsafe object
}

@_cdecl("swift_deallocUninitializedObject")
public func swift_deallocUninitializedObject(object: Builtin.RawPointer, allocatedSize: Int, allocatedAlignMask: Int) {
unsafe swift_deallocObject(
object: UnsafeMutablePointer<HeapObject>(object),
allocatedSize: allocatedSize,
allocatedAlignMask: allocatedAlignMask)
}

@_cdecl("swift_deallocObject")
public func swift_deallocObject(object: Builtin.RawPointer, allocatedSize: Int, allocatedAlignMask: Int) {
unsafe swift_deallocObject(object: UnsafeMutablePointer<HeapObject>(object), allocatedSize: allocatedSize, allocatedAlignMask: allocatedAlignMask)
Expand Down
37 changes: 37 additions & 0 deletions test/embedded/accessors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -Onone -parse-as-library -enable-experimental-feature Embedded -c -o %t/main.o
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
// RUN: %target-run %t/a.out | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: swift_feature_Embedded

public class C {
public var x: Int {
_read {
yield(y)
}
_modify {
yield(&y)
}
}

var y: Int = 27
}

@main
struct Main {
static func main() {
print("1") // CHECK: 1
let c = C() // CHECK: 27
print(c.y)
c.y = 28
print(c.y) // CHECK: 28
print("")

print("2") // CHECK: 2
print("")
}
}
11 changes: 11 additions & 0 deletions test/embedded/closures-heap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
// REQUIRES: optimized_stdlib
// REQUIRES: swift_feature_Embedded



func f() -> Bool? { return nil }

public class MyClass {
var handler: (()->())? = nil
func foo() {
Expand All @@ -32,5 +36,12 @@ struct Main {
o!.foo() // CHECK: capture local
print(local == 43 ? "43" : "???") // CHECK: 43
o = nil // CHECK: deinit

let closure = {
guard var b = f() else { print("success"); return }
let c = { b = true }
_ = (b, c)
}
closure() // CHECK: success
}
}