Changeset 20657 for lang/javascript/hsp-on-js
- Timestamp:
- 10/04/08 04:45:39 (5 years ago)
- Location:
- lang/javascript/hsp-on-js/trunk
- Files:
-
- 10 modified
-
samples.html (modified) (9 diffs)
-
src/builtin-funcs.js (modified) (2 diffs)
-
src/cp932.js (modified) (1 diff)
-
src/evaluator.js (modified) (2 diffs)
-
src/exception.js (modified) (3 diffs)
-
src/hsp-array.js (modified) (1 diff)
-
src/int-array.js (modified) (1 diff)
-
src/str-array.js (modified) (1 diff)
-
src/variable-agent.js (modified) (1 diff)
-
src/variable.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/hsp-on-js/trunk/samples.html
r20489 r20657 8 8 <title>HSP on JS</title> 9 9 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2/jquery.min.js"></script> 10 <script type="text/javascript" src="hsp-on-js-core-0.0. 1.js" charset="utf-8"></script>10 <script type="text/javascript" src="hsp-on-js-core-0.0.2.js" charset="utf-8"></script> 11 11 <script type="text/javascript"> 12 function XHRReadURL(url, success, error) { 13 var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); 14 xhr.open("GET", url, true); 15 xhr.onreadystatechange = function(){ 16 if(xhr.readyState != 4) return; 17 if(200 <= xhr.status && xhr.status < 300) { 18 setTimeout(function(){success(xhr)}, 0); 19 } else if(xhr.status) { 20 setTimeout(function(){error(xhr)}, 0); 21 } 22 }; 23 xhr.send(null); 24 return xhr; 25 } 26 12 27 with(HSPonJS) { 13 28 Evaluator.prototype.disposeException = function disposeException(e) { … … 17 32 msg += this.getBuiltinFuncName(insn)||''; 18 33 msg += "\n"; 19 msg += '-- >'+(e.message||ErrorMessages[e.errcode]);34 msg += '--\x3e '+(e.message||ErrorMessages[e.errcode]); 20 35 alert(msg); 21 36 return; … … 30 45 return; 31 46 } 47 if(e instanceof FileReadException) { 48 var self = this; 49 self.fileReadXHR = XHRReadURL( 50 e.path, 51 function(xhr){ 52 self.fileReadXHR = null; 53 self.catchHSPException(function(){ e.success.call(self, xhr.responseText); }); 54 self.pc ++; 55 self.evaluate(); 56 }, 57 function() { 58 self.fileReadXHR = null; 59 self.catchHSPException(function(){ e.error.call(self); }); 60 self.pc ++; 61 self.evaluate(); 62 }); 63 return; 64 } 32 65 throw e; 33 66 }; … … 35 68 if(this.timeoutID != undefined) { 36 69 clearTimeout(this.timeoutID); 70 } 71 if(this.fileReadXHR) { 72 this.fileReadXHR.abort(); 73 this.fileReadXHR = null; 37 74 } 38 75 }; … … 58 95 $(function(){ 59 96 var evaluators = []; 97 function quitEvaluator(i) { 98 if(evaluators[i]) { 99 evaluators[i].quit(); 100 evaluators[i] = null; 101 } 102 } 60 103 $('textarea').each(function(i) { 61 104 var textarea = this; … … 75 118 var script = textarea.value; 76 119 resultTextarea.value = ''; 77 if(evaluators[i]) { 78 evaluators[i].quit(); 79 evaluators[i] = null; 80 } 120 quitEvaluator(i); 81 121 $.post('compile.cgi', {script: script}, function(jsonData){ 82 122 var data = eval('('+jsonData+')'); … … 89 129 var evaluator = new HSPonJS.Evaluator(axdata, sequence); 90 130 evaluator.resultTextarea = resultTextarea; 91 if(evaluators[i]) { 92 evaluators[i].quit(); 93 evaluators[i] = null; 94 } 131 quitEvaluator(i); 95 132 evaluators[i] = evaluator; 96 133 resultTextarea.style.display = ''; … … 100 137 }); 101 138 $(resetButton).click(function(){ 102 if(evaluators[i]) { 103 evaluators[i].quit(); 104 evaluators[i] = null; 105 } 139 quitEvaluator(i); 106 140 resultTextarea.style.display = 'none'; 107 141 resetButton.style.display = 'none'; … … 250 284 } 251 285 stop</textarea> 286 <h2>ファイル読み込み</h2> 287 <textarea cols="100" rows="10"> 288 sdim buf, 10000 289 bload "samples.html", buf // この HTML ファイル自身の内容を取得 290 ins = instr(buf, 0, "<h1") 291 mes strmid(buf, ins, 100)</textarea> 252 292 <h2>使用ライブラリ</h2> 253 293 <ul> -
lang/javascript/hsp-on-js/trunk/src/builtin-funcs.js
r20416 r20657 226 226 return new IntValue(this.loopStack[this.loopStack.length - 1].cnt); 227 227 }, 228 0x06: function strsize() { 229 return this.strsize; 230 }, 228 231 0x07: function looplev() { 229 232 return new IntValue(this.loopStack.length); … … 241 244 242 245 BuiltinFuncs[Token.Type.INTCMD] = { 246 0x11: function exist(path) { 247 this.scanArgs(arguments, 's'); 248 path = path.toStrValue()._value; 249 throw new FileReadException( 250 path, 251 function(data) { this.strsize = new IntValue(data.length); }, 252 function() { this.strsize = new IntValue(-1); }); 253 }, 254 0x16: function bload(path, v) { 255 this.scanArgs(arguments, 'sv'); 256 path = path.toStrValue()._value; 257 throw new FileReadException( 258 path, 259 function(data) { 260 var size = v.getByteSize(); 261 v.setbytes(0, CP932.encode(data).substr(0, size)); 262 }, 263 function() { 264 throw new HSPError(ErrorCode.FILE_IO); 265 }); 266 }, 243 267 0x1a: function poke(v, offset, val) { 244 268 this.scanArgs(arguments, 'vNN'); -
lang/javascript/hsp-on-js/trunk/src/cp932.js
r20137 r20657 12 12 13 13 encode: function encode(str){ 14 return str.replace(/[^\x00-\x 7f]/g,function(s){14 return str.replace(/[^\x00-\xff]/g,function(s){ 15 15 var c=s.charCodeAt(0),m; 16 16 return 65376<c&&c<65440?String.fromCharCode(c-65216):(c=CP932.Table.indexOf(s))<0?"\x81\x45":String.fromCharCode((m=(c<8272?c:(c=CP932.Table.lastIndexOf(s)))/188|0)<31?m+129:m+193)+String.fromCharCode((c%=188)<63?c+64:c+65) -
lang/javascript/hsp-on-js/trunk/src/evaluator.js
r20292 r20657 13 13 this.refdval = new DoubleArray(); 14 14 this.refstr = new StrArray(); 15 this.strsize = new IntValue(0); 15 16 this.random = new VCRandom(); 16 17 } … … 23 24 this.dispatch(insn); 24 25 } 26 } catch(e) { 27 if(!(e instanceof HSPException)) { 28 throw e; 29 } 30 this.disposeException(e); 31 } 32 }, 33 catchHSPException: function catchHSPException(callback) { 34 try { 35 callback(); 25 36 } catch(e) { 26 37 if(!(e instanceof HSPException)) { -
lang/javascript/hsp-on-js/trunk/src/exception.js
r20137 r20657 89 89 "外部オブジェクトの呼び出しに失敗しました", // 39 90 90 "関数の戻り値が設定されていません。", // 40 91 "関数を命令として記述しています。 ¥n(HSP2から関数化された名前を使用している可能性があります)", // 4191 "関数を命令として記述しています。\n(HSP2から関数化された名前を使用している可能性があります)", // 41 92 92 "*" 93 93 ]; … … 102 102 } 103 103 WaitException.prototype = new HSPException; 104 105 function FileReadException(path, success, error) { 106 this.path = path; 107 this.success = success; 108 this.error = error; 109 } 110 FileReadException.prototype = new HSPException; 111 104 112 105 113 function HSPError(errcode, message) { … … 116 124 HSPonJS.WaitException = WaitException; 117 125 HSPonJS.StopException = StopException; 126 HSPonJS.FileReadException = FileReadException; 118 127 HSPonJS.HSPError = HSPError; 119 128 } -
lang/javascript/hsp-on-js/trunk/src/hsp-array.js
r20320 r20657 102 102 this.setbyte(offset, bytesOffset + i, buf.charCodeAt(i)); 103 103 } 104 }, 105 getByteSize: function getByteSize(offset) { 106 throw new HSPError(ErrorCode.UNSUPPORTED_FUNCTION, 107 VarTypeNames[this.getType()]+" 型はメモリ読み込みに対応していません"); 104 108 } 105 109 }; -
lang/javascript/hsp-on-js/trunk/src/int-array.js
r20320 r20657 36 36 value |= (val & 0xff) << (bytesOffset % 4 * 8); 37 37 this.values[i] = new IntValue(value); 38 }, 39 getByteSize: function getByteSize(offset) { 40 return (this.values.length - offset) * 4; 38 41 } 39 42 }); -
lang/javascript/hsp-on-js/trunk/src/str-array.js
r20320 r20657 65 65 } 66 66 this.values[offset] = str.slice(0, bytesOffset) + buf + str.slice(bytesOffset + buf.length); 67 }, 68 getByteSize: function getByteSize(offset) { 69 return this.values[offset].length; 67 70 } 68 71 }); -
lang/javascript/hsp-on-js/trunk/src/variable-agent.js
r20320 r20657 95 95 if(offset == null) throw new HSPError(ErrorCode.ARRAY_OVERFLOW); 96 96 return this.variable.setbytes(offset, bytesOffset, buf); 97 }, 98 getByteSize: function getByteSize() { 99 var offset = this.variable.value.getOffset(this.indices); 100 if(offset == null) throw new HSPError(ErrorCode.ARRAY_OVERFLOW); 101 return this.variable.getByteSize(offset); 97 102 } 98 103 }; -
lang/javascript/hsp-on-js/trunk/src/variable.js
r20320 r20657 86 86 setbytes: function setbytes(offset, bytesOffset, buf) { 87 87 return this.value.setbytes(offset, bytesOffset, buf); 88 }, 89 getByteSize: function getByteSize(offset) { 90 return this.value.getByteSize(offset); 88 91 } 89 92 };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)