Skip to content

Commit

Permalink
add type reference to Chuck_Func
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Nov 27, 2024
1 parent 1d2b0b6 commit ac2a6ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/core/chuck_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3082,16 +3082,21 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f )

// make a new type for the function
type = env->context->new_Chuck_Type( env );
// type id
type->xid = te_function;
type->base_name = "[function]";
// type size
type->size = sizeof(void *);

// function type name; this will be updated later in this function once we have more info (e.g., value_ref)
type->base_name = "[fun]";
// 1.5.4.3 (ge) add ref; was: type->parent_type = env->ckt_function;
// part of #2024-func-call-update
CK_SAFE_REF_ASSIGN(type->parent_type,env->ckt_function);
CK_SAFE_REF_ASSIGN(type->parent_type, env->ckt_function);
// 1.5.4.3 (ge) add ref; was: type->func_bridge = func;
// part of #2024-func-call-update
// part of #2024-func-call-update | TODO: break cycle?
CK_SAFE_REF_ASSIGN(type->func_bridge, func);
// 1.5.4.3 (ge) add func to type reference
// part of #2024-func-call-update | TODO: break cycle?
CK_SAFE_REF_ASSIGN(func->type_ref, type);

// make new value, with potential overloaded name
value = env->context->new_Chuck_Value( type, func_name );
Expand Down Expand Up @@ -3409,10 +3414,13 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f )
assert( f->code == NULL || f->code->s_type == ae_stmt_code );
if( f->code && !type_engine_scan2_code_segment( env, &f->code->stmt_code, FALSE ) )
{
EM_error2( 0, "...in function '%s'", func->signature().c_str() ); // S_name(f->name) );
EM_error2( 0, "...in function '%s'", func->signature(FALSE,FALSE).c_str() ); // S_name(f->name) );
goto error;
}

// update the function-specific type's name | 1.5.4.3 (ge) added
type->base_name = "[fun]" + func->signature(FALSE,FALSE);

// pop the value stack
env->curr->value.pop();
// clear the env's function definition
Expand Down
4 changes: 3 additions & 1 deletion src/core/chuck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9316,7 +9316,9 @@ Chuck_Type * Chuck_Func::type() const
string Chuck_Func::signature( t_CKBOOL incFuncDef, t_CKBOOL incRetType ) const
{
// check we have the necessary info
if( !value_ref || !def() || !def()->ret_type )
// 1.5.4.3 (ge) added conditional check on ret_type
// to allow this function to be used pre-typecheck
if( !value_ref || !def() || (incRetType && !def()->ret_type) )
return "[function signature missing info]";

// check if a member func
Expand Down
2 changes: 1 addition & 1 deletion src/test/06-Errors/error-string-func-concat-1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error-string-func-concat-1.ck:17:9: error: cannot perform '+' on string and '[function]'
error-string-func-concat-1.ck:17:9: error: cannot perform '+' on string and '[fun]Foo.getFoo()'
[17] <<< " " + f.getFoo >>>;
^
error-string-func-concat-1.ck:17:13: error: ...(hint: to call the function, add '()' and any arguments)
Expand Down
2 changes: 1 addition & 1 deletion src/test/06-Errors/error-string-func-concat-2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error-string-func-concat-2.ck:12:9: error: cannot perform '+' on '[function]' and string
error-string-func-concat-2.ck:12:9: error: cannot perform '+' on '[fun]Foo.bar()' and string
[12] Foo.bar + " ";
^
error-string-func-concat-2.ck:12:5: error: ...(hint: to call the function, add '()' and any arguments)
Expand Down
2 changes: 1 addition & 1 deletion src/test/06-Errors/error-string-func-concat-3.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error-string-func-concat-3.ck:9:5: error: cannot perform '+' on '[function]' and string
error-string-func-concat-3.ck:9:5: error: cannot perform '+' on '[fun]foo()' and string
[9] foo + "";
^
error-string-func-concat-3.ck:9:1: error: ...(hint: to call the function, add '()' and any arguments)
Expand Down

0 comments on commit ac2a6ef

Please sign in to comment.