// utility int DescribeString(char* str, int len, Object* str_list){ char tail[1024] = {'\0'}; if( !isNil(Cdr(str_list)) ) DescribeString(tail, 1024, Cdr(str_list)); return snprintf(str, len, "%c%s", TakeCharacter(Car(str_list))->c, tail); }
/*-------------------------------------------------------------------------* * LOAD_MATH_EXPRESSION * * * *-------------------------------------------------------------------------*/ static WamWord Load_Math_Expression(WamWord exp) { WamWord word, tag_mask; WamWord *adr; WamWord *lst_adr; ArithInf *arith; DEREF(exp, word, tag_mask); if (tag_mask == TAG_INT_MASK || tag_mask == TAG_FLT_MASK) return word; if (tag_mask == TAG_LST_MASK) { lst_adr = UnTag_LST(word); DEREF(Cdr(lst_adr), word, tag_mask); if (word != NIL_WORD) { word = Pl_Put_Structure(ATOM_CHAR('/'), 2); Pl_Unify_Atom(ATOM_CHAR('.')); Pl_Unify_Integer(2); Pl_Err_Type(pl_type_evaluable, word); } DEREF(Car(lst_adr), word, tag_mask); if (tag_mask == TAG_REF_MASK) Pl_Err_Instantiation(); if (tag_mask != TAG_INT_MASK) { Pl_Err_Type(pl_type_integer, word); } return word; } if (tag_mask == TAG_STC_MASK) { adr = UnTag_STC(word); arith = (ArithInf *) Pl_Hash_Find(arith_tbl, Functor_And_Arity(adr)); if (arith == NULL) { word = Pl_Put_Structure(ATOM_CHAR('/'), 2); Pl_Unify_Atom(Functor(adr)); Pl_Unify_Integer(Arity(adr)); Pl_Err_Type(pl_type_evaluable, word); } if (Arity(adr) == 1) return (*(arith->fct)) (Load_Math_Expression(Arg(adr, 0))); return (*(arith->fct)) (Load_Math_Expression(Arg(adr, 0)), Load_Math_Expression(Arg(adr, 1))); } if (tag_mask == TAG_REF_MASK) Pl_Err_Instantiation(); if (tag_mask == TAG_ATM_MASK) { word = Pl_Put_Structure(ATOM_CHAR('/'), 2); Pl_Unify_Value(exp); Pl_Unify_Integer(0); /* then type_error */ } Pl_Err_Type(pl_type_evaluable, word); return word; }
static void Show_List_Arg(int depth, WamWord *lst_adr) { WamWord word, tag_mask; terminal_rec: depth--; Show_Term(depth, MAX_ARG_OF_FUNCTOR_PREC, GENERAL_TERM, Car(lst_adr)); if (depth == 0) /* dots already written by Show_Term */ return; DEREF(Cdr(lst_adr), word, tag_mask); switch (Tag_From_Tag_Mask(tag_mask)) { case REF: SHOW_LIST_PIPE; Show_Global_Var(UnTag_REF(word)); break; case ATM: if (word != NIL_WORD) { SHOW_LIST_PIPE; if (Try_Portray(word)) return; Show_Atom(GENERAL_TERM, UnTag_ATM(word)); } break; #ifndef NO_USE_FD_SOLVER case FDV: SHOW_LIST_PIPE; if (Try_Portray(word)) return; Show_Fd_Variable(UnTag_FDV(word)); break; #endif case INT: SHOW_LIST_PIPE; if (Try_Portray(word)) return; Show_Integer(UnTag_INT(word)); break; case FLT: SHOW_LIST_PIPE; if (Try_Portray(word)) return; Show_Float(Pl_Obtain_Float(UnTag_FLT(word))); break; case LST: Out_Char(','); if (space_args) Out_Space(); lst_adr = UnTag_LST(word); goto terminal_rec; break; case STC: SHOW_LIST_PIPE; if (Try_Portray(word)) return; Show_Structure(depth, MAX_ARG_OF_FUNCTOR_PREC, GENERAL_TERM, UnTag_STC(word)); break; } }
thing_th *funky_macro(thing_th *args) { if(has_repr(Car(args))) { return env_set(sym(Car(args)), build_macro(Cdr(args))); } return build_macro(args); }
thing_th *funky_head(thing_th *args) { return Car(Car(args)); }
thing_th *funky_is_error(thing_th *args) { return (th_kind(Car(args))==error_k) ? lookup_txt("true") : NULL; }
thing_th *funky_set(thing_th *args) { return inner_funky_set(Car(args), Car(Cdr(args))); }
thing_th *funky_not_operator(thing_th *args) { if(!Car(args)) return lookup_txt("true"); return NULL; }
static thing_th *horrendous_recursion_trap_eval(thing_th *args) { return eval(Car(args)); }
static thing_th *define_procedure(thing_th *args) { return Proc(Car(args), Cdr(args)); }
thing_th *funky_last(thing_th *args) { return Car(last_el(Car(args))); }
thing_th *funky_rest(thing_th *args) { return Cdr(Car(args)); }
void init() { g_car = Car(MAP_WD / 2 - 1, 1, -1, 0); add_enemy(); init_map(); }
/*-------------------------------------------------------------------------* * PL_BLT_UNIV * * * *-------------------------------------------------------------------------*/ Bool FC Pl_Blt_Univ(WamWord term_word, WamWord list_word) { WamWord word, tag_mask; WamWord *adr; WamWord car_word; int lst_length; WamWord *arg1_adr; WamWord *term_adr, *lst_adr, *stc_adr; WamWord functor_word, functor_tag; int functor; int arity; Pl_Set_C_Bip_Name("=..", 2); DEREF(term_word, word, tag_mask); if (tag_mask == TAG_REF_MASK) goto list_to_term; /* from term to list functor+args */ if (tag_mask == TAG_LST_MASK) { adr = UnTag_LST(word); car_word = Tag_ATM(ATOM_CHAR('.')); lst_length = 1 + 2; arg1_adr = &Car(adr); } else if (tag_mask == TAG_STC_MASK) { adr = UnTag_STC(word); car_word = Tag_ATM(Functor(adr)); lst_length = 1 + Arity(adr); arg1_adr = &Arg(adr, 0); } #ifndef NO_USE_FD_SOLVER else if (tag_mask == TAG_FDV_MASK) { adr = UnTag_FDV(word); car_word = Tag_REF(adr); /* since Dont_Separate_Tag */ lst_length = 1 + 0; } #endif else /* TAG_ATM/INT/FLT_MASK */ { car_word = word; lst_length = 1 + 0; } Pl_Check_For_Un_List(list_word); Pl_Unset_C_Bip_Name(); for (;;) { if (!Pl_Get_List(list_word) || !Pl_Unify_Value(car_word)) return FALSE; list_word = Pl_Unify_Variable(); if (--lst_length == 0) break; car_word = *arg1_adr++; } return Pl_Get_Nil(list_word); /* from list functor+args to term */ list_to_term: term_adr = UnTag_REF(word); DEREF(list_word, word, tag_mask); if (tag_mask == TAG_REF_MASK) Pl_Err_Instantiation(); if (word == NIL_WORD) Pl_Err_Domain(pl_domain_non_empty_list, list_word); if (tag_mask != TAG_LST_MASK) Pl_Err_Type(pl_type_list, list_word); lst_adr = UnTag_LST(word); DEREF(Car(lst_adr), functor_word, functor_tag); if (functor_tag == TAG_REF_MASK) Pl_Err_Instantiation(); DEREF(Cdr(lst_adr), word, tag_mask); if (word == NIL_WORD) { if (functor_tag != TAG_ATM_MASK && functor_tag != TAG_INT_MASK && functor_tag != TAG_FLT_MASK) Pl_Err_Type(pl_type_atomic, functor_word); term_word = functor_word; goto finish; } if (functor_tag != TAG_ATM_MASK) Pl_Err_Type(pl_type_atom, functor_word); if (tag_mask == TAG_REF_MASK) Pl_Err_Instantiation(); if (tag_mask != TAG_LST_MASK) Pl_Err_Type(pl_type_list, list_word); functor = UnTag_ATM(functor_word); stc_adr = H; H++; /* space for f/n maybe lost if a list */ arity = 0; for (;;) { arity++; lst_adr = UnTag_LST(word); DEREF(Car(lst_adr), word, tag_mask); Do_Copy_Of_Word(tag_mask, word); /* since Dont_Separate_Tag */ Global_Push(word); DEREF(Cdr(lst_adr), word, tag_mask); if (word == NIL_WORD) break; if (tag_mask == TAG_REF_MASK) Pl_Err_Instantiation(); if (tag_mask != TAG_LST_MASK) Pl_Err_Type(pl_type_list, list_word); } if (arity > MAX_ARITY) Pl_Err_Representation(pl_representation_max_arity); if (functor == ATOM_CHAR('.') && arity == 2) /* a list */ term_word = Tag_LST(stc_adr + 1); else { *stc_adr = Functor_Arity(functor, arity); term_word = Tag_STC(stc_adr); } finish: Bind_UV(term_adr, term_word); Pl_Unset_C_Bip_Name(); return TRUE; }
thing_th *funky_gen(thing_th *args) { if(!Car(args) || !Cdr(args)) return Err(Cons(String("Incomplete Gen construction"), NULL)); return Gen(Car(args), Cdr(args)); }
thing_th *funky_pair(thing_th *args) { return Cons(Car(args), Cons(Car(Cdr(args)), NULL)); }
thing_th *funky_cons(thing_th *args) { return Cons(Car(args), Car(Cdr(args))); }
static int set_grid_pair(thing_th *grid, thing_th *pair) { return pair && set_grid_pair_data(grid, Car(pair), Car(Cdr(pair))); }
thing_th *funky_is_grid(thing_th *args) { return (th_kind(Car(args))==grid_k) ? lookup_txt("true") : NULL; }
thing_th *funky_grid(thing_th *args) { thing_th *grid=Grid(); while(set_grid_pair(grid, Car(args))) args=Cdr(args); return grid; }
static thing_th *build_macro(thing_th *args) { return Mac(Car(args), Cdr(args)); }
thing_th *funky_grid_get(thing_th *args) { return funky_grid_getter(Car(args), Car(Cdr(args))); }
thing_th *funky_quote(thing_th *args) { return Car(args); }
thing_th *funky_truthy(thing_th *args) { return this_cell_is_truthy(Car(args)) ? lookup_txt("true") : NULL; }
int main (int argc, char *argv[]) { int done; if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); exit (1); } atexit (Terminate); SDL_ShowCursor(SDL_DISABLE); #ifdef GP2X screen = SDL_SetVideoMode (320,240, 16, SDL_SWSURFACE); #else screen = SDL_SetVideoMode (640,480, 16, SDL_SWSURFACE); #endif if (screen == NULL) { fprintf (stderr, "Couldn't set 320x240x16 video mode: %s\n", SDL_GetError ()); exit (2); } SDL_Surface *bg = IMG_Load("images/tset.png"); if (SDL_NumJoysticks() > 0) { joy = SDL_JoystickOpen(0); if(!joy) { fprintf (stderr, "Couldn't open joystick 0: %s\n", SDL_GetError ()); } } done = 0; car Car(200,100,0.0,screen); long int lframe = SDL_GetTicks(); while (!done) { SDL_Event event; /* Check for events */ while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: /* if press Ctrl + C, terminate program */ if ((event.key.keysym.sym == SDLK_ESCAPE)) done = 1; if(event.key.keysym.sym == SDLK_LEFT) Car.setKeys(Car.getKeys()|LEFT); if(event.key.keysym.sym == SDLK_RIGHT) Car.setKeys(Car.getKeys()|RIGHT); if(event.key.keysym.sym == SDLK_UP) Car.setKeys(Car.getKeys()|UP); if(event.key.keysym.sym == SDLK_DOWN) Car.setKeys(Car.getKeys()|DOWN); break; case SDL_KEYUP: if(event.key.keysym.sym == SDLK_LEFT) Car.setKeys(Car.getKeys()^LEFT); if(event.key.keysym.sym == SDLK_RIGHT) Car.setKeys(Car.getKeys()^RIGHT); if(event.key.keysym.sym == SDLK_UP) Car.setKeys(Car.getKeys()^UP); if(event.key.keysym.sym == SDLK_DOWN) Car.setKeys(Car.getKeys()^DOWN); break; case SDL_JOYBUTTONDOWN: /* if press Start button, terminate program */ if(event.jbutton.button == VK_LEFT) Car.rotate(-3); if(event.jbutton.button == VK_RIGHT) Car.rotate(3); if(event.jbutton.button == VK_UP) Car.setAc(1.2); if(event.jbutton.button == VK_DOWN) Car.setAc(-1.2); if ( event.jbutton.button == VK_START ) done = 1; break; case SDL_JOYBUTTONUP: if(event.jbutton.button == VK_LEFT && Car.getRam()<0) Car.rotate(0); if(event.jbutton.button == VK_RIGHT && Car.getRam()>0) Car.rotate(0); if(event.jbutton.button == VK_UP && Car.getAccel()>0) Car.setAc(0.0); if(event.jbutton.button == VK_DOWN && Car.getAccel()<0) Car.setAc(0.0); break; case SDL_QUIT: done = 1; break; default: break; } } drawTiled(bg,screen,0,0,128,96,640,480); Car.update(); Car.draw(); SDL_Flip(screen); } return 0; }
thing_th *funky_nilly(thing_th *args) { return Car(args) ? NULL : lookup_txt("true"); }
/*-------------------------------------------------------------------------* * SHOW_TERM * * * *-------------------------------------------------------------------------*/ static void Show_Term(int depth, int prec, int context, WamWord term_word) { WamWord word, tag_mask; WamWord *adr; if (depth == 0) { Show_Atom(GENERAL_TERM, atom_dots); return; } DEREF(term_word, word, tag_mask); if (tag_mask != TAG_REF_MASK && Try_Portray(word)) return; switch (Tag_From_Tag_Mask(tag_mask)) { case REF: adr = UnTag_REF(word); if (Is_A_Local_Adr(adr)) { Globalize_Local_Unbound_Var(adr, word); adr = UnTag_REF(word); } Show_Global_Var(adr); break; case ATM: Show_Atom(context, UnTag_ATM(word)); break; #ifndef NO_USE_FD_SOLVER case FDV: Show_Fd_Variable(UnTag_FDV(word)); break; #endif case INT: Show_Integer(UnTag_INT(word)); break; case FLT: Show_Float(Pl_Obtain_Float(UnTag_FLT(word))); break; case LST: adr = UnTag_LST(word); if (ignore_op) { Out_String("'.'("); Show_Term(depth - 1, MAX_ARG_OF_FUNCTOR_PREC, GENERAL_TERM, Car(adr)); Out_Char(','); Show_Term(depth - 1, MAX_ARG_OF_FUNCTOR_PREC, GENERAL_TERM, Cdr(adr)); Out_Char(')'); } else { Out_Char('['); Show_List_Arg(depth, adr); Out_Char(']'); } break; case STC: adr = UnTag_STC(word); Show_Structure(depth, prec, context, adr); break; } }
thing_th *funky_length(thing_th *args) { return inner_funky_length(Car(args)); }
coord_noi Derapaj(int x,int y,int speed,int direction,int direction_change,int engine) { int speed_aux=(400-speed)/2; int deplasare=0; coord_noi aux; aux.x_aux=x; aux.y_aux=y; //initializam variabilele aux.speed_aux=speed; if(speed_aux<=70) { deplasare=0; speed+=30; } if(speed_aux>70 && speed_aux<100) { deplasare=1; speed+=30; } if(speed_aux>=100 && speed_aux<150) { deplasare=2; speed+=30; } if(speed_aux>=150 && speed_aux<170) { deplasare=3; speed+=30; } if(speed_aux>=170 && speed_aux<185) { deplasare=4; speed+=30; } if(speed_aux>=185 && speed_aux<=197) { deplasare=5; speed+=30; } switch(direction) { case 1: { switch(direction_change) { case 2: { while(deplasare && Conditie(x,y,direction_change)) { x++; y++; Car(x,y,direction_change,0,1,0); Sterge_Masina_Derapaj(x,y,2); Urme_Derapaj(x,y,2,deplasare); Sound_Derapaj(1000); //Statistics(x,y,speed,0,1,0,100); delay(speed); deplasare--; aux.speed_aux+=deplasare*4; speed+=deplasare*4; } if(!Conditie(x,y,direction_change)) //o tentativa { Refa_Zona_Afectata(x,y); y--; //destul de buna Car(x,y,direction_change,0,1,0); engine=0; speed=400; } break; } case 4: { while(deplasare && Conditie(x,y,direction_change) { x++; y--; Car(x,y,direction_change,0,1,0); Sterge_Masina_Derapaj(x,y,1); Urme_Derapaj(x,y,1,deplasare); Sound_Derapaj(1000); //Statistics(x,y,speed,0,1,0,100); delay(speed); deplasare--; aux.speed_aux+=deplasare*4; speed+=deplasare*4; } if(!Conditie(x,y,direction_change)) //o tentativa { Refa_Zona_Afectata(x,y); y++; //destul de buna Car(x,y,direction_change,0,1,0); engine=0; speed=400; } }//while break; }//case 4 case 3: { while(deplasare) { x++; if(Conditie(x,y,direction_change)) { Car(x,y,direction_change,0,1,0); Sterge_Masina_Derapaj(x,y,12); Urme_Derapaj(x,y,3,deplasare); Sound_Derapaj(1000); //Statistics(x,y,speed,0,1,0,100); delay(speed); deplasare--; aux.speed_aux+=deplasare*10;//scade mult din viteza speed+=deplasare*10; } } //modificam si viteza break; } }//switch direction_change_change break;//de la case1; }//case mare 1
at *car(at *q) { ifn (LISTP(q)) RAISEF("not a list", q); return q ? Car(q) : q; }