Преглед изворни кода

fixed endlines mismatch in files

Nicolas Cannasse пре 3 година
родитељ
комит
773b0bc3fa
5 измењених фајлова са 373 додато и 373 уклоњено
  1. 115 115
      libs/fmt/dxt.c
  2. 207 207
      src/code.c
  3. 45 45
      src/module.c
  4. 1 1
      src/std/array.c
  5. 5 5
      src/std/fun.c

+ 115 - 115
libs/fmt/dxt.c

@@ -1,5 +1,5 @@
-#define HL_NAME(n) fmt_##n
-#include <hl.h>
+#define HL_NAME(n) fmt_##n
+#include <hl.h>
 
 static const int BIT5[] = { 0, 8, 16, 25, 33, 41, 49, 58, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189, 197, 206, 214, 222, 230, 239, 247, 255 };
 static const int BIT6[] = { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255 };
@@ -46,8 +46,8 @@ static int dxtAlpha(int a0, int a1, int t) {
 	case 7: return 255;
 	}
 	return 0;
-}
-
+}
+
 static int dxtColor(int c0, int c1, int a, int t) {
 	switch (t) {
 	case 0: return DXT_COLOR1(c0, a);
@@ -56,114 +56,114 @@ static int dxtColor(int c0, int c1, int a, int t) {
 	case 3: return (c0 > c1) ? DXT_COLOR3(c1, c0, a) : 0;
 	}
 	return 0;
-}
-
-HL_PRIM bool HL_NAME(dxt_decode)( vbyte *data, int *out, int width, int height, int format ) {
-	int x,y,k;
-	int index = 0;
-	int write = 0;
-	int alpha[16];
-	switch( format ) {
-	case 1:
-		for(y=0;y<height>>2;y++) {
-			for(x=0;x<width>>2;x++) {
-				int c0 = data[index] | (data[index + 1] << 8); index += 2;
-				int c1 = data[index] | (data[index + 1] << 8); index += 2;
-				for(k=0;k<4;k++) {
-					unsigned char c = data[index++];
-					int t0 = c & 0x03;
-					int t1 = (c & 0x0C) >> 2;
-					int t2 = (c & 0x30) >> 4;
-					int t3 = (c & 0xC0) >> 6;
-					int w = write + k * width;
-					out[w++] = dxtColor(c0, c1, 0xFF, t0);
-					out[w++] = dxtColor(c0, c1, 0xFF, t1);
-					out[w++] = dxtColor(c0, c1, 0xFF, t2);
-					out[w++] = dxtColor(c0, c1, 0xFF, t3);
-				}
-				write += 4;
-			}
-			write += 3 * width;
-		}
-		return true;
-	case 2:
-		for(y=0;y<height>>2;y++) {
-			for(x=0;x<width>>2;x++) {
-				int ap = 0;
-				for(k=0;k<4;k++) {
-					int a0 = data[index++];
-					int a1 = data[index++];
-					alpha[ap++] = 17 * ((a0 & 0xF0) >> 4);
-					alpha[ap++] = 17 * (a0 & 0x0F);
-					alpha[ap++] = 17 * ((a1 & 0xF0) >> 4);
-					alpha[ap++] = 17 * (a1 & 0x0F);
-				}
-				ap = 0;
-				int c0 = data[index] | (data[index + 1] << 8); index += 2;
-				int c1 = data[index] | (data[index + 1] << 8); index += 2;
-				for (int k = 0; k<4; k++) {
-					int c = data[index++];
-					int t0 = c & 0x03;
-					int t1 = (c & 0x0C) >> 2;
-					int t2 = (c & 0x30) >> 4;
-					int t3 = (c & 0xC0) >> 6;
-					int w = write + k * width;
-					out[w++] = dxtColor(c0, c1, alpha[ap++], t0);
-					out[w++] = dxtColor(c0, c1, alpha[ap++], t1);
-					out[w++] = dxtColor(c0, c1, alpha[ap++], t2);
-					out[w++] = dxtColor(c0, c1, alpha[ap++], t3);
-				}
-				write += 4;
-			}
-			write += 3 * width;
-		}
-		return true;
-	case 3:
-		for(y=0;y<height>>2;y++) {
-			for(x=0;x<width>>2;x++) {
-				int a0 = data[index++];
-				int a1 = data[index++];
-				int b0 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
-				int b1 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
-				alpha[0] = b0 & 0x07;
-				alpha[1] = (b0 >> 3) & 0x07;
-				alpha[2] = (b0 >> 6) & 0x07;
-				alpha[3] = (b0 >> 9) & 0x07;
-				alpha[4] = (b0 >> 12) & 0x07;
-				alpha[5] = (b0 >> 15) & 0x07;
-				alpha[6] = (b0 >> 18) & 0x07;
-				alpha[7] = (b0 >> 21) & 0x07;
-				alpha[8] = b1 & 0x07;
-				alpha[9] = (b1 >> 3) & 0x07;
-				alpha[10] = (b1 >> 6) & 0x07;
-				alpha[11] = (b1 >> 9) & 0x07;
-				alpha[12] = (b1 >> 12) & 0x07;
-				alpha[13] = (b1 >> 15) & 0x07;
-				alpha[14] = (b1 >> 18) & 0x07;
-				alpha[15] = (b1 >> 21) & 0x07;
-				int c0 = data[index] | (data[index + 1] << 8); index += 2;
-				int c1 = data[index] | (data[index + 1] << 8); index += 2;
-				int ap = 0;
-				for (int k = 0; k<4; k++) {
-					int c = data[index++];
-					int t0 = c & 0x03;
-					int t1 = (c & 0x0C) >> 2;
-					int t2 = (c & 0x30) >> 4;
-					int t3 = (c & 0xC0) >> 6;
-					int w = write + k * width;
-					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t0);
-					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t1);
-					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t2);
-					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t3);
-				}
-				write += 4;
-			}
-			write += 3 * width;
-		}
-		return true;
-	default:
-		return false;
-	}
-}
-
-DEFINE_PRIM(_BOOL, dxt_decode, _BYTES _BYTES _I32 _I32 _I32);
+}
+
+HL_PRIM bool HL_NAME(dxt_decode)( vbyte *data, int *out, int width, int height, int format ) {
+	int x,y,k;
+	int index = 0;
+	int write = 0;
+	int alpha[16];
+	switch( format ) {
+	case 1:
+		for(y=0;y<height>>2;y++) {
+			for(x=0;x<width>>2;x++) {
+				int c0 = data[index] | (data[index + 1] << 8); index += 2;
+				int c1 = data[index] | (data[index + 1] << 8); index += 2;
+				for(k=0;k<4;k++) {
+					unsigned char c = data[index++];
+					int t0 = c & 0x03;
+					int t1 = (c & 0x0C) >> 2;
+					int t2 = (c & 0x30) >> 4;
+					int t3 = (c & 0xC0) >> 6;
+					int w = write + k * width;
+					out[w++] = dxtColor(c0, c1, 0xFF, t0);
+					out[w++] = dxtColor(c0, c1, 0xFF, t1);
+					out[w++] = dxtColor(c0, c1, 0xFF, t2);
+					out[w++] = dxtColor(c0, c1, 0xFF, t3);
+				}
+				write += 4;
+			}
+			write += 3 * width;
+		}
+		return true;
+	case 2:
+		for(y=0;y<height>>2;y++) {
+			for(x=0;x<width>>2;x++) {
+				int ap = 0;
+				for(k=0;k<4;k++) {
+					int a0 = data[index++];
+					int a1 = data[index++];
+					alpha[ap++] = 17 * ((a0 & 0xF0) >> 4);
+					alpha[ap++] = 17 * (a0 & 0x0F);
+					alpha[ap++] = 17 * ((a1 & 0xF0) >> 4);
+					alpha[ap++] = 17 * (a1 & 0x0F);
+				}
+				ap = 0;
+				int c0 = data[index] | (data[index + 1] << 8); index += 2;
+				int c1 = data[index] | (data[index + 1] << 8); index += 2;
+				for (int k = 0; k<4; k++) {
+					int c = data[index++];
+					int t0 = c & 0x03;
+					int t1 = (c & 0x0C) >> 2;
+					int t2 = (c & 0x30) >> 4;
+					int t3 = (c & 0xC0) >> 6;
+					int w = write + k * width;
+					out[w++] = dxtColor(c0, c1, alpha[ap++], t0);
+					out[w++] = dxtColor(c0, c1, alpha[ap++], t1);
+					out[w++] = dxtColor(c0, c1, alpha[ap++], t2);
+					out[w++] = dxtColor(c0, c1, alpha[ap++], t3);
+				}
+				write += 4;
+			}
+			write += 3 * width;
+		}
+		return true;
+	case 3:
+		for(y=0;y<height>>2;y++) {
+			for(x=0;x<width>>2;x++) {
+				int a0 = data[index++];
+				int a1 = data[index++];
+				int b0 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
+				int b1 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
+				alpha[0] = b0 & 0x07;
+				alpha[1] = (b0 >> 3) & 0x07;
+				alpha[2] = (b0 >> 6) & 0x07;
+				alpha[3] = (b0 >> 9) & 0x07;
+				alpha[4] = (b0 >> 12) & 0x07;
+				alpha[5] = (b0 >> 15) & 0x07;
+				alpha[6] = (b0 >> 18) & 0x07;
+				alpha[7] = (b0 >> 21) & 0x07;
+				alpha[8] = b1 & 0x07;
+				alpha[9] = (b1 >> 3) & 0x07;
+				alpha[10] = (b1 >> 6) & 0x07;
+				alpha[11] = (b1 >> 9) & 0x07;
+				alpha[12] = (b1 >> 12) & 0x07;
+				alpha[13] = (b1 >> 15) & 0x07;
+				alpha[14] = (b1 >> 18) & 0x07;
+				alpha[15] = (b1 >> 21) & 0x07;
+				int c0 = data[index] | (data[index + 1] << 8); index += 2;
+				int c1 = data[index] | (data[index + 1] << 8); index += 2;
+				int ap = 0;
+				for (int k = 0; k<4; k++) {
+					int c = data[index++];
+					int t0 = c & 0x03;
+					int t1 = (c & 0x0C) >> 2;
+					int t2 = (c & 0x30) >> 4;
+					int t3 = (c & 0xC0) >> 6;
+					int w = write + k * width;
+					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t0);
+					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t1);
+					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t2);
+					out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t3);
+				}
+				write += 4;
+			}
+			write += 3 * width;
+		}
+		return true;
+	default:
+		return false;
+	}
+}
+
+DEFINE_PRIM(_BOOL, dxt_decode, _BYTES _BYTES _I32 _I32 _I32);

