Unified · Split
| @@ -1,7 +1,7 @@ | |||
| 1 | // name: apropos.ck | 1 | // name: ah-help.ck |
| 2 | // (available in chuck-1.4.1.0 and later) | 2 | // (available in chuck-1.4.1.0 and later) |
| 3 | // desc: example showing .apropos(), which can be invoked on | 3 | // desc: example showing .help(), which can be invoked on |
| 4 | // any object or class; .apropos() dynamically generates | 4 | // any object or class; .help() dynamically generates |
| 5 | // information regarding the underlying type of an object | 5 | // information regarding the underlying type of an object |
| 6 | // or a class and outputs this information to the console. | 6 | // or a class and outputs this information to the console. |
| 7 | // the information includes the inheritance chain of the | 7 | // the information includes the inheritance chain of the |
| @@ -9,23 +9,23 @@ · 1 unmodified line | |||
| 9 | // inherited from its parent (and its parent's parent, and | 9 | // inherited from its parent (and its parent's parent, and |
| 10 | // so on). | 10 | // so on). |
| 11 | // | 11 | // |
| 12 | // .apropos() is designed to be a run-time teaching/learning tool | 12 | // .help() is designed to be a run-time teaching/learning tool |
| 13 | // and a quick referencewhile programming. It's fun, sort of! | 13 | // and a quick referencewhile programming. It's fun, sort of! |
| 14 | 14 | ||
| 15 | // an object/ugen instance | 15 | // an object/ugen instance |
| 16 | SinOsc osc; | 16 | SinOsc osc; |
| 17 | // call apropos() on it to learn about its underlying information | 17 | // call help() on it to learn about its underlying information |
| 18 | osc.apropos(); | 18 | osc.help(); |
| 19 | 19 | ||
| 20 | // apropos() can be called directly on classes without instances | 20 | // help() can be called directly on classes without instances |
| 21 | Machine.apropos(); | 21 | Machine.help(); |
| 22 | 22 | ||
| 23 | // 2-d int array | 23 | // 2-d int array |
| 24 | int a[10][10]; | 24 | int a[10][10]; |
| 25 | // calling apropros on a 2d-array | 25 | // calling apropros on a 2d-array |
| 26 | a.apropos(); | 26 | a.help(); |
| 27 | // calling apropros on an array | 27 | // calling apropros on an array |
| 28 | a[0].apropos(); | 28 | a[0].help(); |
| 29 | 29 | ||
| 30 | // a user-created class | 30 | // a user-created class |
| 31 | public class Foo | 31 | public class Foo |
| @@ -33,5 +33,5 @@ public class Foo · 1 unmodified line | |||
| 33 | fun void bar() | 33 | fun void bar() |
| 34 | { <<< "hi" >>>; } | 34 | { <<< "hi" >>>; } |
| 35 | } | 35 | } |
| 36 | // calling apropos() on the class | 36 | // calling help() on the class |
| 37 | Foo.apropos(); | 37 | Foo.help(); |
| @@ -491,13 +491,13 @@ void CK_DLL_CALL ck_add_ugen_funcf_auto_num_channels( Chuck_DL_Query * query, · 490 unmodified lines | |||
| 491 | // name: ck_add_ugen_ctrl() | 491 | // name: ck_add_ugen_ctrl() |
| 492 | // desc: (ugen only) add ctrl parameters | 492 | // desc: (ugen only) add ctrl parameters |
| 493 | //----------------------------------------------------------------------------- | 493 | //----------------------------------------------------------------------------- |
| 494 | void CK_DLL_CALL ck_add_ugen_ctrl( Chuck_DL_Query * query, f_ctrl ugen_ctrl, f_cget ugen_cget, | 494 | //void CK_DLL_CALL ck_add_ugen_ctrl( Chuck_DL_Query * query, f_ctrl ugen_ctrl, f_cget ugen_cget, |
| 495 | const char * type, const char * name ) | 495 | // const char * type, const char * name ) |
| 496 | { | 496 | //{ |
| 497 | // this is no longer used | 497 | // // this is no longer used |
| 498 | EM_error2( 0, "class import: obselete ck_add_ugen_ctrl invoked..." ); | 498 | // EM_error2( 0, "class import: obselete ck_add_ugen_ctrl invoked..." ); |
| 499 | return; | 499 | // return; |
| 500 | 500 | // | |
| 501 | // // make sure there is class | 501 | // // make sure there is class |
| 502 | // if( !query->curr_class ) | 502 | // if( !query->curr_class ) |
| 503 | // { | 503 | // { |
| @@ -515,7 +515,7 @@ void CK_DLL_CALL ck_add_ugen_ctrl( Chuck_DL_Query * query, f_ctrl ugen_ctrl, f_c · 11 unmodified lines | |||
| 515 | // | 515 | // |
| 516 | // // set | 516 | // // set |
| 517 | // query->curr_func = NULL; | 517 | // query->curr_func = NULL; |
| 518 | } | 518 | //} |
| 519 | 519 | ||
| 520 | 520 | ||
| 521 | 521 | ||
| @@ -950,7 +950,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier ) · 428 unmodified lines | |||
| 950 | add_ugen_func = ck_add_ugen_func; | 950 | add_ugen_func = ck_add_ugen_func; |
| 951 | add_ugen_funcf = ck_add_ugen_funcf; | 951 | add_ugen_funcf = ck_add_ugen_funcf; |
| 952 | add_ugen_funcf_auto_num_channels = ck_add_ugen_funcf_auto_num_channels; | 952 | add_ugen_funcf_auto_num_channels = ck_add_ugen_funcf_auto_num_channels; |
| 953 | add_ugen_ctrl = ck_add_ugen_ctrl; // not used but needed for import for now | 953 | // add_ugen_ctrl = ck_add_ugen_ctrl; // not used |
| 954 | end_class = ck_end_class; | 954 | end_class = ck_end_class; |
| 955 | doc_class = ck_doc_class; | 955 | doc_class = ck_doc_class; |
| 956 | doc_func = ck_doc_func; | 956 | doc_func = ck_doc_func; |
| @@ -46,9 +46,9 @@ · 45 unmodified lines | |||
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | // major version must be the same between chuck:chugin | 48 | // major version must be the same between chuck:chugin |
| 49 | #define CK_DLL_VERSION_MAJOR (0x0007) | 49 | #define CK_DLL_VERSION_MAJOR (0x0008) |
| 50 | // minor version of chugin must be less than or equal to chuck's | 50 | // minor version of chugin must be less than or equal to chuck's |
| 51 | #define CK_DLL_VERSION_MINOR (0x0001) | 51 | #define CK_DLL_VERSION_MINOR (0x0000) |
| 52 | #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) | 52 | #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) |
| 53 | #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) | 53 | #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) |
| 54 | #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) | 54 | #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) |
| @@ -303,9 +303,9 @@ typedef void (CK_DLL_CALL * f_add_arg)( Chuck_DL_Query * query, const char * typ · 248 unmodified lines | |||
| 303 | typedef void (CK_DLL_CALL * f_add_ugen_func)( Chuck_DL_Query * query, f_tick tick, f_pmsg pmsg, t_CKUINT num_in, t_CKUINT num_out ); | 303 | typedef void (CK_DLL_CALL * f_add_ugen_func)( Chuck_DL_Query * query, f_tick tick, f_pmsg pmsg, t_CKUINT num_in, t_CKUINT num_out ); |
| 304 | typedef void (CK_DLL_CALL * f_add_ugen_funcf)( Chuck_DL_Query * query, f_tickf tickf, f_pmsg pmsg, t_CKUINT num_in, t_CKUINT num_out ); | 304 | typedef void (CK_DLL_CALL * f_add_ugen_funcf)( Chuck_DL_Query * query, f_tickf tickf, f_pmsg pmsg, t_CKUINT num_in, t_CKUINT num_out ); |
| 305 | typedef void (CK_DLL_CALL * f_add_ugen_funcf_auto_num_channels)( Chuck_DL_Query * query, f_tickf tickf, f_pmsg psmg ); | 305 | typedef void (CK_DLL_CALL * f_add_ugen_funcf_auto_num_channels)( Chuck_DL_Query * query, f_tickf tickf, f_pmsg psmg ); |
| 306 | // ** add a ugen control (not used but needed for import for now) | 306 | // ** add a ugen control (not used) | 1.4.1.0 removed |
| 307 | typedef void (CK_DLL_CALL * f_add_ugen_ctrl)( Chuck_DL_Query * query, f_ctrl ctrl, f_cget cget, | 307 | //typedef void (CK_DLL_CALL * f_add_ugen_ctrl)( Chuck_DL_Query * query, f_ctrl ctrl, f_cget cget, |
| 308 | const char * type, const char * name ); | 308 | // const char * type, const char * name ); |
| 309 | // end class/namespace - must correspondent with begin_class. returns false on error | 309 | // end class/namespace - must correspondent with begin_class. returns false on error |
| 310 | typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); | 310 | typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); |
| 311 | // create main thread hook- used for executing a "hook" function in the main thread of a primary chuck instance | 311 | // create main thread hook- used for executing a "hook" function in the main thread of a primary chuck instance |
| @@ -369,7 +369,7 @@ public: · 57 unmodified lines | |||
| 369 | // (ugen only) add tick and pmsg functions, specify channels by vm | 369 | // (ugen only) add tick and pmsg functions, specify channels by vm |
| 370 | f_add_ugen_funcf_auto_num_channels add_ugen_funcf_auto_num_channels; | 370 | f_add_ugen_funcf_auto_num_channels add_ugen_funcf_auto_num_channels; |
| 371 | // (ugen only) add ctrl parameters | 371 | // (ugen only) add ctrl parameters |
| 372 | f_add_ugen_ctrl add_ugen_ctrl; // not used but needed for import for now | 372 | // f_add_ugen_ctrl add_ugen_ctrl; // not used but needed for import for now |
| 373 | // end class/namespace, compile it | 373 | // end class/namespace, compile it |
| 374 | f_end_class end_class; | 374 | f_end_class end_class; |
| 375 | 375 | ||
| @@ -294,6 +294,8 @@ Chuck_VM_Code * emit_to_code( Chuck_Code * in, · 293 unmodified lines | |||
| 294 | code->stack_depth = in->stack_depth; | 294 | code->stack_depth = in->stack_depth; |
| 295 | // set whether code need this base pointer | 295 | // set whether code need this base pointer |
| 296 | code->need_this = in->need_this; | 296 | code->need_this = in->need_this; |
| 297 | // set whether static inside class | 1.4.1.0 (ge) added | ||
| 298 | code->is_static = in->is_static; | ||
| 297 | // set name | 299 | // set name |
| 298 | code->name = in->name; | 300 | code->name = in->name; |
| 299 | // set filename for me.sourceDir() (added 1.3.0.0) | 301 | // set filename for me.sourceDir() (added 1.3.0.0) |
| @@ -3450,6 +3452,7 @@ t_CKBOOL emit_engine_emit_exp_func_call( Chuck_Emitter * emit, · 3150 unmodified lines | |||
| 3450 | { | 3452 | { |
| 3451 | emit->append( instr = new Chuck_Instr_Func_Call ); | 3453 | emit->append( instr = new Chuck_Instr_Func_Call ); |
| 3452 | } | 3454 | } |
| 3455 | // set line position | ||
| 3453 | instr->set_linepos(linepos); | 3456 | instr->set_linepos(linepos); |
| 3454 | 3457 | ||
| 3455 | return TRUE; | 3458 | return TRUE; |
| @@ -4477,6 +4480,8 @@ t_CKBOOL emit_engine_emit_func_def( Chuck_Emitter * emit, a_Func_Def func_def ) · 1021 unmodified lines | |||
| 4477 | emit->code->name += func->name + "( ... )"; | 4480 | emit->code->name += func->name + "( ... )"; |
| 4478 | // set whether need this | 4481 | // set whether need this |
| 4479 | emit->code->need_this = func->is_member; | 4482 | emit->code->need_this = func->is_member; |
| 4483 | // if static inside class | 1.4.1.0 (ge) added | ||
| 4484 | emit->code->is_static = func->is_static; | ||
| 4480 | // keep track of full path (added 1.3.0.0) | 4485 | // keep track of full path (added 1.3.0.0) |
| 4481 | emit->code->filename = emit->context->full_path; | 4486 | emit->code->filename = emit->context->full_path; |
| 4482 | 4487 | ||
| @@ -4499,6 +4504,19 @@ t_CKBOOL emit_engine_emit_func_def( Chuck_Emitter * emit, a_Func_Def func_def ) · 16 unmodified lines | |||
| 4499 | return FALSE; | 4504 | return FALSE; |
| 4500 | } | 4505 | } |
| 4501 | } | 4506 | } |
| 4507 | // if static function inside class def | 1.4.1.0 (ge) added | ||
| 4508 | else if( func->is_static ) | ||
| 4509 | { | ||
| 4510 | // get the size (for the TYPE argument) | ||
| 4511 | emit->code->stack_depth += sizeof(t_CKUINT); | ||
| 4512 | // create local | ||
| 4513 | if( !emit->alloc_local( sizeof(t_CKUINT), "@type", TRUE, FALSE, FALSE ) ) | ||
| 4514 | { | ||
| 4515 | EM_error2( a->linepos, | ||
| 4516 | "(emit): internal error: cannot allocate local '@type'..." ); | ||
| 4517 | return FALSE; | ||
| 4518 | } | ||
| 4519 | } | ||
| 4502 | 4520 | ||
| 4503 | // ge: 2012 april: added push scope (added 1.3.0.0) | 4521 | // ge: 2012 april: added push scope (added 1.3.0.0) |
| 4504 | emit->push_scope(); | 4522 | emit->push_scope(); |
| @@ -4755,6 +4773,8 @@ t_CKBOOL emit_engine_emit_spork( Chuck_Emitter * emit, a_Exp_Func_Call exp ) · 250 unmodified lines | |||
| 4755 | emit->code = new Chuck_Code; | 4773 | emit->code = new Chuck_Code; |
| 4756 | // handle need this | 4774 | // handle need this |
| 4757 | emit->code->need_this = exp->ck_func->is_member; | 4775 | emit->code->need_this = exp->ck_func->is_member; |
| 4776 | // handle is static (inside class def) | 1.4.1.0 (ge) added | ||
| 4777 | emit->code->is_static = exp->ck_func->is_static; | ||
| 4758 | // name it: e.g. spork~foo [line 5] | 4778 | // name it: e.g. spork~foo [line 5] |
| 4759 | std::ostringstream name; | 4779 | std::ostringstream name; |
| 4760 | name << "spork~" | 4780 | name << "spork~" |
| @@ -61,6 +61,8 @@ public: · 60 unmodified lines | |||
| 61 | t_CKUINT stack_depth; | 61 | t_CKUINT stack_depth; |
| 62 | // need this | 62 | // need this |
| 63 | t_CKBOOL need_this; | 63 | t_CKBOOL need_this; |
| 64 | // is static (in class def) | 1.4.1.0 (ge) added | ||
| 65 | t_CKBOOL is_static; | ||
| 64 | // frame | 66 | // frame |
| 65 | Chuck_Frame * frame; | 67 | Chuck_Frame * frame; |
| 66 | // code | 68 | // code |
| @@ -81,6 +83,7 @@ public: · 14 unmodified lines | |||
| 81 | { | 83 | { |
| 82 | stack_depth = 0; | 84 | stack_depth = 0; |
| 83 | need_this = FALSE; | 85 | need_this = FALSE; |
| 86 | is_static = FALSE; // 1.4.1.0 (ge) added | ||
| 84 | frame = new Chuck_Frame; | 87 | frame = new Chuck_Frame; |
| 85 | } | 88 | } |
| 86 | 89 | ||
| @@ -1979,7 +1979,7 @@ void Chuck_Instr_Add_float_string_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred · 1978 unmodified lines | |||
| 1979 | null_pointer: | 1979 | null_pointer: |
| 1980 | // we have a problem | 1980 | // we have a problem |
| 1981 | CK_FPRINTF_STDERR( | 1981 | CK_FPRINTF_STDERR( |
| 1982 | "[chuck](VM): NullPointerException: (string + string) on line[%lu] in shred[id=%lu:%s]\n", | 1982 | "[chuck](VM): NullPointerException: (float + string) on line[%lu] in shred[id=%lu:%s]\n", |
| 1983 | m_linepos, shred->xid, shred->name.c_str() ); | 1983 | m_linepos, shred->xid, shred->name.c_str() ); |
| 1984 | goto done; | 1984 | goto done; |
| 1985 | 1985 | ||
| @@ -4485,7 +4485,7 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 2499 unmodified lines | |||
| 4485 | t_CKUINT *& mem_sp = (t_CKUINT *&)shred->mem->sp; | 4485 | t_CKUINT *& mem_sp = (t_CKUINT *&)shred->mem->sp; |
| 4486 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; | 4486 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; |
| 4487 | 4487 | ||
| 4488 | // pop word | 4488 | // pop words |
| 4489 | pop_( reg_sp, 2 ); | 4489 | pop_( reg_sp, 2 ); |
| 4490 | // get the function to be called as code | 4490 | // get the function to be called as code |
| 4491 | Chuck_VM_Code * func = (Chuck_VM_Code *)*reg_sp; | 4491 | Chuck_VM_Code * func = (Chuck_VM_Code *)*reg_sp; |
| @@ -4533,6 +4533,14 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 41 unmodified lines | |||
| 4533 | // one less word to copy | 4533 | // one less word to copy |
| 4534 | stack_depth--; | 4534 | stack_depth--; |
| 4535 | } | 4535 | } |
| 4536 | // static inside class | 1.4.1.0 (ge) added | ||
| 4537 | else if( func->is_static ) | ||
| 4538 | { | ||
| 4539 | // copy type from end of arguments to the front | ||
| 4540 | *mem_sp2++ = *(reg_sp2 + stack_depth - 1); | ||
| 4541 | // one less word to copy | ||
| 4542 | stack_depth--; | ||
| 4543 | } | ||
| 4536 | 4544 | ||
| 4537 | // push the arguments | 4545 | // push the arguments |
| 4538 | for( t_CKUINT i = 0; i < stack_depth; i++ ) | 4546 | for( t_CKUINT i = 0; i < stack_depth; i++ ) |
| @@ -4680,17 +4688,14 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre · 141 unmodified lines | |||
| 4680 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; | 4688 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; |
| 4681 | Chuck_DL_Return retval; | 4689 | Chuck_DL_Return retval; |
| 4682 | 4690 | ||
| 4683 | // pop word | 1.4.1.0 (ge): pop an extra element as the base_type | 4691 | // pop code and local depth |
| 4684 | // this accompanies the introduction of TYPE to static function calls | 4692 | pop_( reg_sp, 2 ); |
| 4685 | pop_( reg_sp, 3 ); | ||
| 4686 | // get the base type | ||
| 4687 | Chuck_Type * base_type = (Chuck_Type *)*reg_sp; | ||
| 4688 | // get the function to be called as code | 4693 | // get the function to be called as code |
| 4689 | Chuck_VM_Code * func = (Chuck_VM_Code *)*(reg_sp+1); | 4694 | Chuck_VM_Code * func = (Chuck_VM_Code *)*(reg_sp); |
| 4690 | // get the function to be called | 4695 | // get the function to be called |
| 4691 | f_sfun f = (f_sfun)func->native_func; | 4696 | f_sfun f = (f_sfun)func->native_func; |
| 4692 | // get the local stack depth - caller local variables | 4697 | // get the local stack depth - caller local variables |
| 4693 | t_CKUINT local_depth = *(reg_sp+2); | 4698 | t_CKUINT local_depth = *(reg_sp+1); |
| 4694 | // convert to number of int's (was: 4-byte words), extra partial word counts as additional word | 4699 | // convert to number of int's (was: 4-byte words), extra partial word counts as additional word |
| 4695 | local_depth = ( local_depth / sz_INT ) + ( local_depth & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) | 4700 | local_depth = ( local_depth / sz_INT ) + ( local_depth & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) |
| 4696 | // get the stack depth of the callee function args | 4701 | // get the stack depth of the callee function args |
| @@ -4699,7 +4704,7 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre · 2 unmodified lines | |||
| 4699 | // UNUSED: t_CKUINT prev_stack = ( *(mem_sp-1) >> 2 ) + ( *(mem_sp-1) & 0x3 ? 1 : 0 ); | 4704 | // UNUSED: t_CKUINT prev_stack = ( *(mem_sp-1) >> 2 ) + ( *(mem_sp-1) & 0x3 ? 1 : 0 ); |
| 4700 | // the amount to push in 4-byte words | 4705 | // the amount to push in 4-byte words |
| 4701 | t_CKUINT push = local_depth; | 4706 | t_CKUINT push = local_depth; |
| 4702 | // push the mem stack passed the current function variables and arguments | 4707 | // push the mem stack past the current function variables and arguments |
| 4703 | mem_sp += push; | 4708 | mem_sp += push; |
| 4704 | 4709 | ||
| 4705 | // pass args | 4710 | // pass args |
| @@ -4712,13 +4717,11 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre · 6 unmodified lines | |||
| 4712 | t_CKUINT * reg_sp2 = reg_sp; | 4717 | t_CKUINT * reg_sp2 = reg_sp; |
| 4713 | t_CKUINT * mem_sp2 = mem_sp; | 4718 | t_CKUINT * mem_sp2 = mem_sp; |
| 4714 | 4719 | ||
| 4715 | // need this | 4720 | // need type |
| 4716 | if( func->need_this ) | 4721 | if( func->is_static ) |
| 4717 | { | 4722 | { |
| 4718 | // copy this from end of arguments to the front | 4723 | // copy this from end of arguments to the front |
| 4719 | *mem_sp2++ = *(reg_sp2 + stack_depth - 1); | 4724 | *mem_sp2++ = *(reg_sp2 + stack_depth - 1); |
| 4720 | // advance reg pointer | ||
| 4721 | reg_sp2++; | ||
| 4722 | // one less word to copy | 4725 | // one less word to copy |
| 4723 | stack_depth--; | 4726 | stack_depth--; |
| 4724 | } | 4727 | } |
| @@ -4733,7 +4736,7 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre · 8 unmodified lines | |||
| 4733 | // call the function | 4736 | // call the function |
| 4734 | // (added 1.3.0.0 -- Chuck_DL_Api::Api::instance()) | 4737 | // (added 1.3.0.0 -- Chuck_DL_Api::Api::instance()) |
| 4735 | // (added 1.4.1.0 -- base_type) | 4738 | // (added 1.4.1.0 -- base_type) |
| 4736 | f( base_type, mem_sp, &retval, vm, shred, Chuck_DL_Api::Api::instance() ); | 4739 | f( (Chuck_Type *)(*mem_sp), mem_sp+1, &retval, vm, shred, Chuck_DL_Api::Api::instance() ); |
| 4737 | // clean up memory stack | 4740 | // clean up memory stack |
| 4738 | mem_sp -= push; | 4741 | mem_sp -= push; |
| 4739 | 4742 | ||
| @@ -4818,6 +4821,7 @@ void Chuck_Instr_Spork::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 78 unmodified lines | |||
| 4818 | { | 4821 | { |
| 4819 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; | 4822 | t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; |
| 4820 | t_CKUINT this_ptr = 0; | 4823 | t_CKUINT this_ptr = 0; |
| 4824 | t_CKUINT type_ptr = 0; | ||
| 4821 | 4825 | ||
| 4822 | // pop the stack | 4826 | // pop the stack |
| 4823 | pop_( reg_sp, 1 ); | 4827 | pop_( reg_sp, 1 ); |
| @@ -4839,6 +4843,14 @@ void Chuck_Instr_Spork::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 15 unmodified lines | |||
| 4839 | // add to shred so it's ref counted, and released when shred done (1.3.1.2) | 4843 | // add to shred so it's ref counted, and released when shred done (1.3.1.2) |
| 4840 | sh->add_parent_ref( (Chuck_Object *)this_ptr ); | 4844 | sh->add_parent_ref( (Chuck_Object *)this_ptr ); |
| 4841 | } | 4845 | } |
| 4846 | // need @type (for static functions) | 1.4.1.0 (ge) added | ||
| 4847 | else if( func->is_static ) | ||
| 4848 | { | ||
| 4849 | // pop the stack | ||
| 4850 | pop_( reg_sp, 1 ); | ||
| 4851 | // get type info | ||
| 4852 | type_ptr = *reg_sp; | ||
| 4853 | } | ||
| 4842 | // copy args | 4854 | // copy args |
| 4843 | if( m_val ) | 4855 | if( m_val ) |
| 4844 | { | 4856 | { |
| @@ -4852,6 +4864,11 @@ void Chuck_Instr_Spork::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) · 7 unmodified lines | |||
| 4852 | { | 4864 | { |
| 4853 | push_( (t_CKUINT*&)sh->reg->sp, this_ptr ); | 4865 | push_( (t_CKUINT*&)sh->reg->sp, this_ptr ); |
| 4854 | } | 4866 | } |
| 4867 | // copy type info (for static functions) | 1.4.1.0 (ge) added | ||
| 4868 | else if( func->is_static ) | ||
| 4869 | { | ||
| 4870 | push_( (t_CKUINT*&)sh->reg->sp, type_ptr ); | ||
| 4871 | } | ||
| 4855 | // copy func | 4872 | // copy func |
| 4856 | push_( (t_CKUINT*&)sh->reg->sp, (t_CKUINT)func ); | 4873 | push_( (t_CKUINT*&)sh->reg->sp, (t_CKUINT)func ); |
| 4857 | // push the stack | 4874 | // push the stack |
| @@ -6308,10 +6325,10 @@ void Chuck_Instr_Dot_Static_Func::execute( Chuck_VM * vm, Chuck_VM_Shred * shred · 1450 unmodified lines | |||
| 6308 | // register stack pointer | 6325 | // register stack pointer |
| 6309 | t_CKUINT *& sp = (t_CKUINT *&)shred->reg->sp; | 6326 | t_CKUINT *& sp = (t_CKUINT *&)shred->reg->sp; |
| 6310 | 6327 | ||
| 6311 | // pop the type pointer | ||
| 6312 | // pop_( sp, 1 ); | ||
| 6313 | // 1.4.1.0 (ge): leave the base type on the operand stack | 6328 | // 1.4.1.0 (ge): leave the base type on the operand stack |
| 6314 | 6329 | // commented out: pop the type pointer | |
| 6330 | // pop_( sp, 1 ); | ||
| 6331 | |||
| 6315 | // push the address | 6332 | // push the address |
| 6316 | push_( sp, (t_CKUINT)(m_func) ); | 6333 | push_( sp, (t_CKUINT)(m_func) ); |
| 6317 | } | 6334 | } |
| @@ -86,8 +86,8 @@ t_CKBOOL init_class_object( Chuck_Env * env, Chuck_Type * type ) · 85 unmodified lines | |||
| 86 | if( !type_engine_import_mfun( env, func ) ) goto error; | 86 | if( !type_engine_import_mfun( env, func ) ) goto error; |
| 87 | 87 | ||
| 88 | // add api() | 88 | // add api() |
| 89 | func = make_new_sfun( "void", "apropos", object_apropos ); | 89 | func = make_new_sfun( "void", "help", object_apropos ); |
| 90 | func->doc = "dynamically generate and output information about a class or object."; | 90 | func->doc = "generate and output helpful information about a class or object."; |
| 91 | if( !type_engine_import_sfun( env, func ) ) goto error; | 91 | if( !type_engine_import_sfun( env, func ) ) goto error; |
| 92 | 92 | ||
| 93 | // end the class import | 93 | // end the class import |
| @@ -2506,6 +2506,9 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f ) · 2505 unmodified lines | |||
| 2506 | // note whether the function is marked as member | 2506 | // note whether the function is marked as member |
| 2507 | func->is_member = (f->static_decl != ae_key_static) && | 2507 | func->is_member = (f->static_decl != ae_key_static) && |
| 2508 | (env->class_def != NULL); | 2508 | (env->class_def != NULL); |
| 2509 | // note whether the function is marked as static (in class) | ||
| 2510 | func->is_static = (f->static_decl == ae_key_static) && | ||
| 2511 | (env->class_def != NULL); | ||
| 2509 | // copy the native code, for imported functions | 2512 | // copy the native code, for imported functions |
| 2510 | if( f->s_type == ae_func_builtin ) | 2513 | if( f->s_type == ae_func_builtin ) |
| 2511 | { | 2514 | { |
| @@ -2513,6 +2516,9 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f ) · 1 unmodified line | |||
| 2513 | func->code = new Chuck_VM_Code; | 2516 | func->code = new Chuck_VM_Code; |
| 2514 | // whether the function needs 'this' | 2517 | // whether the function needs 'this' |
| 2515 | func->code->need_this = func->is_member; | 2518 | func->code->need_this = func->is_member; |
| 2519 | // is static inside | ||
| 2520 | func->code->is_static = (f->static_decl == ae_key_static) && | ||
| 2521 | (env->class_def != NULL); | ||
| 2516 | // set the function pointer | 2522 | // set the function pointer |
| 2517 | func->code->native_func = (t_CKUINT)func->def->dl_func_ptr; | 2523 | func->code->native_func = (t_CKUINT)func->def->dl_func_ptr; |
| 2518 | } | 2524 | } |
| @@ -2571,7 +2577,16 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f ) · 52 unmodified lines | |||
| 2571 | // count | 2577 | // count |
| 2572 | count = 1; | 2578 | count = 1; |
| 2573 | // make room for 'this' | 2579 | // make room for 'this' |
| 2574 | f->stack_depth = func->is_member ? sizeof(void *) : 0; | 2580 | if( func->is_member ) |
| 2581 | { | ||
| 2582 | f->stack_depth = sizeof(void *); | ||
| 2583 | } | ||
| 2584 | else if( func->is_static ) // 1.4.1.0 (ge) added | ||
| 2585 | { | ||
| 2586 | // make room for '@type' for static functions inside class def | ||
| 2587 | f->stack_depth = sizeof(void *); | ||
| 2588 | } | ||
| 2589 | |||
| 2575 | // loop over arguments | 2590 | // loop over arguments |
| 2576 | while( arg_list ) | 2591 | while( arg_list ) |
| 2577 | { | 2592 | { |
| @@ -694,7 +694,7 @@ struct Chuck_Value : public Chuck_VM_Object · 693 unmodified lines | |||
| 694 | // member? | 694 | // member? |
| 695 | t_CKBOOL is_member; | 695 | t_CKBOOL is_member; |
| 696 | // static? | 696 | // static? |
| 697 | t_CKBOOL is_static; // do something | 697 | t_CKBOOL is_static; // do something |
| 698 | // is context-global? | 698 | // is context-global? |
| 699 | t_CKBOOL is_context_global; | 699 | t_CKBOOL is_context_global; |
| 700 | // is decl checked | 700 | // is decl checked |
| @@ -762,6 +762,8 @@ struct Chuck_Func : public Chuck_VM_Object · 61 unmodified lines | |||
| 762 | // Chuck_DL_Func * dl_code; | 762 | // Chuck_DL_Func * dl_code; |
| 763 | // member | 763 | // member |
| 764 | t_CKBOOL is_member; | 764 | t_CKBOOL is_member; |
| 765 | // static (inside class) | ||
| 766 | t_CKBOOL is_static; | ||
| 765 | // virtual table index | 767 | // virtual table index |
| 766 | t_CKUINT vt_index; | 768 | t_CKUINT vt_index; |
| 767 | // rember value | 769 | // rember value |
| @@ -775,8 +777,9 @@ struct Chuck_Func : public Chuck_VM_Object · 7 unmodified lines | |||
| 775 | std::string doc; | 777 | std::string doc; |
| 776 | 778 | ||
| 777 | // constructor | 779 | // constructor |
| 778 | Chuck_Func() { def = NULL; code = NULL; is_member = FALSE; vt_index = 0xffffffff; | 780 | Chuck_Func() { def = NULL; code = NULL; is_member = FALSE; is_static = FALSE, |
| 779 | value_ref = NULL; /*dl_code = NULL;*/ next = NULL; up = NULL; } | 781 | vt_index = 0xffffffff; value_ref = NULL; /*dl_code = NULL;*/ next = NULL; |
| 782 | up = NULL; } | ||
| 780 | 783 | ||
| 781 | // destructor | 784 | // destructor |
| 782 | virtual ~Chuck_Func() | 785 | virtual ~Chuck_Func() |
| @@ -1289,6 +1289,7 @@ Chuck_VM_Code::Chuck_VM_Code() · 1288 unmodified lines | |||
| 1289 | num_instr = 0; | 1289 | num_instr = 0; |
| 1290 | stack_depth = 0; | 1290 | stack_depth = 0; |
| 1291 | need_this = FALSE; | 1291 | need_this = FALSE; |
| 1292 | is_static = FALSE; | ||
| 1292 | native_func = 0; | 1293 | native_func = 0; |
| 1293 | native_func_type = NATIVE_UNKNOWN; | 1294 | native_func_type = NATIVE_UNKNOWN; |
| 1294 | } | 1295 | } |
| @@ -139,6 +139,8 @@ public: · 138 unmodified lines | |||
| 139 | t_CKUINT stack_depth; | 139 | t_CKUINT stack_depth; |
| 140 | // whether the function needs 'this' pointer or not | 140 | // whether the function needs 'this' pointer or not |
| 141 | t_CKBOOL need_this; | 141 | t_CKBOOL need_this; |
| 142 | // whether the function is a static function inside class | ||
| 143 | t_CKBOOL is_static; // 1.4.1.0 | ||
| 142 | // native | 144 | // native |
| 143 | t_CKUINT native_func; | 145 | t_CKUINT native_func; |
| 144 | // is ctor? | 146 | // is ctor? |
| @@ -0,0 +1,12 @@ | |||
| 1 | // static function test: calling from class name (no instance) | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string s ) | ||
| 6 | { | ||
| 7 | if( s == "bar" ) <<< "success">>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // call here | ||
| 12 | Foo.foo( "bar" ); | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | // static function test: calling from instance | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string s ) | ||
| 6 | { | ||
| 7 | if( s == "bar" ) <<< "success">>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // instantiate | ||
| 12 | Foo f; | ||
| 13 | // call here | ||
| 14 | f.foo( "bar" ); | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | // static function test: sporking from class | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string s ) | ||
| 6 | { if( s == "bar") <<< "success" >>>; } | ||
| 7 | } | ||
| 8 | |||
| 9 | // spork it | ||
| 10 | spork ~ Foo.foo( "bar" ); | ||
| 11 | |||
| 12 | // give it a chance to run | ||
| 13 | me.yield(); | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | // static function test: sporking using instance | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string s ) | ||
| 6 | { if( s == "bar") <<< "success" >>>; } | ||
| 7 | } | ||
| 8 | |||
| 9 | // instantiate a Foo | ||
| 10 | Foo f; | ||
| 11 | // spork it | ||
| 12 | spork ~ f.foo( "bar" ); | ||
| 13 | |||
| 14 | // give it a chance to run | ||
| 15 | me.yield(); | ||
| @@ -0,0 +1,12 @@ | |||
| 1 | // static function test: multiple arguments | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string a, int b, float c ) | ||
| 6 | { | ||
| 7 | if( a == "bar" && b == 1 && c == 4.0 ) <<< "success" >>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // spork it | ||
| 12 | Foo.foo( "bar", 1, 4.0 ); | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | // static function test: multiple arguments from instance | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string a, int b, float c ) | ||
| 6 | { | ||
| 7 | if( a == "bar" && b == 1 && c == 4.0 ) <<< "success" >>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // instantiate | ||
| 12 | Foo f; | ||
| 13 | // call it | ||
| 14 | f.foo( "bar", 1, 4.0 ); | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | // static function test: multiple arguments, sporked | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string a, int b, float c ) | ||
| 6 | { | ||
| 7 | if( a == "bar" && b == 1 && c == 4.0 ) <<< "success" >>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // spork it | ||
| 12 | spork ~ Foo.foo( "bar", 1, 4.0 ); | ||
| 13 | |||
| 14 | // give it a chance to run | ||
| 15 | me.yield(); | ||
| @@ -0,0 +1,17 @@ | |||
| 1 | // static function test: multiple arguments, sporked from instance | ||
| 2 | |||
| 3 | public class Foo | ||
| 4 | { | ||
| 5 | fun static void foo( string a, int b, float c ) | ||
| 6 | { | ||
| 7 | if( a == "bar" && b == 1 && c == 4.0 ) <<< "success" >>>; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | |||
| 11 | // instantiate f | ||
| 12 | Foo f; | ||
| 13 | // spork it | ||
| 14 | spork ~ f.foo( "bar", 1, 4.0 ); | ||
| 15 | |||
| 16 | // give it a chance to run | ||
| 17 | me.yield(); | ||