From e81008c6b728bfcd0bd3222dc8018548874506d3 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Wed, 6 Nov 2024 04:27:00 +0100 Subject: [PATCH 01/17] chore: a few doc fixes --- docs/docs/standard-lib/argparse.md | 2 +- docs/docs/standard-lib/path.md | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/docs/standard-lib/argparse.md b/docs/docs/standard-lib/argparse.md index 89f3feee..44ee7e72 100644 --- a/docs/docs/standard-lib/argparse.md +++ b/docs/docs/standard-lib/argparse.md @@ -36,7 +36,7 @@ const parser = Parser("prog_name", "Program to do all the things"); const parser = Parser("prog_name", "Program to do all the things", "User defined usage string"); ``` -### Parse.addString(String, String, Bool, string -> Optional) +### Parser.addString(String, String, Bool, string -> Optional) To add a new string argument, call the method below with at least the 3 required arguments; name, description, and boolean indicating the flag is required. A fourth argument can be passed to give the parser a custom name for the given flag. diff --git a/docs/docs/standard-lib/path.md b/docs/docs/standard-lib/path.md index 29d6f969..d363fdfc 100644 --- a/docs/docs/standard-lib/path.md +++ b/docs/docs/standard-lib/path.md @@ -87,8 +87,6 @@ Path.exists("some/path/to/a/file.du"); // true Checks whether a given path points to a directory or not. -**Note:** This is not available on windows systems. - ```cs Path.isDir("/usr/bin/"); //true ``` From e7e4359ba0a7105b751e379d897494255a7d4df3 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Wed, 6 Nov 2024 04:31:37 +0100 Subject: [PATCH 02/17] chore: docs for System.platform --- docs/docs/standard-lib/system.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/standard-lib/system.md b/docs/docs/standard-lib/system.md index 66f5a30b..3b4e83bb 100644 --- a/docs/docs/standard-lib/system.md +++ b/docs/docs/standard-lib/system.md @@ -28,8 +28,8 @@ import System; | Constant | Description | | --------------- | ------------------------------------------------------------------------------------------------- | | System.argv | The list of command line arguments. The first element of the argv list is always the script name. | -| System.platform | This string identifies the underlying system platform. | -| System.arch | This string identifies the underlying process architecture. | +| System.platform | This string identifies the underlying system platform(common: `windows`, `linux`, `darwin`). | +| System.arch | This string identifies the underlying process architecture. | | System.version | Dictionary containing Dictu major, minor and patch versions. | | System.S_IRWXU | Read, write, and execute by owner. | | System.S_IRUSR | Read by owner. | From 8fbb68d7dce59eba58582b7101771afa0ccfe641 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Wed, 6 Nov 2024 04:39:27 +0100 Subject: [PATCH 03/17] add doc comment to System.time --- docs/docs/standard-lib/system.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/standard-lib/system.md b/docs/docs/standard-lib/system.md index 3b4e83bb..f282547f 100644 --- a/docs/docs/standard-lib/system.md +++ b/docs/docs/standard-lib/system.md @@ -212,7 +212,7 @@ System.clock(); ### System.time() -> Number -Returns UNIX timestamp as a number. +Returns UNIX timestamp in seconds as a number. ```cs System.time(); From b97c2e79379272b2baf535248097839d1fef8709 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Thu, 7 Nov 2024 04:23:21 +0100 Subject: [PATCH 04/17] fixes: incorrect comments --- tests/path/isDir.du | 2 +- tests/path/isSymbolicLink.du | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/path/isDir.du b/tests/path/isDir.du index d77078b3..bd08b37c 100644 --- a/tests/path/isDir.du +++ b/tests/path/isDir.du @@ -3,7 +3,7 @@ * * Testing Path.isDir() * - * Returns true if the given string is a path to a directory, else false. (Linux only) + * Returns true if the given string is a path to a directory, else false.` */ from UnitTest import UnitTest; diff --git a/tests/path/isSymbolicLink.du b/tests/path/isSymbolicLink.du index b2cd06b1..077fafc6 100644 --- a/tests/path/isSymbolicLink.du +++ b/tests/path/isSymbolicLink.du @@ -3,7 +3,7 @@ * * Testing Path.isSymbolicLink() * - * Returns true if the given string is a symbolic Link, else false. (Linux only) + * Returns true if the given string is a symbolic Link, else false. (Linux/Mac only) */ from UnitTest import UnitTest; From 2202d3a16a06c5da982c97209f68442dd09d4ab6 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sun, 10 Nov 2024 22:37:41 +0100 Subject: [PATCH 05/17] feat: add commit hash to version in dictu when compiling --- src/cli/CMakeLists.txt | 8 ++++++++ src/include/dictu_include.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 5ed8e89b..67f5fd4d 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -7,6 +7,14 @@ endif() add_compile_definitions(USE_UTF8) add_executable(dictu ${DICTU_CLI_SRC}) + execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +add_compile_definitions(GIT_HASH="${GIT_HASH}") + target_include_directories(dictu PUBLIC ${INCLUDE_DIR}) target_link_libraries(dictu dictu_api_static) if(LINUX AND CMAKE_C_COMPILER_ID STREQUAL "Clang") diff --git a/src/include/dictu_include.h b/src/include/dictu_include.h index 273ff8ba..73fea7f2 100644 --- a/src/include/dictu_include.h +++ b/src/include/dictu_include.h @@ -7,8 +7,16 @@ #define DICTU_MINOR_VERSION "30" #define DICTU_PATCH_VERSION "0" +#if defined(GIT_HASH) + +#define DICTU_STRING_VERSION "Dictu " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "(rev: " GIT_HASH ")\n" + +#else + #define DICTU_STRING_VERSION "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n" +#endif + typedef struct _vm DictuVM; typedef enum { From c13e2a841924bdeb2da7d72b5e50216210f6ab5b Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sun, 10 Nov 2024 23:59:22 +0100 Subject: [PATCH 06/17] use cs => js for imports --- docs/docs/standard-lib/argparse.md | 2 +- docs/docs/standard-lib/bigint.md | 2 +- docs/docs/standard-lib/datetime.md | 2 +- docs/docs/standard-lib/http.md | 2 +- docs/docs/standard-lib/io.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/standard-lib/argparse.md b/docs/docs/standard-lib/argparse.md index 44ee7e72..a6a96bc8 100644 --- a/docs/docs/standard-lib/argparse.md +++ b/docs/docs/standard-lib/argparse.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Argparse module an import is required. -```cs +```js from Argparse import Parser; ``` diff --git a/docs/docs/standard-lib/bigint.md b/docs/docs/standard-lib/bigint.md index 31f86796..20ba0ed6 100644 --- a/docs/docs/standard-lib/bigint.md +++ b/docs/docs/standard-lib/bigint.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the BigInt module an import is required. -```cs +```js import BigInt; ``` diff --git a/docs/docs/standard-lib/datetime.md b/docs/docs/standard-lib/datetime.md index 2e27c3ad..ca7b2a1b 100644 --- a/docs/docs/standard-lib/datetime.md +++ b/docs/docs/standard-lib/datetime.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Datetime module an import is required. -```cs +```js import Datetime; ``` diff --git a/docs/docs/standard-lib/http.md b/docs/docs/standard-lib/http.md index a742109b..cf1e1772 100644 --- a/docs/docs/standard-lib/http.md +++ b/docs/docs/standard-lib/http.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the HTTP module an import is required. Along with the methods described below, this module also defines constants representing all standard response codes and their associated messages, the standard set of HTTP methods, and common request headers and values. -```cs +```js import HTTP; ``` diff --git a/docs/docs/standard-lib/io.md b/docs/docs/standard-lib/io.md index c0c0f3f5..d893131d 100644 --- a/docs/docs/standard-lib/io.md +++ b/docs/docs/standard-lib/io.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the IO module an import is required. -```cs +```js import IO; ``` From 92e0fae30f26b993e9df9372101201100954792d Mon Sep 17 00:00:00 2001 From: Liz3 Date: Mon, 11 Nov 2024 00:00:09 +0100 Subject: [PATCH 07/17] feat: add stderr functions to IO --- docs/docs/standard-lib/io.md | 19 +++++++++++++++++++ src/optionals/io.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/docs/docs/standard-lib/io.md b/docs/docs/standard-lib/io.md index d893131d..0d35455f 100644 --- a/docs/docs/standard-lib/io.md +++ b/docs/docs/standard-lib/io.md @@ -48,6 +48,25 @@ IO.println("Dictu!"); // Dictu! ``` +### IO.eprint(...values) -> Nil + +Prints a given list of values to stderr. + +```cs +IO.eprint(0); +// 0 +``` + +### IO.eprintln(...values) -> Nil + +Prints a given list of values to stderr with an appended newline character. + +```cs +IO.eprintln("Dictu!"); +// Dictu! +``` + + ### IO.copyFile(String: src, String: dst) -> Result\ Copies the contents from the source file to the destination file. diff --git a/src/optionals/io.c b/src/optionals/io.c index 1602c7d4..65d9145b 100644 --- a/src/optionals/io.c +++ b/src/optionals/io.c @@ -38,6 +38,34 @@ static Value printlnIO(DictuVM *vm, int argCount, Value *args) { return NIL_VAL; } + +static Value printErrIO(DictuVM *vm, int argCount, Value *args) { + if (argCount == 0) { + runtimeError(vm, "printErr() takes 1 or more arguments (%d given)", argCount); + return EMPTY_VAL; + } + + for (int i = 0; i < argCount; ++i) { + printValueError(args[i]); + } + + return NIL_VAL; +} + +static Value printErrlnIO(DictuVM *vm, int argCount, Value *args) { + if (argCount == 0) { + runtimeError(vm, "printErrLn() takes 1 or more arguments (%d given)", argCount); + return EMPTY_VAL; + } + + for (int i = 0; i < argCount; ++i) { + printValueError(args[i]); + fprintf(stderr, "\n"); + } + + return NIL_VAL; +} + #ifdef _WIN32 static Value copyFileIO(DictuVM *vm, int argCount, Value *args) { if (argCount != 2) { @@ -138,6 +166,8 @@ Value createIOModule(DictuVM *vm) { */ defineNative(vm, &module->values, "print", printIO); defineNative(vm, &module->values, "println", printlnIO); + defineNative(vm, &module->values, "eprint", printErrIO); + defineNative(vm, &module->values, "eprintln", printErrlnIO); defineNative(vm, &module->values, "copyFile", copyFileIO); pop(vm); From 61cba81638f6f99f8629f4190e7ba25980451c28 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Mon, 11 Nov 2024 02:20:09 +0100 Subject: [PATCH 08/17] rename other cs => js --- docs/docs/standard-lib/json.md | 2 +- docs/docs/standard-lib/log.md | 2 +- docs/docs/standard-lib/math.md | 2 +- docs/docs/standard-lib/net.md | 2 +- docs/docs/standard-lib/object.md | 2 +- docs/docs/standard-lib/path.md | 2 +- docs/docs/standard-lib/process.md | 2 +- docs/docs/standard-lib/queue.md | 2 +- docs/docs/standard-lib/socket.md | 2 +- docs/docs/standard-lib/stack.md | 2 +- docs/docs/standard-lib/term.md | 2 +- docs/docs/standard-lib/uuid.md | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/docs/standard-lib/json.md b/docs/docs/standard-lib/json.md index 4a76e868..718cbf13 100644 --- a/docs/docs/standard-lib/json.md +++ b/docs/docs/standard-lib/json.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the JSON module an import is required. -```cs +```js import JSON; ``` diff --git a/docs/docs/standard-lib/log.md b/docs/docs/standard-lib/log.md index 9c23fe4a..39a71ce7 100644 --- a/docs/docs/standard-lib/log.md +++ b/docs/docs/standard-lib/log.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Log module an import is required. -```cs +```js import Log; ``` diff --git a/docs/docs/standard-lib/math.md b/docs/docs/standard-lib/math.md index 81baa7ee..c47289c3 100644 --- a/docs/docs/standard-lib/math.md +++ b/docs/docs/standard-lib/math.md @@ -21,7 +21,7 @@ parent: Standard Library To make use of the Math module an import is required. For the purpose of the documentation, an iterable is either a list, or passing multiple arguments to the function directly. -```cs +```js import Math; ``` diff --git a/docs/docs/standard-lib/net.md b/docs/docs/standard-lib/net.md index ec6f1a1f..9f88b2ad 100644 --- a/docs/docs/standard-lib/net.md +++ b/docs/docs/standard-lib/net.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Net module an import is required. -```cs +```js import Net; ``` diff --git a/docs/docs/standard-lib/object.md b/docs/docs/standard-lib/object.md index 2c3522ff..a2af2ef3 100644 --- a/docs/docs/standard-lib/object.md +++ b/docs/docs/standard-lib/object.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Object module an import is required. -```cs +```js import Object; ``` diff --git a/docs/docs/standard-lib/path.md b/docs/docs/standard-lib/path.md index d363fdfc..175a2347 100644 --- a/docs/docs/standard-lib/path.md +++ b/docs/docs/standard-lib/path.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Path module an import is required. -```cs +```js import Path; ``` diff --git a/docs/docs/standard-lib/process.md b/docs/docs/standard-lib/process.md index 69e99ef2..825317dc 100644 --- a/docs/docs/standard-lib/process.md +++ b/docs/docs/standard-lib/process.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Process module an import is required. -```cs +```js import Process; ``` diff --git a/docs/docs/standard-lib/queue.md b/docs/docs/standard-lib/queue.md index b724391d..cccc3ce7 100644 --- a/docs/docs/standard-lib/queue.md +++ b/docs/docs/standard-lib/queue.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Queue module an import is required. -```cs +```js import Queue; ``` diff --git a/docs/docs/standard-lib/socket.md b/docs/docs/standard-lib/socket.md index 888dda57..ba543c74 100644 --- a/docs/docs/standard-lib/socket.md +++ b/docs/docs/standard-lib/socket.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Socket module an import is required. -```cs +```js import Socket; ``` diff --git a/docs/docs/standard-lib/stack.md b/docs/docs/standard-lib/stack.md index 022a906f..c60460d8 100644 --- a/docs/docs/standard-lib/stack.md +++ b/docs/docs/standard-lib/stack.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Stack module an import is required. -```cs +```js import Stack; ``` diff --git a/docs/docs/standard-lib/term.md b/docs/docs/standard-lib/term.md index 0b2cb43c..99be8a80 100644 --- a/docs/docs/standard-lib/term.md +++ b/docs/docs/standard-lib/term.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the Term module an import is required. -```cs +```js import Term; ``` diff --git a/docs/docs/standard-lib/uuid.md b/docs/docs/standard-lib/uuid.md index 3cc5d120..180de3dd 100644 --- a/docs/docs/standard-lib/uuid.md +++ b/docs/docs/standard-lib/uuid.md @@ -20,7 +20,7 @@ parent: Standard Library To make use of the UUID module an import is required. -```cs +```js import UUID; ``` From 25bc31df960927982bd9da4a6a4b9607f24cc9e6 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Tue, 12 Nov 2024 03:14:50 +0100 Subject: [PATCH 09/17] style changes to version display --- src/cli/CMakeLists.txt | 3 +++ src/include/dictu_include.h | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 67f5fd4d..5acf7de0 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -14,6 +14,9 @@ add_executable(dictu ${DICTU_CLI_SRC}) OUTPUT_STRIP_TRAILING_WHITESPACE ) add_compile_definitions(GIT_HASH="${GIT_HASH}") +if(CMAKE_BUILD_TYPE MATCHES Debug) + add_compile_definitions(DEBUG DEBUG_STRESS_GC DEBUG_FINAL_MEM) +endif() target_include_directories(dictu PUBLIC ${INCLUDE_DIR}) target_link_libraries(dictu dictu_api_static) diff --git a/src/include/dictu_include.h b/src/include/dictu_include.h index 73fea7f2..4388a710 100644 --- a/src/include/dictu_include.h +++ b/src/include/dictu_include.h @@ -7,13 +7,23 @@ #define DICTU_MINOR_VERSION "30" #define DICTU_PATCH_VERSION "0" +#ifdef DEBUG + +#define DICTU_DEBUG_VERSION_STR " (Debug)" + +#else + +#define DICTU_DEBUG_VERSION_STR "" + +#endif + #if defined(GIT_HASH) -#define DICTU_STRING_VERSION "Dictu " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "(rev: " GIT_HASH ")\n" +#define DICTU_STRING_VERSION DICTU_DEBUG_VERSION_STR "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION " [rev: " GIT_HASH "]\n" #else -#define DICTU_STRING_VERSION "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n" +#define DICTU_STRING_VERSION DICTU_DEBUG_VERSION_STR "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n" #endif From aa86597c47aa402bdd3bd624acec53981d40152f Mon Sep 17 00:00:00 2001 From: Liz3 Date: Wed, 13 Nov 2024 05:05:38 +0100 Subject: [PATCH 10/17] add a option to not relocate the binary --- CMakeLists.txt | 1 + src/cli/CMakeLists.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8903f64f..5af7c362 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ if (ENABLE_VCPKG) endif(ENABLE_VCPKG) option(BUILD_CLI "Build the CLI" ON) +option(NO_EXEC_RELOCATE "Do not relocate the executable" OFF) add_subdirectory(src) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 5acf7de0..ec38c372 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,6 +1,7 @@ set(DICTU_CLI_SRC main.c linenoise/linenoise.c linenoise/linenoise.h linenoise/stringbuf.c linenoise/stringbuf.h linenoise/utf8.c linenoise/utf8.h) +if(NOT NO_EXEC_RELOCATE) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) - +endif() if(NOT WIN32) list(FILTER DICTU_CLI_SRC EXCLUDE REGEX "linenoise-win32.c") endif() From 663c989f4045be0f806d2aad6c10c92a49326590 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 21:47:17 +0100 Subject: [PATCH 11/17] rename var --- CMakeLists.txt | 2 +- src/cli/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5af7c362..6fb2234b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (ENABLE_VCPKG) endif(ENABLE_VCPKG) option(BUILD_CLI "Build the CLI" ON) -option(NO_EXEC_RELOCATE "Do not relocate the executable" OFF) +option(EXEC_RELOCATE "Relocate the executable to the root dir" ON) add_subdirectory(src) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index ec38c372..9aa9b513 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,5 +1,5 @@ set(DICTU_CLI_SRC main.c linenoise/linenoise.c linenoise/linenoise.h linenoise/stringbuf.c linenoise/stringbuf.h linenoise/utf8.c linenoise/utf8.h) -if(NOT NO_EXEC_RELOCATE) +if(EXEC_RELOCATE) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) endif() if(NOT WIN32) From 4c0854322d686d9f344d3fc7e62063e8650ac8cf Mon Sep 17 00:00:00 2001 From: Liz3 Date: Fri, 15 Nov 2024 22:52:54 +0100 Subject: [PATCH 12/17] fix: typo --- src/include/dictu_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/dictu_include.h b/src/include/dictu_include.h index 4388a710..9587f3f4 100644 --- a/src/include/dictu_include.h +++ b/src/include/dictu_include.h @@ -9,7 +9,7 @@ #ifdef DEBUG -#define DICTU_DEBUG_VERSION_STR " (Debug)" +#define DICTU_DEBUG_VERSION_STR "(Debug)" #else From da0c85efa3ddd60dec328d1cf8535b80ff1e9345 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sat, 16 Nov 2024 05:45:45 +0100 Subject: [PATCH 13/17] fix: move ffi outside of own folder --- src/optionals/{ffi => }/ffi.c | 0 src/optionals/{ffi => }/ffi.h | 4 ++-- src/optionals/optionals.c | 1 - src/optionals/optionals.h | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) rename src/optionals/{ffi => }/ffi.c (100%) rename src/optionals/{ffi => }/ffi.h (91%) diff --git a/src/optionals/ffi/ffi.c b/src/optionals/ffi.c similarity index 100% rename from src/optionals/ffi/ffi.c rename to src/optionals/ffi.c diff --git a/src/optionals/ffi/ffi.h b/src/optionals/ffi.h similarity index 91% rename from src/optionals/ffi/ffi.h rename to src/optionals/ffi.h index 7b1de964..5b6d4f2a 100644 --- a/src/optionals/ffi/ffi.h +++ b/src/optionals/ffi.h @@ -3,8 +3,8 @@ #include -#include "../optionals.h" -#include "../../vm/vm.h" +#include "optionals.h" +#include "../vm/vm.h" #ifdef _WIN32 #define LIB_EXTENSION ".dll" diff --git a/src/optionals/optionals.c b/src/optionals/optionals.c index f2fbe811..7d39fab3 100644 --- a/src/optionals/optionals.c +++ b/src/optionals/optionals.c @@ -1,5 +1,4 @@ #include "optionals.h" -#include "ffi/ffi.h" BuiltinModules modules[] = { {"Argparse", &createArgParseModule, false}, diff --git a/src/optionals/optionals.h b/src/optionals/optionals.h index 70bcae93..af96f87c 100644 --- a/src/optionals/optionals.h +++ b/src/optionals/optionals.h @@ -29,7 +29,7 @@ #include "object/object.h" #include "buffer.h" #include "unittest/unittest.h" -#include "ffi/ffi.h" +#include "ffi.h" typedef Value (*BuiltinModule)(DictuVM *vm); From 0337e0cfb1f882fe8c9fe2445413f9421a66dfde Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sat, 16 Nov 2024 06:07:33 +0100 Subject: [PATCH 14/17] fix: refactor System.mkdirAll --- src/optionals/system.c | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/optionals/system.c b/src/optionals/system.c index 9a17a8b3..fa5e664c 100644 --- a/src/optionals/system.c +++ b/src/optionals/system.c @@ -1,4 +1,5 @@ #include "system.h" +#include "../vm/utf8.h" #ifdef _WIN32 #define rmdir(DIRNAME) _rmdir(DIRNAME) @@ -268,7 +269,7 @@ static Value mkdirAllNative(DictuVM *vm, int argCount, Value *args) { return EMPTY_VAL; } - char *dir = AS_CSTRING(args[0]); + ObjString *dir = AS_STRING(args[0]); int mode = 0777; @@ -280,34 +281,30 @@ static Value mkdirAllNative(DictuVM *vm, int argCount, Value *args) { mode = AS_NUMBER(args[1]); } - - char tmp[256]; - char *p = NULL; - size_t len; - - snprintf(tmp, sizeof(tmp), "%s", dir); - - len = strlen(tmp); - if (tmp[len - 1] == '/' || tmp[len - 1] == '\\') { - tmp[len - 1] = 0; - } - int retval; - - for (p = tmp + 1; *p; p++) { - if (*p == '/' || *p == '\\') { - *p = 0; - - retval = MKDIR(tmp, mode); - if (retval < 0) { - ERROR_RESULT; + bool lastSeperator = false; + int byteOffset = 0; + char* ptr = dir->chars; + for(int i = 0; i < dir->character_len; i++) { + utf8_int32_t cp; + char *n = utf8codepoint(ptr, &cp); + if(cp == '/' || cp == '\\') { + if(byteOffset > 0){ + dir->chars[byteOffset] = '\0'; + retval = MKDIR(dir->chars, mode); + dir->chars[byteOffset] = cp; } - - *p = '/'; + lastSeperator = true; + } else { + lastSeperator = false; } + ptr = n; + byteOffset += utf8codepointsize(cp); } - - retval = MKDIR(tmp, mode); + if(!lastSeperator){ + retval = MKDIR(dir->chars, mode); + } + if (retval < 0) { ERROR_RESULT; } From 10d333eb7cdb985c96da2c4721a77a5b0c898489 Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sat, 16 Nov 2024 21:41:28 +0100 Subject: [PATCH 15/17] indentation --- src/optionals/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/optionals/io.c b/src/optionals/io.c index 65d9145b..630d2511 100644 --- a/src/optionals/io.c +++ b/src/optionals/io.c @@ -60,7 +60,7 @@ static Value printErrlnIO(DictuVM *vm, int argCount, Value *args) { for (int i = 0; i < argCount; ++i) { printValueError(args[i]); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); } return NIL_VAL; From 295d6f09807e5b2fa6c70d767d63539a565d6a3e Mon Sep 17 00:00:00 2001 From: Liz3 Date: Sun, 17 Nov 2024 01:20:48 +0100 Subject: [PATCH 16/17] remove this --- ops/checkTests.du | 3 --- 1 file changed, 3 deletions(-) diff --git a/ops/checkTests.du b/ops/checkTests.du index d9288ec3..d7f102a3 100644 --- a/ops/checkTests.du +++ b/ops/checkTests.du @@ -23,9 +23,6 @@ const ignored = { 'range.du', 'select.du', ], - 'ffi': [ - 'libs', - ], '*': [ 'import.du', ] From e68c6ed0b5b6b74cf02889c0cf4c2cdb130fd414 Mon Sep 17 00:00:00 2001 From: Liz Date: Sun, 17 Nov 2024 03:12:12 +0100 Subject: [PATCH 17/17] Update tests/path/isDir.du --- tests/path/isDir.du | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/path/isDir.du b/tests/path/isDir.du index bd08b37c..676317bf 100644 --- a/tests/path/isDir.du +++ b/tests/path/isDir.du @@ -3,7 +3,8 @@ * * Testing Path.isDir() * - * Returns true if the given string is a path to a directory, else false.` + * Returns true if the given string is a path to a directory, else false. + */ from UnitTest import UnitTest;