#author("2018-01-20T06:51:26+09:00","","") #author("2018-01-20T07:04:26+09:00","","") [[white_space]] *white_space企画の現状 stackモジュール ver 0.1.1[#mc04b04d] #ifndef _MY_WS_DEFINE_ #define _MY_WS_DEFINE_ #define STACK_MEMBERS 1024 #define HEAP_MEMBERS 1024 #define MAX_LABELS 200 #define MAX_LABEL_LENGTH 500 #define MAX_INSTRUCTIONS 24 #define MAX_INSTRUCTION_LENGTH 5 #define MAX_NESTED_SUBROUTINES 20 #endif //struct stack_model { // long size; // long current; // long long* contents; //} stack; #module stack_model stack_size,stack_current,stack_contents #modinit stack_size = 0 stack_current = 0 dim stack_contents,STACK_MEMBERS@ return #modfunc local set_size int p_int stack_size = p_int return #modfunc local set_current int p_int stack_current = p_int return #modfunc local set_contents int p_value,int p_index stack_contents.p_index = p_value return #modcfunc local get_size return stack_size #modcfunc local get_current return stack_current #modcfunc local get_contents int p_index tmp_index=STACK_MEMBERS@ if p_index >=STACK_MEMBERS@{tmp_index=STACK_MEMBERS@-1} ; logmes ""+STACK_MEMBERS@+" "+p_index return stack_contents.p_index #global newmod stack,stack_model #if 1 set_size@stack_model stack,20 set_current@stack_model stack,5 repeat 5 set_contents@stack_model stack,cnt*2,cnt loop logmes "stack size:"+get_size@stack_model(stack) logmes "stack current:"+get_current@stack_model(stack) repeat 10 logmes "stack contents "+cnt+":"+get_contents@stack_model(stack,cnt) loop #endif //bool create_stack(void) //{ // if (stack.contents = (long long*)calloc(STACK_MEMBERS, sizeof(long long))) { // stack.size = STACK_MEMBERS; // stack.current = STACK_MEMBERS; // return true; // } // return false; //} #module #deffunc create_stack repeat STACK_MEMBERS set_contents@stack_model stack@,0,cnt loop set_size@stack_model stack@,STACK_MEMBERS@ set_current@stack_model stack@,STACK_MEMBERS@ return 1 #global #if 1 create_stack #endif //bool stack_push(long long val) //{ // if (stack.current >= 1) { // stack.current--; // stack.contents[stack.current] = val; // return true; // } // return false; //} #module #defcfunc stack_push int p_val,local loc_cur loc_cur=get_current@stack_model(stack@) if loc_cur >= 1{ loc_cur-- set_current@stack_model stack@,loc_cur set_contents@stack_model stack@,p_val,loc_cur return 1 } return 0 #global #if 1 logmes ""+stack_push(10) logmes ""+stack_push(20) logmes ""+stack_push(30) #endif //long long stack_pop(void) //{ // if (stack.current < stack.size) { // stack.current++; // return stack.contents[stack.current - 1]; // } // return 0; //} #module #defcfunc stack_pop local loc_cur,local loc_size loc_cur = get_current@stack_model(stack@) loc_size = get_size@stack_model(stack@) if loc_cur < loc_size{ loc_cur++ set_current@stack_model stack@,loc_cur loc_cur-- return get_contents@stack_model(stack@,loc_cur) } return 0 #global #if 1 logmes "pop 1 :"+stack_pop() logmes "pop 2 :"+stack_pop() logmes "pop 3 :"+stack_pop() #endif //long long stack_peak(int depth) //{ // if ((stack.current + depth) < stack.size) { // return stack.contents[stack.current + depth]; // } // return 0; //} #module #defcfunc stack_peak int p_depth , local loc_cur , local loc_cur_b , local loc_size loc_cur = get_current@stack_model(stack@) loc_cur_b = loc_cur + p_depth loc_size = get_size@stack_model(stack@) if loc_cur_b < loc_size { return get_contents@stack_model(stack@,loc_cur_b) } return 0 #global #if 1 logmes ""+stack_push(10) logmes ""+stack_push(20) logmes ""+stack_push(30) logmes "peak 2 : "+stack_peak(2) logmes "peak 1 : "+stack_peak(1) logmes "peak 0 : "+stack_peak(0) #endif //void cleanup_stack(void) //{ // free (stack.contents); // return; //} // stackは配列表現にしてあるので何もしなくてもたぶんOKw #module #deffunc cleanup_stack return #global #if 1 cleanup_stack #endif