Browse Source

Fixed most warnings

Saša Barišić 8 years ago
parent
commit
b0a48bf696

+ 1 - 1
gravity_visualstudio/exports.def

@@ -1,4 +1,4 @@
-LIBRARY gravity
+LIBRARY GravityLang
 EXPORTS
 
 ;;;	gravity_vm.h

+ 4 - 1
src/compiler/gravity_codegen.c

@@ -128,6 +128,9 @@ static opcode_t token2opcode(gtoken_t op) {
 		
 		default: assert(0); break;  // should never reach this point
 	}
+
+	assert(0);
+	return NOT; // huehue, geddit?
 }
 
 #if 0
@@ -789,7 +792,7 @@ static void visit_function_decl (gvisitor_t *self, gnode_function_decl_t *node)
 	if (node->block) {gnode_array_each(node->block->stmts, {visit(val);});}
 	
 	// check for upvalues
-	if (node->uplist) f->nupvalues = gnode_array_size(node->uplist);
+	if (node->uplist) f->nupvalues = (uint16_t)gnode_array_size(node->uplist);
 	
 	// remove current function
 	CONTEXT_POP();

+ 3 - 3
src/compiler/gravity_optimizer.c

@@ -205,7 +205,7 @@ static void finalize_function (gravity_function_t *f) {
 	gravity_hash_free(labels);
 	
 	f->bytecode = bytecode;
-	f->purity = (notpure == 0) ? 1.0 : ((float)(notpure * 100) / (float)ninst) / 100.0f;
+	f->purity = (notpure == 0) ? 1.0f : ((float)(notpure * 100) / (float)ninst) / 100.0f;
 }
 
 // MARK: -
@@ -302,7 +302,7 @@ static bool optimize_const_instruction (inst_t *inst, inst_t *inst1, inst_t *ins
 			break;
 			
 		case REM:
-			if (type == DOUBLE_TAG) d = (int64_t)d1 % (int64_t)d2;
+			if (type == DOUBLE_TAG) d = (double)((int64_t)d1 % (int64_t)d2);
 			else n = n1 % n2;
 			break;
 			
@@ -337,7 +337,7 @@ static bool optimize_neg_instruction (ircode_t *code, inst_t *inst, uint32_t i)
 	uint64_t n = inst1->n;
 	if (n>131072) return false;
 	inst1->p1 = inst->p2;
-	inst1->n = -n;
+	inst1->n = -(int64_t)n;
 	inst_setskip(inst);
 	return true;
 }

+ 1 - 1
src/compiler/gravity_semacheck2.c

@@ -207,7 +207,7 @@ static gnode_t *lookup_identifier (gvisitor_t *self, const char *identifier, gno
 				
 				// add upvalue to all enclosing functions
 				// base_node has index = len - 1 so from (len - 2) up to n-1 levels
-				uint16_t idx = len - 2;
+				uint16_t idx = (uint16_t)(len - 2);
 				while (n > 1) {
 					f = (gnode_function_decl_t *) gnode_array_get(decls, idx);
 					gnode_function_add_upvalue(f, var, --n);

+ 3 - 3
src/runtime/gravity_core.c

@@ -659,7 +659,7 @@ static bool list_loadat (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
 	register uint32_t count = (uint32_t)marray_size(list->array);
 	
 	if (index < 0) index = count + index;
-	if ((index < 0) || (index >= count)) RETURN_ERROR("Out of bounds error: index %d beyond bounds 0...%d", index, count-1);
+	if ((index < 0) || ((uint32_t)index >= count)) RETURN_ERROR("Out of bounds error: index %d beyond bounds 0...%d", index, count-1);
 	
 	RETURN_VALUE(marray_get(list->array, index), rindex);
 }
@@ -676,11 +676,11 @@ static bool list_storeat (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
 	
 	if (index < 0) index = count + index;
 	if (index < 0) RETURN_ERROR("Out of bounds error: index %d beyond bounds 0...%d", index, count-1);
-	if (index >= count) {
+	if ((uint32_t)index >= count) {
 		// handle list resizing here
 		marray_resize(gravity_value_t, list->array, index-count);
 		marray_nset(list->array, index+1);
-		for (size_t i=count; i<index; ++i) {
+		for (int32_t i=count; i<index; ++i) {
 			marray_set(list->array, i, VALUE_FROM_NULL);
 		}
 		marray_set(list->array, index, value);

+ 1 - 1
src/runtime/gravity_vm.c

@@ -1961,7 +1961,7 @@ void gravity_gc_start (gravity_vm *vm) {
 	gravity_gc_sweep(vm);
 	
 	// dynamically update gcthreshold
-	vm->gcthreshold = vm->memallocated + (vm->memallocated * vm->gcratio / 100);
+	vm->gcthreshold = (gravity_int_t)(vm->memallocated + (vm->memallocated * vm->gcratio / 100));
 	if (vm->gcthreshold < vm->gcminthreshold) vm->gcthreshold = vm->gcminthreshold;
 	
 	#if GRAVITY_GC_STATS

+ 1 - 1
src/shared/gravity_value.c

@@ -509,7 +509,7 @@ uint16_t gravity_function_cpool_add (gravity_vm *vm, gravity_function_t *f, grav
 		gravity_value_t v2 = marray_get(f->cpool, i);
 		if (gravity_value_equals(v,v2)) {
 			gravity_value_free(NULL, v);
-			return i;
+			return (uint16_t)i;
 		}
 	}
 	

+ 4 - 3
src/utils/gravity_utils.c

@@ -215,7 +215,8 @@ DIRREF directory_init (const char *dirpath) {
 	WCHAR			path[MAX_PATH];
 	WCHAR			dirpathW[MAX_PATH];
 	HANDLE			hFind;
-	
+	(void)hFind;
+
 	// convert dirpath to dirpathW
 	MultiByteToWideChar(CP_UTF8, 0, dirpath, -1, dirpathW, MAX_PATH);
 	
@@ -236,7 +237,7 @@ const char *directory_read (DIRREF ref) {
 	while (1) {
 		#ifdef WIN32
 		WIN32_FIND_DATA findData;
-		const char 			*file_name;
+		char 			*file_name;
 		
 		if (FindNextFile(ref, &findData) == 0) {
 			FindClose(ref);
@@ -247,7 +248,7 @@ const char *directory_read (DIRREF ref) {
 		if (findData.cFileName[0] == '.') continue;
 
 		file_name = malloc(MAX_PATH);
-		strncpy(file_name, findData.cFileName, MAX_PATH);
+		strncpy(file_name, (const char*)findData.cFileName, MAX_PATH); // TODO: Incompatible types, fix WCHAR* -> const char*
 
 		return (const char *)file_name;
 		#else