/*
 int2.h
  interpreter v2 (in development)
*/

enum
{ /* required type indices */
  /* the built-in handlers take xint8-arrays as ASCII-compatible strings (includes UTF-8) */
	_t_list, /* data: name list ([ahash.8] [bname.pstr]) */
	_t_func, /* pack/malloc=script func; otherwise, native code */
	_t_float,
	_t_double,
	_t_int8, /* arrays are taken as C-strings (null-clipped) */
	_t_int16,
	_t_int32,
	_t_int64,
	_t_uint8, /* arrays are taken as raw strings (unclipped) */
	_t_uint16,
	_t_uint32,
	_t_uint64,
	_t_pstr /* Pascal str; first byte in reads is size clip */
};

typedef struct list_item/*(16)*/
{
	uint32		type; /* [ptr.1] [const.1] [item.1] [pack.1] [index.28] */
	int32		size; /* offset if ref (both ptr/item) */
	item_data	data;
} list_item;

#define ITEM_IS_REF(i)			!(~(i)->type&0xA0000000u)
#define ITEM_IS_PTR(i)			!!((i)->type&0x80000000u)
#define ITEM_IS_CONST(i)		!!((i)->type&0x40000000u)
#define ITEM_IS_ITEM(i)			!!((i)->type&0x20000000u)
#define ITEM_IS_PACKED(i)		!!((i)->type&0x10000000u)
#define ITEM_HAS_MALLOC(i)		((int32)((i)->type&0x90000000u)>0)
#define ITEM_TYPE(i)			((i)->type&0xFFFFFFF)
#define ITEM_PTR(i)			(ITEM_IS_PTR(i)?(i)->data.vptr:(i)->data.raw)

/*
 script binary file:
  'i','n','t','\0'; type names list for each index; script globals list (everything)

 all data is stored MSB
 all items are packed in file, so the pack bit instead serves as whether
the type field is stored 8 bits (4-bit index) or 32 bits
 bit #31 of size is invalid, so first bit #7 is used to pack in 8 bits (7-bit size)
*/

enum
{ /* macro indices (handler should return -1 when "not handled") */
	_m_type		= 0x100, /* item type string (required) */
	_m_namex, /* index for field name (where applicable) */
	_m_esize /* element/sample size (where applicable) */
};

typedef int8 *(*type_handler)(int32 m);
