Nicolas Cannasse 3 роки тому
батько
коміт
4aef3f197e
2 змінених файлів з 44 додано та 8 видалено
  1. 12 1
      src/code.c
  2. 32 7
      src/module.c

+ 12 - 1
src/code.c

@@ -911,8 +911,12 @@ hl_code_hash *hl_code_hash_alloc( hl_code *c ) {
 	h->types_hashes = types_hashes;
 
 	h->globals_signs = malloc(sizeof(int) * c->nglobals);
-	for(i=0;i<c->nglobals;i++)
+	for(i=0;i<c->nglobals;i++) {
+		hl_type *t = c->globals[i];
 		h->globals_signs[i] = i | 0x80000000;
+		if( t->kind == HABSTRACT )
+			h->globals_signs[i] = hl_code_hash_type(h,t); // some global abstracts allocated by compiler
+	}
 	for(i=0;i<c->ntypes;i++) {
 		hl_type *t = c->types + i;
 		switch( t->kind ) {
@@ -1012,6 +1016,13 @@ void hl_code_hash_remap_globals( hl_code_hash *hnew, hl_code_hash *hold ) {
 	c->globals = nglobals;
 	c->nglobals = new_count;
 
+#	ifdef HL_DEBUG
+	for(i=old_count;i<new_count;i++) {
+		hl_type *t = c->globals[i];
+		uprintf(USTR("New global %s\n"),hl_type_str(t));
+	}
+#	endif
+
 	int *nsigns = malloc(sizeof(int) * c->nglobals);
 	for(i=0;i<new_count;i++)
 		nsigns[i] = i < old_count ? hold->globals_signs[i] : -1;

+ 32 - 7
src/module.c

@@ -733,16 +733,41 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 	// patch same types
 	for(i1=0;i1<m1->code->ntypes;i1++) {
 		hl_type *p = m1->code->types + i1;
-		if( p->kind != HOBJ && p->kind != HSTRUCT ) continue;
+		switch( p->kind ) {
+		case HOBJ:
+		case HSTRUCT:
+			break;
+		case HENUM:
+			if( !p->tenum->global_value ) continue;
+			break;
+		default:
+			continue;
+		}
 		for(i2=0;i2<c->ntypes;i2++) {
 			hl_type *t = c->types + i2;
 			if( p->kind != t->kind ) continue;
-			if( ucmp(p->obj->name,t->obj->name) != 0 ) continue;
-			if( hl_code_hash_type(m1->hash,p) == hl_code_hash_type(m2->hash,t)  ) {
-				t->obj = p->obj; // alias the types ! they are different pointers but have the same layout
-			} else {
-				uprintf(USTR("[HotReload] Type %s has changed\n"),t->obj->name);
-				changes_count++;
+			switch( p->kind ) {
+			case HOBJ:
+			case HSTRUCT:
+				if( ucmp(p->obj->name,t->obj->name) != 0 ) continue;
+				if( hl_code_hash_type(m1->hash,p) == hl_code_hash_type(m2->hash,t)  ) {
+					t->obj = p->obj; // alias the types ! they are different pointers but have the same layout
+				} else {
+					uprintf(USTR("[HotReload] Type %s has changed\n"),t->obj->name);
+					changes_count++;
+				}
+				break;
+			case HENUM:
+				if( ucmp(p->tenum->name,t->tenum->name) != 0 ) continue;
+				if( hl_code_hash_type(m1->hash,p) == hl_code_hash_type(m2->hash,t)  ) {
+					t->tenum = p->tenum; // alias the types ! they are different pointers but have the same layout
+				} else {
+					uprintf(USTR("[HotReload] Type %s has changed\n"),t->tenum->name);
+					changes_count++;
+				}
+				break;
+			default:
+				break;
 			}
 			break;
 		}