2021-06-21 21:02:20 +08:00
|
|
|
/*
|
2022-04-03 02:39:57 +08:00
|
|
|
* Copyright (c) 2020-2022 Thakee Nathees
|
|
|
|
* Copyright (c) 2021-2022 Pocketlang Contributors
|
2021-06-21 21:02:20 +08:00
|
|
|
* Distributed Under The MIT License
|
|
|
|
*/
|
|
|
|
|
2022-04-15 20:35:15 +08:00
|
|
|
#ifndef MODULES_H
|
|
|
|
#define MODULES_H
|
|
|
|
|
|
|
|
#include <pocketlang.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-29 02:33:20 +08:00
|
|
|
void registerModuleDummy(PKVM* vm);
|
2022-04-20 17:10:08 +08:00
|
|
|
void registerModuleIO(PKVM* vm);
|
|
|
|
void registerModulePath(PKVM* vm);
|
2022-04-22 00:07:38 +08:00
|
|
|
void registerModuleMath(PKVM* vm);
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Registers all the cli modules.
|
|
|
|
#define REGISTER_ALL_MODULES(vm) \
|
|
|
|
do { \
|
2022-04-29 02:33:20 +08:00
|
|
|
registerModuleDummy(vm); \
|
2022-04-20 17:10:08 +08:00
|
|
|
registerModuleIO(vm); \
|
|
|
|
registerModulePath(vm); \
|
2022-04-22 00:07:38 +08:00
|
|
|
registerModuleMath(vm); \
|
2022-04-20 17:10:08 +08:00
|
|
|
} while (false)
|
2021-06-21 21:02:20 +08:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2022-04-20 17:10:08 +08:00
|
|
|
/* MODULES INTERNAL */
|
2021-06-21 21:02:20 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Allocate a new module object of type [Ty].
|
|
|
|
#define NEW_OBJ(Ty) (Ty*)malloc(sizeof(Ty))
|
2021-06-28 21:47:19 +08:00
|
|
|
|
2022-04-20 17:10:08 +08:00
|
|
|
// Dellocate module object, allocated by NEW_OBJ(). Called by the freeObj
|
|
|
|
// callback.
|
|
|
|
#define FREE_OBJ(ptr) free(ptr)
|
2021-06-21 21:02:20 +08:00
|
|
|
|
2022-04-22 00:07:38 +08:00
|
|
|
// Returns the docstring of the function, which is a static const char* defined
|
|
|
|
// just above the function by the DEF() macro below.
|
|
|
|
#define DOCSTRING(fn) __doc_##fn
|
|
|
|
|
|
|
|
// A macro to declare a function, with docstring, which is defined as
|
|
|
|
// ___doc_<fn> = docstring; That'll used to generate function help text.
|
|
|
|
#define DEF(fn, docstring) \
|
|
|
|
static const char* DOCSTRING(fn) = docstring; \
|
|
|
|
static void fn(PKVM* vm)
|
|
|
|
|
2022-04-15 20:35:15 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* SHARED FUNCTIONS */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
// These are "public" module functions that can be shared. Since some modules
|
|
|
|
// can be used for cli's internals we're defining such functions here and they
|
|
|
|
// will be imported in the cli.
|
|
|
|
|
2022-05-04 14:28:23 +08:00
|
|
|
// The pocketlang's import statement path resolving function. This
|
|
|
|
// implementation is required by pockelang from it's hosting application
|
|
|
|
// inorder to use the import statements.
|
|
|
|
char* pathResolveImport(PKVM * vm, const char* from, const char* path);
|
2022-04-15 20:35:15 +08:00
|
|
|
|
|
|
|
#endif // MODULES_H
|