Browse Source

handle global values for enum as well

Nicolas Cannasse 9 years ago
parent
commit
f8074cdfbf
2 changed files with 4 additions and 3 deletions
  1. 2 2
      src/code.c
  2. 2 1
      src/module.c

+ 2 - 2
src/code.c

@@ -167,7 +167,7 @@ static void hl_read_type( hl_reader *r, hl_type *t ) {
 			int i;
 			const uchar *name = hl_get_ustring(r);
 			int super = INDEX();
-			int global = INDEX();
+			int global = UINDEX();
 			int nfields = UINDEX();
 			int nproto = UINDEX();
 			t->obj = (hl_type_obj*)hl_malloc(&r->code->alloc,sizeof(hl_type_obj));
@@ -220,9 +220,9 @@ static void hl_read_type( hl_reader *r, hl_type *t ) {
 			int i,j;
 			t->tenum = hl_malloc(&r->code->alloc,sizeof(hl_type_enum));
 			t->tenum->name = hl_get_ustring(r);
+			t->tenum->global_value = (void**)(int_val)UINDEX();
 			t->tenum->nconstructs = READ();
 			t->tenum->constructs = (hl_enum_construct*)hl_malloc(&r->code->alloc, sizeof(hl_enum_construct)*t->tenum->nconstructs);
-			t->tenum->global_value = NULL;
 			for(i=0;i<t->tenum->nconstructs;i++) {
 				hl_enum_construct *c = t->tenum->constructs + i;
 				c->name = hl_get_ustring(r);

+ 2 - 1
src/module.c

@@ -184,10 +184,11 @@ int hl_module_init( hl_module *m ) {
 		switch( t->kind ) {
 		case HOBJ:
 			t->obj->m = &m->ctx;
-			t->obj->global_value = ((int)t->obj->global_value) < 0 ? NULL : m->globals_data + m->globals_indexes[(int)t->obj->global_value];
+			t->obj->global_value = ((int)t->obj->global_value) ? (void**)(m->globals_data + m->globals_indexes[(int)t->obj->global_value-1]) : NULL;
 			break;
 		case HENUM:
 			hl_init_enum(t->tenum);
+			t->tenum->global_value = ((int)t->tenum->global_value) ? (void**)(m->globals_data + m->globals_indexes[(int)t->tenum->global_value-1]) : NULL;
 			break;
 		case HVIRTUAL:
 			hl_init_virtual(t,&m->ctx);