Example #1
0
File: jit.cpp Project: goccy/gperl
GPerlJITCompiler::GPerlJITCompiler(void)
{
	size_t h_fields_num = 5;
	jit_type_t h_fields[5];
	h_fields[0] = jit_type_int;/* type */
	h_fields[1] = jit_type_int;/* mark_flag */
	h_fields[2] = jit_type_void_ptr;/* mark */
	h_fields[3] = jit_type_void_ptr;/* free */
	h_fields[4] = jit_type_void_ptr;/* next */
	jit_type_t header = jit_type_create_struct(h_fields, h_fields_num, 0);
	size_t fields_num = 5;
	jit_type_t fields[5];
	fields[0] = header;
	fields[1] = jit_type_void_ptr;/* slot1 */
	fields[2] = jit_type_void_ptr;/* slot2 */
	fields[3] = jit_type_void_ptr;/* slot3 */
	fields[4] = jit_type_void_ptr;/* slot4 */
	jit_type_t object = jit_type_create_struct(fields, fields_num, 0);
	object_ptr_type = jit_type_create_pointer(object, 0);
	jit_type_t v_fields[6];
	size_t v_fields_num = 6;
	v_fields[0] = jit_type_sys_ulonglong; /* bytes */
	v_fields[1] = jit_type_int;    /* ivalue */
	v_fields[2] = jit_type_float64;/* dvalue */
	v_fields[3] = jit_type_sys_bool;    /* bvalue */
	v_fields[4] = jit_type_void_ptr;/* svalue */
	v_fields[5] = jit_type_void_ptr;/* ovalue */
	value_type = jit_type_create_union(v_fields, v_fields_num, 0);
}
Example #2
0
PHP_METHOD(Struct, __construct) {
	HashTable *zfields;
	HashPosition zposition;
	php_jit_struct_t *pstruct;
	zval *zmember;
	zend_ulong nfield = 0;
	jit_type_t *jfields;
	char **jnames = NULL;
	
	if (php_jit_parameters("H", &zfields) != SUCCESS) {
		php_jit_exception("unexpected parameters, expected (Type[] fields)");
		return;
	}
	
	pstruct = PHP_JIT_FETCH_STRUCT(getThis());
	
	pstruct->nfields = zend_hash_num_elements(zfields);
	pstruct->zfields  = 
		(zval*) ecalloc(pstruct->nfields, sizeof(zval));
	jfields = 
		(jit_type_t*) ecalloc(pstruct->nfields, sizeof(jit_type_t));
	
	for (zend_hash_internal_pointer_reset_ex(zfields, &zposition);
		(zmember = zend_hash_get_current_data_ex(zfields, &zposition));
		zend_hash_move_forward_ex(zfields, &zposition)) {
		zend_ulong znidx = 0L;
		zend_string *zname = NULL;
		php_jit_type_t *ptype;
		
		if (!zmember || 
			Z_TYPE_P(zmember) != IS_OBJECT || 
			!instanceof_function(Z_OBJCE_P(zmember), jit_type_ce)) {
			php_jit_exception("non type found in fields list at %d", nfield);
			return;
		}
		ZVAL_COPY(&pstruct->zfields[nfield], zmember);
		
		ptype = 
		    PHP_JIT_FETCH_TYPE(&pstruct->zfields[nfield]);
		
		jfields[nfield] = jit_type_copy(ptype->type);
		
		if (zend_hash_get_current_key_ex(zfields, &zname, &znidx, &zposition) == HASH_KEY_IS_STRING) {
			if (!zname || !ZSTR_LEN(zname)) {
				php_jit_exception("invalid name found in fields list at %d", nfield);
				efree(jfields);
				return;
			}
			
			if (!pstruct->names) {
				pstruct->names = ecalloc(pstruct->nfields, sizeof(zend_string*));
			}
			
			pstruct->names[nfield] = zend_string_copy(zname);
		} else {
			if (pstruct->names) {
				php_jit_exception("un-named type found in fields list at %d", nfield);
				efree(jfields);
				return;
			}
		}
		
		nfield++;
	}
	
	pstruct->type = jit_type_create_struct(jfields, pstruct->nfields, 0);
	
	if (pstruct->names) {
		jit_type_set_names(pstruct->type, (char**) pstruct->names, pstruct->nfields);	
	}
	
	efree(jfields);
}