Skip to content

Commit

Permalink
Merge pull request #758 from liz3/liz3/doc-fixes
Browse files Browse the repository at this point in the history
multiple fixes of small things and QOL
  • Loading branch information
Jason2605 authored Nov 17, 2024
2 parents ac22490 + e68c6ed commit a2554ab
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 59 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (ENABLE_VCPKG)
endif(ENABLE_VCPKG)

option(BUILD_CLI "Build the CLI" ON)
option(EXEC_RELOCATE "Relocate the executable to the root dir" ON)

add_subdirectory(src)

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/standard-lib/argparse.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Argparse module an import is required.

```cs
```js
from Argparse import Parser;
```

Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/bigint.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the BigInt module an import is required.

```cs
```js
import BigInt;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Datetime module an import is required.

```cs
```js
import Datetime;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

Expand Down
21 changes: 20 additions & 1 deletion docs/docs/standard-lib/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the IO module an import is required.

```cs
```js
import IO;
```

Expand Down Expand Up @@ -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\<Nil>

Copies the contents from the source file to the destination file.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the JSON module an import is required.

```cs
```js
import JSON;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Log module an import is required.

```cs
```js
import Log;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Net module an import is required.

```cs
```js
import Net;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Object module an import is required.

```cs
```js
import Object;
```

Expand Down
4 changes: 1 addition & 3 deletions docs/docs/standard-lib/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Path module an import is required.

```cs
```js
import Path;
```

Expand Down Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Process module an import is required.

```cs
```js
import Process;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Queue module an import is required.

```cs
```js
import Queue;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Socket module an import is required.

```cs
```js
import Socket;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Stack module an import is required.

```cs
```js
import Stack;
```

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/standard-lib/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/term.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the Term module an import is required.

```cs
```js
import Term;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/uuid.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parent: Standard Library

To make use of the UUID module an import is required.

```cs
```js
import UUID;
```

Expand Down
3 changes: 0 additions & 3 deletions ops/checkTests.du
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const ignored = {
'range.du',
'select.du',
],
'ffi': [
'libs',
],
'*': [
'import.du',
]
Expand Down
14 changes: 13 additions & 1 deletion src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
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(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()

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}")
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)
if(LINUX AND CMAKE_C_COMPILER_ID STREQUAL "Clang")
Expand Down
20 changes: 19 additions & 1 deletion src/include/dictu_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
#define DICTU_MINOR_VERSION "30"
#define DICTU_PATCH_VERSION "0"

#define DICTU_STRING_VERSION "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n"
#ifdef DEBUG

#define DICTU_DEBUG_VERSION_STR "(Debug)"

#else

#define DICTU_DEBUG_VERSION_STR ""

#endif

#if defined(GIT_HASH)

#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_DEBUG_VERSION_STR "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n"

#endif

typedef struct _vm DictuVM;

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/optionals/ffi/ffi.h → src/optionals/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stdlib.h>

#include "../optionals.h"
#include "../../vm/vm.h"
#include "optionals.h"
#include "../vm/vm.h"

#ifdef _WIN32
#define LIB_EXTENSION ".dll"
Expand Down
30 changes: 30 additions & 0 deletions src/optionals/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/optionals/optionals.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "optionals.h"
#include "ffi/ffi.h"

BuiltinModules modules[] = {
{"Argparse", &createArgParseModule, false},
Expand Down
2 changes: 1 addition & 1 deletion src/optionals/optionals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit a2554ab

Please sign in to comment.