/* * Free memory used to store function and its constants */ void freefunc(FUNC *fp) { long index; unsigned long i; if (fp == NULL) return; if (fp == curfunc) { index = newindex; } else { for (index = 0; index < funccount; index++) { if (functions[index] == fp) break; } if (index == funccount) { math_error("Bad call to freefunc!!!"); /*NOTREACHED*/ } } if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { printf("Freeing function \"%s\"\n",namestr(&funcnames,index)); dumpnames = FALSE; for (i = 0; i < fp->f_opcodecount; ) { printf("%ld: ", i); i += dumpop(&fp->f_opcodes[i]); } } freenumbers(fp); if (fp != functemplate) free(fp); }
/* * Commit the just defined function for use. * This replaces any existing definition for the function. * This should only be called for normal user-defined functions. */ void endfunc(void) { register FUNC *fp; /* function just finished */ unsigned long size; /* size of just created function */ unsigned long index; if (oldop != OP_RETURN) { addop(OP_UNDEF); addop(OP_RETURN); } checklabels(); if (errorcount) { printf("\"%s\": %ld error%s\n", newname, errorcount, ((errorcount == 1) ? "" : "s")); return; } size = funcsize(curfunc->f_opcodecount); fp = (FUNC *) malloc(size); if (fp == NULL) { math_error("Cannot commit function"); /*NOTREACHED*/ } memcpy((char *) fp, (char *) curfunc, size); if (curfunc != functemplate) free(curfunc); if (newname[0] != '*' && (conf->traceflags & TRACE_FNCODES)) { dumpnames = TRUE; for (size = 0; size < fp->f_opcodecount; ) { printf("%ld: ", (long)size); size += dumpop(&fp->f_opcodes[size]); } } if ((inputisterminal() && conf->resource_debug & RSCDBG_STDIN_FUNC) || (!inputisterminal() && conf->resource_debug & RSCDBG_FILE_FUNC)) { printf("%s(", newname); for (index = 0; index < fp->f_paramcount; index++) { if (index) putchar(','); printf("%s", paramname(index)); } printf(") "); if (functions[newindex]) printf("re"); printf("defined\n"); } if (functions[newindex]) { freenumbers(functions[newindex]); free(functions[newindex]); } functions[newindex] = fp; }
/* * Main loop */ int main(int argc, char *argv[]) { int c, n = 0; int warm = 0; xeq_init_contexts(); load_statefile(); if (argc > 1) { if (argc == 2) { if (strcmp(argv[1], "commands") == 0) { dump_commands(0); return 0; } if (strcmp(argv[1], "reg") == 0) { dump_registers(); return 0; } if (strcmp(argv[1], "wake") == 0) { warm = 1; goto skipargs; } if (strcmp(argv[1], "opcodes") == 0) { dump_opcodes(stdout, 0); return 0; } if (strcmp(argv[1], "xref") == 0) { dump_opcodes(stdout, 1); return 0; } if (strcmp(argv[1], "constants") == 0) { dump_constants(); return 0; } dump_menu("statistics", "", CATALOGUE_STATS); dump_menu("probability", "", CATALOGUE_PROB); dump_menu("clear", "", CATALOGUE_CLEAR); dump_menu("displ", "", CATALOGUE_DISPL); dump_menu("more", "", CATALOGUE_MORE); dump_menu("modes", "", CATALOGUE_MODE); dump_menu("conversions", "", CATALOGUE_CONV); dump_menu("constants", "# ", CATALOGUE_CONST); } for (c=0; c<65536; c++) { if (isDBL(c) && (c & 0xff)) /* Don't show all multi-word instructions */ continue; n += dumpop(c, argc > 2); } printf("total number of opcodes %d\n", n); printf("\tniladic commands %d\n", NUM_NILADIC); for (n=c=0; c<NUM_MONADIC; c++) { if (monfuncs[c].mondreal != NULL) n++; if (monfuncs[c].mondcmplx != NULL) n++; if (monfuncs[c].monint != NULL) n++; } printf("\tmonadic commands %d with %d functions\n", NUM_MONADIC, n); for (n=c=0; c<NUM_DYADIC; c++) { if (dyfuncs[c].dydreal != NULL) n++; if (dyfuncs[c].dydcmplx != NULL) n++; if (dyfuncs[c].dydint != NULL) n++; } printf("\tdyadic commands %d with %d functions\n", NUM_DYADIC, n); for (n=c=0; c<NUM_TRIADIC; c++) { if (trifuncs[c].trireal != NULL) n++; if (trifuncs[c].triint != NULL) n++; } printf("\ttriadic commands %d with %d functions\n", NUM_TRIADIC, n); printf("\targument commands %d\n", NUM_RARG); printf("\tmultiword commands %d\n", NUM_MULTI); printf("\tspecial commands %d\n", NUM_SPECIAL); printf("\ttotal commands %u\n", dump_commands(1)); return 0; } skipargs: if (!warm) init_34s(); State2.flags = 1; if (setuptty(0) == 0) { display(); JustDisplayed = 0; while ((c = GETCHAR()) != GETCHAR_ERR && c != CH_QUIT) { #ifdef USECURSES if (c == CH_TRACE) { State2.trace = 1 - State2.trace; display(); } else if (c == CH_FLAGS) { State2.flags = 1 - State2.flags; display(); } else if (c == CH_REFRESH) { clear(); display(); } else if (c == CH_ICOUNT) { instruction_count = 0; view_instruction_counter = 1 - view_instruction_counter; display(); } else if (c == CH_PASTE) { paste_raw_x("123.14159265358979323846264338327950"); c = K_UNKNOWN; clear(); display(); } else if (c == CH_COPY) { char buffer[66]; const char *p = fill_buffer_from_raw_x(buffer); printf("%s\n", p); fflush(NULL); sleep(1); c = K_UNKNOWN; } else #endif c=remap(c); if(c != K_UNKNOWN) { process_keycode(c); process_keycode(K_RELEASE); } } setuptty(1); } shutdown(); return 0; }
/* The main function */ int main(int argc, char const *argv[]) { DBusError dbe; struct state_st state; /* Parse the command line. */ if (argv[1] && argv[1][0] == 'd') { /* Debug dump */ assert(loadstate(&state)); dumpop(&state); return 0; } else if (argv[1] && argv[1][0] == 'r') { /* Repair the GA state. */ unsigned i; assert(loadstate(&state)); for (i = 0; i < G_N_ELEMENTS(state.pop); i++) { /* Ensure that genes are bounded. */ struct genome_st *g = &state.pop[i]; if (g->window > TIMEOUT) g->window = TIMEOUT; else if (g->window < 3) g->window = 3; if (g->threshold <= 0) g->threshold = 0.1; else if (g->threshold >= 1) g->threshold = 0.9; } savestate(&state); return 0; } /* Redirect stdio. */ assert((stderr = fopen(FNAME".err", "a")) != NULL); assert((stdout = fopen(FNAME".log", "a")) != NULL); /* Initialize infrastructure for the test. */ Loop = g_main_loop_new(0, 0); DBus = dbus_bus_get(DBUS_BUS_SESSION, NULL); dbus_connection_setup_with_g_main(DBus, g_main_context_default()); dbus_error_init(&dbe); dbus_bus_add_match(DBus, "type='method_call',interface='com.nokia.HildonDesktop.AppMgr',member='LaunchApplication'", &dbe); assert(!dbus_error_is_set(&dbe)); Dpy = XOpenDisplay(NULL); assert(Dpy != NULL); if (!loadstate(&state)) initpop(&state); /* Test */ eval(&state.pop[state.idx++]); if (state.idx >= G_N_ELEMENTS(state.pop)) generation(&state); /* Done and reboot. */ savestate(&state); if (argv[1]) system("echo reboot | sudo gainroot"); return 0; } /* main */