Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cMiMicDbCompiler.c
00001 #include "NyLPC_mimicvm_utils_protected.h" 00002 #include "NyLPC_cMiMicDbCompiler.h" 00003 00004 00005 00006 void NyLPC_cMiMicDbCompiler_initialize(NyLPC_TcMiMicDbCompiler_t* i_inst) 00007 { 00008 i_inst->_bc_fragment_len=0; 00009 } 00010 00011 /** 00012 * この関数は、MiMicDBのフラグメントをコンパイルします。 00013 * @param o_parsed_len 00014 * 変換した文字列の長さ。 00015 * @return 00016 * ステータスを返す。 00017 */ 00018 NyLPC_TcMiMicDbCompiler_RET NyLPC_cMiMicDbCompiler_compileFragment(NyLPC_TcMiMicDbCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,NyLPC_TUInt32* o_val,NyLPC_TUInt16* o_parsed_bc) 00019 { 00020 int i; 00021 NyLPC_TUInt8 c=i_inst->_bc_fragment_len; 00022 if(c==0 && i_bc->len>=8){ 00023 //キャッシュ0でソースが十分あるときは直接変換 00024 if(NyLPC_mimicvm_txt2UInt(i_bc->ptr,8,o_val)){ 00025 *o_parsed_bc=8; 00026 return NyLPC_TcMiMicDbCompiler_RET_OK; 00027 }else{ 00028 i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FORMAT; 00029 return NyLPC_TcMiMicDbCompiler_RET_ERROR; 00030 } 00031 }else{ 00032 //キャッシュが0でなければ、パディングして変換 00033 for(i=0;i<i_bc->len;i++){ 00034 i_inst->_tmp[c]=i_bc->ptr[i]; 00035 c++; 00036 //8個のバイトコードが溜まったら変換 00037 if(c==8){ 00038 i_inst->_bc_fragment_len=0; 00039 if(NyLPC_mimicvm_txt2UInt(i_inst->_tmp,8,o_val)){ 00040 *o_parsed_bc=i+1;//見チェック 00041 return NyLPC_TcMiMicDbCompiler_RET_OK; 00042 }else{ 00043 i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FORMAT; 00044 return NyLPC_TcMiMicDbCompiler_RET_ERROR; 00045 } 00046 } 00047 } 00048 i_inst->_bc_fragment_len=c; 00049 *o_parsed_bc=i_bc->len; 00050 return NyLPC_TcMiMicDbCompiler_RET_CONTINUE; 00051 } 00052 } 00053 /** 00054 * MiMicDBフラグメントを1文字パースします。 00055 */ 00056 NyLPC_TcMiMicDbCompiler_RET NyLPC_cMiMicDbCompiler_compileFragment2(NyLPC_TcMiMicDbCompiler_t* i_inst,NyLPC_TChar i_bc,NyLPC_TUInt32* o_val) 00057 { 00058 struct NyLPC_TCharArrayPtr bc; 00059 NyLPC_TUInt16 l; 00060 bc.ptr=&i_bc; 00061 bc.len=1; 00062 return NyLPC_cMiMicDbCompiler_compileFragment(i_inst,&bc,o_val,&l); 00063 } 00064 00065 /** 00066 * 複数の数値を一括して変換する。テストしえてないから注意な。 00067 * @return 00068 * 0 - エラー。変換エラーが発生した。 00069 * 0<n - 成功。o_valに出力したデータの数 00070 */ 00071 NyLPC_TUInt16 NyLPC_cMiMicDbCompiler_compile(NyLPC_TcMiMicDbCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,struct NyLPC_TUInt32ArrayPtr* o_val) 00072 { 00073 struct NyLPC_TUInt32ArrayPtr wp=*o_val; 00074 struct NyLPC_TCharArrayPtr rp=*i_bc; 00075 NyLPC_TUInt16 s; 00076 NyLPC_Assert(i_bc->len>0); 00077 while(i_bc->len>0){ 00078 //空き領域チェック 00079 if(wp.len==0){ 00080 //空き領域不足 00081 i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_OUT_BUFFER_TOO_SHORT; 00082 return 0; 00083 } 00084 switch(NyLPC_cMiMicDbCompiler_compileFragment(i_inst,&rp,o_val->ptr,&s)){ 00085 case NyLPC_TcMiMicDbCompiler_RET_OK: 00086 //入力ポインタの移動 00087 if(!NyLPC_TCharArrayPtr_seek(&rp,s)){ 00088 return 0; 00089 } 00090 //出力ポインタの移動 00091 if(!NyLPC_TUInt32ArrayPtr_seek(&wp,1)){ 00092 return 0;//エラー 00093 } 00094 continue; 00095 case NyLPC_TcMiMicDbCompiler_RET_CONTINUE: 00096 //フラグメント化してたらエラー 00097 i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FRAGMENT_UNIT; 00098 default: 00099 return 0; 00100 } 00101 } 00102 //変換完了 00103 return o_val->len-wp.len; 00104 } 00105 00106 00107 #define TEST 00108 #ifndef TEST 00109 void main(void) 00110 { 00111 int i=0; 00112 struct NyLPC_TCharArrayPtr bc; 00113 const char* BC="0000000100000002"; 00114 const char* rp; 00115 NyLPC_TcMiMicDbCompiler_t inst; 00116 NyLPC_TUInt32 obuf[1024]; 00117 NyLPC_TUInt16 pl; 00118 NyLPC_cMiMicDbCompiler_initialize(&inst); 00119 bc.ptr=(char*)BC; 00120 bc.len=strlen(BC); 00121 rp=BC; 00122 NyLPC_cMiMicDbCompiler_compileFragment(&inst,&bc,obuf,&pl); 00123 /* 00124 for(;;){ 00125 switch(NyLPC_cMiMicDbCompiler_compileFragment2(&inst,*bc.ptr,&obuf[i])) 00126 { 00127 case NyLPC_TcMiMicDbCompiler_RET_ERROR: 00128 printf("ERROR"); 00129 return; 00130 case NyLPC_TcMiMicDbCompiler_RET_CONTINUE: 00131 NyLPC_TCharArrayPtr_seek(&bc,1); 00132 break; 00133 case NyLPC_TcMiMicDbCompiler_RET_OK: 00134 i++; 00135 NyLPC_TCharArrayPtr_seek(&bc,1); 00136 break; 00137 } 00138 } 00139 */ 00140 return; 00141 } 00142 #endif
Generated on Tue Jul 12 2022 16:22:57 by
1.7.2
