Skip to content

Commit b7d637d

Browse files
committed
Working. about to add GC.
1 parent 3eb34a1 commit b7d637d

File tree

8 files changed

+506
-55
lines changed

8 files changed

+506
-55
lines changed

JawaScriptExecutive-iOS/JawaArray.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern NSMutableDictionary* arrayPrototype;
1919
}
2020
@property NSMutableArray* elements;
2121

22-
+(void) initialize;
2322
-(id) initIn:(JawaExecutor *)ex;
2423
-(NSString*) description;
2524
-(NSMutableString*) toJSON:(NSMutableString *)ret;

JawaScriptExecutive-iOS/JawaArray.m

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
@implementation JawaArray
1616

17-
+(void)initialize {
18-
if (self == [JawaArray class]) {
19-
arrayPrototype = [[NSMutableDictionary alloc]init];
20-
}
21-
}
22-
2317
-(id)initIn:(JawaExecutor *)ex {
2418
self = [super init];
2519
if (self) {
@@ -31,11 +25,39 @@ -(id)initIn:(JawaExecutor *)ex {
3125
}
3226

3327
-(NSString*)description {
34-
return @"";
28+
BOOL first = true;
29+
NSMutableString* ret = [NSMutableString stringWithString:@"["];
30+
for (JawaObjectRef* obj in self.elements) {
31+
if (!first)
32+
[ret appendString:@","];
33+
first = false;
34+
[ret appendString:[obj description]];
35+
}
36+
[ret appendString:@"]"];
37+
return ret;
3538
}
3639

3740
-(NSMutableString*) toJSON:(NSMutableString*)ret {
38-
return [NSMutableString stringWithFormat: @""];
41+
if (ret == nil)
42+
ret = [NSMutableString stringWithString:@""];
43+
BOOL first = true;
44+
[ret appendString:@"["];
45+
for (JawaObjectRef* obj in self.elements) {
46+
if (!first)
47+
[ret appendString:@","];
48+
first = false;
49+
if ([obj.object isMemberOfClass:[NSMutableString class]]) {
50+
[ret appendString:@"\""];
51+
NSString* r = [[obj description] stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
52+
[ret appendString:r];
53+
[ret appendString:@"\""];
54+
} else if ([obj.object isKindOfClass:[JawaObject class]]) {
55+
[((JawaObject*)obj.object) toJSON:ret];
56+
} else
57+
[ret appendString:[obj description]];
58+
}
59+
[ret appendString:@"]"];
60+
return ret;
3961
}
4062

4163
-(void)append:(JawaObjectRef*)element {
@@ -51,10 +73,14 @@ -(JawaObjectRef*)at:(int)index {
5173
}
5274

5375
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName {
54-
int ID = [self getBuiltinID:funcName];
76+
NSUInteger ID = [self getBuiltinID:funcName];
5577
switch(ID) {
78+
// Array.length
79+
case 0: {
80+
return [JawaObjectRef RefWithNumber:self.elements.count in:self.executor];
81+
}
5682
default:
57-
break;
83+
[NSException raise:@"JavaScript Runtime Exception" format:@"%@ not implemented yet", funcName];
5884
}
5985
return nil;
6086
}

JawaScriptExecutive-iOS/JawaExecutor.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,33 @@ typedef NS_ENUM(NSInteger, ASTType) {
7979
};
8080

8181
#define PR_statements @"0"
82+
#define PR_arguments @"2"
8283
#define PR_id @"3"
8384

8485
#define PR_elements @"7"
8586
#define PR_literal @"8"
87+
#define PR_object @"10"
88+
#define PR_property @"11"
89+
#define PR_function @"12"
90+
#define PR_ops @"15"
91+
#define PR_subExpressions @"16"
92+
#define PR_onTrue @"18"
93+
#define PR_onFalse @"19"
8694
#define PR_params @"23"
8795
#define PR_body @"24"
96+
#define PR_test @"25"
8897
#define PR_varName @"26"
8998
#define PR_initialization @"27"
99+
#define PR_iterable @"28"
100+
#define PR_iterator @"29"
101+
#define PR_init @"30"
102+
#define PR_update @"31"
103+
#define PR_argument @"32"
90104
#define PR_declarations @"33"
91105

92106
typedef NS_ENUM(NSInteger, PropType) {
93107
PR_valueType,
94-
PR_arguments,
108+
95109

96110
PR_key,
97111

@@ -101,33 +115,30 @@ typedef NS_ENUM(NSInteger, PropType) {
101115

102116
PR_constructor,
103117

104-
PR_object,
105-
PR_property,
106-
PR_function,
118+
119+
107120
PR_subExpression,
108121
PR_op,
109122

110-
PR_ops,
111-
PR_subExpressions,
123+
112124
PR_condition,
113-
PR_onTrue,
114-
PR_onFalse,
125+
115126

116127
PR_left,
117128
PR_right,
118129
PR_expressions,
119130

120131

121132

122-
PR_test,
123133

124134

125-
PR_iterable,
126-
PR_iterator,
127135

128-
PR_init,
129-
PR_update,
130-
PR_argument,
136+
137+
138+
139+
140+
141+
131142

132143
};
133144

0 commit comments

Comments
 (0)