int run_file() { Node *ptree; AstNode *stree; EmCodeObject *co; EmObject *retval; ptree = parse(); if (ptree) { printtree(ptree); stree = ast_from_ptree(ptree); printstree(stree); co = compile_ast_tree(stree); printobj((EmObject *)co, stdout); INCREF(&nulobj); retval = run_codeobject(co, NULL, &nulobj); if (retval) DECREF(retval); freetree(ptree); freestree(stree); } fclose(source.fp); return 1; }
void showCelem (Tcelem *celems) { int j; for (j=0;j<celems->csize;j++) { printobj(celems->elems[j].id); } }
Tdist searchNN(Index S,Obj obj,int k,bool show) { FURTHEST_INDEX *fi=(FURTHEST_INDEX *)S; int i,j,n; Obj *found,tmp_obj,new_obj; Tdist rval,*found_dist,tmp_dist,new_dist; if (fi==NULL) { fprintf(stderr,"Attempting to search a null pointer.\n"); exit(1); } if (fi->magic!=MAGIC) { fprintf(stderr,"Attempting to search an index with bad magic number.\n"); exit(1); } found=(Obj *)malloc(sizeof(Obj)*k); found_dist=(Tdist *)malloc(sizeof(Tdist)*k); n=0; for (i=0;i<fi->num_points;i++) { new_obj=fi->pdp[i].obj; new_dist=distance(obj,new_obj); /* fprintf(stderr,"distance %d to %d is %f\n",obj,new_obj,new_dist); */ for (j=0;j<n;j++) if (new_dist>found_dist[j]) { tmp_dist=new_dist; new_dist=found_dist[j]; found_dist[j]=tmp_dist; tmp_obj=new_obj; new_obj=found[j]; found[j]=tmp_obj; } if (n<k) { found[n]=new_obj; found_dist[n]=new_dist; n++; } } if (n<=0) { fprintf(stderr,"Cannot find any points in database??\n"); exit(1); } if (show) for (i=0;i<n;i++) printobj(found[i]); rval=found_dist[0]; free(found); free(found_dist); /* fprintf(stderr,"returning %f\n",rval); */ return rval; }
void printobj(obj *object) { switch(object->type) { case APPLICATION: putchar('`'); printobj(object->function); printobj(object->argument); break; case LAMBDA: putchar('\\'); printobj(object->expression); break; case REFERENCE: printf("%u ", object->reference); break; case SYMBOL: printf("%s ", object->symbol); break; } }
void listobject_print(EmObject *ob, FILE *fp) { EmListObject *lo = (EmListObject *) ob; int i; fprintf(fp, "["); for (i = 0; i < lo->nitems; i++) { printobj(lo->list[i], fp); if (i < lo->nitems - 1) fprintf(fp, ", "); } fprintf(fp, "]"); }
int XIOdebug(char *fmt, ...) { char ch; va_list ap; int nchars = 0; va_start(ap,fmt); while( (ch = *fmt++) != '\0') { if( ch == '%' ) fmt = printobj(fmt,ap,&nchars); else { obyte(ch); nchars ++; } } return nchars; }
static int _search (vpnode *node, Obj obj, Tdist r, bool show) { int rep = 0; if (node->hoja) { rep += searchbucket (node->u.hoja.bucket,node->u.hoja.size,obj,r,show); } else { Tdist dist; dist = distance (obj, node->u.interno.query); if (dist <= r) { rep++; if (show) printobj(node->u.interno.query); } if (dist-r < node->u.interno.dist) rep += _search(node->u.interno.child1,obj,r,show); if (dist+r >= node->u.interno.dist) rep += _search(node->u.interno.child2,obj,r,show); } return rep; }
int search(Index S,Obj obj,Tdist r,bool show) { FURTHEST_INDEX *fi=(FURTHEST_INDEX *)S; int i,j,n; Tdist target_dist; float approx,best_approx; int *next_to_try,found_next,found_in_proj; float x,*projected_query,y,z; if (fi==NULL) { fprintf(stderr,"Attempting to search a null pointer.\n"); exit(1); } if (fi->magic!=MAGIC) { fprintf(stderr,"Attempting to search an index with bad magic number.\n"); exit(1); } target_dist=searchNN(S,obj,1,0); best_approx=0; n=0; if (fi->algorithm==2) { /* QUERY DEPENDENT BY PROJECTED VALUE */ next_to_try=(int *)malloc(fi->num_projections*sizeof(int)); projected_query=(float *)malloc(fi->num_projections*sizeof(float)); for (i=0;i<fi->num_projections;i++) { next_to_try[i]=0; x=0.0; for (j=0;j<fi->num_dimensions;j++) x+=(fi->projections[i*fi->num_dimensions+j]*(db(obj)[j])); projected_query[i]=x; } for (i=0;i<r;i++) { found_next=fi->pdp[fi->num_points+next_to_try[0]].obj; y=fabs(fi->pdp[fi->num_points+next_to_try[0]].u.pdist -projected_query[0]); found_in_proj=0; for (j=1;j<fi->num_projections;j++) { z=fabs(fi->pdp[fi->num_points*(j+1)+next_to_try[j]].u.pdist -projected_query[j]); if (z>y) { y=z; found_next=fi->pdp[fi->num_points*(j+1)+ next_to_try[j]].obj; found_in_proj=j; } } next_to_try[found_in_proj]++; if (distance(obj,found_next)>=target_dist) { if (show) printobj(found_next); n=1; } approx=((float)distance(obj,found_next))/(float)target_dist; if (approx>best_approx) best_approx=approx; } free(projected_query); free(next_to_try); } else { /* QUERY INDEPENDENT BY RANK OR PROJECTED VALUE */ for (i=0;i<r;i++) { if (distance(obj,fi->pdp[i].obj)>=target_dist) { if (show) printobj(fi->pdp[i].obj); n=1; } approx=((float)distance(obj,fi->pdp[i].obj))/(float)target_dist; if (approx>best_approx) best_approx=approx; } } printf("FURTHESTDATA %f %d\n",1.0/best_approx,n); return 0; }
int main(int argc, char **argv) { int ch; int rc = 0; struct rule *r; fn_list *pre_input = NULL; #ifdef YYDEBUG extern int yydebug; yydebug = 0; #endif hcreate(MAXRULE); while ((ch = getopt(argc, argv, "cdi:kntqS:")) != -1) { switch (ch) { case 'c': cflag++; break; case 'd': #ifdef YYDEBUG yydebug = 1; #else fprintf(stderr, "Rebuild with -DYYDEBUG to use -d.\n"); #endif break; case 'k': c2flag++; break; case 'n': canon = 0; break; case 'i': { fn_list *ifile = calloc(sizeof(fn_list), 1); ifile->filename = optarg; ifile->next = pre_input; pre_input = ifile; break; } case 't': tflag++; break; case 'p': permissive = 0; break; case 'q': qflag++; break; case 'S': top_rule_name = optarg; break; default: usage(); } } argc -= optind; argv += optind; if (argc > 1) usage(); predefine(pre_input); /* Parse the grammar, perhaps spouting errors. */ parse_from((argc > 0)? argv[0] : NULL); /* If we're not quiet, then output the grammar again. */ if (!qflag) { if (canon) canonify(rules); for (r = rules; r; r = r->next) { if (r->predefined) { /* do not output */ } else if (r->rule) { printf("%s = ", r->name); printobj(r->rule, tflag); if (cflag) printf(" ; line %d", r->line); printf("\n"); } else { printf("; %s UNDEFINED\n", r->name); } if (r->next == rules) break; } for (r = rules; r; r = r->next) { if (r->used == 0 && r->predefined == 0 && r->rule && strcmp(r->name, top_rule_name)) printf("; %s defined but not used\n", r->name); if (r->next == rules) break; } } rc = summary(); hdestroy(); exit(rc); }
void print_exception() { if (last_exception != NULL) { printobj(last_exception, stderr); } fprintf(stderr, "\n"); }
void print(obj *object) { printobj(object); putchar('\n'); }