view dwt/internal/objc/runtime.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 8b48be5454ce
children 30a762abda2a
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2008 Jacob Carlborg. All rights reserved.
 * Authors: Jacob Carlborg
 * Version: Initial created: 2008
 * License: $(LINK2 http://opensource.org/licenses/bsd-license.php, BSD Style)
 * 
 */
module dwt.internal.objc.runtime;

import tango.stdc.stringz : fromStringz, toStringz;

import dwt.dwthelper.utils : string;
import dwt.internal.cocoa.NSPoint;
import dwt.internal.cocoa.NSRange;
import dwt.internal.cocoa.NSSize;
static import dwt.internal.objc.bindings;



alias objc_ivar* Ivar;
alias objc_method* Method;
alias objc_object Protocol;

alias char* SEL;
alias objc_class* Class;
alias objc_object* id;

alias extern cast(C) id function(id, SEL, ...) IMP;

struct objc_object
{
    Class isa;
}

struct objc_super
{
    id receiver;
    Class clazz;
}

struct objc_class
{
    Class isa;
    Class super_class;
    const char* name;
    int versionn;
    int info;
    int instance_size;
    objc_ivar_list* ivars;
    objc_method_list** methodLists;
    objc_cache* cache;
    objc_protocol_list* protocols;
}

struct objc_ivar
{
    char* ivar_name;
    char* ivar_type;
    int ivar_offset;

    version cast(X86_64)
        int space;
}

struct objc_ivar_list
{
    int ivar_count;

    version cast(X86_64)
        int space;

    /* variable length structure */
    objc_ivar ivar_list[1];
}

struct objc_method
{
    SEL method_name;
    char* method_types;
    IMP method_imp;
}

struct objc_method_list
{
    objc_method_list* obsolete;

    int method_count;

    version cast(X86_64)
        int space;

    /* variable length structure */
    objc_method method_list[1];
}

struct objc_cache
{
    uint mask /* total = mask + 1 */;
    uint occupied;
    Method buckets[1];
}

struct objc_protocol_list
{
    objc_protocol_list* next;
    long count;
    Protocol* list[1];
}



alias dwt.internal.objc.bindings.objc_registerClassPair objc_registerClassPair;

bool class_addIvar (Class cls, string name, size_t size, byte alignment, string types)
{
    return dwt.internal.objc.bindings.class_addIvar(cls, name.ptr, size, alignment, types.ptr);
}

bool class_addMethod (Class cls, SEL name, IMP imp, string types)
{
    return dwt.internal.objc.bindings.class_addMethod(cls, name, imp, types.ptr);
}

Class objc_allocateClassPair (Class superclass, string name, size_t extraBytes)
{
    return dwt.internal.objc.bindings.objc_allocateClassPair(superclass, name.ptr, extraBytes);
}

id objc_getClass (string name)
{
    return dwt.internal.objc.bindings.objc_getClass(name.ptr);
}

id objc_lookUpClass (string name)
{
    return dwt.internal.objc.bindings.objc_lookUpClass(name.ptr);
}

string object_getClassName (id obj)
{
    return fromStringz(dwt.internal.objc.bindings.object_getClassName(obj));
}

Ivar object_getInstanceVariable (id obj, string name, void** outValue)
{
    return dwt.internal.objc.bindings.object_getInstanceVariable(obj, name.ptr, outValue);
}

Ivar object_setInstanceVariable (id obj, string name, void* value)
{
    return dwt.internal.objc.bindings.object_setInstanceVariable(obj, name.ptr, value);
}

string sel_registerName (string str)
{
    return fromStringz(dwt.internal.objc.bindings.sel_registerName(str.ptr));
}

id objc_msgSend (ARGS...)(id theReceiver, string theSelector, ARGS args)
{
    return dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector.ptr, args);
}

/// dummy function for now
int objc_msgSend_struct (T, ARGS...)(T* result, id theReceiver, string theSelector, ARGS args)
{
    //result = *cast(T) dwt.internal.objc.bindings.objc_msgSend(theReceiver, theSelector.ptr, args);
    return 0;
}

void objc_msgSend_stret (T, ARGS...)(T* stretAddr, id theReceiver, string theSelector, ARGS args)
{
    dwt.internal.objc.bindings.objc_msgSend_stret(stretAddr, theReceiver, theSelector.ptr, args);
}

id objc_msgSendSuper (ARGS...)(objc_super* superr, string op, ARGS args)
{
    return dwt.internal.objc.bindings.objc_msgSendSuper(superr, op.ptr, args);
}

version cast(X86)
{
    double objc_msgSend_fpret(ARGS...)(id self, string op, ARGS args)
    {
        return dwt.internal.objc.bindings.objc_msgSend_fpret(self, op.ptr, args);
    }
}