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

JuliaFunction: set name and "location" of the function #182

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions JuliaInterface/src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,8 @@ static Obj DoCallJuliaFuncXArg(Obj func, Obj args)
//
Obj NewJuliaFunc(jl_function_t * function)
{
// TODO: set a sensible name?
// jl_datatype_t * dt = ...
// jl_typename_t * tname = dt->name;
// // struct _jl_methtable_t *mt;
// jl_sym_t *name = tname->mt->name;

Obj func = NewFunctionC("", -1, "arg", 0);
const char * name = jl_symbol_name(jl_gf_name(function));
Obj func = NewFunctionC(name, -1, "arg", 0);

SET_HDLR_FUNC(func, 0, DoCallJuliaFunc0Arg);
SET_HDLR_FUNC(func, 1, DoCallJuliaFunc1Arg);
Expand All @@ -204,6 +199,16 @@ Obj NewJuliaFunc(jl_function_t * function)
// the Julia function point in here
SET_FEXS_FUNC(func, (Obj)function);

// add a function body so that we can store some meta data about the
// origin of this function, for slightly more helpful printing of the
// function.
Obj body = NewBag(T_BODY, sizeof(BodyHeader));
SET_FILENAME_BODY(body, MakeImmString("Julia"));
SET_LOCATION_BODY(body, MakeImmString(name));
SET_BODY_FUNC(func, body);
CHANGED_BAG(body);
CHANGED_BAG(func);

return func;
}

Expand Down
8 changes: 8 additions & 0 deletions JuliaInterface/tst/utils.tst
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,13 @@ Error, JuliaGetFieldOfObject: <field_name> must be a string
gap> JuliaGetFieldOfObject(JuliaModule("Base"), "not-a-field");
Error, type Module has no field not-a-field

##
gap> NameFunction(Julia.Base.parse);
"parse"
gap> Display(Julia.Base.parse);
function ( arg... )
<<kernel code>> from Julia:parse
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <<kernel code>> from bit is fixed by GAP (at least currently), and so is the "FOO:BAR" format for the final part. Nice would of course be something like: <<Julia function Base.parse>>. Alas, I also don't really know how to produce Base.parse instead of parse. Perhaps it's as simply as checking for the parent module, getting its name, and prepending it (with a dot), and then repeating this until the top level is reached? Alas, we can figure that out later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it is fine that way for now. If people start to complain we can still fix it. A sensible top-level would be Main I guess. Or maybe Top?

end

##
gap> STOP_TEST( "utils.tst", 1 );