-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntentionalIDEAppDelegate.m
100 lines (87 loc) · 3.16 KB
/
IntentionalIDEAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// IntentionalIDEAppDelegate.m
// IntentionalIDE
//
// Created by cfregin on 29.03.10.
// Copyright 2010 Carsten Fregin. All rights reserved.
//
#import "IntentionalIDEAppDelegate.h"
//#import "generated/clang.c"
@implementation IntentionalIDEAppDelegate
@synthesize window;
@synthesize loadedClasses;
-(void)gotClasses:(NSNotification*)notification{
[self setLoadedClasses:[[notification userInfo] valueForKey:@"NSLoadedClasses"]];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
ANTLRParser *parser = [[ANTLRParser alloc] init];
[parser release];
/* pANTLR3_UINT8 fName;
pANTLR3_INPUT_STREAM input;
pJavaScriptLexer lxr;
pANTLR3_COMMON_TOKEN_STREAM tstream;
pJavaScriptParser psr;
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *demoPath = [NSString stringWithFormat:@"%@/demo.js",resourcePath];
fName = (pANTLR3_UINT8)[demoPath UTF8String];
input = antlr3AsciiFileStreamNew(fName);
if (input == NULL )
{
fprintf(stderr, "Unable to open file %s\n", (char *)fName);
exit(ANTLR3_ERR_NOMEM);
}
lxr = JavaScriptLexerNew(input);
if (lxr == NULL)
{
fprintf(stderr, "Unable to create the lexer due to malloc() failure1\n");
exit(ANTLR3_ERR_NOMEM);
}
tstream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
if (tstream == NULL)
{
fprintf(stderr, "Out of memory trying to allocate token stream\n");
exit(ANTLR3_ERR_NOMEM);
}
psr = JavaScriptParserNew(tstream); // SimpleParserNew is generated by ANTLR3
if (tstream == NULL)
{
fprintf(stderr, "Out of memory trying to allocate parser\n");
exit(ANTLR3_ERR_NOMEM);
}
psr->program(psr);
psr ->free (psr); psr = NULL;
tstream ->free (tstream); tstream = NULL;
lxr ->free (lxr); lxr = NULL;
input ->close (input); input = NULL;*/
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotClasses:) name:NSBundleDidLoadNotification object:nil];
//Load framework dynamicaly
Class theClass2 = NSClassFromString(@"DynaLoaderTest");// [localFramework classNamed:@"DynaLoaderTest"];
//Class schould be null
assert(theClass2==nil);
[theClass2 release];
//now load
localFramework = [NSBundle bundleWithPath:@"IntentionalObjectiveC.framework"];
if([localFramework load]){
Class theClass2 = NSClassFromString(@"DynaLoaderTest");// [localFramework classNamed:@"DynaLoaderTest"];
assert(theClass2);
//Class schould be null
id myobj = [[theClass2 alloc] init];
NSLog(@"Now:%@" , [myobj getTheName]);
[myobj release];
[theClass2 release];
}
//unload
if([localFramework unload]){
Class theClass3 = NSClassFromString(@"DynaLoaderTest");// [localFramework classNamed:@"DynaLoaderTest"];
//assert(theClass3==nil);
}
IntentionalClass *mainClass = [[IntentionalClass alloc] init];
IntentionalMethod *mainMethod = [[IntentionalMethod alloc] initWithLanguage:JAVA_SCRIPT name:@"main" code:@"trace('hello');"];
[mainClass addMethod:mainMethod];
CodeExecutor *executor = [[CodeExecutor alloc] initWithRoot:mainClass];
[executor start];
// [mainMethod autorelease];
[mainClass release];
[executor release];
}
@end