Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto generate CLI module registry #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/cli.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "vm.h"
#include "cli.h"

void setRootDirectory(WrenVM* vm) {
void cliSetRootDirectory(WrenVM* vm) {
const char* dir = wrenGetSlotString(vm,1);
// const char* boo = malloc(20);
// boo = "test";
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef cli_h
#define cli_h

void setRootDirectory(WrenVM* vm);
void cliSetRootDirectory(WrenVM* vm);

#endif

Expand Down
270 changes: 140 additions & 130 deletions src/cli/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,45 @@
#include "_wren.inc"
#include "essentials.h"

extern void setRootDirectory(WrenVM* vm);
extern void directoryList(WrenVM* vm);

// To locate foreign classes and modules, we build a big directory for them in
// static data. The nested collection initializer syntax gets pretty noisy, so
// define a couple of macros to make it easier.
#define SENTINEL_METHOD { false, NULL, NULL }
#define SENTINEL_CLASS { NULL, { SENTINEL_METHOD } }
#define SENTINEL_MODULE {NULL, NULL, { SENTINEL_CLASS } }

#define NAMED_MODULE(name, identifier ) { #name, &identifier##ModuleSource, {
#define MODULE(name) { #name, &name##ModuleSource, {
#define END_MODULE SENTINEL_CLASS } },

#define CLASS(name) { #name, {
#define END_CLASS SENTINEL_METHOD } },

#define METHOD(signature, fn) { false, signature, fn },
#define STATIC_METHOD(signature, fn) { true, signature, fn },
#define ALLOCATE(fn) { true, "<allocate>", (WrenForeignMethodFn)fn },
#define FINALIZE(fn) { true, "<finalize>", (WrenForeignMethodFn)fn },


// The array of built-in modules.
/* START AUTOGEN: core.cli.modules */
extern void cliSetRootDirectory(WrenVM* vm);
extern void directoryCreate(WrenVM* vm);
extern void directoryDelete(WrenVM* vm);
extern void fileAllocate(WrenVM* vm);
extern void fileFinalize(void* data);
extern void directoryList(WrenVM* vm);
extern void fileDescriptor(WrenVM* vm);
extern void fileDelete(WrenVM* vm);
extern void fileOpen(WrenVM* vm);
extern void fileRealPath(WrenVM* vm);
extern void fileSizePath(WrenVM* vm);
extern void fileClose(WrenVM* vm);
extern void fileDescriptor(WrenVM* vm);
extern void fileReadBytes(WrenVM* vm);
extern void fileRealPath(WrenVM* vm);
extern void fileSize(WrenVM* vm);
extern void fileStat(WrenVM* vm);
extern void fileWriteBytes(WrenVM* vm);
extern void platformHomePath(WrenVM* vm);
extern void platformIsPosix(WrenVM* vm);
extern void platformName(WrenVM* vm);
extern void processAllArguments(WrenVM* vm);
extern void processChdir(WrenVM* vm);
extern void processCwd(WrenVM* vm);
extern void processPid(WrenVM* vm);
extern void processPpid(WrenVM* vm);
extern void processVersion(WrenVM* vm);
extern void processExit(WrenVM* vm);
extern void processExec(WrenVM* vm);
extern void fileAllocate(WrenVM* vm);
extern void fileFinalize(void* data);
extern void statPath(WrenVM* vm);
extern void statBlockCount(WrenVM* vm);
extern void statBlockSize(WrenVM* vm);
Expand All @@ -51,130 +63,128 @@ extern void statMode(WrenVM* vm);
extern void statSize(WrenVM* vm);
extern void statSpecialDevice(WrenVM* vm);
extern void statUser(WrenVM* vm);
extern void statIsDirectory(WrenVM* vm);
extern void statIsFile(WrenVM* vm);
extern void statIsDirectory(WrenVM* vm);
extern void statAllocate(WrenVM* vm);
extern void statFinalize(void* data);
extern void stdinIsRaw(WrenVM* vm);
extern void stdinIsRawSet(WrenVM* vm);
extern void stdinIsTerminal(WrenVM* vm);
extern void stdinReadStart(WrenVM* vm);
extern void stdinReadStop(WrenVM* vm);
extern void stdoutFlush(WrenVM* vm);
extern void stderrWrite(WrenVM* vm);
extern void stdoutFlush(WrenVM* vm);
extern void platformHomePath(WrenVM* vm);
extern void platformIsPosix(WrenVM* vm);
extern void platformName(WrenVM* vm);
extern void processExec(WrenVM* vm);
extern void processAllArguments(WrenVM* vm);
extern void processCwd(WrenVM* vm);
extern void processChdir(WrenVM* vm);
extern void processPid(WrenVM* vm);
extern void processPpid(WrenVM* vm);
extern void processVersion(WrenVM* vm);
extern void processExit(WrenVM* vm);
extern void schedulerCaptureMethods(WrenVM* vm);
extern void timerStartTimer(WrenVM* vm);



// To locate foreign classes and modules, we build a big directory for them in
// static data. The nested collection initializer syntax gets pretty noisy, so
// define a couple of macros to make it easier.
#define SENTINEL_METHOD { false, NULL, NULL }
#define SENTINEL_CLASS { NULL, { SENTINEL_METHOD } }
#define SENTINEL_MODULE {NULL, NULL, { SENTINEL_CLASS } }

#define NAMED_MODULE(name, identifier ) { #name, &identifier##ModuleSource, {
#define MODULE(name) { #name, &name##ModuleSource, {
#define END_MODULE SENTINEL_CLASS } },

#define CLASS(name) { #name, {
#define END_CLASS SENTINEL_METHOD } },

#define METHOD(signature, fn) { false, signature, fn },
#define STATIC_METHOD(signature, fn) { true, signature, fn },
#define ALLOCATE(fn) { true, "<allocate>", (WrenForeignMethodFn)fn },
#define FINALIZE(fn) { true, "<finalize>", (WrenForeignMethodFn)fn },

// The array of built-in modules.
static ModuleRegistry coreCLImodules[] =
{
MODULE(runtime)
END_MODULE
MODULE(cli)
CLASS(CLI)
STATIC_METHOD("setRootDirectory_(_)", setRootDirectory)
END_CLASS
END_MODULE
MODULE(io)
CLASS(Directory)
STATIC_METHOD("create_(_,_)", directoryCreate)
STATIC_METHOD("delete_(_,_)", directoryDelete)
STATIC_METHOD("list_(_,_)", directoryList)
END_CLASS
CLASS(File)
ALLOCATE(fileAllocate)
FINALIZE(fileFinalize)
STATIC_METHOD("delete_(_,_)", fileDelete)
STATIC_METHOD("open_(_,_,_)", fileOpen)
STATIC_METHOD("realPath_(_,_)", fileRealPath)
STATIC_METHOD("sizePath_(_,_)", fileSizePath)
METHOD("close_(_)", fileClose)
METHOD("descriptor", fileDescriptor)
METHOD("readBytes_(_,_,_)", fileReadBytes)
METHOD("size_(_)", fileSize)
METHOD("stat_(_)", fileStat)
METHOD("writeBytes_(_,_,_)", fileWriteBytes)
END_CLASS
CLASS(Stat)
STATIC_METHOD("path_(_,_)", statPath)
METHOD("blockCount", statBlockCount)
METHOD("blockSize", statBlockSize)
METHOD("device", statDevice)
METHOD("group", statGroup)
METHOD("inode", statInode)
METHOD("linkCount", statLinkCount)
METHOD("mode", statMode)
METHOD("size", statSize)
METHOD("specialDevice", statSpecialDevice)
METHOD("user", statUser)
METHOD("isDirectory", statIsDirectory)
METHOD("isFile", statIsFile)
END_CLASS
CLASS(Stdin)
STATIC_METHOD("isRaw", stdinIsRaw)
STATIC_METHOD("isRaw=(_)", stdinIsRawSet)
STATIC_METHOD("isTerminal", stdinIsTerminal)
STATIC_METHOD("readStart_()", stdinReadStart)
STATIC_METHOD("readStop_()", stdinReadStop)
END_CLASS
CLASS(Stdout)
STATIC_METHOD("flush()", stdoutFlush)
END_CLASS
CLASS(Stderr)
STATIC_METHOD("write(_)", stderrWrite)
END_CLASS
END_MODULE
MODULE(os)
CLASS(Platform)
STATIC_METHOD("homePath", platformHomePath)
STATIC_METHOD("isPosix", platformIsPosix)
STATIC_METHOD("name", platformName)
END_CLASS
CLASS(Process)
STATIC_METHOD("allArguments", processAllArguments)
STATIC_METHOD("chdir_(_)", processChdir)
STATIC_METHOD("cwd", processCwd)
STATIC_METHOD("pid", processPid)
STATIC_METHOD("ppid", processPpid)
STATIC_METHOD("version", processVersion)
STATIC_METHOD("exit_(_)", processExit)
STATIC_METHOD("exec_(_,_,_,_,_)", processExec)
END_CLASS
END_MODULE
MODULE(repl)
END_MODULE
MODULE(scheduler)
CLASS(Scheduler)
STATIC_METHOD("captureMethods_()", schedulerCaptureMethods)
END_CLASS
END_MODULE
MODULE(timer)
CLASS(Timer)
STATIC_METHOD("startTimer_(_,_)", timerStartTimer)
END_CLASS
END_MODULE

SENTINEL_MODULE
static ModuleRegistry coreCLImodules[] = {
MODULE(cli)
CLASS(CLI)
STATIC_METHOD("setRootDirectory_(_)", cliSetRootDirectory)
END_CLASS
END_MODULE

MODULE(io)
CLASS(Directory)
STATIC_METHOD("create_(_,_)", directoryCreate)
STATIC_METHOD("delete_(_,_)", directoryDelete)
STATIC_METHOD("list_(_,_)", directoryList)
END_CLASS
CLASS(File)
ALLOCATE(fileAllocate)
FINALIZE(fileFinalize)
METHOD("descriptor", fileDescriptor)
STATIC_METHOD("delete_(_,_)", fileDelete)
STATIC_METHOD("open_(_,_,_)", fileOpen)
STATIC_METHOD("realPath_(_,_)", fileRealPath)
STATIC_METHOD("sizePath_(_,_)", fileSizePath)
METHOD("close_(_)", fileClose)
METHOD("readBytes_(_,_,_)", fileReadBytes)
METHOD("size_(_)", fileSize)
METHOD("stat_(_)", fileStat)
METHOD("writeBytes_(_,_,_)", fileWriteBytes)
END_CLASS
CLASS(Stat)
ALLOCATE(statAllocate)
FINALIZE(statFinalize)
STATIC_METHOD("path_(_,_)", statPath)
METHOD("blockCount", statBlockCount)
METHOD("blockSize", statBlockSize)
METHOD("device", statDevice)
METHOD("group", statGroup)
METHOD("inode", statInode)
METHOD("linkCount", statLinkCount)
METHOD("mode", statMode)
METHOD("size", statSize)
METHOD("specialDevice", statSpecialDevice)
METHOD("user", statUser)
METHOD("isFile", statIsFile)
METHOD("isDirectory", statIsDirectory)
END_CLASS
CLASS(Stdin)
STATIC_METHOD("isRaw", stdinIsRaw)
STATIC_METHOD("isRaw=(_)", stdinIsRawSet)
STATIC_METHOD("isTerminal", stdinIsTerminal)
STATIC_METHOD("readStart_()", stdinReadStart)
STATIC_METHOD("readStop_()", stdinReadStop)
END_CLASS
CLASS(Stderr)
STATIC_METHOD("write(_)", stderrWrite)
END_CLASS
CLASS(Stdout)
STATIC_METHOD("flush()", stdoutFlush)
END_CLASS
END_MODULE

MODULE(os)
CLASS(Platform)
STATIC_METHOD("homePath", platformHomePath)
STATIC_METHOD("isPosix", platformIsPosix)
STATIC_METHOD("name", platformName)
END_CLASS
CLASS(Process)
STATIC_METHOD("exec_(_,_,_,_,_)", processExec)
STATIC_METHOD("allArguments", processAllArguments)
STATIC_METHOD("cwd", processCwd)
STATIC_METHOD("chdir_(_)", processChdir)
STATIC_METHOD("pid", processPid)
STATIC_METHOD("ppid", processPpid)
STATIC_METHOD("version", processVersion)
STATIC_METHOD("exit_(_)", processExit)
END_CLASS
END_MODULE

MODULE(repl)
END_MODULE

MODULE(runtime)
END_MODULE

MODULE(scheduler)
CLASS(Scheduler)
STATIC_METHOD("captureMethods_()", schedulerCaptureMethods)
END_CLASS
END_MODULE

MODULE(timer)
CLASS(Timer)
STATIC_METHOD("startTimer_(_,_)", timerStartTimer)
END_CLASS
END_MODULE
SENTINEL_MODULE
};
/* END AUTOGEN: core.cli.modules */

static ModuleRegistry additionalRegistry[] =
{
Expand Down
7 changes: 7 additions & 0 deletions src/module/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ void fileWriteBytes(WrenVM* vm)
fileWriteBytesCallback);
}

void statAllocate(WrenVM* vm) {

}
void statFinalize(void* data) {

}

void statPath(WrenVM* vm)
{
const char* path = wrenGetSlotString(vm, 1);
Expand Down
Loading