Commit graph

61 commits

Author SHA1 Message Date
Alexander Motzkau
831aaf0c05 Add iterators to variables and functions types
Allow iterating over function list, local and global variables. The
iterators will give the list of functions/variables in program order.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
d0904f9913 Added str() operator to Python representation of LPC types
str(lpctype) returns the LPC code of the LPC type.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
25ab0f48bc Added separate Python types for various closure types
Added LfunClosure, (Simul)EfunClosure, (Unbound/Bound)LambdaClosure and
OperatorClosure types for Python.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
f7c95ae898 Add program_name member function to ldmud.Object object
To streamline Python representations for normal and lightweight objects
also add a program_name member function to normal objects.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
1895ab4790 Make struct members iterable in Python
Add len and [] implementation to Python struct member list,
so they can be iterated over in definition order.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
2c173d9322 Make Python representations of LPC values hashable
Add hash and eq function to all Python implementations,
so all LPC values can be used in Python dictionaries as keys.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
8b3031d3b4 With pragma save_local_names save debugging info for local variables
Previously pragma save_local_names was only used to store information of
variables of coroutines to be inspected by Python code. Extend this to
all local variables.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
eade730e47 Publish standard and Python registered structs
Standard struct definition where not usable in dynamic settings
(e.g. to_type()), as the definition was not registered to the corresponding
struct name and type.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
15166819ed Implement Python-registered structs
Python can register global struct definitions via ldmud.register_struct().
Also added corresponding namespace ldmud.registered_structs that contains
all registered struct types.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
0142ebbd27 Added abilities to Python integration to trace LPC program execution
Added BEFORE_INSTRUCTION hook to be called for every instruction.
Added call_stack property to query the current stack.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
e453976fdd Fix crash in Python's register_type() function
When a type was registered a second time, the cleanup function might call
xfree() on invalid pointers.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
b6e70a7e6c Fix crash when Python calls a destructed object
When calling an lfun from Python, the corresponding object was not
checked accordingly.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
50ab31c108 Fix cleanup when building arguments for LPC calls from Python
When Python code called into LPC with invalid arguments,
there was an off-by-one error when cleaning up arguments on the stack.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
1db6633aab Implement to_type() efun
to_type() converts a value to a given target type.
If required, does so recursively.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
8b2b719784 Added sub-namespace for registered efuns and types
ldmud.registered_efuns contains all registered Python efuns and
ldmud.registered_types provides all registered Python types.
Those are read-only, for manipulation there is (un)register_efun/type().
2025-03-21 21:30:30 +01:00
Alexander Motzkau
52dc66d499 Add support for LPC type objects in Python
Fully support the LPC type system in Python, providing representations
for basic types (int, float, string, bytes), named (lightweight) object
types, concrete struct types and union types.
2022-10-10 23:38:01 +02:00
Alexander Motzkau
9c219db7cf Release Python global interpreter lock when not executing Python code
The global interpreter lock is acquired during initialization and never
released. So if any Python modules start additional threads they can
hardly run, because the lock is held by the main thread mostly all of
the time.
2022-11-07 22:27:52 +01:00
Alexander Motzkau
73ed64c46b Fix save_value()/save_object() for Python objects
For non-saveable Python objects the delimiter (comma) was printed twice.
2022-09-29 23:11:19 +02:00
Alexander Motzkau
508b6efc82 Add Python statistics to driver_info()
Add driver_info information DI_NUM_LPC_PYTHON_REFS and
DI_NUM_PYTHON_LPC_REFS to get the number of references between
both runtime environments.
2022-06-30 22:17:26 +02:00
Alexander Motzkau
8365fa5ebe Implement usage of Python objects in LPC
Python can register certain types for LPC. Objects of those types
can then be passed between Python and LPC code.
2022-05-25 23:16:58 +02:00
Alexander Motzkau
676eee0601 Fix crash in Python when accessing a swapped object
Python routines did restore the object but forgot to update internal pointers
resulting in dereference of invalid pointers.
2022-09-02 18:17:56 +02:00
Alexander Motzkau
ca6b3b9e9b Fix memory leak in Python ldmud.Mapping.__init__() function
The __init__() of ldmud.Mapping forgot the give up the references
of the dictionary items to transfer.
2022-08-01 19:20:40 +02:00
Alexander Motzkau
2593a95766 Handle uninitialized objects in Python gracefully
Detect uninitialized objects and pass them as zero (or
for arrays/mappings as empty array/mappings) to LPC.
2022-07-19 20:34:52 +02:00
Alexander Motzkau
788cd95871 Do cleanup operations across Python boundary
Include any LPC data exclusively held by Python code in the cleanup process,
which is to remove any dangling object references (replacing with 0 or
removing from mappings).
2022-06-29 23:47:41 +02:00
Alexander Motzkau
9a89c72a92 Implement range index operator for wide mappings
Introduce a mapping index operation m[key, index1 .. index2].
(Implements #753)
2021-06-09 16:32:21 +02:00
Alexander Motzkau
c61f92f52d Fix crash when running LPC code on Python startup
At startup the current_object was initialized incorrectly (setting its type
to object, but with a NULL object), resulting in a NULL pointer dereference
later on. (Fixes #902)
2022-01-11 21:52:37 +01:00
Alexander Motzkau
bf44f19753 Save local variable names for inspection in coroutines
With the new pragma save_local_names the names of local variables are
stored in the program so they can be inspected (with Python) later on.
2022-01-09 21:22:34 +01:00
Alexander Motzkau
8556262748 Implement coroutines
Add a new type and several statements to LPC to implement coroutines.
Coroutines allow a function to suspend its execution and resume it
later.
2022-01-09 21:22:34 +01:00
Alexander Motzkau
0659a4124d Implement lightweight objects
Add a new type and data structure to LPC. Lightweight objects combine
properties from structs (small memory footprint, automatic lifetime
management) and objects (capsulation, functions).
(Implements #688)
2022-01-09 01:13:21 +01:00
Alexander Motzkau
2fb165ddbd Python: Add possibility to save data in an object
Give LPC objects a Python dictionary, so arbitrary members can be saved
there. So efuns can store a state there.
2022-01-08 22:16:53 +01:00
Alexander Motzkau
9414a7a046 Preprocessor statements and pragmas must be written in full
It is no more permissible to preprocessor statements in part
(e.g. '#incl <>' or just '# <>'), also pragma names must be written fully.
2021-02-02 20:41:00 +01:00
Alexander Motzkau
325b29fa14 Prevent empty mapping entries after failed assignments
A mapping entry will only be created when the actual assignment
is executed, not when the lvalue is created.
(Fixes #148)
2020-11-11 02:21:16 +01:00
Alexander Motzkau
0c8c25ad36 Implemented bool conversion for objects and closures in Python
The Object and Closure types in Python now support evaluation in a
boolean context and return False if the corresponding object was
destructed, True otherwise.
2020-10-27 19:40:09 +01:00
Alexander Motzkau
cc1d20ba91 Fix hash and call operator of closures in Python
The call operator crashed on uninitialized closures,
the hash operator did not hash lfun or efun closures correctly.
2020-10-24 13:51:58 +02:00
Alexander Motzkau
07c99b6e16 Implement support for lvalues of struct members in Python
Struct member access is now done via the .members attribute of
structs and lvalues. For Struct objects this will return a member
object with .name, .type and .value attributes. For Lvalue objects
this will return an Lvalue for the given member.
2020-08-26 22:27:57 +02:00
Alexander Motzkau
e682e553a8 Implement support for lvalues in Python
Add an Lvalue class to represent LPC lvalues.
2020-08-26 22:27:57 +02:00
Alexander Motzkau
f840212a68 Introduce pragma warn_unused_variables
When active the compiler will warn about variables that are not used,
i.e. not read from or not written to. The warning differentiates between
variables that were just declared, variables that were written to or
variables that were only read from. Taking a reference from a variable
is seen as a read/write access, so no warning afterwards.
2020-07-05 13:18:57 +02:00
Alexander Motzkau
a828c3616d Make pragma strict_types raise errors again
The last release reimplemented pragma strict_types with warning only,
this release will make that errors again.
2020-07-05 13:18:57 +02:00
Alexander Motzkau
012214967f Corrected checks for Python efun calls with ellipsis.
When checking the number of arguments for calls to Python efuns,
the existence of ellipsis in the argument list were ignored,
resulting in false compile errors.
2020-04-28 22:30:06 +02:00
Alexander Motzkau
987b89bbd8 Python: Added protector for replace_program()
When lfun or variable objects are created, we need to make sure,
the indices are adjusted if a replace_program() is in progress.
Just like closures we create a protector structure that will be
processed after the replace_program().
2020-04-28 22:30:06 +02:00
Alexander Motzkau
68bc5440c7 Python: Implemented variable list for object representation
In Python the representation of an LPC object offers an attribute
variables, that contains all variables of that object with some
information about it and an attribute to change its value.
2020-04-28 22:30:06 +02:00
Alexander Motzkau
855ee6441a Python: Implemented function list for object representation
In Python the representation of an LPC object offers an attribute
functions, that contains all visible functions of that object
with some information about that function and the call operator.
2020-04-28 22:30:06 +02:00
Alexander Motzkau
628a6ee00e Implemented type checks for Python efuns
If Python efuns have type annotations they are evaluated
at compile and runtime. Even without annotations the number
of arguments are checked at compile time.
2019-11-04 22:16:19 +01:00
Alexander Motzkau
9ebe41e5ce Implemented byte sequence support for Python.
Byte sequences are now passed as byte objects to Python and vice versa.
2019-04-28 16:43:50 +02:00
Alexander Motzkau
b3c3da3ffb Fixed a bug in type deduction of python efun calls.
When calling python efuns the expression return type
was left uninitialized, resulting in errors or even
crashs when that type was evaluated.
2018-01-30 23:27:00 +01:00
Alexander Motzkau
fa61acc6b7 Fixed a crash on exceptions with python efun closures.
On a call to python efun closures the funstart entry
in the constrol stack was left uninitialized, resulting
in a crash when it that value was used to generate
the stack trace.
2018-01-30 23:27:00 +01:00
Alexander Motzkau
4baeda32f3 Corrected test suite to respect the absence of pkg-python.
Omit the --python-script option when running without the python package
compiled in. Also the t-python test will be skipped. (Fixes #851)
2017-09-30 19:27:10 +02:00
Alexander Motzkau
a34d55ecec Python: Implemented iterators for mappings. 2016-10-12 22:27:48 +02:00
Alexander Motzkau
2e2069da48 Python: Implemented slices for arrays and mappings, and Object.name. 2016-10-12 22:27:47 +02:00
Alexander Motzkau
fc5cc09c9a Python: Implemented (un)register_hook 2016-10-12 22:27:47 +02:00