Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
1 Classes/Core/SVBridgeSupport.m
@@ -1442,6 +1442,7 @@ id sv_calling_objc_method_handler(id target, Method m, NSMutableArray *args, SVF
[_context createSymbolTable];
[_context setObject:context forKey:SV_PARENT_CONTEXT_KEY];
[_context setObject:BL(YES) forKey:@"__SV_IN_OBJECT"];
+ [_context setObject:realClass forKey:@"__SV_OBJECT_CLASS"];
SVSymbolTable * table = [_context symbolTable];
SVSymbol * _self = [table symbolWithName:@"self"];
_self.value = target;
View
41 Classes/Core/SVFunction.m
@@ -511,6 +511,35 @@ - (id) evalCallWithContext:(NSMutableDictionary *)context
extern NSMutableDictionary * sv_block_table;
+BOOL isInObject(NSMutableDictionary * context);
+Class objectClass(NSMutableDictionary* context);
+
+Class checkForNestedClass(Class c,NSString * className) {
+ Class oldClass;
+ Class parentClass;
+ do {
+ oldClass = parentClass;
+ NSString * nested_class = [NSString stringWithFormat:@"%@#%@",NormalizedClassNameFor(c),className];
+ if (NSClassFromString(nested_class)) {
+ // Special case for classes.
+ if (![[SVSymbolTable sharedTable] lookupSymbol:nested_class]) {
+ SVSymbol * sym = [[SVSymbolTable sharedTable] symbolWithName:nested_class isConst:YES];
+ sym.value = [SVClassWrapper wrapperFromObjCClass:NSClassFromString(nested_class)];
+ return sym.value;
+ } else {
+ SVSymbol * sym = [[SVSymbolTable sharedTable] lookupSymbol:nested_class];
+ if (!sym.value) {
+ sym.value = [SVClassWrapper wrapperFromObjCClass:NSClassFromString(nested_class)];
+ }
+ return sym.value;
+ }
+ }
+ parentClass = class_getSuperclass(c);
+ c = parentClass;
+ } while(parentClass != oldClass);
+ return Nil;
+}
+
- (id) evalObjectFunctionCallWithContext:(NSMutableDictionary *)context {
SVInstanceRef * ref = self.name;
id lhs = [ref.lvalue evaluateWithContext:context];
@@ -529,6 +558,18 @@ - (id) evalObjectFunctionCallWithContext:(NSMutableDictionary *)context {
}
lhs = sym.value;
}
+ } else if(isInObject(context)) {
+ Class main_class = objectClass(context);
+ if(!(lhs = checkForNestedClass(main_class,varName))) {
+ if([ref.key isEqual:@"=="]) {
+ if(self.arguments.count && [[[self.arguments objectAtIndex:0] value] isEqual:__sv_nil])
+ return BL(YES);
+ else
+ return __sv_nil;
+ } else
+ return __sv_nil;
+ }
+
} else {
if([ref.key isEqual:@"=="]) {
if(self.arguments.count && [[[self.arguments objectAtIndex:0] value] isEqual:__sv_nil])
View
12 Classes/Core/SVVariable.m
@@ -38,6 +38,18 @@ BOOL isInObject(NSMutableDictionary* context) {
return objkey != nil;
}
+Class objectClass(NSMutableDictionary* context) {
+ if(!isInObject(context))
+ return Nil;
+ id objkey = nil;
+ while(context && !(objkey = [context objectForKey:@"__SV_IN_OBJECT"]))
+ context = [context objectForKey:SV_PARENT_CONTEXT_KEY];
+ if(objkey)
+ return [context objectForKey:@"__SV_OBJECT_CLASS"];
+ else
+ return Nil;
+}
+
@implementation SVVariable
+(void) initialize {
View
5 Classes/Types/SVCategory.m
@@ -82,7 +82,10 @@ - (id) evaluateWithContext:(NSMutableDictionary *)context
BOOL res;
for (id content in self.contents) {
- if ([content isKindOfClass:[SVIvar class]]) {
+ if([content isKindOfClass:[SVClass class]]) {
+ [(SVClass*)content setName:[NSString stringWithFormat:@"%@#%@",self.className,[content name]]];
+ [content evaluateWithContext:context];
+ } else if ([content isKindOfClass:[SVIvar class]]) {
NSString * ivarName = [content name];
if (!class_addMethod(_svClass, NSSelectorFromString(ivarName), (IMP)__sv_stubPropertyGetter, "@@:")) {
continue;
View
5 Classes/Types/SVClass.m
@@ -729,7 +729,10 @@ - (id) evaluateWithContext:(NSMutableDictionary *)context
[context setObject:BL(YES) forKey:self.name];
for (id content in self.contents) {
- if ([content isKindOfClass:[SVIvar class]]) {
+ if([content isKindOfClass:[SVClass class]]) {
+ [(SVClass*)content setName:[NSString stringWithFormat:@"%@#%@",self.name,[content name]]];
+ [content evaluateWithContext:context];
+ } else if ([content isKindOfClass:[SVIvar class]]) {
NSString * ivarName = [content name];
if (!class_addMethod(_svClass, NSSelectorFromString(ivarName), (IMP)__sv_stubPropertyGetter, "@@:")) {
return BL(NO);
View
3 TODO
@@ -1,8 +1,5 @@
These are plans for the future of Silver:
-Parallel assignments:
- a,b = c,d
-
Modules:
Modules, like in Ruby, will be similar to classes but can be mixed into classes using the include keyword.
View
31 Tests/SVClassSystemTests.m
@@ -472,4 +472,35 @@ -(void) testCVarDistinct {
P(var);
assertThat(var,is(equalTo(expect)));
}
+
+-(void) testNestedClass {
+ PC(@"class NestedClassTest { class NestedClassTestInner { def ret { return 10; }; }; def my_ret { x = NestedClassTestInner.alloc.init; return x.ret; }; }; y = NestedClassTest.alloc.init; y.my_ret;");
+ P(var);
+ assertThat(var,is(equalTo(N(10))));
+}
+
+-(void) testNestedClass2 {
+ PC(@"class NestedClassTest2 { class NestedClassTestInner { def ret { return 10; }; }; }; x = NestedClassTestInner.alloc.init;");
+ P(var);
+ assertThat(var,is(equalTo(nil)));
+}
+
+-(void) testNestedClassDifferent {
+ NSArray *expect = [NSArray arrayWithObjects:N(10),N(25),nil];
+ PC(@"class NestedClassTest3 { class NestedClassTestInner { def ret { return 10; }; }; def my_ret { x = NestedClassTestInner.alloc.init; return x.ret; }; }; class NestedClassTest4 { class NestedClassTestInner { def ret { return 25; }; }; def my_ret { x = NestedClassTestInner.alloc.init; return x.ret; }; }; na = NestedClassTest3.alloc.init; nb = NestedClassTest4.alloc.init; na,nb=na.my_ret,nb.my_ret;");
+ P(var);
+ assertThat(var,is(equalTo(expect)));
+}
+
+-(void) testNestedClassSuper {
+ PC(@"class NestedClassTestSuper { class NestedClassTestInner { def ret { return 10; }; }; }; class NestedClassTest5 < NestedClassTestSuper { def my_ret { x = NestedClassTestInner.alloc.init; return x.ret; }; }; y = NestedClassTest5.alloc.init; y.my_ret;");
+ P(var);
+ assertThat(var,is(equalTo(N(10))));
+}
+
+-(void) testCategoryNestedClass {
+ PC(@"class NSNumber { class NestedClassTestInner { def ret { return 25; }; }; def my_ret { x = NestedClassTestInner.alloc.init; return x.ret if self > 10; }; }; 15.my_ret;");
+ P(var);
+ assertThat(var,is(equalTo(N(25))));
+}
@end

No commit comments for this range

Something went wrong with that request. Please try again.