+ 207 - 207
src/code.c

@@ -886,217 +886,217 @@ int hl_code_hash_type( hl_code_hash *h, hl_type *t ) {
 	return hash;
 }
 
-hl_code_hash *hl_code_hash_alloc( hl_code *c ) {
-	int i;
-	hl_code_hash *h = malloc(sizeof(hl_code_hash));
-	memset(h,0,sizeof(hl_code_hash));
-	h->code = c;
-
-	h->functions_indexes = malloc(sizeof(int) * (c->nfunctions + c->nnatives));
-	for(i=0;i<c->nfunctions;i++) {
-		hl_function *f = c->functions + i;
-		h->functions_indexes[f->findex] = i;
-	}
-	for(i=0;i<c->nnatives;i++) {
-		hl_native *n = c->natives + i;
-		h->functions_indexes[n->findex] = i + c->nfunctions;
-	}
-
-	h->types_hashes = malloc(sizeof(int) * c->ntypes);
-	for(i=0;i<c->ntypes;i++)
-		h->types_hashes[i] = hash_type_first(c->types + i, false);
-	int *types_hashes = malloc(sizeof(int) * c->ntypes); // use a second buffer for order-indepedent
-	for(i=0;i<c->ntypes;i++)
-		types_hashes[i] = h->types_hashes[i] ^ hash_type_rec(h, c->types + i);
-	free(h->types_hashes);
-	h->types_hashes = types_hashes;
-
-	h->globals_signs = malloc(sizeof(int) * c->nglobals);
-	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 ) {
-		case HOBJ:
-		case HSTRUCT:
-			if( t->obj->global_value )
-				h->globals_signs[(int)(int_val)t->obj->global_value - 1] = hl_code_hash_type(h,t); 
-			break;
-		case HENUM:
-			if( t->tenum->global_value )
-				h->globals_signs[(int)(int_val)t->tenum->global_value - 1] = hl_code_hash_type(h,t); 
-			break;
+hl_code_hash *hl_code_hash_alloc( hl_code *c ) {
+	int i;
+	hl_code_hash *h = malloc(sizeof(hl_code_hash));
+	memset(h,0,sizeof(hl_code_hash));
+	h->code = c;
+
+	h->functions_indexes = malloc(sizeof(int) * (c->nfunctions + c->nnatives));
+	for(i=0;i<c->nfunctions;i++) {
+		hl_function *f = c->functions + i;
+		h->functions_indexes[f->findex] = i;
+	}
+	for(i=0;i<c->nnatives;i++) {
+		hl_native *n = c->natives + i;
+		h->functions_indexes[n->findex] = i + c->nfunctions;
+	}
+
+	h->types_hashes = malloc(sizeof(int) * c->ntypes);
+	for(i=0;i<c->ntypes;i++)
+		h->types_hashes[i] = hash_type_first(c->types + i, false);
+	int *types_hashes = malloc(sizeof(int) * c->ntypes); // use a second buffer for order-indepedent
+	for(i=0;i<c->ntypes;i++)
+		types_hashes[i] = h->types_hashes[i] ^ hash_type_rec(h, c->types + i);
+	free(h->types_hashes);
+	h->types_hashes = types_hashes;
+
+	h->globals_signs = malloc(sizeof(int) * c->nglobals);
+	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 ) {
+		case HOBJ:
+		case HSTRUCT:
+			if( t->obj->global_value )
+				h->globals_signs[(int)(int_val)t->obj->global_value - 1] = hl_code_hash_type(h,t); 
+			break;
+		case HENUM:
+			if( t->tenum->global_value )
+				h->globals_signs[(int)(int_val)t->tenum->global_value - 1] = hl_code_hash_type(h,t); 
+			break;
 		default:
 			break;
-		}
-	}
-	for(i=0;i<c->nconstants;i++) {
-		hl_constant *k = c->constants + i;
-		hl_type *t = c->globals[k->global];
-		int hash = -1;
-		int j;
-		for(j=0;j<k->nfields;j++) {
-			int index = k->fields[j];
-			switch( t->obj->fields[j].t->kind ) {
-			case HI32:
-				H32(c->ints[index]);
-				break;
-			case HBYTES:
-				HSTR(c->strings[index]);
-				break;
-			default:
-				break;
-			}
-		}
-		h->globals_signs[k->global] = hash;
-	}
-
-	// look into boot code to identify globals that are constant enum constructors
-	// this is a bit hackish but we need them for remap and there's no metatada
-	hl_function *f = c->functions + h->functions_indexes[c->entrypoint];
-	for(i=4;i<f->nops;i++) {
-		hl_opcode *op = f->ops + i;
-		hl_type *t;
-		switch( op->op ) {
-		case OSetGlobal:
-			t = c->globals[op->p1];
-			if( t->kind == HENUM && f->ops[i-2].op == OGetArray && f->ops[i-3].op == OInt )
-				h->globals_signs[op->p1] = c->ints[f->ops[i-3].p2];
-			break;
-		default:
-			break;
-		}
-	}
-
-	for(i=0;i<c->nglobals;i++)
-		h->globals_signs[i] ^= hl_code_hash_type(h,c->globals[i]);
-	return h;
-}
-
+		}
+	}
+	for(i=0;i<c->nconstants;i++) {
+		hl_constant *k = c->constants + i;
+		hl_type *t = c->globals[k->global];
+		int hash = -1;
+		int j;
+		for(j=0;j<k->nfields;j++) {
+			int index = k->fields[j];
+			switch( t->obj->fields[j].t->kind ) {
+			case HI32:
+				H32(c->ints[index]);
+				break;
+			case HBYTES:
+				HSTR(c->strings[index]);
+				break;
+			default:
+				break;
+			}
+		}
+		h->globals_signs[k->global] = hash;
+	}
 
-void hl_code_hash_remap_globals( hl_code_hash *hnew, hl_code_hash *hold ) {
-	hl_code *c = hnew->code;
-	int i;
-	int old_start = 0;
-
-	int count = c->nglobals;
-	int old_count = hold->code->nglobals;
-	int extra =	old_count - count;
-	if( extra < 0 ) extra = 0;
-	int *remap = malloc(sizeof(int) * count);
-
-	for(i=0;i<count;i++) {
-		int k;
-		int h = hnew->globals_signs[i];
-		remap[i] = -1;
-		for(k=old_start;k<old_count;k++) {
-			if( hold->globals_signs[k] == h ) {
-				if( k == old_start ) old_start++;
-				remap[i] = k;
-				break;
-			}
-		}
-	}
-
-	// new globals
-	for(i=0;i<count;i++)
-		if( remap[i] == -1 )
-			remap[i] = old_count + extra++;
-
-	hl_type **nglobals;
-	int new_count = old_count + extra;
-	ALLOC(nglobals,hl_type*,new_count);
-	for(i=0;i<new_count;i++)
-		nglobals[i] = i < old_count ? hold->code->globals[i] : &hlt_void;
-	for(i=0;i<count;i++)
-		nglobals[remap[i]] = c->globals[i];
-	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;
-	for(i=0;i<count;i++)
-		nsigns[remap[i]] = hnew->globals_signs[i];
-	free(hnew->globals_signs);
-	hnew->globals_signs = nsigns;
-
-	for(i=0;i<c->ntypes;i++) {
-		hl_type *t = c->types + i;
-		switch( t->kind ) {
-		case HSTRUCT:
-		case HOBJ:
-			if( t->obj->global_value )
-				t->obj->global_value = (void*)(int_val)(remap[(int)(int_val)t->obj->global_value - 1] + 1);
-			break;
-		case HENUM:
-			if( t->tenum->global_value )
-				t->tenum->global_value = (void*)(int_val)(remap[(int)(int_val)t->tenum->global_value - 1] + 1);
-			break;
+	// look into boot code to identify globals that are constant enum constructors
+	// this is a bit hackish but we need them for remap and there's no metatada
+	hl_function *f = c->functions + h->functions_indexes[c->entrypoint];
+	for(i=4;i<f->nops;i++) {
+		hl_opcode *op = f->ops + i;
+		hl_type *t;
+		switch( op->op ) {
+		case OSetGlobal:
+			t = c->globals[op->p1];
+			if( t->kind == HENUM && f->ops[i-2].op == OGetArray && f->ops[i-3].op == OInt )
+				h->globals_signs[op->p1] = c->ints[f->ops[i-3].p2];
+			break;
 		default:
 			break;
-		}
-	}
-	for(i=0;i<c->nconstants;i++)
-		c->constants[i].global = remap[c->constants[i].global];
-
-	for(i=0;i<c->nfunctions;i++) {
-		hl_function *f = c->functions + i;
-		int k;
-		for(k=0;k<f->nops;k++) {
-			hl_opcode *op = f->ops + k;
-			switch( op->op ) {
-			case OGetGlobal:
-				op->p2 = remap[op->p2];
-				break;
-			case OSetGlobal:
-				op->p1 = remap[op->p1];
-				break;
+		}
+	}
+
+	for(i=0;i<c->nglobals;i++)
+		h->globals_signs[i] ^= hl_code_hash_type(h,c->globals[i]);
+	return h;
+}
+
+
+void hl_code_hash_remap_globals( hl_code_hash *hnew, hl_code_hash *hold ) {
+	hl_code *c = hnew->code;
+	int i;
+	int old_start = 0;
+
+	int count = c->nglobals;
+	int old_count = hold->code->nglobals;
+	int extra =	old_count - count;
+	if( extra < 0 ) extra = 0;
+	int *remap = malloc(sizeof(int) * count);
+
+	for(i=0;i<count;i++) {
+		int k;
+		int h = hnew->globals_signs[i];
+		remap[i] = -1;
+		for(k=old_start;k<old_count;k++) {
+			if( hold->globals_signs[k] == h ) {
+				if( k == old_start ) old_start++;
+				remap[i] = k;
+				break;
+			}
+		}
+	}
+
+	// new globals
+	for(i=0;i<count;i++)
+		if( remap[i] == -1 )
+			remap[i] = old_count + extra++;
+
+	hl_type **nglobals;
+	int new_count = old_count + extra;
+	ALLOC(nglobals,hl_type*,new_count);
+	for(i=0;i<new_count;i++)
+		nglobals[i] = i < old_count ? hold->code->globals[i] : &hlt_void;
+	for(i=0;i<count;i++)
+		nglobals[remap[i]] = c->globals[i];
+	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;
+	for(i=0;i<count;i++)
+		nsigns[remap[i]] = hnew->globals_signs[i];
+	free(hnew->globals_signs);
+	hnew->globals_signs = nsigns;
+
+	for(i=0;i<c->ntypes;i++) {
+		hl_type *t = c->types + i;
+		switch( t->kind ) {
+		case HSTRUCT:
+		case HOBJ:
+			if( t->obj->global_value )
+				t->obj->global_value = (void*)(int_val)(remap[(int)(int_val)t->obj->global_value - 1] + 1);
+			break;
+		case HENUM:
+			if( t->tenum->global_value )
+				t->tenum->global_value = (void*)(int_val)(remap[(int)(int_val)t->tenum->global_value - 1] + 1);
+			break;
+		default:
+			break;
+		}
+	}
+	for(i=0;i<c->nconstants;i++)
+		c->constants[i].global = remap[c->constants[i].global];
+
+	for(i=0;i<c->nfunctions;i++) {
+		hl_function *f = c->functions + i;
+		int k;
+		for(k=0;k<f->nops;k++) {
+			hl_opcode *op = f->ops + k;
+			switch( op->op ) {
+			case OGetGlobal:
+				op->p2 = remap[op->p2];
+				break;
+			case OSetGlobal:
+				op->p1 = remap[op->p1];
+				break;
 			default:
 				break;
-			}
-		}
-	}
-
-	free(remap);
-}
-
-void hl_code_hash_finalize( hl_code_hash *h ) {
-	hl_code *c = h->code;
-	int i;
-	h->functions_signs = malloc(sizeof(int) * (c->nfunctions + c->nnatives));
-	for(i=0;i<c->nfunctions;i++) {
-		hl_function *f = c->functions + i;
-		h->functions_signs[i] = hash_fun_sign(h, f);
-	}
-	for(i=0;i<c->nnatives;i++) {
-		hl_native *n = c->natives + i;
-		h->functions_signs[i + c->nfunctions] = hash_native(h,n);
-	}
-	h->functions_hashes = malloc(sizeof(int) * c->nfunctions);
-	for(i=0;i<c->nfunctions;i++) {
-		hl_function *f = c->functions + i;
-		h->functions_hashes[i] = hash_fun(h,f);
-	}
-}
-
-void hl_code_hash_free( hl_code_hash *h ) {
-	free(h->functions_hashes);
-	free(h->functions_indexes);
-	free(h->functions_signs);
-	free(h->globals_signs);
-	free(h->types_hashes);
-	free(h);
-}
-
+			}
+		}
+	}
+
+	free(remap);
+}
+
+void hl_code_hash_finalize( hl_code_hash *h ) {
+	hl_code *c = h->code;
+	int i;
+	h->functions_signs = malloc(sizeof(int) * (c->nfunctions + c->nnatives));
+	for(i=0;i<c->nfunctions;i++) {
+		hl_function *f = c->functions + i;
+		h->functions_signs[i] = hash_fun_sign(h, f);
+	}
+	for(i=0;i<c->nnatives;i++) {
+		hl_native *n = c->natives + i;
+		h->functions_signs[i + c->nfunctions] = hash_native(h,n);
+	}
+	h->functions_hashes = malloc(sizeof(int) * c->nfunctions);
+	for(i=0;i<c->nfunctions;i++) {
+		hl_function *f = c->functions + i;
+		h->functions_hashes[i] = hash_fun(h,f);
+	}
+}
+
+void hl_code_hash_free( hl_code_hash *h ) {
+	free(h->functions_hashes);
+	free(h->functions_indexes);
+	free(h->functions_signs);
+	free(h->globals_signs);
+	free(h->types_hashes);
+	free(h);
+}
+

