Skip to content

Commit

Permalink
un-namespace Chuck_DL_Api
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 9, 2023
1 parent e25918b commit bdcc177
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 57 deletions.
15 changes: 6 additions & 9 deletions src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll )
}

// get DL API reference | 1.5.1.5
m_api = Chuck_DL_Api::Api::instance();
m_api = Chuck_DL_Api::instance();

linepos = 0;
errorEncountered = FALSE;
Expand Down Expand Up @@ -1396,10 +1396,7 @@ Chuck_DL_MainThreadHook::Chuck_DL_MainThreadHook( f_mainthreadhook hook, f_maint
// module load-time; this ensures that the actual instantiation is in
// alignment with whatever host is loading the module.
//-----------------------------------------------------------------------------
namespace Chuck_DL_Api
{
Api Api::g_api;
}
Chuck_DL_Api Chuck_DL_Api::g_api;


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1935,7 +1932,7 @@ static t_CKBOOL CK_DLL_CALL ck_array_int_get_key( Chuck_DL_Api::ArrayInt a, cons
//-----------------------------------------------------------------------------
// constructor for the VMApi; connects function pointers to host-side impl
//-----------------------------------------------------------------------------
Chuck_DL_Api::Api::VMApi::VMApi() :
Chuck_DL_Api::VMApi::VMApi() :
srate(ck_srate),
now(ck_now),
create_event_buffer(ck_create_event_buffer),
Expand All @@ -1952,7 +1949,7 @@ remove_all_shreds(ck_remove_all_shreds)
//-----------------------------------------------------------------------------
// constructor for the ObjectApi; connects function pointers to host-side impl
//-----------------------------------------------------------------------------
Chuck_DL_Api::Api::ObjectApi::ObjectApi() :
Chuck_DL_Api::ObjectApi::ObjectApi() :
get_type(ck_get_type),
create(ck_create_with_shred),
create_without_shred(ck_create_without_shred),
Expand Down Expand Up @@ -1981,7 +1978,7 @@ array_int_get_key(ck_array_int_get_key)
//-----------------------------------------------------------------------------
// constructor for the TypeApi; connects function pointers to host-side impl
//-----------------------------------------------------------------------------
Chuck_DL_Api::Api::TypeApi::TypeApi() :
Chuck_DL_Api::TypeApi::TypeApi() :
lookup(ck_type_lookup),
get_vtable_offset(ck_get_vtable_offset),
is_equal(ck_type_isequal),
Expand Down Expand Up @@ -2021,7 +2018,7 @@ Chuck_DL_Return CK_DLL_CALL ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t
// pack the args_list into memory
func->pack_cache( args_list, numArgs );
// call the function | added 1.3.0.0: the DL API instance
f( obj, func->args_cache, &RETURN, vm, caller_shred, Chuck_DL_Api::Api::instance() );
f( obj, func->args_cache, &RETURN, vm, caller_shred, Chuck_DL_Api::instance() );
}
else
{
Expand Down
32 changes: 16 additions & 16 deletions src/core/chuck_dl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ struct Chuck_DL_Ctrl;
union Chuck_DL_Return;
struct Chuck_DL_MainThreadHook;
struct Chuck_DLL;
namespace Chuck_DL_Api { struct Api; }
struct Chuck_DL_Api;
// un-namespaced Chuck_DL_Api | 1.5.1.5 (ge)
// namespace Chuck_DL_Api { struct Api; }

// object forward references
struct Chuck_UGen;
Expand Down Expand Up @@ -170,7 +172,7 @@ struct Chuck_UAnaBlobProxy;
#define CK_DLL_CALL
#endif

typedef const Chuck_DL_Api::Api *CK_DL_API;
typedef const Chuck_DL_Api * CK_DL_API;



Expand Down Expand Up @@ -818,18 +820,16 @@ Chuck_DL_Return CK_DLL_CALL ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t
//-----------------------------------------------------------------------------
// dynamic linking callable API to ChucK's innards
//-----------------------------------------------------------------------------
namespace Chuck_DL_Api
struct Chuck_DL_Api
{
typedef Chuck_Object * Object;
typedef Chuck_Type * Type;
typedef Chuck_String * String;
typedef Chuck_ArrayInt * ArrayInt; // 1.5.0.1 (ge) added
typedef Chuck_Object * Object;
typedef Chuck_Type * Type;
typedef Chuck_String * String;
typedef Chuck_ArrayInt * ArrayInt; // 1.5.0.1 (ge) added

struct Api
{
public:
static Api g_api;
static inline const Api * instance() { return &g_api; }
static Chuck_DL_Api g_api;
static inline const Chuck_DL_Api * instance() { return &g_api; }

// api to access host-side ChucK virtual machine
struct VMApi
Expand Down Expand Up @@ -922,23 +922,23 @@ struct Api
} * const type;

// constructor
Api() :
Chuck_DL_Api() :
vm(new VMApi),
object(new ObjectApi),
type(new TypeApi)
{ }

private:
// make this object un-copy-able
Api( Api & a ) :
Chuck_DL_Api( Chuck_DL_Api & a ) :
vm(a.vm),
object(a.object),
type(a.type)
{ assert(0); };
// make this object un-copy-able, part 2
Api & operator=( Api & a ) { assert(0); return a; }
Chuck_DL_Api & operator=( Chuck_DL_Api & a ) { assert(0); return a; }
};
}




Expand All @@ -961,7 +961,7 @@ struct Api
#define RTLD_LAZY 0x1
#define RTLD_NOW 0x2
#define RTLD_LOCAL 0x4
#define RTLD_GLOBAL 0x8
#define RTLD_GLOBAL 0x8
#define RTLD_NOLOAD 0x10
#define RTLD_SHARED 0x20 /* not used, the default */
#define RTLD_UNSHARED 0x40
Expand Down
20 changes: 10 additions & 10 deletions src/core/chuck_instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4143,7 +4143,7 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Sh
{
// check type TODO: make this faster
if( type->allocator )
object = type->allocator( vm, shred, Chuck_DL_Api::Api::instance() );
object = type->allocator( vm, shred, Chuck_DL_Api::instance() );
else if( isa( type, vm->env()->ckt_fileio ) ) object = new Chuck_IO_File( vm );
else if( isa( type, vm->env()->ckt_event ) ) object = new Chuck_Event;
else if( isa( type, vm->env()->ckt_string ) ) object = new Chuck_String;
Expand Down Expand Up @@ -4967,15 +4967,15 @@ void Chuck_Instr_Func_Call_Member::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
{
// cast to right type
f_ctor f = (f_ctor)func->native_func;
// call (added 1.3.0.0 -- Chuck_DL_Api::Api::instance())
f( (Chuck_Object *)(*mem_sp), mem_sp + 1, vm, shred, Chuck_DL_Api::Api::instance() );
// call (added 1.3.0.0 -- Chuck_DL_Api::instance())
f( (Chuck_Object *)(*mem_sp), mem_sp + 1, vm, shred, Chuck_DL_Api::instance() );
}
else
{
// cast to right type
f_mfun f = (f_mfun)func->native_func;
// call the function (added 1.3.0.0 -- Chuck_DL_Api::Api::instance())
f( (Chuck_Object *)(*mem_sp), mem_sp + 1, &retval, vm, shred, Chuck_DL_Api::Api::instance() );
// call the function (added 1.3.0.0 -- Chuck_DL_Api::instance())
f( (Chuck_Object *)(*mem_sp), mem_sp + 1, &retval, vm, shred, Chuck_DL_Api::instance() );
}

// push the return
Expand Down Expand Up @@ -5110,9 +5110,9 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
}

// call the function
// (added 1.3.0.0 -- Chuck_DL_Api::Api::instance())
// (added 1.3.0.0 -- Chuck_DL_Api::instance())
// (added 1.4.1.0 -- base_type)
f( (Chuck_Type *)(*mem_sp), mem_sp+1, &retval, vm, shred, Chuck_DL_Api::Api::instance() );
f( (Chuck_Type *)(*mem_sp), mem_sp+1, &retval, vm, shred, Chuck_DL_Api::instance() );

// push the return
// 1.3.1.0: check type to use kind instead of size
Expand Down Expand Up @@ -5238,7 +5238,7 @@ void Chuck_Instr_Func_Call_Global::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
}

