00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _IMPULSE_FRAME_INLINE_
00009 #define _IMPULSE_FRAME_INLINE_
00010
00011 #include "../protos/array.h"
00012
00013 namespace impulse {
00014
00015
00016
00017
00018
00019 inline void* Frame::operator new( size_t size )
00020 {
00021 Frame* frame = (Frame*) ::operator new( size );
00022
00023
00024
00025 return frame;
00026 }
00027
00028 inline Frame::Frame( Frame* proto ) : _proto( proto ), _refCount( 0 ) { }
00029
00030
00031 inline Value Frame::getSlot( Symbol& symbol )
00032 {
00033 return slots()[&symbol];
00034 }
00035
00036 inline Value Frame::setSlot( Symbol& symbol, Value value )
00037 {
00038 if (slots().find( &symbol ) != slots().end())
00039 slots()[&symbol].decrRef();
00040
00041 value.incrRef();
00042
00043 return slots()[&symbol] = value;
00044 }
00045
00046
00047 inline Value Frame::send( Symbol& selector, Array& args )
00048 {
00049 return send( selector, args, this );
00050 }
00051
00052 inline Value Frame::send( Symbol& selector, Array& args, Value self )
00053 {
00054 BEG( "Frame::send( sel = " << selector.getName().c_str() << ", self = " << self.inspect() << " )" );
00055
00056 Value result = -1;
00057
00058 Value method = getSlot( selector );
00059
00060 if (method.getFrame() != _nil_.getFrame())
00061 {
00062 Array margs( this, &args );
00063
00064 try
00065 {
00066 result = method.eval( margs, self );
00067 }
00068 catch( string error )
00069 {
00070 cout << "** " << inspect() << "::" << selector.getName() << ": " << error << endl;
00071 }
00072 }
00073 else if (proto() != NULL)
00074 {
00075 result = proto()->send( selector, args, self );
00076 }
00077 else
00078 {
00079 cout << "*** " << inspect() << " Slot not found: " << selector.getName() << endl;
00080 }
00081
00082 END( result.inspect() );
00083
00084 return result;
00085 }
00086
00087 }
00088
00089 #endif