Changeset 25644

Show
Ignore:
Timestamp:
12/01/08 22:41:07 (5 years ago)
Author:
fujidig
Message:

'比較演算の複合代入で、型が変わることをチェックしていなかったのを修正'

Location:
lang/javascript/hsp-on-js/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/hsp-on-js/trunk/src/evaluator.js

    r24973 r25644  
    158158                        } 
    159159                } 
    160                 function pushCompoundAssignCode(calcCode, indicesCount) { 
     160                function pushCompoundAssignCode(calcCode, indicesCount, variableExpr) { 
    161161                        push('var arg = stack.pop();'); 
    162                         if(indicesCount == 0) { 
    163                                 push('array.assign(0, array.at(0).'+operateMethodNames[calcCode]+'(arg));'); 
    164                         } else if(indicesCount == 1) { 
    165                                 push('var offset = self.scanArg(stack.pop(), "i").toIntValue()._value;'); 
    166                                 push('array.expand1D(offset);'); 
    167                                 push('array.assign(offset, array.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     162                        if(!(8 <= calcCode && calcCode <= 13)) { 
     163                                // 比較演算以外は同じ型の値が返ってくることに依存して型チェックをしない 
     164                                push('var array = '+variableExpr+'.value;'); 
     165                                if(indicesCount == 0) { 
     166                                        push('array.assign(0, array.at(0).'+operateMethodNames[calcCode]+'(arg));'); 
     167                                } else if(indicesCount == 1) { 
     168                                        push('var offset = self.scanArg(stack.pop(), "i").toIntValue()._value;'); 
     169                                        push('array.expand1D(offset);'); 
     170                                        push('array.assign(offset, array.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     171                                } else { 
     172                                        pushGettingIndicesCode(indicesCount, 0); 
     173                                        push('stack.length -= '+indicesCount+';'); 
     174                                        push('array.expand(indices);'); 
     175                                        push('var offset = array.getOffset(indices);'); 
     176                                        push('array.assign(offset, array.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     177                                } 
    168178                        } else { 
    169                                 pushGettingIndicesCode(indicesCount, 0); 
    170                                 push('stack.length -= '+indicesCount+';'); 
    171                                 push('array.expand(indices);'); 
    172                                 push('var offset = array.getOffset(indices);'); 
    173                                 push('array.assign(offset, array.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     179                                push('var variable = '+variableExpr+';'); 
     180                                if(indicesCount == 0) { 
     181                                        push('if(variable.value.getType() != arg.getType()) variable.reset(arg.getType());'); 
     182                                        push('variable.value.assign(0, variable.value.at(0).'+operateMethodNames[calcCode]+'(arg));'); 
     183                                } else if(indicesCount == 1) { 
     184                                        push('var offset = self.scanArg(stack.pop(), "i").toIntValue()._value;'); 
     185                                        push('if(variable.value.getType() != arg.getType()) {'); 
     186                                        push('    if(offset == 0) {'); 
     187                                        push('        variable.reset(arg.getType());'); 
     188                                        push('    } else {'); 
     189                                        push('        throw new HSPError(ErrorCode.INVALID_ARRAYSTORE);'); 
     190                                        push('    }'); 
     191                                        push('}'); 
     192                                        push('variable.value.assign(offset, variable.value.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     193                                } else { 
     194                                        pushGettingIndicesCode(indicesCount, 0); 
     195                                        push('stack.length -= '+indicesCount+';'); 
     196                                        push('var array = variable.value;'); 
     197                                        push('array.expand(indices);'); 
     198                                        push('var offset = array.getOffset(indices);'); 
     199                                        push('if(array.getType() != arg.getType()) {'); 
     200                                        push('    if(offset == 0) {'); 
     201                                        push('        variable.reset(arg.getType());'); 
     202                                        push('        array = variable.value;'); 
     203                                        push('        array.expand(indices);'); 
     204                                        push('    } else {'); 
     205                                        push('        throw new HSPError(ErrorCode.INVALID_ARRAYSTORE);'); 
     206                                        push('    }'); 
     207                                        push('}'); 
     208                                        push('array.assign(offset, array.at(offset).'+operateMethodNames[calcCode]+'(arg));'); 
     209                                } 
    174210                        } 
    175211                } 
     
    379415                                var varId = insn.opts[1]; 
    380416                                var indicesCount = insn.opts[2]; 
    381                                 push('var array = variables['+varId+'].value;'); 
    382                                 pushCompoundAssignCode(calcCode, indicesCount); 
     417                                pushCompoundAssignCode(calcCode, indicesCount, 'variables['+varId+']'); 
    383418                                break; 
    384419                        case Instruction.Code.COMPOUND_ASSIGN_ARG_ARRAY: 
     
    386421                                var argNum = insn.opts[1]; 
    387422                                var indicesCount = insn.opts[2]; 
    388                                 push('var array = self.getArg('+argNum+').value;'); 
    389                                 pushCompoundAssignCode(calcCode, indicesCount); 
     423                                pushCompoundAssignCode(calcCode, indicesCount, 'self.getArg('+argNum+')'); 
    390424                                break; 
    391425                        case Instruction.Code.COMPOUND_ASSIGN_MEMBER: 
     
    393427                                var memberNum = insn.opts[1]; 
    394428                                var indicesCount = insn.opts[2]; 
    395                                 push('var array = self.getThismod().toValue().members['+memberNum+'].value;'); 
    396                                 pushCompoundAssignCode(calcCode, indicesCount); 
     429                                pushCompoundAssignCode(calcCode, indicesCount, 'self.getThismod().toValue().members['+memberNum+']'); 
    397430                                break; 
    398431                        case Instruction.Code.INC: 
  • lang/javascript/hsp-on-js/trunk/src/t.hsp

    r23230 r25644  
    1 #define q a++ 
    2  
    3 st = gettime(-1) 
    4 repeat 10000 
    5 q:q:q:q:q:q:q:q:q:q 
    6 q:q:q:q:q:q:q:q:q:q 
    7 q:q:q:q:q:q:q:q:q:q 
    8 q:q:q:q:q:q:q:q:q:q 
    9 q:q:q:q:q:q:q:q:q:q 
    10 loop 
    11 ed = gettime(-1) 
    12 mes strf("%d ms", ed - st) 
    13  
     1a = 1.0 
     2a.1 < = 1 
     3mes a.0 
     4mes a.1 
     5a0 = a.0 
     6a1 = a.1 
     7mes vartype(a0) 
     8mes vartype(a1)