瀏覽代碼

fixed wrt hot reload

Nicolas Cannasse 3 年之前
父節點
當前提交
31dd01aa7e
共有 2 個文件被更改,包括 25 次插入10 次删除
  1. 8 5
      src/module.c
  2. 17 5
      src/std/obj.c

+ 8 - 5
src/module.c

@@ -758,6 +758,7 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 				if( ucmp(p->obj->name,t->obj->name) != 0 ) 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)  ) {
 				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
 					t->obj = p->obj; // alias the types ! they are different pointers but have the same layout
+					t->vobj_proto = p->vobj_proto;
 				} else {
 				} else {
 					uprintf(USTR("[HotReload] Type %s has changed\n"),t->obj->name);
 					uprintf(USTR("[HotReload] Type %s has changed\n"),t->obj->name);
 					changes_count++;
 					changes_count++;
@@ -826,11 +827,13 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 	hl_module_add(m2);
 	hl_module_add(m2);
 
 
 	// call entry point (will only update types)
 	// call entry point (will only update types)
-	vclosure cl;
-	cl.t = c->functions[m2->functions_indexes[c->entrypoint]].type;
-	cl.fun = m2->functions_ptrs[c->entrypoint];
-	cl.hasValue = 0;
-	hl_dyn_call(&cl,NULL,0);
+	if( m2->functions_ptrs[c->entrypoint] ) {
+		vclosure cl;
+		cl.t = c->functions[m2->functions_indexes[c->entrypoint]].type;
+		cl.fun = m2->functions_ptrs[c->entrypoint];
+		cl.hasValue = 0;
+		hl_dyn_call(&cl,NULL,0);
+	}
 
 
 	return true;
 	return true;
 }
 }

+ 17 - 5
src/std/obj.c

@@ -408,12 +408,24 @@ HL_API void hl_flush_proto( hl_type *ot ) {
 	hl_module_context *m = o->m;
 	hl_module_context *m = o->m;
 	if( !rt || !ot->vobj_proto ) return;
 	if( !rt || !ot->vobj_proto ) return;
 	for(i=0;i<o->nbindings;i++) {
 	for(i=0;i<o->nbindings;i++) {
-		hl_runtime_binding *b = rt->bindings + i;
+		int fid = o->bindings[i<<1];
 		int mid = o->bindings[(i<<1)|1];
 		int mid = o->bindings[(i<<1)|1];
-		if( b->closure )
-			b->ptr = m->functions_ptrs[mid];
-		else
-			((vclosure*)b->ptr)->fun = m->functions_ptrs[mid];
+		hl_runtime_binding *b = NULL;
+		int j;
+		for(j=0;j<rt->nbindings;j++)
+			if( rt->bindings[j].fid == fid ) {
+				b = rt->bindings + j;
+				break;
+			}
+		void *ptr = m->functions_ptrs[mid];
+		if( b->closure ) {
+			if( b->ptr != ptr )
+				b->ptr = ptr;
+		} else {
+			vclosure *c = (vclosure*)b->ptr;
+			if( c->fun != ptr )
+				c->fun = ptr;
+		}
 	}
 	}
 }
 }