From 1be913de639e79a88c35970edbe47b651b5ee840 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Mon, 20 Mar 2017 19:00:37 +0300 Subject: [PATCH] Review fixes --- .../kotlin/native/interop/indexer/Indexer.kt | 4 +- runtime/src/launcher/cpp/launcher.cpp | 5 --- samples/tetris/README.md | 11 +++++ samples/tetris/sdl.def | 9 ++-- samples/tetris/tetris.kt | 44 ++++++++++--------- 5 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 samples/tetris/README.md diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt index 73334fc14b1..ec2c77c463a 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt @@ -91,7 +91,7 @@ internal class NativeIndexImpl(val language: Language) : NativeIndex() { } } - if (underlying !is ConstArrayType) return underlying + assert (underlying is ConstArrayType) // So the result must feel like array: return ConstArrayType(RecordType(structDeclaration), 1) } @@ -102,7 +102,7 @@ internal class NativeIndexImpl(val language: Language) : NativeIndex() { val underlying = convertType(clang_getTypedefDeclUnderlyingType(declCursor)) - if (name == "__builtin_va_list") { + if (name == "__builtin_va_list" && underlying is ConstArrayType) { // On some platforms (e.g. macOS) libclang reports `__builtin_va_list` to be defined as array using // typedef struct __va_list_tag __builtin_va_list[1] // while `struct __va_list_tag` is incomplete. diff --git a/runtime/src/launcher/cpp/launcher.cpp b/runtime/src/launcher/cpp/launcher.cpp index 203983e7045..fcbc098a306 100644 --- a/runtime/src/launcher/cpp/launcher.cpp +++ b/runtime/src/launcher/cpp/launcher.cpp @@ -38,8 +38,3 @@ extern "C" int Konan_main(int argc, char** argv) { return exitStatus; } - -// Allow override of entry point for cases like SDL. -int __attribute__((weak)) main(int argc, char** argv) { - return Konan_main(argc, argv); -} diff --git a/samples/tetris/README.md b/samples/tetris/README.md new file mode 100644 index 00000000000..0e6c3674299 --- /dev/null +++ b/samples/tetris/README.md @@ -0,0 +1,11 @@ +Start with building compiler by using `dist` and `cross_dist` for cross-targets. +To build Tetris application for your host platform use +./build +note that SDL2 must be installed on the host. +For cross-compilation to iOS use +TARGET=iphone ./build + +During build process compilation script creates interoperability bindings to SDL2, using SDL C headers, +and then compiles an application with the produced bindings. + +To deploy executable to iPhone device take Info.plist, then use XCode and your own private signing identity. diff --git a/samples/tetris/sdl.def b/samples/tetris/sdl.def index 482efc9c2bd..f79cd0b19f1 100644 --- a/samples/tetris/sdl.def +++ b/samples/tetris/sdl.def @@ -1,12 +1,13 @@ headers = SDL.h stdio.h string.h unistd.h stdlib.h time.h excludedFunctions = _IO_flockfile _IO_funlockfile _IO_ftrylockfile \ _IO_cleanup_region_start _IO_cleanup_region_end \ - mkstemp_dprotected_np add_profil profil unwhiteout zopen \ - SDL_PointInRect SDL_RectEmpty SDL_RectEquals \ - __darwin_fd_isset __sputc matherr _mm_stream_si32 _mm_stream_si64 + _mm_stream_si32 _mm_stream_si64 \ + SDL_PointInRect SDL_RectEmpty SDL_RectEquals entryPoint = SDL_main -compilerOpts.osx = -D_POSIX_SOURCE -mxsave -mavx -mf16c +compilerOpts = -D_POSIX_SOURCE +compilerOpts.osx = compilerOpts.linux = -D_REENTRANT +compilerOpts.ios = linkerOpts.linux = -lm diff --git a/samples/tetris/tetris.kt b/samples/tetris/tetris.kt index e2447ae643c..549cc5f2cd1 100644 --- a/samples/tetris/tetris.kt +++ b/samples/tetris/tetris.kt @@ -513,6 +513,10 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User private fun stretch(value: Int) = (value.toFloat() * ratio + 0.5).toInt() inner class GamePadButtons(width: Int, height: Int, gamePadHeight: Int) { + val MOVE_BUTTON_SIZE = 50 + val ROTATE_BUTTON_SIZE = 80 + val BUTTONS_MARGIN = 25 + val arena = Arena() val leftRect: SDL_Rect val rightRect: SDL_Rect @@ -521,40 +525,38 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User val rotateRect: SDL_Rect init { - val s1 = 50 - val s2 = 80 - val m = 25 - val x = (width - 3 * s1 - 2 * m - m - s2) / 2 - s1 - val y2 = (gamePadHeight - 2 * s1 - m) / 2 + val moveButtonsWidth = 3 * MOVE_BUTTON_SIZE + 2 * BUTTONS_MARGIN + BUTTONS_MARGIN + val x = (width - moveButtonsWidth - ROTATE_BUTTON_SIZE) / 2 - MOVE_BUTTON_SIZE + val y2 = (gamePadHeight - 2 * MOVE_BUTTON_SIZE - BUTTONS_MARGIN) / 2 leftRect = arena.alloc() - leftRect.w.value = s1 - leftRect.h.value = s1 + leftRect.w.value = MOVE_BUTTON_SIZE + leftRect.h.value = MOVE_BUTTON_SIZE leftRect.x.value = x - leftRect.y.value = height - gamePadHeight + y2 + s1 + m + leftRect.y.value = height - gamePadHeight + y2 + MOVE_BUTTON_SIZE + BUTTONS_MARGIN downRect = arena.alloc() - downRect.w.value = s1 - downRect.h.value = s1 - downRect.x.value = x + s1 + m + downRect.w.value = MOVE_BUTTON_SIZE + downRect.h.value = MOVE_BUTTON_SIZE + downRect.x.value = x + MOVE_BUTTON_SIZE + BUTTONS_MARGIN downRect.y.value = leftRect.y.value dropRect = arena.alloc() - dropRect.w.value = s1 - dropRect.h.value = s1 + dropRect.w.value = MOVE_BUTTON_SIZE + dropRect.h.value = MOVE_BUTTON_SIZE dropRect.x.value = downRect.x.value dropRect.y.value = height - gamePadHeight + y2 rightRect = arena.alloc() - rightRect.w.value = s1 - rightRect.h.value = s1 - rightRect.x.value = x + 2 * s1 + 2 * m - rightRect.y.value = height - gamePadHeight + y2 + s1 + m + rightRect.w.value = MOVE_BUTTON_SIZE + rightRect.h.value = MOVE_BUTTON_SIZE + rightRect.x.value = x + 2 * MOVE_BUTTON_SIZE + 2 * BUTTONS_MARGIN + rightRect.y.value = height - gamePadHeight + y2 + MOVE_BUTTON_SIZE + BUTTONS_MARGIN rotateRect = arena.alloc() - rotateRect.w.value = s2 - rotateRect.h.value = s2 - rotateRect.x.value = x + 3 * s1 + 2 * m + m - rotateRect.y.value = height - gamePadHeight + y2 - m + rotateRect.w.value = ROTATE_BUTTON_SIZE + rotateRect.h.value = ROTATE_BUTTON_SIZE + rotateRect.x.value = x + moveButtonsWidth + rotateRect.y.value = height - gamePadHeight + y2 - BUTTONS_MARGIN } fun getCommandAt(x: Int, y: Int): UserCommand? {