1
1
// RUN: %empty-directory(%t)
2
- // RUN: %{python} %utils/split_file.py -o %t %s
3
-
4
- // RUN: %target-swift-frontend %t/main.swift -enable-experimental-feature Embedded -c -o %t/main.o
5
- // RUN: %target-clang -g -x c %t/runtime.c -c -o %t/runtime.o
6
- // RUN: %target-clang %t/main.o %t/runtime.o -o %t/a.out -dead_strip
2
+ // RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -c -o %t/main.o
3
+ // RUN: %target-clang -x c -c %S/Inputs/tiny-runtime-dummy-refcounting.c -o %t/runtime.o
4
+ // RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
5
+ // RUN: %target-clang %t/main.o %t/runtime.o %t/print.o -o %t/a.out -dead_strip
7
6
// RUN: %target-run %t/a.out | %FileCheck %s
8
7
9
8
// REQUIRES: executable_test
10
9
11
- // BEGIN main.swift
12
-
13
10
@_silgen_name ( " putchar " )
14
11
func putchar( _: UInt8 )
15
12
@@ -26,23 +23,21 @@ public func print(_ s: StaticString, terminator: StaticString = "\n") {
26
23
}
27
24
}
28
25
29
- @_silgen_name ( " vprintf " )
30
- func vprintf ( _: UnsafePointer < UInt8 > , _ : UnsafeRawPointer )
26
+ @_silgen_name ( " print_long " )
27
+ func print_long ( _: Int )
31
28
32
- var global : Int = 0
33
- public func print( _ n: Int ) {
34
- let f : StaticString = " %d "
35
- global = n
36
- vprintf ( f. utf8Start, & global)
29
+ public func print( _ n: Int , terminator: StaticString = " \n " ) {
30
+ print_long ( n)
31
+ print ( " " , terminator: terminator)
37
32
}
38
33
39
- public func print( _ array: [ Int ] ) {
40
- print ( " [ " , terminator: " " )
41
- for e in array {
42
- print ( e )
43
- print ( " , " , terminator: " " )
44
- }
45
- print ( " ] " )
34
+ func print( _ array: [ Int ] ) {
35
+ print ( " [ " , terminator: " " )
36
+ for i in 0 ..< array. count {
37
+ print_long ( array [ i ] )
38
+ if i != array . count - 1 { print ( " , " , terminator: " " ) }
39
+ }
40
+ print ( " ] " )
46
41
}
47
42
48
43
func test( ) {
@@ -51,32 +46,8 @@ func test() {
51
46
a. append ( contentsOf: [ 5 , 4 ] )
52
47
let b = a. sorted ( )
53
48
var c = b
54
- c = c. reversed ( )
55
- print ( c) // CHECK: [8, 5, 4, 3, 2, 1, ]
49
+ c = c. reversed ( ) . filter { $0 % 2 == 0 }
50
+ print ( c) // CHECK: [8, 4, 2 ]
56
51
}
57
52
58
53
test ( )
59
-
60
- // BEGIN runtime.c
61
-
62
- #include < stdint. h>
63
- #include < stdlib. h>
64
- #include < stdbool. h>
65
-
66
- size_t _swiftEmptyArrayStorage[ ] = { /*isa*/0 , /*refcount*/0 , /*count*/0 , /*flags*/1 } ;
67
-
68
- void * swift_allocObject( void * metadata, size_t required Size, size_t required AlignmentMask) {
69
- void * r = NULL;
70
- posix_memalign ( & r, requiredAlignmentMask + 1 , requiredSize) ;
71
- return r;
72
- }
73
-
74
- void swift_deallocClassInstance( ) { }
75
- void swift_initStackObject( ) { }
76
- bool swift_isUniquelyReferenced_nonNull_native ( void * ) { return true ; }
77
- void swift_release( ) { }
78
- void swift_retain( ) { }
79
- void swift_setDeallocating( ) { }
80
-
81
- void swift_beginAccess( ) { }
82
- void swift_endAccess( ) { }
0 commit comments