This commit is contained in:
nakst 2022-02-07 16:32:55 +00:00
parent b809edf13b
commit f385ad581c
6 changed files with 66 additions and 12 deletions

View File

@ -329,6 +329,37 @@ int External_DirectoryInternalNextIteration(ExecutionContext *context, Value *re
return 3;
}
int ExternalOpenDocumentEnumerate(ExecutionContext *context, Value *returnValue) {
EsBuffer buffer = { .canGrow = true };
_EsOpenDocumentEnumerate(&buffer);
size_t count = 0;
EsBufferReadInto(&buffer, &count, sizeof(size_t));
uintptr_t index = HeapAllocate(context);
context->heap[index].type = T_LIST;
context->heap[index].internalValuesAreManaged = true;
context->heap[index].length = count;
context->heap[index].list = (Value *) EsHeapAllocate(sizeof(Value) * count, false);
for (uintptr_t i = 0; i < count; i++) {
size_t pathBytes = 0;
EsBufferReadInto(&buffer, &pathBytes, sizeof(size_t));
char *path = (char *) EsHeapAllocate(pathBytes, false);
EsBufferReadInto(&buffer, path, pathBytes);
context->heap[index].list[i].i = HeapAllocate(context);
context->heap[context->heap[index].list[i].i].type = T_STR;
context->heap[context->heap[index].list[i].i].bytes = pathBytes;
context->heap[context->heap[index].list[i].i].text = path;
}
EsHeapFree(buffer.out);
EsAssert(!buffer.error);
returnValue->i = index;
return 3;
}
#define EXTERNAL_STUB(name) int name(ExecutionContext *, Value *) { EsPrint("Unimplemented " #name "\n"); EsAssert(false); return -1; }
// TODO What to do with these?

View File

