int main() { /* ** Push several values on each stack. */ push_int( 5 ); push_int( 22 ); push_int( 15 ); push_float( 25.3 ); push_float( -40.5 ); /* ** Empty the integer stack and print the values. */ while( !is_empty_int() ) { printf( "Popping %d\n", top_int() ); pop_int(); } /* ** Empty the float stack and print the values. */ while( !is_empty_float() ) { printf( "Popping %f\n", top_float() ); pop_float(); } return EXIT_SUCCESS; }
/* ** 'get_number' is called to evaluate an expression that returns an ** integer value. It is used by the functions handling the various ** Basic commands in this file */ static int32 get_number(void) { factor(); switch (get_topitem()) { case STACK_INT: return pop_int(); case STACK_FLOAT: return TOINT(pop_float()); default: error(ERR_TYPENUM); } return 0; }
/*----------------------------------------------------------------------------*/ PmReturn_t tres_pm_get_state(pPmFrame_t *ppframe) { PmReturn_t retv = PM_RET_OK; pPmObj_t pobj; pPmObj_t pobj_new; pPmInstance_t pcli; pPmDict_t pdict; int16_t index; float fval; int32_t ival; if(NATIVE_GET_NUM_ARGS() != 1) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } pobj = NATIVE_GET_LOCAL(0); if(OBJ_GET_TYPE(pobj) != OBJ_TYPE_CLI) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } pcli = (pPmInstance_t)pobj; pdict = pcli->cli_attrs; if(*tres_pm_io.state_len > 0) { // restore each attribute of the object for(index = pdict->length - 1; index >= 0; index--) { seglist_getItem(pdict->d_keys, index, &pobj); retv = seglist_getItem(pdict->d_vals, index, &pobj); PM_RETURN_IF_ERROR(retv); switch (OBJ_GET_TYPE(pobj)) { case OBJ_TYPE_INT: //pop int pop_int(&ival); retv = int_new(ival, &pobj_new); break; case OBJ_TYPE_FLT: //pop float pop_float(&fval); retv = float_new(fval, &pobj_new); break; default: /* Raise TypeError */ PM_RAISE(retv, PM_RET_EX_TYPE); } if (retv == PM_RET_OK) { seglist_setItem(pdict->d_vals, pobj_new, index); } } } NATIVE_SET_TOS((pPmObj_t)pcli); return retv; }
/*----------------------------------------------------------------------------*/ PmReturn_t tres_pm_state_pop(pPmFrame_t *ppframe) { PmReturn_t retv = PM_RET_OK; pPmObj_t r_pflt; pPmObj_t pa; float fval; int32_t ival; int pop_retv; /* Raise TypeError if wrong number of args */ pa = NATIVE_GET_LOCAL(0); if(NATIVE_GET_NUM_ARGS() != 1) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } switch (OBJ_GET_TYPE(pa)) { //case OBJ_TYPE_STR: // ptr = (char const *)&(((pPmString_t)pa)->val); // // TODO: unimplemented // break; case OBJ_TYPE_INT: pop_retv = pop_int(&ival); if(pop_retv != TRES_ERR_NONE) { ival = ((pPmInt_t) pa)->val; } retv = int_new(ival, &r_pflt); break; case OBJ_TYPE_FLT: pop_retv = pop_float(&fval); if(pop_retv != TRES_ERR_NONE) { fval = ((pPmFloat_t) pa)->val; } retv = float_new(fval, &r_pflt); break; default: /* Raise TypeError */ PM_RAISE(retv, PM_RET_EX_TYPE); } NATIVE_SET_TOS(r_pflt); return retv; }
bool parse(SensorInfo &si) { _error.str(""); std::string spec_type; float x=std::numeric_limits<float>::quiet_NaN(); float y=std::numeric_limits<float>::quiet_NaN(); float z=std::numeric_limits<float>::quiet_NaN(); Spec spec_marker[] = { { "led", "uint32_t", &si.id, true }, { "tracker", "uint32_t", &si.tracker, false }, { "x", "float", &x, false }, { "y", "float", &y, false }, { "z", "float", &z, false }, { "", "", NULL, false } // sentinel }; Spec spec_rigid[] = { { "tracker", "uint32_t", &si.tracker, true }, { "", "", NULL, false } // sentinel }; if(pop_int("sensor", si.sensor_id)) { _error << "required key 'sensor' not found"; return false; } if(pop("type", spec_type)) { _error << "required key 'type' not found"; return false; } Spec* spec = NULL; if(spec_type == "rigid" || spec_type == "rigid_body") { si.type = OWL::Type::RIGID; spec = spec_rigid; } else if(spec_type == "point") { si.type = OWL::Type::MARKER; spec = spec_marker; } else { _error << "unknown sensor type: " << spec_type; return false; } for(int i = 0; spec[i].dest; i++) { int ret = 0; if(spec[i].type == "string") ret = pop(spec[i].key, *((std::string*) spec[i].dest)); else if(spec[i].type == "uint32_t") ret = pop_uint(spec[i].key, *((uint32_t*) spec[i].dest)); else if(spec[i].type == "float") ret = pop_float(spec[i].key, *((float*) spec[i].dest)); else { _error << "unknown spec type: " << spec[i].type; return false; } if(ret == 1) { if(spec[i].required) { _error << "required key not found: " << spec[i].key; return false; } } else if(ret) { _error << "error reading value for key \'" << spec[i].key << "'"; return false; } } if(si.type == OWL::Type::RIGID) si.id = si.tracker; //special case (legacy) if(!isnan(x) || !isnan(y) || !isnan(z)) { if(isnan(x) || isnan(y) || isnan(z)) { _error << "x,y,z keys must all be specified if any are specified."; return false; } if(contains("pos")) { _error << "pos and x,y,z keys are mutually exclusive."; return false; } std::stringstream pos; pos << x << ',' << y << ',' << z; keyvals["pos"] = pos.str(); } si.opt = join(); return true; }