From 75ec6bf244552cc905adc4e134372f9268bfe8c1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 9 Jan 2011 19:41:24 +0900 Subject: [PATCH] Clean out some unnecessary types from the progs engine and clean up the mess. This is a nasty commit, sorry, but 99% of the commit is interdependent. --- include/QF/pr_comp.h | 40 +- libs/gamecode/engine/pr_debug.c | 12 - libs/gamecode/engine/pr_exec.c | 40 -- libs/gamecode/engine/pr_opcode.c | 270 ++++--------- nq/source/sv_progs.c | 7 +- qw/source/sv_progs.c | 7 +- ruamoko/cl_menu/CrosshairView.h | 4 +- ruamoko/cl_menu/CrosshairView.r | 4 +- ruamoko/cl_menu/CvarColorView.h | 4 +- ruamoko/cl_menu/CvarColorView.r | 2 +- ruamoko/cl_menu/CvarRangeView.h | 10 +- ruamoko/cl_menu/CvarRangeView.r | 2 +- ruamoko/cl_menu/CvarToggleView.h | 8 +- ruamoko/cl_menu/CvarToggleView.r | 2 +- ruamoko/cl_menu/Frame.h | 2 +- ruamoko/cl_menu/HUD.h | 6 +- ruamoko/cl_menu/HUD.r | 10 +- ruamoko/cl_menu/MenuGroup.r | 4 +- ruamoko/cl_menu/ProxyView.h | 6 +- ruamoko/cl_menu/ProxyView.r | 4 +- ruamoko/cl_menu/client_menu.h | 2 +- ruamoko/cl_menu/client_menu.qc | 10 +- ruamoko/cl_menu/controls_o.qc | 26 +- ruamoko/cl_menu/options.qc | 64 ++-- ruamoko/cl_menu/plistmenu.h | 4 +- ruamoko/cl_menu/plistmenu.r | 46 +-- ruamoko/cl_menu/servlist.qc | 4 +- ruamoko/game/Axe.h | 2 +- ruamoko/game/Axe.r | 2 +- ruamoko/game/Weapon.h | 2 +- ruamoko/game/World.r | 12 +- ruamoko/gui/Group.r | 6 +- ruamoko/gui/View.r | 2 +- ruamoko/include/Array.h | 12 +- ruamoko/include/AutoreleasePool.h | 2 +- ruamoko/include/ListNode.h | 2 +- ruamoko/include/Object.h | 2 +- ruamoko/include/PropertyList.h | 32 +- ruamoko/include/Protocol.h | 2 +- ruamoko/include/gui/Group.h | 6 +- ruamoko/include/gui/InputLine.h | 2 +- ruamoko/include/gui/View.h | 4 +- ruamoko/lib/Array.r | 14 +- ruamoko/lib/AutoreleasePool.r | 2 +- ruamoko/lib/Entity.r | 2 +- ruamoko/lib/Object.r | 4 +- ruamoko/lib/PropertyList.r | 32 +- ruamoko/lib/Protocol.r | 2 +- ruamoko/scheme/BaseContinuation.r | 8 +- ruamoko/scheme/Boolean.r | 4 +- ruamoko/scheme/CompiledCode.h | 14 +- ruamoko/scheme/CompiledCode.r | 12 +- ruamoko/scheme/Compiler.h | 22 +- ruamoko/scheme/Compiler.r | 156 ++++---- ruamoko/scheme/Cons.h | 20 +- ruamoko/scheme/Cons.r | 22 +- ruamoko/scheme/Continuation.h | 2 +- ruamoko/scheme/Continuation.r | 6 +- ruamoko/scheme/Error.h | 4 +- ruamoko/scheme/Error.r | 4 +- ruamoko/scheme/Frame.h | 14 +- ruamoko/scheme/Frame.r | 10 +- ruamoko/scheme/Instruction.h | 6 +- ruamoko/scheme/Instruction.r | 4 +- ruamoko/scheme/Lambda.h | 8 +- ruamoko/scheme/Lambda.r | 6 +- ruamoko/scheme/Lexer.h | 2 +- ruamoko/scheme/Lexer.r | 10 +- ruamoko/scheme/Machine.h | 24 +- ruamoko/scheme/Machine.r | 70 ++-- ruamoko/scheme/Nil.r | 2 +- ruamoko/scheme/Parser.h | 6 +- ruamoko/scheme/Parser.r | 16 +- ruamoko/scheme/Primitive.h | 2 +- ruamoko/scheme/Primitive.r | 4 +- ruamoko/scheme/Procedure.h | 2 +- ruamoko/scheme/Procedure.r | 2 +- ruamoko/scheme/SchemeObject.h | 2 +- ruamoko/scheme/SchemeObject.r | 4 +- ruamoko/scheme/Scope.h | 16 +- ruamoko/scheme/Scope.r | 14 +- ruamoko/scheme/Symbol.h | 12 +- ruamoko/scheme/Symbol.r | 28 +- ruamoko/scheme/Void.h | 2 +- ruamoko/scheme/Void.r | 2 +- ruamoko/scheme/builtins.h | 2 +- ruamoko/scheme/builtins.r | 140 +++---- ruamoko/scheme/state.h | 8 +- tools/qfcc/include/Makefile.am | 8 +- tools/qfcc/include/codespace.h | 47 +++ tools/qfcc/include/def.h | 1 + tools/qfcc/include/emit.h | 12 - tools/qfcc/include/expr.h | 5 + tools/qfcc/include/type.h | 54 ++- tools/qfcc/source/Makefile.am | 6 +- tools/qfcc/source/class.c | 40 +- tools/qfcc/source/codespace.c | 83 ++++ tools/qfcc/source/constfold.c | 398 ++------------------ tools/qfcc/source/def.c | 14 +- tools/qfcc/source/emit.c | 97 ++--- tools/qfcc/source/expr.c | 381 ++++++++++--------- tools/qfcc/source/function.c | 63 ++-- tools/qfcc/source/idstuff.c | 2 +- tools/qfcc/source/immediate.c | 7 +- tools/qfcc/source/linker.c | 6 +- tools/qfcc/source/method.c | 39 +- tools/qfcc/source/obj_file.c | 6 +- tools/qfcc/source/qc-lex.l | 2 +- tools/qfcc/source/qfcc.c | 4 +- tools/qfcc/source/qfprogs.c | 8 - tools/qfcc/source/qp-parse.y | 10 +- tools/qfcc/source/reloc.c | 1 + tools/qfcc/source/struct.c | 5 +- tools/qfcc/source/stub.c | 1 + tools/qfcc/source/switch.c | 6 +- tools/qfcc/source/type.c | 606 ++++++++++++++++++------------ 116 files changed, 1538 insertions(+), 1812 deletions(-) create mode 100644 tools/qfcc/include/codespace.h create mode 100644 tools/qfcc/source/codespace.c diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index 1b52f4fa8..aad052963 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -42,14 +42,9 @@ typedef enum { ev_pointer, // end of v6 types ev_quat, ev_integer, - ev_uinteger, ev_short, // value is embedded in the opcode - ev_struct, - ev_object, - ev_class, - ev_sel, - ev_array, - + + ev_invalid, // invalid type. used for instruction checking ev_type_count // not a type, gives number of types } etype_t; @@ -263,33 +258,8 @@ typedef enum { OP_MOVE, OP_MOVEP, - OP_ADD_U, - OP_SUB_U, - OP_MUL_U, - OP_DIV_U, - OP_BITAND_U, - OP_BITOR_U, - OP_BITXOR_U, - OP_BITNOT_U, - OP_AND_U, - OP_OR_U, - OP_NOT_U, - OP_EQ_U, - OP_NE_U, - OP_MOD_U, OP_SHL_U, OP_SHR_U, - OP_STORE_U, - OP_STOREB_U, - OP_STOREBI_U, - OP_STOREP_U, - OP_LOAD_U, - OP_LOADB_U, - OP_LOADBI_U, - OP_ADDRESS_U, - - OP_CONV_IU, - OP_CONV_UI, OP_STATE_F, @@ -383,8 +353,12 @@ typedef struct pr_va_list_s { pointer_t list; // pr_type_t } pr_va_list_t; +#define PROG_VERSION_ENCODE(a,b,c) \ + ( (((0x##a) & 0x0ff) << 24) \ + |(((0x##b) & 0xfff) << 12) \ + |(((0x##c) & 0xfff) << 0) ) #define PROG_ID_VERSION 6 -#define PROG_VERSION 0x00fff005 // MMmmmRRR 0.fff.005 (hex) +#define PROG_VERSION PROG_VERSION_ENCODE(0,fff,006) typedef struct dprograms_s { pr_uint_t version; diff --git a/libs/gamecode/engine/pr_debug.c b/libs/gamecode/engine/pr_debug.c index 15e87287a..ffe73a09d 100644 --- a/libs/gamecode/engine/pr_debug.c +++ b/libs/gamecode/engine/pr_debug.c @@ -645,12 +645,6 @@ value_string (progs_t *pr, etype_t type, pr_type_t *val) case ev_integer: dsprintf (line, "%d", val->integer_var); break; - case ev_uinteger: - dsprintf (line, "$%08x", val->uinteger_var); - break; - case ev_sel: - dsprintf (line, "(SEL) %s", PR_GetString (pr, val->string_var)); - break; default: dsprintf (line, "bad type %i", type); break; @@ -1041,18 +1035,12 @@ ED_Print (progs_t *pr, edict_t *ed) switch (type) { case ev_entity: case ev_integer: - case ev_uinteger: case ev_pointer: case ev_func: case ev_field: if (!v->integer_var) continue; break; - case ev_sel: - if (!v[0].integer_var - && !PR_GetString (pr, v[1].string_var)[0]) - continue; - break; case ev_string: if (PR_StringValid (pr, v->string_var)) if (!PR_GetString (pr, v->string_var)[0]) diff --git a/libs/gamecode/engine/pr_exec.c b/libs/gamecode/engine/pr_exec.c index 31acb5a52..54fa5093b 100644 --- a/libs/gamecode/engine/pr_exec.c +++ b/libs/gamecode/engine/pr_exec.c @@ -312,7 +312,6 @@ signal_hook (int sig, void *data) OPC.integer_var = 0x7fffffff; return 1; case OP_MOD_I: - case OP_MOD_U: case OP_MOD_F: OPC.integer_var = 0x00000000; return 1; @@ -572,7 +571,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_STORE_S: case OP_STORE_FN: // pointers case OP_STORE_I: - case OP_STORE_U: case OP_STORE_P: OPB.integer_var = OPA.integer_var; break; @@ -589,7 +587,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_STOREP_S: case OP_STOREP_FN: // pointers case OP_STOREP_I: - case OP_STOREP_U: case OP_STOREP_P: pointer = OPB.integer_var; if (pr_boundscheck->int_val) { @@ -638,7 +635,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_ADDRESS_FLD: case OP_ADDRESS_FN: case OP_ADDRESS_I: - case OP_ADDRESS_U: case OP_ADDRESS_P: OPC.integer_var = st->a; break; @@ -649,7 +645,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_LOAD_S: case OP_LOAD_FN: case OP_LOAD_I: - case OP_LOAD_U: case OP_LOAD_P: if (pr_boundscheck->int_val) { if (OPA.entity_var < 0 @@ -696,7 +691,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_LOADB_FLD: case OP_LOADB_FN: case OP_LOADB_I: - case OP_LOADB_U: case OP_LOADB_P: pointer = OPA.integer_var + OPB.integer_var; if (pr_boundscheck->int_val) { @@ -728,7 +722,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_LOADBI_FLD: case OP_LOADBI_FN: case OP_LOADBI_I: - case OP_LOADBI_U: case OP_LOADBI_P: pointer = OPA.integer_var + (short) st->b; if (pr_boundscheck->int_val) { @@ -770,7 +763,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_STOREB_FLD: case OP_STOREB_FN: case OP_STOREB_I: - case OP_STOREB_U: case OP_STOREB_P: pointer = OPB.integer_var + OPC.integer_var; if (pr_boundscheck->int_val) { @@ -802,7 +794,6 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum) case OP_STOREBI_FLD: case OP_STOREBI_FN: case OP_STOREBI_I: - case OP_STOREBI_U: case OP_STOREBI_P: pointer = OPB.integer_var + (short) st->c; if (pr_boundscheck->int_val) { @@ -990,44 +981,18 @@ op_call: OPC.integer_var = OPA.float_var; break; case OP_BITAND_I: - case OP_BITAND_U: OPC.integer_var = OPA.integer_var & OPB.integer_var; break; case OP_BITOR_I: - case OP_BITOR_U: OPC.integer_var = OPA.integer_var | OPB.integer_var; break; case OP_BITXOR_I: - case OP_BITXOR_U: OPC.integer_var = OPA.integer_var ^ OPB.integer_var; break; case OP_BITNOT_I: - case OP_BITNOT_U: OPC.integer_var = ~OPA.integer_var; break; - case OP_ADD_U: - OPC.uinteger_var = OPA.uinteger_var + OPB.uinteger_var; - break; - case OP_SUB_U: - OPC.uinteger_var = OPA.uinteger_var - OPB.uinteger_var; - break; - case OP_MUL_U: - OPC.uinteger_var = OPA.uinteger_var * OPB.uinteger_var; - break; - case OP_DIV_U: - OPC.uinteger_var = OPA.uinteger_var / OPB.uinteger_var; - break; - case OP_MOD_U: - OPC.uinteger_var = OPA.uinteger_var % OPB.uinteger_var; - break; - case OP_CONV_IU: - OPC.uinteger_var = OPA.integer_var; - break; - case OP_CONV_UI: - OPC.integer_var = OPA.uinteger_var; - break; - case OP_GE_I: case OP_GE_P: OPC.integer_var = OPA.integer_var >= OPB.integer_var; @@ -1058,25 +1023,20 @@ op_call: break; case OP_AND_I: - case OP_AND_U: OPC.integer_var = OPA.integer_var && OPB.integer_var; break; case OP_OR_I: - case OP_OR_U: OPC.integer_var = OPA.integer_var || OPB.integer_var; break; case OP_NOT_I: - case OP_NOT_U: case OP_NOT_P: OPC.integer_var = !OPA.integer_var; break; case OP_EQ_I: - case OP_EQ_U: case OP_EQ_P: OPC.integer_var = OPA.integer_var == OPB.integer_var; break; case OP_NE_I: - case OP_NE_U: case OP_NE_P: OPC.integer_var = OPA.integer_var != OPB.integer_var; break; diff --git a/libs/gamecode/engine/pr_opcode.c b/libs/gamecode/engine/pr_opcode.c index 12ecfff9f..3e3059282 100644 --- a/libs/gamecode/engine/pr_opcode.c +++ b/libs/gamecode/engine/pr_opcode.c @@ -60,13 +60,7 @@ VISIBLE int pr_type_size[ev_type_count] = { 1, // ev_pointer 4, // ev_quat 1, // ev_integer - 1, // ev_uinteger 0, // ev_short value in opcode - 0, // ev_struct variable - 0, // ev_object variable - 0, // ev_class variable - 2, // ev_sel - 0, // ev_array variable }; VISIBLE const char *pr_type_name[ev_type_count] = { @@ -80,13 +74,8 @@ VISIBLE const char *pr_type_name[ev_type_count] = { "pointer", "quaternion", "integer", - "uinteger", "short", - "struct", - "object", - "Class", - "SEL", - "array", + "invalid", }; // default format is "%Ga, %Gb, %gc" @@ -106,8 +95,8 @@ VISIBLE const char *pr_type_name[ev_type_count] = { // x place holder for P (padding) // 0-7 parameter index (for P) VISIBLE opcode_t pr_opcodes[] = { - {"", "done", OP_DONE, false, - ev_entity, ev_field, ev_void, + {"", "done", OP_DONE, false, // OP_DONE is actually the same as + ev_entity, ev_field, ev_void, // OP_RETURN, the types are bogus PROG_ID_VERSION, "%Va", }, @@ -142,7 +131,7 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"~", "conj.q", OP_CONJ_Q, false, - ev_quat, ev_void, ev_quat, + ev_quat, ev_invalid, ev_quat, PROG_ID_VERSION, }, @@ -304,11 +293,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, "%Ga.%Gb(%Ec), %gc", }, - {".", "load.u", OP_LOAD_U, false, - ev_entity, ev_field, ev_uinteger, - PROG_VERSION, - "%Ga.%Gb(%Ec), %gc", - }, {".", "load.p", OP_LOAD_P, false, ev_entity, ev_field, ev_pointer, PROG_VERSION, @@ -355,11 +339,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, "*(%Ga + %Gb), %gc", }, - {".", "loadb.u", OP_LOADB_U, false, - ev_pointer, ev_integer, ev_uinteger, - PROG_VERSION, - "*(%Ga + %Gb), %gc", - }, {".", "loadb.p", OP_LOADB_P, false, ev_pointer, ev_integer, ev_pointer, PROG_VERSION, @@ -406,11 +385,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, "*(%Ga + %sb), %gc", }, - {".", "loadbi.u", OP_LOADBI_U, false, - ev_pointer, ev_short, ev_uinteger, - PROG_VERSION, - "*(%Ga + %sb), %gc", - }, {".", "loadbi.p", OP_LOADBI_P, false, ev_pointer, ev_short, ev_pointer, PROG_VERSION, @@ -424,52 +398,47 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"&", "address.f", OP_ADDRESS_F, false, - ev_float, ev_void, ev_pointer, + ev_float, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.v", OP_ADDRESS_V, false, - ev_vector, ev_void, ev_pointer, + ev_vector, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.q", OP_ADDRESS_Q, false, - ev_quat, ev_void, ev_pointer, + ev_quat, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.s", OP_ADDRESS_S, false, - ev_string, ev_void, ev_pointer, + ev_string, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.ent", OP_ADDRESS_ENT, false, - ev_entity, ev_void, ev_pointer, + ev_entity, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.fld", OP_ADDRESS_FLD, false, - ev_field, ev_void, ev_pointer, + ev_field, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.fn", OP_ADDRESS_FN, false, - ev_func, ev_void, ev_pointer, + ev_func, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.i", OP_ADDRESS_I, false, - ev_integer, ev_void, ev_pointer, - PROG_VERSION, - "%Ga, %gc", - }, - {"&", "address.u", OP_ADDRESS_U, false, - ev_uinteger, ev_void, ev_pointer, + ev_integer, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, {"&", "address.p", OP_ADDRESS_P, false, - ev_pointer, ev_void, ev_pointer, + ev_pointer, ev_invalid, ev_pointer, PROG_VERSION, "%Ga, %gc", }, @@ -486,125 +455,104 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"=", "conv.if", OP_CONV_IF, false, - ev_integer, ev_void, ev_float, + ev_integer, ev_invalid, ev_float, PROG_VERSION, "%Ga, %gc", }, {"=", "conv.fi", OP_CONV_FI, false, - ev_float, ev_void, ev_integer, - PROG_VERSION, - "%Ga, %gc", - }, - - {"=", "conv.iu", OP_CONV_IU, false, - ev_integer, ev_void, ev_uinteger, - PROG_VERSION, - "%Ga, %gc", - }, - {"=", "conv.ui", OP_CONV_UI, false, - ev_uinteger, ev_void, ev_integer, + ev_float, ev_invalid, ev_integer, PROG_VERSION, "%Ga, %gc", }, {"=", "store.f", OP_STORE_F, true, - ev_float, ev_float, ev_void, + ev_float, ev_float, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.v", OP_STORE_V, true, - ev_vector, ev_vector, ev_void, + ev_vector, ev_vector, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.q", OP_STORE_Q, true, - ev_quat, ev_quat, ev_void, + ev_quat, ev_quat, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.s", OP_STORE_S, true, - ev_string, ev_string, ev_void, + ev_string, ev_string, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.ent", OP_STORE_ENT, true, - ev_entity, ev_entity, ev_void, + ev_entity, ev_entity, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.fld", OP_STORE_FLD, true, - ev_field, ev_field, ev_void, + ev_field, ev_field, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.fn", OP_STORE_FN, true, - ev_func, ev_func, ev_void, + ev_func, ev_func, ev_invalid, PROG_ID_VERSION, "%Ga, %gb", }, {"=", "store.i", OP_STORE_I, true, - ev_integer, ev_integer, ev_void, - PROG_VERSION, - "%Ga, %gb", - }, - {"=", "store.u", OP_STORE_U, true, - ev_uinteger, ev_uinteger, ev_void, + ev_integer, ev_integer, ev_invalid, PROG_VERSION, "%Ga, %gb", }, {"=", "store.p", OP_STORE_P, true, - ev_pointer, ev_pointer, ev_void, + ev_pointer, ev_pointer, ev_invalid, PROG_VERSION, "%Ga, %gb", }, {".=", "storep.f", OP_STOREP_F, true, - ev_float, ev_pointer, ev_void, + ev_float, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.v", OP_STOREP_V, true, - ev_vector, ev_pointer, ev_void, + ev_vector, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.q", OP_STOREP_Q, true, - ev_quat, ev_pointer, ev_void, + ev_quat, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.s", OP_STOREP_S, true, - ev_string, ev_pointer, ev_void, + ev_string, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.ent", OP_STOREP_ENT, true, - ev_entity, ev_pointer, ev_void, + ev_entity, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.fld", OP_STOREP_FLD, true, - ev_field, ev_pointer, ev_void, + ev_field, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.fn", OP_STOREP_FN, true, - ev_func, ev_pointer, ev_void, + ev_func, ev_pointer, ev_invalid, PROG_ID_VERSION, "%Ga, *%Gb", }, {".=", "storep.i", OP_STOREP_I, true, - ev_integer, ev_pointer, ev_void, - PROG_VERSION, - "%Ga, *%Gb", - }, - {".=", "storep.u", OP_STOREP_U, true, - ev_uinteger, ev_pointer, ev_void, + ev_integer, ev_pointer, ev_invalid, PROG_VERSION, "%Ga, *%Gb", }, {".=", "storep.p", OP_STOREP_P, true, - ev_pointer, ev_pointer, ev_void, + ev_pointer, ev_pointer, ev_invalid, PROG_VERSION, "%Ga, *%Gb", }, @@ -649,11 +597,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, "%Ga, *(%Gb + %Gc)", }, - {".=", "storeb.u", OP_STOREB_U, true, - ev_uinteger, ev_pointer, ev_integer, - PROG_VERSION, - "%Ga, *(%Gb + %Gc)", - }, {".=", "storeb.p", OP_STOREB_P, true, ev_pointer, ev_pointer, ev_integer, PROG_VERSION, @@ -700,11 +643,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, "%Ga, *(%Gb + %sc)", }, - {".=", "storebi.u", OP_STOREBI_U, true, - ev_uinteger, ev_pointer, ev_short, - PROG_VERSION, - "%Ga, *(%Gb + %sc)", - }, {".=", "storebi.p", OP_STOREBI_P, true, ev_pointer, ev_pointer, ev_short, PROG_VERSION, @@ -712,126 +650,126 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"", "return", OP_RETURN, false, - ev_void, ev_void, ev_void, + ev_void, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Ra", }, {"!", "not.f", OP_NOT_F, false, - ev_float, ev_void, ev_integer, + ev_float, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.v", OP_NOT_V, false, - ev_vector, ev_void, ev_integer, + ev_vector, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.q", OP_NOT_Q, false, - ev_quat, ev_void, ev_integer, + ev_quat, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.s", OP_NOT_S, false, - ev_string, ev_void, ev_integer, + ev_string, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.ent", OP_NOT_ENT, false, - ev_entity, ev_void, ev_integer, + ev_entity, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.fn", OP_NOT_FN, false, - ev_func, ev_void, ev_integer, + ev_func, ev_invalid, ev_integer, PROG_ID_VERSION, "%Ga, %gc", }, {"!", "not.p", OP_NOT_P, false, - ev_pointer, ev_void, ev_integer, + ev_pointer, ev_invalid, ev_integer, PROG_VERSION, "%Ga, %gc", }, {"", "if", OP_IF, false, - ev_integer, ev_void, ev_void, + ev_integer, ev_short, ev_invalid, PROG_ID_VERSION, "%Ga branch %sb (%Ob)", }, {"", "ifnot", OP_IFNOT, false, - ev_integer, ev_void, ev_void, + ev_integer, ev_short, ev_invalid, PROG_ID_VERSION, "%Ga branch %sb (%Ob)", }, {"", "ifbe", OP_IFBE, true, - ev_integer, ev_integer, ev_void, + ev_integer, ev_short, ev_invalid, PROG_VERSION, "%Ga branch %sb (%Ob)", }, {"", "ifb", OP_IFB, true, - ev_integer, ev_integer, ev_void, + ev_integer, ev_short, ev_invalid, PROG_VERSION, "%Ga branch %sb (%Ob)", }, {"", "ifae", OP_IFAE, true, - ev_integer, ev_integer, ev_void, + ev_integer, ev_short, ev_invalid, PROG_VERSION, "%Ga branch %sb (%Ob)", }, {"", "ifa", OP_IFA, true, - ev_integer, ev_integer, ev_void, + ev_integer, ev_short, ev_invalid, PROG_VERSION, "%Ga branch %sb (%Ob)", }, // calls returns REG_RETURN {"", "call0", OP_CALL0, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa ()", }, {"", "call1", OP_CALL1, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x)", }, {"", "call2", OP_CALL2, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x)", }, {"", "call3", OP_CALL3, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x)", }, {"", "call4", OP_CALL4, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x, %P3x)", }, {"", "call5", OP_CALL5, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x, %P3x, %P4x)", }, {"", "call6", OP_CALL6, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x, %P3x, %P4x, %P5x)", }, {"", "call7", OP_CALL7, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x, %P3x, %P4x, %P5x, %P6x)", }, {"", "call8", OP_CALL8, false, - ev_func, ev_void, ev_void, + ev_func, ev_invalid, ev_invalid, PROG_ID_VERSION, "%Fa (%P0x, %P1x, %P2x, %P3x, %P4x, %P5x, %P6x, %P7x)", }, {"", "rcall1", OP_RCALL1, false, - ev_func, ev_void, ev_void, + ev_func, ev_void, ev_invalid, PROG_VERSION, "%Fa (%P0b)", }, @@ -872,7 +810,7 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"", "state", OP_STATE, false, - ev_float, ev_func, ev_void, + ev_float, ev_func, ev_invalid, PROG_ID_VERSION, "%Ga, %Gb", }, @@ -884,19 +822,19 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"", "goto", OP_GOTO, false, - ev_integer, ev_void, ev_void, + ev_short, ev_invalid, ev_invalid, PROG_ID_VERSION, "branch %sa (%Oa)", }, {"", "jump", OP_JUMP, false, - ev_integer, ev_void, ev_void, + ev_integer, ev_invalid, ev_invalid, PROG_VERSION, "%Ga", }, {"", "jumpb", OP_JUMPB, false, - ev_pointer, ev_integer, ev_void, + ev_pointer, ev_integer, ev_invalid, PROG_VERSION, - "%Ga, %Gb", + "%Ga[%Gb]", }, {"&&", "and.f", OP_AND, false, @@ -925,11 +863,11 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, {"<<", "shl.u", OP_SHL_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, {">>", "shr.u", OP_SHR_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, @@ -971,35 +909,6 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, - {"+", "add.u", OP_ADD_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"-", "sub.u", OP_SUB_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"*", "mul.u", OP_MUL_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"/", "div.u", OP_DIV_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"%", "mod_u", OP_MOD_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"&", "bitand.u", OP_BITAND_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"|", "bitor.u", OP_BITOR_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"%", "mod.f", OP_MOD_F, false, ev_float, ev_float, ev_float, PROG_VERSION, @@ -1031,7 +940,7 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, {"!", "not.i", OP_NOT_I, false, - ev_integer, ev_void, ev_integer, + ev_integer, ev_invalid, ev_integer, PROG_VERSION, "%Ga, %gc", }, @@ -1044,42 +953,20 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, - {"&&", "and.u", OP_AND_U, false, - ev_uinteger, ev_uinteger, ev_integer, - PROG_VERSION, - }, - {"||", "or.u", OP_OR_U, false, - ev_uinteger, ev_uinteger, ev_integer, - PROG_VERSION, - }, - {"!", "not.u", OP_NOT_U, false, - ev_uinteger, ev_void, ev_integer, - PROG_VERSION, - "%Ga, %gc", - }, - {"==", "eq.u", OP_EQ_U, false, - ev_uinteger, ev_uinteger, ev_integer, - PROG_VERSION, - }, - {"!=", "ne.u", OP_NE_U, false, - ev_uinteger, ev_uinteger, ev_integer, - PROG_VERSION, - }, - {">=", "ge.u", OP_GE_U, false, - ev_uinteger, ev_uinteger, ev_integer, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, {"<=", "le.u", OP_LE_U, false, - ev_uinteger, ev_uinteger, ev_integer, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, {">", "gt.u", OP_GT_U, false, - ev_uinteger, ev_uinteger, ev_integer, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, {"<", "lt.u", OP_LT_U, false, - ev_uinteger, ev_uinteger, ev_integer, + ev_integer, ev_integer, ev_integer, PROG_VERSION, }, @@ -1088,7 +975,7 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, {"~", "bitnot.f", OP_BITNOT_F, false, - ev_float, ev_void, ev_float, + ev_float, ev_invalid, ev_float, PROG_VERSION, "%Ga, %gc", }, @@ -1097,16 +984,7 @@ VISIBLE opcode_t pr_opcodes[] = { PROG_VERSION, }, {"~", "bitnot.i", OP_BITNOT_I, false, - ev_integer, ev_void, ev_integer, - PROG_VERSION, - "%Ga, %gc", - }, - {"^", "bitxor.u", OP_BITXOR_U, false, - ev_uinteger, ev_uinteger, ev_uinteger, - PROG_VERSION, - }, - {"~", "bitnot.u", OP_BITNOT_U, false, - ev_uinteger, ev_void, ev_uinteger, + ev_integer, ev_invalid, ev_integer, PROG_VERSION, "%Ga, %gc", }, @@ -1137,7 +1015,7 @@ VISIBLE opcode_t pr_opcodes[] = { }, {"", "move", OP_MOVE, true, - ev_struct, ev_short, ev_struct, + ev_void, ev_short, ev_void, PROG_VERSION, "%Ga, %sb, %gc", }, @@ -1212,9 +1090,9 @@ check_global (progs_t *pr, dstatement_t *st, opcode_t *op, etype_t type, switch (type) { case ev_short: break; - case ev_void: + case ev_invalid: if (operand) { - msg = "non-zero global index in void operand"; + msg = "non-zero global index in invalid operand"; goto error; } break; diff --git a/nq/source/sv_progs.c b/nq/source/sv_progs.c index 3646b7a6f..57f03b56b 100644 --- a/nq/source/sv_progs.c +++ b/nq/source/sv_progs.c @@ -356,6 +356,7 @@ set_address (sv_def_t *def, void *address) switch (def->type) { case ev_void: case ev_short: + case ev_invalid: case ev_type_count: break; case ev_float: @@ -369,12 +370,6 @@ set_address (sv_def_t *def, void *address) case ev_func: case ev_pointer: case ev_integer: - case ev_uinteger: - case ev_object: - case ev_class: - case ev_sel: - case ev_array: - case ev_struct: *(int **)def->field = (int *) address; break; } diff --git a/qw/source/sv_progs.c b/qw/source/sv_progs.c index bf3d34995..efbbdadd6 100644 --- a/qw/source/sv_progs.c +++ b/qw/source/sv_progs.c @@ -357,6 +357,7 @@ set_address (sv_def_t *def, void *address) switch (def->type) { case ev_void: case ev_short: + case ev_invalid: case ev_type_count: break; case ev_float: @@ -370,12 +371,6 @@ set_address (sv_def_t *def, void *address) case ev_func: case ev_pointer: case ev_integer: - case ev_uinteger: - case ev_object: - case ev_class: - case ev_sel: - case ev_array: - case ev_struct: *(int **)def->field = (int *) address; break; } diff --git a/ruamoko/cl_menu/CrosshairView.h b/ruamoko/cl_menu/CrosshairView.h index e95861fa6..c4e0487db 100644 --- a/ruamoko/cl_menu/CrosshairView.h +++ b/ruamoko/cl_menu/CrosshairView.h @@ -6,9 +6,9 @@ @interface CrosshairView : View { - CrosshairCvar crosshair; + CrosshairCvar []crosshair; } --(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair; +-(id)initWithBounds:(Rect)aRect :(CrosshairCvar[])_crosshair; -(void) next; @end diff --git a/ruamoko/cl_menu/CrosshairView.r b/ruamoko/cl_menu/CrosshairView.r index c5e9c0a1e..6d7205aa1 100644 --- a/ruamoko/cl_menu/CrosshairView.r +++ b/ruamoko/cl_menu/CrosshairView.r @@ -6,10 +6,10 @@ @implementation CrosshairView { - CrosshairCvar crosshair; + CrosshairCvar []crosshair; } --(id)initWithBounds:(Rect)aRect :(CrosshairCvar)_crosshair +-(id)initWithBounds:(Rect)aRect :(CrosshairCvar[])_crosshair { self = [self initWithBounds:aRect]; crosshair = _crosshair; diff --git a/ruamoko/cl_menu/CvarColorView.h b/ruamoko/cl_menu/CvarColorView.h index 38c5124b2..ade2b30c2 100644 --- a/ruamoko/cl_menu/CvarColorView.h +++ b/ruamoko/cl_menu/CvarColorView.h @@ -7,9 +7,9 @@ @interface CvarColorView : View { - CvarColor color; + CvarColor []color; } --(id)initWithBounds:(Rect)aRect :(CvarColor)_color; +-(id)initWithBounds:(Rect)aRect :(CvarColor [])_color; -(void)next; -(void)prev; @end diff --git a/ruamoko/cl_menu/CvarColorView.r b/ruamoko/cl_menu/CvarColorView.r index 8a6f16ca9..88aed2012 100644 --- a/ruamoko/cl_menu/CvarColorView.r +++ b/ruamoko/cl_menu/CvarColorView.r @@ -6,7 +6,7 @@ #include "CvarColor.h" @implementation CvarColorView --(id)initWithBounds:(Rect)aRect :(CvarColor)_color +-(id)initWithBounds:(Rect)aRect :(CvarColor [])_color { self = [self initWithBounds:aRect]; color = _color; diff --git a/ruamoko/cl_menu/CvarRangeView.h b/ruamoko/cl_menu/CvarRangeView.h index 5223d529e..05fbbb73c 100644 --- a/ruamoko/cl_menu/CvarRangeView.h +++ b/ruamoko/cl_menu/CvarRangeView.h @@ -9,13 +9,13 @@ @interface CvarRangeView : Group { - Text title; - Text value; - Slider slider; - CvarRange range; + Text []title; + Text []value; + Slider []slider; + CvarRange []range; } -(void)update; --(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range; +-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange [])_range; -(void)inc; -(void)dec; @end diff --git a/ruamoko/cl_menu/CvarRangeView.r b/ruamoko/cl_menu/CvarRangeView.r index 759bb1ed7..e149e74cd 100644 --- a/ruamoko/cl_menu/CvarRangeView.r +++ b/ruamoko/cl_menu/CvarRangeView.r @@ -15,7 +15,7 @@ [value setText:ftos ([range value])]; } --(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange)_range +-(id)initWithBounds:(Rect)aRect title:(string)_title sliderWidth:(integer)width :(CvarRange [])_range { local Rect rect; diff --git a/ruamoko/cl_menu/CvarToggleView.h b/ruamoko/cl_menu/CvarToggleView.h index 4a61537ae..6091819b7 100644 --- a/ruamoko/cl_menu/CvarToggleView.h +++ b/ruamoko/cl_menu/CvarToggleView.h @@ -8,12 +8,12 @@ @interface CvarToggleView : Group { - Text title; - Text value; - CvarToggle toggle; + Text []title; + Text []value; + CvarToggle []toggle; } -(void)update; --(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle; +-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle [])_toggle; -(void)toggle; @end diff --git a/ruamoko/cl_menu/CvarToggleView.r b/ruamoko/cl_menu/CvarToggleView.r index ff1d37e2d..4adc30546 100644 --- a/ruamoko/cl_menu/CvarToggleView.r +++ b/ruamoko/cl_menu/CvarToggleView.r @@ -13,7 +13,7 @@ [value setText:[toggle value] ? "On" : "Off"]; } --(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle)_toggle +-(id)initWithBounds:(Rect)aRect title:(string)_title :(CvarToggle [])_toggle { local Rect rect; diff --git a/ruamoko/cl_menu/Frame.h b/ruamoko/cl_menu/Frame.h index 497803811..83c759ddb 100644 --- a/ruamoko/cl_menu/Frame.h +++ b/ruamoko/cl_menu/Frame.h @@ -3,7 +3,7 @@ @interface Frame : Object { - QPic picture; + QPic []picture; float duration; } - (id) initWithFile: (string) file duration: (float) time; diff --git a/ruamoko/cl_menu/HUD.h b/ruamoko/cl_menu/HUD.h index 15d867778..f80055219 100644 --- a/ruamoko/cl_menu/HUD.h +++ b/ruamoko/cl_menu/HUD.h @@ -37,7 +37,7 @@ @interface HUDGraphic : HUDObject { - QPic picture; + QPic []picture; } - (id) initWithComponents: (integer)x :(integer)y :(string) _file; @@ -52,7 +52,7 @@ @interface HUDAnimation : HUDObject { - Array frames; + Array []frames; integer currentFrame; float nextFrameTime; BOOL looping; @@ -60,7 +60,7 @@ - (id) initWithComponents: (integer) x :(integer) y; - (void) dealloc; - (Size) size; -- (void) addFrame: (Frame) frame; +- (void) addFrame: (Frame []) frame; - (void) changeFrame; - (void) display; - (void) start; diff --git a/ruamoko/cl_menu/HUD.r b/ruamoko/cl_menu/HUD.r index bc90bcca4..0b7289ea7 100644 --- a/ruamoko/cl_menu/HUD.r +++ b/ruamoko/cl_menu/HUD.r @@ -147,13 +147,13 @@ integer HUDHandleClass; - (Size) size { - local Frame frame; + local Frame []frame; frame = [frames objectAtIndex: currentFrame]; return [frame size]; } -- (void) addFrame: (Frame) frame +- (void) addFrame: (Frame[]) frame { [frames addObject: frame]; } @@ -161,7 +161,7 @@ integer HUDHandleClass; - (void) changeFrame { while (time >= nextFrameTime) { - local Frame f; + local Frame []f; if (++currentFrame == [frames count]) { if (looping) currentFrame = 0; @@ -178,7 +178,7 @@ integer HUDHandleClass; - (void) display { - local Frame f; + local Frame []f; if (!visible) return; @@ -192,7 +192,7 @@ integer HUDHandleClass; - (void) start { - local Frame f; + local Frame []f; currentFrame = 0; f = [frames objectAtIndex: 0]; diff --git a/ruamoko/cl_menu/MenuGroup.r b/ruamoko/cl_menu/MenuGroup.r index 0d0a8b53d..e125155f2 100644 --- a/ruamoko/cl_menu/MenuGroup.r +++ b/ruamoko/cl_menu/MenuGroup.r @@ -57,10 +57,10 @@ - (void) draw { - local View cur; + local View []cur; [super draw]; - cur = (View) [views objectAtIndex:current]; + cur = [views objectAtIndex:current]; opt_cursor (cur.xabs - 8, cur.yabs); } @end diff --git a/ruamoko/cl_menu/ProxyView.h b/ruamoko/cl_menu/ProxyView.h index 13ccffe23..f19539868 100644 --- a/ruamoko/cl_menu/ProxyView.h +++ b/ruamoko/cl_menu/ProxyView.h @@ -5,10 +5,10 @@ @interface ProxyView : View { - View title; - View view; + View []title; + View []view; } --(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView; +-(id)initWithBounds:(Rect)aRect title:(View[])aTitle view:(View[])aView; @end #endif//__ProxyView_h diff --git a/ruamoko/cl_menu/ProxyView.r b/ruamoko/cl_menu/ProxyView.r index 93e680970..ae2ff52c0 100644 --- a/ruamoko/cl_menu/ProxyView.r +++ b/ruamoko/cl_menu/ProxyView.r @@ -2,7 +2,7 @@ @implementation ProxyView --(id)initWithBounds:(Rect)aRect title:(View)aTitle view:(View)aView +-(id)initWithBounds:(Rect)aRect title:(View [])aTitle view:(View [])aView { self = [super initWithBounds:aRect]; if (!self) @@ -24,7 +24,7 @@ [view draw]; } -- (void) setBasePosFromView: (View) aview +- (void) setBasePosFromView: (View []) aview { [super setBasePosFromView:aview]; [title setBasePosFromView:self]; diff --git a/ruamoko/cl_menu/client_menu.h b/ruamoko/cl_menu/client_menu.h index 813781bc0..88da600da 100644 --- a/ruamoko/cl_menu/client_menu.h +++ b/ruamoko/cl_menu/client_menu.h @@ -2,6 +2,6 @@ #define __client_menu_h @class InputLine; -@extern InputLine input_active; +@extern InputLine []input_active; #endif diff --git a/ruamoko/cl_menu/client_menu.qc b/ruamoko/cl_menu/client_menu.qc index 82fe69e73..392ce0982 100644 --- a/ruamoko/cl_menu/client_menu.qc +++ b/ruamoko/cl_menu/client_menu.qc @@ -123,10 +123,10 @@ integer save_cursor; string (QFile f) get_comment = { local string line; - local PLItem plist; + local PLItem []plist; plist = [PLItem fromFile:f]; - line = [(PLString) [(PLDictionary) plist getObjectForKey:"comment"] string]; + line = [(PLString[]) [(PLDictionary[]) plist getObjectForKey:"comment"] string]; return line; } @@ -368,9 +368,9 @@ string lanConfig_portname; string lanConfig_joinname; #define NUM_LANCONFIG_CMDS 3 integer [NUM_LANCONFIG_CMDS] lanConfig_cursor_table = { 72, 92, 124 }; -InputLine lanConfig_port_il; -InputLine lanConfig_join_il; -InputLine input_active; +InputLine []lanConfig_port_il; +InputLine []lanConfig_join_il; +InputLine []input_active; integer (integer x, integer y) join_draw = { diff --git a/ruamoko/cl_menu/controls_o.qc b/ruamoko/cl_menu/controls_o.qc index 96503795a..6a141849c 100644 --- a/ruamoko/cl_menu/controls_o.qc +++ b/ruamoko/cl_menu/controls_o.qc @@ -37,9 +37,9 @@ integer set_key_flag; // holds flag for the key-setting // three global hashes for the main binding groups -Array movement_bindings; -Array misc_bindings; -Array weapon_bindings; +Array []movement_bindings; +Array []misc_bindings; +Array []weapon_bindings; struct binding_s { string text; @@ -110,7 +110,7 @@ binding_t [10] weapon_binding_list = { {"Thunderbolt", "impulse 8"}, }; -Binding (binding_t binding) +Binding [](binding_t binding) new_binding = { return [[Binding alloc] initWithBinding:binding]; @@ -168,11 +168,11 @@ get_keyname = gets the keys for a keybinding-hash */ -void (Array list) +void (Array []list) get_hash_keys = { local integer i,hlen; - local Binding binding; + local Binding []binding; local string desc1 = "", desc2 = ""; hlen = [list count]; @@ -229,7 +229,7 @@ load_keybindings = It takes the binding as argument. This function is called by the real callbacks. */ -integer (Binding binding, integer key) +integer (Binding []binding, integer key) CB_MAIN_control_binding = { local integer retval = 0, bindcnt = 0; @@ -270,7 +270,7 @@ CB_MAIN_control_binding = integer (string text, integer key) CB_basic_control_binding = { - local Binding binding = [movement_bindings objectAtIndex: stoi (text)]; + local Binding []binding = [movement_bindings objectAtIndex: stoi (text)]; local integer ret = CB_MAIN_control_binding (binding, key); // fetch all keynames (possible to optimize.. but not very neccessary) @@ -307,7 +307,7 @@ DRAW_basic_control_binding = hl = [movement_bindings count]; for(i = 0; i < hl; i++) { - local Binding binding = [movement_bindings objectAtIndex: i]; + local Binding []binding = [movement_bindings objectAtIndex: i]; draw_val_item (x + 20, y + 40 + ( i * 10), bind_desc_pad, binding.text, binding.keys); } @@ -347,7 +347,7 @@ MENU_basic_control_binding = integer (string text, integer key) CB_misc_control_binding = { - local Binding binding = [misc_bindings objectAtIndex: stoi (text)]; + local Binding []binding = [misc_bindings objectAtIndex: stoi (text)]; local integer ret = CB_MAIN_control_binding (binding, key); // fetch all keynames (possible to optimize.. but not very neccessary) @@ -384,7 +384,7 @@ DRAW_misc_control_binding = hl = [misc_bindings count]; for(i=0;i < hl; i++) { - local Binding binding = [misc_bindings objectAtIndex: i]; + local Binding []binding = [misc_bindings objectAtIndex: i]; draw_val_item (x + 20, y + 40+(i*10), bind_desc_pad, binding.text, binding.keys); } @@ -423,7 +423,7 @@ MENU_misc_control_binding = integer (string text, integer key) CB_weapon_control_binding = { - local Binding binding = [weapon_bindings objectAtIndex: stoi (text)]; + local Binding []binding = [weapon_bindings objectAtIndex: stoi (text)]; local integer ret = CB_MAIN_control_binding (binding, key); // fetch all keynames (possible to optimize.. but not very neccessary) @@ -460,7 +460,7 @@ DRAW_weapon_control_binding = hl = [weapon_bindings count]; for(i = 0; i < hl; i++) { - local Binding binding = [weapon_bindings objectAtIndex: i]; + local Binding []binding = [weapon_bindings objectAtIndex: i]; draw_val_item (x + 20, y + 40 + (i * 10), bind_desc_pad, binding.text, binding.keys); } diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index 122b846f2..36f60f794 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -53,32 +53,32 @@ #include "CvarColor.h" #include "CvarToggle.h" -Group video_options; -Group audio_options; +Group []video_options; +Group []audio_options; -Group control_options; -CvarToggleView grab_mouse_view; -CvarToggleView invert_mouse_view; -CvarToggleView autorun_view; -CvarToggleView freelook_view; -CvarToggleView lookspring_view; -CvarToggleView lookstrafe_view; -CvarRangeView mouse_amp_view; +Group []control_options; +CvarToggleView []grab_mouse_view; +CvarToggleView []invert_mouse_view; +CvarToggleView []autorun_view; +CvarToggleView []freelook_view; +CvarToggleView []lookspring_view; +CvarToggleView []lookstrafe_view; +CvarRangeView []mouse_amp_view; -Group feature_options; -CvarToggleView fraglog_view; -CvarToggleView autorecord_view; +Group []feature_options; +CvarToggleView []fraglog_view; +CvarToggleView []autorecord_view; -Group player_options; -InputLine player_config_plname_il; -InputLine player_config_tname_il; -InputLine player_config_iactive; -CvarColorView topcolor_view; -CvarColorView bottomcolor_view; +Group []player_options; +InputLine []player_config_plname_il; +InputLine []player_config_tname_il; +InputLine []player_config_iactive; +CvarColorView []topcolor_view; +CvarColorView []bottomcolor_view; -Group network_options; -InputLine network_config_rate_il; -InputLine network_config_iactive; +Group []network_options; +InputLine []network_config_rate_il; +InputLine []network_config_iactive; /* some definitions of border values for different things @@ -133,7 +133,7 @@ KEY_video_options = Menu function for the video options menu. */ -void (PLItem plist) +void (PLItem []plist) MENU_video_options = { local @param ret; @@ -143,7 +143,7 @@ MENU_video_options = Menu_KeyEvent (KEY_video_options); if (plist) { - ret = object_from_plist ([(PLDictionary) plist getObjectForKey:"video_options"]); + ret = object_from_plist ([(PLDictionary[]) plist getObjectForKey:"video_options"]); video_options = ret.pointer_val; } @@ -180,7 +180,7 @@ KEY_audio_options = Makes the audio menu */ -void (PLItem plist) +void (PLItem []plist) MENU_audio_options = { local @param ret; @@ -190,7 +190,7 @@ MENU_audio_options = Menu_KeyEvent (KEY_audio_options); if (plist) { - ret = object_from_plist ([(PLDictionary) plist getObjectForKey:"audio_options"]); + ret = object_from_plist ([(PLDictionary[]) plist getObjectForKey:"audio_options"]); audio_options = ret.pointer_val; } @@ -264,7 +264,7 @@ KEY_control_options = Menu make function for control options */ -void (PLItem plist) +void (PLItem []plist) MENU_control_options = { local @param ret; @@ -274,7 +274,7 @@ MENU_control_options = Menu_KeyEvent (KEY_control_options); if (plist) { - ret = object_from_plist ([(PLDictionary) plist getObjectForKey:"control_options"]); + ret = object_from_plist ([(PLDictionary[]) plist getObjectForKey:"control_options"]); control_options = ret.pointer_val; } @@ -328,7 +328,7 @@ DRAW_feature_options = Makes the feature option menu */ -void (PLItem plist) +void (PLItem []plist) MENU_feature_options = { local Rect rect; @@ -512,7 +512,7 @@ CB_ME_player_options = Makes the player option menu */ -void (PLItem plist) +void (PLItem []plist) MENU_player_options = { local Rect rect; @@ -682,7 +682,7 @@ CB_ME_network_options = Makes the network option menu */ -void (PLItem plist) +void (PLItem []plist) MENU_network_options = { local id view; @@ -743,7 +743,7 @@ void () MENU_options = { local integer spacing = 120; - local PLItem plist; + local PLItem []plist; plist = read_plist ("menu.plist"); diff --git a/ruamoko/cl_menu/plistmenu.h b/ruamoko/cl_menu/plistmenu.h index 1ab134ca3..435b5fd35 100644 --- a/ruamoko/cl_menu/plistmenu.h +++ b/ruamoko/cl_menu/plistmenu.h @@ -3,7 +3,7 @@ #include "PropertyList.h" -@extern @param object_from_plist (PLItem plist); -@extern PLItem read_plist (string fname); +@extern @param object_from_plist (PLItem []plist); +@extern PLItem []read_plist (string fname); #endif//__plistmenu_r diff --git a/ruamoko/cl_menu/plistmenu.r b/ruamoko/cl_menu/plistmenu.r index abe98a005..a2b26f8a0 100644 --- a/ruamoko/cl_menu/plistmenu.r +++ b/ruamoko/cl_menu/plistmenu.r @@ -33,7 +33,7 @@ #include "plistmenu.h" @static @param -class_from_plist (PLDictionary pldict) +class_from_plist (PLDictionary []pldict) { local @param [8]params; local @param ret; @@ -41,12 +41,12 @@ class_from_plist (PLDictionary pldict) local string classname, selname, paramstr; local id class; local id obj; - local PLArray messages, msg; + local PLArray []messages, msg; local integer message_count, i, j; local SEL sel; - local PLItem item; + local PLItem []item; - classname = [(PLString) [pldict getObjectForKey:"Class"] string]; + classname = [(PLString[]) [pldict getObjectForKey:"Class"] string]; class = obj_lookup_class (classname); if (!class) { dprint ("could not find " + classname + "\n"); @@ -55,15 +55,15 @@ class_from_plist (PLDictionary pldict) } obj = [class alloc]; - messages = (PLArray) [pldict getObjectForKey:"Messages"]; + messages = (PLArray[]) [pldict getObjectForKey:"Messages"]; message_count = [messages count]; for (i = 0; i < message_count; i++) { - msg = (PLArray) [messages getObjectAtIndex:i]; - selname = [(PLString) [msg getObjectAtIndex:0] string]; + msg = (PLArray[]) [messages getObjectAtIndex:i]; + selname = [(PLString[]) [msg getObjectAtIndex:0] string]; sel = sel_get_uid (selname); va_list.count = [msg count] - 1; for (j = 0; j < va_list.count; j++) { - paramstr = [(PLString) [msg getObjectAtIndex:j + 1] string]; + paramstr = [(PLString[]) [msg getObjectAtIndex:j + 1] string]; switch (str_mid (paramstr, 0, 1)) { case "\"": va_list.list[j].string_val = str_mid (paramstr, 1, -1); @@ -88,9 +88,9 @@ class_from_plist (PLDictionary pldict) } @static @param -array_from_plist (PLArray plarray) +array_from_plist (PLArray []plarray) { - local Array array; + local Array []array; local integer i, count; local @param ret; @@ -110,29 +110,29 @@ union ParamRect { }; @static @param -rect_from_plist (PLString plstring) +rect_from_plist (PLString []plstring) { local string str = [plstring string]; local string tmp; local integer xp, yp, xl, yl; - local PLItem item; + local PLItem []item; local union ParamRect pr; pr.r = makeRect (0, 0, 0, 0); if (str_mid (str, 0, 1) == "[") { tmp = "(" + str_mid (str, 1, -1) + ")"; item = [PLItem fromString:tmp]; - xp = stoi ([(PLString) [(PLArray) item getObjectAtIndex:0] string]); - yp = stoi ([(PLString) [(PLArray) item getObjectAtIndex:1] string]); - xl = stoi ([(PLString) [(PLArray) item getObjectAtIndex:2] string]); - yl = stoi ([(PLString) [(PLArray) item getObjectAtIndex:3] string]); + xp = stoi ([(PLString[]) [(PLArray[]) item getObjectAtIndex:0] string]); + yp = stoi ([(PLString[]) [(PLArray[]) item getObjectAtIndex:1] string]); + xl = stoi ([(PLString[]) [(PLArray[]) item getObjectAtIndex:2] string]); + yl = stoi ([(PLString[]) [(PLArray[]) item getObjectAtIndex:3] string]); pr.r = makeRect (xp, yp, xl, yl); } return pr.p; } @static @param -string_from_plist (PLString plstring) +string_from_plist (PLString []plstring) { local @param ret; local string str = [plstring string]; @@ -145,28 +145,28 @@ string_from_plist (PLString plstring) } @param -object_from_plist (PLItem plist) +object_from_plist (PLItem []plist) { local @param ret; switch ([plist type]) { case QFDictionary: - return class_from_plist ((PLDictionary) plist); + return class_from_plist ((PLDictionary []) plist); case QFArray: - return array_from_plist ((PLArray) plist); + return array_from_plist ((PLArray []) plist); case QFBinary: ret.pointer_val = NIL; return ret; case QFString: - return string_from_plist ((PLString) plist); + return string_from_plist ((PLString []) plist); } } -PLItem +PLItem [] read_plist (string fname) { local QFile file; - local PLItem plist; + local PLItem []plist; file = QFS_OpenFile (fname); if (!file) { diff --git a/ruamoko/cl_menu/servlist.qc b/ruamoko/cl_menu/servlist.qc index 9e6f285b4..45b1c9b83 100644 --- a/ruamoko/cl_menu/servlist.qc +++ b/ruamoko/cl_menu/servlist.qc @@ -25,8 +25,8 @@ integer (integer x, integer y) servlist_all_draw = integer serv_nfull; integer serv_nempty; -InputLine serv_maxping; -InputLine serv_game; +InputLine []serv_maxping; +InputLine []serv_game; integer (integer x, integer y) servlist_filter_draw = { diff --git a/ruamoko/game/Axe.h b/ruamoko/game/Axe.h index 61d0231fe..e5fdd2504 100644 --- a/ruamoko/game/Axe.h +++ b/ruamoko/game/Axe.h @@ -7,7 +7,7 @@ @interface Axe: Object { - Entity owner; + Entity[] owner; float damage; } diff --git a/ruamoko/game/Axe.r b/ruamoko/game/Axe.r index b9098b827..da4523060 100644 --- a/ruamoko/game/Axe.r +++ b/ruamoko/game/Axe.r @@ -18,7 +18,7 @@ return self; } -- (void) setOwner: (Entity) o +- (void) setOwner: (Entity []) o { owner = o; } diff --git a/ruamoko/game/Weapon.h b/ruamoko/game/Weapon.h index 3ed7ecc30..b7b79d1e4 100644 --- a/ruamoko/game/Weapon.h +++ b/ruamoko/game/Weapon.h @@ -5,7 +5,7 @@ @protocol Weapon -- (void) setOwner: (Entity)o; +- (void) setOwner: (Entity [])o; - (void) fire; @end diff --git a/ruamoko/game/World.r b/ruamoko/game/World.r index 6d5bd0fc5..33d98b775 100644 --- a/ruamoko/game/World.r +++ b/ruamoko/game/World.r @@ -8,12 +8,12 @@ integer deathmatch; @interface BodyQueue: Object { - entity [MAX_BODIES] bodies; + entity[MAX_BODIES] bodies; integer head; } - (id) init; -- (void) addEntity: (GameEntity)ent; +- (void) addEntity: (GameEntity [])ent; @end @@ -27,7 +27,7 @@ integer deathmatch; head = NIL; for (i = 0; i < MAX_BODIES; i++) { - local GameEntity ent = NIL; + local GameEntity[] ent = NIL; ent = [[GameEntity alloc] init]; bodies[i] = ent.ent; } @@ -38,7 +38,7 @@ integer deathmatch; #endif } -- (void) addEntity: (GameEntity)ent +- (void) addEntity: (GameEntity[])ent { local entity be = bodies[head++]; local entity e = [ent ent]; @@ -63,7 +63,7 @@ integer deathmatch; } - (void) spawn: (entity)ent; -- (void) copyToBodyQueue: (GameEntity)ent; +- (void) copyToBodyQueue: (GameEntity [])ent; @end @@ -75,7 +75,7 @@ integer deathmatch; bodyque = [[BodyQueue alloc] init]; } -- (void) copyToBodyQueue: (GameEntity)ent +- (void) copyToBodyQueue: (GameEntity [])ent { [bodyque addEntity: ent]; } diff --git a/ruamoko/gui/Group.r b/ruamoko/gui/Group.r index cef3951bc..ee6887b5a 100644 --- a/ruamoko/gui/Group.r +++ b/ruamoko/gui/Group.r @@ -17,13 +17,13 @@ [super dealloc]; } -- (View) addView: (View)aView +- (View []) addView: (View [])aView { [views addObject:aView]; return aView; } -- (id) addViews: (Array)viewlist +- (id) addViews: (Array [])viewlist { while ([viewlist count]) { [self addView: [viewlist objectAtIndex: 0]]; @@ -44,7 +44,7 @@ [views makeObjectsPerformSelector:sel withObject:self]; } -- (void) setBasePosFromView: (View) view +- (void) setBasePosFromView: (View []) view { [super setBasePosFromView:view]; local SEL sel = @selector (setBasePosFromView:); diff --git a/ruamoko/gui/View.r b/ruamoko/gui/View.r index c713cccb8..ecf51e1e8 100644 --- a/ruamoko/gui/View.r +++ b/ruamoko/gui/View.r @@ -50,7 +50,7 @@ yabs = ypos + y; } -- (void) setBasePosFromView: (View) view +- (void) setBasePosFromView: (View []) view { Point pos = [view basePos]; xabs = xpos + pos.x; diff --git a/ruamoko/include/Array.h b/ruamoko/include/Array.h index e2c4110b5..d3b6d5e14 100644 --- a/ruamoko/include/Array.h +++ b/ruamoko/include/Array.h @@ -43,7 +43,7 @@ /** Returns a copy of \a array, retaining its contents. */ -+ (id) arrayWithArray: (Array)array; ++ (id) arrayWithArray: (Array [])array; /** Create an array containing only \a anObject . @@ -79,7 +79,7 @@ /** Initialize the receiver with objects from \a array. */ -- (id) initWithArray: (Array)array; +- (id) initWithArray: (Array [])array; /** Initialize the receiver with objects from \a array. @@ -87,7 +87,7 @@ \param array The array to duplicate \param flag if #YES, copies the contents instead of retaining them. */ -- (id) initWithArray: (Array)array +- (id) initWithArray: (Array [])array copyItems: (BOOL)flag; /** @@ -193,7 +193,7 @@ /** Adds each object in \a array to the receiver, retaining it. */ -- (void) addObjectsFromArray: (Array)array; +- (void) addObjectsFromArray: (Array [])array; /** Adds a single object to an array @@ -218,7 +218,7 @@ \note If \a array and self are the same object, this method has no effect. */ -- (void) setArray: (Array)array; +- (void) setArray: (Array [])array; //\} ///\name Removing Objects @@ -245,7 +245,7 @@ Finds and removes all objects from the receiver that are equal to any objects in array \a anArray. */ -- (void) removeObjectsInArray: (Array)anArray; +- (void) removeObjectsInArray: (Array [])anArray; /** Finds and removes all objects from the receiver that are \b exactly equal diff --git a/ruamoko/include/AutoreleasePool.h b/ruamoko/include/AutoreleasePool.h index 173284d5d..7adcd5c78 100644 --- a/ruamoko/include/AutoreleasePool.h +++ b/ruamoko/include/AutoreleasePool.h @@ -22,7 +22,7 @@ */ @interface AutoreleasePool: Object { - Array array; ///< a list of objects awaiting release + Array[] array; ///< a list of objects awaiting release } /** diff --git a/ruamoko/include/ListNode.h b/ruamoko/include/ListNode.h index fd3b90284..7c27e7d25 100644 --- a/ruamoko/include/ListNode.h +++ b/ruamoko/include/ListNode.h @@ -34,7 +34,7 @@ @interface ListNode: Object { - ListNode nextNode; + ListNode[] nextNode; id data; } diff --git a/ruamoko/include/Object.h b/ruamoko/include/Object.h index b7b2ed7cb..91414fc5d 100644 --- a/ruamoko/include/Object.h +++ b/ruamoko/include/Object.h @@ -25,7 +25,7 @@ withObject: (id)anObject withObject: (id)anotherObject; - (BOOL) respondsToSelector: (SEL)aSelector; -- (BOOL) conformsToProtocol: (Protocol)aProtocol; +- (BOOL) conformsToProtocol: (Protocol [])aProtocol; - (id) retain; - (id) autorelease; diff --git a/ruamoko/include/PropertyList.h b/ruamoko/include/PropertyList.h index c75d9b571..016371a6e 100644 --- a/ruamoko/include/PropertyList.h +++ b/ruamoko/include/PropertyList.h @@ -9,12 +9,12 @@ plitem_t item; integer own; } -+ (PLItem) newDictionary; -+ (PLItem) newArray; -+ (PLItem) newData:(void[]) data size:(integer) len; -+ (PLItem) newString:(string) str; -+ (PLItem) fromString:(string) str; -+ (PLItem) fromFile:(QFile) file; ++ (PLItem []) newDictionary; ++ (PLItem []) newArray; ++ (PLItem []) newData:(void[]) data size:(integer) len; ++ (PLItem []) newString:(string) str; ++ (PLItem []) fromString:(string) str; ++ (PLItem []) fromFile:(QFile) file; - initWithItem:(plitem_t) item; - initWithOwnItem:(plitem_t) item; @@ -23,31 +23,31 @@ @end @interface PLDictionary: PLItem -+ (PLDictionary) new; ++ (PLDictionary []) new; - (integer) count; - (integer) numKeys; -- (PLItem) getObjectForKey:(string) key; -- (PLItem) allKeys; -- addKey:(string) key value:(PLItem) value; +- (PLItem []) getObjectForKey:(string) key; +- (PLItem []) allKeys; +- addKey:(string) key value:(PLItem []) value; @end @interface PLArray: PLItem -+ (PLArray) new; ++ (PLArray []) new; - (integer) count; - (integer) numObjects; -- (PLItem) getObjectAtIndex:(integer) index; -- addObject:(PLItem) object; -- insertObject:(PLItem) object atIndex:(integer) index; +- (PLItem []) getObjectAtIndex:(integer) index; +- addObject:(PLItem []) object; +- insertObject:(PLItem []) object atIndex:(integer) index; @end @interface PLData: PLItem -+ (PLData) new:(void[]) data size:(integer) len; ++ (PLData []) new:(void[]) data size:(integer) len; @end @interface PLString: PLItem -+ (PLString) new:(string) str; ++ (PLString []) new:(string) str; - (string) string; @end diff --git a/ruamoko/include/Protocol.h b/ruamoko/include/Protocol.h index 8dbfb16d4..2b2eacfba 100644 --- a/ruamoko/include/Protocol.h +++ b/ruamoko/include/Protocol.h @@ -17,7 +17,7 @@ struct obj_method_description { } - (string) name; -- (BOOL) conformsTo: (Protocol)aProtocolObject; +- (BOOL) conformsTo: (Protocol [])aProtocolObject; - (struct obj_method_description []) descriptionForInstanceMethod: (SEL)aSel; - (struct obj_method_description []) descriptionForClassMethod: (SEL)aSel; @end diff --git a/ruamoko/include/gui/Group.h b/ruamoko/include/gui/Group.h index 9e41f8911..c193516ac 100644 --- a/ruamoko/include/gui/Group.h +++ b/ruamoko/include/gui/Group.h @@ -7,11 +7,11 @@ @interface Group : View { - Array views; + Array []views; } - (void) dealloc; -- (View) addView: (View)aView; -- (id) addViews: (Array)viewlist; +- (View[]) addView: (View[])aView; +- (id) addViews: (Array[])viewlist; - (void) moveTo: (integer)x y:(integer)y; - (void) draw; @end diff --git a/ruamoko/include/gui/InputLine.h b/ruamoko/include/gui/InputLine.h index 7cf4badcd..934443f40 100644 --- a/ruamoko/include/gui/InputLine.h +++ b/ruamoko/include/gui/InputLine.h @@ -44,7 +44,7 @@ struct il_data_t { @interface InputLineBox: View { - InputLine input_line; + InputLine []input_line; } - (id) initWithBounds: (Rect)aRect promptCharacter: (integer)char; diff --git a/ruamoko/include/gui/View.h b/ruamoko/include/gui/View.h index 7626eeac5..93eb7e2b6 100644 --- a/ruamoko/include/gui/View.h +++ b/ruamoko/include/gui/View.h @@ -10,7 +10,7 @@ integer xpos, ypos; integer xlen, ylen; integer xabs, yabs; - View parent; + View []parent; integer flags; } @@ -20,7 +20,7 @@ - (id) canFocus: (integer)cf; - (integer) canFocus; - (void) setBasePos: (integer)x y: (integer)y; -- (void) setBasePosFromView: (View)view; +- (void) setBasePosFromView: (View[])view; - (void) draw; - (integer) keyEvent:(integer)key unicode:(integer)unicode down:(integer)down; diff --git a/ruamoko/lib/Array.r b/ruamoko/lib/Array.r index 5d7c4d421..d1ca65d0d 100644 --- a/ruamoko/lib/Array.r +++ b/ruamoko/lib/Array.r @@ -26,14 +26,14 @@ return [[[self alloc] initWithCapacity: cap] autorelease]; } -+ (id) arrayWithArray: (Array)array ++ (id) arrayWithArray: (Array [])array { return [[array copy] autorelease]; } + (id) arrayWithObject: (id)anObject { - Array newArray = (Array)[self arrayWithCapacity: STANDARD_CAPACITY]; + Array [] newArray = (Array [])[self arrayWithCapacity: STANDARD_CAPACITY]; [newArray addObject: anObject]; return newArray; @@ -86,7 +86,7 @@ return self; } -- (id) initWithArray: (Array)array +- (id) initWithArray: (Array [])array { #if 0 local unsigned i; @@ -104,7 +104,7 @@ #endif } -- (id) initWithArray: (Array)array +- (id) initWithArray: (Array [])array copyItems: (BOOL)copy { local unsigned i; @@ -241,7 +241,7 @@ count++; } -- (void) addObjectsFromArray: (Array)array +- (void) addObjectsFromArray: (Array [])array { local unsigned i; @@ -299,7 +299,7 @@ [tmp release]; } -- (void) setArray: (Array)array +- (void) setArray: (Array [])array { if (self == array) return; @@ -381,7 +381,7 @@ } while (i); } -- (void) removeObjectsInArray: (Array)array +- (void) removeObjectsInArray: (Array [])array { local unsigned i = [array count]; diff --git a/ruamoko/lib/AutoreleasePool.r b/ruamoko/lib/AutoreleasePool.r index ad3b897ce..990e11f64 100644 --- a/ruamoko/lib/AutoreleasePool.r +++ b/ruamoko/lib/AutoreleasePool.r @@ -4,7 +4,7 @@ #include "Array.h" #include "Array+Private.h" -@static Array poolStack; +@static Array[] poolStack; @implementation AutoreleasePool diff --git a/ruamoko/lib/Entity.r b/ruamoko/lib/Entity.r index 4f728f723..e6fa485c6 100644 --- a/ruamoko/lib/Entity.r +++ b/ruamoko/lib/Entity.r @@ -67,7 +67,7 @@ function PR_FindFunction (string func) = #0; local string field, value; local plitem_t keys; local function func; - local Entity e; + local Entity [] e; classname = PL_String (PL_ObjectForKey (dict, "classname")); if (classname == "worldspawn") diff --git a/ruamoko/lib/Object.r b/ruamoko/lib/Object.r index 9281d7446..8d5fd216a 100644 --- a/ruamoko/lib/Object.r +++ b/ruamoko/lib/Object.r @@ -8,7 +8,7 @@ void (id object, integer code, string fmt, @va_list args) obj_verror = #0; IMP (id receiver, SEL op) obj_msg_lookup = #0; IMP (Super class, SEL op) obj_msg_lookup_super = #0; id (id receiver, SEL op, ...) obj_msgSend = #0; -id (Super class, SEL op, ...) obj_msgSend_super = #0; +id (Super[] class, SEL op, ...) obj_msgSend_super = #0; @param (id receiver, SEL op, @va_list args) obj_msg_sendv = #0; (void []) (integer size) obj_malloc = #0; (void []) (integer size) obj_atomic_malloc = #0; @@ -206,7 +206,7 @@ BOOL (id object) object_is_meta_class = #0; return (class_get_instance_method ([self class], aSelector) != NIL); } -- (BOOL) conformsToProtocol: (Protocol)aProtocol +- (BOOL) conformsToProtocol: (Protocol [])aProtocol { return [[self class] conformsToProtocol: aProtocol]; } diff --git a/ruamoko/lib/PropertyList.r b/ruamoko/lib/PropertyList.r index a3c2cafbb..f67722497 100644 --- a/ruamoko/lib/PropertyList.r +++ b/ruamoko/lib/PropertyList.r @@ -2,22 +2,22 @@ @implementation PLItem -+ (PLItem) newDictionary ++ (PLItem []) newDictionary { return [PLDictionary new]; } -+ (PLItem) newArray ++ (PLItem []) newArray { return [PLArray new]; } -+ (PLItem) newData:(void[]) data size:(integer) len ++ (PLItem []) newData:(void[]) data size:(integer) len { return [PLData new:data size:len]; } -+ (PLItem) newString:(string) str ++ (PLItem []) newString:(string) str { return [PLString new:str]; } @@ -49,12 +49,12 @@ return [[class alloc] initWithItem: item]; } -+ (PLItem) fromString:(string) str ++ (PLItem []) fromString:(string) str { return [[PLItem itemClass: PL_GetPropertyList (str)] autorelease]; } -+ (PLItem) fromFile:(QFile) file ++ (PLItem []) fromFile:(QFile) file { return [[PLItem itemClass: PL_GetFromFile (file)] autorelease]; } @@ -99,7 +99,7 @@ @implementation PLDictionary -+ (PLDictionary) new ++ (PLDictionary []) new { return [[PLDictionary alloc] initWithOwnItem: PL_NewDictionary ()]; } @@ -114,17 +114,17 @@ return PL_D_NumKeys (item); } -- (PLItem) getObjectForKey:(string) key +- (PLItem []) getObjectForKey:(string) key { return [[PLItem itemClass: PL_ObjectForKey (item, key)] autorelease]; } -- (PLItem) allKeys +- (PLItem []) allKeys { return [[PLItem itemClass: PL_D_AllKeys (item)] autorelease]; } -- addKey:(string) key value:(PLItem) value +- addKey:(string) key value:(PLItem []) value { if (!value.own) { obj_error (self, 0, "add of unowned key/value to PLDictionary"); @@ -140,7 +140,7 @@ @implementation PLArray -+ (PLArray) new ++ (PLArray []) new { return [[PLArray alloc] initWithOwnItem: PL_NewArray ()]; } @@ -155,12 +155,12 @@ return PL_A_NumObjects (item); } -- (PLItem) getObjectAtIndex:(integer) index +- (PLItem []) getObjectAtIndex:(integer) index { return [[PLItem itemClass: PL_ObjectAtIndex (item, index)] autorelease]; } -- addObject:(PLItem) object +- addObject:(PLItem []) object { if (!object.own) { obj_error (self, 0, "add of unowned object to PLArray"); @@ -172,7 +172,7 @@ return self; } -- insertObject:(PLItem) object atIndex:(integer) index +- insertObject:(PLItem []) object atIndex:(integer) index { if (!object.own) { obj_error (self, 0, "add of unowned object to PLArray"); @@ -188,7 +188,7 @@ @implementation PLData -+ (PLData) new:(void[]) data size:(integer) len ++ (PLData []) new:(void[]) data size:(integer) len { return [[PLData alloc] initWithOwnItem: PL_NewData (data, len)]; } @@ -197,7 +197,7 @@ @implementation PLString -+ (PLString) new: (string) str ++ (PLString []) new: (string) str { return [[PLString alloc] initWithOwnItem: PL_NewString (str)]; } diff --git a/ruamoko/lib/Protocol.r b/ruamoko/lib/Protocol.r index bd2b619d9..fefc11da9 100644 --- a/ruamoko/lib/Protocol.r +++ b/ruamoko/lib/Protocol.r @@ -17,7 +17,7 @@ struct obj_method_description_list { return protocol_name; } -- (BOOL) conformsTo: (Protocol)aProtocolObject +- (BOOL) conformsTo: (Protocol [])aProtocolObject { local integer i; local struct obj_protocol_list [] proto_list; diff --git a/ruamoko/scheme/BaseContinuation.r b/ruamoko/scheme/BaseContinuation.r index 7dddd4817..a12cbb290 100644 --- a/ruamoko/scheme/BaseContinuation.r +++ b/ruamoko/scheme/BaseContinuation.r @@ -2,7 +2,7 @@ #include "Cons.h" instruction_t returninst; -BaseContinuation base; +BaseContinuation []base; @implementation BaseContinuation + (void) initialize @@ -15,14 +15,14 @@ BaseContinuation base; return base; } -- (void) restoreOnMachine: (Machine) m +- (void) restoreOnMachine: (Machine []) m { [m state].program = &returninst; } -- (void) invokeOnMachine: (Machine) m +- (void) invokeOnMachine: (Machine []) m { - [m value: [(Cons) [m stack] car]]; + [m value: [(Cons []) [m stack] car]]; [m state].program = &returninst; } diff --git a/ruamoko/scheme/Boolean.r b/ruamoko/scheme/Boolean.r index 559c29294..7c178643c 100644 --- a/ruamoko/scheme/Boolean.r +++ b/ruamoko/scheme/Boolean.r @@ -1,7 +1,7 @@ #include "Boolean.h" -Boolean trueConstant; -Boolean falseConstant; +Boolean []trueConstant; +Boolean []falseConstant; @implementation Boolean diff --git a/ruamoko/scheme/CompiledCode.h b/ruamoko/scheme/CompiledCode.h index 1a08acd23..91933af0e 100644 --- a/ruamoko/scheme/CompiledCode.h +++ b/ruamoko/scheme/CompiledCode.h @@ -8,26 +8,26 @@ struct lineinfo_s { integer linenumber; - String sourcefile; + String []sourcefile; }; typedef struct lineinfo_s lineinfo_t; @interface CompiledCode: SchemeObject { - Frame literals; - Array instructions; - Array constants; + Frame []literals; + Array []instructions; + Array []constants; instruction_t [] code; lineinfo_t [] lineinfo; integer minargs, size; } -- (void) addInstruction: (Instruction) inst; -- (integer) addConstant: (SchemeObject) c; +- (void) addInstruction: (Instruction []) inst; +- (integer) addConstant: (SchemeObject []) c; - (void) compile; - (instruction_t []) code; - (lineinfo_t []) lineinfo; -- (Frame) literals; +- (Frame []) literals; - (integer) minimumArguments; - (void) minimumArguments: (integer) min; diff --git a/ruamoko/scheme/CompiledCode.r b/ruamoko/scheme/CompiledCode.r index 0201698a2..0dffee772 100644 --- a/ruamoko/scheme/CompiledCode.r +++ b/ruamoko/scheme/CompiledCode.r @@ -22,7 +22,7 @@ [instructions makeObjectsPerformSelector: @selector(mark)]; } -- (void) addInstruction: (Instruction) inst +- (void) addInstruction: (Instruction []) inst { [inst line: [self line]]; [inst source: [self source]]; @@ -32,7 +32,7 @@ } } -- (integer) addConstant: (SchemeObject) c +- (integer) addConstant: (SchemeObject []) c { local integer number = [constants count]; [constants addObject: c]; @@ -42,12 +42,12 @@ - (void) compile { local integer index; - local Instruction inst; + local Instruction []inst; literals = [Frame newWithSize: [constants count] link: NIL]; code = obj_malloc (@sizeof(instruction_t) * [instructions count]); lineinfo = obj_malloc(@sizeof(lineinfo_t) * [instructions count]); for (index = 0; index < [constants count]; index++) { - [literals set: index to: (SchemeObject) [constants objectAtIndex: index]]; + [literals set: index to: (SchemeObject[]) [constants objectAtIndex: index]]; } for (index = 0; index < [instructions count]; index++) { inst = [instructions objectAtIndex: index]; @@ -72,14 +72,14 @@ return lineinfo; } -- (Frame) literals +- (Frame[]) literals { return literals; } - (void) dealloc { - local Array temp; + local Array []temp; if (instructions) { temp = instructions; diff --git a/ruamoko/scheme/Compiler.h b/ruamoko/scheme/Compiler.h index 14d6f9098..f95847289 100644 --- a/ruamoko/scheme/Compiler.h +++ b/ruamoko/scheme/Compiler.h @@ -10,20 +10,20 @@ @interface Compiler: SchemeObject { - CompiledCode code; - SchemeObject sexpr; - Scope scope; - Error err; + CompiledCode []code; + SchemeObject []sexpr; + Scope []scope; + Error []err; } -+ (id) newWithLambda: (SchemeObject) xp scope: (Scope) sc; -- (id) initWithLambda: (SchemeObject) xp scope: (Scope) sc; -- (SchemeObject) compile; ++ (id) newWithLambda: (SchemeObject []) xp scope: (Scope []) sc; +- (id) initWithLambda: (SchemeObject []) xp scope: (Scope []) sc; +- (SchemeObject[]) compile; -- (void) emitExpression: (SchemeObject) expression flags: (integer) fl; -- (void) emitLambda: (SchemeObject) expression; -- (void) emitConstant: (SchemeObject) expression; -- (void) emitApply: (SchemeObject) expression flags: (integer) fl; +- (void) emitExpression: (SchemeObject []) expression flags: (integer) fl; +- (void) emitLambda: (SchemeObject []) expression; +- (void) emitConstant: (SchemeObject []) expression; +- (void) emitApply: (SchemeObject []) expression flags: (integer) fl; @end #endif //__Compiler_h diff --git a/ruamoko/scheme/Compiler.r b/ruamoko/scheme/Compiler.r index 616f46c33..43216e267 100644 --- a/ruamoko/scheme/Compiler.r +++ b/ruamoko/scheme/Compiler.r @@ -6,12 +6,12 @@ #include "Cons.h" #include "defs.h" -Symbol lambdaSym; -Symbol quoteSym; -Symbol defineSym; -Symbol ifSym; -Symbol letrecSym; -Symbol beginSym; +Symbol []lambdaSym; +Symbol []quoteSym; +Symbol []defineSym; +Symbol []ifSym; +Symbol []letrecSym; +Symbol []beginSym; @implementation Compiler + (void) initialize @@ -30,12 +30,12 @@ Symbol beginSym; [beginSym retain]; } -+ (id) newWithLambda: (SchemeObject) xp scope: (Scope) sc ++ (id) newWithLambda: (SchemeObject[]) xp scope: (Scope[]) sc { return [[self alloc] initWithLambda: xp scope: sc]; } -- (id) initWithLambda: (SchemeObject) xp scope: (Scope) sc +- (id) initWithLambda: (SchemeObject[]) xp scope: (Scope[]) sc { self = [super init]; sexpr = xp; @@ -45,14 +45,14 @@ Symbol beginSym; return self; } -- (void) emitBuildEnvironment: (SchemeObject) arguments +- (void) emitBuildEnvironment: (SchemeObject []) arguments { local integer count, index; - local SchemeObject cur; + local SchemeObject []cur; scope = [Scope newWithOuter: scope]; count = 0; - for (cur = arguments; [cur isKindOfClass: [Cons class]]; cur = [(Cons) cur cdr]) { + for (cur = arguments; [cur isKindOfClass: [Cons class]]; cur = [(Cons[]) cur cdr]) { count++; } [code minimumArguments: count]; @@ -62,12 +62,12 @@ Symbol beginSym; [code addInstruction: [Instruction opcode: MAKEENV operand: count]]; [code addInstruction: [Instruction opcode: LOADENV]]; cur = arguments; - for (index = 0; index < count; cur = [(Cons) cur cdr]) { + for (index = 0; index < count; cur = [(Cons[]) cur cdr]) { if ([cur isKindOfClass: [Cons class]]) { - [scope addName: (Symbol) [(Cons) cur car]]; + [scope addName: (Symbol[]) [(Cons[]) cur car]]; [code addInstruction: [Instruction opcode: SET operand: index]]; } else if ([cur isKindOfClass: [Symbol class]]) { - [scope addName: (Symbol) cur]; + [scope addName: (Symbol[]) cur]; [code addInstruction: [Instruction opcode: SETREST operand: index]]; break; @@ -81,21 +81,21 @@ Symbol beginSym; } } -- (void) emitSequence: (SchemeObject) expressions flags: (integer) fl +- (void) emitSequence: (SchemeObject[]) expressions flags: (integer) fl { - local SchemeObject cur; + local SchemeObject []cur; - for (cur = expressions; cur != [Nil nil]; cur = [(Cons) cur cdr]) { - if ([(Cons) cur cdr] == [Nil nil] && (fl & TAIL)) { - [self emitExpression: [(Cons) cur car] flags: fl]; + for (cur = expressions; cur != [Nil nil]; cur = [(Cons[]) cur cdr]) { + if ([(Cons[]) cur cdr] == [Nil nil] && (fl & TAIL)) { + [self emitExpression: [(Cons[]) cur car] flags: fl]; } else { - [self emitExpression: [(Cons) cur car] flags: fl & ~TAIL]; + [self emitExpression: [(Cons[]) cur car] flags: fl & ~TAIL]; } if (err) return; } } -- (void) emitVariable: (Symbol) sym +- (void) emitVariable: (Symbol[]) sym { local integer depth = [scope depthOf: sym]; local integer index = [scope indexOf: sym]; @@ -114,27 +114,27 @@ Symbol beginSym; } } -- (void) emitDefine: (SchemeObject) expression +- (void) emitDefine: (SchemeObject[]) expression { local integer index = 0; if (![expression isKindOfClass: [Cons class]] || - ![[(Cons) expression cdr] isKindOfClass: [Cons class]]) { + ![[(Cons[]) expression cdr] isKindOfClass: [Cons class]]) { err = [Error type: "syntax" message: "Malformed define statement" by: expression]; return; } - if ([[(Cons) expression car] isKindOfClass: [Cons class]]) { - index = [code addConstant: [(Cons) [(Cons) expression car] car]]; + if ([[(Cons[]) expression car] isKindOfClass: [Cons class]]) { + index = [code addConstant: [(Cons[]) [(Cons[]) expression car] car]]; [self emitLambda: cons(lambdaSym, - cons([(Cons) [(Cons) expression car] cdr], - [(Cons) expression cdr]))]; + cons([(Cons[]) [(Cons[]) expression car] cdr], + [(Cons[]) expression cdr]))]; if (err) return; - } else if ([[(Cons) expression car] isKindOfClass: [Symbol class]]) { - index = [code addConstant: [(Cons) expression car]]; - [self emitExpression: [(Cons) [(Cons) expression cdr] car] flags: 0]; + } else if ([[(Cons[]) expression car] isKindOfClass: [Symbol class]]) { + index = [code addConstant: [(Cons[]) expression car]]; + [self emitExpression: [(Cons[]) [(Cons[]) expression cdr] car] flags: 0]; if (err) return; } else { err = [Error type: "syntax" @@ -148,12 +148,12 @@ Symbol beginSym; [code addInstruction: [Instruction opcode: SETGLOBAL]]; } -- (void) emitIf: (SchemeObject) expression flags: (integer) fl +- (void) emitIf: (SchemeObject[]) expression flags: (integer) fl { - local Instruction falseLabel, endLabel; + local Instruction []falseLabel, endLabel; local integer index; if (![expression isKindOfClass: [Cons class]] || - ![[(Cons) expression cdr] isKindOfClass: [Cons class]]) { + ![[(Cons[]) expression cdr] isKindOfClass: [Cons class]]) { err = [Error type: "syntax" message: "Malformed if expression" by: expression]; @@ -162,19 +162,19 @@ Symbol beginSym; falseLabel = [Instruction opcode: LABEL]; endLabel = [Instruction opcode: LABEL]; - [self emitExpression: [(Cons) expression car] flags: fl & ~TAIL]; + [self emitExpression: [(Cons[]) expression car] flags: fl & ~TAIL]; if (err) return; [code addInstruction: [Instruction opcode: IFFALSE label: falseLabel]]; - [self emitExpression: [(Cons) [(Cons) expression cdr] car] flags: fl]; + [self emitExpression: [(Cons[]) [(Cons[]) expression cdr] car] flags: fl]; if (err) return; [code addInstruction: [Instruction opcode: GOTO label: endLabel]]; [code addInstruction: falseLabel]; - if ([(Cons) [(Cons) expression cdr] cdr] == [Nil nil]) { + if ([(Cons[]) [(Cons[]) expression cdr] cdr] == [Nil nil]) { index = [code addConstant: [Void voidConstant]]; [code addInstruction: [Instruction opcode: LOADLITS]]; [code addInstruction: [Instruction opcode: GET operand: index]]; } else { - [self emitExpression: [(Cons) [(Cons) [(Cons) expression cdr] cdr] car] flags: fl]; + [self emitExpression: [(Cons[]) [(Cons[]) [(Cons[]) expression cdr] cdr] car] flags: fl]; if (err) return; } [code addInstruction: endLabel]; @@ -184,14 +184,14 @@ Symbol beginSym; -- (void) emitLetrec: (SchemeObject) expression flags: (integer) fl +- (void) emitLetrec: (SchemeObject[]) expression flags: (integer) fl { - local SchemeObject bindings; + local SchemeObject []bindings; local integer count; if (!isList(expression) || - !isList([(Cons) expression car]) || - ![[(Cons) expression cdr] isKindOfClass: [Cons class]]) { + !isList([(Cons[]) expression car]) || + ![[(Cons[]) expression cdr] isKindOfClass: [Cons class]]) { err = [Error type: "syntax" message: "Malformed letrec expression" by: expression]; @@ -201,8 +201,8 @@ Symbol beginSym; count = 0; - for (bindings = [(Cons) expression car]; bindings != [Nil nil]; bindings = [(Cons) bindings cdr]) { - [scope addName: (Symbol) [(Cons) [(Cons) bindings car] car]]; + for (bindings = [(Cons[]) expression car]; bindings != [Nil nil]; bindings = [(Cons[]) bindings cdr]) { + [scope addName: (Symbol[]) [(Cons[]) [(Cons[]) bindings car] car]]; count++; } @@ -210,84 +210,84 @@ Symbol beginSym; count = 0; - for (bindings = [(Cons) expression car]; bindings != [Nil nil]; bindings = [(Cons) bindings cdr]) { - [self emitSequence: [(Cons) [(Cons) bindings car] cdr] flags: fl & ~TAIL]; + for (bindings = [(Cons[]) expression car]; bindings != [Nil nil]; bindings = [(Cons[]) bindings cdr]) { + [self emitSequence: [(Cons[]) [(Cons[]) bindings car] cdr] flags: fl & ~TAIL]; [code addInstruction: [Instruction opcode: PUSH]]; [code addInstruction: [Instruction opcode: LOADENV]]; [code addInstruction: [Instruction opcode: SET operand: count]]; count++; } - [self emitSequence: [(Cons) expression cdr] flags: fl]; + [self emitSequence: [(Cons[]) expression cdr] flags: fl]; [code addInstruction: [Instruction opcode: POPENV]]; scope = [scope outer]; } -- (void) emitExpression: (SchemeObject) expression flags: (integer) fl +- (void) emitExpression: (SchemeObject[]) expression flags: (integer) fl { if ([expression isKindOfClass: [Cons class]]) { [code source: [expression source]]; [code line: [expression line]]; - if ([(Cons) expression car] == lambdaSym) { + if ([(Cons[]) expression car] == lambdaSym) { [self emitLambda: expression]; - } else if ([(Cons) expression car] == quoteSym) { - [self emitConstant: [(Cons) [(Cons) expression cdr] car]]; - } else if ([(Cons) expression car] == defineSym) { - [self emitDefine: [(Cons) expression cdr]]; - } else if ([(Cons) expression car] == ifSym) { - [self emitIf: [(Cons) expression cdr] flags: fl]; - } else if ([(Cons) expression car] == letrecSym) { - [self emitLetrec: [(Cons) expression cdr] flags: fl]; - } else if ([(Cons) expression car] == beginSym) { - [self emitSequence: [(Cons) expression cdr] flags: fl]; + } else if ([(Cons[]) expression car] == quoteSym) { + [self emitConstant: [(Cons[]) [(Cons[]) expression cdr] car]]; + } else if ([(Cons[]) expression car] == defineSym) { + [self emitDefine: [(Cons[]) expression cdr]]; + } else if ([(Cons[]) expression car] == ifSym) { + [self emitIf: [(Cons[]) expression cdr] flags: fl]; + } else if ([(Cons[]) expression car] == letrecSym) { + [self emitLetrec: [(Cons[]) expression cdr] flags: fl]; + } else if ([(Cons[]) expression car] == beginSym) { + [self emitSequence: [(Cons[]) expression cdr] flags: fl]; } else { [self emitApply: expression flags: fl]; } } else if ([expression isKindOfClass: [Symbol class]]) { - [self emitVariable: (Symbol) expression]; + [self emitVariable: (Symbol[]) expression]; } else { [self emitConstant: expression]; } } -- (void) emitArguments: (SchemeObject) expression +- (void) emitArguments: (SchemeObject[]) expression { if (expression == [Nil nil]) { return; } else { - [self emitArguments: [(Cons) expression cdr]]; + [self emitArguments: [(Cons[]) expression cdr]]; if (err) return; - [self emitExpression: [(Cons) expression car] flags: 0]; + [self emitExpression: [(Cons[]) expression car] flags: 0]; if (err) return; [code addInstruction: [Instruction opcode: PUSH]]; } } -- (void) emitApply: (SchemeObject) expression flags: (integer) fl +- (void) emitApply: (SchemeObject[]) expression flags: (integer) fl { - local Instruction label = [Instruction opcode: LABEL]; + local Instruction []label = [Instruction opcode: LABEL]; if (!(fl & TAIL)) { [code addInstruction: [Instruction opcode: MAKECONT label: label]]; } - [self emitArguments: [(Cons) expression cdr]]; + [self emitArguments: [(Cons[]) expression cdr]]; if (err) return; - [self emitExpression: [(Cons) expression car] flags: fl & ~TAIL]; + [self emitExpression: [(Cons[]) expression car] flags: fl & ~TAIL]; if (err) return; [code addInstruction: [Instruction opcode: CALL]]; [code addInstruction: label]; } -- (void) emitLambda: (SchemeObject) expression +- (void) emitLambda: (SchemeObject[]) expression { - local Compiler compiler = [Compiler newWithLambda: expression + local Compiler []compiler = [Compiler newWithLambda: expression scope: scope]; - local SchemeObject res; + local SchemeObject []res; local integer index; res = [compiler compile]; if ([res isError]) { - err = (Error) res; + err = (Error []) res; return; } index = [code addConstant: res]; @@ -296,7 +296,7 @@ Symbol beginSym; [code addInstruction: [Instruction opcode: MAKECLOSURE]]; } -- (void) emitConstant: (SchemeObject) expression +- (void) emitConstant: (SchemeObject[]) expression { local integer index; index = [code addConstant: expression]; @@ -304,29 +304,29 @@ Symbol beginSym; [code addInstruction: [Instruction opcode: GET operand: index]]; } -- (void) checkLambdaSyntax: (SchemeObject) expression +- (void) checkLambdaSyntax: (SchemeObject[]) expression { if (![expression isKindOfClass: [Cons class]] || - [(Cons) expression car] != lambdaSym || - [(Cons) expression cdr] == [Nil nil] || - [(Cons) [(Cons) expression cdr] cdr] == [Nil nil]) { + [(Cons[]) expression car] != lambdaSym || + [(Cons[]) expression cdr] == [Nil nil] || + [(Cons[]) [(Cons[]) expression cdr] cdr] == [Nil nil]) { err = [Error type: "syntax" message: "malformed lambda expression" by: expression]; } } -- (SchemeObject) compile +- (SchemeObject[]) compile { [self checkLambdaSyntax: sexpr]; if (err) { return err; } - [self emitBuildEnvironment: [(Cons) [(Cons) sexpr cdr] car]]; + [self emitBuildEnvironment: [(Cons[]) [(Cons[]) sexpr cdr] car]]; if (err) { return err; } - [self emitSequence: [(Cons) [(Cons) sexpr cdr] cdr] flags: TAIL]; + [self emitSequence: [(Cons[]) [(Cons[]) sexpr cdr] cdr] flags: TAIL]; if (err) { return err; } diff --git a/ruamoko/scheme/Cons.h b/ruamoko/scheme/Cons.h index e1ea9eacc..7a3d5069b 100644 --- a/ruamoko/scheme/Cons.h +++ b/ruamoko/scheme/Cons.h @@ -4,18 +4,18 @@ @interface Cons: SchemeObject { - SchemeObject car, cdr; + SchemeObject []car, cdr; } -+ (id) newWithCar: (SchemeObject) a cdr: (SchemeObject) d; -- (id) initWithCar: (SchemeObject) a cdr: (SchemeObject) d; -- (SchemeObject) car; -- (void) car: (SchemeObject) a; -- (SchemeObject) cdr; -- (void) cdr: (SchemeObject) d; ++ (id) newWithCar: (SchemeObject []) a cdr: (SchemeObject []) d; +- (id) initWithCar: (SchemeObject []) a cdr: (SchemeObject []) d; +- (SchemeObject []) car; +- (void) car: (SchemeObject []) a; +- (SchemeObject []) cdr; +- (void) cdr: (SchemeObject []) d; @end -@extern Cons cons (SchemeObject car, SchemeObject cdr); -@extern BOOL isList (SchemeObject ls); -@extern integer length (SchemeObject foo); +@extern Cons []cons (SchemeObject []car, SchemeObject []cdr); +@extern BOOL isList (SchemeObject []ls); +@extern integer length (SchemeObject []foo); #endif //__Cons_h diff --git a/ruamoko/scheme/Cons.r b/ruamoko/scheme/Cons.r index be5019f36..14c9d5028 100644 --- a/ruamoko/scheme/Cons.r +++ b/ruamoko/scheme/Cons.r @@ -4,37 +4,37 @@ #include "defs.h" #include "SchemeString.h" -Cons cons (SchemeObject car, SchemeObject cdr) +Cons []cons (SchemeObject []car, SchemeObject []cdr) { return [Cons newWithCar: car cdr: cdr]; } -integer length (SchemeObject foo) +integer length (SchemeObject []foo) { local integer len; - for (len = 0; [foo isKindOfClass: [Cons class]]; foo = [(Cons) foo cdr]) { + for (len = 0; [foo isKindOfClass: [Cons class]]; foo = [(Cons []) foo cdr]) { len++; } return len; } -BOOL isList (SchemeObject ls) +BOOL isList (SchemeObject []ls) { return ls == [Nil nil] || ([ls isKindOfClass: [Cons class]] && - isList([(Cons) ls cdr])); + isList([(Cons[]) ls cdr])); } @implementation Cons -+ (id) newWithCar: (SchemeObject) a cdr: (SchemeObject) d ++ (id) newWithCar: (SchemeObject []) a cdr: (SchemeObject []) d { return [[self alloc] initWithCar: a cdr: d]; } -- (id) initWithCar: (SchemeObject) a cdr: (SchemeObject) d +- (id) initWithCar: (SchemeObject []) a cdr: (SchemeObject []) d { car = a; cdr = d; @@ -48,22 +48,22 @@ BOOL isList (SchemeObject ls) return [super init]; } -- (SchemeObject) car +- (SchemeObject []) car { return car; } -- (void) car: (SchemeObject) a +- (void) car: (SchemeObject []) a { car = a; } -- (SchemeObject) cdr +- (SchemeObject []) cdr { return cdr; } -- (void) cdr: (SchemeObject) d +- (void) cdr: (SchemeObject []) d { cdr = d; } diff --git a/ruamoko/scheme/Continuation.h b/ruamoko/scheme/Continuation.h index f3fc0f969..2daf4e2c2 100644 --- a/ruamoko/scheme/Continuation.h +++ b/ruamoko/scheme/Continuation.h @@ -10,7 +10,7 @@ } + (id) newWithState: (state_t []) st pc: (integer) p; - (id) initWithState: (state_t []) st pc: (integer) p; -- (void) restoreOnMachine: (Machine) m; +- (void) restoreOnMachine: (Machine []) m; @end diff --git a/ruamoko/scheme/Continuation.r b/ruamoko/scheme/Continuation.r index 7722492bb..c27d5534a 100644 --- a/ruamoko/scheme/Continuation.r +++ b/ruamoko/scheme/Continuation.r @@ -22,15 +22,15 @@ return self; } -- (void) restoreOnMachine: (Machine) m +- (void) restoreOnMachine: (Machine []) m { [m state: &state]; return; } -- (void) invokeOnMachine: (Machine) m +- (void) invokeOnMachine: (Machine []) m { - [m value: [(Cons) [m stack] car]]; + [m value: [(Cons []) [m stack] car]]; [m state: &state]; return; } diff --git a/ruamoko/scheme/Error.h b/ruamoko/scheme/Error.h index 84de628d1..8a5c1e04c 100644 --- a/ruamoko/scheme/Error.h +++ b/ruamoko/scheme/Error.h @@ -6,9 +6,9 @@ { string type, message; } -+ (id) type: (string) t message: (string) m by: (SchemeObject) o; ++ (id) type: (string) t message: (string) m by: (SchemeObject []) o; + (id) type: (string) t message: (string) m; -- (id) initWithType: (string) t message: (string) m by: (SchemeObject) o; +- (id) initWithType: (string) t message: (string) m by: (SchemeObject []) o; - (string) type; - (string) message; diff --git a/ruamoko/scheme/Error.r b/ruamoko/scheme/Error.r index 1a44a2bc2..91625e6cb 100644 --- a/ruamoko/scheme/Error.r +++ b/ruamoko/scheme/Error.r @@ -2,7 +2,7 @@ #include "string.h" @implementation Error -+ (id) type: (string) t message: (string) m by: (SchemeObject) o ++ (id) type: (string) t message: (string) m by: (SchemeObject []) o { return [[self alloc] initWithType: t message: m by: o]; } @@ -12,7 +12,7 @@ return [[self alloc] initWithType: t message: m by: NIL]; } -- (id) initWithType: (string) t message: (string) m by: (SchemeObject) o +- (id) initWithType: (string) t message: (string) m by: (SchemeObject []) o { self = [super init]; type = str_new(); diff --git a/ruamoko/scheme/Frame.h b/ruamoko/scheme/Frame.h index 7e24fcc8e..c4353d82b 100644 --- a/ruamoko/scheme/Frame.h +++ b/ruamoko/scheme/Frame.h @@ -4,15 +4,15 @@ @interface Frame: SchemeObject { - SchemeObject[] array; + SchemeObject[][] array; integer size; - Frame link; + Frame []link; } -+ (id) newWithSize: (integer) sz link: (Frame) l; -- (id) initWithSize: (integer) sz link: (Frame) l; -- (void) set: (integer) index to: (SchemeObject) o; -- (SchemeObject) get: (integer) index; -- (Frame) getLink; ++ (id) newWithSize: (integer) sz link: (Frame []) l; +- (id) initWithSize: (integer) sz link: (Frame []) l; +- (void) set: (integer) index to: (SchemeObject []) o; +- (SchemeObject []) get: (integer) index; +- (Frame []) getLink; @end #endif //__FOO_h diff --git a/ruamoko/scheme/Frame.r b/ruamoko/scheme/Frame.r index ead1030fa..a1b7a0773 100644 --- a/ruamoko/scheme/Frame.r +++ b/ruamoko/scheme/Frame.r @@ -1,12 +1,12 @@ #include "Frame.h" @implementation Frame -+ (id) newWithSize: (integer) sz link: (Frame) l ++ (id) newWithSize: (integer) sz link: (Frame []) l { return [[self alloc] initWithSize: sz link: l]; } -- (id) initWithSize: (integer) sz link: (Frame) l +- (id) initWithSize: (integer) sz link: (Frame []) l { self = [super init]; size = sz; @@ -15,17 +15,17 @@ return self; } -- (void) set: (integer) index to: (SchemeObject) o +- (void) set: (integer) index to: (SchemeObject []) o { array[index] = o; } -- (SchemeObject) get: (integer) index +- (SchemeObject []) get: (integer) index { return array[index]; } -- (Frame) getLink +- (Frame []) getLink { return link; } diff --git a/ruamoko/scheme/Instruction.h b/ruamoko/scheme/Instruction.h index 1769928b7..0e67bbfd3 100644 --- a/ruamoko/scheme/Instruction.h +++ b/ruamoko/scheme/Instruction.h @@ -36,12 +36,12 @@ typedef struct instruction_s instruction_t; { opcode_e opcode; integer operand, offset; - Instruction label; + Instruction []label; } + (id) opcode: (opcode_e) oc; + (id) opcode: (opcode_e) oc operand: (integer) op; -+ (id) opcode: (opcode_e) oc label: (Instruction) l; -- (id) initWithOpcode: (opcode_e) oc operand: (integer) op label: (Instruction) l; ++ (id) opcode: (opcode_e) oc label: (Instruction []) l; +- (id) initWithOpcode: (opcode_e) oc operand: (integer) op label: (Instruction []) l; - (void) offset: (integer) ofs; - (integer) offset; - (opcode_e) opcode; diff --git a/ruamoko/scheme/Instruction.r b/ruamoko/scheme/Instruction.r index fda1c2707..b5d7c10c8 100644 --- a/ruamoko/scheme/Instruction.r +++ b/ruamoko/scheme/Instruction.r @@ -12,12 +12,12 @@ return [[self alloc] initWithOpcode: oc operand: op label: NIL]; } -+ (id) opcode: (opcode_e) oc label: (Instruction) l ++ (id) opcode: (opcode_e) oc label: (Instruction []) l { return [[self alloc] initWithOpcode: oc operand: 0 label: l]; } -- (id) initWithOpcode: (opcode_e) oc operand: (integer) op label: (Instruction) l +- (id) initWithOpcode: (opcode_e) oc operand: (integer) op label: (Instruction []) l { self = [super init]; opcode = oc; diff --git a/ruamoko/scheme/Lambda.h b/ruamoko/scheme/Lambda.h index 55fd19034..9304c021d 100644 --- a/ruamoko/scheme/Lambda.h +++ b/ruamoko/scheme/Lambda.h @@ -7,11 +7,11 @@ @interface Lambda: Procedure { - Frame env; - CompiledCode code; + Frame []env; + CompiledCode []code; } -+ (id) newWithCode: (CompiledCode) c environment: (Frame) e; -- (id) initWithCode: (CompiledCode) c environment: (Frame) e; ++ (id) newWithCode: (CompiledCode []) c environment: (Frame []) e; +- (id) initWithCode: (CompiledCode []) c environment: (Frame []) e; @end #endif //__Lambda_h diff --git a/ruamoko/scheme/Lambda.r b/ruamoko/scheme/Lambda.r index 114718f04..3ea890cf8 100644 --- a/ruamoko/scheme/Lambda.r +++ b/ruamoko/scheme/Lambda.r @@ -8,12 +8,12 @@ #include "Machine.h" @implementation Lambda -+ (id) newWithCode: (CompiledCode) c environment: (Frame) e ++ (id) newWithCode: (CompiledCode []) c environment: (Frame []) e { return [[self alloc] initWithCode: c environment: e]; } -- (id) initWithCode: (CompiledCode) c environment: (Frame) e +- (id) initWithCode: (CompiledCode []) c environment: (Frame []) e { self = [super init]; code = c; @@ -21,7 +21,7 @@ return self; } -- (void) invokeOnMachine: (Machine) m +- (void) invokeOnMachine: (Machine []) m { [super invokeOnMachine: m]; if (length([m stack]) < [code minimumArguments]) { diff --git a/ruamoko/scheme/Lexer.h b/ruamoko/scheme/Lexer.h index 2fed9610f..d94b08687 100644 --- a/ruamoko/scheme/Lexer.h +++ b/ruamoko/scheme/Lexer.h @@ -11,7 +11,7 @@ } + (id) newFromSource: (string) s file: (string) f; - (id) initWithSource: (string) s file: (string) f; -- (SchemeObject) nextToken; +- (SchemeObject []) nextToken; - (integer) lineNumber; @end diff --git a/ruamoko/scheme/Lexer.r b/ruamoko/scheme/Lexer.r index f8d2268b1..a38a270d9 100644 --- a/ruamoko/scheme/Lexer.r +++ b/ruamoko/scheme/Lexer.r @@ -44,13 +44,13 @@ BOOL issymbol (string x) return self; } -- (SchemeObject) nextToken +- (SchemeObject[]) nextToken { local integer len; - local Number num; - local Symbol sym; - local String str; - local Boolean bl; + local Number []num; + local Symbol []sym; + local String []str; + local Boolean []bl; for (len = 0; isjunk(str_mid(source, len, len+1)); len++) { if (str_mid(source, len, len+1) == ";") { diff --git a/ruamoko/scheme/Machine.h b/ruamoko/scheme/Machine.h index 2c39d41eb..b3bb00834 100644 --- a/ruamoko/scheme/Machine.h +++ b/ruamoko/scheme/Machine.h @@ -10,23 +10,23 @@ @interface Machine: SchemeObject { state_t state; - SchemeObject value; + SchemeObject []value; hashtab_t globals; - SchemeObject all_globals; + SchemeObject []all_globals; } -- (void) loadCode: (CompiledCode) code; -- (SchemeObject) run; -- (void) addGlobal: (Symbol) sym value: (SchemeObject) val; -- (void) environment: (Frame) e; -- (void) continuation: (Continuation) c; -- (Continuation) continuation; -- (void) value: (SchemeObject) o; -- (SchemeObject) stack; -- (void) stack: (SchemeObject) o; +- (void) loadCode: (CompiledCode []) code; +- (SchemeObject []) run; +- (void) addGlobal: (Symbol []) sym value: (SchemeObject []) val; +- (void) environment: (Frame []) e; +- (void) continuation: (Continuation []) c; +- (Continuation []) continuation; +- (void) value: (SchemeObject []) o; +- (SchemeObject []) stack; +- (void) stack: (SchemeObject []) o; - (state_t []) state; - (void) state: (state_t []) st; - (void) reset; -- (void) procedure: (Procedure) pr; +- (void) procedure: (Procedure []) pr; @end #endif //__Machine_h diff --git a/ruamoko/scheme/Machine.r b/ruamoko/scheme/Machine.r index 3758b3e07..d0f9f3761 100644 --- a/ruamoko/scheme/Machine.r +++ b/ruamoko/scheme/Machine.r @@ -10,7 +10,7 @@ string GlobalGetKey (void []ele, void []data) { - return [[((Cons) ele) car] printForm]; + return [[((Cons[]) ele) car] printForm]; } void GlobalFree (void []ele, void []data) @@ -37,14 +37,14 @@ void GlobalFree (void []ele, void []data) return self; } -- (void) addGlobal: (Symbol) sym value: (SchemeObject) val +- (void) addGlobal: (Symbol[]) sym value: (SchemeObject[]) val { - local Cons c = cons(sym, val); + local Cons []c = cons(sym, val); Hash_Add(globals, c); all_globals = cons(c, all_globals); } -- (void) loadCode: (CompiledCode) code +- (void) loadCode: (CompiledCode[]) code { state.program = [code code]; state.literals = [code literals]; @@ -52,37 +52,37 @@ void GlobalFree (void []ele, void []data) state.pc = 0; } -- (void) environment: (Frame) e +- (void) environment: (Frame[]) e { state.env = e; } -- (void) continuation: (Continuation) c +- (void) continuation: (Continuation[]) c { state.cont = c; } -- (void) value: (SchemeObject) v +- (void) value: (SchemeObject[]) v { value = v; } -- (SchemeObject) value +- (SchemeObject[]) value { return value; } -- (Continuation) continuation +- (Continuation[]) continuation { return state.cont; } -- (SchemeObject) stack +- (SchemeObject[]) stack { return state.stack; } -- (void) stack: (SchemeObject) o +- (void) stack: (SchemeObject[]) o { state.stack = o; } @@ -94,26 +94,26 @@ void GlobalFree (void []ele, void []data) - (void) state: (state_t []) st { - state.program = st[0].program; - state.pc = st[0].pc; - state.literals = st[0].literals; - state.stack = st[0].stack; - state.cont = st[0].cont; - state.env = st[0].env; - state.proc = st[0].proc; - state.lineinfo = st[0].lineinfo; + state.program = st.program; + state.pc = st.pc; + state.literals = st.literals; + state.stack = st.stack; + state.cont = st.cont; + state.env = st.env; + state.proc = st.proc; + state.lineinfo = st.lineinfo; } -- (void) procedure: (Procedure) pr +- (void) procedure: (Procedure[]) pr { state.proc = pr; } -- (SchemeObject) run +- (SchemeObject[]) run { local integer opcode; local integer operand; - local SchemeObject res; + local SchemeObject []res; while (1) { if (value && [value isError]) { dprintf("Error: %s[%s]\n", [value description], [value printForm]); @@ -134,17 +134,17 @@ void GlobalFree (void []ele, void []data) state.stack = cons(value, state.stack); break; case POP: - value = [(Cons) state.stack car]; + value = [(Cons[]) state.stack car]; if (value) { dprintf("Pop: %s\n", [value printForm]); } else { dprintf("Pop: NULL!!!!\n"); } - state.stack = [(Cons) state.stack cdr]; + state.stack = [(Cons[]) state.stack cdr]; break; case MAKECLOSURE: dprintf("Makeclosure\n"); - value = [Lambda newWithCode: (CompiledCode) value + value = [Lambda newWithCode: (CompiledCode[]) value environment: state.env]; break; case MAKECONT: @@ -169,16 +169,16 @@ void GlobalFree (void []ele, void []data) dprintf("Popenv\n"); state.env = [state.env getLink]; case GET: - value = [(Frame) value get: operand]; + value = [(Frame[]) value get: operand]; dprintf("Get: %i --> %s\n", operand, [value printForm]); break; case SET: - [(Frame) value set: operand to: [(Cons) state.stack car]]; - dprintf("Set: %i --> %s\n", operand, [[(Cons) state.stack car] printForm]); - state.stack = [(Cons) state.stack cdr]; + [(Frame[]) value set: operand to: [(Cons[]) state.stack car]]; + dprintf("Set: %i --> %s\n", operand, [[(Cons[]) state.stack car] printForm]); + state.stack = [(Cons[]) state.stack cdr]; break; case SETREST: - [(Frame) value set: operand to: state.stack]; + [(Frame[]) value set: operand to: state.stack]; dprintf("Setrest: %i --> %s\n", operand, [state.stack printForm]); state.stack = [Nil nil]; break; @@ -188,11 +188,11 @@ void GlobalFree (void []ele, void []data) break; case GETLINK: dprintf("Getlink\n"); - value = [(Frame) value getLink]; + value = [(Frame[]) value getLink]; break; case GETGLOBAL: dprintf("Getglobal: %s\n", [value printForm]); - res = [((Cons) Hash_Find(globals, [value printForm])) cdr]; + res = [((Cons[]) Hash_Find(globals, [value printForm])) cdr]; if (!res) { return [Error type: "binding" message: sprintf("Undefined binding: %s", @@ -204,8 +204,8 @@ void GlobalFree (void []ele, void []data) break; case SETGLOBAL: dprintf("Setglobal: %s\n", [value printForm]); - [self addGlobal: (Symbol) value value: [(Cons) state.stack car]]; - state.stack = [(Cons) state.stack cdr]; + [self addGlobal: (Symbol[]) value value: [(Cons[]) state.stack car]]; + state.stack = [(Cons[]) state.stack cdr]; break; case CALL: dprintf("Call\n"); @@ -217,7 +217,7 @@ void GlobalFree (void []ele, void []data) [value printForm], [state.stack printForm]) by: self]; } - [(Procedure) value invokeOnMachine: self]; + [(Procedure[]) value invokeOnMachine: self]; break; case RETURN: dprintf("Return: %s\n", [value printForm]); diff --git a/ruamoko/scheme/Nil.r b/ruamoko/scheme/Nil.r index 165391aca..d757253c7 100644 --- a/ruamoko/scheme/Nil.r +++ b/ruamoko/scheme/Nil.r @@ -1,7 +1,7 @@ #include "Nil.h" #include "defs.h" -Nil one_nil_to_rule_them_all; +Nil []one_nil_to_rule_them_all; @implementation Nil diff --git a/ruamoko/scheme/Parser.h b/ruamoko/scheme/Parser.h index 29ad205f9..38cd11c69 100644 --- a/ruamoko/scheme/Parser.h +++ b/ruamoko/scheme/Parser.h @@ -4,13 +4,13 @@ @interface Parser: SchemeObject { - Lexer lexer; + Lexer []lexer; string file; } + (id) newFromSource: (string) s file: (string) f; - (id) initWithSource: (string) s file: (string) f; -- (SchemeObject) readAtomic; -- (SchemeObject) read; +- (SchemeObject []) readAtomic; +- (SchemeObject []) read; @end #endif //__Parser_h diff --git a/ruamoko/scheme/Parser.r b/ruamoko/scheme/Parser.r index 861e15c7c..8f6ed421e 100644 --- a/ruamoko/scheme/Parser.r +++ b/ruamoko/scheme/Parser.r @@ -19,11 +19,11 @@ return self; } -- (SchemeObject) readList +- (SchemeObject[]) readList { - local SchemeObject token, res; + local SchemeObject []token, res; local integer line; - local Error err; + local Error []err; line = [lexer lineNumber]; token = [self readAtomic]; @@ -60,9 +60,9 @@ } } -- (SchemeObject) readAtomic +- (SchemeObject[]) readAtomic { - local SchemeObject token, list, res; + local SchemeObject []token, list, res; local integer line; line = [lexer lineNumber]; @@ -93,10 +93,10 @@ } else return token; } -- (SchemeObject) read +- (SchemeObject[]) read { - local SchemeObject token; - local Error err; + local SchemeObject []token; + local Error []err; token = [self readAtomic]; if (token == [Symbol rightParen]) { diff --git a/ruamoko/scheme/Primitive.h b/ruamoko/scheme/Primitive.h index 49def0039..a076f86c9 100644 --- a/ruamoko/scheme/Primitive.h +++ b/ruamoko/scheme/Primitive.h @@ -3,7 +3,7 @@ #include "Procedure.h" #include "Machine.h" -typedef SchemeObject (SchemeObject args, Machine m) primfunc_t; +typedef SchemeObject [](SchemeObject []args, Machine []m) primfunc_t; @interface Primitive: Procedure { diff --git a/ruamoko/scheme/Primitive.r b/ruamoko/scheme/Primitive.r index f23ff43a9..0687772ac 100644 --- a/ruamoko/scheme/Primitive.r +++ b/ruamoko/scheme/Primitive.r @@ -13,9 +13,9 @@ func = f; return self; } -- (SchemeObject) invokeOnMachine: (Machine) m +- (SchemeObject[]) invokeOnMachine: (Machine[]) m { - local SchemeObject value = func ([m stack], m); + local SchemeObject []value = func ([m stack], m); [super invokeOnMachine: m]; if (value) { [m value: value]; diff --git a/ruamoko/scheme/Procedure.h b/ruamoko/scheme/Procedure.h index 6a45c9e00..ffcd943ab 100644 --- a/ruamoko/scheme/Procedure.h +++ b/ruamoko/scheme/Procedure.h @@ -5,7 +5,7 @@ @class Machine; @interface Procedure: SchemeObject -- (void) invokeOnMachine: (Machine) m; +- (void) invokeOnMachine: (Machine []) m; @end #endif //__Procedure_h diff --git a/ruamoko/scheme/Procedure.r b/ruamoko/scheme/Procedure.r index f2c504d80..d7520fdcf 100644 --- a/ruamoko/scheme/Procedure.r +++ b/ruamoko/scheme/Procedure.r @@ -2,7 +2,7 @@ #include "Machine.h" @implementation Procedure -- (void) invokeOnMachine: (Machine) m +- (void) invokeOnMachine: (Machine []) m { [m procedure: self]; return; diff --git a/ruamoko/scheme/SchemeObject.h b/ruamoko/scheme/SchemeObject.h index 865cba5f4..d553a89b3 100644 --- a/ruamoko/scheme/SchemeObject.h +++ b/ruamoko/scheme/SchemeObject.h @@ -9,7 +9,7 @@ @interface SchemeObject: Object { - @public SchemeObject prev, next; + @public SchemeObject []prev, next; BOOL marked, root; integer line; string source; diff --git a/ruamoko/scheme/SchemeObject.r b/ruamoko/scheme/SchemeObject.r index 42152ee53..a5eef29b0 100644 --- a/ruamoko/scheme/SchemeObject.r +++ b/ruamoko/scheme/SchemeObject.r @@ -2,7 +2,7 @@ #include "defs.h" //#include "debug.h" -SchemeObject maybe_garbage, not_garbage, not_garbage_end, wait_list, roots, queue_pos; +SchemeObject []maybe_garbage, not_garbage, not_garbage_end, wait_list, roots, queue_pos; BOOL markstate; typedef enum { @@ -42,7 +42,7 @@ integer checkpoint; + (void) collect { - local SchemeObject cur; + local SchemeObject []cur; local integer amount; switch (gc_state) { diff --git a/ruamoko/scheme/Scope.h b/ruamoko/scheme/Scope.h index 8da75bb73..f2cc489e0 100644 --- a/ruamoko/scheme/Scope.h +++ b/ruamoko/scheme/Scope.h @@ -6,15 +6,15 @@ @interface Scope: SchemeObject { - Scope outerScope; - Array names; + Scope []outerScope; + Array []names; } -+ (id) newWithOuter: (Scope) o; -- (id) initWithOuter: (Scope) o; -- (integer) depthOf: (Symbol) sym; -- (integer) indexOf: (Symbol) sym; -- (void) addName: (Symbol) sym; -- (Scope) outer; ++ (id) newWithOuter: (Scope []) o; +- (id) initWithOuter: (Scope []) o; +- (integer) depthOf: (Symbol []) sym; +- (integer) indexOf: (Symbol []) sym; +- (void) addName: (Symbol []) sym; +- (Scope []) outer; @end #endif //__Scope_h diff --git a/ruamoko/scheme/Scope.r b/ruamoko/scheme/Scope.r index 774b8b232..f199c535c 100644 --- a/ruamoko/scheme/Scope.r +++ b/ruamoko/scheme/Scope.r @@ -3,12 +3,12 @@ @implementation Scope -+ (id) newWithOuter: (Scope) o ++ (id) newWithOuter: (Scope []) o { return [[self alloc] initWithOuter: o]; } -- (id) initWithOuter: (Scope) o +- (id) initWithOuter: (Scope []) o { self = [super init]; outerScope = o; @@ -16,7 +16,7 @@ return self; } -- (integer) indexLocal: (Symbol) sym +- (integer) indexLocal: (Symbol []) sym { local integer index; @@ -28,7 +28,7 @@ return -1; } -- (integer) indexOf: (Symbol) sym +- (integer) indexOf: (Symbol []) sym { local integer index; @@ -41,7 +41,7 @@ } } -- (integer) depthOf: (Symbol) sym +- (integer) depthOf: (Symbol []) sym { local integer index; local integer res; @@ -64,7 +64,7 @@ } } -- (void) addName: (Symbol) sym +- (void) addName: (Symbol []) sym { [names addObject: sym]; } @@ -84,7 +84,7 @@ [outerScope mark]; } -- (Scope) outer +- (Scope []) outer { return outerScope; } diff --git a/ruamoko/scheme/Symbol.h b/ruamoko/scheme/Symbol.h index 9923ef01e..6f7254640 100644 --- a/ruamoko/scheme/Symbol.h +++ b/ruamoko/scheme/Symbol.h @@ -6,13 +6,13 @@ { } + (void) initialize; -+ (Symbol) leftParen; -+ (Symbol) rightParen; -+ (Symbol) dot; -+ (Symbol) forString: (string) s; -+ (Symbol) quote; ++ (Symbol []) leftParen; ++ (Symbol []) rightParen; ++ (Symbol []) dot; ++ (Symbol []) forString: (string) s; ++ (Symbol []) quote; @end -@extern Symbol symbol (string str); +@extern Symbol []symbol (string str); #endif //__Symbol_h diff --git a/ruamoko/scheme/Symbol.r b/ruamoko/scheme/Symbol.r index c928d7b91..2555729bd 100644 --- a/ruamoko/scheme/Symbol.r +++ b/ruamoko/scheme/Symbol.r @@ -4,25 +4,25 @@ string SymbolGetKey (void [] ele, void [] data) { - local Symbol s = (Symbol) ele; + local Symbol []s = (Symbol[]) ele; return [s stringValue]; } void SymbolFree (void [] ele, void [] data) { - local Symbol s = (Symbol) ele; + local Symbol []s = (Symbol[]) ele; [s release]; } hashtab_t symbols; -Symbol lparen; -Symbol rparen; -Symbol quote; -Symbol dot; +Symbol []lparen; +Symbol []rparen; +Symbol []quote; +Symbol []dot; -Symbol symbol (string str) +Symbol []symbol (string str) { return [Symbol forString: str]; } @@ -41,35 +41,35 @@ Symbol symbol (string str) [dot retain]; } -+ (Symbol) forString: (string) s ++ (Symbol[]) forString: (string) s { - local Symbol res; + local Symbol []res; if ((res = Hash_Find (symbols, s))) { return res; } else { - res = (Symbol) [self newFromString: s]; + res = (Symbol[]) [self newFromString: s]; Hash_Add (symbols, res); return res; } } -+ (Symbol) leftParen ++ (Symbol[]) leftParen { return lparen; } -+ (Symbol) rightParen ++ (Symbol[]) rightParen { return rparen; } -+ (Symbol) quote ++ (Symbol[]) quote { return quote; } -+ (Symbol) dot ++ (Symbol[]) dot { return dot; } diff --git a/ruamoko/scheme/Void.h b/ruamoko/scheme/Void.h index ca934acb6..205a98b06 100644 --- a/ruamoko/scheme/Void.h +++ b/ruamoko/scheme/Void.h @@ -8,6 +8,6 @@ + (id) voidConstant; @end -@extern Void voidConstant; +@extern Void []voidConstant; #endif //__Void_h diff --git a/ruamoko/scheme/Void.r b/ruamoko/scheme/Void.r index 8adde740a..ebf466103 100644 --- a/ruamoko/scheme/Void.r +++ b/ruamoko/scheme/Void.r @@ -1,6 +1,6 @@ #include "Void.h" -Void voidConstant; +Void []voidConstant; @implementation Void diff --git a/ruamoko/scheme/builtins.h b/ruamoko/scheme/builtins.h index e553b2f35..fca73812c 100644 --- a/ruamoko/scheme/builtins.h +++ b/ruamoko/scheme/builtins.h @@ -1,3 +1,3 @@ #include "Primitive.h" -@extern void builtin_addtomachine (Machine m); +@extern void builtin_addtomachine (Machine []m); diff --git a/ruamoko/scheme/builtins.r b/ruamoko/scheme/builtins.r index fc867e2a9..0b7f3a0cc 100644 --- a/ruamoko/scheme/builtins.r +++ b/ruamoko/scheme/builtins.r @@ -10,26 +10,26 @@ #include "Boolean.h" #include "Error.h" -BOOL num_args (SchemeObject list, integer num) +BOOL num_args (SchemeObject []list, integer num) { - for (; [list isKindOfClass: [Cons class]]; list = [(Cons) list cdr]) { + for (; [list isKindOfClass: [Cons class]]; list = [(Cons[]) list cdr]) { num--; } return num == 0; } -SchemeObject bi_display (SchemeObject args, Machine m) +SchemeObject []bi_display (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "display" message: "expected 1 argument" by: m]; } - print([[(Cons) args car] printForm]); + print([[(Cons[]) args car] printForm]); return [Void voidConstant]; } -SchemeObject bi_newline (SchemeObject args, Machine m) +SchemeObject []bi_newline (SchemeObject []args, Machine []m) { if (!num_args(args, 0)) { return [Error type: "newline" @@ -40,28 +40,28 @@ SchemeObject bi_newline (SchemeObject args, Machine m) return [Void voidConstant]; } -SchemeObject bi_add (SchemeObject args, Machine m) +SchemeObject []bi_add (SchemeObject []args, Machine []m) { local integer sum = 0; - local SchemeObject cur; + local SchemeObject []cur; - for (cur = args; cur != [Nil nil]; cur = [(Cons) cur cdr]) { - if (![[(Cons) cur car] isKindOfClass: [Number class]]) { + for (cur = args; cur != [Nil nil]; cur = [(Cons[]) cur cdr]) { + if (![[(Cons[]) cur car] isKindOfClass: [Number class]]) { return [Error type: "+" message: sprintf("non-number argument: %s\n", - [[(Cons) cur car] printForm]) + [[(Cons[]) cur car] printForm]) by: m]; } - sum += [(Number) [(Cons) cur car] intValue]; + sum += [(Number[]) [(Cons[]) cur car] intValue]; } return [Number newFromInt: sum]; } -SchemeObject bi_sub (SchemeObject args, Machine m) +SchemeObject []bi_sub (SchemeObject []args, Machine []m) { local integer diff = 0; - local SchemeObject cur; + local SchemeObject []cur; if (args == [Nil nil]) { return [Error type: "-" @@ -69,7 +69,7 @@ SchemeObject bi_sub (SchemeObject args, Machine m) by: m]; } - cur = [(Cons) args car]; + cur = [(Cons[]) args car]; if (![cur isKindOfClass: [Number class]]) { return [Error type: "-" @@ -78,47 +78,47 @@ SchemeObject bi_sub (SchemeObject args, Machine m) by: m]; } - diff = [(Number) cur intValue]; + diff = [(Number[]) cur intValue]; - if ([(Cons) args cdr] == [Nil nil]) { + if ([(Cons[]) args cdr] == [Nil nil]) { return [Number newFromInt: -diff]; } - for (cur = [(Cons) args cdr]; cur != [Nil nil]; cur = [(Cons) cur cdr]) { - if (![[(Cons) cur car] isKindOfClass: [Number class]]) { + for (cur = [(Cons[]) args cdr]; cur != [Nil nil]; cur = [(Cons[]) cur cdr]) { + if (![[(Cons[]) cur car] isKindOfClass: [Number class]]) { return [Error type: "-" message: sprintf("non-number argument: %s\n", - [[(Cons) cur car] printForm]) + [[(Cons[]) cur car] printForm]) by: m]; } - diff -= [(Number) [(Cons) cur car] intValue]; + diff -= [(Number[]) [(Cons[]) cur car] intValue]; } return [Number newFromInt: diff]; } -SchemeObject bi_mult (SchemeObject args, Machine m) +SchemeObject []bi_mult (SchemeObject []args, Machine []m) { local integer prod = 1; - local SchemeObject cur; + local SchemeObject []cur; - for (cur = args; cur != [Nil nil]; cur = [(Cons) cur cdr]) { - if (![[(Cons) cur car] isKindOfClass: [Number class]]) { + for (cur = args; cur != [Nil nil]; cur = [(Cons[]) cur cdr]) { + if (![[(Cons[]) cur car] isKindOfClass: [Number class]]) { return [Error type: "*" message: sprintf("non-number argument: %s\n", - [[(Cons) cur car] printForm]) + [[(Cons[]) cur car] printForm]) by: m]; } - prod *= [(Number) [(Cons) cur car] intValue]; + prod *= [(Number[]) [(Cons[]) cur car] intValue]; } return [Number newFromInt: prod]; } -SchemeObject bi_div (SchemeObject args, Machine m) +SchemeObject []bi_div (SchemeObject []args, Machine []m) { local integer frac = 0; - local SchemeObject cur; + local SchemeObject []cur; if (args == [Nil nil]) { return [Error type: "/" @@ -126,7 +126,7 @@ SchemeObject bi_div (SchemeObject args, Machine m) by: m]; } - cur = [(Cons) args car]; + cur = [(Cons[]) args car]; if (![cur isKindOfClass: [Number class]]) { return [Error type: "/" @@ -135,123 +135,123 @@ SchemeObject bi_div (SchemeObject args, Machine m) by: m]; } - frac = [(Number) cur intValue]; + frac = [(Number[]) cur intValue]; - if ([(Cons) args cdr] == [Nil nil]) { + if ([(Cons[]) args cdr] == [Nil nil]) { return [Number newFromInt: 1/frac]; } - for (cur = [(Cons) args cdr]; cur != [Nil nil]; cur = [(Cons) cur cdr]) { - if (![[(Cons) cur car] isKindOfClass: [Number class]]) { + for (cur = [(Cons[]) args cdr]; cur != [Nil nil]; cur = [(Cons[]) cur cdr]) { + if (![[(Cons[]) cur car] isKindOfClass: [Number class]]) { return [Error type: "/" message: sprintf("non-number argument: %s\n", - [[(Cons) cur car] printForm]) + [[(Cons[]) cur car] printForm]) by: m]; } - frac /= [(Number) [(Cons) cur car] intValue]; + frac /= [(Number[]) [(Cons[]) cur car] intValue]; } return [Number newFromInt: frac]; } -SchemeObject bi_cons (SchemeObject args, Machine m) +SchemeObject []bi_cons (SchemeObject []args, Machine []m) { if (!num_args(args, 2)) { return [Error type: "cons" message: "expected 2 arguments" by: m]; } - [(Cons) args cdr: [(Cons) [(Cons) args cdr] car]]; + [(Cons[]) args cdr: [(Cons[]) [(Cons[]) args cdr] car]]; return args; } -SchemeObject bi_null (SchemeObject args, Machine m) +SchemeObject []bi_null (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "null?" message: "expected 1 argument" by: m]; } - return [(Cons) args car] == [Nil nil] + return [(Cons[]) args car] == [Nil nil] ? [Boolean trueConstant] : [Boolean falseConstant]; } -SchemeObject bi_car (SchemeObject args, Machine m) +SchemeObject []bi_car (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "car" message: "expected 1 argument" by: m]; } - if (![[(Cons) args car] isKindOfClass: [Cons class]]) { + if (![[(Cons[]) args car] isKindOfClass: [Cons class]]) { return [Error type: "car" message: sprintf("expected pair, got: %s", - [[(Cons) args car] printForm]) + [[(Cons[]) args car] printForm]) by: m]; } - return [(Cons) [(Cons) args car] car]; + return [(Cons[]) [(Cons[]) args car] car]; } -SchemeObject bi_cdr (SchemeObject args, Machine m) +SchemeObject []bi_cdr (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "cdr" message: "expected 1 argument" by: m]; } - if (![[(Cons) args car] isKindOfClass: [Cons class]]) { + if (![[(Cons[]) args car] isKindOfClass: [Cons class]]) { return [Error type: "cdr" message: sprintf("expected pair, got: %s", - [[(Cons) args car] printForm]) + [[(Cons[]) args car] printForm]) by: m]; } - return [(Cons) [(Cons) args car] cdr]; + return [(Cons[]) [(Cons[]) args car] cdr]; } -SchemeObject bi_apply (SchemeObject args, Machine m) +SchemeObject []bi_apply (SchemeObject []args, Machine []m) { - local SchemeObject cur, prev; + local SchemeObject []cur, prev; if (args == [Nil nil]) { return [Error type: "apply" message: "expected at least 1 argument" by: m]; - } else if (![[(Cons) args car] isKindOfClass: [Procedure class]]) { + } else if (![[(Cons[]) args car] isKindOfClass: [Procedure class]]) { return [Error type: "apply" message: sprintf("expected procedure as 1st argument, got: %s", - [[(Cons) args car] printForm]) + [[(Cons[]) args car] printForm]) by: m]; } prev = NIL; - for (cur = args; [(Cons) cur cdr] != [Nil nil]; cur = [(Cons) cur cdr]) { + for (cur = args; [(Cons[]) cur cdr] != [Nil nil]; cur = [(Cons[]) cur cdr]) { prev = cur; } if (prev) { - [(Cons) prev cdr: [(Cons) cur car]]; + [(Cons[]) prev cdr: [(Cons[]) cur car]]; } - [m stack: [(Cons) args cdr]]; - [(Procedure) [(Cons) args car] invokeOnMachine: m]; + [m stack: [(Cons[]) args cdr]]; + [(Procedure[]) [(Cons[]) args car] invokeOnMachine: m]; return NIL; } -SchemeObject bi_callcc (SchemeObject args, Machine m) +SchemeObject []bi_callcc (SchemeObject []args, Machine []m) { if (args == [Nil nil]) { return [Error type: "call-with-current-continuation" message: "expected at least 1 argument" by: m]; - } else if (![[(Cons) args car] isKindOfClass: [Procedure class]]) { + } else if (![[(Cons[]) args car] isKindOfClass: [Procedure class]]) { return [Error type: "call-with-current-continuation" message: sprintf("expected procedure as 1st argument, got: %s", - [[(Cons) args car] printForm]) + [[(Cons[]) args car] printForm]) by: m]; } if ([m continuation]) { @@ -260,11 +260,11 @@ SchemeObject bi_callcc (SchemeObject args, Machine m) [m stack: cons([BaseContinuation baseContinuation], [Nil nil])]; } - [(Procedure) [(Cons) args car] invokeOnMachine: m]; + [(Procedure[]) [(Cons[]) args car] invokeOnMachine: m]; return NIL; } -SchemeObject bi_eq (SchemeObject args, Machine m) +SchemeObject []bi_eq (SchemeObject []args, Machine []m) { if (!num_args(args, 2)) { return [Error type: "eq?" @@ -272,21 +272,21 @@ SchemeObject bi_eq (SchemeObject args, Machine m) by: m]; } return - [(Cons) args car] == [(Cons) [(Cons) args cdr] car] ? + [(Cons[]) args car] == [(Cons[]) [(Cons[]) args cdr] car] ? [Boolean trueConstant] : [Boolean falseConstant]; } -SchemeObject bi_numeq (SchemeObject args, Machine m) +SchemeObject []bi_numeq (SchemeObject []args, Machine []m) { - local SchemeObject num1, num2; + local SchemeObject []num1, num2; if (!num_args(args, 2)) { return [Error type: "=" message: "expected 2 arguments" by: m]; } - num1 = [(Cons) args car]; - num2 = [(Cons) [(Cons) args cdr] car]; + num1 = [(Cons[]) args car]; + num2 = [(Cons[]) [(Cons[]) args cdr] car]; if (![num1 isKindOfClass: [Number class]]) { return [Error type: "=" message: sprintf("expected number argument, got: %s", @@ -300,12 +300,12 @@ SchemeObject bi_numeq (SchemeObject args, Machine m) } return - [(Number) num1 intValue] == [(Number) num2 intValue] ? + [(Number[]) num1 intValue] == [(Number[]) num2 intValue] ? [Boolean trueConstant] : [Boolean falseConstant]; } -SchemeObject bi_islist (SchemeObject args, Machine m) +SchemeObject []bi_islist (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "list?" @@ -319,7 +319,7 @@ SchemeObject bi_islist (SchemeObject args, Machine m) [Boolean falseConstant]; } -SchemeObject bi_ispair (SchemeObject args, Machine m) +SchemeObject []bi_ispair (SchemeObject []args, Machine []m) { if (!num_args(args, 1)) { return [Error type: "pair?" @@ -328,14 +328,14 @@ SchemeObject bi_ispair (SchemeObject args, Machine m) } return - [[(Cons) args car] isKindOfClass: [Cons class]] ? + [[(Cons[]) args car] isKindOfClass: [Cons class]] ? [Boolean trueConstant] : [Boolean falseConstant]; } #define builtin(name, func) [m addGlobal: symbol(#name) value: [Primitive newFromFunc: (func)]] -void builtin_addtomachine (Machine m) +void builtin_addtomachine (Machine []m) { builtin(display, bi_display); builtin(newline, bi_newline); diff --git a/ruamoko/scheme/state.h b/ruamoko/scheme/state.h index 39e13ac53..a06305a55 100644 --- a/ruamoko/scheme/state.h +++ b/ruamoko/scheme/state.h @@ -11,10 +11,10 @@ struct state_s { instruction_t [] program; lineinfo_t [] lineinfo; integer pc; - Frame literals, env; - SchemeObject stack; - Continuation cont; - Procedure proc; + Frame []literals, env; + SchemeObject []stack; + Continuation []cont; + Procedure []proc; }; typedef struct state_s state_t; diff --git a/tools/qfcc/include/Makefile.am b/tools/qfcc/include/Makefile.am index 96ac59aa4..a913d784b 100644 --- a/tools/qfcc/include/Makefile.am +++ b/tools/qfcc/include/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS= foreign -EXTRA_DIST= class.h cpp.h debug.h def.h emit.h expr.h function.h \ - idstuff.h immediate.h linker.h method.h obj_file.h opcodes.h \ - options.h qfcc.h qfprogs.h reloc.h strpool.h struct.h switch.h \ - symtab.h type.h +EXTRA_DIST= class.h codespace.h cpp.h debug.h def.h emit.h expr.h \ + function.h grab.h idstuff.h immediate.h linker.h method.h \ + obj_file.h opcodes.h options.h qfcc.h qfprogs.h reloc.h strpool.h \ + struct.h switch.h symtab.h type.h diff --git a/tools/qfcc/include/codespace.h b/tools/qfcc/include/codespace.h new file mode 100644 index 000000000..81334ef64 --- /dev/null +++ b/tools/qfcc/include/codespace.h @@ -0,0 +1,47 @@ +/* + codespace.h + + management of code segement + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2011/01/07 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ + +#ifndef __codespace_h +#define __codespace_h + +typedef struct codespace_s { + struct statement_s *code; + int size; + int max_size; +} codespace_t; + +codespace_t *codespace_new (void); +void codespace_delete (codespace_t *codespace); +void codespace_addcode (codespace_t *codespace, struct statement_s *code, + int size); +struct statement_s *codespace_newstatement (codespace_t *codespace); + +#endif//__codespace_h diff --git a/tools/qfcc/include/def.h b/tools/qfcc/include/def.h index e9837d995..c6ca021b0 100644 --- a/tools/qfcc/include/def.h +++ b/tools/qfcc/include/def.h @@ -110,6 +110,7 @@ typedef enum { } storage_class_t; extern def_t def_void; +extern def_t def_invalid; extern def_t def_function; scope_t *new_scope (scope_type type, defspace_t *space, scope_t *parent); diff --git a/tools/qfcc/include/emit.h b/tools/qfcc/include/emit.h index e79a5e6a9..a033f35c8 100644 --- a/tools/qfcc/include/emit.h +++ b/tools/qfcc/include/emit.h @@ -32,18 +32,6 @@ #ifndef __emit_h #define __emit_h -typedef struct codespace_s { - struct statement_s *code; - int size; - int max_size; -} codespace_t; - -codespace_t *codespace_new (void); -void codespace_delete (codespace_t *codespace); -void codespace_addcode (codespace_t *codespace, struct statement_s *code, - int size); -struct statement_s *codespace_newstatement (codespace_t *codespace); - struct expr_s; struct def_s *emit_statement (struct expr_s *e, opcode_t *op, struct def_s *var_a, struct def_s *var_b, struct def_s *var_c); struct def_s *emit_sub_expr (struct expr_s*e, struct def_s *dest); diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 2e22a51d9..f33d3c4af 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -209,6 +209,11 @@ extern expr_type expr_types[]; */ expr_t *type_mismatch (expr_t *e1, expr_t *e2, int op); +expr_t *param_mismatch (expr_t *e, int param, const char *fn, + struct type_s *t1, struct type_s *t2); +expr_t *cast_error (expr_t *e, struct type_s *t1, struct type_s *t2); +expr_t *test_error (expr_t *e, struct type_s *t); + extern expr_t *local_expr; /** Get the type descriptor of the expression result. diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index c62b62521..59b30583b 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -34,19 +34,42 @@ #include "QF/pr_comp.h" +typedef struct ty_func_s { + struct type_s *type; + int num_params; + struct type_s *param_types[MAX_PARMS]; +} ty_func_t; + +typedef struct ty_fldptr_s { + struct type_s *type; +} ty_fldptr_t; + +typedef struct ty_array_s { + struct type_s *type; + int base; + int size; +} ty_array_t; + +typedef enum { + ty_none, ///< func/field/pointer or not used + ty_struct, + ty_array, + ty_class, +} ty_type_e; + typedef struct type_s { - etype_t type; - const char *name; - struct type_s *next; -// function/pointer/struct types are more complex - struct type_s *aux_type; // return type or field type - int num_parms; // -1 = variable args - struct type_s *parm_types[MAX_PARMS]; // only [num_parms] allocated + etype_t type; ///< ev_invalid means structure/array etc + const char *name; + /// function/pointer/array/struct types are more complex + ty_type_e ty; union { - struct class_s *class; // for ev_class - struct struct_s *strct; // for ev_struct - int base; // for arrays - } s; + ty_func_t func; + ty_fldptr_t fldptr; + ty_array_t array; + struct struct_s *strct; + struct class_s *class; + } t; + struct type_s *next; } type_t; typedef struct typedef_s { @@ -55,6 +78,7 @@ typedef struct typedef_s { type_t *type; } typedef_t; +extern type_t type_invalid; extern type_t type_void; extern type_t type_string; extern type_t type_float; @@ -66,9 +90,8 @@ extern type_t type_pointer; extern type_t type_floatfield; extern type_t type_quaternion; extern type_t type_integer; -extern type_t type_uinteger; extern type_t type_short; -extern type_t type_struct; + extern type_t type_id; extern type_t type_Class; extern type_t type_Protocol; @@ -99,10 +122,15 @@ type_t *field_type (type_t *aux); type_t *pointer_type (type_t *aux); type_t *array_type (type_t *aux, int size); type_t *based_array_type (type_t *aux, int base, int top); +void print_type_str (struct dstring_s *str, type_t *type); void print_type (type_t *type); const char *encode_params (type_t *type); void encode_type (struct dstring_s *encoding, type_t *type); type_t *parse_type (const char *str); +int is_scalar (type_t *type); +int is_struct (type_t *type); +int is_class (type_t *type); +int is_array (type_t *type); int type_assignable (type_t *dst, type_t *src); int type_size (type_t *type); diff --git a/tools/qfcc/source/Makefile.am b/tools/qfcc/source/Makefile.am index fc4b34b0f..6872220e2 100644 --- a/tools/qfcc/source/Makefile.am +++ b/tools/qfcc/source/Makefile.am @@ -52,9 +52,9 @@ bin_SCRIPTS= $(qfpreqcc) EXTRA_PROGRAMS= qfcc qfpc qfprogs common_src=\ - class.c constfold.c cpp.c debug.c def.c emit.c expr.c function.c grab.c \ - idstuff.c immediate.c linker.c method.c obj_file.c opcodes.c options.c \ - qfcc.c reloc.c strpool.c struct.c switch.c symtab.c \ + class.c codespace.c constfold.c cpp.c debug.c def.c emit.c expr.c \ + function.c grab.c idstuff.c immediate.c linker.c method.c obj_file.c \ + opcodes.c options.c qfcc.c reloc.c strpool.c struct.c switch.c symtab.c \ type.c qfcc_SOURCES= qc-lex.l qc-parse.y $(common_src) diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index c2020cfb0..9be02c3ba 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -49,6 +49,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "qfcc.h" +#include "codespace.h" #include "class.h" #include "def.h" #include "emit.h" @@ -126,7 +127,7 @@ class_def (class_type_t *class_type, int external) break; case ct_class: name = va ("_OBJ_CLASS_%s", class_type->c.class->name); - type = type_Class.aux_type; + type = type_Class.t.fldptr.type; break; case ct_protocol: return 0; // probably in error recovery @@ -156,9 +157,9 @@ get_class (const char *name, int create) c = calloc (sizeof (class_t), 1); c->name = name; - new = *type_Class.aux_type; - new.s.class = c; - c->type = pointer_type (find_type (&new)); + new = *type_Class.t.fldptr.type; + new.t.class = c; + c->type = find_type (&new); c->methods = new_methodlist (); c->class_type.type = ct_class; c->class_type.c.class = c; @@ -171,7 +172,7 @@ static void set_self_type (class_t *class, method_t *method) { if (method->instance) - method->params->type = class->type; + method->params->type = pointer_type (class->type); else method->params->type = &type_Class; } @@ -246,7 +247,7 @@ begin_class (class_t *class) current_class = &class->class_type; class->def = class_def (current_class, 0); - meta_def = get_def (type_Class.aux_type, + meta_def = get_def (type_Class.t.fldptr.type, va ("_OBJ_METACLASS_%s", class->name), pr.scope, st_static); meta_def->initialized = meta_def->constant = 1; @@ -257,9 +258,9 @@ begin_class (class_t *class) EMIT_STRING (meta->super_class, class->super_class->name); EMIT_STRING (meta->name, class->name); meta->info = _PR_CLS_META; - meta->instance_size = type_size (type_Class.aux_type); + meta->instance_size = type_size (type_Class.t.fldptr.type); EMIT_DEF (meta->ivars, - emit_struct (type_Class.aux_type->s.class->ivars, + emit_struct (type_Class.t.fldptr.type->t.class->ivars, "Class")); class->def->initialized = class->def->constant = 1; @@ -558,7 +559,8 @@ class_message_response (class_t *class, int class_msg, expr_t *sel) class_t *c = class; category_t *cat; - if (sel->type != ex_pointer && sel->e.pointer.type != type_SEL.aux_type) { + if (sel->type != ex_pointer + && sel->e.pointer.type != type_SEL.t.fldptr.type) { error (sel, "not a selector"); return 0; } @@ -790,7 +792,7 @@ class_finish_module (void) symtab_def->nosave = 1; symtab = &G_STRUCT (pr_symtab_t, symtab_def->ofs); if (selector_table_def) { - symtab->sel_ref_cnt = selector_table_def->type->num_parms; + symtab->sel_ref_cnt = selector_table_def->type->t.func.num_params; EMIT_DEF (symtab->refs, selector_table_def); } symtab->cls_def_cnt = num_classes; @@ -920,14 +922,14 @@ emit_protocol (protocol_t *protocol) def_t *proto_def; pr_protocol_t *proto; - proto_def = get_def (type_Protocol.aux_type, - va ("_OBJ_PROTOCOL_%s", protocol->name), - pr.scope, st_none); + proto_def = get_def (&type_Protocol, + va ("_OBJ_PROTOCOL_%s", protocol->name), + pr.scope, st_none); if (proto_def) return proto_def; - proto_def = get_def (type_Protocol.aux_type, - va ("_OBJ_PROTOCOL_%s", protocol->name), - pr.scope, st_static); + proto_def = get_def (&type_Protocol, + va ("_OBJ_PROTOCOL_%s", protocol->name), + pr.scope, st_static); proto_def->initialized = proto_def->constant = 1; proto_def->nosave = 1; proto = &G_STRUCT (pr_protocol_t, proto_def->ofs); @@ -960,9 +962,9 @@ emit_protocol_list (protocollist_t *protocols, const char *name) new_struct_field (protocol_list, &type_integer, "count", vis_public); for (i = 0; i < protocols->count; i++) new_struct_field (protocol_list, &type_pointer, 0, vis_public); - proto_list_def = get_def (type_Protocol.aux_type, - va ("_OBJ_PROTOCOLS_%s", name), - pr.scope, st_static); + proto_list_def = get_def (&type_Protocol, + va ("_OBJ_PROTOCOLS_%s", name), + pr.scope, st_static); proto_list_def->initialized = proto_list_def->constant = 1; proto_list_def->nosave = 1; proto_list = &G_STRUCT (pr_protocol_list_t, proto_list_def->ofs); diff --git a/tools/qfcc/source/codespace.c b/tools/qfcc/source/codespace.c new file mode 100644 index 000000000..7635a274c --- /dev/null +++ b/tools/qfcc/source/codespace.c @@ -0,0 +1,83 @@ +/* + codespace.c + + management of code segement + + Copyright (C) 2011 Bill Currie + + Author: Bill Currie + Date: 2011/01/07 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +static __attribute__ ((used)) const char rcsid[] = "$Id$"; + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#include + +#include "QF/pr_comp.h" + +#include "codespace.h" + +codespace_t * +codespace_new (void) +{ + return calloc (1, sizeof (codespace_t)); +} + +void +codespace_delete (codespace_t *codespace) +{ + free (codespace->code); + free (codespace); +} + +void +codespace_addcode (codespace_t *codespace, dstatement_t *code, int size) +{ + if (codespace->size + size > codespace->max_size) { + codespace->max_size = (codespace->size + size + 16383) & ~16383; + codespace->code = realloc (codespace->code, + codespace->max_size * sizeof (dstatement_t)); + } + memcpy (codespace->code + codespace->size, code, + size * sizeof (dstatement_t)); + codespace->size += size; +} + +dstatement_t * +codespace_newstatement (codespace_t *codespace) +{ + if (codespace->size >= codespace->max_size) { + codespace->max_size += 16384; + codespace->code = realloc (codespace->code, + codespace->max_size * sizeof (dstatement_t)); + } + return codespace->code + codespace->size++; +} diff --git a/tools/qfcc/source/constfold.c b/tools/qfcc/source/constfold.c index 31a3ce74c..34ea5cfb9 100644 --- a/tools/qfcc/source/constfold.c +++ b/tools/qfcc/source/constfold.c @@ -402,7 +402,7 @@ static expr_t * do_op_func (int op, expr_t *e, expr_t *e1, expr_t *e2) { if (op == 'c') { - e->e.expr.type = get_type (e1)->aux_type; + e->e.expr.type = get_type (e1)->t.func.type; return e; } if (op == EQ || op == NE) { @@ -427,7 +427,7 @@ do_op_pointer (int op, expr_t *e, expr_t *e1, expr_t *e2) if (!valid_op (op, valid)) return error (e1, "invalid operand for pointer"); - if (op == PAS && (type = get_type (e1)->aux_type) != get_type (e2)) { + if (op == PAS && (type = get_type (e1)->t.fldptr.type) != get_type (e2)) { // make sure auto-convertions happen expr_t *tmp = new_temp_def_expr (type); expr_t *ass = new_binary_expr ('=', tmp, e2); @@ -449,10 +449,10 @@ do_op_pointer (int op, expr_t *e, expr_t *e1, expr_t *e2) if (op != PAS && op != '.' && op != '&' && op != 'M' && extract_type (e1) != extract_type (e2)) return type_mismatch (e1, e2, op); - if ((op == '.' || op == '&') && get_type (e2) == &type_uinteger) { - //FIXME should implement unsigned addressing - e->e.expr.e2 = cf_cast_expr (&type_integer, e2); - } + //if ((op == '.' || op == '&') && get_type (e2) == &type_uinteger) { + // //FIXME should implement unsigned addressing + // e->e.expr.e2 = cf_cast_expr (&type_integer, e2); + //} return e; } @@ -632,161 +632,6 @@ do_op_integer (int op, expr_t *e, expr_t *e1, expr_t *e2) return e1; } -static expr_t * -convert_to_uinteger (expr_t *e) -{ - if (get_type (e) == &type_uinteger) - return e; - - switch (e->type) { - case ex_integer: - convert_int_uint (e); - return e; - case ex_short: - convert_short_uint (e); - return e; - case ex_def: - case ex_expr: - case ex_uexpr: - case ex_temp: - case ex_block: - return cf_cast_expr (&type_uinteger, e); - default: - internal_error (e); - } -} - -static expr_t * -do_op_uinteger (int op, expr_t *e, expr_t *e1, expr_t *e2) -{ - expr_t *conv; - type_t *type; - unsigned i1, i2; - static int valid[] = { - '=', 'b', '+', '-', '*', '/', '&', '|', '^', '%', - SHL, SHR, AND, OR, LT, GT, LE, GE, EQ, NE, 0 - }; - - if (!valid_op (op, valid)) - return error (e1, "invalid operand for uinteger"); - - if (e1->type == ex_short) - convert_short_uint (e1); - if (e1->type == ex_integer) - convert_int_uint (e1); - if (op == 'b') { - // bind is backwards to assign (why did I do that? :P) - if ((type = get_type (e2)) != &type_uinteger) { - e->e.expr.e1 = e1 = cf_cast_expr (type, e1); - } else if ((conv = convert_to_uinteger (e1)) != e1) { - e->e.expr.e1 = e1 = conv; - } - } else if (op == '=' || op == PAS) { - if ((type = get_type (e1)) != &type_uinteger) { - e->e.expr.e2 = e2 = cf_cast_expr (type, e2); - } else if ((conv = convert_to_uinteger (e2)) != e2) { - e->e.expr.e2 = e2 = conv; - } - } else { - if (get_type (e1) != &type_uinteger) { - e->e.expr.e1 = e1 = cf_cast_expr (&type_uinteger, e1); - } - if (e2->type == ex_short) - convert_short_uint (e2); - if (e2->type == ex_integer) - convert_int_uint (e2); - if (get_type (e2) != &type_uinteger) { - e->e.expr.e2 = e2 = cf_cast_expr (&type_uinteger, e2); - } - if ((conv = convert_to_uinteger (e2)) != e2) { - e->e.expr.e2 = e2 = conv; - } - } - - if (is_compare (op) || is_logic (op)) { - if (options.code.progsversion > PROG_ID_VERSION) - e->e.expr.type = &type_integer; - else - e->e.expr.type = &type_float; - } else { - e->e.expr.type = &type_uinteger; - } - - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) - return e; - - i1 = e1->e.uinteger_val; - i2 = e2->e.uinteger_val; - - switch (op) { - case '+': - e1->e.uinteger_val += i2; - break; - case '-': - e1->e.uinteger_val -= i2; - break; - case '*': - e1->e.uinteger_val *= i2; - break; - case '/': - if (options.warnings.integer_divide) - warning (e2, "%d / %d == %d", i1, i2, i1 / i2); - e1->e.uinteger_val /= i2; - break; - case '&': - e1->e.uinteger_val = i1 & i2; - break; - case '|': - e1->e.uinteger_val = i1 | i2; - break; - case '^': - e1->e.uinteger_val = i1 ^ i2; - break; - case '%': - e1->e.uinteger_val = i1 % i2; - break; - case SHL: - e1->e.uinteger_val = i1 << i2; - break; - case SHR: - e1->e.uinteger_val = i1 >> i2; - break; - case AND: - e1->e.uinteger_val = i1 && i2; - break; - case OR: - e1->e.uinteger_val = i1 || i2; - break; - case LT: - e1->type = ex_integer; - e1->e.integer_val = i1 < i2; - break; - case GT: - e1->type = ex_integer; - e1->e.integer_val = i1 > i2; - break; - case LE: - e1->type = ex_integer; - e1->e.integer_val = i1 <= i2; - break; - case GE: - e1->type = ex_integer; - e1->e.integer_val = i1 >= i2; - break; - case EQ: - e1->type = ex_integer; - e1->e.integer_val = i1 == i2; - break; - case NE: - e1->type = ex_integer; - e1->e.integer_val = i1 != i2; - break; - default: - return error (e1, "invalid operand for uinteger"); - } - return e1; -} - static expr_t * do_op_short (int op, expr_t *e, expr_t *e1, expr_t *e2) { @@ -896,19 +741,21 @@ do_op_struct (int op, expr_t *e, expr_t *e1, expr_t *e2) return e; } -static expr_t * -do_op_array (int op, expr_t *e, expr_t *e1, expr_t *e2) -{ - return e; -} - static expr_t * do_op_invalid (int op, expr_t *e, expr_t *e1, expr_t *e2) { - print_expr (e),puts(""); - return error (e1, "invalid operands for binary %s: %s %s", - get_op_string (op), pr_type_name[extract_type (e1)], - pr_type_name[extract_type (e2)]); + dstring_t *t1 = dstring_newstr (); + dstring_t *t2 = dstring_newstr (); + + print_type_str (t1, get_type (e1)); + print_type_str (t2, get_type (e2)); + + //print_expr (e),puts(""); + e1 = error (e1, "invalid operands for binary %s: %s %s", + get_op_string (op), t1->str, t2->str); + dstring_delete (t1); + dstring_delete (t2); + return e1; } typedef expr_t *(*operation_t) (int op, expr_t *e, expr_t *e1, expr_t *e2); @@ -924,13 +771,8 @@ static operation_t op_void[ev_type_count] = { do_op_invalid, // ev_pointer do_op_invalid, // ev_quaternion do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_string[ev_type_count] = { @@ -944,13 +786,8 @@ static operation_t op_string[ev_type_count] = { do_op_invalid, // ev_pointer do_op_invalid, // ev_quaternion do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_float[ev_type_count] = { @@ -964,13 +801,8 @@ static operation_t op_float[ev_type_count] = { do_op_invalid, // ev_pointer do_op_quaternion, // ev_quaternion do_op_float, // ev_integer - do_op_float, // ev_uinteger do_op_float, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_vector[ev_type_count] = { @@ -984,13 +816,8 @@ static operation_t op_vector[ev_type_count] = { do_op_invalid, // ev_pointer do_op_invalid, // ev_quaternion do_op_vector, // ev_integer - do_op_vector, // ev_uinteger do_op_vector, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_entity[ev_type_count] = { @@ -1004,13 +831,8 @@ static operation_t op_entity[ev_type_count] = { do_op_invalid, // ev_pointer do_op_invalid, // ev_quaternion do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_field[ev_type_count] = { @@ -1024,13 +846,8 @@ static operation_t op_field[ev_type_count] = { do_op_invalid, // ev_pointer do_op_invalid, // ev_quaternion do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_func[ev_type_count] = { @@ -1044,13 +861,8 @@ static operation_t op_func[ev_type_count] = { do_op_func, // ev_pointer do_op_func, // ev_quaternion do_op_func, // ev_integer - do_op_func, // ev_uinteger do_op_func, // ev_short - do_op_func, // ev_struct - do_op_func, // ev_object - do_op_func, // ev_class - do_op_func, // ev_sel - do_op_func, // ev_array + do_op_func, // ev_invalid }; static operation_t op_pointer[ev_type_count] = { @@ -1064,13 +876,8 @@ static operation_t op_pointer[ev_type_count] = { do_op_pointer, // ev_pointer do_op_pointer, // ev_quaternion do_op_pointer, // ev_integer - do_op_pointer, // ev_uinteger do_op_pointer, // ev_short - do_op_pointer, // ev_struct - do_op_pointer, // ev_object - do_op_pointer, // ev_class - do_op_pointer, // ev_sel - do_op_pointer, // ev_array + do_op_pointer, // ev_invalid }; static operation_t op_quaternion[ev_type_count] = { @@ -1084,13 +891,8 @@ static operation_t op_quaternion[ev_type_count] = { do_op_invalid, // ev_pointer do_op_quaternion, // ev_quaternion do_op_quaternion, // ev_integer - do_op_quaternion, // ev_uinteger do_op_quaternion, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_integer[ev_type_count] = { @@ -1104,33 +906,8 @@ static operation_t op_integer[ev_type_count] = { do_op_invalid, // ev_pointer do_op_quaternion, // ev_quaternion do_op_integer, // ev_integer - do_op_uinteger, // ev_uinteger do_op_integer, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_uinteger[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_float, // ev_float - do_op_vector, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_invalid, // ev_pointer - do_op_quaternion, // ev_quaternion - do_op_uinteger, // ev_integer - do_op_uinteger, // ev_uinteger - do_op_uinteger, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t op_short[ev_type_count] = { @@ -1144,113 +921,8 @@ static operation_t op_short[ev_type_count] = { do_op_invalid, // ev_pointer do_op_quaternion, // ev_quaternion do_op_integer, // ev_integer - do_op_uinteger, // ev_uinteger do_op_short, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_struct[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_invalid, // ev_float - do_op_invalid, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_pointer, // ev_pointer - do_op_invalid, // ev_quaternion - do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger - do_op_invalid, // ev_short - do_op_struct, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_object[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_invalid, // ev_float - do_op_invalid, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_invalid, // ev_pointer - do_op_invalid, // ev_quaternion - do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger - do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_class[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_invalid, // ev_float - do_op_invalid, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_invalid, // ev_pointer - do_op_invalid, // ev_quaternion - do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger - do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_sel[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_invalid, // ev_float - do_op_invalid, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_invalid, // ev_pointer - do_op_invalid, // ev_quaternion - do_op_invalid, // ev_integer - do_op_invalid, // ev_uinteger - do_op_invalid, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array -}; - -static operation_t op_array[ev_type_count] = { - do_op_invalid, // ev_void - do_op_invalid, // ev_string - do_op_invalid, // ev_float - do_op_invalid, // ev_vector - do_op_invalid, // ev_entity - do_op_invalid, // ev_field - do_op_invalid, // ev_func - do_op_invalid, // ev_pointer - do_op_invalid, // ev_quaternion - do_op_array, // ev_integer - do_op_array, // ev_uinteger - do_op_array, // ev_short - do_op_invalid, // ev_struct - do_op_invalid, // ev_object - do_op_invalid, // ev_class - do_op_invalid, // ev_sel - do_op_invalid, // ev_array + do_op_invalid, // ev_invalid }; static operation_t *do_op[ev_type_count] = { @@ -1264,13 +936,8 @@ static operation_t *do_op[ev_type_count] = { op_pointer, // ev_pointer op_quaternion, // ev_quaternion op_integer, // ev_integer - op_uinteger, // ev_uinteger op_short, // ev_short - op_struct, // ev_struct - op_object, // ev_object - op_class, // ev_class - op_sel, // ev_sel - op_array, // ev_array + op_void, // ev_invalid }; expr_t * @@ -1332,7 +999,10 @@ fold_constants (expr_t *e) if (op == 's') return e; - if (!do_op[t1][t2]) + if (is_struct (get_type (e1)) && is_struct (get_type (e2))) + return do_op_struct (op, e, e1, e2); + + if (!do_op[t1] || !do_op[t1][t2]) internal_error (e); return do_op[t1][t2] (op, e, e1, e2); } diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index 0af805459..f12bd3bbc 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -64,6 +64,7 @@ typedef struct locref_s { } locref_t; def_t def_void = { &type_void, "def void" }; +def_t def_invalid = { &type_invalid, "def invalid" }; def_t def_function = { &type_function, "def function" }; static def_t *free_temps[4]; // indexted by type size @@ -280,8 +281,8 @@ get_def (type_t *type, const char *name, scope_t *scope, // not valid for st_static or st_extern def->space = space; if (space) { - if (type->type == ev_field && type->aux_type == &type_vector) - def->ofs = new_location (type->aux_type, space); + if (type->type == ev_field && type->t.fldptr.type == &type_vector) + def->ofs = new_location (type->t.fldptr.type, space); else def->ofs = new_location (type, space); } @@ -299,14 +300,14 @@ get_def (type_t *type, const char *name, scope_t *scope, if (type->type == ev_field) { if (storage == st_global || storage == st_static) { - G_INT (def->ofs) = new_location (type->aux_type, + G_INT (def->ofs) = new_location (type->t.fldptr.type, pr.entity_data); reloc_def_field (def, def->ofs); def->constant = 1; def->nosave = 1; } - if (type->aux_type->type == ev_vector) { + if (type->t.fldptr.type->type == ev_vector) { vector_component (1, def, 0, scope, storage); vector_component (1, def, 1, scope, storage); vector_component (1, def, 2, scope, storage); @@ -524,7 +525,8 @@ def_initialized (def_t *d) { d->initialized = 1; if (d->type == &type_vector - || (d->type->type == ev_field && d->type->aux_type == &type_vector)) { + || (d->type->type == ev_field + && d->type->t.fldptr.type == &type_vector)) { d = d->def_next; d->initialized = 1; d = d->def_next; @@ -557,7 +559,7 @@ def_to_ddef (def_t *def, ddef_t *ddef, int aux) type_t *type = def->type; if (aux) - type = type->aux_type; + type = type->t.fldptr.type; // aux is true only for fields ddef->type = type->type; ddef->ofs = def->ofs; ddef->s_name = ReuseString (def->name); diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c index 91c6e87c8..2e5a96de2 100644 --- a/tools/qfcc/source/emit.c +++ b/tools/qfcc/source/emit.c @@ -45,6 +45,7 @@ static __attribute__ ((used)) const char rcsid[] = #include #include +#include "codespace.h" #include "def.h" #include "debug.h" #include "emit.h" @@ -60,43 +61,6 @@ static __attribute__ ((used)) const char rcsid[] = static expr_t zero; -codespace_t * -codespace_new (void) -{ - return calloc (1, sizeof (codespace_t)); -} - -void -codespace_delete (codespace_t *codespace) -{ - free (codespace->code); - free (codespace); -} - -void -codespace_addcode (codespace_t *codespace, dstatement_t *code, int size) -{ - if (codespace->size + size > codespace->max_size) { - codespace->max_size = (codespace->size + size + 16383) & ~16383; - codespace->code = realloc (codespace->code, - codespace->max_size * sizeof (dstatement_t)); - } - memcpy (codespace->code + codespace->size, code, - size * sizeof (dstatement_t)); - codespace->size += size; -} - -dstatement_t * -codespace_newstatement (codespace_t *codespace) -{ - if (codespace->size >= codespace->max_size) { - codespace->max_size += 16384; - codespace->code = realloc (codespace->code, - codespace->max_size * sizeof (dstatement_t)); - } - return codespace->code + codespace->size++; -} - static void add_statement_ref (def_t *def, dstatement_t *st, int field) { @@ -146,7 +110,7 @@ emit_statement (expr_t *e, opcode_t *op, def_t *var_a, def_t *var_b, statement->a = var_a ? var_a->ofs : 0; statement->b = var_b ? var_b->ofs : 0; statement->c = 0; - if (op->type_c == ev_void || op->right_associative) { + if (op->type_c == ev_invalid || op->right_associative) { // ifs, gotos, and assignments don't need vars allocated if (var_c) statement->c = var_c->ofs; @@ -230,6 +194,8 @@ emit_function_call (expr_t *e, def_t *dest) expr_t *earg; expr_t *parm; opcode_t *op; + type_t *t1 = &type_invalid; + type_t *t2 = &type_invalid; int count = 0, ind; const char *pref = ""; @@ -241,6 +207,10 @@ emit_function_call (expr_t *e, def_t *dest) parm = new_param_expr (get_type (earg), ind); if (options.code.progsversion != PROG_ID_VERSION && ind < 2) { pref = "R"; + if (ind == 1) + t2 = &type_void; + if (ind == 0) + t1 = &type_void; if (options.code.vector_calls && earg->type == ex_vector) { a[ind] = vector_call (earg, parm, ind); } else { @@ -248,7 +218,7 @@ emit_function_call (expr_t *e, def_t *dest) } continue; } - if (extract_type (parm) == ev_struct) { + if (is_struct (get_type (parm))) { expr_t *a = assign_expr (parm, earg); a->line = e->line; a->file = e->file; @@ -260,19 +230,18 @@ emit_function_call (expr_t *e, def_t *dest) p = emit_sub_expr (parm, 0); arg = emit_sub_expr (earg, p); if (arg != p) { - op = opcode_find ("=", arg->type, arg->type, &type_void); + op = opcode_find ("=", arg->type, arg->type, &type_invalid); emit_statement (e, op, arg, p, 0); } } } } - op = opcode_find (va ("<%sCALL%d>", pref, count), - &type_function, &type_void, &type_void); + op = opcode_find (va ("<%sCALL%d>", pref, count), &type_function, t1, t2); emit_statement (e, op, func, a[0], a[1]); - ret = emit_sub_expr (new_ret_expr (func->type->aux_type), 0); + ret = emit_sub_expr (new_ret_expr (func->type->t.func.type), 0); if (dest) { - op = opcode_find ("=", dest->type, ret->type, &type_void); + op = opcode_find ("=", dest->type, ret->type, &type_invalid); emit_statement (e, op, ret, dest, 0); return dest; } else { @@ -319,7 +288,8 @@ emit_assign_expr (int oper, expr_t *e) } def_b = emit_sub_expr (e2, def_a); if (def_b != def_a) { - op = opcode_find (operator, def_b->type, def_a->type, &type_void); + op = opcode_find (operator, def_b->type, def_a->type, + &type_invalid); emit_statement (e, op, def_b, def_a, 0); } return def_a; @@ -335,7 +305,7 @@ emit_assign_expr (int oper, expr_t *e) } else { def_a = emit_sub_expr (e1, 0); def_c = 0; - op = opcode_find (operator, def_b->type, def_a->type, &type_void); + op = opcode_find (operator, def_b->type, def_a->type, &type_invalid); } emit_statement (e, op, def_b, def_a, def_c); return def_b; @@ -382,24 +352,27 @@ emit_move_expr (expr_t *e) src = emit_sub_expr (e2, 0); dst = emit_sub_expr (e1, 0); - if (dst_type->type == ev_struct && src_type->type == ev_struct) { + if (is_struct (dst_type) && is_struct (src_type)) { size_expr = new_short_expr (type_size (dst->type)); - } else if (dst_type->type == ev_struct) { + dst_type = src_type = &type_void; + } else if (is_struct (dst_type)) { if (dst->alias) dst = dst->alias; dst = emit_sub_expr (address_expr (new_def_expr (dst), 0, 0), 0); + dst_type = dst->type; size_expr = new_integer_expr (type_size (dst_type)); - } else if (src_type->type == ev_struct) { + } else if (is_struct (src_type)) { if (src->alias) src = src->alias; src = emit_sub_expr (address_expr (new_def_expr (src), 0, 0), 0); - size_expr = new_integer_expr (type_size (dst_type->aux_type)); + src_type = src->type; + size_expr = new_integer_expr (type_size (dst_type->t.fldptr.type)); } else { - size_expr = new_integer_expr (type_size (dst_type->aux_type)); + size_expr = new_integer_expr (type_size (dst_type->t.fldptr.type)); } size = emit_sub_expr (size_expr, 0); - op = opcode_find ("", src->type, size->type, dst->type); + op = opcode_find ("", src_type, size->type, dst_type); return emit_statement (e, op, src, size, dst); } @@ -445,7 +418,7 @@ emit_deref_expr (expr_t *e, def_t *dest) } if (e->type == ex_uexpr && e->e.expr.op == '&' && e->e.expr.e1->type == ex_def) { - d = new_def (e->e.expr.type->aux_type, 0, current_scope); + d = new_def (e->e.expr.type->t.fldptr.type, 0, current_scope); d->alias = e->e.expr.e1->e.def; d->local = d->alias->local; d->ofs = d->alias->ofs; @@ -457,7 +430,7 @@ emit_deref_expr (expr_t *e, def_t *dest) dest->file = e->file; dest->users += 2; } - if (dest->type->type == ev_struct) { + if (is_struct (dest->type)) { expr_t *d = new_def_expr (dest); expr_t *m = new_move_expr (d, e, dest->type); d->line = dest->line; @@ -685,12 +658,12 @@ emit_sub_expr (expr_t *e, def_t *dest) case '!': operator = "!"; def_a = emit_sub_expr (e->e.expr.e1, 0); - def_b = &def_void; + def_b = &def_invalid; break; case '~': operator = "~"; def_a = emit_sub_expr (e->e.expr.e1, 0); - def_b = &def_void; + def_b = &def_invalid; break; case '-': zero.type = expr_types[extract_type (e->e.expr.e1)]; @@ -738,15 +711,9 @@ emit_sub_expr (expr_t *e, def_t *dest) return def_a; } if ((def_a->type->type == ev_pointer - && (e->e.expr.type->type == ev_integer - || e->e.expr.type->type == ev_uinteger)) - || ((def_a->type->type == ev_integer - || def_a->type->type == ev_uinteger) - && e->e.expr.type->type == ev_pointer) + && e->e.expr.type->type == ev_integer) || (def_a->type->type == ev_integer - && e->e.expr.type->type == ev_uinteger) - || (def_a->type->type == ev_uinteger - && e->e.expr.type->type == ev_integer)) { + && e->e.expr.type->type == ev_pointer)) { def_t *tmp; tmp = new_def (e->e.expr.type, 0, def_a->scope); tmp->ofs = 0; @@ -755,7 +722,7 @@ emit_sub_expr (expr_t *e, def_t *dest) tmp->freed = 1; return tmp; } - def_b = &def_void; + def_b = &def_invalid; if (!dest) { dest = get_tempdef (e->e.expr.type, current_scope); dest->file = e->file; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index b4d7f0120..913f64a5b 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -88,11 +88,11 @@ etype_t qc_types[] = { ev_pointer, // ex_pointer ev_quat, // ex_quaternion ev_integer, // ex_integer - ev_uinteger, // ex_uinteger + ev_integer, // ex_uinteger ev_short, // ex_short }; -type_t *ev_types[] = { +type_t *ev_types[ev_type_count] = { &type_void, &type_string, &type_float, @@ -103,13 +103,8 @@ type_t *ev_types[] = { &type_pointer, &type_quaternion, &type_integer, - &type_uinteger, &type_short, &type_void, // FIXME what type? - &type_void, // FIXME what type? - &type_void, // FIXME what type? - &type_SEL, - &type_void, // FIXME what type? }; expr_type expr_types[] = { @@ -286,19 +281,60 @@ get_op_string (int op) expr_t * type_mismatch (expr_t *e1, expr_t *e2, int op) { - etype_t t1, t2; + dstring_t *t1 = dstring_newstr (); + dstring_t *t2 = dstring_newstr (); - t1 = extract_type (e1); - t2 = extract_type (e2); + print_type_str (t1, get_type (e1)); + print_type_str (t2, get_type (e2)); - if (0) { - print_type (get_type (e1)); - print_type (get_type (e2)); - printf ("\n%p %p\n", get_type (e1), get_type (e2)); - } + e1 = error (e1, "type mismatch: %s %s %s", + t1->str, get_op_string (op), t2->str); + dstring_delete (t1); + dstring_delete (t2); + return e1; +} - return error (e1, "type mismatch: %s %s %s", - pr_type_name[t1], get_op_string (op), pr_type_name[t2]); +expr_t * +param_mismatch (expr_t *e, int param, const char *fn, type_t *t1, type_t *t2) +{ + dstring_t *s1 = dstring_newstr (); + dstring_t *s2 = dstring_newstr (); + + print_type_str (s1, t1); + print_type_str (s2, t2); + + e = error (e, "type mismatch for parameter %d of %s: %s %s", param, fn, + s1->str, s2->str); + dstring_delete (s1); + dstring_delete (s2); + return e; +} + +expr_t * +cast_error (expr_t *e, type_t *t1, type_t *t2) +{ + dstring_t *s1 = dstring_newstr (); + dstring_t *s2 = dstring_newstr (); + + print_type_str (s1, t1); + print_type_str (s2, t2); + + e = error (e, "can not cast from %s to %s", s1->str, s2->str); + dstring_delete (s1); + dstring_delete (s2); + return e; +} + +expr_t * +test_error (expr_t *e, type_t *t) +{ + dstring_t *s = dstring_newstr (); + + print_type_str (s, t); + + e = error (e, "%s cannot be tested", s->str); + dstring_delete (s); + return e; } static void @@ -309,7 +345,7 @@ check_initialized (expr_t *e) if (e->type == ex_def && !(e->e.def->type->type == ev_func && !e->e.def->local) - && !(e->e.def->type->type == ev_struct) + && !is_struct (e->e.def->type) && !e->e.def->external && !e->e.def->initialized) { name = e->e.def->name; @@ -640,8 +676,8 @@ constant_expr (expr_t *var) return new_field_expr (G_INT (def->ofs), def->type, def); case ev_integer: return new_integer_expr (G_INT (def->ofs)); - case ev_uinteger: - return new_uinteger_expr (G_INT (def->ofs)); +// case ev_uinteger: +// return new_uinteger_expr (G_INT (def->ofs)); default: return var; } @@ -883,52 +919,54 @@ field_expr (expr_t *e1, expr_t *e2) return e1; t1 = get_type (e1); switch (t1->type) { - case ev_struct: - case ev_class: - check_initialized (e1); - if (e2->type != ex_name) - return error (e2, "structure field name expected"); - if (t1->type == ev_struct) - strct = t1->s.strct; - else - strct = t1->s.class->ivars; - field = struct_find_field (strct, e2->e.string_val); - if (!field) - return error (e2, "structure has no field %s", - e2->e.string_val); - e2->type = ex_short; - e2->e.short_val = field->offset; - e = unary_expr ('.', address_expr (e1, e2, field->type)); - return e; + case ev_invalid: + if (t1->ty == ty_struct || t1->ty == ty_class) { + check_initialized (e1); + if (e2->type != ex_name) + return error (e2, "structure field name expected"); + if (t1->ty == ty_struct) + strct = t1->t.strct; + else + strct = t1->t.class->ivars; + field = struct_find_field (strct, e2->e.string_val); + if (!field) + return error (e2, "structure has no field %s", + e2->e.string_val); + e2->type = ex_short; + e2->e.short_val = field->offset; + e = unary_expr ('.', address_expr (e1, e2, field->type)); + return e; + } + break; case ev_pointer: check_initialized (e1); - switch (t1->aux_type->type) { - case ev_struct: - if (e2->type == ex_name) { - field = struct_find_field (t1->aux_type->s.strct, - e2->e.string_val); - if (!field) - return error (e2, "structure has no field %s", - e2->e.string_val); - e2->type = ex_short; - e2->e.short_val = field->offset; - t1 = pointer_type (field->type); - } - break; - case ev_object: - case ev_class: - if (e2->type == ex_name) { - int protected; + switch (t1->t.fldptr.type->type) { + case ev_invalid: + if (t1->t.fldptr.type->ty == ty_struct) { + if (e2->type == ex_name) { + field = struct_find_field (t1->t.fldptr.type->t.strct, + e2->e.string_val); + if (!field) + return error (e2, "structure has no field %s", + e2->e.string_val); + e2->type = ex_short; + e2->e.short_val = field->offset; + t1 = pointer_type (field->type); + } + } else if (t1->t.fldptr.type->ty == ty_class) { + if (e2->type == ex_name) { + int protected; - class = t1->aux_type->s.class; - protected = class_access (current_class, class); - field = class_find_ivar (class, protected, - e2->e.string_val); - if (!field) - return new_error_expr (); - e2->type = ex_short; - e2->e.short_val = field->offset; - t1 = pointer_type (field->type); + class = t1->t.fldptr.type->t.class; + protected = class_access (current_class, class); + field = class_find_ivar (class, protected, + e2->e.string_val); + if (!field) + return new_error_expr (); + e2->type = ex_short; + e2->e.short_val = field->offset; + t1 = pointer_type (field->type); + } } break; default: @@ -944,7 +982,7 @@ field_expr (expr_t *e1, expr_t *e2) } else { break; } - e1->e.pointer.type = t1->aux_type; + e1->e.pointer.type = t1->t.fldptr.type; return unary_expr ('.', e1); } else { e = new_binary_expr ('&', e1, e2); @@ -966,7 +1004,7 @@ field_expr (expr_t *e1, expr_t *e2) e2 = new_def_expr (d); t2 = get_type (e2); e = new_binary_expr ('.', e1, e2); - e->e.expr.type = t2->aux_type; + e->e.expr.type = t2->t.fldptr.type; return e; } else { t2 = get_type (e2); @@ -974,7 +1012,7 @@ field_expr (expr_t *e1, expr_t *e2) return e2; if (t2->type == ev_field) { e = new_binary_expr ('.', e1, e2); - e->e.expr.type = t2->aux_type; + e->e.expr.type = t2->t.fldptr.type; return e; } } @@ -1116,7 +1154,7 @@ test_expr (expr_t *e, int test) case ev_string: new = new_string_expr (0); break; - case ev_uinteger: +// case ev_uinteger: case ev_integer: case ev_short: return e; @@ -1144,12 +1182,8 @@ test_expr (expr_t *e, int test) case ev_quat: new = new_quaternion_expr (zero); break; - case ev_struct: - case ev_object: - case ev_class: - case ev_sel: - case ev_array: - return error (e, "%s cannot be tested", pr_type_name[type]); + case ev_invalid: + return test_error (e, get_type (e)); } new->line = e->line; new->file = e->file; @@ -1270,9 +1304,9 @@ convert_from_bool (expr_t *e, type_t *type) } else if (type == &type_integer) { one = new_integer_expr (1); zero = new_integer_expr (0); - } else if (type == &type_uinteger) { - one = new_uinteger_expr (1); - zero = new_uinteger_expr (0); +// } else if (type == &type_uinteger) { +// one = new_uinteger_expr (1); +// zero = new_uinteger_expr (0); } else { return error (e, "can't convert from bool value"); } @@ -1581,9 +1615,9 @@ binary_expr (int op, expr_t *e1, expr_t *e2) if (t2 == &type_integer) { convert_short_int (e1); t1 = &type_integer; - } else if (t2 == &type_uinteger) { - convert_short_uint (e1); - t1 = &type_uinteger; +// } else if (t2 == &type_uinteger) { +// convert_short_uint (e1); +// t1 = &type_uinteger; } } @@ -1591,9 +1625,9 @@ binary_expr (int op, expr_t *e1, expr_t *e2) if (t1 == &type_integer) { convert_short_int (e2); t2 = &type_integer; - } else if (t1 == &type_uinteger) { - convert_short_uint (e2); - t2 = &type_uinteger; +// } else if (t1 == &type_uinteger) { +// convert_short_uint (e2); +// t2 = &type_uinteger; } } @@ -1603,9 +1637,9 @@ binary_expr (int op, expr_t *e1, expr_t *e2) || t2 == &type_quaternion) { convert_int (e1); t1 = &type_float; - } else if (t2 == &type_uinteger) { - convert_int_uint (e1); - t1 = &type_uinteger; +// } else if (t2 == &type_uinteger) { +// convert_int_uint (e1); +// t1 = &type_uinteger; } } else if (e1->type == ex_uinteger) { if (t2 == &type_float @@ -1623,9 +1657,9 @@ binary_expr (int op, expr_t *e1, expr_t *e2) || t1 == &type_quaternion) { convert_int (e2); t2 = &type_float; - } else if (t1 == &type_uinteger) { - convert_int_uint (e2); - t2 = &type_uinteger; +// } else if (t1 == &type_uinteger) { +// convert_int_uint (e2); +// t2 = &type_uinteger; } } else if (e2->type == ex_uinteger) { if (t1 == &type_float @@ -1659,8 +1693,8 @@ binary_expr (int op, expr_t *e1, expr_t *e2) } break; case ev_field: - if (t1->aux_type == t2) { - type = t1->aux_type; + if (t1->t.fldptr.type == t2) { + type = t1->t.fldptr.type; } else { goto type_mismatch; } @@ -1943,7 +1977,7 @@ bitnot_expr: if (extract_type (e) != ev_pointer) return error (e, "invalid type for unary ."); e = new_unary_expr ('.', e); - e->e.expr.type = get_type (e->e.expr.e1)->aux_type; + e->e.expr.type = get_type (e->e.expr.e1)->t.fldptr.type; return e; } error (e, "internal error"); @@ -1972,24 +2006,24 @@ build_function_call (expr_t *fexpr, type_t *ftype, expr_t *params) if (arg_count > MAX_PARMS) { return error (fexpr, "more than %d parameters", MAX_PARMS); } - if (ftype->num_parms < -1) { - if (-arg_count > ftype->num_parms + 1) { + if (ftype->t.func.num_params < -1) { + if (-arg_count > ftype->t.func.num_params + 1) { if (!options.traditional) return error (fexpr, "too few arguments"); if (options.warnings.traditional) warning (fexpr, "too few arguments"); } - parm_count = -ftype->num_parms - 1; - } else if (ftype->num_parms >= 0) { - if (arg_count > ftype->num_parms) { + parm_count = -ftype->t.func.num_params - 1; + } else if (ftype->t.func.num_params >= 0) { + if (arg_count > ftype->t.func.num_params) { return error (fexpr, "too many arguments"); - } else if (arg_count < ftype->num_parms) { + } else if (arg_count < ftype->t.func.num_params) { if (!options.traditional) return error (fexpr, "too few arguments"); if (options.warnings.traditional) warning (fexpr, "too few arguments"); } - parm_count = ftype->num_parms; + parm_count = ftype->t.func.num_params; } for (i = arg_count - 1, e = params; i >= 0; i--, e = e->next) { type_t *t = get_type (e); @@ -2001,24 +2035,22 @@ build_function_call (expr_t *fexpr, type_t *ftype, expr_t *params) err = error (e, "formal parameter %d is too large to be passed by" " value", i + 1); check_initialized (e); - if (ftype->parm_types[i] == &type_float && e->type == ex_integer) { + if (ftype->t.func.param_types[i] == &type_float && e->type == ex_integer) { convert_int (e); t = &type_float; } if (i < parm_count) { if (e->type == ex_nil) - convert_nil (e, t = ftype->parm_types[i]); + convert_nil (e, t = ftype->t.func.param_types[i]); if (e->type == ex_bool) - convert_from_bool (e, ftype->parm_types[i]); + convert_from_bool (e, ftype->t.func.param_types[i]); if (e->type == ex_error) return e; - if (!type_assignable (ftype->parm_types[i], t)) { - print_type (ftype->parm_types[i]); puts (""); - print_type (t); puts (""); - err = error (e, "type mismatch for parameter %d of %s", - i + 1, fexpr->e.def->name); + if (!type_assignable (ftype->t.func.param_types[i], t)) { + err = param_mismatch (e, i + 1, fexpr->e.def->name, + ftype->t.func.param_types[i], t); } - t = ftype->parm_types[i]; + t = ftype->t.func.param_types[i]; } else { if (e->type == ex_nil) convert_nil (e, t = &type_vector); //XXX largest param size @@ -2065,10 +2097,10 @@ build_function_call (expr_t *fexpr, type_t *ftype, expr_t *params) append_expr (call, e); } e = new_binary_expr ('c', fexpr, args); - e->e.expr.type = ftype->aux_type; + e->e.expr.type = ftype->t.func.type; append_expr (call, e); - if (ftype->aux_type != &type_void) { - call->e.block.result = new_ret_expr (ftype->aux_type); + if (ftype->t.func.type != &type_void) { + call->e.block.result = new_ret_expr (ftype->t.func.type); } else if (options.traditional) { call->e.block.result = new_ret_expr (&type_float); } @@ -2116,7 +2148,7 @@ return_expr (function_t *f, expr_t *e) type_t *t; if (!e) { - if (f->def->type->aux_type != &type_void) { + if (f->def->type->t.func.type != &type_void) { if (options.traditional) { if (options.warnings.traditional) warning (e, @@ -2134,15 +2166,15 @@ return_expr (function_t *f, expr_t *e) if (e->type == ex_error) return e; - if (f->def->type->aux_type == &type_void) { + if (f->def->type->t.func.type == &type_void) { if (!options.traditional) return error (e, "returning a value for a void function"); if (options.warnings.traditional) warning (e, "returning a value for a void function"); } if (e->type == ex_bool) - e = convert_from_bool (e, f->def->type->aux_type); - if (f->def->type->aux_type == &type_float && e->type == ex_integer) { + e = convert_from_bool (e, f->def->type->t.func.type); + if (f->def->type->t.func.type == &type_float && e->type == ex_integer) { e->type = ex_float; e->e.float_val = e->e.integer_val; t = &type_float; @@ -2150,7 +2182,7 @@ return_expr (function_t *f, expr_t *e) check_initialized (e); if (t == &type_void) { if (e->type == ex_nil) { - t = f->def->type->aux_type; + t = f->def->type->t.func.type; e->type = expr_types[t->type]; if (e->type == ex_nil) return error (e, "invalid return type for NIL"); @@ -2162,7 +2194,7 @@ return_expr (function_t *f, expr_t *e) //FIXME does anything need to be done here? } } - if (!type_assignable (f->def->type->aux_type, t)) { + if (!type_assignable (f->def->type->t.func.type, t)) { if (!options.traditional) return error (e, "type mismatch for return value of %s", f->def->name); @@ -2170,8 +2202,8 @@ return_expr (function_t *f, expr_t *e) warning (e, "type mismatch for return value of %s", f->def->name); } else { - if (f->def->type->aux_type != t) - e = cast_expr (f->def->type->aux_type, e); + if (f->def->type->t.func.type != t) + e = cast_expr (f->def->type->t.func.type, e); } return new_unary_expr ('r', e); } @@ -2256,29 +2288,33 @@ array_expr (expr_t *array, expr_t *index) if (index->type == ex_error) return index; - if (array_type->type != ev_pointer && array_type->type != ev_array) + if (array_type->type != ev_pointer && !is_array (array_type)) return error (array, "not an array"); - if (index_type != &type_integer && index_type != &type_uinteger) + if (index_type != &type_integer) return error (index, "invalid array index type"); - if (array_type->num_parms + if (array_type->t.func.num_params && index->type >= ex_integer - && index->e.uinteger_val >= (unsigned int) array_type->num_parms) + && (index->e.integer_val < array_type->t.array.base + || index->e.integer_val - array_type->t.array.base + >= array_type->t.array.size)) return error (index, "array index out of bounds"); - size = type_size (array_type->aux_type); - if (size > 1) { - scale = new_expr (); - scale->type = expr_types[index_type->type]; - scale->e.integer_val = size; - index = binary_expr ('*', index, scale); - } + size = type_size (array_type->t.array.type); + scale = new_expr (); + scale->type = expr_types[index_type->type]; + scale->e.integer_val = size; + index = binary_expr ('*', index, scale); + index = binary_expr ('-', index, + binary_expr ('*', scale, + new_integer_expr (array_type->t.array.base))); + index = fold_constants (index); if ((index->type == ex_integer && index->e.integer_val < 32768 && index->e.integer_val >= -32768) || (index->type == ex_uinteger && index->e.uinteger_val < 32768)) { index->type = ex_short; } - if (array_type->type == ev_array) { - e = address_expr (array, index, array_type->aux_type); + if (is_array (array_type)) { + e = address_expr (array, index, array_type->t.array.type); } else { if (index->type != ex_short || index->e.integer_val) { e = new_binary_expr ('&', array, index); @@ -2322,11 +2358,11 @@ address_expr (expr_t *e1, expr_t *e2, type_t *t) def_t *def = e1->e.def; def->used = 1; type = def->type; - if (type->type == ev_struct || type->type == ev_class) { + if (is_struct (type) || is_class (type)) { e = new_pointer_expr (0, t, def); e->line = e1->line; e->file = e1->file; - } else if (type->type == ev_array) { + } else if (is_array (type)) { e = e1; e->type = ex_pointer; e->e.pointer.val = 0; @@ -2456,10 +2492,10 @@ assign_expr (expr_t *e1, expr_t *e2) abort (); } //XXX func = func ??? - if (t1->type != ev_pointer || t2->type != ev_array) + if (t1->type != ev_pointer || !is_array (t2)) check_initialized (e2); else { - e2 = address_expr (e2, 0, t2->aux_type); + e2 = address_expr (e2, 0, t2->t.fldptr.type); // FIXME t2 = get_type (e2); } if (e2->type == ex_bool) @@ -2491,7 +2527,7 @@ assign_expr (expr_t *e1, expr_t *e2) } type = t1; if (is_indirect (e1) && is_indirect (e2)) { - if (extract_type (e2) == ev_struct) { + if (is_struct (get_type (e2))) { e1 = address_expr (e1, 0, 0); e2 = address_expr (e2, 0, 0); e = new_move_expr (e1, e2, get_type (e2)); @@ -2505,7 +2541,7 @@ assign_expr (expr_t *e1, expr_t *e2) } return e; } else if (is_indirect (e1)) { - if (extract_type (e1) == ev_struct) { + if (is_struct (get_type (e1))) { e1 = address_expr (e1, 0, 0); return new_move_expr (e1, e2, get_type (e2)); } @@ -2526,7 +2562,7 @@ assign_expr (expr_t *e1, expr_t *e2) } } } else if (is_indirect (e2)) { - if (extract_type (e1) == ev_struct) { + if (is_struct (get_type (e1))) { e2 = address_expr (e2, 0, 0); e2->rvalue = 1; return new_move_expr (e1, e2, get_type (e2)); @@ -2547,7 +2583,7 @@ assign_expr (expr_t *e1, expr_t *e2) } } } - if (extract_type (e1) == ev_struct) { + if (is_struct (get_type (e1))) { return new_move_expr (e1, e2, get_type (e2)); } if (!type) @@ -2578,19 +2614,17 @@ cast_expr (type_t *type, expr_t *e) if (!(type->type == ev_pointer && (e_type->type == ev_pointer - || e_type == &type_integer || e_type == &type_uinteger - || e_type->type == ev_array)) + || e_type == &type_integer //|| e_type == &type_uinteger + || is_array (e_type))) && !(type->type == ev_func && e_type->type == ev_func) - && !(((type == &type_integer || type == &type_uinteger) + && !(((type == &type_integer) && (e_type == &type_float || e_type == &type_integer - || e_type == &type_uinteger || e_type->type == ev_pointer)) + || e_type->type == ev_pointer)) || (type == &type_float - && (e_type == &type_integer || e_type == &type_uinteger)))) { - return error (e, "can not cast from %s to %s", - pr_type_name[extract_type (e)], - pr_type_name[type->type]); + && (e_type == &type_integer)))) { + return cast_error (e, get_type (e), type); } - if (e_type ->type == ev_array) { + if (is_array (e_type)) { return address_expr (e, 0, 0); } if (e->type == ex_uexpr && e->e.expr.op == '.') { @@ -2614,21 +2648,21 @@ init_elements (def_t *def, expr_t *eles) ofs = def->ofs; if (def->local && local_expr) ofs = 0; - if (def->type->type == ev_array) { - elements = calloc (def->type->num_parms, sizeof (def_t)); - for (i = 0; i < def->type->num_parms; i++) { - elements[i].type = def->type->aux_type; - elements[i].ofs = ofs + i * type_size (def->type->aux_type); + if (is_array (def->type)) { + elements = calloc (def->type->t.array.size, sizeof (def_t)); + for (i = 0; i < def->type->t.array.size; i++) { + elements[i].type = def->type->t.array.type; + elements[i].ofs = ofs + i * type_size (def->type->t.array.type); } num_params = i; - } else if (def->type->type == ev_struct) { + } else if (is_struct (def->type)) { struct_field_t *field; - for (i = 0, field = def->type->s.strct->struct_head; field; + for (i = 0, field = def->type->t.strct->struct_head; field; i++, field = field->next) ; elements = calloc (i, sizeof (def_t)); - for (i = 0, field = def->type->s.strct->struct_head; field; + for (i = 0, field = def->type->t.strct->struct_head; field; i++, field = field->next) { elements[i].type = field->type; elements[i].ofs = ofs + field->offset; @@ -2652,8 +2686,8 @@ init_elements (def_t *def, expr_t *eles) g = G_POINTER (pr_type_t, elements[i].ofs); c = constant_expr (e); if (c->type == ex_block) { - if (elements[i].type->type != ev_array - && elements[i].type->type != ev_struct) { + if (!is_array (elements[i].type) + && !is_struct (elements[i].type)) { error (e, "type mismatch in initializer"); continue; } @@ -2663,15 +2697,6 @@ init_elements (def_t *def, expr_t *eles) if (c->type == ex_integer && elements[i].type->type == ev_float) convert_int (c); - else if (c->type == ex_integer - && elements[i].type->type == ev_uinteger) - convert_int_uint (c); - else if (c->type == ex_uinteger - && elements[i].type->type == ev_float) - convert_uint (c); - else if (c->type == ex_uinteger - && elements[i].type->type == ev_integer) - convert_uint_int (c); if (get_type (c) != elements[i].type) { error (e, "type mismatch in initializer"); continue; @@ -2711,8 +2736,8 @@ selector_expr (keywordarg_t *selector) selector = (keywordarg_t *) reverse_params ((param_t *) selector); selector_name (sel_id, selector); index = selector_index (sel_id->str); - index *= type_size (type_SEL.aux_type); - sel_def = get_def (type_SEL.aux_type, "_OBJ_SELECTOR_TABLE", pr.scope, + index *= type_size (type_SEL.t.fldptr.type); + sel_def = get_def (type_SEL.t.fldptr.type, "_OBJ_SELECTOR_TABLE", pr.scope, st_extern); sel = new_def_expr (sel_def); dstring_delete (sel_id); @@ -2756,8 +2781,7 @@ super_expr (class_type_t *class_type) if (!class->super_class) return error (new_expr (), "%s has no super class", class->name); - super_d = get_def (type_Super.aux_type, ".super", current_func->scope, - st_local); + super_d = get_def (&type_Super, ".super", current_func->scope, st_local); def_initialized (super_d); super = new_def_expr (super_d); super_block = new_block_expr (); @@ -2812,22 +2836,27 @@ message_expr (expr_t *receiver, keywordarg_t *message) if (receiver->type == ex_error) return receiver; - if (rec_type->type != ev_pointer - || (rec_type->aux_type->type != ev_object - && rec_type->aux_type->type != ev_class)) + if (!(rec_type->type == ev_pointer + && is_class (rec_type->t.fldptr.type)) + && !is_class (rec_type)) return error (receiver, "not a class/object"); if (self) { class = extract_class (current_class); if (rec_type == &type_Class) class_msg = 1; } else { - class = rec_type->aux_type->s.class; + if (is_class (rec_type)) { + class = rec_type->t.class; + receiver = address_expr (receiver, 0, 0); + } else { + class = rec_type->t.fldptr.type->t.class; + } } } method = class_message_response (class, class_msg, selector); if (method) - rec_type = method->type->aux_type; + rec_type = method->type->t.func.type; for (m = message; m; m = m->next) { *a = m->expr; diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 52dd77132..9a73a40c5 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -48,6 +48,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "qfcc.h" +#include "codespace.h" #include "debug.h" #include "def.h" #include "emit.h" @@ -131,11 +132,11 @@ parse_params (type_t *type, param_t *parms) memset (&new, 0, sizeof (new)); new.type = ev_func; - new.aux_type = type; - new.num_parms = 0; + new.t.func.type = type; + new.t.func.num_params = 0; for (p = parms; p; p = p->next) { - if (new.num_parms > MAX_PARMS) { + if (new.t.func.num_params > MAX_PARMS) { error (0, "too many params"); return type; } @@ -144,10 +145,10 @@ parse_params (type_t *type, param_t *parms) error (0, "internal error"); abort (); } - new.num_parms = -(new.num_parms + 1); + new.t.func.num_params = -(new.t.func.num_params + 1); } else if (p->type) { - new.parm_types[new.num_parms] = p->type; - new.num_parms++; + new.t.func.param_types[new.t.func.num_params] = p->type; + new.t.func.num_params++; } } //print_type (&new); puts(""); @@ -229,8 +230,8 @@ func_compare (const void *a, const void *b) overloaded_function_t *fb = *(overloaded_function_t **) b; type_t *ta = fa->type; type_t *tb = fb->type; - int na = ta->num_parms; - int nb = tb->num_parms; + int na = ta->t.func.num_params; + int nb = tb->t.func.num_params; int ret, i; if (na < 0) @@ -239,11 +240,11 @@ func_compare (const void *a, const void *b) nb = ~nb; if (na != nb) return nb - na; - if ((ret = (fb->type->num_parms - fa->type->num_parms))) + if ((ret = (fb->type->t.func.num_params - fa->type->t.func.num_params))) return ret; for (i = 0; i < na && i < nb; i++) - if (ta->parm_types[i] != tb->parm_types[i]) - return (long)(tb->parm_types[i] - ta->parm_types[i]); + if (ta->t.func.param_types[i] != tb->t.func.param_types[i]) + return (long)(tb->t.func.param_types[i] - ta->t.func.param_types[i]); return 0; } @@ -264,12 +265,12 @@ find_function (expr_t *fexpr, expr_t *params) for (e = params; e; e = e->next) { if (e->type == ex_error) return e; - type.num_parms++; + type.t.func.num_params++; } - if (type.num_parms > MAX_PARMS) + if (type.t.func.num_params > MAX_PARMS) return fexpr; for (i = 0, e = params; e; i++, e = e->next) { - type.parm_types[type.num_parms - 1 - i] = get_type (e); + type.t.func.param_types[type.t.func.num_params - 1 - i] = get_type (e); if (e->type == ex_error) return e; } @@ -282,7 +283,7 @@ find_function (expr_t *fexpr, expr_t *params) free (funcs); return fexpr; } - type.aux_type = ((overloaded_function_t *) funcs[0])->type->aux_type; + type.t.func.type = ((overloaded_function_t *) funcs[0])->type->t.func.type; dummy.type = find_type (&type); qsort (funcs, func_count, sizeof (void *), func_compare); @@ -299,17 +300,17 @@ find_function (expr_t *fexpr, expr_t *params) } for (i = 0; i < func_count; i++) { f = (overloaded_function_t *) funcs[i]; - parm_count = f->type->num_parms; - if ((parm_count >= 0 && parm_count != type.num_parms) - || (parm_count < 0 && ~parm_count > type.num_parms)) { + parm_count = f->type->t.func.num_params; + if ((parm_count >= 0 && parm_count != type.t.func.num_params) + || (parm_count < 0 && ~parm_count > type.t.func.num_params)) { funcs[i] = 0; continue; } if (parm_count < 0) parm_count = ~parm_count; for (j = 0; j < parm_count; j++) { - if (!type_assignable (f->type->parm_types[j], - type.parm_types[j])) { + if (!type_assignable (f->type->t.func.param_types[j], + type.t.func.param_types[j])) { funcs[i] = 0; break; } @@ -352,13 +353,13 @@ check_function (def_t *func, param_t *params) param_t *p; int i; - if (!type_size (func->type->aux_type)) { + if (!type_size (func->type->t.func.type)) { error (0, "return type is an incomplete type"); - func->type->aux_type = &type_void;//FIXME + func->type->t.func.type = &type_void;//FIXME } - if (type_size (func->type->aux_type) > type_size (&type_param)) { + if (type_size (func->type->t.func.type) > type_size (&type_param)) { error (0, "return value too large to be passed by value"); - func->type->aux_type = &type_void;//FIXME + func->type->t.func.type = &type_void;//FIXME } for (p = params, i = 0; p; p = p->next, i++) { if (!p->selector && !p->type && !p->name) @@ -387,7 +388,7 @@ build_scope (function_t *f, def_t *func, param_t *params) f->scope = new_scope (sc_params, new_defspace (), pr.scope); - if (func->type->num_parms < 0) { + if (func->type->t.func.num_params < 0) { args = get_def (&type_va_list, ".args", f->scope, st_local); args->used = 1; def_initialized (args); @@ -461,7 +462,7 @@ begin_function (def_t *def, const char *nicename, param_t *params) func->aux->source_line = def->line; func->aux->line_info = lineno - pr.linenos; func->aux->local_defs = pr.num_locals; - func->aux->return_type = def->type->aux_type->type; + func->aux->return_type = def->type->t.func.type->type; lineno->fa.func = func->aux - pr.auxfunctions; } @@ -581,12 +582,12 @@ function_parms (function_t *f, byte *parm_size) { int count, i; - if (f->def->type->num_parms >= 0) - count = f->def->type->num_parms; + if (f->def->type->t.func.num_params >= 0) + count = f->def->type->t.func.num_params; else - count = -f->def->type->num_parms - 1; + count = -f->def->type->t.func.num_params - 1; for (i = 0; i < count; i++) - parm_size[i] = type_size (f->def->type->parm_types[i]); - return f->def->type->num_parms; + parm_size[i] = type_size (f->def->type->t.func.param_types[i]); + return f->def->type->t.func.num_params; } diff --git a/tools/qfcc/source/idstuff.c b/tools/qfcc/source/idstuff.c index 57cd15780..349e8591f 100644 --- a/tools/qfcc/source/idstuff.c +++ b/tools/qfcc/source/idstuff.c @@ -268,7 +268,7 @@ WriteProgdefs (const char *filename) if (!d->name || !d->ofs || d->type->type != ev_field) continue; - switch (d->type->aux_type->type) { + switch (d->type->t.fldptr.type->type) { case ev_float: fprintf (f, "\tfloat\t%s;\n", d->name); break; diff --git a/tools/qfcc/source/immediate.c b/tools/qfcc/source/immediate.c index 7b5890c8b..770f8c996 100644 --- a/tools/qfcc/source/immediate.c +++ b/tools/qfcc/source/immediate.c @@ -190,9 +190,10 @@ ReuseConstant (expr_t *expr, def_t *def) case ex_uinteger: if (!def || def->type != &type_float) { tab = integer_imm_defs; - if (e.type == ex_uinteger) - type = &type_uinteger; - else + //FIXME + //if (e.type == ex_uinteger) + // type = &type_uinteger; + //else type = &type_integer; break; } diff --git a/tools/qfcc/source/linker.c b/tools/qfcc/source/linker.c index 0b711262c..2e99151d6 100644 --- a/tools/qfcc/source/linker.c +++ b/tools/qfcc/source/linker.c @@ -1,5 +1,5 @@ /* - link.c + linker.c qc object file linking @@ -31,8 +31,7 @@ # include "config.h" #endif -static __attribute__ ((used)) const char rcsid[] = - "$Id$"; +static __attribute__ ((used)) const char rcsid[] = "$Id$"; #ifdef HAVE_STRING_H # include @@ -56,6 +55,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "QF/pakfile.h" #include "QF/va.h" +#include "codespace.h" #include "def.h" #include "emit.h" #include "expr.h" diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index fca0c7558..f5c3cc090 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -80,7 +80,7 @@ method_free (void *_meth, void *unused) } method_t * -new_method (type_t *ret_type, param_t *selector, param_t *opt_parms) +new_method (type_t *ret_type, param_t *selector, param_t *opt_params) { method_t *meth = malloc (sizeof (method_t)); param_t *cmd = new_param (0, &type_SEL, "_cmd"); @@ -88,8 +88,8 @@ new_method (type_t *ret_type, param_t *selector, param_t *opt_parms) dstring_t *name = dstring_newstr (); dstring_t *types = dstring_newstr (); - opt_parms = reverse_params (opt_parms); - selector = _reverse_params (selector, opt_parms); + opt_params = reverse_params (opt_params); + selector = _reverse_params (selector, opt_params); cmd->next = selector; self->next = cmd; @@ -349,7 +349,7 @@ selector_t * get_selector (expr_t *sel) { selector_t _sel = {0, 0, sel->e.pointer.val}; - _sel.index /= type_size (type_SEL.aux_type); + _sel.index /= type_size (type_SEL.t.fldptr.type); return (selector_t *) Hash_FindElement (sel_index_hash, &_sel); } @@ -364,8 +364,8 @@ emit_selectors (void) if (!sel_index) return 0; - sel_type = array_type (type_SEL.aux_type, sel_index); - sel_def = get_def (type_SEL.aux_type, "_OBJ_SELECTOR_TABLE", pr.scope, + sel_type = array_type (type_SEL.t.fldptr.type, sel_index); + sel_def = get_def (type_SEL.t.fldptr.type, "_OBJ_SELECTOR_TABLE", pr.scope, st_extern); sel_def->type = sel_type; sel_def->ofs = new_location (sel_type, pr.near_data); @@ -409,7 +409,8 @@ emit_methods (methodlist_t *_methods, const char *name, int instance) new_struct_field (method_list, &type_pointer, "method_next", vis_public); new_struct_field (method_list, &type_integer, "method_count", vis_public); for (i = 0; i < count; i++) - new_struct_field (method_list, type_Method.aux_type, 0, vis_public); + new_struct_field (method_list, type_Method.t.fldptr.type, 0, + vis_public); methods_def = get_def (method_list->type, va ("_OBJ_%s_METHODS_%s", type, name), pr.scope, st_static); @@ -490,11 +491,11 @@ clear_selectors (void) expr_t * method_check_params (method_t *method, expr_t *args) { - int i, count, parm_count; + int i, count, param_count; expr_t *a, **arg_list, *err = 0; type_t *mtype = method->type; - if (mtype->num_parms == -1) + if (mtype->t.func.num_params == -1) return 0; for (count = 0, a = args; a; a = a->next) @@ -503,14 +504,14 @@ method_check_params (method_t *method, expr_t *args) if (count > MAX_PARMS) return error (args, "more than %d parameters", MAX_PARMS); - if (mtype->num_parms >= 0) - parm_count = mtype->num_parms; + if (mtype->t.func.num_params >= 0) + param_count = mtype->t.func.num_params; else - parm_count = -mtype->num_parms - 1; + param_count = -mtype->t.func.num_params - 1; - if (count < parm_count) + if (count < param_count) return error (args, "too few arguments"); - if (mtype->num_parms >= 0 && count > mtype->num_parms) + if (mtype->t.func.num_params >= 0 && count > mtype->t.func.num_params) return error (args, "too many arguments"); arg_list = malloc (count * sizeof (expr_t *)); @@ -523,13 +524,11 @@ method_check_params (method_t *method, expr_t *args) if (!t) return e; - if (i < parm_count) { + if (i < param_count) { if (e->type != ex_nil) - if (!type_assignable (mtype->parm_types[i], t)) { - print_type (mtype->parm_types[i]); puts (""); - print_type (t); puts (""); - err = error (e, "type mismatch for parameter %d of %s", - i - 1, method->name); + if (!type_assignable (mtype->t.func.param_types[i], t)) { + err = param_mismatch (e, i - 1, method->name, + mtype->t.func.param_types[i], t); } } else { if (e->type == ex_integer && options.warnings.vararg_integer) diff --git a/tools/qfcc/source/obj_file.c b/tools/qfcc/source/obj_file.c index 080992666..21a70be08 100644 --- a/tools/qfcc/source/obj_file.c +++ b/tools/qfcc/source/obj_file.c @@ -31,8 +31,7 @@ # include "config.h" #endif -static __attribute__ ((used)) const char rcsid[] = - "$Id$"; +static __attribute__ ((used)) const char rcsid[] = "$Id$"; #ifdef HAVE_STRING_H # include @@ -46,6 +45,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "QF/qendian.h" #include "QF/quakeio.h" +#include "codespace.h" #include "debug.h" #include "def.h" #include "emit.h" @@ -573,7 +573,7 @@ qfo_to_progs (qfo_t *qfo, pr_info_t *pr) pf->aux->line_info = qf->line_info; pf->aux->local_defs = 0; pf->aux->num_locals = 0; - pf->aux->return_type = pf->def->type->aux_type->type; + pf->aux->return_type = pf->def->type->t.func.type->type; pf->builtin = qf->builtin; pf->code = qf->code; pf->function_num = i + 1; diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index 1f5953d42..80ff8cdab 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -278,7 +278,7 @@ static keyword_t keywords[] = { {"entity", TYPE, &type_entity, 1, PROG_ID_VERSION}, {"quaternion", TYPE, &type_quaternion, 0, PROG_VERSION}, {"integer", TYPE, &type_integer, 0, PROG_VERSION}, - {"unsigned", TYPE, &type_uinteger, 0, PROG_VERSION}, + {"unsigned", TYPE, &type_integer, 0, PROG_VERSION},//FIXME {"function", TYPE, &type_function, 0, PROG_VERSION}, {"id", TYPE, &type_id, 0, PROG_VERSION}, {"Class", TYPE, &type_Class, 0, PROG_VERSION}, diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 53e92608c..3386d01ab 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -30,8 +30,7 @@ # include "config.h" #endif -static __attribute__ ((used)) const char rcsid[] = - "$Id$"; +static __attribute__ ((used)) const char rcsid[] = "$Id$"; #ifdef HAVE_SYS_TYPES_H # include @@ -70,6 +69,7 @@ static __attribute__ ((used)) const char rcsid[] = #include "qfcc.h" #include "class.h" +#include "codespace.h" #include "cpp.h" #include "debug.h" #include "def.h" diff --git a/tools/qfcc/source/qfprogs.c b/tools/qfcc/source/qfprogs.c index 8dea49f45..acd1fd4c0 100644 --- a/tools/qfcc/source/qfprogs.c +++ b/tools/qfcc/source/qfprogs.c @@ -275,8 +275,6 @@ get_auxtype (const char *type) return ev_field; case '(': return ev_func; - case ':': - return ev_sel; case '@': // id case '#': // class case '^': @@ -285,14 +283,8 @@ get_auxtype (const char *type) return ev_quat; case 'i': return ev_integer; - case 'I': - return ev_uinteger; case 's': return ev_short; - case '{': - return ev_struct; - case '[': - return ev_array; } } } diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y index 9612b35b2..cdc4db295 100644 --- a/tools/qfcc/source/qp-parse.y +++ b/tools/qfcc/source/qp-parse.y @@ -239,13 +239,13 @@ subprogram_declaration } declarations compound_statement ';' { + type_t *ret_type = $1->type->t.func.type; current_scope = current_scope->parent; //current_storage = st_global; //FIXME want a true void return - if ($1->type->aux_type->type != ev_void) - append_expr ($5, - return_expr (current_func, - new_ret_expr ($1->type->aux_type))); + if (ret_type) + append_expr ($5, return_expr (current_func, + new_ret_expr (ret_type))); build_code_function (current_func, 0, $5); current_func = 0; } @@ -338,7 +338,7 @@ statement { convert_name ($1); if ($1->type == ex_def && extract_type ($1) == ev_func) - $1 = new_ret_expr ($1->e.def->type->aux_type); + $1 = new_ret_expr ($1->e.def->type->t.func.type); $$ = assign_expr ($1, $3); } | procedure_statement { $$ = $1; } diff --git a/tools/qfcc/source/reloc.c b/tools/qfcc/source/reloc.c index 570c0e670..9035b2aff 100644 --- a/tools/qfcc/source/reloc.c +++ b/tools/qfcc/source/reloc.c @@ -42,6 +42,7 @@ static __attribute__ ((used)) const char rcsid[] = #endif #include +#include "codespace.h" #include "def.h" #include "emit.h" #include "expr.h" diff --git a/tools/qfcc/source/struct.c b/tools/qfcc/source/struct.c index 2426c55a2..1a4f0bdd0 100644 --- a/tools/qfcc/source/struct.c +++ b/tools/qfcc/source/struct.c @@ -123,10 +123,11 @@ init_struct (struct_t *strct, type_t *type, struct_type stype, if (name) strct->name = save_string (name); strct->type = type; - strct->type->type = ev_struct; + strct->type->type = ev_invalid; + strct->type->ty = ty_struct; strct->struct_tail = &strct->struct_head; strct->struct_fields = Hash_NewTable (61, struct_field_get_key, 0, 0); - strct->type->s.strct = strct; + strct->type->t.strct = strct; strct->stype = stype; if (name) { strct->type->name = strct->name; diff --git a/tools/qfcc/source/stub.c b/tools/qfcc/source/stub.c index be2582374..febcff724 100644 --- a/tools/qfcc/source/stub.c +++ b/tools/qfcc/source/stub.c @@ -3,6 +3,7 @@ #endif #include "class.h" +#include "codespace.h" #include "debug.h" #include "def.h" #include "emit.h" diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c index 187e80633..dc68d976d 100644 --- a/tools/qfcc/source/switch.c +++ b/tools/qfcc/source/switch.c @@ -308,7 +308,8 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val, range->type = ex_uinteger; - def = get_def (array_type (&type_uinteger, high - low + 1), name, + //FIXME unsigned int better? + def = get_def (array_type (&type_integer, high - low + 1), name, pr.scope, st_static); table = new_def_expr (def); @@ -316,7 +317,8 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val, branch = new_binary_expr (IFB, temp, low_label); append_expr (sw, branch); } - test = binary_expr (GT, cast_expr (&type_uinteger, temp), range); + //FIXME unsigned int + test = binary_expr (GT, cast_expr (&type_integer, temp), range); branch = new_binary_expr ('i', test, high_label); append_expr (sw, branch); branch = new_binary_expr ('g', table, temp); diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 5c8114e2e..e946a077d 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -58,45 +58,46 @@ static __attribute__ ((used)) const char rcsid[] = #include "type.h" // simple types. function types are dynamically allocated +type_t type_invalid = { ev_invalid, "invalid" }; type_t type_void = { ev_void, "void" }; type_t type_string = { ev_string, "string" }; type_t type_float = { ev_float, "float" }; type_t type_vector = { ev_vector, "vector" }; type_t type_entity = { ev_entity, "entity" }; -type_t type_field = { ev_field, "field", NULL, &type_void }; +type_t type_field = {ev_field, "field", ty_none, {{&type_void}} }; // type_function is a void() function used for state defs -type_t type_function = { ev_func, "function", NULL, &type_void }; -type_t type_pointer = { ev_pointer, "pointer", NULL, &type_void }; +type_t type_function = { ev_func, "function", ty_none, {{&type_void}} }; +type_t type_pointer = { ev_pointer, "pointer", ty_none, {{&type_void}} }; type_t type_quaternion = { ev_quat, "quaternion" }; type_t type_integer = { ev_integer, "integer" }; -type_t type_uinteger = { ev_uinteger, "uiniteger" }; type_t type_short = { ev_short, "short" }; -type_t type_struct = { ev_struct, "struct" }; // these will be built up further type_t type_id = { ev_pointer, "id" }; type_t type_Class = { ev_pointer, "Class" }; -type_t type_Protocol = { ev_pointer, "Protocol" }; +type_t type_Protocol = { ev_invalid, "Protocol" }; type_t type_SEL = { ev_pointer, "SEL" }; -type_t type_IMP = { ev_func, "IMP", NULL, &type_id, -3, { &type_id, - &type_SEL }}; -type_t type_supermsg = { ev_func, ".supermsg", NULL, &type_id, -3, - { 0, &type_SEL }}; -type_t type_obj_exec_class = { ev_func, "function", NULL, &type_void, 1, { 0 }}; +type_t type_IMP = { ev_func, "IMP", ty_none, + {{&type_id, -3, {&type_id, &type_SEL}}}}; +type_t type_supermsg = { ev_func, ".supermsg", ty_none, + {{&type_id, -3, {0, &type_SEL}}}}; +type_t type_obj_exec_class = { ev_func, "function", ty_none, + {{&type_void, 1, { 0 }}}}; type_t type_Method = { ev_pointer, "Method" }; -type_t type_Super = { ev_pointer, "Super" }; -type_t type_method_description = { ev_struct, "obj_method_description" }; +type_t type_Super = { ev_invalid, "Super" }; +type_t type_method_description = { ev_invalid, "obj_method_description", + ty_struct }; type_t *type_category; type_t *type_ivar; type_t *type_module; -type_t type_va_list = { ev_struct, "@va_list" }; -type_t type_param = { ev_struct, "@param" }; +type_t type_va_list = { ev_invalid, "@va_list", ty_struct }; +type_t type_param = { ev_invalid, "@param", ty_struct }; type_t type_zero; struct_t *vector_struct; struct_t *quaternion_struct; -type_t type_floatfield = { ev_field, ".float", NULL, &type_float }; +type_t type_floatfield = { ev_field, ".float", ty_none, {{&type_float}} }; static type_t *free_types; @@ -115,6 +116,56 @@ new_type (void) return type; } +static int +types_same (type_t *a, type_t *b) +{ + int i, count; + + if (a->type != b->type || a->ty != b->ty) + return 0; + switch (a->ty) { + case ty_none: + switch (a->type) { + case ev_field: + case ev_pointer: + if (a->t.fldptr.type != b->t.fldptr.type) + return 0; + return 1; + case ev_func: + if (a->t.func.type != b->t.func.type + || a->t.func.num_params != b->t.func.num_params) + return 0; + count = a->t.func.num_params; + if (count < 0) + count = ~count; // param count in one's complement + for (i = 0; i < count; i++) + if (a->t.func.param_types[i] + != b->t.func.param_types[i]) + return 0; + return 1; + default: // other types don't have aux data + return 1; + } + break; + case ty_struct: + if (a->t.strct != b->t.strct) + return 0; + return 1; + case ty_array: + if (a->t.array.type != b->t.array.type + || a->t.array.base != b->t.array.base + || a->t.array.size != b->t.array.size) + return 0; + return 1; + case ty_class: + if (a->t.class != b->t.class) + return 0; + return 1; + } + error (0, "we be broke"); + abort (); +} + /* find_type @@ -125,29 +176,9 @@ type_t * find_type (type_t *type) { type_t *check; - int c, i; for (check = pr.types; check; check = check->next) { - if (check->type != type->type - || check->aux_type != type->aux_type - || check->num_parms != type->num_parms - || check->s.class != type->s.class) - continue; - - if (check->type != ev_func) - return check; - - if (check->num_parms == -1) - return check; - - if ((c = check->num_parms) < 0) - c = -c - 1; - - for (i = 0; i < c; i++) - if (check->parm_types[i] != type->parm_types[i]) - break; - - if (i == c) + if (types_same (check, type)) return check; } @@ -202,7 +233,7 @@ field_type (type_t *aux) memset (&new, 0, sizeof (new)); new.type = ev_field; - new.aux_type = aux; + new.t.fldptr.type = aux; return find_type (&new); } @@ -213,7 +244,7 @@ pointer_type (type_t *aux) memset (&new, 0, sizeof (new)); new.type = ev_pointer; - new.aux_type = aux; + new.t.fldptr.type = aux; return find_type (&new); } @@ -223,9 +254,10 @@ array_type (type_t *aux, int size) type_t new; memset (&new, 0, sizeof (new)); - new.type = ev_array; - new.aux_type = aux; - new.num_parms = size; + new.type = ev_invalid; + new.ty = ty_array; + new.t.array.type = aux; + new.t.array.size = size; return find_type (&new); } @@ -235,63 +267,99 @@ based_array_type (type_t *aux, int base, int top) type_t new; memset (&new, 0, sizeof (new)); - new.type = ev_array; - new.aux_type = aux; - new.num_parms = top - base + 1; - new.s.base = base; + new.type = ev_invalid; + new.ty = ty_array; + new.t.array.type = aux; + new.t.array.base = base; + new.t.array.size = top - base + 1; return find_type (&new); } +void +print_type_str (dstring_t *str, type_t *type) +{ + if (!type) { + dasprintf (str, " (null)"); + return; + } + switch (type->type) { + case ev_field: + dasprintf (str, ".("); + print_type_str (str, type->t.fldptr.type); + dasprintf (str, ")"); + break; + case ev_func: + print_type_str (str, type->t.func.type); + if (type->t.func.num_params == -1) { + dasprintf (str, "(...)"); + } else { + int c, i; + dasprintf (str, "("); + if ((c = type->t.func.num_params) < 0) + c = ~c; // num_params is one's compliment + for (i = 0; i < c; i++) { + if (i) + dasprintf (str, ", "); + print_type_str (str, type->t.func.param_types[i]); + } + if (type->t.func.num_params < 0) + dasprintf (str, ", ..."); + dasprintf (str, ")"); + } + break; + case ev_pointer: + if (type == &type_id) { + dasprintf (str, "id"); + break; + } + if (type == &type_SEL) { + dasprintf (str, "SEL"); + break; + } + dasprintf (str, "(*"); + print_type_str (str, type->t.fldptr.type); + dasprintf (str, ")"); + break; + case ev_invalid: + switch (type->ty) { + case ty_class: + dasprintf (str, " %s", type->t.class->name); + break; + case ty_struct: + { + const char *tag = "struct"; + + if (type->t.strct->stype == str_union) + tag = "union"; + dasprintf (str, " %s %s", tag, type->t.strct->name); + } + break; + case ty_array: + print_type_str (str, type->t.array.type); + if (type->t.array.base) { + dasprintf (str, "[%d..%d]", type->t.array.base, + type->t.array.base + type->t.array.size - 1); + } else { + dasprintf (str, "[%d]", type->t.array.size); + } + break; + case ty_none: + break; + } + break; + default: + dasprintf (str, " %s", pr_type_name[type->type]); + break; + } +} + void print_type (type_t *type) { - if (!type) { - printf (" (null)"); - return; - } - switch (type->type) { - case ev_field: - printf (" .("); - print_type (type->aux_type); - printf (")"); - break; - case ev_func: - print_type (type->aux_type); - if (type->num_parms == -1) { - printf ("(...)"); - } else { - int c, i; - printf ("("); - if ((c = type->num_parms) < 0) - c = -c - 1; - for (i = 0; i < c; i++) { - if (i) - printf (", "); - print_type (type->parm_types[i]); - } - if (type->num_parms < 0) - printf (", ..."); - printf (")"); - } - break; - case ev_pointer: - print_type (type->aux_type); - if (type->num_parms) - printf ("[%d]", type->num_parms); - else - printf ("[]"); - break; - case ev_object: - case ev_class: - printf (" %s", type->s.class->name); - break; - case ev_struct: - printf (" %s %s", pr_type_name[type->type], type->s.strct->name); - break; - default: - printf(" %s", pr_type_name[type->type]); - break; - } + dstring_t *str = dstring_newstr (); + print_type_str (str, type); + printf ("%s", str->str); + dstring_delete (str); } const char * @@ -301,129 +369,142 @@ encode_params (type_t *type) dstring_t *encoding = dstring_newstr (); int i, count; - if (type->num_parms < 0) - count = -type->num_parms - 1; + if (type->t.func.num_params < 0) + count = -type->t.func.num_params - 1; else - count = type->num_parms; + count = type->t.func.num_params; for (i = 0; i < count; i++) - encode_type (encoding, type->parm_types[i]); - if (type->num_parms < 0) - dstring_appendstr (encoding, "."); + encode_type (encoding, type->t.func.param_types[i]); + if (type->t.func.num_params < 0) + dasprintf (encoding, "."); ret = save_string (encoding->str); dstring_delete (encoding); return ret; } +static void _encode_type (dstring_t *encoding, type_t *type, int level); + +static void +encode_struct_fields (dstring_t *encoding, struct_t *strct, int level) +{ + struct_field_t *field; + + for (field = strct->struct_head; field; field = field->next) + _encode_type (encoding, field->type, level + 1); +} + +static void +encode_class (dstring_t *encoding, type_t *type, int level) +{ + class_t *class = type->t.class; + const char *name ="?"; + + if (class->name) + name = class->name; + dasprintf (encoding, "{%s=", name); //FIXME loses info about being a class + if (level < 2 && class->ivars) + encode_struct_fields (encoding, class->ivars, level); + dasprintf (encoding, "}"); +} + +static void +encode_struct (dstring_t *encoding, type_t *type, int level) +{ + struct_t *strct = type->t.strct; + const char *name ="?"; + char su = '='; + + if (strct->name) + name = strct->name; + if (strct->stype == str_union) + su = '-'; + dasprintf (encoding, "{%s%c", name, su); + if (level < 2) + encode_struct_fields (encoding, strct, level); + dasprintf (encoding, "}"); +} + static void _encode_type (dstring_t *encoding, type_t *type, int level) { - struct_field_t *field; - struct_t *strct; - if (!type) return; switch (type->type) { case ev_void: - dstring_appendstr (encoding, "v"); + dasprintf (encoding, "v"); break; case ev_string: - dstring_appendstr (encoding, "*"); + dasprintf (encoding, "*"); break; case ev_float: - dstring_appendstr (encoding, "f"); + dasprintf (encoding, "f"); break; case ev_vector: - dstring_appendstr (encoding, "V"); + dasprintf (encoding, "V"); break; case ev_entity: - dstring_appendstr (encoding, "E"); + dasprintf (encoding, "E"); break; case ev_field: - dstring_appendstr (encoding, "F"); - _encode_type (encoding, type->aux_type, level + 1); + dasprintf (encoding, "F"); + _encode_type (encoding, type->t.fldptr.type, level + 1); break; case ev_func: - dstring_appendstr (encoding, "("); - _encode_type (encoding, type->aux_type, level + 1); - dstring_appendstr (encoding, encode_params (type)); - dstring_appendstr (encoding, ")"); + dasprintf (encoding, "("); + _encode_type (encoding, type->t.func.type, level + 1); + dasprintf (encoding, "%s)", encode_params (type)); break; case ev_pointer: - type = type->aux_type; - switch (type->type) { - case ev_object: - dstring_appendstr (encoding, "@"); - break; - case ev_class: - dstring_appendstr (encoding, "#"); - break; - case ev_struct: - if (type == type_SEL.aux_type) { - dstring_appendstr (encoding, ":"); - break; - } - // fall through - default: - dstring_appendstr (encoding, "^"); - _encode_type (encoding, type, level + 1); - break; + if (type == &type_id) { + dasprintf (encoding, "@"); + break; } + if (type == &type_SEL) { + dasprintf (encoding, ":"); + break; + } + if (type == &type_Class) { + dasprintf (encoding, "#"); + break; + } + type = type->t.fldptr.type; + dasprintf (encoding, "^"); + _encode_type (encoding, type, level + 1); break; case ev_quat: - dstring_appendstr (encoding, "Q"); + dasprintf (encoding, "Q"); break; case ev_integer: - dstring_appendstr (encoding, "i"); - break; - case ev_uinteger: - dstring_appendstr (encoding, "I"); + dasprintf (encoding, "i"); break; case ev_short: - dstring_appendstr (encoding, "s"); + dasprintf (encoding, "s"); break; - case ev_struct: - case ev_object: - case ev_class: - if (type->type == ev_struct) { - strct = type->s.strct; - } else { - strct = type->s.class->ivars; + case ev_invalid: + switch (type->ty) { + case ty_class: + encode_class (encoding, type, level); + break; + case ty_struct: + encode_struct (encoding, type, level); + break; + case ty_array: + dasprintf (encoding, "["); + dasprintf (encoding, "%d", type->t.array.size); + if (type->t.array.base) + dasprintf (encoding, ":%d", type->t.array.base); + dasprintf (encoding, "="); + _encode_type (encoding, type->t.array.type, level + 1); + dasprintf (encoding, "]"); + break; + case ty_none: + dasprintf (encoding, "?"); + break; } - dstring_appendstr (encoding, "{"); - if (strct->name) { - dstring_appendstr (encoding, strct->name); - } else if (type->type == ev_object || type->type == ev_class) { - dstring_appendstr (encoding, type->s.class->name); - } - if (level < 2) { - struct_t *s; - if (type->type == ev_struct - && type->s.strct->stype == str_union) - dstring_appendstr (encoding, "-"); - else - dstring_appendstr (encoding, "="); - if (type->type == ev_struct) { - s = type->s.strct; - } else { - s = type->s.class->ivars; - } - for (field = s->struct_head; field; field = field->next) - _encode_type (encoding, field->type, level + 1); - } - dstring_appendstr (encoding, "}"); - break; - case ev_sel: - dstring_appendstr (encoding, ":"); - break; - case ev_array: - dstring_appendstr (encoding, "["); - dstring_appendstr (encoding, va ("%d ", type->num_parms)); - _encode_type (encoding, type->aux_type, level + 1); - dstring_appendstr (encoding, "]"); break; case ev_type_count: - dstring_appendstr (encoding, "?"); + dasprintf (encoding, "?"); break; } } @@ -458,14 +539,14 @@ _parse_type (const char **str) return field_type (_parse_type (str)); case '(': new.type = ev_func; - new.aux_type = _parse_type (str); + new.t.func.type = _parse_type (str); while (**str && **str != ')' && **str != '.') - new.parm_types[new.num_parms++] = _parse_type (str); + new.t.func.param_types[new.t.func.num_params++] = _parse_type (str); if (!**str) return 0; if (**str == '.') { (*str)++; - new.num_parms = -new.num_parms - 1; + new.t.func.num_params = -new.t.func.num_params - 1; } if (**str != ')') return 0; @@ -483,14 +564,14 @@ _parse_type (const char **str) return &type_quaternion; case 'i': return &type_integer; - case 'I': - return &type_uinteger; case 's': return &type_short; case '{': - new.type = ev_struct; + new.type = ev_invalid; + new.ty = ty_struct; name = dstring_newstr (); - for (s = *str; *s && *s != '=' && *s != '-' && *s !='}'; s++) + for (s = *str; + *s && *s != '=' && *s != '-' && *s != '#' && *s != '}'; s++) ; if (!*s) return 0; @@ -538,18 +619,31 @@ _parse_type (const char **str) (*str)++; return strct->type; case '[': - new.type = ev_array; - while (isdigit ((byte)**str)) { - new.num_parms *= 10; - new.num_parms += *(*str)++ - '0'; - } - while (isspace ((byte)**str)) + { + type_t *type; + int base = 0; + int size = 0; + + while (isdigit ((byte)**str)) { + size *= 10; + size += *(*str)++ - '0'; + } + if (**str == ':') { + (*str)++; + while (isdigit ((byte)**str)) { + size *= 10; + size += *(*str)++ - '0'; + } + } + if (**str != '=') + return 0; (*str)++; - new.aux_type = _parse_type (str); - if (**str != ']') - return 0; - (*str)++; - return find_type (&new); + type = _parse_type (str); + if (**str != ']') + return 0; + (*str)++; + return based_array_type (type, base, base + size - 1); + } default: return 0; } @@ -558,15 +652,45 @@ _parse_type (const char **str) type_t * parse_type (const char *str) { - return _parse_type (&str); + const char *s = str; + type_t *type = _parse_type (&s); + if (!type) { + error (0, "internal error: parsing type string `%s'", str); + abort (); + } + return type; } -static int +int is_scalar (type_t *type) { etype_t t = type->type; - if (t == ev_float || t == ev_integer || t == ev_uinteger || t == ev_short) + if (t == ev_float || t == ev_integer || t == ev_short) + return 1; + return 0; +} + +int +is_struct (type_t *type) +{ + if (type->type == ev_invalid && type->ty == ty_struct) + return 1; + return 0; +} + +int +is_class (type_t *type) +{ + if (type->type == ev_invalid && type->ty == ty_class) + return 1; + return 0; +} + +int +is_array (type_t *type) +{ + if (type->type == ev_invalid && type->ty == ty_array) return 1; return 0; } @@ -578,24 +702,24 @@ type_assignable (type_t *dst, type_t *src) if (dst == src) return 1; - if (dst->type == ev_pointer && src->type == ev_array) { - if (dst->aux_type == src->aux_type) + if (dst->type == ev_pointer + && src->type == ev_invalid && src->ty == ty_array) { + if (dst->t.fldptr.type == src->t.array.type) return 1; return 0; } if (dst->type != ev_pointer || src->type != ev_pointer) return is_scalar (dst) && is_scalar (src); - dst = dst->aux_type; - src = src->aux_type; + dst = dst->t.fldptr.type; + src = src->t.fldptr.type; if (dst->type == ev_void) return 1; if (src->type == ev_void) return 1; - if ((dst->type != ev_object && dst->type != ev_class) - || (src->type != ev_object && src->type != ev_class)) + if (!is_class (dst) || !is_class (src)) return 0; - dst_class = dst->s.class; - src_class = src->s.class; + dst_class = dst->t.class; + src_class = src->t.class; //printf ("%s %s\n", dst_class->class_name, src_class->class_name); if (!dst_class || dst_class == &class_id) return 1; @@ -627,20 +751,23 @@ type_size (type_t *type) case ev_pointer: case ev_quat: case ev_integer: - case ev_uinteger: case ev_short: - case ev_sel: case ev_type_count: return pr_type_size[type->type]; - case ev_struct: - return type->s.strct->size; - case ev_object: - case ev_class: - if (!type->s.class->ivars) - return 0; - return type->s.class->ivars->size; - case ev_array: - return type->num_parms * type_size (type->aux_type); + case ev_invalid: + switch (type->ty) { + case ty_struct: + return type->t.strct->size; + case ty_class: + if (!type->t.class->ivars) + return 0; + return type->t.class->ivars->size; + case ty_array: + return type->t.array.size * type_size (type->t.array.type); + case ty_none: + return 0; + } + break; } return 0; } @@ -660,7 +787,6 @@ init_types (void) new_struct_field (strct, &type_function, "func_val", vis_public); new_struct_field (strct, &type_pointer, "pointer_val", vis_public); new_struct_field (strct, &type_integer, "integer_val", vis_public); - new_struct_field (strct, &type_uinteger, "uinteger_val", vis_public); strct = calloc (sizeof (struct_t), 1); init_struct (strct, &type_param, str_union, 0); @@ -672,7 +798,6 @@ init_types (void) new_struct_field (strct, &type_function, "func_val", vis_public); new_struct_field (strct, &type_pointer, "pointer_val", vis_public); new_struct_field (strct, &type_integer, "integer_val", vis_public); - new_struct_field (strct, &type_uinteger, "uinteger_val", vis_public); strct = vector_struct = get_struct (0, 1); init_struct (strct, new_type (), str_struct, 0); @@ -684,12 +809,14 @@ init_types (void) return; if (options.code.progsversion != PROG_ID_VERSION) { - strct = type_zero.s.strct; + strct = type_zero.t.strct; + // vector can't be part of .zero for v6 progs because for v6 progs, + // .zero is only one word wide. new_struct_field (strct, &type_vector, "vector_val", vis_public); new_struct_field (strct, &type_quaternion, "quaternion_val", vis_public); - strct = type_param.s.strct; + strct = type_param.t.strct; new_struct_field (strct, &type_quaternion, "quaternion_val", vis_public); } @@ -703,19 +830,19 @@ init_types (void) init_struct (strct, new_type (), str_struct, 0); new_struct_field (strct, &type_string, "sel_id", vis_public); new_struct_field (strct, &type_string, "sel_types", vis_public); - type_SEL.aux_type = strct->type; + type_SEL.t.fldptr.type = strct->type; strct = get_struct (0, 1); init_struct (strct, new_type (), str_struct, 0); new_struct_field (strct, &type_SEL, "method_name", vis_public); new_struct_field (strct, &type_string, "method_types", vis_public); new_struct_field (strct, &type_IMP, "method_imp", vis_public); - type_Method.aux_type = strct->type; + type_Method.t.fldptr.type = strct->type; strct = get_struct (0, 1); init_struct (strct, type = new_type (), str_struct, 0); - type->type = ev_class; - type->s.class = &class_Class; + type->ty = ty_class; + type->t.class = &class_Class; new_struct_field (strct, &type_Class, "class_pointer", vis_public); new_struct_field (strct, &type_Class, "super_class", vis_public); new_struct_field (strct, &type_string, "name", vis_public); @@ -729,27 +856,26 @@ init_types (void) new_struct_field (strct, &type_pointer, "sibling_class", vis_public); new_struct_field (strct, &type_pointer, "protocols", vis_public); new_struct_field (strct, &type_pointer, "gc_object_type", vis_public); - type_Class.aux_type = strct->type; + type_Class.t.fldptr.type = strct->type; class_Class.ivars = strct; strct = get_struct (0, 1); - init_struct (strct, type = new_type (), str_struct, 0); - type->type = ev_class; - type->s.class = &class_Protocol; + init_struct (strct, type = &type_Protocol, str_struct, 0); + type->ty = ty_class; + type->t.class = &class_Protocol; new_struct_field (strct, &type_Class, "class_pointer", vis_public); new_struct_field (strct, &type_string, "protocol_name", vis_public); new_struct_field (strct, &type_pointer, "protocol_list", vis_public); new_struct_field (strct, &type_pointer, "instance_methods", vis_public); new_struct_field (strct, &type_pointer, "class_methods", vis_public); - type_Protocol.aux_type = strct->type; class_Protocol.ivars = strct; strct = get_struct (0, 1); init_struct (strct, type = new_type (), str_struct, 0); - type->type = ev_object; - type->s.class = &class_id; + type->ty = ty_class; + type->t.class = &class_id; new_struct_field (strct, &type_Class, "class_pointer", vis_public); - type_id.aux_type = strct->type; + type_id.t.fldptr.type = strct->type; class_id.ivars = strct; strct = get_struct (0, 1); @@ -774,17 +900,9 @@ init_types (void) type_ivar = strct->type; strct = get_struct ("Super", 1); - init_struct (strct, new_type (), str_struct, 0); + init_struct (strct, &type_Super, str_struct, 0); new_struct_field (strct, &type_id, "self", vis_public); new_struct_field (strct, &type_Class, "class", vis_public); - type_Super.aux_type = strct->type; -#if 0 - type = type_module = new_struct ("obj_module_t"); - new_struct_field (strct, &type_integer, "version", vis_public); - new_struct_field (strct, &type_integer, "size", vis_public); - new_struct_field (strct, &type_string, "name", vis_public); - new_struct_field (strct, &type_pointer, "symtab", vis_public); -#endif } void @@ -815,9 +933,7 @@ chain_initial_types (void) chain_type (&type_quaternion); chain_type (&type_integer); - chain_type (&type_uinteger); chain_type (&type_short); - chain_type (&type_struct); chain_type (&type_IMP); chain_type (&type_Super); @@ -830,7 +946,7 @@ chain_initial_types (void) chain_type (type_category); chain_type (type_ivar); - type_supermsg.parm_types[0] = &type_Super; + type_supermsg.t.func.param_types[0] = pointer_type (&type_Super); chain_type (&type_supermsg); strct = get_struct ("obj_module_s", 1); @@ -843,7 +959,7 @@ chain_initial_types (void) new_typedef ("obj_module_t", type_module); chain_type (type_module); - type_obj_exec_class.parm_types[0] = pointer_type (type_module); + type_obj_exec_class.t.func.param_types[0] = pointer_type (type_module); chain_type (&type_obj_exec_class); }