[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Objective-C - Smalltalk bridge
From: |
Marcel Weiher |
Subject: |
Re: Objective-C - Smalltalk bridge |
Date: |
Sat, 21 May 2005 13:38:49 +0100 |
On 12 May 2005, at 23:37, Stefan Urbanek wrote:
Issues I had:
- the bridge requires readline and ncurses - can be that eliminated
somehow?
- the program ended on Smalltalk readline
- how can I get ObjC proxy for a Smalltalk object? I was not able
to say
anything about a result of an execution. I want to do someting like:
Smalltalk *smalltalk; /* say this exists */
NSMutableArray *array; /* this exists too */
...
result = [smalltalk execute:@"1+1"];
[array addObject:result];
NSLog(@"Added number %i", [result intValue]);
Also ... how can I reference ObjectiveC objects from Smalltalk?
Would it
be possible to give more examples?
With Objective-Smalltalk, you get that, but without a bridge or proxies:
marcel@tpol[marcel]cat > stexec.m
#import <MPWTalk/MPWStCompiler.h>
int main( int argc, char *argv[] ) {
id pool = [NSAutoreleasePool new];
id eval = [MPWStCompiler new];
id result = [eval evaluate:@"1+1."];
NSLog(@"result: %d",[result intValue]);
exit(0);
return 0;
}
marcel@tpol[marcel]cc -O -Wall -o stexec stexec.m -framework MPWTalk -
framework MPWFoundation -framework Foundation
stexec.m: In function 'main':
stexec.m:4: warning: unused variable 'pool'
marcel@tpol[marcel]./stexec
2005-05-21 13:11:34.516 stexec[714] result: 2
marcel@tpol[marcel]
What is Objective-Smalltalk? In a nutshell: a Smalltalk syntax for
the Objective-C runtime + language semantics. So there are no
proxies and no two runtimes that have to talk to each other. This
allows Objective-ST to be very compact, currently only around 1.5
KLOC, with several hundred of those being the unit tests. That
includes a basic compiler/interpreter (compiler for the syntax,
'interpreter' for running the returned Objective-C objects that
represent a script/method) ready for integration. It is still early
days, but good enough to use in some of my shipping products.
I am currently working on a (very primitive) little method browser:
Another part: stsh, a smalltalk shell, both for interactive and
scripting use.
marcel@tpol[stsh]stsh
> 3 + 4
7
> last * 6
42
> theAnswer := last
42
> theAnswer class
NSCFNumber
> context scanner setIntClass:NSDecimalNumber
> 1 class
NSDecimalNumber
>
-------------- pdfdump.stsh ---------------
#!/usr/local/bin/stsh
filename := args objectAtIndex:1
stdout print: 'pdfdump of: '
stdout println: filename
data := NSData dataWithContentsOfMappedFile: filename
pdf := (MPWPDFFile alloc initWithPdfData:data ) autorelease
pages := pdf pages
stdout writeObject: pages count
stdout println: ' pages'
stdout writeObject:pages
contentStreams := pages collect contentStreams
allStreams := contentStreams collect lastObject
allContent := allStreams collect stringValue
stdout println: 'got allContent'
stdout writeObject:allContent
--------------- pdfdump.stsh -------------------
In the works: a gcc front end, though that is *quite* a struggle.
Doing a JIT might be simpler... :-(
Cheers,
Marcel