mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Added path::home_directory, path::documents_directory, path::videos_directory, path::pictures_directory, path::desktop_directory, path::screenshots_directory,
`path::public_share_directory`, `path::templates_directory`, `path::saved_games_directory`, `path::music_directory`, `path::downloads_directory`. Fix codegen bug in expressions like `foo(x()) ?? io::EOF?` causing irregular crashes.
This commit is contained in:
committed by
Christoffer Lerno
parent
cbd415881b
commit
69b3263a00
@@ -1,11 +1,18 @@
|
||||
module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
|
||||
|
||||
typedef CFArrayRef = void*;
|
||||
typedef CFArray = inline CFType;
|
||||
alias CFArrayRef = CFArray*;
|
||||
typedef CFArrayCallBacksRef = void*;
|
||||
typedef CFMutableArrayRef = void*;
|
||||
typedef CFMutableArray = inline CFArray;
|
||||
typedef CFMutableArrayRef = CFMutableArray*;
|
||||
|
||||
extern fn CFIndex CFArray.getCount(&self) @extern("CFArrayGetCount");
|
||||
extern fn void* CFArray.getValueAtIndex(&self, CFIndex i) @extern("CFArrayGetValueAtIndex");
|
||||
|
||||
extern fn CFArrayRef macos_CFArrayCreate(CFAllocatorRef allocator, void** values, CFIndex num_values, CFArrayCallBacksRef callBacks) @extern("CFArrayCreate") @builtin;
|
||||
extern fn CFArrayRef macos_CFArrayCopy(CFAllocatorRef allocator, CFArrayRef array) @extern("CFArrayCopy") @builtin;
|
||||
extern fn CFIndex macos_CFArrayGetCount(CFArrayRef array) @extern("CFArrayGetCount") @builtin;
|
||||
extern fn void macos_CFArrayAppendArray(CFMutableArrayRef theArray, CFArrayRef otherArray, CFRange otherRange) @extern("CFArrayAppendArray") @builtin;
|
||||
extern fn void CFMutableArray.appendArray(&self, CFArrayRef otherArray, CFRange otherRange) @extern("CFArrayAppendArray");
|
||||
extern fn void CFMutableArray.appendValue(&self, void *value) @extern("CFArrayAppendValue");
|
||||
|
||||
extern fn CFMutableArrayRef macos_CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, CFArrayCallBacksRef callBacks) @extern("CFArrayCreateMutable") @builtin;
|
||||
extern fn void macos_CFArrayAppendValue(CFMutableArrayRef theArray, void *value) @extern("CFArrayAppendValue") @builtin;
|
||||
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
module std::os::macos::cf @if(env::DARWIN) @link(env::DARWIN, "CoreFoundation.framework");
|
||||
|
||||
typedef CFTypeRef = void*;
|
||||
typedef CFType = void;
|
||||
typedef CFTypeRef = CFType*;
|
||||
alias CFIndex = isz;
|
||||
|
||||
typedef CFString = inline CFType;
|
||||
alias CFStringRef = CFString*;
|
||||
|
||||
struct CFRange
|
||||
{
|
||||
CFIndex location;
|
||||
CFIndex length;
|
||||
}
|
||||
|
||||
extern fn CFTypeRef macos_CFRetain(CFTypeRef cf) @extern("CFRetain") @builtin;
|
||||
extern fn void macos_CFRelease(CFTypeRef cf) @extern("CFRelease") @builtin;
|
||||
extern fn ZString CFString.getCStringPtr(&self, CFStringEncoding encoding) @extern("CFStringGetCStringPtr");
|
||||
extern fn ZString CFString.getCString(&self, char* buffer, usz len, CFStringEncoding encoding) @extern("CFStringGetCString");
|
||||
|
||||
extern fn CFTypeRef CFType.retain(&self) @extern("CFRetain");
|
||||
extern fn void CFType.release(&self) @extern("CFRelease");
|
||||
extern fn CFIndex CFType.getRetainCount(&self) @extern("CFGetRetainCount");
|
||||
|
||||
enum CFStringEncoding : const uint
|
||||
{
|
||||
INVALID_ID = 0xffffffffU,
|
||||
MAC_ROMAN = 0,
|
||||
WINDOWS_LATIN_1 = 0x0500,
|
||||
ISO_LATIM_1 = 0x0201,
|
||||
NEXT_STEP_LATIN = 0x0B01,
|
||||
ASCII = 0x0600,
|
||||
UNICODE = 0x0100,
|
||||
UTF8 = 0x08000100,
|
||||
NON_LOSSY_ASCII = 0x0BFF,
|
||||
|
||||
UTF16 = 0x0100,
|
||||
UTF16BE = 0x10000100,
|
||||
UTF16LE = 0x14000100,
|
||||
|
||||
UTF32 = 0x0c000100,
|
||||
UTF32BE = 0x18000100,
|
||||
UTF32LE = 0x1c000100
|
||||
}
|
||||
|
||||
@@ -1,2 +1,60 @@
|
||||
module std::os::darwin @if(env::DARWIN);
|
||||
module std::os::darwin @if(env::DARWIN) @link("Foundation.framework");
|
||||
import std::os::macos::cf, std::os::macos::objc, std::io;
|
||||
|
||||
enum NSSearchPathDomainMask : const NSUInteger
|
||||
{
|
||||
USER = 1,
|
||||
LOCAL = 2,
|
||||
NETWORK = 4,
|
||||
SYSTEM = 8,
|
||||
ALL = 0x0ffff
|
||||
}
|
||||
|
||||
enum NSSearchPathDirectory : const NSUInteger
|
||||
{
|
||||
APPLICATION = 1,
|
||||
DEMO_APPLICATION,
|
||||
DEVELOPER_APPLICATION,
|
||||
ADMIN_APPLICATION,
|
||||
LIBRARY,
|
||||
DEVELOPER,
|
||||
USER,
|
||||
DOCUMENTATION,
|
||||
DOCUMENT,
|
||||
CORE_SERVICE,
|
||||
AUTOSAVED_INFORMATION,
|
||||
DESKTOP = 12,
|
||||
CACHES = 13,
|
||||
APPLICATION_SUPPORT = 14,
|
||||
DOWNLOADS = 15,
|
||||
INPUT_METHODS = 16,
|
||||
MOVIES = 17,
|
||||
MUSIC = 18,
|
||||
PICTURES = 19,
|
||||
PRINTER_DESCRIPTION = 20,
|
||||
SHARED_PUBLIC = 21,
|
||||
PREFERENCE_PANES = 22,
|
||||
APPLICATION_SCRIPTS = 23,
|
||||
ITEM_REPLACEMENT = 99,
|
||||
ALL_APPLICATIONS = 100,
|
||||
ALL_LIBRARIES = 101,
|
||||
TRASH = 102,
|
||||
}
|
||||
|
||||
// real signature in Foundation
|
||||
extern fn CFArrayRef nsSearchPathForDirectoriesInDomains(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, bool expandTilde) @extern("NSSearchPathForDirectoriesInDomains");
|
||||
|
||||
|
||||
|
||||
fn String? find_first_directory_temp(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
objc::@autoreleasepool()
|
||||
{
|
||||
CFArrayRef arr = nsSearchPathForDirectoriesInDomains(directory, domainMask, true);
|
||||
if (!arr.getCount()) return io::PATH_COULD_NOT_BE_FOUND?;
|
||||
CFStringRef str = (CFStringRef)arr.getValueAtIndex(0);
|
||||
char* buffer = tmalloc(2048);
|
||||
if (!str.getCString(buffer, 2048, UTF8)) return io::PATH_COULD_NOT_BE_FOUND?;
|
||||
return ((ZString)buffer).str_view();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ macro bool ObjcClass.equals(ObjcClass a, ObjcClass b) => a == b;
|
||||
fn ObjcId alloc(ObjcClass cls) => objc::msg_send(cls, SendVoid, "alloc");
|
||||
fn void release(ObjcId id) => objc::msg_send(id, SendVoid, "release");
|
||||
|
||||
alias NSUInteger = $typefrom(env::ARCH_64_BIT ??? ulong : uint);
|
||||
alias NSInteger = $typefrom(env::ARCH_64_BIT ??? long : int);
|
||||
|
||||
macro ObjcClass? class_by_name(ZString c)
|
||||
{
|
||||
ObjcClass cls = objc::lookUpClass(c);
|
||||
@@ -43,6 +46,15 @@ macro msg_send(id, $FunctionType, ZString $selector, ...)
|
||||
return (($FunctionType)&msgSend)((ObjcId)id, sel_getUid($selector), $vasplat);
|
||||
}
|
||||
|
||||
macro void @autoreleasepool(;@body())
|
||||
{
|
||||
void* ctx = objc_autoreleasePoolPush();
|
||||
defer objc_autoreleasePoolPop(ctx);
|
||||
@body();
|
||||
}
|
||||
|
||||
extern fn void* objc_autoreleasePoolPush();
|
||||
extern fn void objc_autoreleasePoolPop(void* context);
|
||||
extern fn ObjcClass getClass(ZString name) @extern("objc_getClass");
|
||||
extern fn int getClassList(ObjcClass* buffer, int buffer_count) @extern("objc_getClassList");
|
||||
extern fn ObjcClass lookUpClass(ZString name) @extern("objc_lookUpClass") @builtin;
|
||||
|
||||
Reference in New Issue
Block a user