mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
The original attempt at handling the returns from loadModuleFn wasn't ideal. 889cae5ff1
Instead of making the host go via the VM allocation and need to understand it semantically, we can instead solve the problem of the unfreed return result directly.
This also opens up the option of providing a length parameter or other information needed later (length is optional, and not used as of right now, but exists to show intent).
72 lines
2.1 KiB
C
72 lines
2.1 KiB
C
#pragma once
|
|
#ifndef WREN_TEST_H
|
|
#define WREN_TEST_H
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "wren.h"
|
|
|
|
// The maximum number of components in a path. We can't normalize a path that
|
|
// contains more than this number of parts. The number here assumes a max path
|
|
// length of 4096, which is common on Linux, and then assumes each component is
|
|
// at least two characters, "/", and a single-letter directory name.
|
|
#define MAX_COMPONENTS 2048
|
|
|
|
typedef struct {
|
|
const char* start;
|
|
const char* end;
|
|
} Slice;
|
|
|
|
// Categorizes what form a path is.
|
|
typedef enum
|
|
{
|
|
// An absolute path, starting with "/" on POSIX systems, a drive letter on
|
|
// Windows, etc.
|
|
PATH_TYPE_ABSOLUTE,
|
|
|
|
// An explicitly relative path, starting with "./" or "../".
|
|
PATH_TYPE_RELATIVE,
|
|
|
|
// A path that has no leading prefix, like "foo/bar".
|
|
PATH_TYPE_SIMPLE,
|
|
} PathType;
|
|
|
|
|
|
typedef struct
|
|
{
|
|
// Dynamically allocated array of characters.
|
|
char* chars;
|
|
|
|
// The number of characters currently in use in [chars], not including the
|
|
// null terminator.
|
|
size_t length;
|
|
|
|
// Size of the allocated [chars] buffer.
|
|
size_t capacity;
|
|
} Path;
|
|
|
|
//path helpers
|
|
void ensureCapacity(Path* path, size_t capacity);
|
|
void appendSlice(Path* path, Slice slice);
|
|
void pathAppendString(Path* path, const char* string);
|
|
void pathFree(Path* path);
|
|
void pathDirName(Path* path);
|
|
void pathRemoveExtension(Path* path);
|
|
void pathAppendChar(Path* path, char c);
|
|
void pathJoin(Path* path, const char* string);
|
|
void pathNormalize(Path* path);
|
|
char* pathToString(Path* path);
|
|
PathType pathType(const char* path);
|
|
//file helpers
|
|
char* readFile(const char* path);
|
|
WrenLoadModuleResult readModule(WrenVM* vm, const char* module);
|
|
//vm helpers
|
|
void vm_write(WrenVM* vm, const char* text);
|
|
void reportError(WrenVM* vm, WrenErrorType type, const char* module, int line, const char* message);
|
|
const char* resolveModule(WrenVM* vm, const char* importer, const char* module);
|
|
//main helpers
|
|
bool isModuleAnAPITest(const char* module);
|
|
WrenInterpretResult runFile(WrenVM* vm, const char* path);
|
|
int handle_args(int argc, const char* argv[]);
|
|
|
|
#endif //WREN_TEST_H
|