test.c (1308B)
1 #include <stdio.h> 2 3 #include "stk.h" 4 #include "var.h" 5 6 7 void printstk(stk_t* stk) 8 { 9 var_cont* test0 = stk_at(stk, 0); 10 var_cont* test1 = stk_at(stk, 1); 11 var_cont* test2 = stk_at(stk, 2); 12 var_cont* test3 = stk_at(stk, 3); 13 printf("%i, %i, %i, %i\n", 14 test0->type, test1->type, test2->type, test3->type); 15 } 16 17 void playstk(stk_t* new) 18 { 19 var_cont* one = var_new(VOID); 20 var_cont* two = var_new(G_INT); 21 var_cont* three = var_new(G_FLOAT); 22 var_cont* four = var_new(G_CHAR); 23 var_cont* five = var_new(G_STR); 24 25 stk_push(new, one); 26 stk_push(new, two); 27 stk_push(new, three); 28 stk_push(new, four); 29 stk_push(new, five); 30 31 printf("init: \n"); 32 printstk(new); 33 34 stk_pop(new); 35 36 printf("stk_pop: \n"); 37 printstk(new); 38 39 stk_rot_top(new); 40 41 printf("stk_rot_top: \n"); 42 printstk(new); 43 44 stk_rot_top(new); 45 46 stk_rot_three(new); 47 48 printf("stk_rot_top + stk_rot_three: \n"); 49 printstk(new); 50 51 stk_rot_three(new); 52 53 printf("stk_rot_three: \n"); 54 printstk(new); 55 } 56 57 int main(int argc, char* argv[]) 58 { 59 init_var_track(); 60 61 stk_t* new = stk_new(); 62 63 playstk(new); 64 65 printf("-- NEW STACK LEVEL --\n"); 66 stk_newlevel(&new); 67 68 playstk(new); 69 70 printf("-- LEVEL 1: "); 71 printstk(new); 72 73 stk_poplevel(&new); 74 75 printf("-- LEVEL 0: "); 76 printstk(new); 77 78 stk_newlevel(&new); 79 stk_newlevel(&new); 80 81 stk_del(new); 82 83 return 0; 84 }