Skip to content

Means to expose functions from modules#227

Merged
jeff5 merged 6 commits intojython:mainfrom
jeff5:expose-module-3.8
Feb 4, 2023
Merged

Means to expose functions from modules#227
jeff5 merged 6 commits intojython:mainfrom
jeff5:expose-module-3.8

Conversation

@jeff5
Copy link
Copy Markdown
Member

@jeff5 jeff5 commented Dec 30, 2022

This PR will introduce by stages a tested mechanism to define built-in modules and potentially third-party extensions. The Java methods in classes identified as Python modules will appear to Python as functions. The intent is described in Python Modules in Java.

Built-in functions in modules look different from bound methods on objects, but they are in fact the same object type:

>>> abs
<built-in function abs>
>>> "hello".split
<built-in method split of str object at 0x000002446349C930>
>>> type("hello".split)==type(abs)
True

For technical reasons, we start by renaming the implementation class PyJavaMethod to PyJavaFunction.

Draft for now.

PyJavaMethod represents bound and unbound *methods* (name
'builtin_function_or_method'). CPython calls the same idea PyCFunction.
PEP 573 introduces a PyCMethod (name 'builtin_method') for methods of
types in modules.

It's going to be confusing if we don't go with PyJavaFunction.
Port the basic apparatus of modules defined in Java from VSJ and a test.
Rationalise ArgParser to eliminate a legacy constructor.
@jeff5
Copy link
Copy Markdown
Member Author

jeff5 commented Dec 30, 2022

This change brings over the basic apparatus of modules defined in Java, and a fairly complete exposure mechanism. A test shows that we can build by reflection a module definition that is somewhat like the PyMethodDef table found in CPython modules.

As a result we find and fix a bug and some inefficiencies in
PyJavaFunction calls.
Separate extension module initialisation into create and exec phases,
roughly as PEP 489.
We implement a few built-in functions and object references, and a unit
test of the functions. The Interpreter now makes itself an instance of
the module so that it is available to the frame.
With a few adjustments to the interpreter frame and the function object,
we show that we can access the contents of the builtins module as we
interpret CPython byte code.
@jeff5 jeff5 marked this pull request as ready for review January 2, 2023 14:48
@jeff5
Copy link
Copy Markdown
Member Author

jeff5 commented Jan 2, 2023

This seems like a good place to stop and invite comment (if any available). I'll merge in a week or so.

@jeff5 jeff5 merged commit 9d11bd4 into jython:main Feb 4, 2023
@jeff5 jeff5 deleted the expose-module-3.8 branch February 4, 2023 15:20
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

Successfully merging this pull request may close these issues.

1 participant