added moo_oowtoptr() and moo_ptrtooow()
This commit is contained in:
		| @ -840,7 +840,7 @@ static moo_oop_t string_to_error (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) | |||||||
| 	return MOO_ERROR_TO_OOP(num); | 	return MOO_ERROR_TO_OOP(num); | ||||||
| } | } | ||||||
|  |  | ||||||
| static moo_oop_t string_to_smptr (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) | static moo_oop_t string_to_ptr (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) | ||||||
| { | { | ||||||
| 	moo_oow_t num = 0; | 	moo_oow_t num = 0; | ||||||
| 	const moo_ooch_t* ptr, * end; | 	const moo_ooch_t* ptr, * end; | ||||||
| @ -874,22 +874,7 @@ static moo_oop_t string_to_smptr (moo_t* moo, moo_oocs_t* str, moo_ioloc_t* loc) | |||||||
| 		ptr++; | 		ptr++; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| #if 0 | 	return moo_oowtoptr(moo, num); | ||||||
| 	if (!MOO_IN_SMPTR_RANGE(num)) |  | ||||||
| 	{ |  | ||||||
| 		moo_setsynerr (moo, MOO_SYNERR_SMPTRLITINVAL, loc, str); |  | ||||||
| 		return MOO_NULL; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return MOO_SMPTR_TO_OOP(num); |  | ||||||
| #else |  | ||||||
| 	/* TODO: change the function name from string_to_smptr() to string_to_ptr() if this part of code is permanently accepted */ |  | ||||||
| 	if (MOO_IN_SMPTR_RANGE(num)) return MOO_SMPTR_TO_OOP(num); |  | ||||||
| 	ret = moo_instantiate(moo, moo->_large_pointer, MOO_NULL, 0); |  | ||||||
| 	if (!ret) return MOO_NULL; |  | ||||||
| 	MOO_OBJ_SET_WORD_VAL(ret, 0, num); |  | ||||||
| 	return ret; |  | ||||||
| #endif |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* --------------------------------------------------------------------- | /* --------------------------------------------------------------------- | ||||||
| @ -5537,7 +5522,7 @@ static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, cons | |||||||
| 			{ | 			{ | ||||||
| 				moo_oop_t tmp; | 				moo_oop_t tmp; | ||||||
|  |  | ||||||
| 				tmp = string_to_smptr(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | 				tmp = string_to_ptr(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | ||||||
| 				if (!tmp) return -1; | 				if (!tmp) return -1; | ||||||
|  |  | ||||||
| 				if (add_literal(moo, tmp, &index) <= -1 || | 				if (add_literal(moo, tmp, &index) <= -1 || | ||||||
| @ -9501,7 +9486,7 @@ static moo_oop_t token_to_literal (moo_t* moo, int rdonly) | |||||||
| 			return string_to_error(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | 			return string_to_error(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | ||||||
|  |  | ||||||
| 		case MOO_IOTOK_SMPTRLIT: | 		case MOO_IOTOK_SMPTRLIT: | ||||||
| 			return string_to_smptr(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | 			return string_to_ptr(moo, TOKEN_NAME(moo), TOKEN_LOC(moo)); | ||||||
|  |  | ||||||
| 		case MOO_IOTOK_CHARLIT: | 		case MOO_IOTOK_CHARLIT: | ||||||
| 			MOO_ASSERT (moo, TOKEN_NAME_LEN(moo) == 1); | 			MOO_ASSERT (moo, TOKEN_NAME_LEN(moo) == 1); | ||||||
|  | |||||||
| @ -2173,6 +2173,7 @@ MOO_EXPORT int moo_initdbgi ( | |||||||
| MOO_EXPORT void moo_finidbgi ( | MOO_EXPORT void moo_finidbgi ( | ||||||
| 	moo_t* moo | 	moo_t* moo | ||||||
| ); | ); | ||||||
|  |  | ||||||
| /* ========================================================================= | /* ========================================================================= | ||||||
|  * COMMON OBJECT MANAGEMENT FUNCTIONS |  * COMMON OBJECT MANAGEMENT FUNCTIONS | ||||||
|  * ========================================================================= */ |  * ========================================================================= */ | ||||||
| @ -2254,6 +2255,17 @@ MOO_EXPORT int moo_inttointmax ( | |||||||
| ); | ); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | MOO_EXPORT moo_oop_t moo_oowtoptr ( | ||||||
|  | 	moo_t*    moo, | ||||||
|  | 	moo_oow_t num | ||||||
|  | ); | ||||||
|  |  | ||||||
|  | MOO_EXPORT int moo_ptrtooow ( | ||||||
|  | 	moo_t*      moo, | ||||||
|  | 	moo_oop_t   ptr, | ||||||
|  | 	moo_oow_t*  num | ||||||
|  | ); | ||||||
|  |  | ||||||
| MOO_EXPORT moo_oop_t moo_findclass ( | MOO_EXPORT moo_oop_t moo_findclass ( | ||||||
| 	moo_t*            moo, | 	moo_t*            moo, | ||||||
| 	moo_oop_nsdic_t   nsdic, | 	moo_oop_nsdic_t   nsdic, | ||||||
|  | |||||||
| @ -387,3 +387,33 @@ moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_class_t _class, moo_oo | |||||||
| 	moo_popvolats (moo, tmp_count); | 	moo_popvolats (moo, tmp_count); | ||||||
| 	return oop; | 	return oop; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | moo_oop_t moo_oowtoptr (moo_t* moo, moo_oow_t num) | ||||||
|  | { | ||||||
|  | 	moo_oop_t ret; | ||||||
|  |  | ||||||
|  | 	if (MOO_IN_SMPTR_RANGE(num)) return MOO_SMPTR_TO_OOP(num); | ||||||
|  | 	ret = moo_instantiate(moo, moo->_large_pointer, MOO_NULL, 0); | ||||||
|  | 	if (!ret) return MOO_NULL; | ||||||
|  | 	MOO_OBJ_SET_WORD_VAL(ret, 0, num); | ||||||
|  | 	return ret; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int moo_ptrtooow (moo_t* moo, moo_oop_t ptr, moo_oow_t* num) | ||||||
|  | { | ||||||
|  | 	if (MOO_OOP_IS_SMPTR(ptr))  | ||||||
|  | 	{ | ||||||
|  | 		*num = (moo_oow_t)MOO_OOP_TO_SMPTR(ptr); | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (MOO_CLASSOF(moo, ptr) == moo->_large_pointer) | ||||||
|  | 	{ | ||||||
|  | 		MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(ptr) == 1); | ||||||
|  | 		*num = MOO_OBJ_GET_WORD_VAL(ptr, 0); | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	moo_seterrnum (moo, MOO_EINVAL); | ||||||
|  | 	return -1; | ||||||
|  | } | ||||||
|  | |||||||
| @ -542,8 +542,7 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) | |||||||
| 	sig = MOO_STACK_GETARG(moo, nargs, 1); | 	sig = MOO_STACK_GETARG(moo, nargs, 1); | ||||||
| 	args = MOO_STACK_GETARG(moo, nargs, 2); | 	args = MOO_STACK_GETARG(moo, nargs, 2); | ||||||
|  |  | ||||||
| 	if (MOO_OOP_IS_SMPTR(fun)) f = MOO_OOP_TO_SMPTR(fun); | 	if (moo_ptrtooow(moo, fun, (moo_oow_t*)&f) <= -1) goto softfail; | ||||||
| 	else if (moo_inttooow(moo, fun, (moo_oow_t*)&f) <= -1) goto softfail; |  | ||||||
|  |  | ||||||
| 	/* the signature must not be empty. at least the return type must be | 	/* the signature must not be empty. at least the return type must be | ||||||
| 	 * specified */ | 	 * specified */ | ||||||
| @ -851,27 +850,9 @@ static moo_pfrc_t pf_getsym (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) | |||||||
|  |  | ||||||
| 	MOO_DEBUG4 (moo, "<ffi.getsym> %.*js => %p in %p\n", MOO_OBJ_GET_SIZE(name), MOO_OBJ_GET_CHAR_SLOT(name), sym, ffi->handle); | 	MOO_DEBUG4 (moo, "<ffi.getsym> %.*js => %p in %p\n", MOO_OBJ_GET_SIZE(name), MOO_OBJ_GET_CHAR_SLOT(name), sym, ffi->handle); | ||||||
|  |  | ||||||
| #if 0 |  | ||||||
| 	ret = moo_oowtoptr(moo, (moo_oow_t)sym); | 	ret = moo_oowtoptr(moo, (moo_oow_t)sym); | ||||||
| 	if (!ret) goto softfail; | 	if (!ret) goto softfail; | ||||||
|  |  | ||||||
| #else |  | ||||||
| 	if (MOO_IN_SMPTR_RANGE(sym)) |  | ||||||
| 	{ |  | ||||||
| 		ret = MOO_SMPTR_TO_OOP(sym); |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		ret = moo_oowtoint(moo, (moo_oow_t)sym); |  | ||||||
| 		if (!ret) goto softfail; |  | ||||||
| 		/* |  | ||||||
| 		MOO_DEBUG1 (moo, "<ffi.getsym> unaligned symbol address - %p\n", sym); |  | ||||||
| 		moo_seterrnum (moo, MOO_EINVAL); |  | ||||||
| 		goto softfail; |  | ||||||
| 		*/ |  | ||||||
| 	} |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	MOO_STACK_SETRET (moo, nargs, ret); | 	MOO_STACK_SETRET (moo, nargs, ret); | ||||||
| 	return MOO_PF_SUCCESS; | 	return MOO_PF_SUCCESS; | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user