// 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."); }
// get map A2_API inline void a2_getmap(struct a2_state* state){ int top = a2_top(state)-1; struct a2_obj* k = a2_getcstack(state->env_p, top); struct a2_obj* map = a2_getcstack(state->env_p, top-1); struct a2_obj* v = NULL; check_map(map); check_key(k); v = a2_map_query(a2_gcobj2map(obj_vX(map, obj)), k); if(v==NULL) obj_setX(map, A2_TNIL, point, NULL); else *map = *v; }
//set map static inline void _vm_setmap(struct a2_vm* vm_p){ int i, end=ir_gb(curr_ir)+2*ir_gc(curr_ir); struct a2_obj* _d = callinfo_sfreg(curr_ci, ir_ga(curr_ir)); struct a2_obj* _v = NULL; struct a2_map* map = NULL; assert(obj_t(_d)==A2_TMAP); struct a2_kv kv={0}; for(i=ir_gb(curr_ir); i<end; i+=2){ kv.key = callinfo_sfreg(curr_ci, i); kv.vp = callinfo_sfreg(curr_ci, i+1); map = a2_gcobj2map(obj_vX(_d, obj)); if( (_v=a2_map_query(map, kv.key))==NULL ) a2_map_add(map, &kv); else *_v = *kv.vp; } curr_pc++; }