mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix of ternary / elvis where legs are bool or optional.
This commit is contained in:
committed by
Christoffer Lerno
parent
b1ed066e55
commit
76ee384a4c
19
lib/std/io/dir.c3
Normal file
19
lib/std/io/dir.c3
Normal file
@@ -0,0 +1,19 @@
|
||||
module std::io::dir;
|
||||
|
||||
struct PlatformDir
|
||||
{
|
||||
void* data;
|
||||
}
|
||||
|
||||
define Dir = distinct PlatformDir*;
|
||||
|
||||
$if (env::OS_TYPE == OsType.WIN32):
|
||||
/*
|
||||
private extern ulong _win32_GetCurrentDirectoryW(ulong, Char16* buffer) @extname("GetCurrentDirectoryW");
|
||||
private extern bool _win32_CreateSymbolicLinkW(Char16* symlink_file, Char16* target_file, ulong flags) @extname("CreateSymbolicLinkW");
|
||||
private extern bool _win32_CreateDirectoryW(Char16* path_name, void* security_attributes) @extname("CreateDirectoryW");
|
||||
private extern bool _win32_DeleteFileW(Char16* file) @extname("DeleteFileW");
|
||||
private extern bool _win32_CopyFileW(Char16* from_file, Char16* to_file, bool no_overwrite) @extname("CopyFileW");
|
||||
private extern ulong _win32_GetFullPathNameW(Char16* file_name, ulong buffer_len, Char16* buffer, Char16** file_part) @extname("GetFullPathNameW");
|
||||
*/
|
||||
$endif;
|
||||
21
lib/std/os/macos/cf_allocator.c3
Normal file
21
lib/std/os/macos/cf_allocator.c3
Normal file
@@ -0,0 +1,21 @@
|
||||
module std::os::macos::cf;
|
||||
|
||||
$if (env::OS_TYPE == OsType.MACOSX):
|
||||
|
||||
define CFAllocatorRef = distinct void*;
|
||||
define CFAllocatorContextRef = distinct void*;
|
||||
define CFOptionFlags = usz;
|
||||
|
||||
macro CFAllocatorRef default_allocator() = _macos_CFAllocatorGetDefault();
|
||||
macro void CFAllocatorRef.dealloc(CFAllocatorRef allocator, void* ptr) = _macos_CFAllocatorDeallocate(allocator, ptr);
|
||||
macro void* CFAllocatorRef.alloc(CFAllocatorRef allocator, usz size) = _macos_CFAllocatorAllocate(allocator, size, 0);
|
||||
macro usz CFAllocatorRef.get_preferred_size(CFAllocatorRef allocator, usz req_size) = _macos_CFAllocatorGetPreferredSizeForSize(allocator, req_size, 0);
|
||||
macro void CFAllocatorRef.set_default(CFAllocatorRef allocator) = _macos_CFAllocatorSetDefault(allocator);
|
||||
|
||||
extern fn CFAllocatorRef _macos_CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContextRef context) @extname("CFAllocatorCreate");
|
||||
extern fn void _macos_CFAllocatorDeallocate(CFAllocatorRef allocator, void* ptr) @extname("CFAllocatorDeallocate");
|
||||
extern fn CFAllocatorRef _macos_CFAllocatorGetDefault() @extname("CFAllocatorGetDefault");
|
||||
extern fn void _macos_CFAllocatorSetDefault(CFAllocatorRef allocator) @extname("CFAllocatorSetDefault");
|
||||
extern fn void* _macos_CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint) @extname("CFAllocatorAllocate");
|
||||
extern fn CFIndex _macos_CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint) @extname("CFAllocatorGetPreferredSizeForSize");
|
||||
$endif;
|
||||
14
lib/std/os/macos/cf_array.c3
Normal file
14
lib/std/os/macos/cf_array.c3
Normal file
@@ -0,0 +1,14 @@
|
||||
module std::os::macos::cf;
|
||||
|
||||
$if (env::OS_TYPE == OsType.MACOSX):
|
||||
|
||||
define CFArrayRef = distinct void*;
|
||||
define CFArrayCallBacksRef = distinct void*;
|
||||
define CFMutableArrayRef = distinct void*;
|
||||
extern fn CFArrayRef _macos_CFArrayCreate(CFAllocatorRef allocator, void** values, CFIndex num_values, CFArrayCallBacksRef callBacks) @extname("CFArrayCreate");
|
||||
extern fn CFArrayRef _macos_CFArrayCopy(CFAllocatorRef allocator, CFArrayRef array) @extname("CFArrayCopy");
|
||||
extern fn CFIndex _macos_CFArrayGetCount(CFArrayRef array) @extname("CFArrayGetCount");
|
||||
extern fn void _macos_CFArrayAppendArray(CFMutableArrayRef theArray, CFArrayRef otherArray, CFRange otherRange) @extname("CFArrayAppendArray");
|
||||
extern fn CFMutableArrayRef _macos_CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, CFArrayCallBacksRef callBacks) @extname("CFArrayCreateMutable");
|
||||
extern fn void _macos_CFArrayAppendValue(CFMutableArrayRef theArray, void *value) @extname("CFArrayAppendValue");
|
||||
$endif;
|
||||
16
lib/std/os/macos/core_foundation.c3
Normal file
16
lib/std/os/macos/core_foundation.c3
Normal file
@@ -0,0 +1,16 @@
|
||||
module std::os::macos::cf;
|
||||
|
||||
$if (env::OS_TYPE == OsType.MACOSX):
|
||||
|
||||
define CFTypeRef = distinct void*;
|
||||
define CFIndex = isz;
|
||||
struct CFRange
|
||||
{
|
||||
CFIndex location;
|
||||
CFIndex length;
|
||||
}
|
||||
|
||||
extern fn CFTypeRef _macos_CFRetain(CFTypeRef cf) @extname("CFRetain");
|
||||
extern fn void _macos_CFRelease(CFTypeRef cf) @extname("CFRelease");
|
||||
|
||||
$endif;
|
||||
49
lib/std/os/macos/objc.c3
Normal file
49
lib/std/os/macos/objc.c3
Normal file
@@ -0,0 +1,49 @@
|
||||
module std::os::macos::objc;
|
||||
|
||||
$if (env::OS_TYPE == OsType.MACOSX):
|
||||
|
||||
define Class = distinct void*;
|
||||
define Method = distinct void*;
|
||||
define Ivar = distinct void*;
|
||||
define Selector = distinct void*;
|
||||
|
||||
fault ObjcFailure
|
||||
{
|
||||
CLASS_NOT_FOUND
|
||||
}
|
||||
|
||||
macro char* Class.name(Class cls) = _macos_class_getName(cls);
|
||||
macro Class Class.superclass(Class cls) = _macos_class_getSuperclass(cls);
|
||||
macro bool Class.responds_to(Class cls, Selector sel) = _macos_class_respondsToSelector(cls, sel);
|
||||
macro Method Class.method(Class cls, Selector name) = _macos_class_getClassMethod(cls, name);
|
||||
|
||||
macro bool Selector.equals(Selector a, Selector b) = a == b;
|
||||
macro bool Class.equals(Class a, Class b) = a == b;
|
||||
|
||||
macro Selector selector_register(char* c) = _macos_sel_registerName(c);
|
||||
macro Class! class_by_name(char* c)
|
||||
{
|
||||
Class cls = _macos_objc_lookUpClass(c);
|
||||
if (!cls) return ObjcFailure.CLASS_NOT_FOUND!;
|
||||
return cls;
|
||||
}
|
||||
|
||||
macro Class[] class_get_list(Allocator *allocator = mem::temp_allocator())
|
||||
{
|
||||
int num_classes = _macos_objc_getClassList(null, 0);
|
||||
if (!num_classes) return {};
|
||||
Class[] entries = array::make(Class, num_classes, allocator);
|
||||
_macos_objc_getClassList(entries.ptr, entries.len);
|
||||
return entries;
|
||||
}
|
||||
|
||||
extern fn Class _macos_objc_getClass(char* name) @extname("objc_getClass");
|
||||
extern fn int _macos_objc_getClassList(Class* buffer, int buffer_count) @extname("objc_getClassList");
|
||||
extern fn char* _macos_class_getName(Class cls) @extname("class_getName");
|
||||
extern fn Class _macos_class_getSuperclass(Class cls) @extname("class_getSuperclass");
|
||||
extern fn Method _macos_class_getClassMethod(Class cls, Selector name) @extname("class_getClassMethod");
|
||||
extern fn bool _macos_class_respondsToSelector(Class cls, Selector name) @extname("class_respondsToSelector");
|
||||
extern fn Selector _macos_sel_registerName(char* str) @extname("sel_registerName");
|
||||
extern fn Class _macos_objc_lookUpClass(char* name) @extname("objc_lookUpClass");
|
||||
$endif;
|
||||
|
||||
Reference in New Issue
Block a user