Changeset 22626
- Timestamp:
- 11/03/08 18:38:22 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/hsp-on-js/branches/source-convert/src/evaluator.js
r22575 r22626 67 67 lines.push(Utils.strTimes('\t', indent) + line); 68 68 } 69 function pushJumpSubroutineCode(posExpr) { 70 push('if(self.frameStack.length >= 256) {'); 71 push(' throw new HSPError(ErrorCode.STACK_OVERFLOW);'); 72 push('}'); 73 push('self.frameStack.push(new Frame(self.pc + 1, null, null));'); 74 push('self.pc = '+posExpr+';'); 75 } 69 76 var lines = []; 70 77 var indent = 0; 71 78 var sequence = this.sequence; 72 var operateMethodNames = 'add,sub,mul,div,mod,and,or,xor,eq,ne,gt,lt,gteq,lteq,rsh,lsh'.split(','); 79 var operateMethodNames = 'add,sub,mul,div,mod,and,or,xor,eq,ne,gt,lt,gteq,lteq,rsh,lsh'.split(','); 80 73 81 push('for(;;) {'); indent ++; 74 82 push('switch(self.pc) {'); … … 115 123 break; 116 124 case Instruction.Code.GOTO: 117 push('self.pc = '+(insn.opts[0].pos - 1)+';'); 125 push('self.pc = '+insn.opts[0].pos+';'); 126 push('continue;'); 118 127 break; 119 128 case Instruction.Code.IFNE: 120 129 push('if(stack.pop().toIntValue()._value) {'); 121 push(' self.pc = '+(insn.opts[0].pos - 1)+';'); 130 push(' self.pc = '+insn.opts[0].pos+';'); 131 push(' continue;'); 122 132 push('}'); 123 133 break; 124 134 case Instruction.Code.IFEQ: 125 135 push('if(!stack.pop().toIntValue()._value) {'); 126 push(' self.pc = '+(insn.opts[0].pos - 1)+';'); 136 push(' self.pc = '+insn.opts[0].pos+';'); 137 push(' continue;'); 127 138 push('}'); 128 139 break; … … 180 191 push('self.callUserDefFunc(userDefFuncs['+userDefFunc.id+'], '+ 181 192 'Utils.aryPopN(stack, '+argc+'));'); 193 push('self.pc ++;'); 194 push('continue;'); 182 195 break; 183 196 case Instruction.Code.GETARG: … … 222 235 } 223 236 push('self.callUserDefFunc(userDefFuncs['+module.constructor.id+'], args);'); 237 push('self.pc ++;'); 238 push('continue;'); 224 239 } else if(argc > 1) { 225 240 push('throw new HSPError(ErrorCode.TOO_MANY_PARAMETERS);') … … 232 247 push('self.return_();'); 233 248 } 249 push('self.pc ++;'); 250 push('continue;'); 234 251 break; 235 252 case Instruction.Code.DELMOD: … … 239 256 push('}'); 240 257 push('self.deleteStruct(v);'); 258 push('self.pc ++;'); 259 push('continue;'); 241 260 break; 242 261 case Instruction.Code.REPEAT: … … 257 276 push('var end = Infinity;'); 258 277 } 259 push('if(end == 0) {'); indent ++;260 push(' self.pc = '+(pos - 1)+';');261 push(' break;');262 indent --;push('}');278 push('if(end == 0) {'); 279 push(' self.pc = '+pos+';'); 280 push(' continue;'); 281 push('}'); 263 282 push('end += begin;'); 264 283 push('self.loopStack.push(new LoopData(begin, end, '+(pc + 1)+'));'); … … 270 289 push('var data = self.loopStack[self.loopStack.length - 1];'); 271 290 push('data.cnt ++;'); 272 push('if(data.cnt >= data.end) {'); indent ++; 291 push('if(data.cnt < data.end) {'); 292 push(' self.pc = data.pc;'); 293 push(' continue;'); 294 push('}'); 273 295 push('self.loopStack.pop();'); 274 push('break;');275 indent --; push('}');276 push('self.pc = data.pc - 1;');277 296 break; 278 297 case Instruction.Code.CNT: 279 298 push('if(self.loopStack.length == 0) {'); 280 299 push(' stack.push(new IntValue(0));'); 281 push(' break;');282 push(' }');283 push(' stack.push(new IntValue(self.loopStack[self.loopStack.length - 1].cnt));');300 push('} else {'); 301 push(' stack.push(new IntValue(self.loopStack[self.loopStack.length - 1].cnt));'); 302 push('}'); 284 303 break; 285 304 case Instruction.Code.CONTINUE: … … 298 317 push('if('+newCntExpr+' >= data.end) {'); 299 318 push(' self.loopStack.pop();'); 300 push(' self.pc = ' + (label.pos - 1)+';'); 301 push(' break;'); 302 push('}'); 303 push('self.pc = data.pc - 1;'); 319 push(' self.pc = '+pos+';'); 320 push('} else {'); 321 push(' self.pc = data.pc;'); 322 push('}'); 323 push('continue;'); 304 324 break; 305 325 case Instruction.Code.BREAK: … … 309 329 push('}'); 310 330 push('self.loopStack.pop();'); 311 push('self.pc = '+(label.pos - 1)+';'); 331 push('self.pc = '+label.pos+';'); 332 push('continue;'); 312 333 break; 313 334 case Instruction.Code.FOREACH: … … 326 347 push('if(data.cnt >= v.variable.getL0()) {') 327 348 push(' self.loopStack.pop();'); 328 push(' self.pc = '+ (pos - 1)+';');329 push(' break;');349 push(' self.pc = '+pos+';'); 350 push(' continue;'); 330 351 push('}'); 331 352 push('if(v.variable.at([data.cnt]).isUsing() == false) {'); // label 型 や struct 型の empty を飛ばす … … 333 354 push(' if(data.cnt >= data.end) {'); 334 355 push(' self.loopStack.pop();'); 335 push(' self.pc = '+(pos - 1)+';'); 336 push(' break;'); 356 push(' self.pc = '+pos+';'); 357 push(' } else {'); 358 push(' self.pc = data.pc - 1;'); 337 359 push(' }'); 338 push(' self.pc = data.pc - 1;');360 push(' continue;'); 339 361 push('}'); 340 362 break; 341 363 case Instruction.Code.GOSUB: 342 push('self.subroutineJump('+insn.opts[0].pos+');'); 364 pushJumpSubroutineCode(insn.opts[0].pos); 365 push('continue;'); 343 366 break; 344 367 case Instruction.Code.GOTO_EXPR: 345 push('self.pc = self.scanArg(stack.pop(), "l").toValue().pos - 1;'); 368 push('self.pc = self.scanArg(stack.pop(), "l").toValue().pos;'); 369 push('continue;'); 346 370 break; 347 371 case Instruction.Code.GOSUB_EXPR: 348 push('self.subroutineJump(self.scanArg(stack.pop(), "l").toValue().pos);'); 372 pushJumpSubroutineCode('self.scanArg(stack.pop(), "l").toValue().pos'); 373 push('continue;'); 349 374 break; 350 375 case Instruction.Code.EXGOTO: … … 354 379 push('var a = self.scanArg(self.scanArg(stack.pop(), "v"), "i").toIntValue()._value;'); 355 380 push('if(mode >= 0) {'); 356 push(' if(a >= b) self.pc = pos - 1;');381 push(' if(a >= b) { self.pc = pos; continue; }'); 357 382 push('} else {'); 358 push(' if(a <= b) self.pc = pos - 1;');383 push(' if(a <= b) { self.pc = pos; continue; }'); 359 384 push('}'); 360 385 break; … … 365 390 push('var mode = self.scanArg(stack.pop(), "n").toIntValue()._value;'); 366 391 push('if(mode >= 0) {'); 367 push(' if(a >= b) self.pc = '+(pos - 1)+';');392 push(' if(a >= b) { self.pc = '+pos+'; continue; }'); 368 393 push('} else {'); 369 push(' if(a <= b) self.pc = '+(pos - 1)+';');394 push(' if(a <= b) { self.pc = '+pos+'; continue; }'); 370 395 push('}'); 371 396 break; … … 374 399 push('var a = self.scanArg(variables['+insn.opts[0]+'].at(0), "i").toIntValue()._value;'); 375 400 push('var b = self.scanArg(stack.pop(), "n").toIntValue()._value;'); 376 push('if(a >= b) self.pc = '+(pos - 1)+';');401 push('if(a >= b) { self.pc = '+pos+'; continue; }'); 377 402 break; 378 403 case Instruction.Code.EXGOTO_OPT3: … … 380 405 push('var a = self.scanArg(variables['+insn.opts[0]+'].at(0), "i").toIntValue()._value;'); 381 406 push('var b = self.scanArg(stack.pop(), "n").toIntValue()._value;'); 382 push('if(a <= b) self.pc = '+(pos - 1)+';');407 push('if(a <= b) { self.pc = '+pos+'; continue; }'); 383 408 break; 384 409 case Instruction.Code.ON: … … 394 419 push('stack.length -= '+(argc + 1)+';'); 395 420 if(isGosub) { 396 push('self.subroutineJump(pos);'); 421 pushJumpSubroutineCode('pos'); 422 push('continue;'); 397 423 } else { 398 push('self.pc = pos - 1;'); 424 push('self.pc = pos;'); 425 push('continue;'); 399 426 } 400 427 break; … … 402 429 throw new Error("未対応の命令コード: "+insn.code); 403 430 } 404 push(' break;');431 push('self.pc ++;'); 405 432 indent --; 406 433 } 407 434 push('}'); 408 push('self.pc ++;');409 435 indent --; push('}'); 410 436 //print(lines.join("\n")); … … 519 545 runCallback(); 520 546 } 521 },522 subroutineJump: function subroutineJump(pos) {523 if(this.frameStack.length >= 256) {524 throw new HSPError(ErrorCode.STACK_OVERFLOW);525 }526 this.frameStack.push(new Frame(this.pc + 1, null, null));527 this.pc = pos - 1;528 547 }, 529 548 popIndices: function popIndices(argc) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)