Changeset 113
- Timestamp:
- 01/04/08 07:06:49 (11 months ago)
- Files:
-
- branches/1.9/bin/walnut.exe (modified) (previous)
- branches/1.9/bin/walnut.lib (modified) (previous)
- branches/1.9/source/interpreter.d (modified) (3 diffs)
- branches/1.9/source/methods.d (modified) (2 diffs)
- branches/1.9/source/value.d (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.9/source/interpreter.d
r112 r113 8 8 void parse(Value self, Value cc) 9 9 { 10 const (char)[]source = self.s;11 const (char)*10 const_string source = self.s; 11 const_char* 12 12 p, 13 13 pStart, 14 last = &source[ $];14 last = &source[length-1]; 15 15 size_t 16 16 line = 1; … … 34 34 buffer ~= v; 35 35 } 36 foreach(b; buffer) { 37 printf("GOT TOKEN %s", b.toString()); 38 } 36 39 } 37 40 38 Value tokenize(ref const (char)* p, const(char)* pStart, const(char)* last, ref size_t line, Value cc)41 Value tokenize(ref const_char* p, const_char* pStart, const_char* last, ref size_t line, Value cc) 39 42 { 40 43 Value v; … … 337 340 p++; 338 341 } 339 const (char)[]word = pStart[0..(p-pStart)];342 const_string word = pStart[0..(p-pStart)]; 340 343 p--; 341 344 switch(word) { branches/1.9/source/methods.d
r103 r113 54 54 */ 55 55 static Value Global_parseInt(Value self, Value cc, Value[] arguments ...) { 56 uint base; 57 char* s; 56 uint base, quotient, i; 57 char[] s; 58 int a0; 58 59 if(arguments.length) { 60 a0 = arguments[0].toInteger(); 59 61 if(arguments.length > 1) { 60 62 base = arguments[1].toInteger(); 61 if(base == 1 || base > 36)63 if(base == 1 || base > 16) 62 64 return NAN; 63 65 } 64 66 if(base == 0) 65 67 base = 10; 66 return cast(Value) std.string.toString(std.string.itoa( arguments[0].toInteger(), s, base )); 68 do { 69 s[i++] = "0123456789abcdefghijklmnopqrstuvwxyz"[ quotient % base ]; 70 quotient /= base; 71 } 72 while( quotient ); 73 if( a0 < 0 ) 74 s[i++] = '-'; 75 s.reverse; 76 return cast(Value) s; 67 77 } 68 78 return NAN; … … 1220 1230 */ 1221 1231 static Value Date_parse(Value self, Value cc, Value[] arguments ...) { 1222 return cast(Value) (arguments.length? parse(arguments[0].toString()) : d_time_nan);1232 return cast(Value) (arguments.length? std.date.parse(arguments[0].toString()) : d_time_nan); 1223 1233 } 1224 1234 branches/1.9/source/value.d
r111 r113 21 21 alias std.date.d_time d_time; 22 22 alias std.regexp.RegExp RegExp; 23 24 version(D_Version2) { 25 alias const(char) const_char; 26 alias const(Value) const_Value; 27 alias const(char)[] const_string; 28 } else { 29 alias char const_char; 30 alias Value const_Value; 31 alias char[] const_string; 32 } 33 23 34 24 35 /// TYPE can be checked at runtime to find out what the type of a Value is. … … 115 126 struct { 116 127 uint length; 117 const (char)[]* keys;128 const_string* keys; 118 129 Value* values; 119 130 } … … 123 134 } 124 135 struct { 125 const (char)* start;126 const (char)* end;136 const_char* start; 137 const_char* end; 127 138 } 128 139 Value[] a; 129 const (char)[]s;140 const_string s; 130 141 bool b; 131 142 int i; … … 137 148 ubyte access; 138 149 139 bool opIn_r(const(char)[]key) {150 const bool opIn_r(const_string key) { 140 151 /// OPTIMIZE: linear search 141 152 for(int i = 0; i < length; i++) { … … 145 156 return false; 146 157 } 147 const Value opIndex(const (char)[]key) {158 const Value opIndex(const_string key) { 148 159 /// OPTIMIZE: linear search 149 160 const(Value)* self = this; … … 158 169 return UNDEFINED; 159 170 } 160 void opIndexAssign(Value v, const (char)[]key) {171 void opIndexAssign(Value v, const_string key) { 161 172 /// OPTIMIZE: linear search 162 173 for(int i = 0; i < length; i++) { … … 167 178 } 168 179 length++; 169 keys = cast(const (char)[]*) std.c.stdlib.realloc(keys,length);180 keys = cast(const_string*) std.c.stdlib.realloc(keys,length); 170 181 values = cast(Value*) std.c.stdlib.realloc(values,Value.sizeof * length); 171 182 } … … 196 207 s[0] = x; 197 208 Value v; 198 v.s = cast(const (char)[]) s;209 v.s = cast(const_string) s; 199 210 v.type = TYPE.STRING; 200 211 return v; 201 212 } 202 static Value opCall(const (char)[]x) {213 static Value opCall(const_string x) { 203 214 Value v; 204 215 v.s = x; … … 252 263 char[] s; 253 264 s[0] = x; 254 this.s = cast(const (char)[]) s;265 this.s = cast(const_string) s; 255 266 type = TYPE.STRING; 256 267 } 257 void opAssign(const (char)[]x) {268 void opAssign(const_string x) { 258 269 s = x; 259 270 type = TYPE.STRING; … … 279 290 type = TYPE.REGEXP; 280 291 } 281 const const (char)[]toString() {292 const const_string toString() { 282 293 switch(type) { 283 294 case TYPE.UNDEFINED: return TEXT_undefined; … … 295 306 return MESSAGE_native_function; 296 307 case TYPE.OBJECT: 297 const (char)[]s;308 const_string s; 298 309 for(int i = 18; i < 34; i++) { 299 310 if(*this == Global.values[i]) { … … 308 319 case TYPE.STRING: return this.s; 309 320 case TYPE.REGEXP: return '/'~this.s~'/'; 321 default: return "TOKEN" ~ std.string.toString(type); 310 322 } 311 323 assert(0);