// call the function
f( mem_sp, &retval, vm, shred, Chuck_DL_Api::Api::instance() );
f( mem_sp, &retval, vm, shred, Chuck_DL_Api::instance() );

// push the return
// 1.3.1.0: check type to use kind instead of size
Expand Down Expand Up @@ -7287,8 +7287,8 @@ void Chuck_Instr_Cast_object2string::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
Chuck_Object * obj = (Chuck_Object *)(*sp);
// return
Chuck_DL_Return RETURN;
// get toString from it (added 1.3.0.0 -- Chuck_DL_Api::Api::instance())
object_toString( obj, NULL, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() );
// get toString from it (added 1.3.0.0 -- Chuck_DL_Api::instance())
object_toString( obj, NULL, &RETURN, vm, shred, Chuck_DL_Api::instance() );
// get pointer
Chuck_String * str = RETURN.v_string;
// set it
Expand Down
10 changes: 5 additions & 5 deletions src/core/chuck_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ CK_DLL_MFUN( ugen_op )

// for multiple channels
Chuck_DL_Return ret;
// added 1.3.0.0 -- Chuck_DL_Api::Api::instance()
// added 1.3.0.0 -- Chuck_DL_Api::instance()
for( t_CKUINT i = 0; i < ugen->m_multi_chan_size; i++ )
ugen_op( ugen->m_multi_chan[i], ARGS, &ret, VM, SHRED, API );
// added 1.3.0.2 -- apply op to subgraph outlet
Expand Down Expand Up @@ -1628,7 +1628,7 @@ CK_DLL_MFUN( ugen_next )

