OSDN Git Service

保存コミット
authorhikarupsp <hikarupsp@users.sourceforge.jp>
Sun, 10 Nov 2013 12:58:24 +0000 (21:58 +0900)
committerhikarupsp <hikarupsp@users.sourceforge.jp>
Sun, 10 Nov 2013 12:58:24 +0000 (21:58 +0900)
ai.js
ainet.js [new file with mode: 0644]
aiwrcgnz.js
elcc/elcexpr.js
header.js
webcpu/const.js
webcpu/memory.js
webcpu/webcpu.js

diff --git a/ai.js b/ai.js
index e3c3da0..51857da 100644 (file)
--- a/ai.js
+++ b/ai.js
@@ -1,5 +1,8 @@
 //AI004
 
+//開発時クロスドメイン許可で起動するには、
+// /Applications/Google\ Chrome.app/ --allow-file-access-from-files --disable-web-security
+
 function AI(messageBoxDOMObject, debugBoxDOMObject){
        //ブラウザチェック
        this.checkBrowser();
@@ -7,6 +10,7 @@ function AI(messageBoxDOMObject, debugBoxDOMObject){
        this.input = new AI_Input(this);
        this.wordRecognition = new AI_WordRecognition(this);
        this.IOManager = new AI_IOManager(this);
+       this.networkManager = new AI_NetworkManager(this);
        this.memory = new AI_Memory(this);
        this.think = new AI_Think(this);
        //出力関連
@@ -40,6 +44,7 @@ function AI(messageBoxDOMObject, debugBoxDOMObject){
        this.processByMode = this.inputProcess_Standard;
 
        this.debug("AI system initialized.\n");
+       this.debug("To enter internal console mode,\n  type '#4ca6ed1a-e62e-470b-9d7b-e332f709e48f'.\n");
 }
 AI.prototype = {
        UUIDStrLen: 36,
@@ -185,8 +190,19 @@ AI.prototype = {
                        this.wordRecognition.computeEachWordLevel();
                        this.wordRecognition.sortCandidateWordListByWordLevel();
                        this.wordRecognition.debugShowCandidateWordList();
+               } else if(str.indexOf("inputFromURL ") == 0){
+                       //webページを読み込む
+                       //inputFromURL http://www.aozora.gr.jp/cards/000035/files/1567_14913.html
+                       var url = str.substring(13);
+                       this.debug("[" + url + "]\n");
+                       var res = this.networkManager.sendRequestSync("GET", url, null);
+                       this.debug("[" + res + "]\n");
                } else{
                        this.debug("Unknown command [" + str + "].\n");
+                       this.debug("Command list:\n");
+                       this.debug("Implemented command list:\n");
+                       this.debug("  show cwl\n");
+                       this.debug("  exit\n");
                }
                
                this.debug("**** End Processing (InternalConsole) ****\n");
diff --git a/ainet.js b/ainet.js
new file mode 100644 (file)
index 0000000..a935bc8
--- /dev/null
+++ b/ainet.js
@@ -0,0 +1,78 @@
+function AI_NetworkManager(env){
+       this.env = env;
+}
+AI_NetworkManager.prototype = {
+       //from PCD2013GSCL
+       //https://sourceforge.jp/projects/h58pcdgame/scm/git/GameScriptCoreLibrary/blobs/master/www/corelib/coresubc.js
+       //http://hakuhin.jp/js/xmlhttprequest.html
+       CreateRequestObject: function(){
+               var rq = null;
+               // XMLHttpRequest
+               try{
+                       // XMLHttpRequest オブジェクトを作成
+                       rq = new XMLHttpRequest();
+               }catch(e){}
+               // Internet Explorer
+               try{
+                       rq = new ActiveXObject('MSXML2.XMLHTTP.6.0');
+               }catch(e){}
+               try{
+                       rq = new ActiveXObject('MSXML2.XMLHTTP.3.0');
+               }catch(e){}
+               try{
+                       rq = new ActiveXObject('MSXML2.XMLHTTP');
+               }catch(e){}
+               if(rq == null){
+                       return null;
+               }
+               return rq;
+       },
+       RequestObjectDisableCache: function(rq){
+               //call after open request.
+               //disable cache
+               //http://vird2002.s8.xrea.com/javascript/XMLHttpRequest.html
+               rq.setRequestHeader('Pragma', 'no-cache');                              // HTTP/1.0 における汎用のヘッダフィールド
+               rq.setRequestHeader('Cache-Control', 'no-cache');               // HTTP/1.1 におけるキャッシュ制御のヘッダフィールド
+               rq.setRequestHeader('If-Modified-Since', 'Thu, 01 Jun 1970 00:00:00 GMT');
+               
+       },
+       sendRequestSync: function(mode, url, data){
+               //同期モード
+               var q = this.CreateRequestObject();
+               q.open(mode, url, false);
+               q.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+               this.RequestObjectDisableCache(q);
+               q.send(data);
+               if(q.status == 0){
+                       alert("ネットワークにアクセスできません。" + q.status + ":" + q.statusText);
+               }else if((200 <= q.status && q.status < 300) || (q.status == 304)){
+                       var res = q.responseText;
+                       return res;
+               }else{
+                       alert("サーバーがエラーを返しました。" + request.status + ":" + request.statusText);
+               }
+               return null;
+       },
+       sendRequestAsync: function(mode, url, data, callback){
+               //非同期モード
+               //callback(res);
+               var q = this.CreateRequestObject();
+               var that = this;
+               q.onreadystatechange = function(){
+                       if(q.readyState == 4){
+                               if(q.status == 0){
+                                       alert("ネットワークにアクセスできません。" + q.status + ":" + q.statusText);
+                               }else if((200 <= q.status && q.status < 300) || (q.status == 304)){
+                                       var res = q.responseText;
+                                       callback(res);
+                               }else{
+                                       alert("サーバーがエラーを返しました。" + request.status + ":" + request.statusText);
+                               }
+                       }
+               };
+               q.open(mode, url, true);
+               q.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+               this.RequestObjectDisableCache(q);
+               q.send(data);
+       },
+}
\ No newline at end of file
index e8d600f..5c6c316 100644 (file)
@@ -47,8 +47,8 @@ AI_WordRecognition.prototype = {
                }
        },
        debugShowCandidateWordList: function(){
-               this.env.debug("candidateWordList:\n");
                var c = this.env.memory.candidateWordList;
+               this.env.debug("candidateWordList:" + c.length + "\n");
                for(var i = 0, iLen = c.length; i < iLen; i++){
                        this.env.debug(c[i].wordCount.toString() + " :" + c[i].wordLevel.toString() + " :" + c[i].str + "\n");
                }
index e261d12..504d2e8 100644 (file)
@@ -9,27 +9,6 @@ function ELCHNOSCompiler_ExpressionStructure(compiler, lineCount){
        this.bin = new Array();
 }
 ELCHNOSCompiler_ExpressionStructure.prototype = {
-       T_VPtr          :0x01,
-       T_SINT8         :0x02,  //8bitの符号付き, いわゆる signed char.
-       T_UINT8         :0x03,
-       T_SINT16        :0x04,  //16bitの符号付き, いわゆる short.
-       T_UINT16        :0x05,
-       T_SINT32        :0x06,
-       T_UINT32        :0x07,
-       T_SINT4         :0x08,
-       T_UINT4         :0x09,
-       T_SINT2         :0x0a,
-       T_UINT2         :0x0b,
-       T_SINT1         :0x0c,  //代入できるのは0か-1のみ.
-       T_UINT1         :0x0d,
-       T_SINT12        :0x0e,
-       T_UINT12        :0x0f,
-       T_SINT20        :0x10,
-       T_UINT20        :0x11,
-       T_SINT24        :0x12,
-       T_UINT24        :0x13,
-       T_SINT28        :0x14,
-       T_UINT28        :0x15,
        createBinary: function(){
                throw new ELCHNOSCompiler_CompileException(5, ["Translation undefined."], this.lineCount);
        },
@@ -133,13 +112,13 @@ var ELCHNOSCompiler_ExpressionStructure_Variable = function(compiler, lineCount)
                        //34    typ32   len32   data... 
                        this.bin.push(0x34);
                        //typ32
-                       if(this.pointerType == this.T_UINT8){
+                       if(this.pointerType == WebCPU.pType.UINT8){
                                this.bin.push(0x00, 0x00, 0x00, 0x03);
                        }
                        //len32
                        this.appendInstruction_UINT32BE(this.length);
                        //data
-                       if(this.pointerType == this.T_UINT8){
+                       if(this.pointerType == WebCPU.pType.UINT8){
                                for(var i = 0, iLen = this.initValue.length; i < iLen; i++){
                                        this.bin.push(this.initValue[i] & 0xFF);
                                }
@@ -170,7 +149,7 @@ var ELCHNOSCompiler_ExpressionStructure_Variable = function(compiler, lineCount)
                if(this.length > 0 || this.isPointer){
                        if(this.bits == 8 && this.isSigned == false){
                                //T_UINT8               :0x03,
-                               this.pointerType = this.T_UINT8;
+                               this.pointerType = WebCPU.pType.UINT8;
                        } else{
                                throw new ELCHNOSCompiler_CompileException(5, ["Not implemented pointer type ", this.pointerType], this.lineCount);
                        }
index 683c6e9..a197b1c 100644 (file)
--- a/header.js
+++ b/header.js
@@ -10,6 +10,7 @@ include("./aimtbase.js");
 include("./aimemtag.js");\r
 include("./aithink.js");\r
 include("./aiwrcgnz.js");\r
+include("./ainet.js");\r
 //ELCC\r
 include("./elcc/elcc.js");\r
 include("./elcc/elcexpr.js");\r
index b594083..68dc13a 100644 (file)
@@ -1,6 +1,28 @@
 WebCPU.maxDebugStringLength = 0xffff;
-
-WebCPU_Instruction.opcode = {
+WebCPU.pType = {
+       VPtr    :0x01,
+       SINT8   :0x02,  //8bitの符号付き, いわゆる signed char.
+       UINT8   :0x03,
+       SINT16  :0x04,  //16bitの符号付き, いわゆる short.
+       UINT16  :0x05,
+       SINT32  :0x06,
+       UINT32  :0x07,
+       SINT4   :0x08,
+       UINT4   :0x09,
+       SINT2   :0x0a,
+       UINT2   :0x0b,
+       SINT1   :0x0c,  //代入できるのは0か-1のみ.
+       UINT1   :0x0d,
+       SINT12  :0x0e,
+       UINT12  :0x0f,
+       SINT20  :0x10,
+       UINT20  :0x11,
+       SINT24  :0x12,
+       UINT24  :0x13,
+       SINT28  :0x14,
+       UINT28  :0x15,
+};
+WebCPU.opcode = {
        NOP:    0x00,
        LB:             0x01,
        LIMM:   0x02,
@@ -50,4 +72,4 @@ WebCPU_Instruction.opcode = {
        DATA:   0x34,
        //
        REMARK: 0xFE,
-}
+};
index c3b7c7a..bc6761d 100644 (file)
@@ -61,7 +61,7 @@ function WebCPU_Pointer(memoryPage){
                if(this.memoryPage.data[0] instanceof WebCPU_Instruction_LB){
                        //ラベルが直下にあればそのラベル番号をポインタに記憶する
                        this.labelNumber = this.memoryPage.data[0].imm32;
-                       this.memoryType = this.T_VPtr;
+                       this.memoryType = WebCPU.pType.VPtr;
                        if(this.memoryPage.data[1]){
                                if(this.memoryPage.data[1] instanceof WebCPU_Instruction_DATA){
                                        //ラベル直下がDATAだった場合はそのDATAの型に従う
@@ -103,27 +103,6 @@ WebCPU_Pointer.prototype = {
                "SINT28",
                "UINT28",       //0x15
        ],
-       T_VPtr          :0x01,
-       T_SINT8         :0x02,  //8bitの符号付き, いわゆる signed char.
-       T_UINT8         :0x03,
-       T_SINT16        :0x04,  //16bitの符号付き, いわゆる short.
-       T_UINT16        :0x05,
-       T_SINT32        :0x06,
-       T_UINT32        :0x07,
-       T_SINT4         :0x08,
-       T_UINT4         :0x09,
-       T_SINT2         :0x0a,
-       T_UINT2         :0x0b,
-       T_SINT1         :0x0c,  //代入できるのは0か-1のみ.
-       T_UINT1         :0x0d,
-       T_SINT12        :0x0e,
-       T_UINT12        :0x0f,
-       T_SINT20        :0x10,
-       T_UINT20        :0x11,
-       T_SINT24        :0x12,
-       T_UINT24        :0x13,
-       T_SINT28        :0x14,
-       T_UINT28        :0x15,
        toString: function(){
                if(this.memoryType == 0xC0FFEE){
                        //API Address, NOT OFFICIAL
index f8215b2..45f0b6e 100755 (executable)
@@ -204,13 +204,13 @@ WebCPU.prototype = {
                var temp4MaxSize = 256;
                var m;
                //P02 = T_UINT8:  &backend[2] (出力バッファ先頭)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_UINT8, backendMaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.UINT8, backendMaxSize);
                this.registers.Pointer[0x02] = new WebCPU_Pointer(m);
                //P03 = T_UINT8:  &backend[backend-maxsize] (出力バッファの限界)
                this.registers.Pointer[0x03] = this.registers.Pointer[0x02].getCopy();
                this.registers.Pointer[0x03].addressOffset = backendMaxSize;
                //P04 = T_UINT8:  &frontend[2] (入力データ先頭)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_UINT8);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.UINT8);
                this.registers.Pointer[0x04] = new WebCPU_Pointer(m);
                this.registers.Pointer[0x04].addressOffset = 0;
                this.registers.Pointer[0x04].memoryPage.data[1].data = new Array();
@@ -223,22 +223,22 @@ WebCPU.prototype = {
                this.registers.Pointer[0x05] = this.registers.Pointer[0x04].getCopy();
                this.registers.Pointer[0x05].addressOffset = i;
                //P06 = T_UINT8:  &temp0[0] (要素数が2M以上のテンポラリバッファ)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_UINT8, temp0MaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.UINT8, temp0MaxSize);
                this.registers.Pointer[0x06] = new WebCPU_Pointer(m);
                //P07 = T_UINT8:  &temp0[temp-maxsize]
                this.registers.Pointer[0x07] = this.registers.Pointer[0x06].getCopy();
                this.registers.Pointer[0x07].addressOffset = temp0MaxSize;
                //P0A = T_UINT32: &temp1[0] (要素数が16Kくらいあれば十分なバッファ)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_UINT32, temp1MaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.UINT32, temp1MaxSize);
                this.registers.Pointer[0x0A] = new WebCPU_Pointer(m);
                //P0B = T_SINT32: &temp2[0] (要素数が64のバッファ:Pxxレジスタの個数)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_SINT32, temp2MaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.SINT32, temp2MaxSize);
                this.registers.Pointer[0x0B] = new WebCPU_Pointer(m);
                //P0C = T_SINT32: &temp3[0] (要素数が4Kのバッファ:登録可能ラベル数)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_SINT32, temp3MaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.SINT32, temp3MaxSize);
                this.registers.Pointer[0x0C] = new WebCPU_Pointer(m);
                //P0D = T_UINT8:  &temp4[0] (要素数が256のバッファ)
-               m = this.mainMemory.allocateMemoryPage(WebCPU_Pointer.prototype.T_UINT8, temp4MaxSize);
+               m = this.mainMemory.allocateMemoryPage(WebCPU.pType.UINT8, temp4MaxSize);
                this.registers.Pointer[0x0D] = new WebCPU_Pointer(m);
                //変換
                this.execute();