Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nicer access to underlying Julia object for wrapped Julia functions #1051

Open
fingolfin opened this issue Sep 24, 2024 · 1 comment
Open

Comments

@fingolfin
Copy link
Member

fingolfin commented Sep 24, 2024

We already have UnwrapJuliaFunc. But it would feel more natural to me if we (also?) had a JuliaPointer method applicable to them.

Bonus points for also putting them into filter IsJuliaWrapper but that's more tricky and likely requires modifying the TypeObj callback table for T_FUNCTION

@fingolfin fingolfin changed the title Allow access to underlying Julia object for wrapped Julia functions Allow nicer access to underlying Julia object for wrapped Julia functions Sep 24, 2024
@fingolfin
Copy link
Member Author

The GAP kernel does this:

static Obj TYPE_FUNCTION;
static Obj TYPE_OPERATION;
static Obj TYPE_FUNCTION_WITH_NAME;
static Obj TYPE_OPERATION_WITH_NAME;

static Obj TypeFunction(Obj func)
{
    if (NAME_FUNC(func) == 0)
        return (IS_OPERATION(func) ? TYPE_OPERATION : TYPE_FUNCTION);
    else
        return (IS_OPERATION(func) ? TYPE_OPERATION_WITH_NAME : TYPE_FUNCTION_WITH_NAME);
}

[...]

    TypeObjFuncs[ T_FUNCTION ] = TypeFunction;

So we could do something like this, roughly:

static Obj (* OriginalTypeFunction)(Obj obj);

static Obj TYPE_JULIA_FUNCTION;

static Obj TypeFunctionJulia(Obj func)
{
    if (IS_JULIA_FUNC(func))
        return TYPE_JULIA_FUNCTION;
    else
        return OriginalTypeFunction(func);
}

....

// inside a suitable init function
    OriginalTypeFunction = TypeObjFuncs[ T_FUNCTION ];
    TypeObjFuncs[ T_FUNCTION ] = TypeFunctionJulia;

Alternatively, instead of the indirect jump (which is slow) we could of course also just duplicate the original logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant