Changeset 148
- Timestamp:
- 04/27/08 03:20:30 (4 months ago)
- Files:
-
- branches/1.9/bin/walnut.exe (modified) (previous)
- branches/1.9/bud.exe (deleted)
- branches/1.9/clean.bat (modified) (1 diff)
- branches/1.9/cmd.exe.lnk (deleted)
- branches/1.9/documentation/pad.dll (deleted)
- branches/1.9/make.bat (modified) (1 diff)
- branches/1.9/release.bat (added)
- branches/1.9/source/main.d (modified) (1 diff)
- branches/1.9/source/methods.d (modified) (10 diffs)
- branches/1.9/source/parser.d (modified) (10 diffs)
- branches/1.9/source/test.d (deleted)
- branches/1.9/source/value.d (modified) (15 diffs)
- branches/1.9/test (deleted)
- branches/1.9/test.bat (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.9/clean.bat
r140 r148 4 4 5 5 del bin\*.obj bin\walnut.* 6 7 8 PAUSE branches/1.9/make.bat
r143 r148 1 2 :: >make -debug3 :: passes -debug and4 :: >make -release5 :: passes -release to the following line:6 1 7 2 del bin\*.obj bin\walnut.* 8 bud.exe -od.\bin -T.\bin\walnut source\main -O -LIBOPT/ma/co %1 9 10 :: you should be able to figure it out from there. 3 cd source 4 dmd -c -O -release -debug -od..\bin main.d methods.d parser.d structure.d text.d value.d 5 cd ..\bin 6 lib -c walnut.lib methods.obj parser.obj structure.obj text.obj value.obj 7 dmd walnut.exe main.obj -L/ma walnut.lib 8 PAUSE branches/1.9/source/main.d
r143 r148 16 16 value; 17 17 18 // pragma(lib,"bin\\walnut.lib");19 20 enum EXIT {21 SUCCESS = 0x00,22 FAILURE = 0x01,23 }24 25 18 int main(char[][] arguments) { 26 19 27 20 /// Fail hard if there's no script. 28 21 if(!arguments.length) 29 return EXIT.FAILURE;22 return 1; 30 23 31 24 /// Initialize the program state 32 25 Value global = Global_init(); 33 c onst_stringpath;26 char[] path; 34 27 35 28 /// Grab the files and collect the source 36 29 for(size_t i = 1; i < arguments.length; i++) { 37 30 path = std.path.defaultExt(arguments[i],"nut"); 38 parseProgram(cast(Value) (cast(c onst_string) std.file.read(path) ~ '\0'), global);31 parseProgram(cast(Value) (cast(char[]) std.file.read(path)), global); 39 32 } 40 33 41 34 /// all done. 42 return EXIT.SUCCESS;35 return 0; 43 36 } branches/1.9/source/methods.d
r142 r148 73 73 } 74 74 static Value* Object_prototype_toSource(ref Value self, ref Value cc, Value[] arguments ...) { 75 c onst_stringbuffer = "{";75 char[] buffer = "{"; 76 76 bool any = false; 77 77 for(int i = 0; i < self.length; i++) { … … 150 150 } 151 151 static Value* Array_prototype_toLocaleString(ref Value self, ref Value cc, Value[] arguments ...) { 152 c onst_stringr = "[";152 char[] r = "["; 153 153 char c = ','; // this character needs to be locale "list separator" 154 154 if(self.a.length) { … … 163 163 } 164 164 static Value* Array_prototype_toSource(ref Value self, ref Value cc, Value[] arguments ...) { 165 c onst_stringr = "[";165 char[] r = "["; 166 166 if(self.a.length) { 167 167 r ~= self.a[0].toString(); … … 185 185 } 186 186 static Value* Array_prototype_join(ref Value self, ref Value cc, Value[] arguments ...) { 187 c onst_strings = TEXT._;187 char[] s = TEXT._; 188 188 if(arguments.length) 189 189 s = arguments[0].toString(); 190 c onst_stringr = self.a[0].toString();190 char[] r = self.a[0].toString(); 191 191 for(int i = 1; i < self.a.length; i++) { 192 192 r ~= s; … … 315 315 static Value* String_prototype_match(ref Value self, ref Value cc, Value[] arguments ...) { 316 316 if(arguments.length && arguments[0].type == TYPE.REGEXP) { 317 c onst_string[] m = arguments[0].r.match(self.toString());317 char[][] m = arguments[0].r.match(self.toString()); 318 318 Value[] v = []; 319 foreach(c onst_strings; m) {319 foreach(char[] s; m) { 320 320 v ~= cast(Value) s; 321 321 } … … 351 351 goto _no0; 352 352 if(arguments[0].type == TYPE.REGEXP) { 353 c onst_string[] v = arguments[0].r.split(self.toString());354 foreach(c onst_strings; v) {353 char[][] v = arguments[0].r.split(self.toString()); 354 foreach(char[] s; v) { 355 355 a ~= cast(Value) s; 356 356 } 357 357 return &cast(Value) a; 358 358 } 359 c onst_stringsep;359 char[] sep; 360 360 sep = arguments[0].toString(); 361 361 if(sep.length == 0) { … … 363 363 a.length = self.s.length; 364 364 a[i].type = TYPE.STRING; 365 a[i].s = self.s. idup;365 a[i].s = self.s.dup; 366 366 } 367 367 else { … … 421 421 s[i++] = std.uni.toUniLower(c); 422 422 } 423 return &cast(Value) cast(c onst_string) s;423 return &cast(Value) cast(char[]) s; 424 424 } 425 425 static Value* String_prototype_toUpperCase(ref Value self, ref Value cc, Value[] arguments ...) { … … 432 432 s[i++] = std.uni.toUniUpper(c); 433 433 } 434 return &cast(Value) cast(c onst_string) s;434 return &cast(Value) cast(char[]) s; 435 435 } 436 436 … … 1035 1035 if(arguments.length) { 1036 1036 Value[] a = []; 1037 c onst_string[] m = self.r.exec(arguments[0].toString());1038 foreach(c onst_strings; m) {1037 char[][] m = self.r.exec(arguments[0].toString()); 1038 foreach(char[] s; m) { 1039 1039 a ~= cast(Value) s; 1040 1040 } branches/1.9/source/parser.d
r147 r148 63 63 uint line = 1, lineMark; 64 64 char last = 0x00; 65 c onst_char* c;65 char* c; 66 66 Value v; 67 67 Value context; … … 72 72 c = &source.toString()[0]; 73 73 context = cc; 74 const_char* cMark; 75 76 scope(failure) 77 dumpTree(v, 1, true); 78 74 char* cMark; 75 debug 76 scope(failure) 77 dumpTree(v, 1, true); 79 78 while(true) { 80 79 cMark = c; … … 88 87 v.a = buffer; 89 88 v.type = TYPE.STATEMENTS; 90 dumpTree(v, 1, false); 89 debug 90 dumpTree(v, 1, false); 91 91 } 92 92 93 93 void parseStatement() 94 94 { 95 debug printf("!%d : parseStatement()\n",c); 95 debug 96 printf("!%d : parseStatement()\n",c); 96 97 Value[] buffer; 97 c onst_strings;98 c onst_char* cMark;98 char[] s; 99 char* cMark; 99 100 100 101 /* Block, 12.1 */ … … 139 140 debug printf("!%d : parseExpression()\n",c); 140 141 Value[] buffer; 141 c onst_char* cMark;142 char* cMark; 142 143 bool bFlag = false; 143 144 … … 250 251 Note: this is called from parsePrimary, as it's picked up by virtue of starting with an [a-zA-Z_$] 251 252 */ 252 bool parseKeyword(c onst_strings)253 bool parseKeyword(char[] s) 253 254 { 254 255 debug printf("!%d : parseKeyword()\n",c); 255 256 256 257 Value[] buffer; 257 c onst_char* cMark;258 char* cMark; 258 259 int i; 259 260 … … 586 587 { 587 588 Value[] buffer; 588 c onst_char* cMark;589 char* cMark; 589 590 debug printf("!%d : KEYVAR\n",c); 590 591 while(true) { … … 610 611 bool neg; 611 612 double d; 612 c onst_char* cMark = c;613 char* cMark = c; 613 614 switch(c[0]) { 614 615 case '\'': 615 616 case '"': 616 617 /* String literal. 7.8.4 page 20 */ 617 c onst_strings;618 c onst_char* cMark2;618 char[] s; 619 char* cMark2; 619 620 cMark2 = c; 620 621 for(c++; c[0] != cMark2[0]; c++) { … … 651 652 } 652 653 c++; 653 c onst_strings = cMark[0..(c-cMark)];654 char[] s = cMark[0..(c-cMark)]; 654 655 cMark = c; 655 656 while(c[0] == 'g' || c[0] == 'i' || c[0] == 'm') { … … 808 809 case '{': 809 810 debug printf("!%d : ObjectLiteral Expression starting\n", c); 810 c onst_string[] b1;811 char[][] b1; 811 812 Value[] b2; 812 813 uint len = 0; … … 845 846 {} 846 847 debug assert(cMark < c, TEXT._unexpected_token); 847 c onst_strings = cMark[0..(c-cMark)];848 char[] s = cMark[0..(c-cMark)]; 848 849 if(parseKeyword(s)) 849 850 return; branches/1.9/source/value.d
r147 r148 19 19 alias std.date.d_time d_time; 20 20 alias std.regexp.RegExp RegExp; 21 22 version(D_Version2) {23 alias const(char) const_char;24 alias const(Value) const_Value;25 alias const(char)[] const_string;26 } else {27 alias char const_char;28 alias Value const_Value;29 alias char[] const_string;30 }31 21 32 22 /// TYPE can be checked at runtime to find out what the type of a Value is. … … 161 151 struct { 162 152 uint length; 163 c onst_string* keys;153 char[]* keys; 164 154 Value* values; 165 155 } … … 169 159 } 170 160 Value[] a; 171 c onst_strings;161 char[] s; 172 162 bool b; 173 163 int i; … … 182 172 Object interactions 183 173 */ 184 const bool opIn_r(const_stringkey) {174 bool opIn_r(char[] key) { 185 175 /// OPTIMIZE: linear search 186 176 for(int i = 1; i < length; i++) { … … 190 180 return false; 191 181 } 192 const Value opIndex(const_stringkey) {182 Value opIndex(char[] key) { 193 183 /// OPTIMIZE: linear search 194 const(Value)* self = this;184 Value* self = this; 195 185 int i; 196 186 do { … … 203 193 return UNDEFINED; 204 194 } 205 void opIndexAssign(Value v, c onst_stringkey) {195 void opIndexAssign(Value v, char[] key) { 206 196 /// OPTIMIZE: linear search 207 197 for(int i = 1; i < length; i++) { … … 213 203 length++; 214 204 /// OPTIMIZE: one-at-a-time realloc 215 keys = cast(c onst_string*) std.c.stdlib.realloc(keys,length);205 keys = cast(char[]*) std.c.stdlib.realloc(keys,length); 216 206 values = cast(Value*) std.c.stdlib.realloc(values,Value.sizeof * length); 217 207 } … … 251 241 s[0] = x; 252 242 Value v = void; 253 v.s = cast(c onst_string) s;243 v.s = cast(char[]) s; 254 244 v.type = TYPE.STRING; 255 245 return v; 256 246 } 257 static Value opCall(c onst_stringx) {247 static Value opCall(char[] x) { 258 248 Value v = void; 259 249 v.s = x; … … 306 296 char[] s; 307 297 s[0] = x; 308 this.s = cast(c onst_string) s;298 this.s = cast(char[]) s; 309 299 type = TYPE.STRING; 310 300 } 311 void opAssign(c onst_stringx) {301 void opAssign(char[] x) { 312 302 s = x; 313 303 type = TYPE.STRING; … … 337 327 artificial opCasts 338 328 */ 339 constbool toBoolean() {329 bool toBoolean() { 340 330 /* ToBoolean 9.2 page 30 */ 341 331 switch(type) { … … 350 340 assert(0,TEXT._unexpected_token); // throw a TypeError 351 341 } 352 c onst const_stringtoString() {342 char[] toString() { 353 343 /* ToString 9.8 page 35 */ 354 344 switch(type) { … … 374 364 We need to get it's className, which is stored as the TEXT._x value for it's constructor in Global. 375 365 */ 376 c onst_strings;366 char[] s; 377 367 for(int i = 2; i < Global.length; i++) { 378 368 if(*this == Global.values[i]) { … … 397 387 assert(0); // throw a TypeError 398 388 } 399 constint toInteger() {389 int toInteger() { 400 390 /* ToInteger 9.4 page 34 */ 401 391 switch(type) { … … 422 412 assert(0); // throw a TypeError 423 413 } 424 constdouble toDouble() {414 double toDouble() { 425 415 /* ToNumber 9.3 page 31 */ 426 416 switch(type) { … … 446 436 assert(0); // throw a TypeError 447 437 } 448 constValue toObject() {438 Value toObject() { 449 439 /* ToObject 9.9 page 36 */ 450 440 switch(type) {
