view datum.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 23dd9c766699
children
line wrap: on
line source

#ifndef _DATUM_H_
#define _DATUM_H_

#include "vis_threading.h"
#include "debugmacros.h"

/*
Old Datum structure
typedef struct
{
	unsigned char type;//0=String,1=Bool,2=Int32,3=UInt32,4=Float, bit 7 = dynamically allocated (i.e. call free when datum is freed)
	int len;
	void * contents;
} datum;
*/

//Support structs for new datum structure
#ifdef CPLUSPLUS
extern "C" {
#endif
#ifndef PROGRAM_STRUCT_DECLARED_
#define PROGRAM_STRUCT_DECLARED_
//icky hack until I figure out a better one
//defined in both datum.h and structs.h ugh

typedef struct
{
	char filename[512];
	struct defchunk * defs;
	struct defchunk * current;
	//struct worker_def * deflist;
	//int num_defs;
	//int defs_storage;
	struct company * companylist;
	int num_companies;
	int companies_storage;
	int refcount;
	VIS_CRITICAL_SECTION(lock)
} program;

#endif

typedef struct
{
	unsigned int len;
	void * data;
} generic_data;
typedef struct
{
	int num_a;
	int num_b;
} two_ints;
//New datum structure
typedef struct
{
	//unsigned short type;
	struct company * company;
	unsigned char union_type;
	union
	{
		generic_data generic;
		two_ints integers;
		double real;
	} c;
	int ref_count;
	VIS_CRITICAL_SECTION(lock)
} datum;

#define DATUMS_PER_STORAGE	512
typedef struct datum_storage
{
	datum datums[DATUMS_PER_STORAGE];
	unsigned short available;
	unsigned char inuse[DATUMS_PER_STORAGE/8];
	int num;
	struct datum_storage * next;
} datum_storage;
#define CHECK_INUSE(storage, index, subindex)	((storage->inuse[index]) & (1 << (subindex)))
#define	SET_INUSE(storage, index)	(storage->inuse[index >> 3] |= (1 << (index & 7)))
#define	CLEAR_INUSE(storage, index)	(storage->inuse[index >> 3] &= ~(1 << (index & 7)))

datum * new_datum(unsigned short type, unsigned char union_type, int generic_len, program * prog);
datum * add_ref(datum * adatum);
void release_ref(datum * adatum);
void datum_set_yesno(datum * adatum, int val);
void init_datum_storage();
datum * copy_datum(datum * adatum, int newsize);
#ifdef CPLUSPLUS
}
#endif

#define DATUM_YES	1
#define DATUM_NO	0

#ifdef GUI_LIB
	#define BUILTIN_TYPE_SCREEN_CUSTOM		17
	#define BUILTIN_TYPE_CUSTOM_WIDGET		16
	#define BUILTIN_TYPE_CHECKBOX			20
	#define BUILTIN_TYPE_DROPDOWN			21
	#ifdef SYLLABLE
		#define USER_DEFINED_TYPES			22
		#define BUILTIN_TYPE_BLUEPRINT		19
		#define BUILTIN_TYPE_BUFFER			18
	#else
		#define USER_DEFINED_TYPES			18
		#define BUILTIN_TYPE_BLUEPRINT		17
		#define BUILTIN_TYPE_BUFFER			16
	#endif
	#define BUILTIN_TYPE_PROGRAM		15
	#define BUILTIN_TYPE_GLOBAL_STORE	14
	#define BUILTIN_TYPE_NETCLIENT		13
#else
	#ifdef SEGA
		#define	USER_DEFINED_TYPES			12
		#define BUILTIN_TYPE_BLUEPRINT		11
		#define BUILTIN_TYPE_BUFFER			10
		#define BUILTIN_TYPE_PROGRAM		9
		#define BUILTIN_TYPE_GLOBAL_STORE	8
	#else
		#ifdef NO_NET
			#define	USER_DEFINED_TYPES			13
			#define BUILTIN_TYPE_BLUEPRINT		12
			#define BUILTIN_TYPE_BUFFER			11
			#define BUILTIN_TYPE_PROGRAM		10
			#define BUILTIN_TYPE_GLOBAL_STORE	9
		#else
			#define	USER_DEFINED_TYPES			14
			#define BUILTIN_TYPE_BLUEPRINT		13
			#define BUILTIN_TYPE_BUFFER			12
			#define BUILTIN_TYPE_PROGRAM		11
			#define BUILTIN_TYPE_GLOBAL_STORE	10
		#endif
	#endif
	#define	BUILTIN_TYPE_NETCLIENT		9
#endif
#define BUILTIN_TYPE_INPUTBOX			12
#define BUILTIN_TYPE_BUTTON				11
#define BUILTIN_TYPE_WINDOW_SHOWN		10
#define BUILTIN_TYPE_WINDOW 			9
#ifdef SEGA
	#define BUILTIN_TYPE_WORKER			7
#else
	#define BUILTIN_TYPE_WORKER				8
#endif //SEGA
#define BUILTIN_TYPE_FILE				7
#define BUILTIN_TYPE_DICT				6
#define BUILTIN_TYPE_LIST				5
#define BUILTIN_TYPE_REAL				4
#define BUILTIN_TYPE_WHOLE				3
#define BUILTIN_TYPE_STRING				2
#define BUILTIN_TYPE_YESNO				1
#define ANY_TYPE						0

#endif //_DATUM_H_