return;\r
}\r
\r
+void NyLPC_TCharArrayPtr_seek(struct NyLPC_TCharArrayPtr* i_struct,NyLPC_TUInt16 i_seek)\r
+{\r
+ i_struct->ptr+=i_seek;\r
+ i_struct->len-=i_seek;\r
+}\r
+\r
+void NyLPC_TUInt32ArrayPtr_seek(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt16 i_seek)\r
+{\r
+ i_struct->ptr+=i_seek;\r
+ i_struct->len-=i_seek;\r
+}
\ No newline at end of file
#ifndef NYLPC_MIMICVM_H_\r
#define NYLPC_MIMICVM_H_\r
#include "../mimicvm/NyLPC_cMiMicTxtCompiler.h"\r
+#include "../mimicvm/NyLPC_cMiMicDbCompiler.h"\r
#include "../mimicvm/NyLPC_cMiMicVM.h"\r
\r
#endif\r
#define NyLPC_TUInt32_castto_TBool(a) ((a)?NyLPC_TBool_TRUE:NyLPC_TBool_FALSE)\r
\r
\r
+//----------------------------------------------------------------------\r
+\r
+/**\r
+ * 長さ付TChar配列の構造体です。\r
+ *\r
+ */\r
+struct NyLPC_TCharArrayPtr\r
+{\r
+ /** 配列のポインタ */\r
+ NyLPC_TChar* ptr;\r
+ /** 配列の長さ */\r
+ NyLPC_TUInt16 len;\r
+};\r
+/**\r
+ * ptrの位置をi_seekだけ進行します。\r
+ * @param i_struct\r
+ * 操作する構造体\r
+ * @param i_seek\r
+ * シークするバイト長\r
+ */\r
+void NyLPC_TCharArrayPtr_seek(struct NyLPC_TCharArrayPtr* i_struct,NyLPC_TUInt16 i_seek);\r
+\r
+\r
+/**\r
+ * 長さ付TUInt32配列の構造体です。\r
+ *\r
+ */\r
+struct NyLPC_TUInt32ArrayPtr\r
+{\r
+ /** 配列のポインタ */\r
+ NyLPC_TUInt32* ptr;\r
+ /** 要素数 */\r
+ NyLPC_TUInt16 len;\r
+};\r
+/**\r
+ * ptrの位置をi_seekだけ進行します。\r
+ * @param i_struct\r
+ * 操作する構造体\r
+ * @param i_seek\r
+ * シークする要素長\r
+ */\r
+void NyLPC_TUInt32ArrayPtr_seek(struct NyLPC_TUInt32ArrayPtr* i_struct,NyLPC_TUInt16 i_seek);\r
+\r
\r
\r
\r
\r
\r
\r
-\r
-\r
void NyLPC_cMiMicDbCompiler_initialize(NyLPC_TcMiMicDbCompiler_t* i_inst)\r
{\r
i_inst->_bc_fragment_len=0;\r
- return;\r
}\r
+\r
/**\r
- *\r
+ * この関数は、MiMicDBのフラグメントをコンパイルします。\r
* @param o_parsed_len\r
* 変換した文字列の長さ。\r
* @return\r
* ステータスを返す。\r
*/\r
-NyLPC_TcMiMicDbCompiler_ST NyLPC_cMiMicDbCompiler_getValue(NyLPC_TcMiMicDbCompiler_t* i_inst,const NyLPC_TChar* i_bc_fragment,NyLPC_TUInt16 i_bc_len,NyLPC_TUInt32* o_val,NyLPC_TUInt16* o_parsed_bc)\r
+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)\r
{\r
int i;\r
NyLPC_TUInt8 c=i_inst->_bc_fragment_len;\r
- if(c==0 && i_bc_len>=8){\r
+ if(c==0 && i_bc->len>=8){\r
//キャッシュ0でソースが十分あるときは直接変換\r
- if(NyLPC_mimicvm_txt2UInt(i_bc_fragment,8,o_val)){\r
+ if(NyLPC_mimicvm_txt2UInt(i_bc->ptr,8,o_val)){\r
*o_parsed_bc=8;\r
- return NyLPC_TcMiMicDbCompiler_ST_OK;\r
+ return NyLPC_TcMiMicDbCompiler_RET_OK;\r
}else{\r
i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FORMAT;\r
- return NyLPC_TcMiMicDbCompiler_ST_ERROR;\r
+ return NyLPC_TcMiMicDbCompiler_RET_ERROR;\r
}\r
}else{\r
//キャッシュが0でなければ、パディングして変換\r
- for(i=0;i<i_bc_len;i++){\r
- i_inst->_tmp[c]=i_bc_fragment[i];\r
+ for(i=0;i<i_bc->len;i++){\r
+ i_inst->_tmp[c]=i_bc->ptr[i];\r
c++;\r
//8個のバイトコードが溜まったら変換\r
if(c==8){\r
i_inst->_bc_fragment_len=0;\r
if(NyLPC_mimicvm_txt2UInt(i_inst->_tmp,8,o_val)){\r
- *o_parsed_bc=i;\r
- return NyLPC_TcMiMicDbCompiler_ST_OK;\r
+ *o_parsed_bc=i+1;//見チェック\r
+ return NyLPC_TcMiMicDbCompiler_RET_OK;\r
}else{\r
i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FORMAT;\r
- return NyLPC_TcMiMicDbCompiler_ST_ERROR;\r
+ return NyLPC_TcMiMicDbCompiler_RET_ERROR;\r
}\r
}\r
}\r
i_inst->_bc_fragment_len=c;\r
- *o_parsed_bc=i_bc_len;\r
- return NyLPC_TcMiMicDbCompiler_ST_CONTINUE;\r
+ *o_parsed_bc=i_bc->len;\r
+ return NyLPC_TcMiMicDbCompiler_RET_CONTINUE;\r
}\r
}\r
/**\r
- * 複数の数値を一括して変換する。\r
+ * MiMicDBフラグメントを1文字パースします。\r
+ */\r
+NyLPC_TcMiMicDbCompiler_RET NyLPC_cMiMicDbCompiler_compileFragment2(NyLPC_TcMiMicDbCompiler_t* i_inst,NyLPC_TChar i_bc,NyLPC_TUInt32* o_val)\r
+{\r
+ struct NyLPC_TCharArrayPtr bc;\r
+ NyLPC_TUInt16 l;\r
+ bc.ptr=&i_bc;\r
+ bc.len=1;\r
+ return NyLPC_cMiMicDbCompiler_compileFragment(i_inst,&bc,o_val,&l);\r
+}\r
+\r
+/**\r
+ * 複数の数値を一括して変換する。テストしえてないから注意な。\r
* @return\r
* 0 - エラー。変換エラーが発生した。\r
* 0<n - 成功。o_valに出力したデータの数\r
*/\r
-NyLPC_TUInt16 NyLPC_cMiMicDbCompiler_getValues(NyLPC_TcMiMicDbCompiler_t* i_inst,const NyLPC_TChar* i_bc_fragment,NyLPC_TUInt16 i_bc_len,NyLPC_TUInt32 o_val[],NyLPC_TUInt16 i_val_len)\r
+NyLPC_TUInt16 NyLPC_cMiMicDbCompiler_compile(NyLPC_TcMiMicDbCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,struct NyLPC_TUInt32ArrayPtr* o_val)\r
{\r
- NyLPC_TUInt16 l=i_bc_len;\r
+ struct NyLPC_TUInt32ArrayPtr wp=*o_val;\r
+ struct NyLPC_TCharArrayPtr rp=*i_bc;\r
NyLPC_TUInt16 s;\r
- NyLPC_TUInt16 val_len=i_val_len;\r
- NyLPC_TUInt32* val=o_val;\r
- const NyLPC_TChar* rp=i_bc_fragment;\r
- NyLPC_Assert(i_bc_len>0);\r
- while(l>0){\r
+ NyLPC_Assert(i_bc->len>0);\r
+ while(i_bc->len>0){\r
//空き領域チェック\r
- if(val_len==0){\r
+ if(wp.len==0){\r
//空き領域不足\r
i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_OUT_BUFFER_TOO_SHORT;\r
return 0;\r
}\r
- switch(NyLPC_cMiMicDbCompiler_getValue(i_inst,rp,l,val,&s)){\r
- case NyLPC_TcMiMicDbCompiler_ST_OK:\r
+ switch(NyLPC_cMiMicDbCompiler_compileFragment(i_inst,&rp,o_val->ptr,&s)){\r
+ case NyLPC_TcMiMicDbCompiler_RET_OK:\r
//入力ポインタの移動\r
- l-=s;\r
- rp+=s;\r
+ NyLPC_TCharArrayPtr_seek(&rp,s);\r
//出力ポインタの移動\r
- val++;\r
- val_len--;\r
+ NyLPC_TUInt32ArrayPtr_seek(&wp,1);\r
continue;\r
- case NyLPC_TcMiMicDbCompiler_ST_CONTINUE:\r
+ case NyLPC_TcMiMicDbCompiler_RET_CONTINUE:\r
//フラグメント化してたらエラー\r
i_inst->error_reason=NyLPC_TcMiMicDbCompiler_ERROR_FRAGMENT_UNIT;\r
default:\r
}\r
}\r
//変換完了\r
- return i_val_len-val_len;\r
+ return o_val->len-wp.len;\r
}\r
\r
\r
#ifndef TEST\r
void main(void)\r
{\r
- const char* BC="00000001";\r
+ int i=0;\r
+ struct NyLPC_TCharArrayPtr bc;\r
+ const char* BC="0000000100000002";\r
const char* rp;\r
NyLPC_TcMiMicDbCompiler_t inst;\r
- NyLPC_TUInt16 s,l;\r
NyLPC_TUInt32 obuf[1024];\r
+ NyLPC_TUInt16 pl;\r
NyLPC_cMiMicDbCompiler_initialize(&inst);\r
- s=strlen(BC);\r
+ bc.ptr=(char*)BC;\r
+ bc.len=strlen(BC);\r
rp=BC;\r
+ NyLPC_cMiMicDbCompiler_compileFragment(&inst,&bc,obuf,&pl);\r
/*\r
for(;;){\r
- s=NyLPC_cMiMicDbCompiler_getValues(&inst,rp,s,obuf,1024);\r
- if(s==0){\r
- printf("エラー");\r
- }\r
- }*/\r
- \r
- for(;;){\r
- if(NyLPC_cMiMicDbCompiler_getValue(&inst,rp,s,obuf,&l)==NyLPC_TcMiMicDbCompiler_ST_ERROR){\r
- printf("エラー");\r
- }else{\r
- s-=l;\r
- rp+=l;\r
- if(s<=0){\r
-\r
- break;\r
- }\r
+ switch(NyLPC_cMiMicDbCompiler_compileFragment2(&inst,*bc.ptr,&obuf[i]))\r
+ {\r
+ case NyLPC_TcMiMicDbCompiler_RET_ERROR:\r
+ printf("ERROR");\r
+ return;\r
+ case NyLPC_TcMiMicDbCompiler_RET_CONTINUE:\r
+ NyLPC_TCharArrayPtr_seek(&bc,1);\r
+ break;\r
+ case NyLPC_TcMiMicDbCompiler_RET_OK:\r
+ i++;\r
+ NyLPC_TCharArrayPtr_seek(&bc,1);\r
+ break;\r
}\r
}\r
+*/\r
return;\r
}\r
#endif\r
\r
#ifndef NYLPC_CMIMICDBCOMPILER_H_\r
#define NYLPC_CMIMICDBCOMPILER_H_\r
+#include "NyLPC_stdlib.h"\r
\r
\r
typedef struct NyLPC_TcMiMicDbCompiler NyLPC_TcMiMicDbCompiler_t;\r
\r
\r
typedef NyLPC_TUInt8 NyLPC_TcMiMicDbCompiler_ERROR;\r
-//\95s\96¾\82È\83G\83\89\81[\r
+//不明なエラー\r
#define NyLPC_TcMiMicDbCompiler_ERROR_UNKNOWN 0x00\r
-//\8fo\97Í\83o\83b\83t\83@\82ª\91«\82è\82È\82¢\81B\r
+//出力バッファが足りない。\r
#define NyLPC_TcMiMicDbCompiler_ERROR_OUT_BUFFER_TOO_SHORT 0x01\r
-//BC\82Ì\8c`\8e®\82ª\82¨\82©\82µ\82¢\81B\r
+//BCの形式がおかしい。\r
#define NyLPC_TcMiMicDbCompiler_ERROR_FORMAT 0x02\r
-//BC\83t\83\89\83O\83\81\83\93\83g\92P\88Ê\82ª\82¨\82©\82µ\82¢\81B(\93r\92\86\82Å\8fI\82í\82Á\82Ä\82é\81H)\r
+//BCフラグメント単位がおかしい。(途中で終わってる?)\r
#define NyLPC_TcMiMicDbCompiler_ERROR_FRAGMENT_UNIT 0x03\r
\r
\r
-typedef NyLPC_TUInt8 NyLPC_TcMiMicDbCompiler_ST;\r
-#define NyLPC_TcMiMicDbCompiler_ST_OK 1\r
-#define NyLPC_TcMiMicDbCompiler_ST_CONTINUE 2\r
-#define NyLPC_TcMiMicDbCompiler_ST_ERROR 3\r
+typedef NyLPC_TUInt8 NyLPC_TcMiMicDbCompiler_RET;\r
+#define NyLPC_TcMiMicDbCompiler_RET_OK 1\r
+#define NyLPC_TcMiMicDbCompiler_RET_CONTINUE 2\r
+#define NyLPC_TcMiMicDbCompiler_RET_ERROR 3\r
\r
\r
\r
struct NyLPC_TcMiMicDbCompiler\r
{\r
NyLPC_TUInt8 _bc_fragment_len;\r
- NyLPC_TcMiMicDbCompiler_ERROR error_reason;//\83G\83\89\81[\97\9d\97R\r
- NyLPC_TChar _tmp[8];//\83e\83\93\83|\83\89\83\8a\r
+ NyLPC_TcMiMicDbCompiler_ERROR error_reason;//エラー理由\r
+ NyLPC_TChar _tmp[8];//テンポラリ\r
};\r
\r
void NyLPC_cMiMicDbCompiler_initialize(NyLPC_TcMiMicDbCompiler_t* i_inst);\r
#define NyLPC_cMiMicDbCompiler_finalize(i);\r
\r
-NyLPC_TcMiMicDbCompiler_ST NyLPC_cMiMicDbCompiler_getValue(NyLPC_TcMiMicDbCompiler_t* i_inst,const NyLPC_TChar* i_bc_fragment,NyLPC_TUInt16 i_bc_len,NyLPC_TUInt32* o_val,NyLPC_TUInt16* o_parsed_bc);\r
-NyLPC_TUInt16 NyLPC_cMiMicDbCompiler_getValues(NyLPC_TcMiMicDbCompiler_t* i_inst,const NyLPC_TChar* i_bc_fragment,NyLPC_TUInt16 i_bc_len,NyLPC_TUInt32 o_val[],NyLPC_TUInt16 i_val_len);\r
+NyLPC_TcMiMicDbCompiler_RET NyLPC_cMiMicDbCompiler_compileFragment2(NyLPC_TcMiMicDbCompiler_t* i_inst,NyLPC_TChar i_bc,NyLPC_TUInt32* o_val);\r
+NyLPC_TUInt16 NyLPC_cMiMicDbCompiler_compile(NyLPC_TcMiMicDbCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,struct NyLPC_TUInt32ArrayPtr* o_val);\r
+/**\r
+ * フラグメントを集積中であるかを返します。TRUEのとき、パース中であり、フラグメント待ち状態です。\r
+ */\r
+#define NyLPC_cMiMicDbCompiler_hasFragment(i) ((i)->_bc_fragment_len>0)\r
\r
\r
\r
#include <stdlib.h>\r
#include "NyLPC_cMiMicTxtCompiler.h"\r
#include "NyLPC_cMiMicVM_protected.h"\r
-\r
+#include "NyLPC_mimicvm_utils_protected.h"\r
\r
\r
struct TInstructionDef\r
void NyLPC_cMiMicBcCompiler_initialize(NyLPC_TcMiMicTxtCompiler_t* i_inst)\r
{\r
i_inst->out_buf=NULL;\r
-}\r
-\r
-/**\r
- * コンパイル結果を保存するバッファをセットします。\r
- * @param i_output\r
- * インストラクションのバイトイメージを格納するバッファ領域。4バイト境界に合わせてください。\r
- * @param i_length\r
- * i_outputの長さ。少なくとも4バイト以上が必要です。\r
- *\r
- */\r
-void NyLPC_cMiMicTxtCompiler_setOutputBuf(NyLPC_TcMiMicTxtCompiler_t* i_inst,NyLPC_TUInt8* i_output,NyLPC_TUInt16 i_length)\r
-{\r
- i_inst->out_buf=i_output;\r
- i_inst->buf_len=i_length;\r
- i_inst->buf_left=i_length;\r
i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_OPC;\r
i_inst->tmp_len=0;\r
}\r
\r
\r
\r
+#define NyLPC_TcMiMicTxtCompiler_ST_OPC 0x01 //OPをパース中\r
+#define NyLPC_TcMiMicTxtCompiler_ST_OPR 0x02 //オペランドを解析中\r
+#define NyLPC_TcMiMicTxtCompiler_ST_CTR 0x03 //制御パラメータを解析中\r
+#define NyLPC_TcMiMicTxtCompiler_ST_OK 0x04 //パースを完了した。(.EMD検出)\r
+#define NyLPC_TcMiMicTxtCompiler_ST_NG 0xff //パースでエラーが発生ウェーイ\r
+\r
+\r
\r
/**\r
- * ã\83\90ã\82¤ã\83\88ã\82³ã\83¼ã\83\89ã\83\95ã\83©ã\82°ã\83¡ã\83³ã\83\88ã\82\92ã\82³ã\83³ã\83\91ã\82¤ã\83©ã\81«å\85¥力します。\r
+ * ã\83\90ã\82¤ã\83\88ã\82³ã\83¼ã\83\89ã\83\95ã\83©ã\82°ã\83¡ã\83³ã\83\88ã\81\8bã\82\891å\91½ä»¤ã\82\92ã\82³ã\83³ã\83\91ã\82¤ã\83«ã\81\97ã\81¦ã\80\81i_binã\81¸å\87º力します。\r
* バイトコードは、バイナリ値に変換されます。\r
* バイナリ値は、MiMicVMの実行形式です。\r
* @return\r
- * 実行結果を返します。TRUEのときは、ステータスをチェックしてください。\r
+ * 実行結果を返します。NyLPC_TcMiMicTxtCompiler_RET_OKの場合に、i_binへo_bin_lenの長さのインストラクションを出力します。\r
*\r
*/\r
-NyLPC_TBool NyLPC_cMiMicBcCompiler_compileFragment(NyLPC_TcMiMicTxtCompiler_t* i_inst,const NyLPC_TChar* i_bc,NyLPC_TUInt16 i_length,NyLPC_TUInt16* o_len)\r
+NyLPC_TcMiMicTxtCompiler_RET NyLPC_cMiMicBcCompiler_compileFragment(NyLPC_TcMiMicTxtCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,struct NyLPC_TUInt32ArrayPtr* i_bin,NyLPC_TUInt16* o_bin_len,NyLPC_TUInt16* o_parsed_bc)\r
{\r
union NyLPC_TcMiMicVM_TInstruction* wptr;\r
int i;\r
- if(i_inst->out_buf==NULL){\r
- return NyLPC_TBool_FALSE;\r
- }\r
- for(i=0;i<i_length;i++)\r
+ for(i=0;i<i_bc->len;i++)\r
{\r
switch(i_inst->st){\r
case NyLPC_TcMiMicTxtCompiler_ST_OPC:\r
if(i_inst->tmp_len>2){\r
NyLPC_OnErrorGoto(ERROR);\r
}\r
- i_inst->tmp[i_inst->tmp_len]=*(i_bc+i);\r
+ i_inst->tmp[i_inst->tmp_len]=*(i_bc->ptr+i);\r
i_inst->tmp_len++;\r
if(i_inst->tmp_len==2){\r
//[A-Z]{2}がそろった。命令コードか制御命令か判定\r
//命令コードならインストラクションの情報をもらってくる。\r
NyLPC_TcMiMicVM_OPR_TYPE_getOpInfo(i_inst->_current_oprtype,&i_inst->_oprbc_len,&i_inst->_inst_len);\r
//バッファがインストラクション長よりも長いか調べておく。\r
- if(i_inst->_inst_len>i_inst->buf_left){\r
+ if(i_inst->_inst_len>i_bin->len){\r
NyLPC_OnErrorGoto(ERROR);\r
}\r
- //オペランドがあるなら、オペランド解析へ\r
- if(i_inst->_oprbc_len>0){\r
- //オペランド解析の準備\r
- i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_OPR;\r
- }else{\r
- //ゼロなら命令の記録\r
- wptr=(union NyLPC_TcMiMicVM_TInstruction*)i_inst->out_buf;\r
+ //オペランドが無ければ、命令確定。\r
+ if(i_inst->_oprbc_len<=0){\r
+ //インストラクションの出力と処理したBC長の計算\r
+ wptr=(union NyLPC_TcMiMicVM_TInstruction*)i_bin->ptr;\r
wptr->op.opc=i_inst->_current_opc;\r
wptr->op.oprtype=i_inst->_current_oprtype;\r
- i_inst->out_buf+=i_inst->_inst_len;\r
- i_inst->buf_left-=i_inst->_inst_len;\r
- if(i_inst->buf_left<sizeof(NyLPC_TcMiMicVM_OP_TYPE)+sizeof(NyLPC_TcMiMicVM_OPR_TYPE)){\r
- //領域不足\r
- NyLPC_OnErrorGoto(ERROR);\r
- }\r
+ NyLPC_TUInt32ArrayPtr_seek(i_bin,1);\r
+ *o_parsed_bc=i+1; //パースしたBCの長さ\r
+ *o_bin_len=i_inst->_inst_len;\r
+ //解析バッファの長さをリセットして、次のBCブロックのパース準備\r
+ i_inst->tmp_len=0;\r
+ return NyLPC_TcMiMicTxtCompiler_RET_OK;//命令確定。\r
}\r
+ //オペランドがあるなら、パース対象を変更。\r
+ i_inst->tmp_len=0;\r
+ i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_OPR;\r
}else if(bc2ctrlc(i_inst->tmp,&(i_inst->_current_opc),&(i_inst->_current_oprtype))){\r
//制御コードの解析\r
if(i_inst->_oprbc_len>0){\r
//パラメータのある制御命令未定義だからエラー。\r
NyLPC_OnErrorGoto(ERROR);\r
- }else{\r
- //END制御命令ならパース終了\r
- if(i_inst->_current_opc==NyLPC_TcMiMicVM_CP_TYPE_END){\r
- *o_len=i+1;\r
- i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_OK;\r
- return NyLPC_TBool_TRUE;\r
- }\r
}\r
+ //END制御命令以外ならエラー\r
+ if(i_inst->_current_opc!=NyLPC_TcMiMicVM_CP_TYPE_END){\r
+ NyLPC_OnErrorGoto(ERROR);\r
+ }\r
+ //END命令\r
+ *o_parsed_bc=i+1; //パースしたBCの長さ\r
+ *o_bin_len=0;\r
+ i_inst->tmp_len=0;\r
+ return NyLPC_TcMiMicTxtCompiler_RET_OK_END;//命令確定。(パース完了)\r
}else{\r
+ //不明な命令\r
NyLPC_OnErrorGoto(ERROR);\r
}\r
- //解析バッファの長さをリセット\r
- i_inst->tmp_len=0;\r
-\r
}\r
break;\r
case NyLPC_TcMiMicTxtCompiler_ST_CTR:\r
+ NyLPC_OnErrorGoto(ERROR);\r
case NyLPC_TcMiMicTxtCompiler_ST_OPR:\r
//オペランド蓄積.\r
- i_inst->tmp[i_inst->tmp_len]=*(i_bc+i);\r
+ i_inst->tmp[i_inst->tmp_len]=*(i_bc->ptr+i);\r
i_inst->tmp_len++;\r
//オペランド長さになるまで値を追記\r
if(i_inst->_oprbc_len==i_inst->tmp_len){\r
//オペランドの収集が完了したらパース\r
- wptr=(union NyLPC_TcMiMicVM_TInstruction*)i_inst->out_buf;\r
+ wptr=(union NyLPC_TcMiMicVM_TInstruction*)i_bin->ptr;\r
wptr->op.opc=i_inst->_current_opc;\r
wptr->op.oprtype=i_inst->_current_oprtype;\r
//オペランドの変換処理\r
default:\r
NyLPC_OnErrorGoto(ERROR);\r
}\r
- //OPR解析成功。wpをずらす。\r
- i_inst->out_buf+=i_inst->_inst_len;\r
- i_inst->buf_left-=i_inst->_inst_len;\r
- //バッファ空いてる?(少なくともOP+OPTの分)\r
- if(i_inst->buf_left<sizeof(NyLPC_TcMiMicVM_OP_TYPE)+sizeof(NyLPC_TcMiMicVM_OPR_TYPE)){\r
- //領域不足\r
- NyLPC_OnErrorGoto(ERROR);\r
- }\r
+ //OPR解析成功。パースしたブロックサイズの計算。\r
+ *o_parsed_bc=i+1; //パースしたBCの長さ\r
+ *o_bin_len=i_inst->_inst_len;\r
i_inst->tmp_len=0;\r
i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_OPC;\r
+ return NyLPC_TcMiMicTxtCompiler_RET_OK;\r
}\r
break;\r
default:\r
NyLPC_OnErrorGoto(ERROR);\r
}\r
}\r
- *o_len=i_length;\r
- return NyLPC_TBool_TRUE;\r
+ *o_bin_len=0;\r
+ *o_parsed_bc=i_bc->len;\r
+ return NyLPC_TcMiMicTxtCompiler_RET_CONTINUE;\r
ERROR:\r
i_inst->st=NyLPC_TcMiMicTxtCompiler_ST_NG;\r
- return NyLPC_TBool_FALSE;\r
+ return NyLPC_TcMiMicTxtCompiler_RET_NG;\r
}\r
\r
-NyLPC_TUInt16 NyLPC_cMiMicBcCompiler_getCompiledInstructionLength(NyLPC_TcMiMicTxtCompiler_t* i_inst)\r
+\r
+\r
+/**\r
+ * フラグメント入力のMiMicBCをコンパイルします。\r
+ * この関数は、1文字のフラグメントMiMicBCをコンパイラに入力します。\r
+ * @return\r
+ * 実行結果を返します。TRUEのときは、ステータスをチェックしてください。\r
+ *\r
+ */\r
+NyLPC_TcMiMicTxtCompiler_RET NyLPC_cMiMicBcCompiler_compileFragment2(NyLPC_TcMiMicTxtCompiler_t* i_inst,NyLPC_TChar i_bc,struct NyLPC_TUInt32ArrayPtr* i_bin,NyLPC_TUInt16* o_bin_len)\r
{\r
- return i_inst->buf_len-i_inst->buf_left;\r
+ struct NyLPC_TCharArrayPtr bc;\r
+ NyLPC_TUInt16 bc_len;\r
+ bc.ptr=&i_bc;\r
+ bc.len=1;\r
+ return NyLPC_cMiMicBcCompiler_compileFragment(i_inst,&bc,i_bin,o_bin_len,&bc_len);\r
}\r
\r
\r
+\r
/**\r
* 2バイトのバイトコードを、制御コードに変換します。\r
*/\r
NyLPC_TUInt8 oprbc_len;\r
NyLPC_TUInt8 ist_len;\r
}_tbl[]={\r
- {NyLPC_TcMiMicVM_OPR_TYPE_NONE, 0, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_WM_WM, (1+1)*2, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_WM_H08, (1+1)*2, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_WM_H16, (1+2)*2, 8},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_WM_H32, (1+4)*2, 8},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_WM, (1)*2, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_H8, (1)*2, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_H16, (2)*2, 4},\r
- {NyLPC_TcMiMicVM_OPR_TYPE_H32, (4)*2, 8},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_NONE, 0, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_WM_WM, (1+1)*2, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_WM_H08, (1+1)*2, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_WM_H16, (1+2)*2, 2},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_WM_H32, (1+4)*2, 2},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_WM, (1)*2, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_H8, (1)*2, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_H16, (2)*2, 1},\r
+ {NyLPC_TcMiMicVM_OPR_TYPE_H32, (4)*2, 2},\r
{0,0,0}\r
};\r
int i;\r
#ifndef TEST\r
void main(void)\r
{\r
- const char* BC="AA0102AB0100000001AE0203AF0200000003AI0304AJ0300000004AM07BA0505BE0607CA0304CB0300000005CE0304CF0300000005CI0304CJ0300000005DA0400000000DE0400000000EA04EE04EF00000000ZAZZ";\r
- const char* rp;\r
+ struct NyLPC_TCharArrayPtr bc;\r
+ const char* BC="AA0102AB0100000001AE0203AF0200000003AI0304AJ0300000004AM07BA0505BE0607CA0304CB0300000005CE0304CF0300000005CI0304CJ0300000005DA0400000000DE0400000000EA04EE04EF00000000ZAZZ.E";\r
NyLPC_TcMiMicTxtCompiler_t inst;\r
- NyLPC_TUInt16 s,l;\r
- NyLPC_TUInt8 obuf[1024];\r
+ struct NyLPC_TUInt32ArrayPtr bin;\r
+\r
+ NyLPC_TUInt16 l,bl;\r
+ NyLPC_TUInt32 obuf[1024];\r
NyLPC_cMiMicBcCompiler_initialize(&inst);\r
- s=strlen(BC);\r
- rp=BC;\r
- NyLPC_cMiMicTxtCompiler_setOutputBuf(&inst,obuf,1024);\r
+ bc.ptr=(char* )BC;\r
+ bc.len=strlen(BC);\r
+ bin.ptr=obuf;\r
+ bin.len=5;\r
\r
for(;;){\r
- if(!NyLPC_cMiMicBcCompiler_compileFragment(&inst,rp,1,&l)){\r
- printf("エラー");\r
- }else{\r
- s-=l;\r
- rp+=l;\r
- if(s<=0){\r
\r
- break;\r
- }\r
+ switch(NyLPC_cMiMicBcCompiler_compileFragment(&inst,&bc,&bin,&bl,&l))\r
+ {\r
+ case NyLPC_TcMiMicTxtCompiler_RET_OK:\r
+ //命令確定。\r
+ NyLPC_TUInt32ArrayPtr_seek(&bin,bl);\r
+ NyLPC_TCharArrayPtr_seek(&bc,l);\r
+ break;\r
+ case NyLPC_TcMiMicTxtCompiler_RET_OK_END:\r
+ //命令終端\r
+ printf("OK");\r
+ break;\r
+ case NyLPC_TcMiMicTxtCompiler_RET_CONTINUE:\r
+ //蓄積中。\r
+ NyLPC_TCharArrayPtr_seek(&bc,l);\r
+ break;\r
+ case NyLPC_TcMiMicTxtCompiler_RET_NG:\r
+ printf("エラー");\r
+ return;\r
+ default:\r
+ break;\r
}\r
}\r
- return;\r
}\r
#endif\r
\r
\r
struct NyLPC_TcMiMicTxtCompiler{\r
NyLPC_TUInt8* out_buf;\r
- NyLPC_TUInt16 buf_len; //出力バッファの長さ\r
- NyLPC_TUInt16 buf_left; //バッファの残り長さ\r
NyLPC_TUInt8 st;//ステータス\r
NyLPC_TcMiMicVM_OP_TYPE _current_opc; //解析中のオペコード\r
NyLPC_TUInt8 _current_oprtype; //解析中のオペランドタイプ\r
NyLPC_TChar tmp[24];\r
};\r
\r
+typedef NyLPC_TUInt8 NyLPC_TcMiMicTxtCompiler_RET;\r
+#define NyLPC_TcMiMicTxtCompiler_RET_OK 0x00\r
+#define NyLPC_TcMiMicTxtCompiler_RET_OK_END 0x01 //命令のパースに成功し、かつEND命令を検出。\r
+#define NyLPC_TcMiMicTxtCompiler_RET_CONTINUE 0x02 //続きのBCを要求している。\r
+#define NyLPC_TcMiMicTxtCompiler_RET_NG 0x80\r
+\r
+\r
+\r
void NyLPC_cMiMicBcCompiler_initialize(NyLPC_TcMiMicTxtCompiler_t* i_inst);\r
#define NyLPC_cMiMicBcCompiler_finalize(i)\r
-void NyLPC_cMiMicTxtCompiler_setOutputBuf(NyLPC_TcMiMicTxtCompiler_t* i_inst,NyLPC_TUInt8* out_buf,NyLPC_TUInt16 i_length);\r
-NyLPC_TUInt16 NyLPC_cMiMicBcCompiler_getCompiledInstructionLength(NyLPC_TcMiMicTxtCompiler_t* i_inst);\r
-NyLPC_TBool NyLPC_cMiMicBcCompiler_compileFragment(NyLPC_TcMiMicTxtCompiler_t* i_inst,const NyLPC_TChar* i_bc,NyLPC_TUInt16 i_length,NyLPC_TUInt16* o_len);\r
-#define NyLPC_cMiMicBcCompiler_getStatus(i) ((i)->st)\r
+NyLPC_TcMiMicTxtCompiler_RET NyLPC_cMiMicBcCompiler_compileFragment(NyLPC_TcMiMicTxtCompiler_t* i_inst,const struct NyLPC_TCharArrayPtr* i_bc,struct NyLPC_TUInt32ArrayPtr* i_bin,NyLPC_TUInt16* o_bin_len,NyLPC_TUInt16* o_parsed_bc);\r
+NyLPC_TcMiMicTxtCompiler_RET NyLPC_cMiMicBcCompiler_compileFragment2(NyLPC_TcMiMicTxtCompiler_t* i_inst,NyLPC_TChar i_bc,struct NyLPC_TUInt32ArrayPtr* i_bin,NyLPC_TUInt16* o_bin_len);\r
+\r
+\r
+\r
+\r
\r
#endif /* NYLPC_CMIMICTXTCOMPILER_H_ */\r
}\r
return NyLPC_TBool_TRUE;\r
}\r
+\r
#include "NyLPC_stdlib.h"\r
\r
\r
+\r
+\r
+\r
NyLPC_TBool NyLPC_mimicvm_txt2UInt(const NyLPC_TChar* i_txt,NyLPC_TUInt8 i_num,void* out);\r
\r
\r