view runtime/object.h @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents c40c3d399133
children 3c4325e6298f
line wrap: on
line source

#ifndef OBJECT_H_
#define OBJECT_H_

#include "plat_types.h"
#include "thread.h"
#include "func.h"

typedef struct{
	rhope_func     *method_lookup;
	rhope_func     *getter_lookup;
	rhope_func     *setter_lookup;
	rhope_func     *convert_to;
	rhope_func     *convert_from;
	special_func   init;
	special_func   copy;
	special_func   cleanup;
	special_func   free;
	struct object  *name;
	uint32_t       type_id;
	uint32_t       first_methodid;
	uint32_t       last_methodid;
	uint32_t       first_getfieldid;
	uint32_t       last_getfieldid;
	uint32_t       first_setfieldid;
	uint32_t       last_setfieldid;
	uint32_t       first_convertto;
	uint32_t       last_convertto;
	uint32_t       first_convertfrom;
	uint32_t       last_convertfrom;
	int32_t       size;
	int32_t       boxed_size;
} blueprint;

struct object {
	rh_atomic32(refcount);
	blueprint  *bprint;
};

typedef struct {
	object    base;
	uint32_t  size;
} multisize;

#pragma pack(push,1)
struct calldata {
	struct calldata	*lastframe;
	void            *vars;
	uint32_t 		func;
	uint16_t 		num_params;
	uint16_t		callspace;
	object 			*params[1];
};
#pragma pack(pop)

#define OBegin typedef struct {
#define Object(name) } nt_ ## name; typedef struct { object SP_header; nt_ ## name payload; } t_ ## name;
#define MObject(name) } nt_ ## name; typedef struct { multisize SP_header; nt_ ## name payload; } t_ ## name; 
#define Box(nakedtype,fieldname,objectname) typedef struct{ object SP_header; nakedtype fieldname; } t_ ## objectname;

#define get_blueprint(object) (object)->bprint

#define add_ref(object) (rh_atomic_add((object), refcount, 1),object)

returntype call_method(uint32_t methodid, calldata * params);
returntype set_field(uint32_t setfieldid, calldata * params);
returntype get_field(uint32_t getfieldid, calldata * params);
object * alloc_object(blueprint * bp);
void * alloc_variable(uint32_t size);
object * new_object(uint32_t type);
object * new_object_bp(blueprint * bp);
multisize * new_multisize(uint32_t type, uint32_t size);
void release_ref(object * obj);
blueprint * register_type_byid(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup);
blueprint * new_blueprint(uint32_t type, int32_t size, special_func init, special_func copy, special_func cleanup);
void add_method(blueprint * bp, uint32_t methodid, rhope_func impl);
void add_getter(blueprint * bp, uint32_t fieldid, rhope_func impl);
void add_setter(blueprint * bp, uint32_t fieldid, rhope_func impl);
returntype convert_to(uint32_t convertto, calldata * params);
returntype convert_from(uint32_t convertfrom, calldata * params);
object * copy_object(object * tocopy);
object * naked_to_boxed(uint32_t type, void * rawdata);
void boxed_to_naked(object * src, void * dest);
returntype coerce_value(uint32_t type, calldata * params);
blueprint * get_blueprint_byid(uint32_t type);

#define INITIAL_TYPE_STORAGE	32
#define INITIAL_METHOD_LOOKUP	8
#define BELOW_INITIAL_METHOD	3

#endif //OBJECT_H_