Changeset 29704
- Timestamp:
- 02/08/09 20:20:16 (4 years ago)
- Location:
- lang/javascript/hsp-on-js/trunk/src
- Files:
-
- 8 modified
- 1 moved
-
compiler.js (modified) (30 diffs)
-
create-package (modified) (1 diff)
-
evaluator.js (modified) (22 diffs)
-
instruction.js (modified) (2 diffs)
-
label-array.js (modified) (3 diffs)
-
label-value.js (moved) (moved from lang/javascript/hsp-on-js/trunk/src/label.js) (2 diffs, 1 prop)
-
param-info.js (modified) (3 diffs)
-
run-in-shell (modified) (1 diff)
-
run-in-shell.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/hsp-on-js/trunk/src/compiler.js
r28714 r29704 67 67 Compiler.prototype = { 68 68 compile: function() { 69 var sequence = [];69 var sequence = new ISeq; 70 70 while(this.tokensPos < this.ax.tokens.length) { 71 71 var token = this.ax.tokens[this.tokensPos]; … … 73 73 throw this.error(); 74 74 } 75 var labelIDs = this.ax.labelsMap[token.pos]; 76 if(labelIDs) { 77 for(var i = 0; i < labelIDs.length; i ++) { 78 var labelID = labelIDs[i]; 79 this.labels[labelID].pos = sequence.length; 80 } 81 } 82 var labels = this.ifLabels[token.pos]; 83 if(labels) { 84 for(var i = 0; i < labels.length; i ++) { 85 labels[i].pos = sequence.length; 86 } 87 } 88 switch(token.type) { 89 case Token.Type.VAR: 90 case Token.Type.STRUCT: 91 this.compileAssignment(sequence); 92 break; 93 case Token.Type.CMPCMD: 94 this.compileBranchCommand(sequence); 95 break; 96 case Token.Type.PROGCMD: 97 this.compileProgramCommand(sequence); 98 break; 99 case Token.Type.MODCMD: 100 this.compileUserDefCommand(sequence); 101 break; 102 case Token.Type.INTCMD: 103 this.compileBasicCommand(sequence); 104 break; 105 case Token.Type.EXTCMD: 106 this.compileGuiCommand(sequence); 107 break; 108 case Token.Type.DLLFUNC: 109 case Token.Type.DLLCTRL: 110 this.compileCommand(sequence); 111 break; 112 default: 113 throw this.error("命令コード " + token.type + " は解釈できません。"); 114 } 115 } 116 return sequence; 75 this.pushLabels(sequence, token.pos); 76 this.compileStatement(sequence); 77 } 78 this.defineInsnIndex(sequence); 79 this.defineLabelPos(sequence); 80 var result = this.sequenceToArray(sequence); 81 this.deleteLink(sequence); 82 return result; 83 }, 84 pushLabels: function(sequence, pos) { 85 var labelIDs = this.ax.labelsMap[pos]; 86 if(labelIDs) { 87 for(var i = 0; i < labelIDs.length; i ++) { 88 var labelID = labelIDs[i]; 89 sequence.push(this.labels[labelID]); 90 } 91 } 92 var labels = this.ifLabels[pos]; 93 if(labels) { 94 for(var i = 0; i < labels.length; i ++) { 95 sequence.push(labels[i]); 96 } 97 } 98 delete this.ifLabels[pos]; 99 }, 100 defineInsnIndex: function(sequence) { 101 var index = 0; 102 sequence.forEachOnlyInsn(function(insn) { 103 insn.index = index++; 104 }); 105 }, 106 defineLabelPos: function(sequence) { 107 sequence.forEach(function(elem) { 108 if(elem.type != ISeqElem.Type.LABEL) return; 109 elem.definePos(); 110 }); 111 }, 112 sequenceToArray: function(sequence) { 113 var result = []; 114 sequence.forEachOnlyInsn(function(insn) { 115 result.push(insn); 116 }); 117 return result; 118 }, 119 deleteLink: function(sequence) { 120 var elem = sequence.first(); 121 while(elem) { 122 var next = elem.next; 123 elem.next = elem.prev = null; 124 elem = next; 125 } 126 ISeq.link(sequence.firstGuard, sequence.lastGuard); 117 127 }, 118 128 pushNewInsn: function(sequence, code, opts, token) { 119 token || (token = this.ax.tokens[this.tokensPos]);120 sequence.push(new Ins truction(code, opts, token.fileName, token.lineNo));129 if(!token) token = this.ax.tokens[this.tokensPos]; 130 sequence.push(new Insn(code, opts, token.fileName, token.lineNo)); 121 131 }, 122 132 getFinfoIdByMinfoId: function(minfoId) { … … 131 141 }, 132 142 error: function(message, token) { 133 token || (token = this.ax.tokens[this.tokensPos]);143 if(!token) token = this.ax.tokens[this.tokensPos]; 134 144 return new CompileError(message, token.fileName, token.lineNo); 145 }, 146 compileStatement: function(sequence) { 147 var token = this.ax.tokens[this.tokensPos]; 148 switch(token.type) { 149 case Token.Type.VAR: 150 case Token.Type.STRUCT: 151 this.compileAssignment(sequence); 152 break; 153 case Token.Type.CMPCMD: 154 this.compileBranchCommand(sequence); 155 break; 156 case Token.Type.PROGCMD: 157 this.compileProgramCommand(sequence); 158 break; 159 case Token.Type.MODCMD: 160 this.compileUserDefCommand(sequence); 161 break; 162 case Token.Type.INTCMD: 163 this.compileBasicCommand(sequence); 164 break; 165 case Token.Type.EXTCMD: 166 this.compileGuiCommand(sequence); 167 break; 168 case Token.Type.DLLFUNC: 169 case Token.Type.DLLCTRL: 170 this.compileCommand(sequence); 171 break; 172 default: 173 throw this.error("命令コード " + token.type + " は解釈できません。"); 174 } 135 175 }, 136 176 compileAssignment: function(sequence) { … … 146 186 // インクリメント / デクリメント 147 187 var indexParamInfos = this.compileNodes(sequence, indexNodes); 148 this.pushNewInsn(sequence, Ins truction.Code.INC + token.val, [varData, indexParamInfos], token);188 this.pushNewInsn(sequence, Insn.Code.INC + token.val, [varData, indexParamInfos], token); 149 189 return; 150 190 } … … 156 196 throw this.error("複合代入のパラメータの数が間違っています。", token); 157 197 } 158 this.pushNewInsn(sequence, Ins truction.Code.COMPOUND_ASSIGN, [token.val, varData, indexParamInfos, rhsParamInfos[0]], token);198 this.pushNewInsn(sequence, Insn.Code.COMPOUND_ASSIGN, [token.val, varData, indexParamInfos, rhsParamInfos[0]], token); 159 199 return; 160 200 } … … 162 202 throw this.error("代入のパラメータの数が間違っています。", token); 163 203 } 164 this.pushNewInsn(sequence, Ins truction.Code.ASSIGN, [varData, indexParamInfos, rhsParamInfos], token);204 this.pushNewInsn(sequence, Insn.Code.ASSIGN, [varData, indexParamInfos, rhsParamInfos], token); 165 205 }, 166 206 compileProgramCommand: function(sequence) { … … 170 210 var labelToken = this.ax.tokens[this.tokensPos + 1]; 171 211 if(labelToken && labelToken.type == Token.Type.LABEL && !labelToken.ex2 && (!this.ax.tokens[this.tokensPos + 2] || this.ax.tokens[this.tokensPos + 2].ex1)) { 172 this.pushNewInsn(sequence, Ins truction.Code.GOTO,212 this.pushNewInsn(sequence, Insn.Code.GOTO, 173 213 [this.labels[labelToken.code]]); 174 214 this.tokensPos += 2; … … 177 217 var paramInfos = this.compileParameters(sequence); 178 218 if(paramInfos.length != 1) throw this.error('goto の引数の数が違います', token); 179 this.pushNewInsn(sequence, Ins truction.Code.GOTO_EXPR, [paramInfos[0]], token);219 this.pushNewInsn(sequence, Insn.Code.GOTO_EXPR, [paramInfos[0]], token); 180 220 } 181 221 break; … … 183 223 var labelToken = this.ax.tokens[this.tokensPos + 1]; 184 224 if(labelToken && labelToken.type == Token.Type.LABEL && !labelToken.ex2 && (!this.ax.tokens[this.tokensPos + 2] || this.ax.tokens[this.tokensPos + 2].ex1)) { 185 this.pushNewInsn(sequence, Ins truction.Code.GOSUB,225 this.pushNewInsn(sequence, Insn.Code.GOSUB, 186 226 [this.labels[labelToken.code]]); 187 227 this.tokensPos += 2; … … 190 230 var paramInfos = this.compileParameters(sequence); 191 231 if(paramInfos.length != 1) throw this.error('gosub の引数の数が違います', token); 192 this.pushNewInsn(sequence, Ins truction.Code.GOSUB_EXPR, [paramInfos[0]], token);232 this.pushNewInsn(sequence, Insn.Code.GOSUB_EXPR, [paramInfos[0]], token); 193 233 } 194 234 break; … … 202 242 if(this.getParametersNodesSub().length > 0) throw this.error('return の引数が多すぎます', token); 203 243 } 204 this.pushNewInsn(sequence, Ins truction.Code.RETURN, [paramInfo], token);244 this.pushNewInsn(sequence, Insn.Code.RETURN, [paramInfo], token); 205 245 break; 206 246 case 0x03: // break … … 211 251 } 212 252 if(this.getParametersNodes().length > 0) throw this.error('break の引数が多すぎます', token); 213 this.pushNewInsn(sequence, Ins truction.Code.BREAK,253 this.pushNewInsn(sequence, Insn.Code.BREAK, 214 254 [this.labels[labelToken.code]], token); 215 255 break; … … 222 262 var paramInfos = this.compileParameters(sequence, false, false, paramInfos); 223 263 if(paramInfos.length > 2) throw this.error('repeat の引数が多すぎます', token); 224 this.pushNewInsn(sequence, Ins truction.Code.REPEAT,264 this.pushNewInsn(sequence, Insn.Code.REPEAT, 225 265 [this.labels[labelToken.code], paramInfos], token); 226 266 break; … … 228 268 this.tokensPos ++; 229 269 if(this.getParametersNodes().length > 0) throw this.error('loop の引数が多すぎます', token); 230 this.pushNewInsn(sequence, Ins truction.Code.LOOP, [], token);270 this.pushNewInsn(sequence, Insn.Code.LOOP, [], token); 231 271 break; 232 272 case 0x06: // continue … … 238 278 var paramInfos = this.compileParameters(sequence); 239 279 if(paramInfos.length > 1) throw this.error('continue の引数が多すぎます', token); 240 this.pushNewInsn(sequence, Ins truction.Code.CONTINUE,280 this.pushNewInsn(sequence, Insn.Code.CONTINUE, 241 281 [this.labels[labelToken.code], paramInfos[0]], token); 242 282 break; … … 248 288 } 249 289 if(this.getParametersNodes().length > 0) throw this.error(); 250 this.pushNewInsn(sequence, Ins truction.Code.FOREACH,290 this.pushNewInsn(sequence, Insn.Code.FOREACH, 251 291 [this.labels[labelToken.code]], token); 252 292 break; … … 259 299 var paramInfos = this.compileParameters(sequence); 260 300 if(paramInfos.length != 1) throw this.error('foreach の引数の数が違います', token); 261 this.pushNewInsn(sequence, Ins truction.Code.EACHCHK,301 this.pushNewInsn(sequence, Insn.Code.EACHCHK, 262 302 [this.labels[labelToken.code], paramInfos[0]], token); 263 303 break; … … 282 322 argc = this.getParametersNodesSub().length; 283 323 } 284 this.pushNewInsn(sequence, Ins truction.Code.NEWMOD,324 this.pushNewInsn(sequence, Insn.Code.NEWMOD, 285 325 [this.compileNode(sequence, varNode), module, paramInfos, argc], token); 286 326 break; … … 289 329 var paramInfos = this.compileParameters(sequence, false, true); 290 330 if(paramInfos.length != 4) throw this.error('exgoto の引数の数が違います', token); 291 this.pushNewInsn(sequence, Ins truction.Code.EXGOTO, [paramInfos], token);331 this.pushNewInsn(sequence, Insn.Code.EXGOTO, [paramInfos], token); 292 332 break; 293 333 case 0x19: // on … … 305 345 this.tokensPos ++; 306 346 var labelParamInfos = this.compileParametersSub(sequence); 307 this.pushNewInsn(sequence, Ins truction.Code.ON, [isGosub, labelParamInfos, indexParamInfo], token);347 this.pushNewInsn(sequence, Insn.Code.ON, [isGosub, labelParamInfos, indexParamInfo], token); 308 348 break; 309 349 default: … … 322 362 var paramInfos = [this.compileOptionalJumpType(sequence)]; 323 363 this.compileParameters(sequence, false, false, paramInfos); 324 this.pushNewInsn(sequence, Ins truction.Code.CALL_BUILTIN_CMD,364 this.pushNewInsn(sequence, Insn.Code.CALL_BUILTIN_CMD, 325 365 [token.type, token.code, paramInfos], token); 326 366 break; … … 336 376 var paramInfos = [this.compileOptionalJumpType(sequence)]; 337 377 this.compileParameters(sequence, false, false, paramInfos); 338 this.pushNewInsn(sequence, Ins truction.Code.CALL_BUILTIN_CMD,378 this.pushNewInsn(sequence, Insn.Code.CALL_BUILTIN_CMD, 339 379 [token.type, token.code, paramInfos], token); 340 380 break; … … 346 386 var token = this.ax.tokens[this.tokensPos++]; 347 387 var paramInfos = this.compileParameters(sequence); 348 this.pushNewInsn(sequence, Ins truction.Code.CALL_BUILTIN_CMD,388 this.pushNewInsn(sequence, Insn.Code.CALL_BUILTIN_CMD, 349 389 [token.type, token.code, paramInfos], token); 350 390 }, … … 367 407 (node.val.getType() == VarType.INT || node.val.getType() == VarType.DOUBLE)) { 368 408 if(!node.val._value) { 369 this.pushNewInsn(sequence, Ins truction.Code.GOTO, [label], token);409 this.pushNewInsn(sequence, Insn.Code.GOTO, [label], token); 370 410 } 371 411 return; 372 412 } 373 this.pushNewInsn(sequence, Ins truction.Code.IFEQ, [label, paramInfo], token);413 this.pushNewInsn(sequence, Insn.Code.IFEQ, [label, paramInfo], token); 374 414 } else { 375 415 if(nodes.length != 0) throw this.error("else の引数の数が間違っています。", token); 376 this.pushNewInsn(sequence, Ins truction.Code.GOTO, [label], token);416 this.pushNewInsn(sequence, Insn.Code.GOTO, [label], token); 377 417 } 378 418 }, … … 415 455 stackSize ++; 416 456 self.pushNewInsn(sequence, 417 node.onlyValue ? Ins truction.Code.GET_VAR : Instruction.Code.PUSH_VAR,457 node.onlyValue ? Insn.Code.GET_VAR : Insn.Code.PUSH_VAR, 418 458 [node.varData, self.compileNodes(sequence, node.indexNodes)], 419 459 node.token); … … 423 463 break; 424 464 case NodeType.LITERAL: 465 break; 466 case NodeType.LABEL: 425 467 break; 426 468 case NodeType.DEFAULT: … … 435 477 var paramInfos = self.compileNodes(sequence, node.paramNodes); 436 478 self.pushNewInsn(sequence, 437 Ins truction.Code.CALL_USERDEF_FUNC,479 Insn.Code.CALL_USERDEF_FUNC, 438 480 [node.userDefFunc, paramInfos], 439 481 node.token); … … 444 486 var paramInfos = self.compileNodes(sequence, node.paramNodes); 445 487 if(node.groupId == Token.Type.SYSVAR && node.subId == 0x04) { 446 self.pushNewInsn(sequence, Ins truction.Code.CNT, [], node.token);488 self.pushNewInsn(sequence, Insn.Code.CNT, [], node.token); 447 489 break; 448 490 } 449 491 self.pushNewInsn(sequence, 450 Ins truction.Code.CALL_BUILTIN_FUNC,492 Insn.Code.CALL_BUILTIN_FUNC, 451 493 [node.groupId, node.subId, paramInfos], 452 494 node.token); … … 530 572 break; 531 573 case Token.Type.LABEL: 532 stack.push(new L iteralNode(this.labels[token.code]));574 stack.push(new LabelNode(this.labels[token.code])); 533 575 this.tokensPos ++; 534 576 break; … … 698 740 var userDefFunc = this.getUserDefFunc(token.code); 699 741 var paramInfos = this.compileNodes(sequence, this.getUserDefFuncallParamNodes(userDefFunc, false, true)); 700 this.pushNewInsn(sequence, Ins truction.Code.CALL_USERDEF_CMD,742 this.pushNewInsn(sequence, Insn.Code.CALL_USERDEF_CMD, 701 743 [userDefFunc, paramInfos], token); 702 744 }, -
lang/javascript/hsp-on-js/trunk/src/create-package
r28263 r29704 26 26 vartype.js 27 27 value.js 28 label .js28 label-value.js 29 29 str-value.js 30 30 double-value.js -
lang/javascript/hsp-on-js/trunk/src/evaluator.js
r29399 r29704 396 396 push('this.frameStack.push(new Frame('+(pc + 1)+', userDefFuncs['+userDefFunc.id+'], args, this.args));'); 397 397 push('this.args = args;'); 398 push('this.pc = '+userDefFunc.label. pos+';');398 push('this.pc = '+userDefFunc.label.getPos()+';'); 399 399 } 400 400 function pushCallingUserdefFuncCode0(mptypes, paramInfos, constructorThismodExpr) { … … 547 547 case NodeType.LITERAL: 548 548 return getLiteralExpr(node.val); 549 case NodeType.LABEL: 550 return getLiteralExpr(new LabelValue(node.getLabelPos())); 549 551 case NodeType.DEFAULT: 550 552 return 'throwHSPError('+ErrorCode.NO_DEFAULT+')'; … … 637 639 function getLabelParamNativeValueExpr(paramInfo) { 638 640 var node = paramInfo.node; 639 if(node.isL iteralNode() && node.val.getType() == VarType.LABEL) {640 return '' + node. val.pos;641 if(node.isLabelNode()) { 642 return '' + node.getLabelPos(); 641 643 } 642 644 return 'this.scanArg('+getParamExpr(paramInfo)+', "l").toValue().pos'; … … 660 662 } 661 663 var insn2func = []; 662 insn2func[Ins truction.Code.NOP] = function(insn, pc) {663 }; 664 insn2func[Ins truction.Code.PUSH_VAR] = function(insn, pc) {664 insn2func[Insn.Code.NOP] = function(insn, pc) { 665 }; 666 insn2func[Insn.Code.PUSH_VAR] = function(insn, pc) { 665 667 var varData = insn.opts[0]; 666 668 var indexParamInfos = insn.opts[1]; 667 669 pushGettingVariableCode(varData, indexParamInfos); 668 670 }; 669 insn2func[Ins truction.Code.GET_VAR] = function(insn, pc) {671 insn2func[Insn.Code.GET_VAR] = function(insn, pc) { 670 672 var varData = insn.opts[0]; 671 673 var indexParamInfos = insn.opts[1]; 672 674 pushGettingArrayValueCode(varData, indexParamInfos); 673 675 }; 674 insn2func[Ins truction.Code.POP] = function(insn, pc) {676 insn2func[Insn.Code.POP] = function(insn, pc) { 675 677 push('stack.pop();'); 676 678 }; 677 insn2func[Ins truction.Code.POP_N] = function(insn, pc) {679 insn2func[Insn.Code.POP_N] = function(insn, pc) { 678 680 pushStackPopCode(insn.opts[0]); 679 681 }; 680 insn2func[Ins truction.Code.DUP] = function(insn, pc) {682 insn2func[Insn.Code.DUP] = function(insn, pc) { 681 683 push('stack.push(stack[stack.length-1]);'); 682 684 }; 683 insn2func[Ins truction.Code.GOTO] = function(insn, pc) {684 push('this.pc = '+insn.opts[0]. pos+';');685 insn2func[Insn.Code.GOTO] = function(insn, pc) { 686 push('this.pc = '+insn.opts[0].getPos()+';'); 685 687 push('continue;'); 686 688 }; 687 insn2func[Ins truction.Code.IFNE] =688 insn2func[Ins truction.Code.IFEQ] = function(insn, pc) {689 insn2func[Insn.Code.IFNE] = 690 insn2func[Insn.Code.IFEQ] = function(insn, pc) { 689 691 var label = insn.opts[0]; 690 692 var paramInfo = insn.opts[1]; 691 693 var expr = getParamExpr(paramInfo)+'.toIntValue()._value'; 692 if(insn.code == Ins truction.Code.IFEQ) {694 if(insn.code == Insn.Code.IFEQ) { 693 695 expr = '!' + expr; 694 696 } 695 697 push('if('+expr+') {'); 696 push(' this.pc = '+insn.opts[0]. pos+';');698 push(' this.pc = '+insn.opts[0].getPos()+';'); 697 699 push(' continue;'); 698 700 push('}'); 699 701 }; 700 insn2func[Ins truction.Code.ASSIGN] = function(insn, pc) {702 insn2func[Insn.Code.ASSIGN] = function(insn, pc) { 701 703 var varData = insn.opts[0]; 702 704 var indexParamInfos = insn.opts[1]; … … 704 706 pushAssignCode(varData, indexParamInfos, rhsParamInfos); 705 707 }; 706 insn2func[Ins truction.Code.COMPOUND_ASSIGN] = function(insn, pc) {708 insn2func[Insn.Code.COMPOUND_ASSIGN] = function(insn, pc) { 707 709 var calcCode = insn.opts[0]; 708 710 var varData = insn.opts[1]; … … 711 713 pushCompoundAssignCode(calcCode, varData, indexParamInfos, rhsParamInfo); 712 714 }; 713 insn2func[Ins truction.Code.INC] = function(insn, pc) {715 insn2func[Insn.Code.INC] = function(insn, pc) { 714 716 var varData = insn.opts[0]; 715 717 var indexParamInfos = insn.opts[1]; 716 718 pushIncCode(varData, indexParamInfos); 717 719 }; 718 insn2func[Ins truction.Code.DEC] = function(insn, pc) {720 insn2func[Insn.Code.DEC] = function(insn, pc) { 719 721 var varData = insn.opts[0]; 720 722 var indexParamInfos = insn.opts[1]; 721 723 pushDecCode(varData, indexParamInfos); 722 724 }; 723 insn2func[Ins truction.Code.CALL_BUILTIN_CMD] =724 insn2func[Ins truction.Code.CALL_BUILTIN_FUNC] = function(insn, pc) {725 insn2func[Insn.Code.CALL_BUILTIN_CMD] = 726 insn2func[Insn.Code.CALL_BUILTIN_FUNC] = function(insn, pc) { 725 727 var type = insn.opts[0]; 726 728 var subid = insn.opts[1]; … … 740 742 } 741 743 } 742 if(insn.code == Ins truction.Code.CALL_BUILTIN_FUNC) {744 if(insn.code == Insn.Code.CALL_BUILTIN_FUNC) { 743 745 push('stack.push(func.apply(this, args));'); 744 746 } else { … … 746 748 } 747 749 }; 748 insn2func[Ins truction.Code.CALL_USERDEF_CMD] =749 insn2func[Ins truction.Code.CALL_USERDEF_FUNC] = function(insn, pc) {750 insn2func[Insn.Code.CALL_USERDEF_CMD] = 751 insn2func[Insn.Code.CALL_USERDEF_FUNC] = function(insn, pc) { 750 752 var userDefFunc = insn.opts[0]; 751 753 var paramInfos = insn.opts[1]; … … 753 755 push('continue;'); 754 756 }; 755 insn2func[Ins truction.Code.NEWMOD] = function(insn, pc) {757 insn2func[Insn.Code.NEWMOD] = function(insn, pc) { 756 758 var varParamInfo = insn.opts[0]; 757 759 var module = insn.opts[1]; … … 780 782 } 781 783 }; 782 insn2func[Ins truction.Code.RETURN] = function(insn, pc) {784 insn2func[Insn.Code.RETURN] = function(insn, pc) { 783 785 var paramInfo = insn.opts[0]; 784 786 push('if(this.frameStack.length == 0) {'); … … 816 818 push('continue;'); 817 819 }; 818 insn2func[Ins truction.Code.REPEAT] = function(insn, pc) {819 var pos = insn.opts[0]. pos;820 insn2func[Insn.Code.REPEAT] = function(insn, pc) { 821 var pos = insn.opts[0].getPos(); 820 822 var paramInfos = insn.opts[1]; 821 823 push('if(this.loopStack.length >= 31) {'); … … 840 842 push('this.loopStack.push(new LoopData(begin, end, '+(pc + 1)+'));'); 841 843 }; 842 insn2func[Ins truction.Code.LOOP] = function(insn, pc) {844 insn2func[Insn.Code.LOOP] = function(insn, pc) { 843 845 push('if(this.loopStack.length == 0) {'); 844 846 push(' throw new HSPError(ErrorCode.LOOP_WITHOUT_REPEAT);'); … … 852 854 push('this.loopStack.pop();'); 853 855 }; 854 insn2func[Ins truction.Code.CNT] = function(insn, pc) {856 insn2func[Insn.Code.CNT] = function(insn, pc) { 855 857 push('if(this.loopStack.length == 0) {'); 856 858 push(' stack.push(new IntValue(0));'); … … 859 861 push('}'); 860 862 }; 861 insn2func[Ins truction.Code.CONTINUE] = function(insn, pc) {862 var pos = insn.opts[0]. pos;863 insn2func[Insn.Code.CONTINUE] = function(insn, pc) { 864 var pos = insn.opts[0].getPos(); 863 865 var paramInfo = insn.opts[1]; 864 866 push('if(this.loopStack.length == 0) {'); … … 880 882 push('continue;'); 881 883 }; 882 insn2func[Ins truction.Code.BREAK] = function(insn, pc) {884 insn2func[Insn.Code.BREAK] = function(insn, pc) { 883 885 var label = insn.opts[0]; 884 886 push('if(this.loopStack.length == 0) {'); … … 886 888 push('}'); 887 889 push('this.loopStack.pop();'); 888 push('this.pc = '+label. pos+';');890 push('this.pc = '+label.getPos()+';'); 889 891 push('continue;'); 890 892 }; 891 insn2func[Ins truction.Code.FOREACH] = function(insn, pc) {893 insn2func[Insn.Code.FOREACH] = function(insn, pc) { 892 894 push('if(this.loopStack.length >= 31) {'); 893 895 push(' throw new HSPError(ErrorCode.TOO_MANY_NEST);'); … … 895 897 push('this.loopStack.push(new LoopData(0, Infinity, '+(pc + 1)+'));'); 896 898 }; 897 insn2func[Ins truction.Code.EACHCHK] = function(insn, pc) {899 insn2func[Insn.Code.EACHCHK] = function(insn, pc) { 898 900 push('if(this.loopStack.length == 0) {'); 899 901 push(' throw new HSPError(ErrorCode.LOOP_WITHOUT_REPEAT);') 900 902 push('}') 901 var pos = insn.opts[0]. pos;903 var pos = insn.opts[0].getPos(); 902 904 var paramInfo = insn.opts[1]; 903 905 push('var array = '+getNoSubscriptVariableExpr(paramInfo)+'.value;'); … … 919 921 push('}'); 920 922 }; 921 insn2func[Ins truction.Code.GOSUB] = function(insn, pc) {923 insn2func[Insn.Code.GOSUB] = function(insn, pc) { 922 924 pushJumpingSubroutineCode(pc); 923 push('this.pc = '+insn.opts[0]. pos+';');925 push('this.pc = '+insn.opts[0].getPos()+';'); 924 926 push('continue;'); 925 927 }; 926 insn2func[Ins truction.Code.GOTO_EXPR] =927 insn2func[Ins truction.Code.GOSUB_EXPR] = function(insn, pc) {928 insn2func[Insn.Code.GOTO_EXPR] = 929 insn2func[Insn.Code.GOSUB_EXPR] = function(insn, pc) { 928 930 var paramInfo = insn.opts[0]; 929 if(insn.code == Ins truction.Code.GOSUB_EXPR) {931 if(insn.code == Insn.Code.GOSUB_EXPR) { 930 932 pushJumpingSubroutineCode(pc); 931 933 } … … 933 935 push('continue;'); 934 936 }; 935 insn2func[Ins truction.Code.EXGOTO] = function(insn, pc) {937 insn2func[Insn.Code.EXGOTO] = function(insn, pc) { 936 938 var paramInfos = insn.opts[0]; 937 939 var counterParamInfo = paramInfos[0]; … … 968 970 push('}'); 969 971 }; 970 insn2func[Ins truction.Code.ON] = function(insn, pc) {972 insn2func[Insn.Code.ON] = function(insn, pc) { 971 973 var isGosub = insn.opts[0]; 972 974 var labelParamInfos = insn.opts[1]; … … 976 978 for(var i = 0; i < labelParamInfos.length; i ++) { 977 979 var paramInfo = labelParamInfos[i]; 978 if(paramInfo.node.isL iteralNode() && paramInfo.node.val.getType() == VarType.LABEL) {979 labelExprs[i] = '' + paramInfo.node. val.pos;980 if(paramInfo.node.isLabelNode()) { 981 labelExprs[i] = '' + paramInfo.node.getLabelPos(); 980 982 } else { 981 983 if(labelsIndex == null) { … … 1119 1121 }, 1120 1122 getBuiltinFuncName: function(insn) { 1121 if(insn.code != Ins truction.Code.CALL_BUILTIN_CMD &&1122 insn.code != Ins truction.Code.CALL_BUILTIN_FUNC) {1123 if(insn.code != Insn.Code.CALL_BUILTIN_CMD && 1124 insn.code != Insn.Code.CALL_BUILTIN_FUNC) { 1123 1125 return undefined; 1124 1126 } -
lang/javascript/hsp-on-js/trunk/src/instruction.js
r28714 r29704 1 function Instruction(code, opts, fileName, lineNo) { 1 var ISeq; 2 var ISeqElem; 3 var Label; 4 var Insn; 5 var getInsnCodeName; 6 7 (function() { 8 9 ISeq = function() { 10 this.firstGuard = new ISeqElem; 11 this.lastGuard = new ISeqElem; 12 link(this.firstGuard, this.lastGuard); 13 } 14 15 function link() { 16 for(var i = 0; i < arguments.length - 1; i ++) { 17 var a = arguments[i]; 18 var b = arguments[i+1]; 19 if(a) a.next = b; 20 if(b) b.prev = a; 21 } 22 } 23 24 ISeq.link = link; 25 26 ISeq.prototype = { 27 first: function() { 28 return this.firstGuard.next; 29 }, 30 last: function() { 31 return this.lastGuard.prev; 32 }, 33 push: function(elem) { 34 link(this.last(), elem, this.lastGuard); 35 return this; 36 }, 37 pop: function() { 38 return this.last().remove(); 39 }, 40 shift: function() { 41 return this.first().remove(); 42 }, 43 unshift: function(elem) { 44 return this.first().insertBefore(elem); 45 }, 46 forEach: function(callback) { 47 var elem = this.first(); 48 var end = this.lastGuard; 49 while(elem != end) { 50 callback(elem); 51 elem = elem.next; 52 } 53 }, 54 forEachOnlyInsn: function(callback) { 55 var elem = this.first(); 56 while(elem) { 57 if(elem.type == ISeqElem.Type.INSN) { 58 callback(elem); 59 } 60 elem = elem.next; 61 } 62 }, 63 getLength: function() { 64 var length = 0; 65 this.forEach(function() { length ++; }); 66 return length; 67 }, 68 toString: function() { 69 return '<ISeq:len='+this.getLength()+'>'; 70 } 71 }; 72 73 ISeqElem = function() { 74 this.prev = null; 75 this.next = null; 76 }; 77 78 ISeqElem.Type = { 79 NONE: 0, 80 INSN: 1, 81 LABEL: 2 82 }; 83 84 ISeqElem.prototype = { 85 type: ISeqElem.Type.NONE, 86 remove: function() { 87 link(this.prev, this.next); 88 link(null, this, null); 89 return this; 90 }, 91 replace: function(insn) { 92 link(this.prev, insn, this.next); 93 link(null, this, null); 94 }, 95 insertAfter: function() { 96 var args = [this]; 97 args.push.apply(args, arguments); 98 args.push(this.next); 99 link.apply(null, args); 100 }, 101 insertBefore: function(insn) { 102 var args = [this.prev]; 103 args.push.apply(args, arguments); 104 args.push(this); 105 link.apply(null, args); 106 }, 107 getNextInsn: function() { 108 var elem = this.next; 109 while(elem) { 110 if(elem.type == ISeqElem.Type.INSN) { 111 return elem; 112 } 113 elem = elem.next; 114 } 115 return null; 116 }, 117 getPrevInsn: function() { 118 var elem = this.prev; 119 while(elem) { 120 if(elem.type == ISeqElem.Type.INSN) { 121 return elem; 122 } 123 elem = elem.prev; 124 } 125 return null; 126 }, 127 getNextElem: function() { 128 var elem = this.next; 129 while(elem) { 130 if(elem.type == ISeqElem.Type.INSN || elem.type == ISeqElem.Type.NONE) { 131 return elem; 132 } 133 elem = elem.next; 134 } 135 return null; 136 }, 137 getPrevElem: function() { 138 var elem = this.prev; 139 while(elem) { 140 if(elem.type == ISeqElem.Type.INSN || elem.type == ISeqElem.Type.NONE) { 141 return elem; 142 } 143 elem = elem.prev; 144 } 145 return null; 146 } 147 }; 148 149 Label = function() { 150 ISeqElem.call(this); 151 this.pos_ = -1; 152 }; 153 154 Label.prototype = new ISeqElem; 155 156 Utils.objectExtend(Label.prototype, { 157 toString: function() { 158 return '<Label:'+this.pos_+'>'; 159 }, 160 getInsn: function() { 161 return this.getNextInsn(); 162 }, 163 getPos: function() { 164 return this.pos_; 165 }, 166 definePos: function() { 167 this.pos_ = this.getInsn().index; 168 }, 169 type: ISeqElem.Type.LABEL 170 }); 171 172 Insn = function(code, opts, fileName, lineNo) { 173 ISeqElem.call(this); 2 174 this.code = code; 3 175 this.opts = opts; 4 176 this.fileName = fileName; 5 177 this.lineNo = lineNo; 6 } 7 8 Instruction.prototype.toString = function() { 9 return this.fileName + '#' + this.lineNo + ': ' + Instruction.CodeNames[this.code] + ' <' + this.opts.join(', ') + '>'; 10 }; 11 12 Instruction.CodeNames = [ 178 this.index = -1; 179 }; 180 181 Insn.prototype = new ISeqElem; 182 183 Utils.objectExtend(Insn.prototype, { 184 toString: function() { 185 return '<Insn:'+getInsnCodeName(this.code)+' <' + this.opts.join(', ') + '> ('+this.fileName + ':' + this.lineNo+')>'; 186 }, 187 clone: function() { 188 return new Insn(this.code, this.opts, this.fileName, this.lineNo); 189 }, 190 type: ISeqElem.Type.INSN 191 }); 192 193 var codeNames = [ 13 194 'NOP', 14 195 'PUSH_VAR', … … 45 226 ]; 46 227 47 Instruction.Code = {}; 48 (function(){ 49 for(var i = 0; i < Instruction.CodeNames.length; i ++) { 50 var name = Instruction.CodeNames[i]; 51 Instruction.Code[name] = i; 228 getInsnCodeName = function(insnCode) { 229 return codeNames[insnCode]; 230 } 231 232 Insn.Code = {}; 233 (function() { 234 for(var i = 0; i < codeNames.length; i ++) { 235 var name = codeNames[i]; 236 Insn.Code[name] = i; 52 237 } 53 238 })(); 54 239 240 })(); 241 55 242 if(typeof HSPonJS != 'undefined') { 56 HSPonJS.Instruction = Instruction; 57 } 58 243 HSPonJS.ISeq = ISeq; 244 HSPonJS.ISeqElem = ISeqElem; 245 HSPonJS.Label = Label; 246 HSPonJS.Insn = Insn; 247 HSPonJS.getInsnCodeName = getInsnCodeName; 248 } 249 -
lang/javascript/hsp-on-js/trunk/src/label-array.js
r28714 r29704 1 1 function LabelArray() { 2 2 HSPArray.call(this); 3 this.values = [Label .EMPTY];3 this.values = [LabelValue.EMPTY]; 4 4 } 5 5 … … 11 11 if(isExpanded) { 12 12 var newLen = this.allLength(); 13 var empty = Label .EMPTY;13 var empty = LabelValue.EMPTY; 14 14 for(var i = this.values.length; i < newLen; i ++) { 15 15 this.values[i] = empty; … … 22 22 if(isExpanded) { 23 23 var newLen = this.l0; 24 var empty = Label .EMPTY;24 var empty = LabelValue.EMPTY; 25 25 for(var i = this.values.length; i < newLen; i ++) { 26 26 this.values[i] = empty; -
lang/javascript/hsp-on-js/trunk/src/label-value.js
r29399 r29704 1 function Label() { 2 this.pos = -1; 1 function LabelValue(pos) { 2 if(pos != undefined) { 3 this.pos = pos; 4 } else { 5 this.pos = -1; 6 } 3 7 } 4 8 5 Label .prototype = new Value;9 LabelValue.prototype = new Value; 6 10 7 Utils.objectExtend(Label .prototype, {11 Utils.objectExtend(LabelValue.prototype, { 8 12 toString: function() { 9 return '<Label :'+this.pos+'>';13 return '<LabelValue:'+this.pos+'>'; 10 14 }, 11 15 getType: function() { … … 13 17 }, 14 18 isUsing: function() { 15 return t his != Label.EMPTY;19 return true; 16 20 } 17 21 }); 18 22 19 Label.EMPTY = new Label; 23 LabelValue.EMPTY = new LabelValue; 24 LabelValue.EMPTY.isUsing = function() { return false; }; 20 25 21 26 if(typeof HSPonJS != 'undefined') { 22 HSPonJS.Label = Label;27 HSPonJS.LabelValue = LabelValue; 23 28 } 24 29 -
lang/javascript/hsp-on-js/trunk/src/param-info.js
r28714 r29704 21 21 isArgNode: function() { return false; }, 22 22 isLiteralNode: function() { return false; }, 23 isLabelNode: function() { return false; }, 23 24 isDefaultNode: function() { return false; }, 24 25 isOperateNode: function() { return false; }, … … 34 35 ARG: 2, 35 36 LITERAL: 3, 36 DEFAULT: 4, 37 OPERATE: 5, 38 USERDEF_FUNCALL: 6, 39 BUILTIN_FUNCALL: 7, 40 GET_STACK: 8 37 LABEL: 4, 38 DEFAULT: 5, 39 OPERATE: 6, 40 USERDEF_FUNCALL: 7, 41 BUILTIN_FUNCALL: 8, 42 GET_STACK: 9 41 43 }; 42 44 … … 88 90 getValueType: function() { 89 91 return this.val.getType(); 92 } 93 }); 94 95 function LabelNode(lobj) { 96 this.lobj = lobj; 97 } 98 LabelNode.prototype = new Node; 99 Utils.objectExtend(LabelNode.prototype, { 100 nodeType: NodeType.LABEL, 101 isLabelNode: function() { return true; }, 102 toString: function() { 103 return '<LabelNode:'+this.lobj+'>'; 104 }, 105 getValueType: function() { 106 return VarType.LABEL; 107 }, 108 getLabelPos: function() { 109 return this.lobj.getPos(); 90 110 } 91 111 }); -
lang/javascript/hsp-on-js/trunk/src/run-in-shell
r28263 r29704 62 62 vartype.js 63 63 value.js 64 label .js64 label-value.js 65 65 str-value.js 66 66 double-value.js -
lang/javascript/hsp-on-js/trunk/src/run-in-shell.js
r28714 r29704 25 25 var fileName, lineNo; 26 26 sequence.forEach(function(insn, i) { 27 var out = Formatter.sprintfForJS('%5d %-20s %-30s ', i, Instruction.CodeNames[insn.code], insn.opts.map(String).join(', '));27 var out = Formatter.sprintfForJS('%5d %-20s %-30s ', i, getInsnCodeName(insn.code), insn.opts.map(String).join(', ')); 28 28 if(fileName != insn.fileName) { 29 29 fileName = insn.fileName;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)