forked from pmougin/F-Script
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFSInterpreter.m
156 lines (129 loc) · 3.41 KB
/
FSInterpreter.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* FSInterpreter.m Copyright (c) 1998-2009 Philippe Mougin. */
/* This software is open source. See the license. */
#import "build_config.h"
#import "FSInterpreter.h"
#import "FSInterpreterPrivate.h"
#import "FSExecutor.h"
#import "FSBooleanPrivate.h"
#import "FSVoidPrivate.h"
#import "FSArray.h"
#import "FSObjectBrowser.h"
#import "FSCompiler.h"
@implementation FSInterpreter
+ (BOOL) validateSyntaxForIdentifier:(NSString *)identifier
{
return [FSCompiler isValidIdentifier:identifier];
}
+ (void)initialize
{
static BOOL tooLate = NO;
if (tooLate) return;
tooLate = YES;
// Dynamic class loading
NSString *repositoryPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"FScriptRepositoryPath"];
if (repositoryPath)
{
NSString *dirName = [repositoryPath stringByAppendingPathComponent:@"classes"];
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:dirName];
NSString *pname;
while ((pname = [direnum nextObject]))
{
if ([[pname pathExtension] isEqualToString:@"bundle"] || [[pname pathExtension] isEqualToString:@"framework"])
{
NSBundle *bundle = [NSBundle bundleWithPath:[dirName stringByAppendingPathComponent:pname]];
[direnum skipDescendents]; // don't enumerate this directory
[bundle principalClass];
}
}
}
}
+ (FSInterpreter *)interpreter
{
return [[[self alloc] init] autorelease];
}
- (FSObjectBrowserButtonCtxBlock *) objectBrowserButtonCtxBlockFromString:(NSString *)source // May raise
{
return [FSObjectBrowserButtonCtxBlock blockWithSource:source parentSymbolTable:[executor symbolTable]]; // May raise
}
- (void)browse
{
FSObjectBrowser *bb = [FSObjectBrowser objectBrowserWithRootObject:nil interpreter:self];
[bb browseWorkspace];
[bb makeKeyAndOrderFront:nil];
}
- (void)browse:(id)anObject
{
[[FSObjectBrowser objectBrowserWithRootObject:anObject interpreter:self] makeKeyAndOrderFront:nil];
}
-(void)dealloc
{
//NSLog(@"FSInterpreter dealloc");
[executor breakCycles];
[executor interpreterIsDeallocating];
[executor release];
[super dealloc];
}
- (NSArray *) identifiers
{
return [executor allDefinedSymbols];
}
-(void)encodeWithCoder:(NSCoder *)coder
{
if ([coder allowsKeyedCoding])
{
[coder encodeObject:executor forKey:@"executor"];
}
else
{
[coder encodeObject:executor];
}
}
-(FSInterpreterResult *)execute:(NSString *)command
{
return [executor execute:command];
}
-(id)init
{
if ((self = [super init]))
{
executor = [[FSExecutor alloc] initWithInterpreter:self];
return self;
}
return nil;
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super init];
if ([coder allowsKeyedCoding])
{
executor = [[coder decodeObjectForKey:@"executor"] retain];
}
else
{
executor = [[coder decodeObject] retain];
}
return self;
}
- (void) installFlightTutorial
{
[executor installFlightTutorial];
}
- (id)objectForIdentifier:(NSString *)identifier found:(BOOL *)found
{
return [executor objectForSymbol:identifier found:found];
}
- (BOOL)setJournalName:(NSString *)filename
{
return [executor setJournalName:filename];
}
-(void)setObject:(id)object forIdentifier:(NSString *)identifier
{
[executor setObject:object forSymbol:identifier];
}
- (void)setShouldJournal:(BOOL)shouldJournal
{
[executor setShouldJournal:shouldJournal];
}
- (BOOL)shouldJournal
{ return [executor shouldJournal]; }
@end