// for multiple channels
Chuck_DL_Return ret;
// added 1.3.0.0 -- Chuck_DL_Api::Api::instance()
// added 1.3.0.0 -- Chuck_DL_Api::instance()
for( t_CKUINT i = 0; i < ugen->m_multi_chan_size; i++ )
ugen_next( ugen->m_multi_chan[i], ARGS, &ret, VM, SHRED, API );
// added 1.3.0.2 -- apply op to subgraph outlet
Expand Down Expand Up @@ -1660,7 +1660,7 @@ CK_DLL_MFUN( ugen_gain )

// for multiple channels
Chuck_DL_Return ret;
// added 1.3.0.0 -- Chuck_DL_Api::Api::instance()
// added 1.3.0.0 -- Chuck_DL_Api::instance()
for( t_CKUINT i = 0; i < ugen->m_multi_chan_size; i++ )
ugen_gain( ugen->m_multi_chan[i], ARGS, &ret, VM, SHRED, API );
// added 1.3.0.2 -- apply gain to subgraph outlet
Expand Down Expand Up @@ -1773,7 +1773,7 @@ CK_DLL_CTOR( uana_ctor )
Chuck_UAnaBlobProxy * proxy = new Chuck_UAnaBlobProxy( blob );
// remember it
OBJ_MEMBER_INT(SELF, uana_offset_blob) = (t_CKINT)proxy;
// HACK: DANGER: manually call blob's ctor (added 1.3.0.0 -- Chuck_DL_Api::Api::instance())
// HACK: DANGER: manually call blob's ctor (added 1.3.0.0 -- Chuck_DL_Api::instance())
uanablob_ctor( blob, NULL, VM, SHRED, API );
}

Expand Down Expand Up @@ -1814,7 +1814,7 @@ CK_DLL_MFUN( uana_upchuck )
{
// for multiple channels
Chuck_DL_Return ret;
// added 1.3.0.0 -- Chuck_DL_Api::Api::instance()
// added 1.3.0.0 -- Chuck_DL_Api::instance()
for( t_CKUINT i = 0; i < uana->m_multi_chan_size; i++ )
uana_upchuck( uana->m_multi_chan[i], ARGS, &ret, VM, SHRED, API );

Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_oo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Chuck_Object::~Chuck_Object()
// sanity check
assert( type->info->dtor && type->info->dtor->native_func );
// REFACTOR-2017: do we know which VM to pass in? (currently NULL)
((f_dtor)(type->info->dtor->native_func))( this, NULL, NULL, Chuck_DL_Api::Api::instance() );
((f_dtor)(type->info->dtor->native_func))( this, NULL, NULL, Chuck_DL_Api::instance() );
}

// go up the inheritance
Expand Down
16 changes: 8 additions & 8 deletions src/core/chuck_ugen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ t_CKBOOL Chuck_UGen::system_tick( t_CKTIME now )

