From 1465efb3a9af560d6408d2d6211b09bb55c0688e Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sat, 21 Sep 2024 13:14:32 +0300 Subject: [PATCH] update API --- .vitepress/config.mts | 40 ++--- src/api/environment/command-line-arguments.md | 47 ------ src/api/environment/environment-variables.md | 46 ------ src/api/environment/index.md | 3 - src/api/process/executable-path.md | 10 -- src/api/process/index.md | 3 - src/api/reference-counting/index.md | 11 +- src/api/runtime-api.md | 137 ++++++++++++++++++ src/api/types/maps.md | 38 ----- src/api/unicode/index.md | 3 - src/api/unicode/utf-16.md | 94 ------------ src/api/unicode/utf-8.md | 71 --------- src/api/using-as-library/index.md | 31 ---- src/compiler/directives.md | 1 + src/runtime/index.md | 7 + src/runtime/public-functionalities.md | 10 ++ src/runtime/runtime-api.md | 137 ++++++++++++++++++ src/some-questions.md | 9 +- 18 files changed, 312 insertions(+), 386 deletions(-) delete mode 100644 src/api/environment/command-line-arguments.md delete mode 100644 src/api/environment/environment-variables.md delete mode 100644 src/api/environment/index.md delete mode 100644 src/api/process/executable-path.md delete mode 100644 src/api/process/index.md create mode 100644 src/api/runtime-api.md delete mode 100644 src/api/types/maps.md delete mode 100644 src/api/unicode/index.md delete mode 100644 src/api/unicode/utf-16.md delete mode 100644 src/api/unicode/utf-8.md delete mode 100644 src/api/using-as-library/index.md create mode 100644 src/runtime/index.md create mode 100644 src/runtime/public-functionalities.md create mode 100644 src/runtime/runtime-api.md diff --git a/.vitepress/config.mts b/.vitepress/config.mts index 55552d3..28a2ece 100644 --- a/.vitepress/config.mts +++ b/.vitepress/config.mts @@ -350,6 +350,14 @@ export default defineConfig({ }, ], }, + { + text: 'Runtime', + link: '/runtime/', + items: [ + { text: 'Public Functionalities', link: '/runtime/public-functionalities' }, + { text: 'Runtime API', link: '/runtime/runtime-api' }, + ], + }, { text: 'Integrated Jule', link: '/integrated-jule/', @@ -392,6 +400,7 @@ export default defineConfig({ text: 'API', link: '/api/', items: [ + { text: 'Runtime API', link: '/api/runtime-api' }, { text: 'Implementation', link: '/api/implementation/', @@ -401,21 +410,6 @@ export default defineConfig({ { text: 'Production', link: '/api/implementation/production' }, ], }, - { - text: 'Environment', - link: '/api/environment/', - items: [ - { text: 'Command-Line Arguments', link: '/api/environment/command-line-arguments' }, - { text: 'Environment Variables', link: '/api/environment/environment-variables' }, - ], - }, - { - text: 'Process', - link: '/api/process/', - items: [ - { text: 'Executable Path', link: '/api/process/executable-path' }, - ], - }, { text: 'Platform Specific', link: '/api/platform-specific' }, { text: 'Types', @@ -424,21 +418,11 @@ export default defineConfig({ { text: 'Primitive', link: '/api/types/primitive' }, { text: 'Limits', link: '/api/types/limits' }, { text: 'Strings', link: '/api/types/strings' }, - { text: 'Maps', link: '/api/types/maps' }, { text: 'Slices', link: '/api/types/slices' }, { text: 'Any', link: '/api/types/any' }, ], }, - { text: 'Atomicity', link: '/api/atomicity' }, { text: 'Deferred Scopes', link: '/api/deferred-scopes' }, - { - text: 'Unicode', - link: '/api/unicode/', - items: [ - { text: 'UTF-8', link: '/api/unicode/utf-8' }, - { text: 'UTF-16', link: '/api/unicode/utf-16' }, - ], - }, { text: 'Reference Counting', link: '/api/reference-counting/', @@ -453,11 +437,6 @@ export default defineConfig({ { text: 'Wrappers', link: '/api/integrated-jule/wrappers' }, ], }, - { - text: 'Using as Library', - link: '/api/using-as-library/', - items: [], - }, ], } ], @@ -542,6 +521,7 @@ export default defineConfig({ }, { text: 'std::net', link: '/std/net' }, { text: 'std::process', link: '/std/process' }, + { text: 'std::runtime', link: '/runtime/' }, { text: 'std::slices', link: '/std/slices' }, { text: 'std::strings', link: '/std/strings' }, { diff --git a/src/api/environment/command-line-arguments.md b/src/api/environment/command-line-arguments.md deleted file mode 100644 index 57b335f..0000000 --- a/src/api/environment/command-line-arguments.md +++ /dev/null @@ -1,47 +0,0 @@ -# Command-Line Arguments - -The API has a variable for command-line arguments. But this variables are does not hold anything by default. The `argc` variable is count of command line arguments, and the `argv` variable is command line arguments. - -Relevant variable (in `env.hpp`): -```cpp -int argc; -char **argv; -``` - -## Setup Command-Line Arguments - -There is a function to set the command-line arguments variables. This function sets the value of the `jule::argc`, and `jule::argv` variables. It takes `argc` and `argv` as arguments. - -Relevant function (in `env.hpp`): -```cpp -void setup_argv(int argc, char **argv); -``` - -For example: -```cpp -#include "api/jule.hpp" - -int main(int argc, char **argv, char **envp) { - jule::setup_argv(argc, argv); - return 0; -} -``` - -## Get Command-Line Arguments - -There is a function for get command-line arguments as Jule slice. It uses `jule::argc` and `jule::argv` variables internally, therefore you should call `jule::setup_argv` function before. But the `jule::arc` and `jule::argv` variables are not used on Windows systems. The Windows implementation uses the `GetCommandLineW` and `CommandLineToArgvW` functions. - -For example: -```cpp -#include "api/jule.hpp" - -int main(int argc, char **argv, char **envp) { - jule::setup_argv(argc, argv); - jule::outln(jule::args()); - return 0; -} -``` - -::: info -JuleC generates IR wich is calls the setup function in entry point by default. -::: diff --git a/src/api/environment/environment-variables.md b/src/api/environment/environment-variables.md deleted file mode 100644 index 039ba9a..0000000 --- a/src/api/environment/environment-variables.md +++ /dev/null @@ -1,46 +0,0 @@ -# Environment Variables - -The API has a variable for environment variables. But this variable does not hold anything by default. - -Relevant variable (in `env.hpp`): -```cpp -char **envp; -``` - -## Setup Environment Variables - -There is a function to set the environment variables variable. This function sets the value of the `jule::envp` variable. It takes `envp` as arguments ant sets the variable. - -Relevant function (in `env.hpp`): -```cpp -void setup_envp(char **envp); -``` - -For example: -```cpp -#include "api/jule.hpp" - -int main(int argc, char **argv, char **envp) { - jule::setup_evp(envp); - return 0; -} -``` - -::: info -JuleC generates IR wich is calls the setup function in entry point by default. -::: - -## Get Envorionment Variables - -There is function for get environment variables as Jule slice. It uses `jule::envp` variable internally, therefore you should call `jule::setup_envp` function before. But the `jule::envp` variable are not used on Windows systems. The Windows implementation uses the `GetEnvironmentStringsW` function. - -For example: -```cpp -#include "api/jule.hpp" - -int main(int argc, char *argv[], char *envp[]) { - jule::setup_evp(envp); - jule::outln(jule::env()); - return 0; -} -``` diff --git a/src/api/environment/index.md b/src/api/environment/index.md deleted file mode 100644 index 0d86218..0000000 --- a/src/api/environment/index.md +++ /dev/null @@ -1,3 +0,0 @@ -# Environment - -Things related to the evironment of your program. \ No newline at end of file diff --git a/src/api/process/executable-path.md b/src/api/process/executable-path.md deleted file mode 100644 index 53bc1a5..0000000 --- a/src/api/process/executable-path.md +++ /dev/null @@ -1,10 +0,0 @@ -# Executable Path - -The API provides a function for you to get the executable path of the program. This function returns the path of the executable at runtime of your program. - -Returns empty string if any error occurrs. - -Relevant function (in `env.hpp`): -```cpp -jule::Str executable(void); -``` diff --git a/src/api/process/index.md b/src/api/process/index.md deleted file mode 100644 index 75f293b..0000000 --- a/src/api/process/index.md +++ /dev/null @@ -1,3 +0,0 @@ -# Process - -Things related to the process of your program. diff --git a/src/api/reference-counting/index.md b/src/api/reference-counting/index.md index 1a5d2c5..642cfb0 100644 --- a/src/api/reference-counting/index.md +++ b/src/api/reference-counting/index.md @@ -2,13 +2,6 @@ Jule's reference counting functionality for allocations is provided in the API. The `ref.hpp` header contains the `Ptr` struct for reference counting. -## Variables - -```cpp -constexpr signed int REFERENCE_DELTA; -``` -The reference counting data delta value that must occur per each reference counting operation. - ## Functions ```cpp @@ -49,11 +42,11 @@ Creates new reference from allocation and reference counting allocation. Referen static jule::Ptr make(T *ptr); ``` -Creates new reference from allocation. Allocates new allocation for reference counting data and starts counting to `jule::REFERENCE_DELTA`. +Creates new reference from allocation. Allocates new allocation for reference counting data and starts counting to reference counting delta of runtime. ### Methods ```cpp -void drop(void); +void dealloc(void); ``` Drops reference. This function will destruct this instace for reference counting. Frees memory if reference counting reaches to zero. diff --git a/src/api/runtime-api.md b/src/api/runtime-api.md new file mode 100644 index 0000000..e956716 --- /dev/null +++ b/src/api/runtime-api.md @@ -0,0 +1,137 @@ +# Runtime API + +If you want to get information about Jule runtime, read the [Runtime](/runtime/) section. This section only shows which API functions are declared to the backend and how. For documentation you need to look at the documentation of the functions. + +## Globals + +```cpp +jule::Int __jule_argc +``` +Declaration of: `argc` + +```cpp +jule::U8 **__jule_argv +``` +Declaration of: `argv` + +```cpp +jule::U8 **__jule_envp +``` +Declaration of: `envp` + +## Functions + +```cpp +jule::Bool __jule_ptrEqual(void *a, void *b); +``` +Declaration of: `ptrEqual` + +```cpp +jule::Str __jule_ptrToStr(void *p); +``` +Declaration of: `ptrToStr` + +```cpp +jule::Str __jule_boolToStr(jule::Bool b); +``` +Declaration of: `boolToStr` + +```cpp +jule::Str __jule_i64ToStr(jule::I64 x); +``` +Declaration of: `i64ToStr` + +```cpp +jule::Str __jule_u64ToStr(jule::U64 x); +``` +Declaration of: `u64ToStr` + +```cpp +jule::Str __jule_f64ToStr(jule::F64 x); +``` +Declaration of: `f64ToStr` + +```cpp +jule::Uint *__jule_RCNew(void); +``` +Declaration of: `_RCNew` + +```cpp +jule::Uint __jule_RCLoad(jule::Uint *p); +``` +Declaration of: `_RCLoad` + +```cpp +void __jule_RCAdd(jule::Uint *p); +``` +Declaration of: `_RCAdd` + +```cpp +jule::Bool __jule_RCDrop(jule::Uint *p); +``` +Declaration of: `_RCDrop` + +```cpp +void __jule_RCFree(jule::Uint *p); +``` +Declaration of: `_RCFree` + +```cpp +jule::Int __jule_compareStr(jule::Str *a, jule::Str *b); +``` +Declaration of: `compareStr` + +```cpp +jule::Int __jule_writeStdout(jule::Slice buf); +``` +Declaration of: `writeStdout` + +```cpp +jule::Int __jule_writeStderr(jule::Slice buf); +``` +Declaration of: `writeStderr` + +```cpp +jule::Int __jule_readStdin(jule::Slice buf); +``` +Declaration of: `readStdin` + +```cpp +void __jule_panic(jule::U8 *m, jule::Int n); +``` +Declaration of: `panic1` + +```cpp +jule::Str __jule_bytesToStr(jule::Slice bytes); +``` +Declaration of: `bytesToStr` + +```cpp +jule::Str __jule_runesToStr(jule::Slice runes); +``` +Declaration of: `runesToStr` + +```cpp +jule::Slice __jule_strToRunes(jule::Str s); +``` +Declaration of: `strToRunes` + +```cpp +jule::Slice __jule_strToBytes(jule::Str s); +``` +Declaration of: `strToBytes` + +```cpp +jule::Str __jule_strFromByte(jule::U8 b); +``` +Declaration of: `strFromByte` + +```cpp +jule::Str __jule_strFromRune(jule::I32 r); +``` +Declaration of: `strFromRune` + +```cpp +void __jule_runeStep(jule::U8 *s, jule::Int len, jule::I32 *r, jule::Int *outLen); +``` +Declaration of: `runeStep` \ No newline at end of file diff --git a/src/api/types/maps.md b/src/api/types/maps.md deleted file mode 100644 index 514b640..0000000 --- a/src/api/types/maps.md +++ /dev/null @@ -1,38 +0,0 @@ -# Maps - -The Jule maps are using `std::unordered_map` with custom hash algorithm which is FNV1 currently. The internal `std::unordered_map` buffer available via the `buffer` field of the `jule::Map`. - -The using of `jule::Map` is too similar to using of `std::unordered_map`. - -For example: - -```cpp -jule::Map map = { - {0, "Hello"}, - {1, "World"}, - {2, "Foo"}, - {3, "Bar"}, -}; -map.del(2); -map.clear(); -``` - -## Lookup - -Jule has [lookup assignments](/common-concepts/maps#lookup-assignments) for lookup maps. In `jule::Map` type, the `lookup` method is equivalent for this. - -For example: -```cpp -jule::Map map = { - {0, "Hello"}, - {1, "World"}, - {2, "Foo"}, - {3, "Bar"}, -}; -jule::Str value; -jule::Bool ok; -map.lookup(3, &value, &ok); -if (ok) { - jule::outln(value); -} -``` diff --git a/src/api/unicode/index.md b/src/api/unicode/index.md deleted file mode 100644 index a6e8206..0000000 --- a/src/api/unicode/index.md +++ /dev/null @@ -1,3 +0,0 @@ -# Unicode - -Jule makes it possible to handle unicode in several ways. Some of this is also provided by the API. This section addresses the unicode functionality of the API. diff --git a/src/api/unicode/utf-16.md b/src/api/unicode/utf-16.md deleted file mode 100644 index 1677339..0000000 --- a/src/api/unicode/utf-16.md +++ /dev/null @@ -1,94 +0,0 @@ -# UTF-16 - -The `utf16.hpp` header of the API provides functionality for UTF-16 encoding. - -## Variables - -```cpp -constexpr signed int UTF16_REPLACEMENT_CHAR; -``` -Unicode replacement character. - ---- - -```cpp -constexpr signed int UTF16_SURR1; -``` -```cpp -constexpr signed int UTF16_SURR2 -``` -```cpp -constexpr signed int UTF16_SURR3 -``` -`0xd800`-`0xdc00` encodes the high 10 bits of a pair. \ -`0xdc00`-`0xe000` encodes the low 10 bits of a pair. \ -the value is those 20 bits plus `0x10000`. - ---- - -```cpp -constexpr signed int UTF16_SURR_SELF -``` - ---- - -```cpp -constexpr signed int UTF16_MAX_RUNE; -``` -Maximum valid Unicode code point. - - -## Functions - -```cpp -jule::I32 -utf16_decode_rune(const jule::I32 r1, const jule::I32 r2); -``` -Returns the UTF-16 decoding of a surrogate pair. If the pair is not a valid UTF-16 surrogate pair, decode_rune returns the Unicode replacement code point U+FFFD. - ---- - -```cpp -std::vector -utf16_decode(const std::vector s); -``` -Returns the Unicode code point sequence represented by the UTF-16 encoding s. - ---- - -```cpp -std::string -utf16_to_utf8_str(const wchar_t *wstr, const std::size_t len); -``` -Convert UTF-16 string pointer to UTF-8 encoded string. - ---- - -```cpp -std::tuple -utf16_encode_rune(jule::I32 r); -``` -Returns the UTF-16 surrogate pair r1, r2 for the given rune. If the rune is not a valid Unicode code point or does not need encoding, encode_rune returns U+FFFD, U+FFFD. - ---- - -```cpp -std::vector -utf16_encode(const std::vector &runes); -``` -Returns the UTF-16 encoding of the Unicode code point sequence s. - ---- - -```cpp -void utf16_append_rune(std::vector &a, const jule::I32 &r); -``` -Appends the UTF-16 encoding of the Unicode code point r to the end of a. If the rune is not a valid Unicode code point, it appends the encoding of U+FFFD. - ---- - -```cpp -std::vector -utf16_from_str(const std::string &s); -``` -Convert UTF-8 encoded string to UTF-16 codepage. diff --git a/src/api/unicode/utf-8.md b/src/api/unicode/utf-8.md deleted file mode 100644 index 3ba14d5..0000000 --- a/src/api/unicode/utf-8.md +++ /dev/null @@ -1,71 +0,0 @@ -# UTF-8 - -The `utf8.hpp` header of the API provides functionality for UTF-8 encoding. - -## Variables - -```cpp -constexpr signed int UTF8_RUNE_ERROR; -``` -The "error" rune or "Unicode replacement character". - ---- - - -```cpp -constexpr signed int UTF8_LOCB; -``` -The default lowest continuation byte. - ---- - - -```cpp -constexpr signed int UTF8_HICB; -``` -The default highest continuation byte. - ---- - - -```cpp -constexpr signed int UTF8_MAX_RUNE; -``` -Maximum valid Unicode code point. - ---- - - -```cpp -constexpr signed int UTF8_SURROGATE_MAX; -``` -```cpp -constexpr signed int UTF8_SURROGATE_MIN; -``` -Code points in the surrogate range are not valid for UTF-8. - - -## Functions - -```cpp -std::string runes_to_utf8(const std::vector &s) noexcept; -``` -Returns string from UTF-8 bytes. - ---- - -```cpp -std::tuple -utf8_decode_rune_str(const char *s, const jule::Int &len); -``` -Unpacks the first UTF-8 encoding in s and returns the rune and its width in string. If s is empty it returns (RUNE_ERROR, 0). Otherwise, if the encoding is invalid, it returns (RUNE_ERROR, 1). Both are impossible results for correct, non-empty UTF-8. - -An encoding is invalid if it is incorrect UTF-8, encodes a rune that is out of range, or is not the shortest possible UTF-8 encoding for the value. No other validation is performed. - ---- - -```cpp -template -void utf8_push_rune_bytes(const jule::I32 &r, Dest &dest); -``` -Pushes UTF-8 encoding bytes of the rune to the destination. If the rune is out of range, it writes the encoding of RUNE_ERROR. It returns bytes of rune. The destination should have the `push_back` method. diff --git a/src/api/using-as-library/index.md b/src/api/using-as-library/index.md deleted file mode 100644 index 56b427b..0000000 --- a/src/api/using-as-library/index.md +++ /dev/null @@ -1,31 +0,0 @@ -# Using as Library - -You may want to use the API as a separate library. This is possible. The API is developed with pure C++, it has no dependencies. - -## Installation - -To install the API, you need to get the API source codes from the source code. For this, it is sufficient to obtain the [`api`](https://github.com/julelang/jule/tree/master/api) directory in the root directory. - -Then put this directory where you want to host it. You can change the name of the `api` directory to `jule` or something different if you wish. - -All you have to do is have the header files, that's all. You are then ready to use it. - -## Using and Compilation - -You don't need to make any changes to your build processes for the API. All header files contain all implementation. - -Just include and use them: -```cpp -#include -#include "api/jule.hpp" - -int main(int argc, char *argv[]) { - jule::setup_argv(argc, argv); - - jule::outln("Command line arguments: "); - for (jule::Str arg: jule::args()) - jule::outln(arg); - - return 0; -} -``` diff --git a/src/compiler/directives.md b/src/compiler/directives.md index 4c6449c..89768d4 100644 --- a/src/compiler/directives.md +++ b/src/compiler/directives.md @@ -52,6 +52,7 @@ Here is the list of variables and their existence: - `x64`: 64-bit cpu architecture - `production`: production compilation enabled - `test`: compiling for testing +- `atomicrc`: atomic reference counting - `clang`: backend compiler is Clang - `gcc`: backend compiler is GCC - `cpp14`: using C++14 standard diff --git a/src/runtime/index.md b/src/runtime/index.md new file mode 100644 index 0000000..ba79d8a --- /dev/null +++ b/src/runtime/index.md @@ -0,0 +1,7 @@ +# Runtime + +Jule does not have a special runtime like virtual machine. However, every Jule program has a implicit use declaration for standard package that defines critical and important functions as well as some API functions by default. This package is the `std::runtime` package. + +API functions are mostly functions that can be used by the backend and require a great deal of low-level programming awareness. Called low-level because it is possible to access types that require careful handling, such as pointers, as well as behavior that can affect the behavior of the entire program. This means you also have access to critical common runtime functions of the Jule programs. + +In addition to providing an API for the backend, the package also contains some definitions that can be accessed directly from within Jule. These definitions grant access to some permitted functions at runtime, but typically most programs do not need this. \ No newline at end of file diff --git a/src/runtime/public-functionalities.md b/src/runtime/public-functionalities.md new file mode 100644 index 0000000..6a59d8d --- /dev/null +++ b/src/runtime/public-functionalities.md @@ -0,0 +1,10 @@ +# Public Runtime Functionalities + +The runtime library provides some public definitions. These definitions are mostly safe, and they may influence common runtime behavior or provide some additional opportunities. + +## Globals + +```jule +const RCDelta: untyped integer +``` +The reference counting data delta value that must occur per each reference counting operation. \ No newline at end of file diff --git a/src/runtime/runtime-api.md b/src/runtime/runtime-api.md new file mode 100644 index 0000000..dc63189 --- /dev/null +++ b/src/runtime/runtime-api.md @@ -0,0 +1,137 @@ +# Runtime API + +The runtime library provides some definitions as APIs to be used in the backend. This section includes which functions are provided as APIs and their documentation. If you want to see how they are declared in the backend, see the [API](/api/runtime-api) documentation. + +## Globals + +```jule +static mut argc: int +``` +Assigned by entry point. + +```jule +static mut argv: **byte +``` +Assigned by entry point. + +```jule +static mut envp: **byte +``` +Assigned by entry point. + +## Functions + +```jule +fn ptrToStr(p: *unsafe): str +``` +Returns pointer in string form. + +```jule +fn boolToStr(b: bool): str +``` +Returns boolean in string form. + +```jule +fn i64ToStr(x: i64): str +``` +Returns x in decimal string format. + +```jule +fn u64ToStr(mut x: u64): str +``` +Returns x in decimal string format. + +```jule +fn f64ToStr(mut f: f64): str +``` +Returns x in decimal string format. + +```jule +fn writeStdout(mut buf: []byte): int +``` +Writes to stdout. Returns written byte count if success, `-1` otherwise. + +```jule +fn writeStderr(mut buf: []byte): int +``` +Writes to stderr. Returns written byte count if success, `-1` otherwise. + +```jule +fn readStdin(mut buf: []byte): int +``` +Reads from stdin. Returns readed byte count if success, `-1` otherwise. + +```jule +fn ptrEqual(a: *unsafe, b: *unsafe): bool +``` +Reports whether pointer allocations are points to same address. + +```jule +fn _RCNew(): _RCPtr +``` +Returns new initialized ready-to-use reference counting data allocation pointer. + +```jule +unsafe fn _RCLoad(p: _RCPtr): _RCType +``` +Reads reference counting data. Passing nil pointer is not safe. + +```jule +unsafe fn _RCAdd(mut p: _RCPtr) +``` +Adds strong reference to reference pointer. Passing nil pointer is not safe. + +```jule +unsafe fn _RCDrop(mut p: _RCPtr): bool +``` +Drops strong reference from reference pointer. Passing nil pointer is not safe. Reports wheter allocation still alive. + +```jule +unsafe fn _RCFree(p: _RCPtr) +``` +Deallocates reference counting data allocation. + +```jule +unsafe fn panic1(m: *byte, n: int) +``` +The built-in panic call. + +```jule +fn compareStr(&a: str, &b: str): int +``` +See `std::strings::{Compare}` function for documentation. + +```jule +fn bytesToStr(bytes: []byte): str +``` +Converts `[]byte` to `str`. + +```jule +fn runesToStr(runes: []rune): str +``` +Converts `[]rune` to `str`. + +```jule +fn strToRunes(s: str): []rune +``` +Converts `str` to `[]rune`. + +```jule +fn strToBytes(s: str): []byte +``` +Converts `str` to `[]byte`. + +```jule +fn strFromByte(b: byte): str +``` +Converts `byte` to `str`. + +```jule +fn strFromRune(r: rune): str +``` +Converts `rune` to `str`. + +```jule +unsafe fn runeStep(s: *byte, n: int, mut r: *rune, mut outLen: *int) +``` +Designed for `[]rune(s)` iterations. Takes pointer to string withl length and sets output pointers by first rune of string. Passing nil pointer for any parameter is not safe except `r`. \ No newline at end of file diff --git a/src/some-questions.md b/src/some-questions.md index ff45927..3502dbb 100644 --- a/src/some-questions.md +++ b/src/some-questions.md @@ -15,6 +15,7 @@ - [Will different memory management methods be added?](#will-different-memory-management-methods-be-added) - [Will runtime reflection be added?](#will-runtime-reflection-be-added) - [Why Jule have an optimizing compiler?](#why-jule-have-an-optimizing-compiler) +- [Jule have a runtime?](#jule-have-a-runtime) ### Why an another language? @@ -140,4 +141,10 @@ Some optimizations are (based on Jule 0.0.15): - Iteration obviously requires converting the string variable `s` into a rune slice. But Jule prevents this. There is no need to create a new allocation for runes and deallocate it after iteration. May be the entire slice won't even be handled in the iteration. So instead of actually doing a `[]rune` conversion in the background, Jule iterates through the string's runes as needed. This eliminates memory allocation and means it will process the required rune at each iteration step. - It is often not possible to know at compile time what type of data the `any` type stores. Therefore, it requires type checking at run time for operations such as casting. But there are some ways to know. In the example code, the algorithm already checks the type and then performs a casting. In this case there is no need to do type checking for casting. This is a different little optimization. -The above two optimizations are also possible to be done by the Jule compiler. The Jule compiler has mastered understanding Jule, and that is undoubtedly its job. Of course the backend compiler cannot do this because it is not optimized for Jule like the Jule compiler and cannot think in terms of Jule at compile time. In this case it is not possible to have the optimizations applied. \ No newline at end of file +The above two optimizations are also possible to be done by the Jule compiler. The Jule compiler has mastered understanding Jule, and that is undoubtedly its job. Of course the backend compiler cannot do this because it is not optimized for Jule like the Jule compiler and cannot think in terms of Jule at compile time. In this case it is not possible to have the optimizations applied. + +### Jule have a runtime? + +If we assume that the concept of "runtime" in this question is used in the sense of virtual machine, no. Jule is a language compiled entirely into machine code. But it has `std::runtime` package in the standard library. However, the main purpose of this package is to define special algorithms and some API functions that Jule programs will hear at run time. + +If you want to know more about this package, read the [Runtime](/runtime/) section. \ No newline at end of file