Skip to content

Commit 66e9d1e

Browse files
committed
Working backup
1 parent 04a345f commit 66e9d1e

File tree

14 files changed

+275
-40
lines changed

14 files changed

+275
-40
lines changed

JawaScriptExecutive-iOS/JawaArray.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@
1111

1212
#import "JawaObject.h"
1313

14+
extern NSMutableDictionary* arrayPrototype;
15+
1416
@interface JawaArray : JawaObject
1517
{
1618

1719
}
20+
@property NSMutableArray* elements;
21+
22+
+(void) initialize;
23+
-(id) initIn:(JawaExecutor *)ex;
24+
-(NSString*) description;
25+
-(NSMutableString*) toJSON:(NSMutableString *)ret;
26+
-(void)append:(JawaObjectRef*)element;
27+
-(JawaObjectRef*)at:(int)index;
28+
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName;
29+
30+
1831
@end
1932

2033

JawaScriptExecutive-iOS/JawaArray.m

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// JawaArray.m
3+
// JawaScriptExecutive-iOS
4+
//
5+
// Created by Chi-Wei (Jack) Wang on 2016/1/27.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "JawaArray.h"
11+
#import "JawaObjectProtected.h"
12+
13+
NSMutableDictionary* arrayPrototype;
14+
15+
@implementation JawaArray
16+
17+
+(void)initialize {
18+
if (self == [JawaArray class]) {
19+
arrayPrototype = [[NSMutableDictionary alloc]init];
20+
}
21+
}
22+
23+
-(id)initIn:(JawaExecutor *)ex {
24+
self = [super init];
25+
if (self) {
26+
_prototype = arrayPrototype;
27+
_elements = [[NSMutableArray alloc]init];
28+
_executor = ex;
29+
}
30+
return self;
31+
}
32+
33+
-(NSString*)description {
34+
return @"";
35+
}
36+
37+
-(NSMutableString*) toJSON:(NSMutableString*)ret {
38+
return [NSMutableString stringWithFormat: @""];
39+
}
40+
41+
-(void)append:(JawaObjectRef*)element {
42+
[self.elements addObject:element];
43+
}
44+
45+
-(JawaObjectRef*)at:(int)index {
46+
if (index < 0 || index >= [self.elements count])
47+
return nil;
48+
return [self.elements objectAtIndex:index];
49+
}
50+
51+
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName {
52+
int ID = [self getBuiltinID:funcName];
53+
switch(ID) {
54+
default:
55+
break;
56+
}
57+
return nil;
58+
}
59+
60+
61+
@end

JawaScriptExecutive-iOS/Executor.h renamed to JawaScriptExecutive-iOS/JawaExecutor.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66
//
77
//
88

9-
#ifndef Executor_h
10-
#define Executor_h
9+
#ifndef JawaExecutor_h
10+
#define JawaExecutor_h
1111

12-
#define QUANTUM 0.0000000000000001;
12+
@class JawaObjectRef;
13+
14+
@interface JawaExecutor : NSObject
15+
@property NSMutableArray* currentActivation;
16+
17+
-(JawaObjectRef*)evaluate:(NSDictionary*)tree;
18+
-(JawaObjectRef*)dispatchBuiltin:(NSString*)funcName;
19+
@end
20+
21+
#define QUANTUM 0.0000000000000001
1322