if( m_op > 0 ) // UGEN_OP_TICK
{
m_valid = tickf( this, m_multi_in_v, m_multi_out_v, 1, Chuck_DL_Api::Api::instance() );
m_valid = tickf( this, m_multi_in_v, m_multi_out_v, 1, Chuck_DL_Api::instance() );

if( !m_valid ) memset( m_multi_out_v, 0, sizeof(SAMPLE)*m_multi_chan_size );

Expand Down Expand Up @@ -1028,9 +1028,9 @@ t_CKBOOL Chuck_UGen::system_tick( t_CKTIME now )

if( m_op > 0 ) // UGEN_OP_TICK
{
// tick the ugen (Chuck_DL_Api::Api::instance() added 1.3.0.0)
// tick the ugen (Chuck_DL_Api::instance() added 1.3.0.0)
// REFACTOR-2017: removed NULL shred (ticks aren't outside shred)
if( tick ) m_valid = tick( this, m_sum, &m_current, Chuck_DL_Api::Api::instance() );
if( tick ) m_valid = tick( this, m_sum, &m_current, Chuck_DL_Api::instance() );
if( !m_valid ) m_current = 0.0f;
// apply gain and pan
m_current *= m_gain * m_pan;
Expand Down Expand Up @@ -1181,7 +1181,7 @@ t_CKBOOL Chuck_UGen::system_tick_v( t_CKTIME now, t_CKUINT numFrames )
{
// compute samples with tickf
// REFACTOR-2017: remove NULL shred
m_valid = tickf( this, m_multi_in_v, m_multi_out_v, numFrames, Chuck_DL_Api::Api::instance() );
m_valid = tickf( this, m_multi_in_v, m_multi_out_v, numFrames, Chuck_DL_Api::instance() );

// zero samples if not valid
if( !m_valid ) memset( m_multi_out_v, 0, sizeof(SAMPLE) * m_multi_chan_size * numFrames );
Expand Down Expand Up @@ -1257,10 +1257,10 @@ t_CKBOOL Chuck_UGen::system_tick_v( t_CKTIME now, t_CKUINT numFrames )
// evaluate single-channel tick
if( m_op > 0 ) // UGEN_OP_TICK
{
// tick the ugen (Chuck_DL_Api::Api::instance() added 1.3.0.0)
// tick the ugen (Chuck_DL_Api::instance() added 1.3.0.0)
if( tick )
for( j = 0; j < numFrames; j++ ) // REFACTOR-2017: remove NULL shred
m_valid = tick( this, m_sum_v[j], &(m_current_v[j]), Chuck_DL_Api::Api::instance() );
m_valid = tick( this, m_sum_v[j], &(m_current_v[j]), Chuck_DL_Api::instance() );
if( !m_valid )
for( j = 0; j < numFrames; j++ )
m_current_v[j] = 0.0f;
Expand Down Expand Up @@ -1544,9 +1544,9 @@ t_CKBOOL Chuck_UAna::system_tock( t_CKTIME now )

if( m_op > 0 ) // UGEN_OP_TOCK
{
// tock the uana (Chuck_DL_Api::Api::instance() added 1.3.0.0)
// tock the uana (Chuck_DL_Api::instance() added 1.3.0.0)
// REFACTOR-2017: remove NULL shred
if( tock ) m_valid = tock( this, this, blobProxy(), Chuck_DL_Api::Api::instance() );
if( tock ) m_valid = tock( this, this, blobProxy(), Chuck_DL_Api::instance() );
if( !m_valid ) { /* clear out blob? */ }
// timestamp the blob
blobProxy()->when() = now;
Expand Down
16 changes: 8 additions & 8 deletions src/core/chuck_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ t_CKBOOL Chuck_VM::initialize_synthesis( )
// allocate dac and adc (REFACTOR-2017: g_t_dac changed to env()->ckt_dac)
env()->ckt_dac->ugen_info->num_outs = env()->ckt_dac->ugen_info->num_ins = m_num_dac_channels;
m_dac = (Chuck_UGen *)instantiate_and_initialize_object( env()->ckt_dac, this );
// Chuck_DL_Api::Api::instance() added 1.3.0.0
object_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::Api::instance() ); // TODO: this can't be the place to do this
stereo_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::Api::instance() ); // TODO: is the NULL shred a problem?
multi_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::Api::instance() ); // TODO: remove and let type system do this
// Chuck_DL_Api::instance() added 1.3.0.0
object_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::instance() ); // TODO: this can't be the place to do this
stereo_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::instance() ); // TODO: is the NULL shred a problem?
multi_ctor( m_dac, NULL, this, NULL, Chuck_DL_Api::instance() ); // TODO: remove and let type system do this
m_dac->add_ref();
// lock it
m_dac->lock();
Expand All @@ -334,10 +334,10 @@ t_CKBOOL Chuck_VM::initialize_synthesis( )
// (REFACTOR-2017: g_t_adc changed to env()->ckt_adc)
env()->ckt_adc->ugen_info->num_ins = env()->ckt_adc->ugen_info->num_outs = m_num_adc_channels;
m_adc = (Chuck_UGen *)instantiate_and_initialize_object( env()->ckt_adc, this );
// Chuck_DL_Api::Api::instance() added 1.3.0.0
object_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::Api::instance() ); // TODO: this can't be the place to do this
stereo_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::Api::instance() );
multi_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::Api::instance() ); // TODO: remove and let type system do this
// Chuck_DL_Api::instance() added 1.3.0.0
object_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::instance() ); // TODO: this can't be the place to do this
stereo_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::instance() );
multi_ctor( m_adc, NULL, this, NULL, Chuck_DL_Api::instance() ); // TODO: remove and let type system do this
m_adc->add_ref();
// lock it
m_adc->lock();
Expand Down

0 comments on commit bdcc177

Please sign in to comment.