Added empty implementation of script objects

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@17433 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Stefan Urbanek 2003-08-05 20:23:47 +00:00
parent da5771113f
commit d8d28d9eee
13 changed files with 310 additions and 13 deletions

View file

@ -1,3 +1,7 @@
2003 Aug 5 Stefan Urbanek <urbanek@host.sk>
* Added STScriptObject and STMethod.
2003 Jun 15
* NSInvocation+additions: added unknown selector creation; created a

View file

@ -9,9 +9,7 @@
<h1><a name="title$STObjCRuntime">STObjCRuntime autogsdoc generated documentation</a></h1>
<h3>Authors</h3>
<dl>
<dt>Stefan Urbanek(<a href="mailto:urbanek@host.sk"><code>
urbanek@host.sk
</code></a>)</dt>
<dt>Stefan Urbanek (<a href="mailto:urbanek@host.sk"><code>urbanek@host.sk</code></a>)</dt>
<dd>
</dd>
</dl>

View file

@ -1,4 +1,9 @@
2003 May 17 Stefan Urbanek <urbanek@host.sk>
2003 Aug 5 Stefan Urbanek <urbanek@host.sk>
* STScriptObject renamed to STSmalltalkScriptObject, because of steptalk
core change.
2003 May 17 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: treat decimal point followed by whitespace as '.' dot -
end of statement.

View file

@ -45,7 +45,7 @@ Smalltalk_OBJC_FILES = \
STLiterals.m \
STMessage.m \
STMethodContext.m \
STScriptObject.m \
STSmalltalkScriptObject.m \
STStack.m \
STUndefinedObject+additions.m \
STSelector+additions.m \

View file

