mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +00:00
Add a little test case for accessing types.
Using ruamoko to access ruamoko type encodings is actually quite pleasant :)
This commit is contained in:
parent
ee8247ec61
commit
d5c831b6da
9 changed files with 195 additions and 2 deletions
|
@ -781,6 +781,7 @@ void PR_Undefined (progs_t *pr, const char *type, const char *name) __attribute_
|
||||||
|
|
||||||
\hideinitializer
|
\hideinitializer
|
||||||
*/
|
*/
|
||||||
|
extern int foo;
|
||||||
#define R_POINTER(p) R_var (p, pointer)
|
#define R_POINTER(p) R_var (p, pointer)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1537,6 +1537,18 @@ rua__c_Object__conformsToProtocol_ (progs_t *pr)
|
||||||
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
PR_RunError (pr, "%s, not implemented", __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
rua_PR_FindGlobal (progs_t *pr)
|
||||||
|
{
|
||||||
|
const char *name = P_GSTRING (pr, 0);
|
||||||
|
ddef_t *def;
|
||||||
|
|
||||||
|
R_POINTER (pr) = 0;
|
||||||
|
def = PR_FindGlobal (pr, name);
|
||||||
|
if (def)
|
||||||
|
R_POINTER (pr) = def->ofs; //FIXME def's can't access > 32k
|
||||||
|
}
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
|
||||||
static builtin_t obj_methods [] = {
|
static builtin_t obj_methods [] = {
|
||||||
|
@ -1602,6 +1614,8 @@ static builtin_t obj_methods [] = {
|
||||||
{"_i_Object__hash", rua__i_Object__hash, -1},
|
{"_i_Object__hash", rua__i_Object__hash, -1},
|
||||||
{"_i_Object_error_error_", rua__i_Object_error_error_, -1},
|
{"_i_Object_error_error_", rua__i_Object_error_error_, -1},
|
||||||
{"_c_Object__conformsToProtocol_", rua__c_Object__conformsToProtocol_, -1},
|
{"_c_Object__conformsToProtocol_", rua__c_Object__conformsToProtocol_, -1},
|
||||||
|
|
||||||
|
{"PR_FindGlobal", rua_PR_FindGlobal, -1},//FIXME
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ typedef enum {
|
||||||
@extern BOOL object_is_instance (id object);
|
@extern BOOL object_is_instance (id object);
|
||||||
@extern BOOL object_is_meta_class (id object);
|
@extern BOOL object_is_meta_class (id object);
|
||||||
|
|
||||||
|
@extern void *PR_FindGlobal (string name); //FIXME where?
|
||||||
|
|
||||||
#endif //__ruamoko_runtime_h_
|
#endif //__ruamoko_runtime_h_
|
||||||
/**
|
/**
|
||||||
\}
|
\}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "AutoreleasePool.h"
|
#include "AutoreleasePool.h"
|
||||||
|
|
||||||
|
void *PR_FindGlobal (string name) = #0; //FIXME where?
|
||||||
|
|
||||||
void __obj_exec_class (struct obj_module *msg) = #0;
|
void __obj_exec_class (struct obj_module *msg) = #0;
|
||||||
void (id object, int code, string fmt, ...) obj_error = #0;
|
void (id object, int code, string fmt, ...) obj_error = #0;
|
||||||
void (id object, int code, string fmt, @va_list args) obj_verror = #0;
|
void (id object, int code, string fmt, @va_list args) obj_verror = #0;
|
||||||
|
|
|
@ -58,7 +58,7 @@ typedef struct qfot_func_s {
|
||||||
///< types
|
///< types
|
||||||
} qfot_func_t;
|
} qfot_func_t;
|
||||||
|
|
||||||
typedef struct qfot_var_t {
|
typedef struct qfot_var_s {
|
||||||
pointer_t type; ///< type of field or self reference for
|
pointer_t type; ///< type of field or self reference for
|
||||||
///< enum
|
///< enum
|
||||||
string_t name; ///< name of field/enumerator
|
string_t name; ///< name of field/enumerator
|
||||||
|
|
|
@ -12,7 +12,7 @@ noinst_PROGRAMS=qwaq @QWAQ_TARGETS@
|
||||||
noinst_DATA=qwaq.dat
|
noinst_DATA=qwaq.dat
|
||||||
|
|
||||||
qwaq_dat_src= \
|
qwaq_dat_src= \
|
||||||
defs.qc main.qc test.r
|
defs.qc main.qc test.r types.r
|
||||||
|
|
||||||
qwaq_SOURCES= main.c builtins.c
|
qwaq_SOURCES= main.c builtins.c
|
||||||
qwaq_LDADD= $(QWAQ_LIBS)
|
qwaq_LDADD= $(QWAQ_LIBS)
|
||||||
|
|
|
@ -108,5 +108,6 @@ int main (int argc, string *argv)
|
||||||
test_str ();
|
test_str ();
|
||||||
test_script ();
|
test_script ();
|
||||||
test_plist ();
|
test_plist ();
|
||||||
|
test_types ();
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,4 +12,5 @@ qwaq.dat
|
||||||
@top_srcdir@/ruamoko/lib/Array+Private.r
|
@top_srcdir@/ruamoko/lib/Array+Private.r
|
||||||
@top_srcdir@/ruamoko/lib/AutoreleasePool.r
|
@top_srcdir@/ruamoko/lib/AutoreleasePool.r
|
||||||
@srcdir@/test.r
|
@srcdir@/test.r
|
||||||
|
@srcdir@/types.r
|
||||||
@srcdir@/main.qc
|
@srcdir@/main.qc
|
||||||
|
|
172
tools/qwaq/types.r
Normal file
172
tools/qwaq/types.r
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
#include "runtime.h" //FIXME for PR_FindGlobal
|
||||||
|
typedef enum {
|
||||||
|
ev_void,
|
||||||
|
ev_string,
|
||||||
|
ev_float,
|
||||||
|
ev_vector,
|
||||||
|
ev_entity,
|
||||||
|
ev_field,
|
||||||
|
ev_func,
|
||||||
|
ev_pointer, // end of v6 types
|
||||||
|
ev_quat,
|
||||||
|
ev_integer,
|
||||||
|
ev_uinteger,
|
||||||
|
ev_short, // value is embedded in the opcode
|
||||||
|
|
||||||
|
ev_invalid, // invalid type. used for instruction checking
|
||||||
|
ev_type_count // not a type, gives number of types
|
||||||
|
} etype_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ty_none, ///< func/field/pointer or not used
|
||||||
|
ty_struct,
|
||||||
|
ty_union,
|
||||||
|
ty_enum,
|
||||||
|
ty_array,
|
||||||
|
ty_class,
|
||||||
|
} ty_meta_e;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct qfot_fldptr_s {
|
||||||
|
etype_t type;
|
||||||
|
struct qfot_type_s *aux_type;
|
||||||
|
} qfot_fldptr_t;
|
||||||
|
|
||||||
|
typedef struct qfot_func_s {
|
||||||
|
etype_t type;
|
||||||
|
struct qfot_type_s *return_type;
|
||||||
|
int num_params;
|
||||||
|
struct qfot_type_s *param_types[1];
|
||||||
|
} qfot_func_t;
|
||||||
|
|
||||||
|
typedef struct qfot_var_s {
|
||||||
|
struct qfot_type_s *type;
|
||||||
|
string name;
|
||||||
|
int offset; // value for enum, 0 for union
|
||||||
|
} qfot_var_t;
|
||||||
|
|
||||||
|
typedef struct qfot_struct_s {
|
||||||
|
string tag;
|
||||||
|
int num_fields;
|
||||||
|
qfot_var_t fields[1];
|
||||||
|
} qfot_struct_t;
|
||||||
|
|
||||||
|
typedef struct qfot_array_s {
|
||||||
|
struct qfot_type_s *type;
|
||||||
|
int base;
|
||||||
|
int size;
|
||||||
|
} qfot_array_t;
|
||||||
|
|
||||||
|
typedef struct qfot_type_s {
|
||||||
|
ty_meta_e meta;
|
||||||
|
int size;
|
||||||
|
string encoding;
|
||||||
|
union {
|
||||||
|
etype_t type;
|
||||||
|
qfot_fldptr_t fldptr;
|
||||||
|
qfot_func_t func;
|
||||||
|
qfot_struct_t strct;
|
||||||
|
qfot_array_t array;
|
||||||
|
Class class;
|
||||||
|
} t;
|
||||||
|
} qfot_type_t;
|
||||||
|
|
||||||
|
typedef struct qfot_type_encodings_s {
|
||||||
|
qfot_type_t *types;
|
||||||
|
int size;
|
||||||
|
} qfot_type_encodings_t;
|
||||||
|
|
||||||
|
qfot_type_t *
|
||||||
|
next_type (qfot_type_t *type)
|
||||||
|
{
|
||||||
|
int size = type.size;
|
||||||
|
if (!size)
|
||||||
|
size = 4;
|
||||||
|
return (qfot_type_t *) ((int *) type + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
string ty_meta_name[6] = {
|
||||||
|
"basic",
|
||||||
|
"struct",
|
||||||
|
"union",
|
||||||
|
"enum",
|
||||||
|
"array",
|
||||||
|
"class",
|
||||||
|
};
|
||||||
|
|
||||||
|
string pr_type_name[ev_type_count] = {
|
||||||
|
"void",
|
||||||
|
"string",
|
||||||
|
"float",
|
||||||
|
"vector",
|
||||||
|
"entity",
|
||||||
|
"field",
|
||||||
|
"function",
|
||||||
|
"pointer",
|
||||||
|
"quaternion",
|
||||||
|
"integer",
|
||||||
|
"uinteger",
|
||||||
|
"short",
|
||||||
|
"invalid",
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
test_types (void)
|
||||||
|
{
|
||||||
|
qfot_type_encodings_t *encodings;
|
||||||
|
qfot_type_t *type;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
encodings = PR_FindGlobal (".type_encodings");
|
||||||
|
if (!encodings) {
|
||||||
|
printf ("Can't find encodings\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (type = encodings.types;
|
||||||
|
((int *)type - (int *) encodings.types) < encodings.size;
|
||||||
|
type = next_type (type)) {
|
||||||
|
printf ("%p %-6s %-20s", type, ty_meta_name[type.meta],
|
||||||
|
type.encoding);
|
||||||
|
if (!type.size) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (type.meta) {
|
||||||
|
case ty_none:
|
||||||
|
printf (" %-10s", pr_type_name[type.t.type]);
|
||||||
|
if (type.t.type == ev_func) {
|
||||||
|
int count = type.t.func.num_params;
|
||||||
|
printf ("%p %d", type.t.func.return_type, count);
|
||||||
|
if (count < 0)
|
||||||
|
count = ~count;
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
printf (" %p", type.t.func.param_types[i]);
|
||||||
|
} else if (type.t.type == ev_pointer) {
|
||||||
|
printf (" *%p", type.t.fldptr.aux_type);
|
||||||
|
} else if (type.t.type == ev_field) {
|
||||||
|
printf (" .%p", type.t.fldptr.aux_type);
|
||||||
|
} else {
|
||||||
|
printf (" %p", type.t.fldptr.aux_type);
|
||||||
|
}
|
||||||
|
printf ("\n");
|
||||||
|
break;
|
||||||
|
case ty_struct:
|
||||||
|
case ty_union:
|
||||||
|
case ty_enum:
|
||||||
|
printf (" %s\n", type.t.strct.tag);
|
||||||
|
for (i = 0; i < type.t.strct.num_fields; i++) {
|
||||||
|
printf (" %p %4x %s\n",
|
||||||
|
type.t.strct.fields[i].type,
|
||||||
|
type.t.strct.fields[i].offset,
|
||||||
|
type.t.strct.fields[i].name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ty_array:
|
||||||
|
printf (" %p %d %d\n", type.t.array.type,
|
||||||
|
type.t.array.base, type.t.array.size);
|
||||||
|
break;
|
||||||
|
case ty_class:
|
||||||
|
printf (" %p %s\n", type.t.class, type.t.class.name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue