Esempio n. 1
0
File: a2_vm.c Progetto: eagles125/A2
// set value
static inline void _vm_setvalue(struct a2_vm* vm_p){
	struct a2_obj* _c = callinfo_sfreg(curr_ci, ir_ga(curr_ir));
	struct a2_obj* _k = _getvalue(vm_p, ir_gb(curr_ir));
	struct a2_obj* _v = _getvalue(vm_p, ir_gc(curr_ir));
	struct a2_obj* __d = NULL;
	switch(obj_t(_c)){
		case A2_TARRAY:
	 		if(obj_t(_k)!=A2_TNUMBER)
	 			vm_error("the key is must number at set array.");
			__d = a2_array_get(a2_gcobj2array(obj_vX(_c, obj)), _k);
			if(!__d)  goto SVALUE_ERROR;
			*__d = *_v;
			break;
		case A2_TMAP:
			if(obj_t(_k)!=A2_TNUMBER && obj_t(_k)!=A2_TSTRING)
				vm_error("the key is must number or string at set map.");
			__d = a2_map_query(a2_gcobj2map(obj_vX(_c, obj)), _k);
			if(!__d) goto SVALUE_ERROR;
			*__d = *_v;
			break;
		default:
			vm_error("the varable is not map or array.");
	}

 	curr_pc++;
 	return;
 SVALUE_ERROR:
 	vm_error("the key is overfllow.");
}
Esempio n. 2
0
// get array
A2_API inline void a2_getarray(struct a2_state* state){
	int top = a2_top(state)-1;
	struct a2_obj* k = a2_getcstack(state->env_p, top);
	struct a2_obj* array = a2_getcstack(state->env_p, top-1);
	struct a2_obj* _v = NULL;

	check_array(array);
	check_num(k);
	_v = a2_array_get(a2_gcobj2array(obj_vX(array, obj)), k);
	if(_v==NULL)
		obj_setX(k, A2_TNIL, point, NULL);
	else
		*k = *_v;
}
Esempio n. 3
0
// set array
A2_API inline void a2_setarray(struct a2_state* state){
	int top = a2_top(state)-1;
	struct a2_obj* v = a2_getcstack(state->env_p, top);
	struct a2_obj* k = a2_getcstack(state->env_p, top-1);
	struct a2_obj* array = a2_getcstack(state->env_p, top-2);
	struct a2_obj* _v = NULL;

	check_array(array);
	check_num(k);
	_v  = a2_array_get(a2_gcobj2array(obj_vX(array, obj)), k);
	if(_v==NULL)
		a2_error(state->env_p, e_run_error, 
			"the error index at array.\n");
	else
		*_v = *v;
	a2_topset(state, top-1);
}