This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Fork of libMiMic by
core/mimicvm/NyLPC_cMiMicVM.cpp@2:b96c1e90d120, 2013-03-27 (annotated)
- Committer:
- nyatla
- Date:
- Wed Mar 27 12:07:47 2013 +0000
- Revision:
- 2:b96c1e90d120
???????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 2:b96c1e90d120 | 1 | /********************************************************************************* |
nyatla | 2:b96c1e90d120 | 2 | * PROJECT: MiMic |
nyatla | 2:b96c1e90d120 | 3 | * -------------------------------------------------------------------------------- |
nyatla | 2:b96c1e90d120 | 4 | * |
nyatla | 2:b96c1e90d120 | 5 | * This file is part of MiMic |
nyatla | 2:b96c1e90d120 | 6 | * Copyright (C)2011 Ryo Iizuka |
nyatla | 2:b96c1e90d120 | 7 | * |
nyatla | 2:b96c1e90d120 | 8 | * MiMic is free software: you can redistribute it and/or modify |
nyatla | 2:b96c1e90d120 | 9 | * it under the terms of the GNU Lesser General Public License as published |
nyatla | 2:b96c1e90d120 | 10 | * by the Free Software Foundation, either version 3 of the License, or |
nyatla | 2:b96c1e90d120 | 11 | * (at your option) any later version. |
nyatla | 2:b96c1e90d120 | 12 | * |
nyatla | 2:b96c1e90d120 | 13 | * This program is distributed in the hope that it will be useful, |
nyatla | 2:b96c1e90d120 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
nyatla | 2:b96c1e90d120 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
nyatla | 2:b96c1e90d120 | 16 | * GNU General Public License for more details. |
nyatla | 2:b96c1e90d120 | 17 | * |
nyatla | 2:b96c1e90d120 | 18 | * You should have received a copy of the GNU Lesser General Public License |
nyatla | 2:b96c1e90d120 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
nyatla | 2:b96c1e90d120 | 20 | * |
nyatla | 2:b96c1e90d120 | 21 | * For further information please contact. |
nyatla | 2:b96c1e90d120 | 22 | * http://nyatla.jp/ |
nyatla | 2:b96c1e90d120 | 23 | * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> |
nyatla | 2:b96c1e90d120 | 24 | * |
nyatla | 2:b96c1e90d120 | 25 | *********************************************************************************/ |
nyatla | 2:b96c1e90d120 | 26 | #include <ctype.h> |
nyatla | 2:b96c1e90d120 | 27 | #include <stdlib.h> |
nyatla | 2:b96c1e90d120 | 28 | #include "NyLPC_cMiMicVM_protected.h" |
nyatla | 2:b96c1e90d120 | 29 | |
nyatla | 2:b96c1e90d120 | 30 | static NyLPC_TUInt8 process_instruction(NyLPC_TcMiMicVM_t* i_inst,const union NyLPC_TcMiMicVM_TInstruction* ist,NyLPC_TUInt32* o_code); |
nyatla | 2:b96c1e90d120 | 31 | |
nyatla | 2:b96c1e90d120 | 32 | |
nyatla | 2:b96c1e90d120 | 33 | |
nyatla | 2:b96c1e90d120 | 34 | void NyLPC_cMiMicVM_initialize(NyLPC_TcMiMicVM_t* i_inst,struct NyLPC_TcMiMicVM_TEvent* i_handler) |
nyatla | 2:b96c1e90d120 | 35 | { |
nyatla | 2:b96c1e90d120 | 36 | NyLPC_Assert(i_inst!=NULL); |
nyatla | 2:b96c1e90d120 | 37 | NyLPC_Assert(i_handler!=NULL); |
nyatla | 2:b96c1e90d120 | 38 | NyLPC_Assert(i_handler->get_stream!=NULL); |
nyatla | 2:b96c1e90d120 | 39 | NyLPC_Assert(i_handler->put_stream!=NULL); |
nyatla | 2:b96c1e90d120 | 40 | NyLPC_Assert(i_handler->sleep!=NULL); |
nyatla | 2:b96c1e90d120 | 41 | i_inst->_event_handler=i_handler; |
nyatla | 2:b96c1e90d120 | 42 | return; |
nyatla | 2:b96c1e90d120 | 43 | } |
nyatla | 2:b96c1e90d120 | 44 | |
nyatla | 2:b96c1e90d120 | 45 | |
nyatla | 2:b96c1e90d120 | 46 | /** |
nyatla | 2:b96c1e90d120 | 47 | * 固定長命令+固定長データを実行します。 |
nyatla | 2:b96c1e90d120 | 48 | * 関数の終了条件は、1.EXIT命令に到達する。2.インストラクションの終端に到達する。3.エラーが発生する。 |
nyatla | 2:b96c1e90d120 | 49 | * |
nyatla | 2:b96c1e90d120 | 50 | */ |
nyatla | 2:b96c1e90d120 | 51 | NyLPC_TUInt32 NyLPC_cMiMicVM_run(NyLPC_TcMiMicVM_t* i_inst,const NyLPC_TUInt32* i_instruction,const NyLPC_TUInt16 i_size_of_instruction) |
nyatla | 2:b96c1e90d120 | 52 | { |
nyatla | 2:b96c1e90d120 | 53 | //データ部をgetstreamと連動させること。 |
nyatla | 2:b96c1e90d120 | 54 | NyLPC_TUInt32 retcode=NyLPC_cMiMicVM_RESULT_OK; |
nyatla | 2:b96c1e90d120 | 55 | NyLPC_TUInt16 pc=0; |
nyatla | 2:b96c1e90d120 | 56 | NyLPC_TUInt8 proc_in_byte; |
nyatla | 2:b96c1e90d120 | 57 | if(i_size_of_instruction>0){ |
nyatla | 2:b96c1e90d120 | 58 | proc_in_byte=process_instruction(i_inst,(const union NyLPC_TcMiMicVM_TInstruction*)(i_instruction+pc),&retcode); |
nyatla | 2:b96c1e90d120 | 59 | pc+=proc_in_byte; |
nyatla | 2:b96c1e90d120 | 60 | //プログラムの終端に到達するか、0バイト処理の場合にブレーク。 |
nyatla | 2:b96c1e90d120 | 61 | while(proc_in_byte>0 && pc<i_size_of_instruction){ |
nyatla | 2:b96c1e90d120 | 62 | proc_in_byte=process_instruction(i_inst,(const union NyLPC_TcMiMicVM_TInstruction*)(i_instruction+pc),&retcode); |
nyatla | 2:b96c1e90d120 | 63 | pc+=proc_in_byte; |
nyatla | 2:b96c1e90d120 | 64 | } |
nyatla | 2:b96c1e90d120 | 65 | } |
nyatla | 2:b96c1e90d120 | 66 | return retcode; |
nyatla | 2:b96c1e90d120 | 67 | } |
nyatla | 2:b96c1e90d120 | 68 | /** |
nyatla | 2:b96c1e90d120 | 69 | * 出力ストリームへ32ビット値を書き出す。 |
nyatla | 2:b96c1e90d120 | 70 | */ |
nyatla | 2:b96c1e90d120 | 71 | NyLPC_TBool NyLPC_cMiMicVM_sput(NyLPC_TcMiMicVM_t* i_inst,NyLPC_TUInt32 i_val) |
nyatla | 2:b96c1e90d120 | 72 | { |
nyatla | 2:b96c1e90d120 | 73 | if(!i_inst->_event_handler->put_stream(i_inst->_event_handler,i_val)){ |
nyatla | 2:b96c1e90d120 | 74 | return NyLPC_TBool_FALSE; |
nyatla | 2:b96c1e90d120 | 75 | } |
nyatla | 2:b96c1e90d120 | 76 | return NyLPC_TBool_TRUE; |
nyatla | 2:b96c1e90d120 | 77 | } |
nyatla | 2:b96c1e90d120 | 78 | /** |
nyatla | 2:b96c1e90d120 | 79 | * 入力ストリームから32ビット値を読み出す。 |
nyatla | 2:b96c1e90d120 | 80 | */ |
nyatla | 2:b96c1e90d120 | 81 | NyLPC_TBool NyLPC_cMiMicVM_sget(NyLPC_TcMiMicVM_t* i_inst,NyLPC_TUInt32* o_val) |
nyatla | 2:b96c1e90d120 | 82 | { |
nyatla | 2:b96c1e90d120 | 83 | if(!i_inst->_event_handler->get_stream(i_inst->_event_handler,o_val)){ |
nyatla | 2:b96c1e90d120 | 84 | return NyLPC_TBool_FALSE; |
nyatla | 2:b96c1e90d120 | 85 | } |
nyatla | 2:b96c1e90d120 | 86 | return NyLPC_TBool_TRUE; |
nyatla | 2:b96c1e90d120 | 87 | } |
nyatla | 2:b96c1e90d120 | 88 | |
nyatla | 2:b96c1e90d120 | 89 | |
nyatla | 2:b96c1e90d120 | 90 | |
nyatla | 2:b96c1e90d120 | 91 | /** |
nyatla | 2:b96c1e90d120 | 92 | * インストラクションを1個処理し、処理したバイト数を返す。 |
nyatla | 2:b96c1e90d120 | 93 | * インストラクションの境界値はチェックされないので、コンパイル時にチェックしておくこと。 |
nyatla | 2:b96c1e90d120 | 94 | * @return |
nyatla | 2:b96c1e90d120 | 95 | * 処理したインストラクションのワード数(UInt32単位)。 |
nyatla | 2:b96c1e90d120 | 96 | * 終了した場合は0を返す。0を返したときは、ret_codeにMiMicVMの終了コードを返す。 |
nyatla | 2:b96c1e90d120 | 97 | */ |
nyatla | 2:b96c1e90d120 | 98 | static NyLPC_TUInt8 process_instruction(NyLPC_TcMiMicVM_t* i_inst,const union NyLPC_TcMiMicVM_TInstruction* ist,NyLPC_TUInt32* o_code) |
nyatla | 2:b96c1e90d120 | 99 | { |
nyatla | 2:b96c1e90d120 | 100 | NyLPC_TUInt32 tret; |
nyatla | 2:b96c1e90d120 | 101 | switch(ist->op.opc){ |
nyatla | 2:b96c1e90d120 | 102 | case NyLPC_TcMiMicVM_OP_TYPE_AND: |
nyatla | 2:b96c1e90d120 | 103 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 104 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 105 | i_inst->wm[ist->wmwm_32.wm1]&=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 106 | break; |
nyatla | 2:b96c1e90d120 | 107 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 108 | i_inst->wm[ist->wmh32_64.wm]&=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 109 | break; |
nyatla | 2:b96c1e90d120 | 110 | default: |
nyatla | 2:b96c1e90d120 | 111 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 112 | } |
nyatla | 2:b96c1e90d120 | 113 | break; |
nyatla | 2:b96c1e90d120 | 114 | case NyLPC_TcMiMicVM_OP_TYPE_OR: |
nyatla | 2:b96c1e90d120 | 115 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 116 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 117 | i_inst->wm[ist->wmwm_32.wm1]|=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 118 | break; |
nyatla | 2:b96c1e90d120 | 119 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 120 | i_inst->wm[ist->wmh32_64.wm]|=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 121 | break; |
nyatla | 2:b96c1e90d120 | 122 | default: |
nyatla | 2:b96c1e90d120 | 123 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 124 | } |
nyatla | 2:b96c1e90d120 | 125 | break; |
nyatla | 2:b96c1e90d120 | 126 | case NyLPC_TcMiMicVM_OP_TYPE_XOR: |
nyatla | 2:b96c1e90d120 | 127 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 128 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 129 | i_inst->wm[ist->wmwm_32.wm1]^=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 130 | break; |
nyatla | 2:b96c1e90d120 | 131 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 132 | i_inst->wm[ist->wmh32_64.wm]^=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 133 | break; |
nyatla | 2:b96c1e90d120 | 134 | default: |
nyatla | 2:b96c1e90d120 | 135 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 136 | } |
nyatla | 2:b96c1e90d120 | 137 | break; |
nyatla | 2:b96c1e90d120 | 138 | case NyLPC_TcMiMicVM_OP_TYPE_NOT: |
nyatla | 2:b96c1e90d120 | 139 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 140 | case NyLPC_TcMiMicVM_OPR_TYPE_WM: |
nyatla | 2:b96c1e90d120 | 141 | i_inst->wm[ist->wm_32.wm]=~i_inst->wm[ist->wm_32.wm]; |
nyatla | 2:b96c1e90d120 | 142 | break; |
nyatla | 2:b96c1e90d120 | 143 | default: |
nyatla | 2:b96c1e90d120 | 144 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 145 | } |
nyatla | 2:b96c1e90d120 | 146 | break; |
nyatla | 2:b96c1e90d120 | 147 | case NyLPC_TcMiMicVM_OP_TYPE_SHL: |
nyatla | 2:b96c1e90d120 | 148 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 149 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H08: |
nyatla | 2:b96c1e90d120 | 150 | i_inst->wm[ist->wmh08_32.wm]=i_inst->wm[ist->wmh08_32.wm]<<ist->wmh08_32.h8; |
nyatla | 2:b96c1e90d120 | 151 | break; |
nyatla | 2:b96c1e90d120 | 152 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 153 | i_inst->wm[ist->wmwm_32.wm1]=i_inst->wm[ist->wmwm_32.wm1]<<i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 154 | break; |
nyatla | 2:b96c1e90d120 | 155 | default: |
nyatla | 2:b96c1e90d120 | 156 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 157 | } |
nyatla | 2:b96c1e90d120 | 158 | break; |
nyatla | 2:b96c1e90d120 | 159 | case NyLPC_TcMiMicVM_OP_TYPE_SHR: |
nyatla | 2:b96c1e90d120 | 160 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 161 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H08: |
nyatla | 2:b96c1e90d120 | 162 | i_inst->wm[ist->wmh08_32.wm]=i_inst->wm[ist->wmh08_32.wm]>>ist->wmh08_32.h8; |
nyatla | 2:b96c1e90d120 | 163 | break; |
nyatla | 2:b96c1e90d120 | 164 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 165 | i_inst->wm[ist->wmwm_32.wm1]=i_inst->wm[ist->wmwm_32.wm1]>>i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 166 | break; |
nyatla | 2:b96c1e90d120 | 167 | default: |
nyatla | 2:b96c1e90d120 | 168 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 169 | } |
nyatla | 2:b96c1e90d120 | 170 | break; |
nyatla | 2:b96c1e90d120 | 171 | case NyLPC_TcMiMicVM_OP_TYPE_ADD: |
nyatla | 2:b96c1e90d120 | 172 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 173 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 174 | i_inst->wm[ist->wmwm_32.wm1]+=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 175 | break; |
nyatla | 2:b96c1e90d120 | 176 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 177 | i_inst->wm[ist->wmh32_64.wm]+=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 178 | break; |
nyatla | 2:b96c1e90d120 | 179 | default: |
nyatla | 2:b96c1e90d120 | 180 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 181 | } |
nyatla | 2:b96c1e90d120 | 182 | break; |
nyatla | 2:b96c1e90d120 | 183 | case NyLPC_TcMiMicVM_OP_TYPE_SUB: |
nyatla | 2:b96c1e90d120 | 184 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 185 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 186 | i_inst->wm[ist->wmwm_32.wm1]-=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 187 | break; |
nyatla | 2:b96c1e90d120 | 188 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 189 | i_inst->wm[ist->wmh32_64.wm]-=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 190 | break; |
nyatla | 2:b96c1e90d120 | 191 | default: |
nyatla | 2:b96c1e90d120 | 192 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 193 | } |
nyatla | 2:b96c1e90d120 | 194 | break; |
nyatla | 2:b96c1e90d120 | 195 | case NyLPC_TcMiMicVM_OP_TYPE_MUL: |
nyatla | 2:b96c1e90d120 | 196 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 197 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 198 | i_inst->wm[ist->wmwm_32.wm1]*=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 199 | break; |
nyatla | 2:b96c1e90d120 | 200 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 201 | i_inst->wm[ist->wmh32_64.wm]*=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 202 | break; |
nyatla | 2:b96c1e90d120 | 203 | default: |
nyatla | 2:b96c1e90d120 | 204 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 205 | } |
nyatla | 2:b96c1e90d120 | 206 | break; |
nyatla | 2:b96c1e90d120 | 207 | case NyLPC_TcMiMicVM_OP_TYPE_MGET: |
nyatla | 2:b96c1e90d120 | 208 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 209 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 210 | i_inst->wm[ist->wmh32_64.wm]=*((NyLPC_TUInt32*)(ist->wmh32_64.h32)); |
nyatla | 2:b96c1e90d120 | 211 | break; |
nyatla | 2:b96c1e90d120 | 212 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 213 | i_inst->wm[ist->wmwm_32.wm1]=*((NyLPC_TUInt32*)(i_inst->wm[ist->wmwm_32.wm2])); |
nyatla | 2:b96c1e90d120 | 214 | break; |
nyatla | 2:b96c1e90d120 | 215 | default: |
nyatla | 2:b96c1e90d120 | 216 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 217 | } |
nyatla | 2:b96c1e90d120 | 218 | break; |
nyatla | 2:b96c1e90d120 | 219 | case NyLPC_TcMiMicVM_OP_TYPE_MPUT: |
nyatla | 2:b96c1e90d120 | 220 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 221 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 222 | *((NyLPC_TUInt32*)(ist->wmh32_64.h32))=i_inst->wm[ist->wmh32_64.wm]; |
nyatla | 2:b96c1e90d120 | 223 | break; |
nyatla | 2:b96c1e90d120 | 224 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 225 | *((NyLPC_TUInt32*)(i_inst->wm[ist->wmwm_32.wm2]))=i_inst->wm[ist->wmwm_32.wm1]; |
nyatla | 2:b96c1e90d120 | 226 | break; |
nyatla | 2:b96c1e90d120 | 227 | default: |
nyatla | 2:b96c1e90d120 | 228 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 229 | } |
nyatla | 2:b96c1e90d120 | 230 | break; |
nyatla | 2:b96c1e90d120 | 231 | case NyLPC_TcMiMicVM_OP_TYPE_SGET: |
nyatla | 2:b96c1e90d120 | 232 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 233 | case NyLPC_TcMiMicVM_OPR_TYPE_WM: |
nyatla | 2:b96c1e90d120 | 234 | if(!i_inst->_event_handler->get_stream(i_inst->_event_handler,&(i_inst->wm[ist->wm_32.wm]))){ |
nyatla | 2:b96c1e90d120 | 235 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 236 | } |
nyatla | 2:b96c1e90d120 | 237 | break; |
nyatla | 2:b96c1e90d120 | 238 | default: |
nyatla | 2:b96c1e90d120 | 239 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 240 | } |
nyatla | 2:b96c1e90d120 | 241 | break; |
nyatla | 2:b96c1e90d120 | 242 | case NyLPC_TcMiMicVM_OP_TYPE_SPUT: |
nyatla | 2:b96c1e90d120 | 243 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 244 | case NyLPC_TcMiMicVM_OPR_TYPE_WM: |
nyatla | 2:b96c1e90d120 | 245 | if(!i_inst->_event_handler->put_stream(i_inst->_event_handler,i_inst->wm[ist->wm_32.wm])){ |
nyatla | 2:b96c1e90d120 | 246 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 247 | } |
nyatla | 2:b96c1e90d120 | 248 | break; |
nyatla | 2:b96c1e90d120 | 249 | case NyLPC_TcMiMicVM_OPR_TYPE_H32: |
nyatla | 2:b96c1e90d120 | 250 | if(!i_inst->_event_handler->put_stream(i_inst->_event_handler,ist->h32_64.h32)){ |
nyatla | 2:b96c1e90d120 | 251 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 252 | } |
nyatla | 2:b96c1e90d120 | 253 | break; |
nyatla | 2:b96c1e90d120 | 254 | default: |
nyatla | 2:b96c1e90d120 | 255 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 256 | } |
nyatla | 2:b96c1e90d120 | 257 | break; |
nyatla | 2:b96c1e90d120 | 258 | case NyLPC_TcMiMicVM_OP_TYPE_LD: |
nyatla | 2:b96c1e90d120 | 259 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 260 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 261 | i_inst->wm[ist->wmwm_32.wm1]=i_inst->wm[ist->wmwm_32.wm2]; |
nyatla | 2:b96c1e90d120 | 262 | break; |
nyatla | 2:b96c1e90d120 | 263 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 264 | i_inst->wm[ist->wmh32_64.wm]=ist->wmh32_64.h32; |
nyatla | 2:b96c1e90d120 | 265 | break; |
nyatla | 2:b96c1e90d120 | 266 | default: |
nyatla | 2:b96c1e90d120 | 267 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 268 | } |
nyatla | 2:b96c1e90d120 | 269 | break; |
nyatla | 2:b96c1e90d120 | 270 | case NyLPC_TcMiMicVM_OP_TYPE_NOP: |
nyatla | 2:b96c1e90d120 | 271 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 272 | case NyLPC_TcMiMicVM_OPR_TYPE_NONE: |
nyatla | 2:b96c1e90d120 | 273 | break; |
nyatla | 2:b96c1e90d120 | 274 | case NyLPC_TcMiMicVM_OPR_TYPE_H08: |
nyatla | 2:b96c1e90d120 | 275 | i_inst->_event_handler->sleep(i_inst->_event_handler,ist->h8_32.h8); |
nyatla | 2:b96c1e90d120 | 276 | break; |
nyatla | 2:b96c1e90d120 | 277 | default: |
nyatla | 2:b96c1e90d120 | 278 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 279 | } |
nyatla | 2:b96c1e90d120 | 280 | break; |
nyatla | 2:b96c1e90d120 | 281 | //native call |
nyatla | 2:b96c1e90d120 | 282 | case NyLPC_TcMiMicVM_OP_TYPE_CALL: |
nyatla | 2:b96c1e90d120 | 283 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 284 | case NyLPC_TcMiMicVM_OPR_TYPE_WM: |
nyatla | 2:b96c1e90d120 | 285 | tret=i_inst->_event_handler->native_call(i_inst->_event_handler,i_inst->wm[ist->wm_32.wm],i_inst); |
nyatla | 2:b96c1e90d120 | 286 | if(!NyLPC_cMiMicVM_RESULT_isOK(tret)){ |
nyatla | 2:b96c1e90d120 | 287 | *o_code=tret; |
nyatla | 2:b96c1e90d120 | 288 | NyLPC_OnErrorGoto(ERROR_INHERIT);//エラー継承 |
nyatla | 2:b96c1e90d120 | 289 | } |
nyatla | 2:b96c1e90d120 | 290 | break; |
nyatla | 2:b96c1e90d120 | 291 | case NyLPC_TcMiMicVM_OPR_TYPE_H32: |
nyatla | 2:b96c1e90d120 | 292 | tret=i_inst->_event_handler->native_call(i_inst->_event_handler,ist->h32_64.h32,i_inst); |
nyatla | 2:b96c1e90d120 | 293 | if(!NyLPC_cMiMicVM_RESULT_isOK(tret)){ |
nyatla | 2:b96c1e90d120 | 294 | *o_code=tret; |
nyatla | 2:b96c1e90d120 | 295 | NyLPC_OnErrorGoto(ERROR_INHERIT);//エラー継承 |
nyatla | 2:b96c1e90d120 | 296 | } |
nyatla | 2:b96c1e90d120 | 297 | break; |
nyatla | 2:b96c1e90d120 | 298 | default: |
nyatla | 2:b96c1e90d120 | 299 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 300 | } |
nyatla | 2:b96c1e90d120 | 301 | break; |
nyatla | 2:b96c1e90d120 | 302 | case NyLPC_TcMiMicVM_OP_TYPE_EXIT: |
nyatla | 2:b96c1e90d120 | 303 | *o_code=NyLPC_cMiMicVM_RESULT_OK;//OKに上書き |
nyatla | 2:b96c1e90d120 | 304 | return 0; |
nyatla | 2:b96c1e90d120 | 305 | default: |
nyatla | 2:b96c1e90d120 | 306 | NyLPC_OnErrorGoto(ERROR); |
nyatla | 2:b96c1e90d120 | 307 | } |
nyatla | 2:b96c1e90d120 | 308 | //実行したコードのワード長を返す。 |
nyatla | 2:b96c1e90d120 | 309 | switch(ist->op.oprtype){ |
nyatla | 2:b96c1e90d120 | 310 | case NyLPC_TcMiMicVM_OPR_TYPE_NONE: |
nyatla | 2:b96c1e90d120 | 311 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_WM: |
nyatla | 2:b96c1e90d120 | 312 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H08: |
nyatla | 2:b96c1e90d120 | 313 | case NyLPC_TcMiMicVM_OPR_TYPE_WM: |
nyatla | 2:b96c1e90d120 | 314 | case NyLPC_TcMiMicVM_OPR_TYPE_H08: |
nyatla | 2:b96c1e90d120 | 315 | case NyLPC_TcMiMicVM_OPR_TYPE_H16: |
nyatla | 2:b96c1e90d120 | 316 | *o_code=NyLPC_cMiMicVM_RESULT_OK;//OKに上書き |
nyatla | 2:b96c1e90d120 | 317 | return 1; |
nyatla | 2:b96c1e90d120 | 318 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H16: |
nyatla | 2:b96c1e90d120 | 319 | case NyLPC_TcMiMicVM_OPR_TYPE_WM_H32: |
nyatla | 2:b96c1e90d120 | 320 | case NyLPC_TcMiMicVM_OPR_TYPE_H32: |
nyatla | 2:b96c1e90d120 | 321 | *o_code=NyLPC_cMiMicVM_RESULT_OK;//OKに上書き |
nyatla | 2:b96c1e90d120 | 322 | return 2; |
nyatla | 2:b96c1e90d120 | 323 | } |
nyatla | 2:b96c1e90d120 | 324 | ERROR: |
nyatla | 2:b96c1e90d120 | 325 | *o_code=NyLPC_cMiMicVM_RESULT_RUNTIME_NG;//ランタイムNG |
nyatla | 2:b96c1e90d120 | 326 | ERROR_INHERIT: |
nyatla | 2:b96c1e90d120 | 327 | return 0; |
nyatla | 2:b96c1e90d120 | 328 | } |
nyatla | 2:b96c1e90d120 | 329 | |
nyatla | 2:b96c1e90d120 | 330 | #define TEST |
nyatla | 2:b96c1e90d120 | 331 | #ifndef TEST |
nyatla | 2:b96c1e90d120 | 332 | |
nyatla | 2:b96c1e90d120 | 333 | #include "NyLPC_cMiMicTxtCompiler.h" |
nyatla | 2:b96c1e90d120 | 334 | void main(void) |
nyatla | 2:b96c1e90d120 | 335 | { |
nyatla | 2:b96c1e90d120 | 336 | struct NyLPC_TcMiMicVM_TEvent eh; |
nyatla | 2:b96c1e90d120 | 337 | NyLPC_TUInt32 ap; |
nyatla | 2:b96c1e90d120 | 338 | NyLPC_TcMiMicVM_t vm; |
nyatla | 2:b96c1e90d120 | 339 | struct NyLPC_TCharArrayPtr bc; |
nyatla | 2:b96c1e90d120 | 340 | NyLPC_TcMiMicTxtCompiler_t inst; |
nyatla | 2:b96c1e90d120 | 341 | struct NyLPC_TUInt32ArrayPtr bin; |
nyatla | 2:b96c1e90d120 | 342 | char BC[1024]; |
nyatla | 2:b96c1e90d120 | 343 | int ist_len; |
nyatla | 2:b96c1e90d120 | 344 | |
nyatla | 2:b96c1e90d120 | 345 | NyLPC_TUInt16 l,bl; |
nyatla | 2:b96c1e90d120 | 346 | NyLPC_TUInt32 obuf[1024]; |
nyatla | 2:b96c1e90d120 | 347 | NyLPC_cMiMicBcCompiler_initialize(&inst); |
nyatla | 2:b96c1e90d120 | 348 | sprintf(BC,"AA0102AB0100000001AE0203AF0200000003AI0304AJ0300000004AM07BA0505BE0607CA0304CB0300000005CE0304CF0300000005CI0304CJ0300000005ZA.E",&ap,&ap); |
nyatla | 2:b96c1e90d120 | 349 | bc.ptr=(char* )BC; |
nyatla | 2:b96c1e90d120 | 350 | bc.len=strlen(BC); |
nyatla | 2:b96c1e90d120 | 351 | bin.ptr=obuf; |
nyatla | 2:b96c1e90d120 | 352 | bin.len=100; |
nyatla | 2:b96c1e90d120 | 353 | ist_len=0; |
nyatla | 2:b96c1e90d120 | 354 | |
nyatla | 2:b96c1e90d120 | 355 | for(;;){ |
nyatla | 2:b96c1e90d120 | 356 | |
nyatla | 2:b96c1e90d120 | 357 | switch(NyLPC_cMiMicBcCompiler_compileFragment(&inst,&bc,&bin,&bl,&l)) |
nyatla | 2:b96c1e90d120 | 358 | { |
nyatla | 2:b96c1e90d120 | 359 | case NyLPC_TcMiMicTxtCompiler_RET_OK: |
nyatla | 2:b96c1e90d120 | 360 | //命令確定。 |
nyatla | 2:b96c1e90d120 | 361 | NyLPC_TCharArrayPtr_seek(&bc,l); |
nyatla | 2:b96c1e90d120 | 362 | ist_len+=bl; |
nyatla | 2:b96c1e90d120 | 363 | break; |
nyatla | 2:b96c1e90d120 | 364 | case NyLPC_TcMiMicTxtCompiler_RET_OK_END: |
nyatla | 2:b96c1e90d120 | 365 | //命令終端 |
nyatla | 2:b96c1e90d120 | 366 | NyLPC_cMiMicVM_initialize(&vm,&eh); |
nyatla | 2:b96c1e90d120 | 367 | if(!NyLPC_cMiMicVM_run(&vm,obuf,ist_len)){ |
nyatla | 2:b96c1e90d120 | 368 | printf("エンダァ"); |
nyatla | 2:b96c1e90d120 | 369 | } |
nyatla | 2:b96c1e90d120 | 370 | printf("OK"); |
nyatla | 2:b96c1e90d120 | 371 | break; |
nyatla | 2:b96c1e90d120 | 372 | case NyLPC_TcMiMicTxtCompiler_RET_CONTINUE: |
nyatla | 2:b96c1e90d120 | 373 | //蓄積中。 |
nyatla | 2:b96c1e90d120 | 374 | NyLPC_TCharArrayPtr_seek(&bc,l); |
nyatla | 2:b96c1e90d120 | 375 | break; |
nyatla | 2:b96c1e90d120 | 376 | case NyLPC_TcMiMicTxtCompiler_RET_NG: |
nyatla | 2:b96c1e90d120 | 377 | printf("エラー"); |
nyatla | 2:b96c1e90d120 | 378 | return; |
nyatla | 2:b96c1e90d120 | 379 | default: |
nyatla | 2:b96c1e90d120 | 380 | break; |
nyatla | 2:b96c1e90d120 | 381 | } |
nyatla | 2:b96c1e90d120 | 382 | } |
nyatla | 2:b96c1e90d120 | 383 | } |
nyatla | 2:b96c1e90d120 | 384 | #endif |