#author("2018-06-17T00:06:18+09:00","","") #author("2018-06-17T00:07:34+09:00","","") *white_space企画の現状 stackモジュール ver 0.1.4.0 [#pf52db10] white_spaceでstack構造をデータ型の一つにしてるので~ 頑張って書きました heap構造も使ってるのでそっちも更新せねば~ モジュール変数で要素を管理してるモジュールと~ ラップしてモジュール変数決め打ちモジュールの二つを記述しています~ 0.1.2.1 setter と getter のラップ増やしました~ #module stack_model~ について~ 後入れ先出し構造のstackのデータ型の~ データを扱うモジュールです~ モジュール変数メンバ~ stack_size~ stackのデータのsizeです~ int型~ stack_current~ stackの中の現在地を示す変数です~ int型~ stack_contents~ stack型データを格納する~ モジュール変数の配列データです~ データ一つは mdl_one_value 型のオブジェクトです~ コンストラクタ~ 引数:int p_size~ stack_sizeとstack_curerentにp_sizeを代入し~ p_sizeの値だけmdl_one_value型の~ stack_contentsを作成します~ #modfunc local set_current~ 引数:int p_int~ stack_currentのsetterです。~ p_intの値を代入~ #modfunc local set_contents~ 引数1:var p_value~ 引数2:int p_index~ stack_contentsのsetterです。~ p_indexの場所にp_valueを代入~ #modcfunc local get_size~ stack_sizeのgetter~ local get_contents~ 引数:int p_index~ stack_contentsのgetterです~ p_indexの場所の値を返す~ #modcfunc local get_current~ stackの現在値のgetter~ #modcfunc local get_contents~ 引数: int p_index~ stackのp_index番目の値を返す~ #modcfunc local ret_vartype~ 引数:int p_index~ stack_contentsのp_index番目の値の型を~ 数値で返す~ #modcfunc local tostr_vartype~ 引数:int p_index~ stack_contentsのp_index番目の値の型を~ 文字列で返す~ ---- #modfunc local push~ 引数:var _p_val~ stackのデータに_p_valの値をpushする~ #modcfunc local pop~ stackのデータをpopします~ 値は返り値として返します~ #modcfunc local top~ stackのデータを取得します。currentは変化しません~ 値は返り値として返します~ #modcfunc local peak~ stackをpeakします~ 値は返り値として返します~ #modfunc local cleanup~ stack型のデータを削除します~ newmod stack,stack_model,STACK_MEMBERS@~ このモジュールでは何種類のstack型データを共存させる~ モジュールと(ここより上の動作)~ 決め打ちで1つのみ作成するモジュールを定義しています~ 1つのみのデータはオブジェクトを指定しなくていいので~ 少しは直感的に操作出来ると思います~ ---- // 後入れ先出し構造のstackのデータ型の // データを扱うモジュールです #include "mdl_value.as" #include "mdl_value.as" //includeガードが効いてるかのTEST #include "mdl_ws_define.as" #include "mdl_ws_define.as" //includeガードが効いてるかのTEST // long size; // long current; // long long* contents; //} stack; // モジュール変数メンバ // stack_size // stackのデータのsizeです // int型 // stack_current // stackの中の現在地を示す変数です // int型 // stack_contents // stack型データを格納する // モジュール変数の配列データです // データ一つは mdl_one_value 型のオブジェクトです #module stack_model stack_size,stack_current,stack_contents // コンストラクタ // 引数:int p_size // stack_sizeとstack_curerentにp_sizeを代入し // p_sizeの値だけmdl_one_value型の // stack_contentsを作成します #modinit int p_size stack_size = p_size stack_current = p_size repeat p_size newmod stack_contents,mdl_one_value loop ; dim stack_contents,STACK_MEMBERS@ return ;#modfunc local set_size int p_int ; stack_size = p_int ; return // stack_currentのsetterです。 // p_intの値を代入 #modfunc local set_current int p_int stack_current = p_int return // stack_contentsのsetterです。 // p_indexの場所にp_valueを代入 #modfunc local set_contents var p_value,int p_index set@mdl_one_value stack_contents.p_index,p_value // stack_contents.p_index = p_value return // stack_contentsのgetterです // p_indexの場所の値を返す #modcfunc local get_size return stack_size // stackの現在値のgetter #modcfunc local get_current return stack_current // stackのp_index番目の値を返す #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 return get@mdl_one_value(stack_contents.p_index) // stack_contentsのp_index番目の値の型を // 数値で返す #modcfunc local ret_vartype int p_index return ret_vartype@mdl_one_value(stack_contents.p_index) ; return tmp;@mdl_one_value(stack_contents.0) // stack_contentsのp_index番目の値の型を // 文字列で返す #modcfunc local tostr_vartype int p_index return tostr_vartype@mdl_one_value(stack_contents.p_index) ; return tmp;@mdl_one_value(stack_contents.0) //bool stack_push(long long val) //{ // if (stack.current >= 1) { // stack.current--; // stack.contents[stack.current] = val; // return true; // } // return false; //} // stackのデータに_p_valの値をpushする #modfunc local push var _p_val if stack_current >= 1{ stack_current-- set@mdl_one_value stack_contents.stack_current,_p_val return 1 } return 0 //long long stack_pop(void) //{ // if (stack.current < stack.size) { // stack.current++; // return stack.contents[stack.current - 1]; // } // return 0; //} // stackのデータをpopします // 値は返り値として返します #modcfunc local pop local loc_pop if stack_current < stack_size { stack_current++ loc_pop=stack_current-1 return get@mdl_one_value(stack_contents.loc_pop) } return 0 // stackのデータを取得します。currentは変化しません // 値は返り値として返します #modcfunc local top if stack_current < stack_size { return get@mdl_one_value(stack_contents.stack_current) } return 0 //long long stack_peak(int depth) //{ // if ((stack.current + depth) < stack.size) { // return stack.contents[stack.current + depth]; // } // return 0; //} // stackをpeakします // 値は返り値として返します #modcfunc local peak int p_depth, local loc_depth if stack_current + p_depth < stack_size { loc_depth=stack_current + p_depth return get@mdl_one_value(stack_contents.loc_depth) } return 0 //void cleanup_stack(void) //{ // free (stack.contents); // return; //} // stack型のデータを削除します #modfunc local cleanup i=0 for i,stack_size-1,-1,-1 delmod stack_contents.i next return #global // このモジュールでは何種類のstack型データを共存させる // モジュールと(ここより上の動作) // 決め打ちで1つのみ作成するモジュールを定義しています // 1つのみのデータはオブジェクトを指定しなくていいので // 少しは直感的に操作出来ると思います //↓重要w newmod stack,stack_model,STACK_MEMBERS@ #if 1 ;set_size@stack_model stack,20 set_current@stack_model stack,5 repeat 5 nn=cnt*2 set_contents@stack_model stack,nn,cnt loop repeat 5,5 nn=12.3+cnt set_contents@stack_model stack,nn,cnt loop repeat 5,10 nn="abc"+cnt set_contents@stack_model stack,nn,cnt loop logmes "stack size:"+get_size@stack_model(stack) logmes "stack current:"+get_current@stack_model(stack) repeat 15 logmes "stack contents "+cnt+":"+get_contents@stack_model(stack,cnt) logmes "type "+cnt+":"+ret_vartype@stack_model(stack,cnt)+" "+tostr_vartype@stack_model(stack,cnt) loop newmod test_st,stack_model,20 tmp_test=555 push@stack_model test_st,tmp_test tmp_test=777 push@stack_model test_st,tmp_test tmp_test=5 push@stack_model test_st,tmp_test tmp_test=12.3 push@stack_model test_st,tmp_test tmp_test="abc" push@stack_model test_st,tmp_test tmp_test=246 push@stack_model test_st,tmp_test logmes "top:"+top@stack_model(test_st) logmes "peak 1:"+peak@stack_model(test_st,1) logmes "peak 2:"+peak@stack_model(test_st,2) logmes "pop:"+pop@stack_model(test_st) logmes "pop:"+pop@stack_model(test_st) logmes "top:"+top@stack_model(test_st) logmes "pop:"+pop@stack_model(test_st) logmes "pop:"+pop@stack_model(test_st) #endif #if 0 cleanup@stack_model(test_st) delmod test_st #endif // つづく ---- #deffunc create_stack~ stackのデータを初期化~ #deffunc stack_set_current~ 引数:int _p_int~ stackの現在値を_p_intにする~ #defcfunc stack_get_size~ stackのsizeを返す~ #defcfunc stack_get_current~ stackの現在値を返す~ #defcfunc stack_ret_vartype~ 引数:int _p_int~ stackの_p_int番目の値の型を返す(数値)~ #defcfunc stack_tostr_vartype~ 引数:int _p_int~ stackの_p_int番目の値の型を返す(文字列)~ ---- #defcfunc stack_push~ 引数: var p_val~ stackにp_valの値をpushする~ #defcfunc stack_pop~ stackからpopする(返り値として返す)~ #defcfunc stack_top~ stackのtopの値を返す~ #defcfunc stack_peak~ 引数:int _p_peak~ stackからpeakする~ #deffunc stack_cleanup~ stackを破棄する~ // つづきここから /* 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 //stackのデータを初期化 #deffunc create_stack // stackのsizeは途中から変えれなくなったw 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 //stackの現在値を_p_intにする #deffunc stack_set_current int _p_int set_current@stack_model stack@,_p_int return //stackのsizeを返す #defcfunc stack_get_size return get_size@stack_model(stack@) //stackの現在値を返す #defcfunc stack_get_current return get_current@stack_model(stack@) //stackの_p_int番目の値の型を返す(数値) #defcfunc stack_ret_vartype int _p_int return ret_vartype@stack_model(stack@,_p_int) //stackの_p_int番目の値の型を返す(文字列) #defcfunc stack_tostr_vartype int _p_int return tostr_vartype@stack_model(stack@,_p_int) //stackにp_valの値をpushする #defcfunc stack_push var p_val,local loc_spush loc_spush=p_val push@stack_model stack@,loc_spush return stat //stackからpopする(返り値として返す) #defcfunc stack_pop return pop@stack_model(stack@) //stackのtopの値を返す #defcfunc stack_top return top@stack_model(stack@) //stackからpeakする #defcfunc stack_peak int _p_peak return peak@stack_model(stack@,_p_peak) //stackを破棄する #deffunc stack_cleanup cleanup@stack_model(stack@) delmod stack@ return #global #if 1 create_stack logmes "size "+stack_get_size() tmp4log=10 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log=23.4 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log=30 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log="abc" logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log=20 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log=34.5 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp_cur=stack_get_current() logmes "cur "+tmp_cur logmes "type "+stack_ret_vartype(tmp_cur) logmes "type "+stack_tostr_vartype(tmp_cur) logmes "type "+stack_ret_vartype(tmp_cur-1) logmes "type "+stack_tostr_vartype(tmp_cur-1) logmes "top "+stack_top() tmp4log=40 logmes "push "+stack_push(tmp4log)+" "+tmp4log tmp4log="top" logmes "push "+stack_push(tmp4log)+" "+tmp4log logmes "top "+stack_top() logmes "peak 1 "+stack_peak(1) logmes "peak 2 "+stack_peak(2) logmes "pop "+stack_pop() logmes "pop "+stack_pop() logmes "top "+stack_top() logmes "peak 1 "+stack_peak(1) logmes "pop "+stack_pop() logmes "pop "+stack_pop() logmes "cur "+stack_get_current() stack_set_current 700 logmes "cur "+stack_get_current() tmp4log=12.3456 logmes "push "+stack_push(tmp4log)+" "+tmp4log #endif #if 0 stack_cleanup #endif