1423
typedef NS_ENUM(NSInteger, ASTType) {
1524
SCRIPT_BODY = 0,
@@ -104,4 +113,4 @@ typedef NS_ENUM(NSInteger, PropType) {
104113
PR_declarations,
105114
};
106115

107-
#endif /* Executor_h */
116+
#endif /* JawaExecutor_h */

JawaScriptExecutive-iOS/Executor.m renamed to JawaScriptExecutive-iOS/JawaExecutor.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "Executor.h"
10+
#import "JawaExecutor.h"
1111

12-
@interface Executor : NSObject
1312

14-
@end
1513

1614
int main(int argc, char *argv[]) {
1715
return 0;

JawaScriptExecutive-iOS/JawaFunc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@
1010
#define JawaFunc_h
1111

1212
#import "JawaObject.h"
13+
#import "JawaObjectProtected.h"
1314

1415
@interface JawaFunc : JawaObject
1516
{
1617

1718
}
19+
@property NSString* name;
20+
@property NSDictionary* body;
21+
@property NSArray* params;
22+
@property BOOL isBuiltIn;
23+
@property BOOL isPropertyWrapper;
1824
@property int switchId;
25+
26+
-(id)initWithName:(NSString*)name in:(JawaExecutor*)ex taking:(NSArray*)params is:(BOOL)builtin is:(BOOL)propertyWrapper and:(NSDictionary*)body;
27+
-(JawaObjectRef*)apply:(JawaObjectRef*)on;
28+
-(JawaObjectRef*)apply;
29+
-(NSString*)description;
1930
@end
2031

2132

JawaScriptExecutive-iOS/JawaFunc.m

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// JawaFunc.m
3+
// JawaScriptExecutive-iOS
4+
//
5+
// Created by Chi-Wei (Jack) Wang on 2016/1/27.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "JawaFunc.h"
11+
#import "JawaString.h"
12+
13+
@implementation JawaFunc
14+
15+
-(id)initWithName:(NSString*)name in:(JawaExecutor*)ex taking:(NSArray*)params is:(BOOL)builtin is:(BOOL)propertyWrapper and:(NSDictionary*)body {
16+
self = [super init];
17+
if (self) {
18+
_name = name;
19+
_params = params;
20+
_isBuiltIn = builtin;
21+
_isPropertyWrapper = propertyWrapper;
22+
_body = body;
23+
_executor = ex;
24+
}
25+
return self;
26+
}
27+
28+
-(JawaObjectRef*)apply:(JawaObjectRef*)on {
29+
if (!self.isBuiltIn)
30+
return nil;
31+
if ([on.object isMemberOfClass:[NSMutableString class]])
32+
return dispatchStringBuiltin((NSMutableString*)on.object, self.name);
33+
if ([on.object isKindOfClass:[JawaObject class]])
34+
return [(JawaObject*)on.object invokeBuiltin:self.name];
35+
return nil;
36+
}
37+
38+
-(JawaObjectRef*)apply {
39+
if (!self.isBuiltIn) {
40+
[self.executor evaluate:self.body];
41+
return [(NSDictionary*)[self.executor.currentActivation
42+
objectAtIndex:0]
43+
objectForKey:@"return"];
44+
} else
45+
return [self.executor dispatchBuiltin:self.name];
46+
}
47+
48+
-(NSString*)description {
49+
return @"function";
50+
}
51+
52+
53+
@end

JawaScriptExecutive-iOS/JawaObject.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ extern NSMutableDictionary* objectPrototype;
1919
}
2020
@property (strong) NSMutableDictionary* properties;
2121
@property (strong) NSMutableDictionary* prototype;
22+
@property (weak) JawaExecutor* executor;
2223

23-
-(id) init;
24-
-(void) setProp:(NSString*)key with:(JawaObjectRef*)value;
24+
+(void)initialize;
25+
-(id)initIn:(JawaExecutor*)ex;
26+
-(void)setProp:(NSString*)key with:(JawaObjectRef*)value;
2527
-(JawaObjectRef*) getProp:(NSString*)key;
2628
-(int)getBuiltinID:(NSString*)funcName;
2729
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName;
2830
-(NSString*)description;
29-
-(NSString*) toJSON:(NSMutableString*)ret;
31+
-(NSMutableString*) toJSON:(NSMutableString*)ret;
3032
@end
3133

3234
#endif /* JawaObject_h */

JawaScriptExecutive-iOS/JawaObject.m

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414

1515
@implementation JawaObject
1616

17-
-(id) init {
17+
+(void)initialize {
18+
if (self == [JawaObject class]) {
19+
objectPrototype = [[NSMutableDictionary alloc]init];
20+
}
21+
}
22+
23+
-(id) initIn:(JawaExecutor *)ex {
1824
self = [super init];
19-
_properties = [[NSMutableDictionary alloc] init];
20-
_prototype = objectPrototype;
25+
if (self) {
26+
_properties = [[NSMutableDictionary alloc] init];
27+
_prototype = objectPrototype;
28+
_executor = ex;
29+
}
2130
return self;
2231
}
2332

@@ -45,20 +54,20 @@ -(int)getBuiltinID:(NSString*)funcName {
4554
-(JawaObjectRef*)invokeBuiltin:(NSString*)funcName {
4655
int ID = [self getBuiltinID:funcName];
4756
switch(ID) {
48-
// toJSON()
57+
// toJSON()
4958
case 0: {
50-
return [JawaObjectRef RefWithString:[self toJSON:nil]];
59+
return [JawaObjectRef RefWithString:[self toJSON:nil] in:self.executor];
5160
}
5261
}
5362
return nil;
5463
}
5564

5665
-(NSString*) description {
57-
return [NSString stringWithFormat:@""];
66+
return @"";
5867
}
5968

60-
-(NSString*) toJSON:(NSMutableString*)ret {
61-
return [NSString stringWithFormat:@""];
69+
-(NSMutableString*) toJSON:(NSMutableString*)ret {
70+
return [NSMutableString stringWithFormat: @""];
6271
}
6372

6473
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// JawaObjectProtected.h
3+
// JawaScriptExecutive-iOS
4+
//
5+
// Created by Chi-Wei (Jack) Wang on 2016/1/27.
6+
//
7+
//
8+
9+
#ifndef JawaObjectProtected_h
10+
#define JawaObjectProtected_h
11+
12+
@interface JawaObject () {
13+
@protected
14+
NSMutableDictionary* _properties;
15+
NSMutableDictionary* _prototype;
16+
__weak JawaExecutor* _executor;
17+
}
18+
19+
@end
20+
21+
#endif /* JawaObjectProtected_h */

JawaScriptExecutive-iOS/JawaObjectRef.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef JawaObjectRef_h
1010
#define JawaObjectRef_h
1111

12-
#define QUANTUM 0.0000000000000001
12+
#import "JawaExecutor.h"
1313

1414
@class JawaArray;
1515
@class JawaFunc;
@@ -22,22 +22,23 @@
2222

2323
@property (strong) NSObject* object;
2424
@property (weak) JawaObjectRef* appliedOn;
25+
@property (weak) JawaExecutor* executor;
2526

26-
-(id)init;
27-
-(id)initWithNumber:(double)number;
28-
-(id)initWithString:(NSString*)string;
29-
-(id)initWithBoolean:(bool)tf;
27+
-(id)initIn:(JawaExecutor*)ex;
28+
-(id)initWithNumber:(double)number in:(JawaExecutor*)ex;
29+
-(id)initWithString:(NSString*)string in:(JawaExecutor*)ex;
30+
-(id)initWithBoolean:(bool)tf in:(JawaExecutor*)ex;
3031
-(id)initWithJawaArray:(JawaArray*)array;
3132
-(id)initWithJawaFunc:(JawaFunc*)func;
3233
-(id)initWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj;
3334
-(id)initWithJawaObject:(JawaObject*)obj;
3435
-(NSString*)description;
3536
-(id)transfer;
3637

37-
+(id)Ref;
38-
+(id)RefWithNumber:(double)number;
39-
+(id)RefWithString:(NSString*)string;
40-
+(id)RefWithBoolean:(bool)tf;
38+
+(id)RefIn:(JawaExecutor*)ex;
39+
+(id)RefWithNumber:(double)number in:(JawaExecutor*)ex;
40+
+(id)RefWithString:(NSString*)string in:(JawaExecutor*)ex;
41+
+(id)RefWithBoolean:(bool)tf in:(JawaExecutor*)ex;
4142
+(id)RefWithJawaArray:(JawaArray*)array;
4243
+(id)RefWithJawaFunc:(JawaFunc*)func;
4344
+(id)RefWithJawaFunc:(JawaFunc*)func on:(JawaObjectRef*)obj;

0 commit comments

Comments
 (0)