+ 45 - 45
src/module.c

@@ -737,47 +737,47 @@ 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;
-		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;
-			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
-					t->vobj_proto = p->vobj_proto;
-				} 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;
-		}
+	for(i1=0;i1<m1->code->ntypes;i1++) {
+		hl_type *p = m1->code->types + i1;
+		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;
+			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
+					t->vobj_proto = p->vobj_proto;
+				} 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;
+		}
 	}
 
 	m2->jit_code = hl_jit_code(ctx, m2, &m2->codesize, &m2->jit_debug, m1);
@@ -828,10 +828,10 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 
 	// call entry point (will only update types)
 	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;
+		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);
 	}
 

+ 1 - 1
src/std/array.c

@@ -23,7 +23,7 @@
 
 HL_PRIM varray *hl_alloc_array( hl_type *at, int size ) {
 	if( size == 0 && at->kind == HDYN ) {
-		static varray empty_array = { &hlt_array, &hlt_dyn };
+		static varray empty_array = { &hlt_array, &hlt_dyn };
 		return &empty_array;
 	}
 	int esize = hl_type_size(at);

+ 5 - 5
src/std/fun.c

@@ -417,9 +417,9 @@ HL_PRIM vdynamic *hl_make_var_args( vclosure *c ) {
 	return (vdynamic*)hl_alloc_closure_ptr(&hlt_var_args,fun_var_args,c);
 }
 
-HL_PRIM void hl_prim_not_loaded() {
-	hl_error("Primitive or library is missing");
-}
+HL_PRIM void hl_prim_not_loaded() {
+	hl_error("Primitive or library is missing");
+}
 
 HL_PRIM bool hl_is_prim_loaded( vdynamic *f ) {
 	return f && f->t->kind == HFUN && ((vclosure*)f)->fun != hl_prim_not_loaded;
@@ -434,13 +434,13 @@ DEFINE_PRIM(_DYN, call_method, _DYN _ARR);
 DEFINE_PRIM(_BOOL, is_prim_loaded, _DYN);
 
 #if defined(HL_VCC) && !defined(HL_XBO)
-static LONG CALLBACK global_handler( PEXCEPTION_POINTERS inf ) {
+static LONG CALLBACK global_handler( PEXCEPTION_POINTERS inf ) {
 	switch( inf->ExceptionRecord->ExceptionCode ) {
 	case EXCEPTION_ACCESS_VIOLATION: hl_error("Access violation");
 	case EXCEPTION_STACK_OVERFLOW: hl_error("Stack overflow");
 	default: break;
 	}
-	return EXCEPTION_CONTINUE_SEARCH;
+	return EXCEPTION_CONTINUE_SEARCH;
 }
 #endif