int Resource::RegisterSymbol(char *symbol, arg_type_t type, void *data) { arg_list_t *sym; arg_list_t *sym_name; if (!symbol || !symbol[0]) { return -1; } switch (type) { case FUNC: printf("You can't bind functions using generic binding\n"); return -2; break; case INT: new_int(&sym, *((int *)data)); break; case FLOAT: new_float(&sym, *((float *)data)); break; case CSTRING: mlisp_new_string(&sym, (char *)data); break; default: mlisp_new_adt(&sym, type, data); } mlisp_new_string(&sym_name, symbol); Bind(sym_name, sym); return 0; }
void do_torus_com(int c) { if (c == 1) { /* None */ TORUS = 0; for (int i = 0; i < MAXODE; i++) itor[i] = 0; return; } new_float("Period :", &TOR_PERIOD); if (TOR_PERIOD <= 0.0) { err_msg("Choose positive period"); return; } if (c == 0) { /* All */ TORUS = 1; for (int i = 0; i < MAXODE; i++) itor[i] = 1; return; } x11_tor_box_open("Fold which", (const char *)uvar_names, itor, NEQ, commit_torus, NULL); }
// build JSON object hierarchy JSON * JSON::parse_private(Lexer *lexer) { // check token to determine what JSON type to construct Json_Token token = lexer->get_token(); switch (token) { case Object_start_token: return parse_object(lexer); case Array_start_token: return parse_array(lexer); case String_token: return new_string(lexer->token_src, lexer->token_len); case Null_token: return new_null(); case True_token: return new_boolean(true); case False_token: return new_boolean(false); case Float_token: return new_float(lexer->float_num); case Unsigned_token: return new_unsigned(lexer->unsigned_num); case Signed_token: return new_signed(lexer->signed_num); default: Serial.println(F("JSON syntax error")); } return null; }
static int handle_float(void *ctx, double doubleVal) { struct parse_context *pctx = (struct parse_context *)ctx; Var v; v = new_float(doubleVal); PUSH(pctx->top, v); return 1; }
int main(){ Float a = new_float(0.1, 5); Float b = new_float(-0.2, 3); Float c = add(a,b); Float d = multiply(b,c); printinfo(a); printinfo(b); printinfo(c); printinfo(d); // int i; // for (i = 0; i < 1000; i++) // { // d = add (d, a); // if (i % 100 == 0) // printinfo(d); // } return 0; }
void new_lookup_com(int i) { char file[128]; int index, ok, status; double xlo, xhi; int npts; char newform[80]; index = select_table(); if (index == -1) return; if (i == 1) { view_table(index); return; } if (my_table[index].flag == 1) { strcpy(file, my_table[index].filename); status = file_selector("Load table", file, "*.tab"); if (status == 0) return; ok = load_table(file, index); if (ok == 1) strcpy(my_table[index].filename, file); } if (my_table[index].flag == 2) { npts = my_table[index].n; xlo = my_table[index].xlo; xhi = my_table[index].xhi; strcpy(newform, my_table[index].filename); new_int("Auto-evaluate? (1/0)", &my_table[index].autoeval); new_int("NPts: ", &npts); new_float("Xlo: ", &xlo); new_float("Xhi: ", &xhi); new_string("Formula :", newform); create_fun_table(npts, xlo, xhi, newform, index); } }
Var dbio_read_var(void) { Var r; int i, l = dbio_read_num(); if (l == (int) TYPE_ANY && dbio_input_version == DBV_Prehistory) l = TYPE_NONE; /* Old encoding for VM's empty temp register * and any as-yet unassigned variables. */ r.type = (var_type) l; switch (l) { case TYPE_CLEAR: case TYPE_NONE: break; case _TYPE_STR: r.v.str = dbio_read_string_intern(); r.type |= TYPE_COMPLEX_FLAG; break; case TYPE_OBJ: case TYPE_ERR: case TYPE_INT: case TYPE_CATCH: case TYPE_FINALLY: r.v.num = dbio_read_num(); break; case _TYPE_FLOAT: r = new_float(dbio_read_float()); break; case _TYPE_LIST: l = dbio_read_num(); r = new_list(l); for (i = 0; i < l; i++) r.v.list[i + 1] = dbio_read_var(); break; default: errlog("DBIO_READ_VAR: Unknown type (%d) at DB file pos. %ld\n", l, ftell(input)); r = zero; break; } return r; }
cont_integ() { double tetemp; double *x; double dif; if(INFLAG==0||FFT!=0||HIST!=0)return; tetemp=TEND; wipe_rep(); data_back(); if(new_float("Continue until:",&tetemp)==-1)return; x=&MyData[0]; tetemp=fabs(tetemp); if(fabs(MyTime)>=tetemp)return; dif=tetemp-fabs(MyTime); /* TEND=tetemp; */ MyStart=1; /* I know it is wasteful to restart, but lets be safe.... */ integrate(&MyTime,x,dif,DELTA_T,1,NJMP,&MyStart); ping(); refresh_browser(storind); }
void do_torus_com(int c) { int i; TORUS=0; if(c==0||c==2){ new_float("Period :",&TOR_PERIOD); if(TOR_PERIOD<=0.0){ err_msg("Choose positive period"); return; } if(c==0){ for(i=0;i<MAXODE;i++)itor[i]=1; TORUS=1; return; } /* Choose them */ choose_torus(); return; } for(i=0;i<MAXODE;i++)itor[i]=0; TORUS=0; }
static int handle_string(void *ctx, const unsigned char *stringVal, unsigned int stringLen) { struct parse_context *pctx = (struct parse_context *)ctx; var_type type; Var v; const char *val = (const char *)stringVal; size_t len = (size_t)stringLen; if (MODE_EMBEDDED_TYPES == pctx->mode && TYPE_NONE != (type = valid_type(&val, &len))) { switch (type) { case TYPE_OBJ: { char *p; if (*val == '#') val++; v.type = TYPE_OBJ; v.v.num = strtol(val, &p, 10); break; } case TYPE_INT: { char *p; v = new_int(strtol(val, &p, 10)); break; } case TYPE_FLOAT: { char *p; v = new_float(strtod(val, &p)); break; } case TYPE_ERR: { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_ERR; int err = parse_error(temp); v.v.err = err > -1 ? err : E_NONE; break; } case TYPE_STR: { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_STR; v.v.str = str_dup(temp); break; } default: panic("Unsupported type in handle_string()"); } } else { char temp[len + 1]; strncpy(temp, val, len); temp[len] = '\0'; v.type = TYPE_STR; v.v.str = str_dup(temp); } PUSH(pctx->top, v); return 1; }
arg_list_t *Resource::Symbol() { int i = 0, j; arg_list_t *a; bool string = false; bool fp = false; float f; arg_list_t *adt; _symbol[0] = 0; if (Is('"')) { Lex(); string = true; } // Mongoose 2001.11.09: Best handle for? grouped (func (func if (Is('(')) { return Function(arg_peek(&_stack)); } while (string || (i == 0 && _look == '-') || isatoz(_look) || isAtoZ(_look) || isdigit(_look) || ismisc(_look)) { if (i < (int)_symbol_len) { _symbol[i++] = _look; _symbol[i] = 0; } if (string && Is('"')) { i--; _symbol[i] = 0; Lex(); break; } Lex(); if (string) { continue; } if (Is('.')) { fp = true; for (j = 0; j < i; j++) { if (!j && _symbol[j] == '-') continue; if (!isdigit(_symbol[j])) break; } if (i == j) { _symbol[i++] = _look; _symbol[i] = 0; Lex(); } } // Mongoose 2002.01.23, Hhhmm... fixes -100.00 and -100, // but is it 'good idea'? if (Is('-') && i == 0) { _symbol[i++] = _look; _symbol[i] = 0; Lex(); } } #ifdef DEBUG_RESOURCE_SYMBOL printf("%s\n", _symbol); #endif if (isnumeric(_symbol, &f)) { if (fp) { new_float(&a, f); } else { new_int(&a, (int)f); } } else { // Mongoose 2002.01.21, FIXME support ADTs and etc too if (Lookup(_symbol, &i)) { new_int(&a, i); } else if (Lookup(_symbol, &f)) { new_float(&a, f); } else if (string) { mlisp_new_string(&a, _symbol); } else if (Lookup(_symbol, &adt)) { mlisp_new_adt(&a, adt->type, adt->data); } else { // Mongoose 2002.01.21, FIXME: hack to handle old string // use for def symbols mlisp_new_string(&a, _symbol); } } return a; }