Changeset 127
- Timestamp:
- 01/10/08 06:42:40 (11 months ago)
- Files:
-
- branches/1.9/bin/walnut.exe (modified) (previous)
- branches/1.9/bin/walnut.lib (modified) (previous)
- branches/1.9/makefile (modified) (1 diff)
- branches/1.9/source/interpreter.d (modified) (14 diffs)
- branches/1.9/source/methods.d (modified) (9 diffs)
- branches/1.9/source/value.d (modified) (2 diffs)
- branches/1.9/test/hello.nut (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.9/makefile
r123 r127 14 14 ################# Variables ################# 15 15 16 DFLAGS=-O - release -quiet -c -Isource16 DFLAGS=-O -debug -release -quiet -c -Isource 17 17 LFLAGS=/ma/NOL 18 18 OBJS=bin\interpreter.obj bin\methods.obj bin\structure.obj bin\text.obj bin\test.obj bin\value.obj branches/1.9/source/interpreter.d
r126 r127 10 10 11 11 uint line = 1; 12 uint parenCount = 0; 12 13 13 /* 14 Bug: 15 parenCount won't be 0 for [ [ ] ] third ] when it gets executed, and is honestly an unneccessary system given16 the recursive nature of the algorithm.17 14 Bug: 15 dumpTree is demonstrating that somewhere between expressions and statements, we're generating a shadow token tree. 16 This will have to be cleaned up before continuing further. 17 18 18 Code naturally matches to matching parens, so if we encounter one of ], }, ) in code, we know we're unmatched. 19 19 The opposite case of never finding a ], }, ) for some [, {, ( is already tackled. … … 34 34 35 35 parseOptionalWS(); 36 c0 = c; 37 parseStatement(); 38 printf("%.*s\n",c0[0..(c-c0)]); 36 // do { 37 parseStatement(); 38 printf("%s\n",c); 39 // } while(c[0] != 0x00); 40 dumpTree(v, 1); 41 } 42 43 void dumpTree(Value v, int tabDepth) 44 { 45 int i,j; 46 printf("%.*s\t%.*s\n",std.string.toString(v.type), v.toString()); 47 if( v.type == TYPE.STATEMENTS 48 || v.type == TYPE.EXPRESSION 49 || v.type == TYPE.ARRAY) { 50 for(i = 0; i < v.a.length; i++) { 51 for(j = 0; j < tabDepth; j++) { 52 printf("\t"); 53 } 54 dumpTree(v.a[i], tabDepth+1); 55 } 56 } 39 57 } 40 58 … … 49 67 switch(c[0]) { 50 68 case '\r': 51 if(c[ 0] != '\n') {69 if(c[1] != '\n') { 52 70 line++; 53 71 c++; … … 93 111 function literals (fail) 94 112 function calls (fail) 113 array indices (fail) 95 114 Synopsis: consumes a number, string, array, object, (expression), or identifier if it's there and stores it in v. 96 115 */ … … 123 142 } 124 143 c++; 144 const_string s = cMark[0..(c-cMark)]; 145 cMark = c; 125 146 while(c[0] == 'g' || c[0] == 'i' || c[0] == 'm') { 126 147 c++; 127 148 } 128 v. s = cMark[0..(c-cMark)];149 v.r = new RegExp(s, cMark[0..(c-cMark)]); 129 150 v.type = TYPE.REGEXP; 130 151 return; … … 222 243 c++; 223 244 } 224 if(eneg) 225 e = -e; 226 if(e > 0) { 245 if(eneg) { 246 for(; --e; ) { 247 d /= 10; 248 } 249 } 250 else if(e > 0) { 227 251 for(; --e; ) { 228 252 d *= 10; 229 }230 }231 else if(e < 0) {232 for(; e++; ) {233 d /= 10;234 253 } 235 254 } … … 249 268 return; 250 269 case '(': 251 parenCount++;252 270 c++; 253 271 parseExpression(); 254 assert(c[0] == ')' && --parenCount == 0, MESSAGE_unmatched_parenthesis);272 assert(c[0] == ')', MESSAGE_unmatched_parenthesis); 255 273 c++; 256 274 return; 257 275 case '[': 258 276 Value[] buffer; 259 parenCount++;260 277 c++; 261 278 while(1) { … … 268 285 c++; 269 286 } 270 assert(c[0] == ']' && --parenCount == 0, MESSAGE_unmatched_parenthesis);287 assert(c[0] == ']', MESSAGE_unmatched_parenthesis); 271 288 c++; 272 289 v.a = buffer; … … 277 294 Value[] b2; 278 295 uint len = 0; 279 parenCount++;280 296 c++; 281 297 while(1) { … … 296 312 c++; 297 313 } 298 assert(c[0] == '}' && --parenCount == 0, MESSAGE_unmatched_parenthesis);314 assert(c[0] == '}', MESSAGE_unmatched_parenthesis); 299 315 c++; 300 316 v.length = len; … … 583 599 /** 584 600 Status: 585 keywords (fail) 601 delete (pass) 602 try (pass) 603 catch ( fail: accepts catch(err) } ) 604 finally (pass) 605 606 other keywords (fail) 586 607 expressions (pass) 587 statements (fail) 608 statements (fail: doesn't assert on unmatched parens) 609 588 610 Synopsis: consumes ( Expression ; | { statement* } | KEY? ? ) 589 611 */ … … 745 767 default: 746 768 if(c[0] == '{') { 747 parenCount++;748 769 c++; 749 770 do { … … 751 772 buffer ~= v; 752 773 } while(c[0] != '}'); 753 parenCount--; 754 c++; 755 assert(parenCount == 0, MESSAGE_unmatched_parenthesis); 774 c++; 756 775 v.a = buffer; 757 776 v.type = TYPE.STATEMENTS; … … 761 780 if(c[0] == ';') 762 781 c++; 782 assert(c[0] != '}', MESSAGE_unmatched_parenthesis); 783 assert(c[0] != ']', MESSAGE_unmatched_parenthesis); 784 assert(c[0] != ')', MESSAGE_unmatched_parenthesis); 763 785 assert(v != UNDEFINED, MESSAGE_unexpected_token); 764 786 } branches/1.9/source/methods.d
r123 r127 111 111 */ 112 112 static Value Global_isFinite(Value self, Value cc, Value[] arguments ...) { 113 return cast(Value) (arguments.length && isfinite(arguments[0].toDouble )? true : false );113 return cast(Value) (arguments.length && isfinite(arguments[0].toDouble())? true : false ); 114 114 } 115 115 … … 356 356 */ 357 357 static Value Array_prototype_toLocaleString(Value self, Value cc, Value[] arguments ...) { 358 const (char)[]r = "[";358 const_string r = "["; 359 359 char c = ','; // this character needs to be locale "list separator" 360 360 if(self.a.length) { … … 376 376 */ 377 377 static Value Array_prototype_toSource(Value self, Value cc, Value[] arguments ...) { 378 const (char)[]r = "[";378 const_string r = "["; 379 379 if(self.a.length) { 380 380 r ~= self.a[0].toString(); … … 412 412 */ 413 413 static Value Array_prototype_join(Value self, Value cc, Value[] arguments ...) { 414 const (char)[]s = TEXT_;414 const_string s = TEXT_; 415 415 if(arguments.length) 416 416 s = arguments[0].toString(); 417 const (char)[]r = self.a[0].toString();417 const_string r = self.a[0].toString(); 418 418 for(int i = 1; i < self.a.length; i++) { 419 419 r ~= s; … … 670 670 static Value String_prototype_match(Value self, Value cc, Value[] arguments ...) { 671 671 if(arguments.length && arguments[0].type == TYPE.REGEXP) { 672 const (char)[][] m = arguments[0].r.match(self.toString());672 const_string[] m = arguments[0].r.match(self.toString()); 673 673 Value[] v = []; 674 foreach(const (char)[]s; m) {674 foreach(const_string s; m) { 675 675 v ~= cast(Value) s; 676 676 } … … 736 736 goto _no0; 737 737 if(arguments[0].type == TYPE.REGEXP) { 738 const (char)[][] v = arguments[0].r.split(self.toString());739 foreach(const (char)[]s; v) {738 const_string[] v = arguments[0].r.split(self.toString()); 739 foreach(const_string s; v) { 740 740 a ~= cast(Value) s; 741 741 } 742 742 return cast(Value) a; 743 743 } 744 const (char)[]sep;744 const_string sep; 745 745 sep = arguments[0].toString(); 746 746 if(sep.length == 0) { … … 834 834 s[i++] = std.uni.toUniLower(c); 835 835 } 836 return cast(Value) cast(const (char)[]) s;836 return cast(Value) cast(const_string) s; 837 837 } 838 838 … … 859 859 s[i++] = std.uni.toUniUpper(c); 860 860 } 861 return cast(Value) cast(const (char)[]) s;861 return cast(Value) cast(const_string) s; 862 862 } 863 863 … … 1996 1996 if(arguments.length) { 1997 1997 Value[] a = []; 1998 const (char)[][] m = self.r.exec(arguments[0].toString());1999 foreach(const (char)[]s; m) {1998 const_string[] m = self.r.exec(arguments[0].toString()); 1999 foreach(const_string s; m) { 2000 2000 a ~= cast(Value) s; 2001 2001 } branches/1.9/source/value.d
r126 r127 36 36 37 37 // value types (public) 38 UNDEFINED = 0 x00,39 NULL = 0x01,40 OBJECT = 0x02,41 ACTIVEX = 0x03,42 FUNCTION = 0x04,43 ARRAY = 0x05,44 STRING = 0x06,45 BOOLEAN = 0x07,46 INT = 0x08,47 DOUBLE = 0x09,48 MATH = 0x0A,49 DATE = 0x0B,50 REGEXP = 0x0C,51 ERROR = 0x0D,38 UNDEFINED = 0, 39 NULL = 1, 40 OBJECT = 2, 41 ACTIVEX = 3, 42 FUNCTION= 4, 43 ARRAY = 5, 44 STRING = 6, 45 BOOLEAN = 7, 46 INT = 8, 47 DOUBLE = 9, 48 MATH = 10, 49 DATE = 11, 50 REGEXP = 12, 51 ERROR = 13, 52 52 53 53 // token types (private) 54 IDENT = 0x0E,55 56 EOF = 0x10,57 WS = 0x11,58 EXPRESSION = 0x12,59 STATEMENTS = 0x13,60 COMMA = 0x14,61 DOT = 0x15,62 COLON = 0x16,63 SEMI = 0x17,64 65 MOV = 0x20,66 ADDA = 0x21,67 SUBA = 0x22,68 MULA = 0x23,69 DIVA = 0x24,70 MODA = 0x25,71 NOTA = 0x26,72 ANDA = 0x27,73 ORA = 0x28,74 SHLA = 0x29,75 SHRA = 0x2A,76 SARA = 0x2B,77 78 INC = 0x31,79 DEC = 0x32,80 ADD = 0x33,81 SUB = 0x34,82 MUL = 0x35,83 DIV = 0x36,84 MOD = 0x37,85 NOT = 0x38,86 NEG = 0x39,87 AND = 0x3A,88 OR = 0x3B,89 SHL = 0x3C,90 SHR = 0x3D,91 SAR = 0x3E,92 93 CMPE = 0x40,94 CMPNE = 0x41,95 CMPL = 0x42,96 CMPLE = 0x43,97 CMPG = 0x44,98 CMPGE = 0x45,99 100 LOGOR = 0x50,101 LOGAND = 0x51,102 LOGQ = 0x52,103 104 KEYbreak = 0x60,105 KEYcase = 0x61,106 KEYcatch = 0x62,107 KEYcontinue = 0x63,108 KEYdefault = 0x64,109 KEYdelete = 0x65,110 KEYdo = 0x66,111 KEYelse = 0x67,112 KEYfinally = 0x68,113 KEYfor = 0x69,54 IDENT = 14, 55 56 EOF = 15, 57 WS = 16, 58 EXPRESSION = 17, 59 STATEMENTS = 18, 60 COMMA = 19, 61 DOT = 20, 62 COLON = 21, 63 SEMI = 22, 64 65 MOV = 23, 66 ADDA = 24, 67 SUBA = 25, 68 MULA = 26, 69 DIVA = 27, 70 MODA = 28, 71 NOTA = 29, 72 ANDA = 30, 73 ORA = 31, 74 SHLA = 32, 75 SHRA = 33, 76 SARA = 34, 77 78 INC = 35, 79 DEC = 36, 80 ADD = 37, 81 SUB = 38, 82 MUL = 39, 83 DIV = 40, 84 MOD = 41, 85 NOT = 42, 86 NEG = 43, 87 AND = 44, 88 OR = 45, 89 SHL = 46, 90 SHR = 47, 91 SAR = 48, 92 93 CMPE = 49, 94 CMPNE = 50, 95 CMPL = 51, 96 CMPLE = 52, 97 CMPG = 53, 98 CMPGE = 54, 99 100 LOGOR = 55, 101 LOGAND = 56, 102 LOGQ = 57, 103 104 KEYbreak = 58, 105 KEYcase = 59, 106 KEYcatch = 60, 107 KEYcontinue = 61, 108 KEYdefault= 62, 109 KEYdelete = 63, 110 KEYdo = 64, 111 KEYelse = 65, 112 KEYfinally = 66, 113 KEYfor = 67, 114 114 // KEYfunction? 115 KEYgoto = 0x6B,116 KEYif = 0x6C,117 KEYinstanceof = 0x6D,118 KEYin = 0x6E,119 KEYnew = 0x6F,120 KEYreturn = 0x70,121 KEYswitch = 0x71,122 KEYthrow = 0x72,123 KEYtry = 0x73,124 KEYtypeof = 0x74,125 KEYvar = 0x75,126 KEYvoid = 0x76,127 KEYwhile = 0x77,128 KEYwith = 0x78,115 KEYgoto = 68, 116 KEYif = 69, 117 KEYinstanceof = 70, 118 KEYin = 71, 119 KEYnew = 72, 120 KEYreturn = 73, 121 KEYswitch= 74, 122 KEYthrow = 75, 123 KEYtry = 76, 124 KEYtypeof = 77, 125 KEYvar = 78, 126 KEYvoid = 79, 127 KEYwhile = 80, 128 KEYwith = 81, 129 129 } 130 130 … … 338 338 return std.string.format(TEXT_bobject_sb,s); 339 339 case TYPE.ARRAY: // return Array_prototype_toSource(this,this); 340 case TYPE.IDENT: 340 341 case TYPE.STRING: 341 342 case TYPE.REGEXP: return this.s; branches/1.9/test/hello.nut
r126 r127 8 8 Object.prototype.toSource 9 9 y-- = 14; 10 delete (su san);10 delete (sue); 11 11 try{ 12 12 eat.it.up.like.a.fat.boy.eats.cake = true; 13 }catch( erro ) 13 }catch( erro ) { 14 14 } 15 15 finally {
