Changeset 20933

Show
Ignore:
Timestamp:
10/08/08 00:23:40 (2 months ago)
Author:
fujidig
Message:

notesel, noteunsel, noteinfo (notemax, notesize) を実装

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

Legend:

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

    r20926 r20933  
    337337                v.setbytes(offset, Utils.strTimes(String.fromCharCode(val), length)); 
    338338        }, 
     339        0x22: function notesel(v) { 
     340                this.scanArgs(arguments, 'v'); 
     341                if(v.getType() != VarType.STR) { 
     342                        v.assign(StrValue.EMPTY_STR); 
     343                } 
     344                var offset = v.variable.value.getOffset(v.indices); 
     345                if(offset == null) throw new HSPError(ErrorCode.ARRAY_OVERFLOW); 
     346                var buf = v.variable.value.values[offset]; 
     347                this.noteStack.push(buf); 
     348        }, 
    339349        0x27: function randomize(seed) { 
    340350                this.scanArgs(arguments, 'N'); 
    341351                this.random.srand(seed ? seed.toIntValue()._value : +new Date); 
     352        }, 
     353        0x28: function noteunsel() { 
     354                this.scanArgs(arguments, ''); 
     355                this.noteStack.pop(); 
    342356        } 
    343357}; 
     
    450464                return new IntValue(using); 
    451465        }, 
     466        0x00e: function noteinfo(n) { 
     467                this.scanArgs(arguments, 'N'); 
     468                n = n ? n.toIntValue()._value : 0; 
     469                switch(n) { 
     470                case 0: // notemax 
     471                        var lines = this.getNote().getValue()._value.split(/\r\n|\n|\r/); 
     472                        var len = lines.length; 
     473                        if(!lines[len-1]) len --; 
     474                        return new IntValue(len); 
     475                case 1: // notesize 
     476                        return new IntValue(this.getNote().getValue()._value.length); 
     477                default: 
     478                        throw new HSPError(ErrorCode.ILLEGAL_FUNCTION); 
     479                } 
     480        }, 
    452481        0x00f: function instr(str, fromIndex, pattern) { 
    453482                this.scanArgs(arguments, 'sNs'); 
  • lang/javascript/hsp-on-js/trunk/src/evaluator.js

    r20704 r20933  
    1010        this.loopStack = []; 
    1111        this.frameStack = []; 
     12        this.noteStack = []; 
    1213        this.stat = new IntArray(); 
    1314        this.refdval = new DoubleArray(); 
     
    202203                this.frameStack.push(new Frame(this.pc + 1)); 
    203204                this.pc = label.pos - 1; 
     205        }, 
     206        getNote: function getNote() { 
     207                if(this.noteStack.length == 0) { 
     208                        throw new HSPError(ErrorCode.ILLEGAL_FUNCTION); 
     209                } 
     210                return this.noteStack[this.noteStack.length - 1]; 
    204211        }, 
    205212        getBuiltinFuncName: function getBuiltinFuncName(insn) { 
  • lang/javascript/hsp-on-js/trunk/src/run-in-shell.js

    r20926 r20933  
    2121function main(){ 
    2222        var data = [ 
    23 '\x48\x53\x50\x33\x01\x03\x00\x00\x01\x00\x00\x00\xb0\x00\x00\x00', 
    24 '\x60\x00\x00\x00\x30\x00\x00\x00\x90\x00\x00\x00\x09\x00\x00\x00', 
    25 '\x99\x00\x00\x00\x04\x00\x00\x00\x9d\x00\x00\x00\x13\x00\x00\x00', 
    26 '\xb0\x00\x00\x00\x00\x00\x00\x00\xb0\x00\x00\x00\x00\x00\x00\x00', 
    27 '\xb0\x00\x00\x00\x00\x00\x00\x00\xb0\x00\x00\x00\x00\x00\x00\x00', 
    28 '\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 
    29 '\x01\x20\x00\x00\x00\x00\x08\x00\x02\x00\x06\x00\x08\x20\x1f\x00', 
    30 '\x01\x00\x00\x00\x04\x40\x64\x00\x08\x20\x1a\x00\x01\x00\x00\x00', 
    31 '\x04\x40\x40\x00\x0f\x20\x11\x00\x0f\x20\x00\x00\x07\x00\x00\x00', 
    32 '\x74\x2e\x68\x73\x70\x00\x00\x61\x00\x12\x00\x00\x00\xfe\x00\x00', 
    33 '\x00\x00\x00\x00\x06\x06\x06\x06\xfd\x07\x00\x00\x00\x00\xff\xff' 
     23'\x48\x53\x50\x33\x01\x03\x00\x00\x04\x00\x00\x00\x61\x02\x00\x00', 
     24'\x70\x00\x00\x00\x70\x01\x00\x00\xe0\x01\x00\x00\x3b\x00\x00\x00', 
     25'\x1b\x02\x00\x00\x08\x00\x00\x00\x23\x02\x00\x00\x3e\x00\x00\x00', 
     26'\x61\x02\x00\x00\x00\x00\x00\x00\x61\x02\x00\x00\x00\x00\x00\x00', 
     27'\x61\x02\x00\x00\x00\x00\x00\x00\x61\x02\x00\x00\x00\x00\x00\x00', 
     28'\x61\x02\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x60\x00\x00\x00', 
     29'\x68\x73\x70\x6c\x65\x74\x33\x00\x00\x00\x00\x00\x00\x00\x00\x00', 
     30'\x01\x20\x00\x00\x00\x00\x08\x00\x02\x00\x06\x00\x08\x20\x22\x00', 
     31'\x01\x00\x00\x00\x09\x20\x0f\x00\x0d\x00\x0e\x00\x00\x00\x28\x00', 
     32'\x04\x00\x01\x00\x00\x00\x29\x00\x01\x20\x01\x00\x00\x00\x08\x00', 
     33'\x02\x00\x08\x00\x08\x20\x22\x00\x01\x00\x01\x00\x09\x20\x0f\x00', 
     34'\x0d\x00\x0e\x00\x00\x00\x28\x00\x04\x00\x01\x00\x00\x00\x29\x00', 
     35'\x01\x20\x02\x00\x00\x00\x08\x00\x02\x00\x0b\x00\x08\x20\x22\x00', 
     36'\x01\x00\x02\x00\x09\x20\x0f\x00\x0d\x00\x0e\x00\x00\x00\x28\x00', 
     37'\x04\x00\x01\x00\x00\x00\x29\x00\x01\x20\x03\x00\x00\x00\x08\x00', 
     38'\x02\x00\x0f\x00\x08\x20\x22\x00\x01\x00\x03\x00\x09\x20\x0f\x00', 
     39'\x0d\x00\x0e\x00\x00\x00\x28\x00\x04\x00\x01\x00\x00\x00\x29\x00', 
     40'\x09\x20\x0f\x00\x0d\x00\x0e\x00\x00\x00\x28\x00\x04\x00\x01\x00', 
     41'\x00\x00\x29\x00\x08\x20\x28\x00\x09\x20\x0f\x00\x0d\x00\x0e\x00', 
     42'\x00\x00\x28\x00\x04\x00\x01\x00\x00\x00\x29\x00\x08\x20\x28\x00', 
     43'\x09\x20\x0f\x00\x0d\x00\x0e\x00\x00\x00\x28\x00\x04\x00\x01\x00', 
     44'\x00\x00\x29\x00\x08\x20\x28\x00\x09\x20\x0f\x00\x0d\x00\x0e\x00', 
     45'\x00\x00\x28\x00\x04\x00\x01\x00\x00\x00\x29\x00\x08\x20\x28\x00', 
     46'\x09\x20\x0f\x00\x01\x20\x00\x00\x00\x00\x08\x00\x02\x00\x14\x00', 
     47'\x02\x40\x15\x00\x02\x40\x17\x00\x02\x40\x1a\x00\x02\x40\x1e\x00', 
     48'\x02\x40\x23\x00\x02\x40\x2a\x00\x0f\x20\x0b\x00\x07\x00\x00\x00', 
     49'\x0f\x20\x0c\x00\x07\x00\x00\x00\x01\x00\x00\x00\x08\x20\x22\x00', 
     50'\x01\x00\x00\x00\x00\x00\x28\x00\x0e\x00\x04\x00\x00\x00\x29\x00', 
     51'\x09\x20\x0f\x00\x0d\x00\x0e\x00\x00\x00\x28\x00\x00\x00\x29\x00', 
     52'\x0f\x20\x05\x00\x0f\x20\x11\x00\x0f\x20\x00\x00\x07\x00\x01\x00', 
     53'\x74\x2e\x68\x73\x70\x00\x2a\x00\x2a\x2a\x00\x2a\x2a\x2a\x00\x2a', 
     54'\x2a\x2a\x2a\x00\x00\x20\x00\x0d\x0a\x00\x0d\x0a\x20\x00\x0d\x0a', 
     55'\x0d\x0a\x00\x61\x0d\x0a\x0d\x0a\x62\x00\x61\x0d\x0a\x0d\x0a\x62', 
     56'\x0d\x0a\x00\x61\x00\x62\x00\x63\x00\x64\x00\xb2\x00\x00\x00\xb2', 
     57'\x00\x00\x00\xfe\x00\x00\x00\x00\x00\x00\x00\x06\x04\x0a\x06\x04', 
     58'\x0a\x06\x04\x0a\x06\x04\x0a\x0a\x02\x0a\x02\x0a\x02\x0a\x02\x00', 
     59'\x02\x12\x0a\x0a\x08\x02\x06\xfd\x33\x00\x00\x00\x00\xfd\x35\x00', 
     60'\x00\x01\x00\xfd\x37\x00\x00\x02\x00\xfd\x39\x00\x00\x03\x00\xff', 
     61'\xff' 
    3462        ].join(''); 
    3563 
  • lang/javascript/hsp-on-js/trunk/src/t.hsp

    r20926 r20933  
    1 a = "" 
    2 memexpand a, 100 
    3 poke a, 64 
     1#runtime "hsplet3" 
     2a = "*" 
     3notesel a 
     4mes noteinfo(1) ; >> 1 
     5        b = "**" 
     6        notesel b 
     7        mes noteinfo(1) ; >> 2 
     8                c = "***" 
     9                notesel c 
     10                mes noteinfo(1) ; >> 3 
     11                        d = "****" 
     12                        notesel d 
     13                        mes noteinfo(1) ; >> 4 
     14                        mes noteinfo(1) ; >> 4 
     15                        noteunsel 
     16                mes noteinfo(1) ; >> 3 
     17                noteunsel 
     18        mes noteinfo(1) ; >> 2 
     19        noteunsel 
     20mes noteinfo(1) ; >> 1 
     21noteunsel 
     22 
     23mes 
     24a = "", " ", "\n", "\n ", "\n\n", "a\n\nb", "a\n\nb\n" 
     25foreach a 
     26        notesel a.cnt 
     27        mes noteinfo() 
     28loop 
     29