@ -32,7 +32,7 @@
#import "STLiterals.h"
#import "STMessage.h"
#import "STMethodContext.h"
#import "STScriptObject.h"
#import "STSmalltalkScriptObject.h"
#import "STStack.h"
#import <StepTalk/STEnvironment.h>
@ -453,7 +453,7 @@ static Class NSInvocation_class = nil;
break;
case STPushRecVarBytecode:
object = [(STScriptObject *)receiver instanceVariableAtIndex:
object = [(STSmalltalkScriptObject *)receiver instanceVariableAtIndex:
bytecode.arg1];
STDebugBytecodeWith(bytecode,object);
STPush(stack,object);
@ -479,7 +479,7 @@ static Class NSInvocation_class = nil;
case STPopAndStoreRecVarBytecode:
STDebugBytecode(bytecode);
[(STScriptObject *)receiver setInstanceVariable:STPop(stack)
[(STSmalltalkScriptObject *)receiver setInstanceVariable:STPop(stack)
atIndex:bytecode.arg1];
break;

View file

@ -23,7 +23,7 @@
#import "STCompiledScript.h"
#import "STScriptObject.h"
#import "STSmalltalkScriptObject.h"
#import "STCompiledMethod.h"
#import <StepTalk/STObjCRuntime.h>
@ -92,12 +92,12 @@ static SEL finalizeSelector;
- (id)executeInEnvironment:(STEnvironment *)env
{
STScriptObject *object;
STSmalltalkScriptObject *object;
int methodCount;
id retval = nil;
object = [[STScriptObject alloc] initWithEnvironment:env
object = [[STSmalltalkScriptObject alloc] initWithEnvironment:env
compiledScript:self];
methodCount = [methodDictionary count];

View file

@ -1,5 +1,5 @@
/**
STScriptObject.h
STSmalltalkScriptObject.h
Object that represents script
Copyright (c) 2002 Free Software Foundation
@ -30,7 +30,7 @@
@class STCompiledScript;
@class STEnvironment;
@interface STScriptObject:NSObject
@interface STSmalltalkScriptObject:NSObject
{
NSString *name;
STBytecodeInterpreter *interpreter;

View file

@ -0,0 +1,170 @@
/**
STSmalltalkScriptObject.m
Object that represents script
Copyright (c) 2002 Free Software Foundation
This file is part of the StepTalk project.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA.
*/
#import "STSmalltalkScriptObject.h"
#import "STBytecodeInterpreter.h"
#import "STCompiledScript.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSString.h>
#import <StepTalk/NSInvocation+additions.h>
#import <StepTalk/STEnvironment.h>
#import <StepTalk/STObjCRuntime.h>
#import <StepTalk/STExterns.h>
@implementation STSmalltalkScriptObject
- initWithEnvironment:(STEnvironment *)env
compiledScript:(STCompiledScript *)compiledScript
{
int count = [compiledScript variableCount];
int i;
[super init];
NSDebugLLog(@"STEngine",
@"creating script object %p with %i ivars",compiledScript,
count);
environment = RETAIN(env);
script = RETAIN(compiledScript);
variables = [[NSMutableArray alloc] initWithCapacity:count];
for(i=0;i<count;i++)
{
[variables addObject:STNil];
}
return self;
}
- (void)dealloc
{
RELEASE(interpreter);
RELEASE(script);
RELEASE(variables);
RELEASE(environment);
[super dealloc];
}
- (STCompiledScript *)script
{
return script;
}
- (void)setInstanceVariable:(id)anObject atIndex:(int)anIndex;
{
if(anObject == nil)
{
anObject = STNil;
}
[variables replaceObjectAtIndex:anIndex withObject:anObject];
}
- (id)instanceVariableAtIndex:(int)anIndex;
{
return [[variables objectAtIndex:anIndex] self];
}
- (BOOL)respondsToSelector:(SEL)aSelector
{
if( [super respondsToSelector:(SEL)aSelector] )
{
return YES;
}
return ([script methodWithName:NSStringFromSelector(aSelector)] != nil);
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
NSMethodSignature *signature = nil;
signature = [super methodSignatureForSelector:sel];
if(!signature)
{
signature = STMethodSignatureForSelector(sel);
}
return signature;
}
- (void) forwardInvocation:(NSInvocation *)invocation
{
STCompiledMethod *method;
NSString *methodName = NSStringFromSelector([invocation selector]);
NSMutableArray *args;
id arg;
int index;
int count;
id retval = nil;
if(!interpreter)
{
NSDebugLLog(@"STEngine",
@"creating new interpreter for script '%@'",
name);
interpreter = [[STBytecodeInterpreter alloc] init];
[interpreter setEnvironment:environment];
}
if([methodName isEqualToString:@"exit"])
{
[interpreter halt];
return;
}
method = [script methodWithName:methodName];
count = [[invocation methodSignature] numberOfArguments];
NSDebugLLog(@"STSending",
@"script object perform: %@ with %i args",
methodName,count-2);
args = [NSMutableArray array];
for(index = 2; index < count; index++)
{
arg = [invocation getArgumentAsObjectAtIndex:index];
[args addObject:arg];
}
NSDebugLLog(@"STSending",
@">> forwarding to self ...");
retval = [interpreter interpretMethod:method
forReceiver:self
arguments:args];
NSDebugLLog(@"STSending",
@"<< returned from forwarding");
[invocation setReturnValue:&retval];
}
@end

View file

@ -41,6 +41,8 @@ libStepTalk_OBJC_FILES = \
STScript.m \
STScriptsManager.m \
STScripting.m \
STMethod.m \
STScriptObject.m \
STSelector.m \
STStructure.m \
STUndefinedObject.m \
@ -56,6 +58,8 @@ STEPTALK_HEADER_FILES = \
STLanguage.h \
STObjCRuntime.h \
STObjectReference.h \
STMethod.h \
STScriptObject.h \
STScript.h \
STScriptsManager.h \
STScripting.h \

View file

@ -0,0 +1,11 @@
/* 2003 Aug 5 */
#import <Foundation/NSObject.h>
@class STEngine;
@interface STMethod:NSObject
- (NSString *)source;
- (NSString *)methodName;
- (NSString *)languageName;
@end

View file

@ -0,0 +1,28 @@
/* 2003 Aug 5 */
#import <Foundation/NSObject.h>
@class NSMutableDictionary;
@class NSDictionary;
@class NSArray;
@class STMethod;
@interface STScriptObject:NSObject
{
NSMutableDictionary *ivars;
NSMutableDictionary *methods;
}
- initWithInstanceVariableNames:(NSString *)names;
- (void)setObject:(id)anObject forVariable:(NSString *)aName;
- (id)objectForVariable:(NSString *)aName;
- (NSArray *)instanceVariableNames;
- (void)addMethod:(STMethod *)aMethod;
- (STMethod *)methodWithName:(NSString *)aName;
- (void)removeMethod:(STMethod *)aMethod;
- (void)removeMethodWithName:(NSString *)aName;
- (NSArray *)methodNames;
- (NSDictionary *)methodDictionary;
@end

18
Source/STMethod.m Normal file
View file

@ -0,0 +1,18 @@
/* 2003 Aug 5 */
#import <StepTalk/STMethod.h>
@implementation STMethod
- (NSString *)source
{
[self _notImplemented:_cmd];
}
- (NSString *)methodName
{
[self _notImplemented:_cmd];
}
- (NSString *)languageName
{
[self _notImplemented:_cmd];
}
@end

59
Source/STScriptObject.m Normal file
View file

@ -0,0 +1,59 @@
/* 2003 Aug 5 */
#import "StepTalk/STScriptObject.h"
@implementation STScriptObject
- initWithInstanceVariableNames:(NSString *)names
{
self = [super init];
methods = [[NSMutableDictionary alloc] init];
return self;
}
- (void)dealloc
{
RELEASE(methods);
RELEASE(ivars);
[super dealloc];
}
- (void)setObject:(id)anObject forVariable:(NSString *)aName
{
[self _notImplemented:_cmd];
}
- (id)objectForVariable:(NSString *)aName
{
[self _notImplemented:_cmd];
}
- (NSArray *)instanceVariableNames
{
[self _notImplemented:_cmd];
}
- (void)addMethod:(STMethod *)aMethod
{
[methods setObject:aMethod forKey:[aMethod methodName]];
}
- (STMethod *)methodWithName:(NSString *)aName
{
return [methods objectForKey:aName];
}
- (void)removeMethod:(STMethod *)aMethod
{
[self _notImplemented:_cmd];
}
- (void)removeMethodWithName:(NSString *)aName
{
[methods removeObjectForKey:aName];
}
- (NSArray *)methodNames
{
return [methods allKeys];
}
- (NSDictionary *)methodDictionary
{
return [NSDictionary dictionaryWithDictionary:methods];
}
@end