2
0
Nicolas Cannasse 9 жил өмнө
parent
commit
387f02a523
4 өөрчлөгдсөн 41 нэмэгдсэн , 36 устгасан
  1. 11 0
      src/callback.c
  2. 23 20
      src/code.c
  3. 1 0
      src/hlmodule.h
  4. 6 16
      src/jit.c

+ 11 - 0
src/callback.c

@@ -136,6 +136,12 @@ static void *hl_call_wrapper_all_ptr( vclosure_wrapper *c ) {
 	return hl_wrapper_call(c,&c + 1, NULL);
 }
 
+static int hl_call_wrapper_all_ptr_i( vclosure_wrapper *c ) {
+	vdynamic d;
+	hl_wrapper_call(c,&c + 1, &d);
+	return d.v.i;
+}
+
 static void *hl_get_wrapper( hl_type *t ) {
 #	ifndef HL_64
 	int i;
@@ -148,6 +154,11 @@ static void *hl_get_wrapper( hl_type *t ) {
 		case HF64:
 			hl_error("TODO");
 			break;
+		case HUI8:
+		case HUI16:
+		case HI32:
+		case HBOOL:
+			return hl_call_wrapper_all_ptr_i;
 		default:
 			return hl_call_wrapper_all_ptr;
 		}

+ 23 - 20
src/code.c

@@ -121,7 +121,7 @@ static hl_type *hl_get_type( hl_reader *r ) {
 	return r->code->types + i;
 }
 
-static const char *hl_get_string( hl_reader *r ) {
+static const char *hl_read_string( hl_reader *r ) {
 	int i = INDEX();
 	if( i < 0 || i >= r->code->nstrings ) {
 		ERROR("Invalid string index");
@@ -130,21 +130,24 @@ static const char *hl_get_string( hl_reader *r ) {
 	return r->code->strings[i];
 }
 
-static const uchar *hl_get_ustring( hl_reader *r ) {
+const uchar *hl_get_ustring( hl_code *code, int index ) {
+	uchar *str = code->ustrings[index];
+	if( str == NULL ) {
+		int size = hl_utf8_length((vbyte*)code->strings[index],0);
+		str = hl_malloc(&code->alloc,(size+1)<<1);
+		hl_from_utf8(str,size+1,code->strings[index]);
+		code->ustrings[index] = str;
+	}
+	return str;
+}
+
+static const uchar *hl_read_ustring( hl_reader *r ) {
 	int i = INDEX();
-	uchar *str;
 	if( i < 0 || i >= r->code->nstrings ) {
 		ERROR("Invalid string index");
 		i = 0;
 	}
-	str = r->code->ustrings[i];
-	if( str == NULL ) {
-		int size = hl_utf8_length((vbyte*)r->code->strings[i],0);
-		str = hl_malloc(&r->code->alloc,(size+1)<<1);
-		hl_from_utf8(str,size+1,r->code->strings[i]);
-		r->code->ustrings[i] = str;
-	}
-	return str;
+	return hl_get_ustring(r->code,i);
 }
 
 static void hl_read_type( hl_reader *r, hl_type *t ) {
@@ -165,7 +168,7 @@ static void hl_read_type( hl_reader *r, hl_type *t ) {
 	case HOBJ:
 		{
 			int i;
-			const uchar *name = hl_get_ustring(r);
+			const uchar *name = hl_read_ustring(r);
 			int super = INDEX();
 			int global = UINDEX();
 			int nfields = UINDEX();
@@ -181,13 +184,13 @@ static void hl_read_type( hl_reader *r, hl_type *t ) {
 			t->obj->rt = NULL;
 			for(i=0;i<nfields;i++) {
 				hl_obj_field *f = t->obj->fields + i;
-				f->name = hl_get_ustring(r);
+				f->name = hl_read_ustring(r);
 				f->hashed_name = hl_hash_gen(f->name,true);
 				f->t = hl_get_type(r);
 			}
 			for(i=0;i<nproto;i++) {
 				hl_obj_proto *p = t->obj->proto + i;
-				p->name = hl_get_ustring(r);
+				p->name = hl_read_ustring(r);
 				p->hashed_name = hl_hash_gen(p->name,true);
 				p->findex = UINDEX();
 				p->pindex = INDEX();
@@ -206,26 +209,26 @@ static void hl_read_type( hl_reader *r, hl_type *t ) {
 			t->virt->fields = (hl_obj_field*)hl_malloc(&r->code->alloc,sizeof(hl_obj_field)*nfields);
 			for(i=0;i<nfields;i++) {
 				hl_obj_field *f = t->virt->fields + i;
-				f->name = hl_get_ustring(r);
+				f->name = hl_read_ustring(r);
 				f->hashed_name = hl_hash_gen(f->name,true);
 				f->t = hl_get_type(r);
 			}
 		}
 		break;
 	case HABSTRACT:
-		t->abs_name = hl_get_ustring(r);
+		t->abs_name = hl_read_ustring(r);
 		break;
 	case HENUM:
 		{
 			int i,j;
 			t->tenum = hl_malloc(&r->code->alloc,sizeof(hl_type_enum));
-			t->tenum->name = hl_get_ustring(r);
+			t->tenum->name = hl_read_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);
 			for(i=0;i<t->tenum->nconstructs;i++) {
 				hl_enum_construct *c = t->tenum->constructs + i;
-				c->name = hl_get_ustring(r);
+				c->name = hl_read_ustring(r);
 				c->nparams = UINDEX();
 				c->params = (hl_type**)hl_malloc(&r->code->alloc,sizeof(hl_type*)*c->nparams);
 				c->offsets = (int*)hl_malloc(&r->code->alloc,sizeof(int)*c->nparams);
@@ -464,8 +467,8 @@ hl_code *hl_code_read( const unsigned char *data, int size ) {
 	ALLOC(c->natives, hl_native, c->nnatives);
 	for(i=0;i<c->nnatives;i++) {
 		hl_native *n = c->natives + i;
-		n->lib = hl_get_string(r);
-		n->name = hl_get_string(r);
+		n->lib = hl_read_string(r);
+		n->name = hl_read_string(r);
 		n->t = hl_get_type(r);
 		n->findex = UINDEX();
 	}

+ 1 - 0
src/hlmodule.h

@@ -90,6 +90,7 @@ typedef struct jit_ctx jit_ctx;
 
 hl_code *hl_code_read( const unsigned char *data, int size );
 void hl_code_free( hl_code *c );
+const uchar *hl_get_ustring( hl_code *c, int index );
 const char* hl_op_name( int op );
 
 hl_module *hl_module_alloc( hl_code *code );

+ 6 - 16
src/jit.c

@@ -2222,7 +2222,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 					preg *a = alloc_cpu(ctx,ra,true);
 					op64(ctx,TEST,a,a);
 					XJump_small(JNotZero,jnz);
-					store(ctx,dst,a,true);
+					op64(ctx,XOR,PEAX,PEAX); // will replace the result of alloc_dynamic at jump land
 					XJump_small(JAlways,jskip);
 					patch_jump(ctx,jnz);
 				}
@@ -2243,8 +2243,8 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 					copy_from(ctx,tmp,ra);
 					op64(ctx,MOV,pmem(&p,Eax,8),tmp);
 				}
-				store(ctx, dst, PEAX, true);
 				if( hl_is_ptr(ra->t) ) patch_jump(ctx,jskip);
+				store(ctx, dst, PEAX, true);
 			}
 			break;
 		case OToSFloat:
@@ -2341,18 +2341,8 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 			}
 			break;
 		case OString:
-			{
-				uchar *str = m->code->ustrings[o->p2];
-				if( !str ) {
-					int i = o->p2;
-					int size = hl_utf8_length((vbyte*)m->code->strings[i],0);
-					str = hl_malloc(&m->code->alloc,(size+1)<<1);
-					hl_from_utf8(str,size+1,m->code->strings[i]);
-					m->code->ustrings[i] = str;
-				}
-				op64(ctx,MOV,alloc_cpu(ctx, dst, false),pconst64(&p,(int_val)str));
-				store(ctx,dst,dst->current,false);
-			}
+			op64(ctx,MOV,alloc_cpu(ctx, dst, false),pconst64(&p,(int_val)hl_get_ustring(m->code,o->p2)));
+			store(ctx,dst,dst->current,false);
 			break;
 		case OBytes:
 			op64(ctx,MOV,alloc_cpu(ctx,dst,false),pconst64(&p,(int_val)m->code->strings[o->p2]));
@@ -2996,7 +2986,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 				case HF64:
 					size = pad_before_call(ctx, HL_WSIZE*2 + sizeof(double));
 					push_reg(ctx,rb);
-					op32(ctx,PUSH,pconst64(&p,hl_hash_utf8(m->code->strings[o->p2])),UNUSED);
+					op32(ctx,PUSH,pconst64(&p,hl_hash_gen(hl_get_ustring(m->code,o->p2),true)),UNUSED);
 					op32(ctx,PUSH,fetch(dst),UNUSED);
 					call_native(ctx,get_dynset(rb->t),size);
 					break;
@@ -3004,7 +2994,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 					size = pad_before_call(ctx, HL_WSIZE*4);
 					op32(ctx,PUSH,fetch(rb),UNUSED);
 					op32(ctx,PUSH,pconst64(&p,(int_val)rb->t),UNUSED);
-					op32(ctx,PUSH,pconst64(&p,hl_hash_utf8(m->code->strings[o->p2])),UNUSED);
+					op32(ctx,PUSH,pconst64(&p,hl_hash_gen(hl_get_ustring(m->code,o->p2),true)),UNUSED);
 					op32(ctx,PUSH,fetch(dst),UNUSED);
 					call_native(ctx,get_dynset(rb->t),size);
 					break;