@ -295,8 +295,8 @@ EsError MountPointAdd(const char *prefix, size_t prefixBytes, EsHandle base, boo
return error;
}
EsError EsMountPointAdd(const char *prefix, size_t prefixBytes, EsHandle base) {
return MountPointAdd(prefix, prefixBytes, base, true);
EsError EsMountPointAdd(const char *prefix, ptrdiff_t prefixBytes, EsHandle base) {
return MountPointAdd(prefix, prefixBytes == -1 ? EsCStringLength(prefix) : prefixBytes, base, true);
}
bool NodeFindMountPoint(const char *prefix, size_t prefixBytes, EsMountPoint *result, bool mutexTaken) {
@ -321,14 +321,19 @@ bool NodeFindMountPoint(const char *prefix, size_t prefixBytes, EsMountPoint *re
return found;
}
bool EsMountPointRemove(const char *prefix, size_t prefixBytes) {
bool EsMountPointRemove(const char *prefix, ptrdiff_t prefixBytes) {
if (prefixBytes == -1) {
prefixBytes = EsCStringLength(prefix);
}
EsMutexAcquire(&api.mountPointsMutex);
bool found = false;
for (uintptr_t i = 0; i < api.mountPoints.Length(); i++) {
EsMountPoint *mountPoint = &api.mountPoints[i];
if (prefixBytes >= mountPoint->prefixBytes && 0 == EsMemoryCompare(prefix, mountPoint->prefix, mountPoint->prefixBytes)) {
if ((uintptr_t) prefixBytes >= mountPoint->prefixBytes
&& 0 == EsMemoryCompare(prefix, mountPoint->prefix, mountPoint->prefixBytes)) {
EsAssert(mountPoint->addedByApplication);
EsHandleClose(mountPoint->base);
api.mountPoints.Delete(i);
@ -341,7 +346,11 @@ bool EsMountPointRemove(const char *prefix, size_t prefixBytes) {
return found;
}
bool EsMountPointGetVolumeInformation(const char *prefix, size_t prefixBytes, EsVolumeInformation *information) {
bool EsMountPointGetVolumeInformation(const char *prefix, ptrdiff_t prefixBytes, EsVolumeInformation *information) {
if (prefixBytes == -1) {
prefixBytes = EsCStringLength(prefix);
}
EsMutexAcquire(&api.mountPointsMutex);
EsMountPoint mountPoint;
bool found = NodeFindMountPoint(prefix, prefixBytes, &mountPoint, true);

View File

@ -2056,9 +2056,9 @@ function EsFileOffsetDifference EsFileStoreGetSize(EsFileStore *file); // Return
function void *EsFileStoreMap(EsFileStore *file, size_t *fileSize, uint32_t flags);
// These calls require permission_all_files.
function bool EsMountPointGetVolumeInformation(const char *prefix, size_t prefixBytes, EsVolumeInformation *information); // Returns false if the mount point does not exist.
function EsError EsMountPointAdd(const char *prefix, size_t prefixBytes, EsHandle base); // The system maintains a duplicate of the base handle.
function bool EsMountPointRemove(const char *prefix, size_t prefixBytes); // Returns false if the mount point does not exist. You can only remove mount points you added with EsMountPointAdd.
function bool EsMountPointGetVolumeInformation(STRING prefix, EsVolumeInformation *information); // Returns false if the mount point does not exist.
function EsError EsMountPointAdd(STRING prefix, EsHandle base); // The system maintains a duplicate of the base handle.
function bool EsMountPointRemove(STRING prefix); // Returns false if the mount point does not exist. You can only remove mount points you added with EsMountPointAdd.
function void EsOpenDocumentQueryInformation(STRING filePath, EsOpenDocumentInformation *information);
function void _EsPathAnnouncePathMoved(STRING oldPath, STRING newPath); // Set oldPathBytes = 0 to make the file manager refresh the path.
function void _EsOpenDocumentEnumerate(EsBuffer *outputBuffer);
@ -2132,8 +2132,8 @@ function void EsAssertionFailure(EsCString cFile, int line);
function EsCalculationValue EsCalculateFromUserExpression(EsCString cExpression); // For user input only; do not rely on consistent behaviour across versions; use with message mutex.
function_not_in_kernel void EsPanic(EsCString format, ...);
function_not_in_kernel void EsPrint(EsCString format, ...);
function void EsPanic(EsCString format, ...);
function void EsPrint(EsCString format, ...);
function void EsPrintDirect(STRING string);
function void EsPrintHelloWorld();
@ -2281,7 +2281,7 @@ function const char *EsStringFormatTemporary(EsCString format, ...); // Not thr
function ptrdiff_t EsStringFormatV(char *buffer, size_t bufferLength, EsCString format, va_list arguments);
function bool EsStringFormatAppend(char *buffer, size_t bufferLength, size_t *bufferPosition, EsCString format, ...); // Return false if buffer filled.
function bool EsStringFormatAppendV(char *buffer, size_t bufferLength, size_t *bufferPosition, EsCString format, va_list arguments);
function bool EsUTF8IsValid(const char *input, ptrdiff_t bytes); // Does not check for surrogate characters or overlong sequences of non-ASCII characters.
function bool EsUTF8IsValid(STRING input); // Does not check for surrogate characters or overlong sequences of non-ASCII characters.
function double EsDoubleParse(STRING string, char **endptr);
function int64_t EsIntegerParse(STRING text); // Parses in hexadecimal if the first two characters are '0x'.

View File

@ -22,6 +22,7 @@ void KernelInitialise() {
}
void KernelMain(uintptr_t) {
EsPrint("Test");
desktopProcess = ProcessSpawn(PROCESS_DESKTOP); // Spawn the desktop process.
DriversInitialise(); // Load the root device.
ProcessStart(desktopProcess, EsLiteral(K_DESKTOP_EXECUTABLE)); // Start the desktop process.

View File

@ -7,7 +7,7 @@
extern "C" void KernelInitialise();
extern "C" int EsStringCompareRaw(const char *s1, size_t b1, const char *s2, size_t b2);
void EsPrint(const char *format, ...);
extern "C" void EsPrint(const char *format, ...);
struct ExportedKernelFunction {
void *address;

View File

@ -417,6 +417,11 @@ void ExternalPassREPLResult(ExecutionContext *context, Value value);
// --------------------------------- Base module.
char baseModuleSource[] = {
// TODO Temporary.
"struct DirectoryChild { str name; bool isDirectory; int size; };"
"DirectoryChild[] Dir() { str[] names = DirectoryEnumerateChildren(\"0:\"); DirectoryChild[] result = new DirectoryChild[]; result:resize(names:len()); for int i = 0; i < names:len(); i += 1 { result[i] = new DirectoryChild; result[i].name = names[i]; result[i].isDirectory = PathIsDirectory(\"0:/\"+names[i]); result[i].size = FileGetSize(\"0:/\"+names[i]); } return result;}"
"str[] OpenDocumentEnumerate() #extcall;"
// Logging:
"void PrintStdErr(str x) #extcall;"
@ -707,6 +712,7 @@ int ExternalRandomInt(ExecutionContext *context, Value *returnValue); // TODO Th
int External_DirectoryInternalStartIteration(ExecutionContext *context, Value *returnValue);
int External_DirectoryInternalNextIteration(ExecutionContext *context, Value *returnValue);
int External_DirectoryInternalEndIteration(ExecutionContext *context, Value *returnValue);
int ExternalOpenDocumentEnumerate(ExecutionContext *context, Value *returnValue);
ExternalFunction externalFunctions[] = {
{ .cName = "PrintStdErr", .callback = ExternalPrintStdErr },
@ -744,6 +750,7 @@ ExternalFunction externalFunctions[] = {
{ .cName = "_DirectoryInternalStartIteration", .callback = External_DirectoryInternalStartIteration },
{ .cName = "_DirectoryInternalNextIteration", .callback = External_DirectoryInternalNextIteration },
{ .cName = "_DirectoryInternalEndIteration", .callback = External_DirectoryInternalEndIteration },
{ .cName = "OpenDocumentEnumerate", .callback = ExternalOpenDocumentEnumerate },
};
// --------------------------------- Tokenization and parsing.
@ -5749,6 +5756,12 @@ int ExternalSystemSleepMs(ExecutionContext *context, Value *returnValue) {
#endif
}
int ExternalOpenDocumentEnumerate(ExecutionContext *context, Value *returnValue) {
(void) context;
returnValue->i = 0;
return 3;
}
CoroutineState *ExternalCoroutineWaitAny(ExecutionContext *context) {
(void) context;
while (sem_wait(&externalCoroutineSemaphore) == -1);