mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-03-04 13:15:55 +08:00
New fibers are not added to temp list -- fixed
This commit is contained in:
parent
156a4e9203
commit
0cfdfa7415
@ -62,12 +62,13 @@ def log(*msg):
|
||||
sys.stderr.write(message + '\n')
|
||||
|
||||
def parse(path):
|
||||
dir = dirname(path).replace('\\', '/') ## Windows.
|
||||
text = ""
|
||||
with open(path, 'r') as fp:
|
||||
for line in fp.readlines():
|
||||
if "//<< AMALG_INLINE >>" in line:
|
||||
path = join(dirname(path), _get_include_path(line))
|
||||
path = path.replace('\\', '/') ## Aaah windows path.
|
||||
path = join(dir, _get_include_path(line))
|
||||
path = path.replace('\\', '/')
|
||||
text += parse(path) + '\n'
|
||||
else: text += line
|
||||
|
||||
|
@ -34,8 +34,7 @@ ALLOW_LONG_LINES = ('http://', 'https://', '<script ', '<link ', '<svg ')
|
||||
IGNORE_FILES = (
|
||||
"cli/modules/pknative.gen.c", ## FIXME: set gen path.
|
||||
"cli/argparse.h", ## FIXME: collect all thirdparty files.
|
||||
"src/libs/tp_dirent.h",
|
||||
"src/libs/tp_cwalk.h",
|
||||
"src/libs/ext_term.c",
|
||||
)
|
||||
|
||||
## A list of directory, contains C source files to perform static checks.
|
||||
|
@ -81,6 +81,7 @@ static char* stdinRead(PKVM* vm);
|
||||
static char* loadScript(PKVM* vm, const char* path);
|
||||
|
||||
void* pkRealloc(PKVM* vm, void* ptr, size_t size) {
|
||||
|
||||
ASSERT(vm->config.realloc_fn != NULL, "PKVM's allocator was NULL.");
|
||||
#if TRACE_MEMORY
|
||||
void* newptr = vm->config.realloc_fn(ptr, size, vm->config.user_data);
|
||||
|
@ -97,7 +97,7 @@ static void popMarkedObjectsInternal(Object* obj, PKVM* vm) {
|
||||
switch (obj->type) {
|
||||
case OBJ_STRING: {
|
||||
vm->bytes_allocated += sizeof(String);
|
||||
vm->bytes_allocated += ((size_t)((String*)obj)->length + 1);
|
||||
vm->bytes_allocated += ((size_t)((String*)obj)->capacity);
|
||||
} break;
|
||||
|
||||
case OBJ_LIST: {
|
||||
@ -410,12 +410,15 @@ Fiber* newFiber(PKVM* vm, Closure* closure) {
|
||||
ASSERT(closure == NULL || closure->fn->arity >= -1, OOPS);
|
||||
|
||||
Fiber* fiber = ALLOCATE(vm, Fiber);
|
||||
ASSERT(fiber != NULL, "Out of memory");
|
||||
|
||||
// Not sure why this memset is needed here. If it doesn't then remove it.
|
||||
memset(fiber, 0, sizeof(Fiber));
|
||||
|
||||
varInitObject(&fiber->_super, vm, OBJ_FIBER);
|
||||
|
||||
vmPushTempRef(vm, &fiber->_super); // fiber.
|
||||
|
||||
fiber->state = FIBER_NEW;
|
||||
fiber->closure = closure;
|
||||
|
||||
@ -431,6 +434,7 @@ Fiber* newFiber(PKVM* vm, Closure* closure) {
|
||||
if (stack_size == 0) stack_size++;
|
||||
|
||||
fiber->stack = ALLOCATE_ARRAY(vm, Var, stack_size);
|
||||
ASSERT(fiber->stack != NULL, "Out of memory");
|
||||
fiber->stack_size = stack_size;
|
||||
fiber->ret = fiber->stack;
|
||||
fiber->sp = fiber->stack + 1;
|
||||
@ -462,6 +466,8 @@ Fiber* newFiber(PKVM* vm, Closure* closure) {
|
||||
// but if we're trying to debut it may crash when dumping the return value).
|
||||
*fiber->ret = VAR_NULL;
|
||||
|
||||
vmPopTempRef(vm); // fiber.
|
||||
|
||||
return fiber;
|
||||
}
|
||||
|
||||
|
259
src/libs/ext_term.c
Normal file
259
src/libs/ext_term.c
Normal file
@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2022 Thakee Nathees
|
||||
* Copyright (c) 2021-2022 Pocketlang Contributors
|
||||
* Distributed Under The MIT License
|
||||
*/
|
||||
|
||||
#ifndef PK_AMALGAMATED
|
||||
#include "libs.h"
|
||||
#endif
|
||||
|
||||
#define TERM_IMPLEMENT
|
||||
#include "thirdparty/term/term.h" //<< AMALG_INLINE >>
|
||||
#undef TERM_IMPLEMENT
|
||||
|
||||
// A reference to the event class, to check is instance of.
|
||||
static PkHandle* _cls_term_event = NULL;
|
||||
|
||||
static void _setSlotVector(PKVM* vm, int slot, int tmp, double x, double y) {
|
||||
|
||||
if (!pkImportModule(vm, "types", slot)) return;
|
||||
if (!pkGetAttribute(vm, slot, "Vector", slot)) return;
|
||||
if (!pkNewInstance(vm, slot, slot, 0, 0)) return;
|
||||
|
||||
pkSetSlotNumber(vm, tmp, x);
|
||||
if (!pkSetAttribute(vm, slot, "x", tmp)) return;
|
||||
pkSetSlotNumber(vm, tmp, y);
|
||||
if (!pkSetAttribute(vm, slot, "y", tmp)) return;
|
||||
}
|
||||
|
||||
void* _termEventNew(PKVM* vm) {
|
||||
term_Event* event = pkRealloc(vm, NULL, sizeof(term_Event));
|
||||
event->type = TERM_ET_UNKNOWN;
|
||||
return event;
|
||||
}
|
||||
|
||||
void _termEventDelete(PKVM* vm, void* event) {
|
||||
pkRealloc(vm, event, 0);
|
||||
}
|
||||
|
||||
void _termEventGetter(PKVM* vm) {
|
||||
const char* name;
|
||||
if (!pkValidateSlotString(vm, 1, &name, NULL)) return;
|
||||
|
||||
term_Event* event = pkGetSelf(vm);
|
||||
|
||||
if (strcmp(name, "type") == 0) {
|
||||
pkSetSlotNumber(vm, 0, (double)event->type);
|
||||
|
||||
} else if (strcmp(name, "keycode") == 0) {
|
||||
pkSetSlotNumber(vm, 0, (double)event->key.code);
|
||||
|
||||
} else if (strcmp(name, "ascii") == 0) {
|
||||
pkSetSlotNumber(vm, 0, (double)event->key.ascii);
|
||||
|
||||
} else if (strcmp(name, "modifiers") == 0) {
|
||||
if (event->type == TERM_ET_KEY_DOWN) {
|
||||
pkSetSlotNumber(vm, 0, (double)event->key.modifiers);
|
||||
} else {
|
||||
pkSetSlotNumber(vm, 0, (double)event->mouse.modifiers);
|
||||
}
|
||||
|
||||
} else if (strcmp(name, "button") == 0) {
|
||||
pkSetSlotNumber(vm, 0, (double)event->mouse.button);
|
||||
|
||||
} else if (strcmp(name, "pos") == 0) {
|
||||
pkReserveSlots(vm, 2);
|
||||
_setSlotVector(vm, 0, 1, event->mouse.pos.x, event->mouse.pos.y);
|
||||
|
||||
} else if (strcmp(name, "scroll") == 0) {
|
||||
pkSetSlotBool(vm, 0, event->mouse.scroll);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void _registerEnums(PKVM* vm, PkHandle* term) {
|
||||
pkReserveSlots(vm, 1);
|
||||
pkSetSlotHandle(vm, 0, term);
|
||||
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_UNKNOWN); pkSetAttribute(vm, 0, "KEY_UNKNOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_0); pkSetAttribute(vm, 0, "KEY_0", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_1); pkSetAttribute(vm, 0, "KEY_1", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_2); pkSetAttribute(vm, 0, "KEY_2", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_3); pkSetAttribute(vm, 0, "KEY_3", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_4); pkSetAttribute(vm, 0, "KEY_4", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_5); pkSetAttribute(vm, 0, "KEY_5", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_6); pkSetAttribute(vm, 0, "KEY_6", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_7); pkSetAttribute(vm, 0, "KEY_7", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_8); pkSetAttribute(vm, 0, "KEY_8", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_9); pkSetAttribute(vm, 0, "KEY_9", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_A); pkSetAttribute(vm, 0, "KEY_A", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_B); pkSetAttribute(vm, 0, "KEY_B", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_C); pkSetAttribute(vm, 0, "KEY_C", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_D); pkSetAttribute(vm, 0, "KEY_D", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_E); pkSetAttribute(vm, 0, "KEY_E", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F); pkSetAttribute(vm, 0, "KEY_F", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_G); pkSetAttribute(vm, 0, "KEY_G", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_H); pkSetAttribute(vm, 0, "KEY_H", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_I); pkSetAttribute(vm, 0, "KEY_I", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_J); pkSetAttribute(vm, 0, "KEY_J", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_K); pkSetAttribute(vm, 0, "KEY_K", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_L); pkSetAttribute(vm, 0, "KEY_L", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_M); pkSetAttribute(vm, 0, "KEY_M", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_N); pkSetAttribute(vm, 0, "KEY_N", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_O); pkSetAttribute(vm, 0, "KEY_O", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_P); pkSetAttribute(vm, 0, "KEY_P", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_Q); pkSetAttribute(vm, 0, "KEY_Q", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_R); pkSetAttribute(vm, 0, "KEY_R", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_S); pkSetAttribute(vm, 0, "KEY_S", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_T); pkSetAttribute(vm, 0, "KEY_T", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_U); pkSetAttribute(vm, 0, "KEY_U", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_V); pkSetAttribute(vm, 0, "KEY_V", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_W); pkSetAttribute(vm, 0, "KEY_W", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_X); pkSetAttribute(vm, 0, "KEY_X", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_Y); pkSetAttribute(vm, 0, "KEY_Y", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_Z); pkSetAttribute(vm, 0, "KEY_Z", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_ESC); pkSetAttribute(vm, 0, "KEY_ESC", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_ENTER); pkSetAttribute(vm, 0, "KEY_ENTER", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_SPACE); pkSetAttribute(vm, 0, "KEY_SPACE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_HOME); pkSetAttribute(vm, 0, "KEY_HOME", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_END); pkSetAttribute(vm, 0, "KEY_END", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_PAGEUP); pkSetAttribute(vm, 0, "KEY_PAGEUP", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_PAGEDOWN); pkSetAttribute(vm, 0, "KEY_PAGEDOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_LEFT); pkSetAttribute(vm, 0, "KEY_LEFT", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_UP); pkSetAttribute(vm, 0, "KEY_UP", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_RIGHT); pkSetAttribute(vm, 0, "KEY_RIGHT", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_DOWN); pkSetAttribute(vm, 0, "KEY_DOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_INSERT); pkSetAttribute(vm, 0, "KEY_INSERT", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_DELETE); pkSetAttribute(vm, 0, "KEY_DELETE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_BACKSPACE); pkSetAttribute(vm, 0, "KEY_BACKSPACE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_TAB); pkSetAttribute(vm, 0, "KEY_TAB", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F1); pkSetAttribute(vm, 0, "KEY_F1", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F2); pkSetAttribute(vm, 0, "KEY_F2", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F3); pkSetAttribute(vm, 0, "KEY_F3", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F4); pkSetAttribute(vm, 0, "KEY_F4", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F5); pkSetAttribute(vm, 0, "KEY_F5", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F6); pkSetAttribute(vm, 0, "KEY_F6", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F7); pkSetAttribute(vm, 0, "KEY_F7", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F8); pkSetAttribute(vm, 0, "KEY_F8", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F9); pkSetAttribute(vm, 0, "KEY_F9", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F10); pkSetAttribute(vm, 0, "KEY_F10", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F11); pkSetAttribute(vm, 0, "KEY_F11", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_KEY_F12); pkSetAttribute(vm, 0, "KEY_F12", 1);
|
||||
|
||||
pkSetSlotNumber(vm, 1, TERM_MB_UNKNOWN); pkSetAttribute(vm, 0, "BUTTON_UNKNOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MB_LEFT); pkSetAttribute(vm, 0, "BUTTON_LEFT", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MB_MIDDLE); pkSetAttribute(vm, 0, "BUTTON_MIDDLE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MB_RIGHT); pkSetAttribute(vm, 0, "BUTTON_RIGHT", 1);
|
||||
|
||||
pkSetSlotNumber(vm, 1, TERM_MD_NONE); pkSetAttribute(vm, 0, "MD_NONE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MD_CTRL); pkSetAttribute(vm, 0, "MD_CTRL", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MD_ALT); pkSetAttribute(vm, 0, "MD_ALT", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_MD_SHIFT); pkSetAttribute(vm, 0, "MD_SHIFT", 1);
|
||||
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_UNKNOWN); pkSetAttribute(vm, 0, "EVENT_UNKNOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_KEY_DOWN); pkSetAttribute(vm, 0, "EVENT_KEY_DOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_RESIZE); pkSetAttribute(vm, 0, "EVENT_RESIZE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_DOUBLE_CLICK); pkSetAttribute(vm, 0, "EVENT_DOUBLE_CLICK", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_MOUSE_DOWN); pkSetAttribute(vm, 0, "EVENT_MOUSE_DOWN", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_MOUSE_UP); pkSetAttribute(vm, 0, "EVENT_MOUSE_UP", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_MOUSE_MOVE); pkSetAttribute(vm, 0, "EVENT_MOUSE_MOVE", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_MOUSE_DRAG); pkSetAttribute(vm, 0, "EVENT_MOUSE_DRAG", 1);
|
||||
pkSetSlotNumber(vm, 1, TERM_ET_MOUSE_SCROLL); pkSetAttribute(vm, 0, "EVENT_MOUSE_SCROLL", 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void _termInit(PKVM* vm) {
|
||||
bool capture_events;
|
||||
if (!pkValidateSlotBool(vm, 1, &capture_events)) return;
|
||||
term_init(capture_events);
|
||||
}
|
||||
|
||||
void _termCleanup(PKVM* vm) {
|
||||
term_cleanup();
|
||||
}
|
||||
|
||||
void _termIsatty(PKVM* vm) {
|
||||
pkSetSlotBool(vm, 0, term_isatty());
|
||||
}
|
||||
|
||||
void _termNewScreenBuffer(PKVM* vm) {
|
||||
term_new_screen_buffer();
|
||||
}
|
||||
|
||||
void _termRestoreScreenBuffer(PKVM* vm) {
|
||||
term_restore_screen_buffer();
|
||||
}
|
||||
|
||||
void _termGetSize(PKVM* vm) {
|
||||
pkReserveSlots(vm, 2);
|
||||
term_Vec size = term_getsize();
|
||||
_setSlotVector(vm, 0, 1, size.x, size.y);
|
||||
}
|
||||
|
||||
void _termGetPosition(PKVM* vm) {
|
||||
pkReserveSlots(vm, 2);
|
||||
term_Vec pos = term_getposition();
|
||||
_setSlotVector(vm, 0, 1, pos.x, pos.y);
|
||||
}
|
||||
|
||||
void _termSetPosition(PKVM* vm) {
|
||||
double x, y;
|
||||
|
||||
int argc = pkGetArgc(vm);
|
||||
if (!pkCheckArgcRange(vm, argc, 1, 2)) return;
|
||||
|
||||
if (argc == 1) {
|
||||
pkReserveSlots(vm, 3);
|
||||
if (!pkGetAttribute(vm, 1, "x", 2)) return;
|
||||
if (!pkValidateSlotNumber(vm, 2, &x)) return;
|
||||
|
||||
if (!pkGetAttribute(vm, 1, "y", 2)) return;
|
||||
if (!pkValidateSlotNumber(vm, 2, &y)) return;
|
||||
} else {
|
||||
if (!pkValidateSlotNumber(vm, 1, &x)) return;
|
||||
if (!pkValidateSlotNumber(vm, 2, &y)) return;
|
||||
}
|
||||
|
||||
term_Vec pos = term_vec((int)x, (int)y);
|
||||
term_setposition(pos);
|
||||
}
|
||||
|
||||
void _termReadEvent(PKVM* vm) {
|
||||
pkReserveSlots(vm, 3);
|
||||
pkSetSlotHandle(vm, 2, _cls_term_event);
|
||||
if (!pkValidateSlotInstanceOf(vm, 1, 2)) return;
|
||||
|
||||
term_Event* event = pkGetSlotNativeInstance(vm, 1);
|
||||
pkSetSlotBool(vm, 0, term_read_event(event));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleTerm(PKVM* vm) {
|
||||
PkHandle* term = pkNewModule(vm, "term");
|
||||
|
||||
_registerEnums(vm, term);
|
||||
pkModuleAddFunction(vm, term, "init", _termInit, 1);
|
||||
pkModuleAddFunction(vm, term, "cleanup", _termCleanup, 0);
|
||||
pkModuleAddFunction(vm, term, "isatty", _termIsatty, 0);
|
||||
pkModuleAddFunction(vm, term, "new_screen_buffer", _termNewScreenBuffer, 0);
|
||||
pkModuleAddFunction(vm, term, "restore_screen_buffer", _termRestoreScreenBuffer, 0);
|
||||
pkModuleAddFunction(vm, term, "getsize", _termGetSize, 0);
|
||||
pkModuleAddFunction(vm, term, "getposition", _termGetPosition, 0);
|
||||
pkModuleAddFunction(vm, term, "setposition", _termSetPosition, -1);
|
||||
pkModuleAddFunction(vm, term, "read_event", _termReadEvent, 1);
|
||||
|
||||
_cls_term_event = pkNewClass(vm, "Event", NULL, term, _termEventNew, _termEventDelete);
|
||||
pkClassAddMethod(vm, _cls_term_event, "@getter", _termEventGetter, 1);
|
||||
|
||||
pkRegisterModule(vm, term);
|
||||
pkReleaseHandle(vm, term);
|
||||
}
|
||||
|
||||
void cleanupModuleTerm(PKVM* vm) {
|
||||
if (_cls_term_event) pkReleaseHandle(vm, _cls_term_event);
|
||||
}
|
@ -8,6 +8,8 @@
|
||||
#include "libs.h"
|
||||
#endif
|
||||
|
||||
// Standard libraries.
|
||||
|
||||
void registerModuleMath(PKVM* vm);
|
||||
void registerModuleTypes(PKVM* vm);
|
||||
void registerModuleTime(PKVM* vm);
|
||||
@ -15,6 +17,12 @@ void registerModuleIO(PKVM* vm);
|
||||
void registerModulePath(PKVM* vm);
|
||||
void registerModuleDummy(PKVM* vm);
|
||||
|
||||
// Additional libraries.
|
||||
|
||||
void registerModuleTerm(PKVM* vm);
|
||||
void cleanupModuleTerm(PKVM* vm);
|
||||
|
||||
// Registers the modules.
|
||||
void registerLibs(PKVM* vm) {
|
||||
registerModuleMath(vm);
|
||||
registerModuleTypes(vm);
|
||||
@ -22,8 +30,11 @@ void registerLibs(PKVM* vm) {
|
||||
registerModuleIO(vm);
|
||||
registerModulePath(vm);
|
||||
registerModuleDummy(vm);
|
||||
|
||||
registerModuleTerm(vm);
|
||||
}
|
||||
|
||||
// Cleanup the modules.
|
||||
void cleanupLibs(PKVM* vm) {
|
||||
|
||||
cleanupModuleTerm(vm);
|
||||
}
|
||||
|
@ -144,6 +144,10 @@ DEF(_dummyCallMethod,
|
||||
if (!pkCallMethod(vm, 1, method, 2, 3, 0)) return;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleDummy(PKVM* vm) {
|
||||
|
||||
PkHandle* dummy = pkNewModule(vm, "dummy");
|
||||
|
@ -402,6 +402,10 @@ DEF(_fileTell, "") {
|
||||
pkSetSlotNumber(vm, 0, (double) ftell(file->fp));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleIO(PKVM* vm) {
|
||||
|
||||
PkHandle* io = pkNewModule(vm, "io");
|
||||
|
@ -181,6 +181,20 @@ DEF(stdMathRound,
|
||||
pkSetSlotNumber(vm, 0, round(num));
|
||||
}
|
||||
|
||||
DEF(stdMathRand,
|
||||
"rand() -> num\n"
|
||||
"Return a random runber in the range of 0..0x7fff.") {
|
||||
|
||||
// RAND_MAX is implementation dependent but is guaranteed to be at least
|
||||
// 0x7fff on any standard library implementation.
|
||||
// https://www.cplusplus.com/reference/cstdlib/RAND_MAX/
|
||||
pkSetSlotNumber(vm, 0, rand() % 0x7fff);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleMath(PKVM* vm) {
|
||||
|
||||
PkHandle* math = pkNewModule(vm, "math");
|
||||
@ -208,6 +222,7 @@ void registerModuleMath(PKVM* vm) {
|
||||
pkModuleAddFunction(vm, math, "atan", stdMathArcTangent, 1);
|
||||
pkModuleAddFunction(vm, math, "log10", stdMathLog10, 1);
|
||||
pkModuleAddFunction(vm, math, "round", stdMathRound, 1);
|
||||
pkModuleAddFunction(vm, math, "rand", stdMathRand, 0);
|
||||
|
||||
pkRegisterModule(vm, math);
|
||||
pkReleaseHandle(vm, math);
|
||||
|
@ -14,7 +14,7 @@
|
||||
// Refactor the bellow macro includes.
|
||||
|
||||
#define _CWALK_IMPL
|
||||
#include "tp_cwalk.h" //<< AMALG_INLINE >>
|
||||
#include "thirdparty/cwalk/cwalk.h" //<< AMALG_INLINE >>
|
||||
#undef _CWALK_IMPL
|
||||
|
||||
#include <errno.h>
|
||||
@ -28,7 +28,7 @@
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
|
||||
#include "tp_dirent.h" //<< AMALG_INLINE >>
|
||||
#include "thirdparty/dirent/dirent.h" //<< AMALG_INLINE >>
|
||||
|
||||
// access() function flag defines for windows.
|
||||
// Reference :https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess?view=msvc-170#remarks
|
||||
@ -339,6 +339,10 @@ DEF(_pathIsDir, "") {
|
||||
pkSetSlotBool(vm, 0, pathIsDir(path));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModulePath(PKVM* vm) {
|
||||
PkHandle* path = pkNewModule(vm, "path");
|
||||
|
||||
|
@ -47,6 +47,10 @@ DEF(_timeSleep,
|
||||
#endif
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleTime(PKVM* vm) {
|
||||
PkHandle* time = pkNewModule(vm, "time");
|
||||
|
||||
|
@ -257,7 +257,7 @@ void _vectorRepr(PKVM* vm) {
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* REGISTER TYPES */
|
||||
/* MODULE REGISTER */
|
||||
/*****************************************************************************/
|
||||
|
||||
void registerModuleTypes(PKVM* vm) {
|
||||
|
21
src/libs/thirdparty/cwalk/LICENSE
vendored
Normal file
21
src/libs/thirdparty/cwalk/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Leonard Iklé
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,27 +1,3 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 Leonard Iklé
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef CWK_LIBRARY_H
|
||||
#define CWK_LIBRARY_H
|
||||
|
21
src/libs/thirdparty/dirent/LICENSE
vendored
Normal file
21
src/libs/thirdparty/dirent/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 1998-2019 Toni Ronkko
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,27 +1,3 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 1998-2019 Toni Ronkko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Dirent interface for Microsoft Visual Studio
|
||||
*
|
21
src/libs/thirdparty/term/LICENSE
vendored
Normal file
21
src/libs/thirdparty/term/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Thakee Nathees
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
1027
src/libs/thirdparty/term/term.h
vendored
Normal file
1027
src/libs/thirdparty/term/term.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user