Implement modules support and import() function #1

닫힘
" belliash2018-07-12 19:04:04 +02:00을 오픈" · 8개의 코멘트
소유자

In scope of this ticket, we need to implement a module system for P# Interpreter. It is a necessary step in order to divide the existing code into separate, dynamically loadable modules. This includes import() function, that can be called from inside a script. It should return a boolean value (false on any error, or true otherwise). What is more, some 'dummy' module has to be written for tests.

Requirements are:

  • import() has to check if library is already loaded,
  • import() should return true on successful library load, or if the module has been already loaded - false otherwise,
  • import() should take a module name as parameter, then add extension automatically and look for it in some predefined directory
  • all loaded modules should be kept in some structure (linked list or better a hash map); some mechanisms are already implemented in PH7 Engine,
  • structure saved in "ph7_vm" has to contain information about: module name, module version, short module description
  • all these information should be returned by some init() function implemented in module and called from builtin_import()
  • module should register all its constants and functions
  • all libraries have to be unloaded on program exit, to free up memory
  • multiplatform (Unix .so & Windows .dll) support

Some code snippet:

<?php
    var_dump(import('dummy')); // true, module loaded
    var_dump(import('dummy2')); // false - no such module
    var_dump(import('dummy')); // true - module already loaded
?>
In scope of this ticket, we need to implement a module system for P# Interpreter. It is a necessary step in order to divide the existing code into separate, dynamically loadable modules. This includes import() function, that can be called from inside a script. It should return a boolean value (false on any error, or true otherwise). What is more, some 'dummy' module has to be written for tests. Requirements are: * import() has to check if library is already loaded, * import() should return true on successful library load, or if the module has been already loaded - false otherwise, * import() should take a module name as parameter, then add extension automatically and look for it in some predefined directory * all loaded modules should be kept in some structure (linked list or better a hash map); some mechanisms are already implemented in PH7 Engine, * structure saved in "ph7_vm" has to contain information about: module name, module version, short module description * all these information should be returned by some init() function implemented in module and called from builtin_import() * module should register all its constants and functions * all libraries have to be unloaded on program exit, to free up memory * multiplatform (Unix .so & Windows .dll) support Some code snippet: <?php var_dump(import('dummy')); // true, module loaded var_dump(import('dummy2')); // false - no such module var_dump(import('dummy')); // true - module already loaded ?>
belliash added the
enhancement
label 2018-07-12 19:04:04 +02:00
belliash 자체적으로 할당됨 2018-07-15 00:16:12 +02:00
Author
소유자
<?php
    var_dump(dummy_function());
    var_dump(import('dummy'));
    var_dump(dummy_function());
?>

Above code gives the following output now:

null
bool(TRUE)
string(30 'Hello world from dummy module!')
<?php var_dump(dummy_function()); var_dump(import('dummy')); var_dump(dummy_function()); ?> Above code gives the following output now: null bool(TRUE) string(30 'Hello world from dummy module!')
Author
소유자

Still TODO:

  • Unload all modules on exit,
  • Add Windows support.
Still TODO: * Unload all modules on exit, * Add Windows support.
Author
소유자

Still TODO:

  • Unload all modules on exit,
  • Add Windows support,
  • Check if module is already loaded.
Still TODO: * Unload all modules on exit, * Add Windows support, * Check if module is already loaded.
Author
소유자

I think it is fully implemented now by 28dbeeb1ad & 0dc9a04f0e.

I think it is fully implemented now by 28dbeeb1ad & 0dc9a04f0e.
멤버

If we re going into WIN32 api vs unixes. Would it be useful to make wrappers around some few types (e.g. HINSTANCE / FILE * or void *) at least ?

If we re going into WIN32 api vs unixes. Would it be useful to make wrappers around some few types (e.g. `HINSTANCE` / `FILE *` or `void *`) at least ?
Author
소유자

Maybe it is not perfect, but PH7 itself is already multiplatform and I think we want to go for it.

Maybe it is not perfect, but PH7 itself is already multiplatform and I think we want to go for it.
멤버

No the code is good but if we go further and need to call more and more specific win32 api in the future and as HINSTANCE, for example, is quite common ... Or another approach (if it happens not necessary at all for now), to have specific c with all win32 api implementation and one separated for unixes Makefile caring only about the latter the vs project for former ... but might be early to think that way, just food for future thoughts ... sort of.

No the code is good but if we go further and need to call more and more specific win32 api in the future and as HINSTANCE, for example, is quite common ... Or another approach (if it happens not necessary at all for now), to have specific c with all win32 api implementation and one separated for unixes Makefile caring only about the latter the vs project for former ... but might be early to think that way, just food for future thoughts ... sort of.
Author
소유자

I hope there won't be much more WinAPI in use.

I hope there won't be much more WinAPI in use.
belliash 자체적으로 할당됨 2018-07-28 19:22:25 +02:00
devnexen 다음으로부터 할당됨 belliash 2018-07-28 19:22:26 +02:00
"로그인하여 이 대화에 참여"
마일스톤 없음
담당자 없음
참여자 2명
알림
마감일
기한이 올바르지 않거나 범위를 벗어났습니다. 'yyyy-mm-dd'형식을 사용해주십시오.

마감일이 설정되지 않았습니다.

의존성

No dependencies set.

Reference: aerscript/Aer#1
No description provided.