diff --git a/docs/.vitepress/en.ts b/docs/.vitepress/en.ts index 9b249578..fb801d43 100644 --- a/docs/.vitepress/en.ts +++ b/docs/.vitepress/en.ts @@ -19,7 +19,7 @@ export const enUs = defineConfig({ { text: 'Get Started', link: '/get-started/installation' }, { text: 'API Reference', - link: '/api-reference/method-functions/run-method', + link: '/api-reference/configuration-reference/typescript-configuration', }, { text: 'Concepts', link: '/concepts/what-is' }, navAbout, diff --git a/docs/.vitepress/id.ts b/docs/.vitepress/id.ts index 8f1ec787..bd26a688 100644 --- a/docs/.vitepress/id.ts +++ b/docs/.vitepress/id.ts @@ -19,7 +19,7 @@ export const idId = defineConfig({ { text: 'Memulai', link: '/id/get-started/installation' }, { text: 'Referensi API', - link: '/id/api-reference/method-functions/run-method', + link: '/id/api-reference/configuration-reference/typescript-configuration', }, { text: 'Konsep', link: '/id/concepts/what-is' }, navAbout, diff --git a/docs/.vitepress/lang/en/sidebarAPIReferences.ts b/docs/.vitepress/lang/en/sidebarAPIReferences.ts index f07829ff..19c7f8ae 100644 --- a/docs/.vitepress/lang/en/sidebarAPIReferences.ts +++ b/docs/.vitepress/lang/en/sidebarAPIReferences.ts @@ -1,12 +1,13 @@ +import { sidebarConfigurationReference } from './sidebarConfigurationReference.js'; +import { sidebarDataTypes } from './sidebarDataTypes.js'; import { sidebarMethodFunctions } from './sidebarMethodFunctions.js'; import { sidebarInstructionSet } from './sidebarInstructionSet.js'; import { sidebarErrorCodes } from './sidebarErrorCodes.js'; export const sidebarAPIReferences = [ + sidebarConfigurationReference, + sidebarDataTypes, sidebarMethodFunctions, - { text: 'Primitive Types', link: '/api-reference/primitive-types' }, - { text: 'Capabilities', link: '/api-reference/capabilities' }, - { text: 'Time Budget', link: '/api-reference/time-budget' }, sidebarInstructionSet, sidebarErrorCodes, ]; diff --git a/docs/.vitepress/lang/en/sidebarConfigurationReference.ts b/docs/.vitepress/lang/en/sidebarConfigurationReference.ts new file mode 100644 index 00000000..023e9765 --- /dev/null +++ b/docs/.vitepress/lang/en/sidebarConfigurationReference.ts @@ -0,0 +1,14 @@ +export const sidebarConfigurationReference = { + text: 'Configuration Reference', + collapsed: false, + items: [ + { + text: 'TypeScript Configuration', + link: '/api-reference/configuration-reference/typescript-configuration', + }, + { + text: 'Rust Configuration', + link: '/api-reference/configuration-reference/rust-configuration', + } + ], +}; diff --git a/docs/.vitepress/lang/en/sidebarDataTypes.ts b/docs/.vitepress/lang/en/sidebarDataTypes.ts new file mode 100644 index 00000000..5e3fe35e --- /dev/null +++ b/docs/.vitepress/lang/en/sidebarDataTypes.ts @@ -0,0 +1,9 @@ +export const sidebarDataTypes = { + text: 'Data Types', + collapsed: false, + items: [ + { text: 'Primitive Types', link: '/api-reference/data-types/primitive-types' }, + { text: 'Capabilities', link: '/api-reference/data-types/capabilities' }, + { text: 'Time Budget', link: '/api-reference/data-types/time-budget' }, + ], +}; diff --git a/docs/.vitepress/lang/en/sidebarGetStarted.ts b/docs/.vitepress/lang/en/sidebarGetStarted.ts index f9a85ccc..50c4ebc9 100644 --- a/docs/.vitepress/lang/en/sidebarGetStarted.ts +++ b/docs/.vitepress/lang/en/sidebarGetStarted.ts @@ -13,7 +13,7 @@ export const sidebarGetStarted = [ }, { text: 'API References', - link: '/api-reference/method-functions/run-method', + link: '/api-reference/configuration-reference/typescript-configuration', }, { text: 'Concepts', diff --git a/docs/.vitepress/lang/id/sidebarAPIReferences.ts b/docs/.vitepress/lang/id/sidebarAPIReferences.ts index 4fd10785..19c7f8ae 100644 --- a/docs/.vitepress/lang/id/sidebarAPIReferences.ts +++ b/docs/.vitepress/lang/id/sidebarAPIReferences.ts @@ -1,12 +1,13 @@ +import { sidebarConfigurationReference } from './sidebarConfigurationReference.js'; +import { sidebarDataTypes } from './sidebarDataTypes.js'; import { sidebarMethodFunctions } from './sidebarMethodFunctions.js'; import { sidebarInstructionSet } from './sidebarInstructionSet.js'; import { sidebarErrorCodes } from './sidebarErrorCodes.js'; export const sidebarAPIReferences = [ + sidebarConfigurationReference, + sidebarDataTypes, sidebarMethodFunctions, - { text: 'Tipe Primitif', link: '/id/api-reference/primitive-types' }, - { text: 'Kapabilitas', link: '/id/api-reference/capabilities' }, - { text: 'Batas Waktu Eksekusi', link: '/id/api-reference/time-budget' }, sidebarInstructionSet, sidebarErrorCodes, ]; diff --git a/docs/.vitepress/lang/id/sidebarConfigurationReference.ts b/docs/.vitepress/lang/id/sidebarConfigurationReference.ts new file mode 100644 index 00000000..e5980256 --- /dev/null +++ b/docs/.vitepress/lang/id/sidebarConfigurationReference.ts @@ -0,0 +1,14 @@ +export const sidebarConfigurationReference = { + text: 'Referensi Konfigurasi', + collapsed: false, + items: [ + { + text: 'Konfigurasi TypeScript', + link: '/id/api-reference/configuration-reference/typescript-configuration', + }, + { + text: 'Konfigurasi Rust', + link: '/id/api-reference/configuration-reference/rust-configuration', + }, + ], +}; diff --git a/docs/.vitepress/lang/id/sidebarDataTypes.ts b/docs/.vitepress/lang/id/sidebarDataTypes.ts new file mode 100644 index 00000000..1bd051fa --- /dev/null +++ b/docs/.vitepress/lang/id/sidebarDataTypes.ts @@ -0,0 +1,9 @@ +export const sidebarDataTypes = { + text: 'Tipe Data', + collapsed: false, + items: [ + { text: 'Tipe Primitif', link: '/id/api-reference/data-types/primitive-types' }, + { text: 'Kapabilitas', link: '/id/api-reference/data-types/capabilities' }, + { text: 'Batas Waktu Eksekusi', link: '/id/api-reference/data-types/time-budget' }, + ], +}; diff --git a/docs/.vitepress/lang/id/sidebarGetStarted.ts b/docs/.vitepress/lang/id/sidebarGetStarted.ts index 5397a791..16e6ba59 100644 --- a/docs/.vitepress/lang/id/sidebarGetStarted.ts +++ b/docs/.vitepress/lang/id/sidebarGetStarted.ts @@ -13,7 +13,7 @@ export const sidebarGetStarted = [ }, { text: 'Referensi API', - link: '/id/api-reference/method-functions/run-method', + link: '/id/api-reference/configuration-reference/typescript-configuration', }, { text: 'Konsep', diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css index 3bf70c4d..faf152e2 100644 --- a/docs/.vitepress/theme/style.css +++ b/docs/.vitepress/theme/style.css @@ -133,4 +133,86 @@ div[class*="language-"] > pre { .fade-enter-from, .fade-leave-to { opacity: 0; -} \ No newline at end of file +} +@keyframes floatAndGlow { + 0%, 100% { + transform: translateY(0); + filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05)); + } + 50% { + transform: translateY(-6px); + filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.12)); + } +} + +/* Light mode (default) */ +.VPImage { + animation: floatAndGlow 4s ease-in-out infinite; +} + +/* Dark mode */ +.dark .VPImage { + filter: invert(1) hue-rotate(180deg); + /* Di dark mode, shadow-nya dibikin sedikit lebih terang/glow tipis biar kontras */ + animation: floatAndGlowDark 4s ease-in-out infinite; +} + +@keyframes floatAndGlowDark { + 0%, 100% { + transform: translateY(0); + filter: invert(1) hue-rotate(180deg) drop-shadow(0 4px 6px rgba(255, 255, 255, 0.05)); + } + 50% { + transform: translateY(-6px); + filter: invert(1) hue-rotate(180deg) drop-shadow(0 12px 16px rgba(255, 255, 255, 0.15)); + } +} + +/* Keyframes buat animasi muncul dari bawah ke atas dengan halus */ +@keyframes fadeInUp { + from { + opacity: 0; + transform: translateY(20px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +/* Terapkan ke elemen teks utama di beranda VitePress (Hero section) */ +.VPHero .name { + animation: fadeInUp 0.8s ease-out forwards; +} + +.VPHero .text { + animation: fadeInUp 0.8s ease-out 0.2s forwards; + opacity: 0; /* Mencegah kedip sebelum animasi mulai */ +} + +.VPHero .tagline { + animation: fadeInUp 0.8s ease-out 0.4s forwards; + opacity: 0; +} + +.VPHero .actions { + animation: fadeInUp 0.8s ease-out 0.6s forwards; + opacity: 0; +} + +@media (prefers-reduced-motion: reduce) { + .VPImage, + .dark .VPImage, + .VPHero .name, + .VPHero .text, + .VPHero .tagline, + .VPHero .actions { + animation: none; + } + + .VPHero .text, + .VPHero .tagline, + .VPHero .actions { + opacity: 1; + } +} diff --git a/docs/data/stats.json b/docs/data/stats.json index 57eb23a4..d9dff8dc 100644 --- a/docs/data/stats.json +++ b/docs/data/stats.json @@ -1,5 +1,5 @@ { - "weekly": "3.5", - "allTime": "42.8", - "updatedAt": "2026-07-28T12:35:48.172Z" + "weekly": "4.0", + "allTime": "96.3", + "updatedAt": "2026-09-21T00:42:01.698Z" } \ No newline at end of file diff --git a/docs/en/api-reference/capabilities.md b/docs/en/api-reference/capabilities.md deleted file mode 100644 index a717f048..00000000 --- a/docs/en/api-reference/capabilities.md +++ /dev/null @@ -1,26 +0,0 @@ -# Capabilities - -A `Capability` grants a host operation permission to access a protected `LightVM` function. Pass the required values in `VMConfig.caps`. TypeScript uses `Observe` by default. - -| Capability | Numeric value | Protected operations | -| --- | ---: | --- | -| `Control` | `0` | `run`, `compile`, `embedded`, function exports, `provide`, clearing outputs, and bytecode optimization | -| `Observe` | `1` | `inspect`, reading outputs, and variable exports | -| `Debug` | `2` | Benchmarks | -| `Unsafe` | `3` | `halt` | - -## Configuration - -::: code-group - -<<< @/examples/capsConfig.ts{ts:line-numbers}[TypeScript] - -<<< @/examples/caps_config.rs{rs:line-numbers}[Rust] - -::: - -Missing capabilities cause the protected operation to fail. Capabilities do not replace resource limits in `SecurityConfig`; configure both for untrusted bytecode. - -::: warning -Grant only the capabilities the host application needs. `Unsafe` permits an external halt but does not enable `SecurityConfig.unsafeMode`. -::: diff --git a/docs/en/api-reference/configuration-reference/rust-configuration.md b/docs/en/api-reference/configuration-reference/rust-configuration.md new file mode 100644 index 00000000..be84c888 --- /dev/null +++ b/docs/en/api-reference/configuration-reference/rust-configuration.md @@ -0,0 +1,35 @@ +# Rust Configuration +This page provides a comprehensive reference for all available configuration options, limits, and security controls when initializing a `LightVM` instance. + +## Full Configuration Example +The following example demonstrates how to configure all available limits, safety flags, and error options using both the builder and object patterns. + +::: code-group +<<< @/examples/configuration-reference/builder_pattern.rs{rs:line-numbers}[Builder Pattern] +<<< @/examples/configuration-reference/object_pattern.rs{rs:line-numbers}[Object Pattern] +::: + +## Configuration Options Breakdown + +| Method / Property | Type | Default | Description | +| :--- | :--- | :--- | :--- | +| `caps` | `Vec` | `vec![]` (grants `Capability::Observe`) | Specifies the active capabilities granted to the virtual machine. | +| `set_max_io` / `max_io` | `usize` | `100` | Maximum number of I/O operations allowed during execution. | +| `set_max_import` / `max_import` | `usize` | `3` | Maximum number of allowed module imports. | +| `set_max_alloc` / `max_alloc` | `usize` | `50` | Maximum number of memory allocations allowed. | +| `set_max_call` / `max_call` | `usize` | `200` | Maximum number of nested function calls allowed. | +| `set_max_jump` / `max_jump` | `usize` | `100` | Maximum number of control flow jumps allowed. | +| `set_max_ticks` / `max_ticks` | `u64` | `1_000_000` | Maximum number of execution ticks before stopping to prevent infinite loops. | +| `set_max_stack_size` / `max_stack_size` | `usize` | `128` | Maximum number of items the evaluation stack can hold. | +| `set_allowed_imports` / `allowed_imports` | `Vec` | `vec!["math".into(), "time".into(), "utils".into()]` | Whitelist of module names that are permitted to be imported. | +| `set_time_budget` / `time_budget` | `TimeBudget` | `TimeBudget::Cheap` | Sets the execution time budget tier limit. | +| `with_unsafe_mode` / `unsafe_mode` | `bool` | `false` | Enables or disables system-level unsafe operations. | +| `with_nightly` / `nightly` | `bool` | `false` | Allows the usage of experimental nightly features. | +| `with_backtrace` / `backtrace` | `bool` | `false` | Displays internal backtrace details in error messages. | +| `with_explain` / `explain` | `bool` | `false` | Displays a more detailed explanatory hint in error messages. | +| `with_hint` / `hint` | `bool` | `true` | Displays general usage hints on error messages. | +| `with_diagnostic_links` / `diagnostic_links` | `bool` | `true` | Includes metadata links pointing to error-code documentation. | + +::: info Related Documentation +Need to check individual error codes mentioned in error messages? Visit the [Error Code Reference](/api-reference/error-codes/lvm001-code). +::: diff --git a/docs/en/api-reference/configuration-reference/typescript-configuration.md b/docs/en/api-reference/configuration-reference/typescript-configuration.md new file mode 100644 index 00000000..5ae5902c --- /dev/null +++ b/docs/en/api-reference/configuration-reference/typescript-configuration.md @@ -0,0 +1,35 @@ +# TypeScript Configuration +This page provides a comprehensive reference for all available configuration options, limits, and security controls when initializing a `LightVM` instance. + +## Full Configuration Example +The following example demonstrates how to configure all available limits, safety flags, and error options using both the builder and object patterns. + +::: code-group +<<< @/examples/configuration-reference/builderPattern.ts{ts:line-numbers}[Builder Pattern] +<<< @/examples/configuration-reference/objectPattern.ts{ts:line-numbers}[Object Pattern] +::: + +## Configuration Options Breakdown + +| Method / Property | Type | Default | Description | +| :--- | :--- | :--- | :--- | +| `caps` | `Capability[]` | `[Capability.Observe]` | Specifies the active capabilities granted to the virtual machine. | +| `setMaxIo` / `maxIo` | `number` | `100` | Maximum number of I/O operations allowed during execution. | +| `setMaxImport` / `maxImport` | `number` | `3` | Maximum number of allowed module imports. | +| `setMaxAlloc` / `maxAlloc` | `number` | `50` | Maximum number of memory allocations allowed. | +| `setMaxCall` / `maxCall` | `number` | `200` | Maximum number of nested function calls allowed. | +| `setMaxJump` / `maxJump` | `number` | `100` | Maximum number of control flow jumps allowed. | +| `setMaxTicks` / `maxTicks` | `number` | `1_000_000` | Maximum number of execution ticks before stopping to prevent infinite loops. | +| `setMaxStackSize` / `maxStackSize` | `number` | `128` | Maximum number of items the evaluation stack can hold. | +| `setAllowedImports` / `allowedImports` | `string[]` | `[]` | Whitelist of module names that are permitted to be imported. | +| `setTimeBudget` / `timeBudget` | `TimeBudget` | `TimeBudget.Cheap` | Sets the execution time budget tier limit. | +| `withUnsafeMode` / `unsafeMode` | `boolean` | `false` | Enables or disables system-level unsafe operations. | +| `withNightly` / `nightly` | `boolean` | `false` | Allows the usage of experimental nightly features. | +| `withBacktrace` / `backtrace` | `boolean` | `false` | Displays internal backtrace details in error messages. | +| `withExplain` / `explain` | `boolean` | `false` | Displays a more detailed explanatory hint in error messages. | +| `withHint` / `hint` | `boolean` | `true` | Displays general usage hints on error messages. | +| `withDiagnosticLinks` / `diagnosticLinks` | `boolean` | `true` | Includes metadata links pointing to error-code documentation. | + +::: info Related Documentation +Need to check individual error codes mentioned in error messages? Visit the [Error Code Reference](/api-reference/error-codes/lvm001-code). +::: diff --git a/docs/en/api-reference/data-types/capabilities.md b/docs/en/api-reference/data-types/capabilities.md new file mode 100644 index 00000000..35f23839 --- /dev/null +++ b/docs/en/api-reference/data-types/capabilities.md @@ -0,0 +1,16 @@ +# Capabilities + +A `Capability` grants a host operation permission to access a protected `LightVM` function. Pass the required values in `VMConfig.caps`. TypeScript uses `Observe` by default. + +| Capability | Numeric value | Protected operations | +| --- | ---: | --- | +| `Control` | `0` | `run`, `compile`, `embedded`, function exports, `provide`, clearing outputs, and bytecode optimization | +| `Observe` | `1` | `inspect`, reading outputs, and variable exports | +| `Debug` | `2` | Benchmarks, reading panic records, and clearing panic records | +| `Unsafe` | `3` | `halt`, which stops the VM | + +`unsafeMode` (or `unsafe_mode` in **Rust**) in disables security checks such as import restrictions and resource quotas for I/O, imports, allocations, calls, and jumps, but does not grant capability permissions. Bounds verification remains enabled. Calling `halt` still requires the `Unsafe` capability in `VMConfig.caps`, even with this mode enabled. + +::: warning +Failing to provide the required capabilities will cause protected host operations to fail execution or trigger runtime errors. Always ensure you grant the minimum necessary capability permissions required by your application. +::: diff --git a/docs/en/api-reference/primitive-types.md b/docs/en/api-reference/data-types/primitive-types.md similarity index 100% rename from docs/en/api-reference/primitive-types.md rename to docs/en/api-reference/data-types/primitive-types.md diff --git a/docs/en/api-reference/data-types/time-budget.md b/docs/en/api-reference/data-types/time-budget.md new file mode 100644 index 00000000..c272d3c9 --- /dev/null +++ b/docs/en/api-reference/data-types/time-budget.md @@ -0,0 +1,9 @@ +# Time Budget + +`TimeBudget` sets how much time Gazle can spend optimizing bytecode. It does not limit VM execution time. + +| Value | Numeric value | Optimizer budget | +| :--- | :--- | :--- | +| `Cheap` (default) | `0` | 200 ms | +| `Normal` | `1` | 1,000 ms | +| `Expensive` | `2` | 5,000 ms | diff --git a/docs/en/api-reference/method-functions/info-method.md b/docs/en/api-reference/method-functions/info-method.md index c80af2ad..4703e21c 100644 --- a/docs/en/api-reference/method-functions/info-method.md +++ b/docs/en/api-reference/method-functions/info-method.md @@ -18,3 +18,7 @@ In **Rust**, you can query the initialized VM instance to inspect current runtim <<< @/examples/methodFunctions/info_code.rs{rust:line-numbers}[Code] ::: + +::: info +**Capability Required**: no specific capability +::: diff --git a/docs/en/api-reference/time-budget.md b/docs/en/api-reference/time-budget.md deleted file mode 100644 index 36ad345f..00000000 --- a/docs/en/api-reference/time-budget.md +++ /dev/null @@ -1,17 +0,0 @@ -# Time Budget - -`TimeBudget` sets how much time Gazle can spend optimizing bytecode. It does not limit VM execution time. - -| Value | Numeric value | Optimizer budget | -| :--- | :--- | :--- | -| `Cheap` (default) | `0` | 200 ms | -| `Normal` | `1` | 1,000 ms | -| `Expensive` | `2` | 5,000 ms | - -Set the budget before starting optimization. Use `setTimeBudget(TimeBudget.Cheap)` before `tools().optimizeBytecode(...)`, or `set_time_budget(TimeBudget::Cheap)` before `tools().optimize_bytecode(...)` in Rust. - -A larger budget allows optimization to continue for longer. It does not guarantee a particular result. - -::: info -`SecurityConfig.maxTicks` limits VM execution work independently of `TimeBudget`. -::: diff --git a/docs/en/get-started/installation.md b/docs/en/get-started/installation.md index 3c73eaca..39c6abbd 100644 --- a/docs/en/get-started/installation.md +++ b/docs/en/get-started/installation.md @@ -38,7 +38,3 @@ If you're using **Rust**, use **Cargo** to integrate **LightVM** natively. <<< @/examples/installation/cargo-specific.sh{sh:line-numbers}[Specific Version] ::: - -## Expected result - -The package is added to your project manifest and is available to import. Continue with [Quick Usage](/get-started/quick-usage) to create a `LightVM` instance. diff --git a/docs/en/get-started/quick-usage.md b/docs/en/get-started/quick-usage.md index 8e60cbd9..89715955 100644 --- a/docs/en/get-started/quick-usage.md +++ b/docs/en/get-started/quick-usage.md @@ -24,57 +24,6 @@ For Rust projects, configure `VmConfig` before creating the VM. ::: -## Diagnostic links - -Formatted VM errors include a `documentation:` metadata row by default. Its URL is derived from the error's `LVM` code and points to the matching page in the [error-code reference](/api-reference/error-codes/lvm001-code). - -Disable the row through the constructor configuration or the fluent API: - -::: code-group - -```rust [Native configuration] -let vm = LightVM::new(VmConfig { - error_options: Some(ErrorOptions { - diagnostic_links: false, - ..Default::default() - }), - ..Default::default() -}); - -let vm = LightVM::new(VmConfig::default()) - .with_diagnostic_links(false); -``` - -```ts [Node.js] -const vm = new LightVM({ - errorOptions: { - backtrace: false, - explain: false, - hint: true, - diagnosticLinks: false, - }, -}); - -vm.withDiagnosticLinks(false); -``` - -```ts [WASM] -const vm = new LightVM({ - caps: [], - errorOptions: { diagnosticLinks: false }, -}); - -vm.withDiagnosticLinks(false); -``` - -::: - -The same setting is retained by `tools()` and applies to errors from tool operations, including bytecode optimization. - -## Expected result - -You have a configured VM instance ready to load bytecode. Continue with the [Run Method](/api-reference/method-functions/run-method), or review [Capabilities](/api-reference/capabilities) before granting access. - -::: info Related API Reference -`TimeBudget` limits bytecode optimization time. Use `SecurityConfig.maxTicks` to limit execution work. +::: tip Detailed Configuration Reference +For a comprehensive breakdown of each configuration option, parameters, and type details in TypeScript, check out the [TypeScript Configuration Reference](/api-reference/configuration-reference/typescript-configuration) or [Rust Configuration Reference](/api-reference/configuration-reference/rust-configuration). ::: diff --git a/docs/en/index.md b/docs/en/index.md index 9c7fa875..2b9192ac 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -33,15 +33,21 @@ hero: link: /get-started/installation - theme: alt text: API Reference - link: /api-reference/method-functions/run-method + link: /api-reference/configuration-reference/typescript-configuration features: - - title: Zero Magic (Deterministic) + - icon: + src: /assets/light/wand-magic.svg + title: Zero Magic details: Instruction execution is linear and completely predictable. The VM operates explicitly, executing instructions exactly as they are defined. - - title: Resource Conscious + - icon: + src: /assets/light/box.svg + title: Resource Conscious details: Designed with a minimal memory footprint through the use of optimized data structures such as SmolStr and ahash for fast metadata management. - - title: Explicit Security + - icon: + src: /assets/light/lock.svg + title: Explicit Security details: Security is managed through a strict Capability system. Every VM access and operation must have permissions explicitly defined by the host from the outset. --- - \ No newline at end of file + diff --git a/docs/examples/configuration-reference/builderPattern.ts b/docs/examples/configuration-reference/builderPattern.ts new file mode 100644 index 00000000..d0e3d47b --- /dev/null +++ b/docs/examples/configuration-reference/builderPattern.ts @@ -0,0 +1,18 @@ +import { LightVM, Capability, TimeBudget } from 'lightvm'; + +const vm = new LightVM({ caps: [Capability.Observe, Capability.Control] }) + .setMaxIo(100) + .setMaxImport(3) + .setMaxAlloc(50) + .setMaxCall(200) + .setMaxJump(100) + .setMaxTicks(1_000_000) + .setMaxStackSize(128) + .setAllowedImports(['math', 'time', 'utils']) + .setTimeBudget(TimeBudget.Cheap) + .withUnsafeMode(false) + .withNightly(false) + .withBacktrace(false) + .withExplain(false) + .withHint(true) + .withDiagnosticLinks(false); diff --git a/docs/examples/configuration-reference/builder_pattern.rs b/docs/examples/configuration-reference/builder_pattern.rs new file mode 100644 index 00000000..d49aa32e --- /dev/null +++ b/docs/examples/configuration-reference/builder_pattern.rs @@ -0,0 +1,24 @@ +use lightvm::LightVM; +use lightvm::types::{vmconfig::VmConfig, capability::Capability, time_budget::TimeBudget}; + +fn main() { + let mut vm = LightVM::new(VmConfig { + caps: vec![Capability::Control, Capability::Observe], + ..Default::default() + }) + .set_max_io(100) + .set_max_import(3) + .set_max_alloc(50) + .set_max_call(200) + .set_max_jump(100) + .set_max_ticks(1_000_000) + .set_max_stack_size(128) + .set_allowed_imports(vec!["math".into(), "time".into(), "utils".into()]) + .set_time_budget(TimeBudget::Cheap) + .with_unsafe_mode(false) + .with_nightly(false) + .with_backtrace(false) + .with_explain(false) + .with_hint(true) + .with_diagnostic_links(false); +} diff --git a/docs/examples/configuration-reference/objectPattern.ts b/docs/examples/configuration-reference/objectPattern.ts new file mode 100644 index 00000000..02122d8a --- /dev/null +++ b/docs/examples/configuration-reference/objectPattern.ts @@ -0,0 +1,26 @@ +import { LightVM, Capability, TimeBudget } from 'lightvm'; + +const vm = new LightVM({ + caps: [Capability.Observe, Capability.Control], + runtimeConfig: { + nightly: false, + }, + errorOptions: { + backtrace: false, + explain: false, + hint: true, + diagnosticLinks: false, + }, + securityConfig: { + maxIo: 100, + maxImport: 3, + maxAlloc: 50, + maxCall: 200, + maxJump: 100, + maxTicks: 1_000_000, + maxStackSize: 128, + allowedImports: ['math', 'time', 'utils'], + timeBudget: TimeBudget.Cheap, + unsafeMode: false, + }, +}); diff --git a/docs/examples/configuration-reference/object_pattern.rs b/docs/examples/configuration-reference/object_pattern.rs new file mode 100644 index 00000000..ae5fe937 --- /dev/null +++ b/docs/examples/configuration-reference/object_pattern.rs @@ -0,0 +1,36 @@ +use lightvm::LightVM; +use lightvm::types::{ + vmconfig::VmConfig, + runtime_config::RuntimeConfig, + error_options::ErrorOptions, + security_config::SecurityConfig, + capability::Capability, + time_budget::TimeBudget +}; + +fn main() { + let mut vm = LightVM::new(VmConfig { + caps: vec![Capability::Control, Capability::Observe], + runtime_config: Some(RuntimeConfig { + nightly: false + }), + error_options: Some(ErrorOptions { + backtrace: false, + explain: false, + hint: true, + diagnostic_links: false + }), + security_config: Some(SecurityConfig { + max_io: 100, + max_import: 3, + max_alloc: 50, + max_call: 200, + max_jump: 100, + max_ticks: 1_000_000, + max_stack_size: 128, + allowed_imports: vec!["math".into(), "time".into(), "utils".into()], + time_budget: TimeBudget::Cheap, + unsafe_mode: false + }) + }); +} diff --git a/docs/examples/getStarted/builderPattern.ts b/docs/examples/getStarted/builderPattern.ts index c21e4bb8..c6ca0306 100644 --- a/docs/examples/getStarted/builderPattern.ts +++ b/docs/examples/getStarted/builderPattern.ts @@ -1,20 +1,5 @@ import { LightVM, Capability, TimeBudget } from 'lightvm'; const vm = new LightVM({ caps: [Capability.Observe, Capability.Control] }) - .setMaxIo(100) // Maximum number of I/O operations allowed (default: 100) - .setMaxImport(3) // Maximum number of allowed module imports (default: 3) - .setMaxAlloc(50) // Maximum number of memory allocations allowed (default: 50) - .setMaxCall(200) // Maximum number of nested function calls allowed (default: 200) - .setMaxJump(100) // Maximum number of control flow jumps allowed (default: 100) - .setMaxTicks(1_000_000) // Maximum number of execution ticks before stopping (default: 1,000,000) - .setMaxStackSize(128) // Maximum number of items the stack can hold (default: 128) - .setAllowedImports(['math', 'time', 'utils']) // Whitelist of modules that can be imported - .setTimeBudget(TimeBudget.Cheap) // Sets the execution time budget limit to prevent infinite loops (Default: Cheap) - .withUnsafeMode(false) // Enable or disable system-level unsafe operations (default: false) - .withNightly(false) // Allow nightly features (default: false) - .withBacktrace(false) // Display backtrace details in error messages (default: false) - .withExplain(false) // Display a more detailed hint in the error message (default: false) - .withHint(true) // Display a hint on error messages (default: true) - .withDiagnosticLinks(false); // Hide links to error-code documentation (default: true) - -const tools = vm.tools(); + .setMaxTicks(1_000_000) + .setTimeBudget(TimeBudget.Cheap); diff --git a/docs/examples/getStarted/builder_pattern.rs b/docs/examples/getStarted/builder_pattern.rs index 9ef97d0b..7113df9e 100644 --- a/docs/examples/getStarted/builder_pattern.rs +++ b/docs/examples/getStarted/builder_pattern.rs @@ -6,21 +6,6 @@ fn main() { caps: vec![Capability::Control, Capability::Observe], ..Default::default() }) - .set_max_io(100) // Maximum number of I/O operations allowed (default: 100) - .set_max_import(3) // Maximum number of allowed module imports (default: 3) - .set_max_alloc(50) // Maximum number of memory allocations allowed (default: 50) - .set_max_call(200) // Maximum number of nested function calls allowed (default: 200) - .set_max_jump(100) // Maximum number of control flow jumps allowed (default: 100) - .set_max_ticks(1_000_000) // Maximum number of execution ticks before stopping (default: 1,000,000) - .set_max_stack_size(128) // Maximum number of items the stack can hold (default: 128) - .set_allowed_imports(vec!["math".into(), "time".into(), "utils".into()]) // Whitelist of modules that can be imported - .set_time_budget(TimeBudget::Cheap) // Sets the execution time budget limit to prevent infinite loops (Default: Cheap) - .with_unsafe_mode(false) // Enable or disable system-level unsafe operations (default: false) - .with_nightly(false) // Allow nightly features (default: false) - .with_backtrace(false) // Display backtrace details in error messages (default: false) - .with_explain(false) // Display a more detailed hint in the error message (default: false) - .with_hint(true) // Display a hint on error messages (default: true) - .with_diagnostic_links(false); // Hide links to error-code documentation (default: true) - - let tools = vm.tools(); + .set_max_ticks(1_000_000) + .set_time_budget(TimeBudget::Cheap); } diff --git a/docs/examples/getStarted/objectPattern.ts b/docs/examples/getStarted/objectPattern.ts index b7a3464a..c1115c79 100644 --- a/docs/examples/getStarted/objectPattern.ts +++ b/docs/examples/getStarted/objectPattern.ts @@ -2,27 +2,8 @@ import { LightVM, Capability, TimeBudget } from 'lightvm'; const vm = new LightVM({ caps: [Capability.Observe, Capability.Control], - runtimeConfig: { - nightly: false, // Allow nightly features (default: false) - }, - errorOptions: { - backtrace: false, // Display backtrace details in error messages (default: false) - explain: false, // Display a more detailed hint in the error message (default: false) - hint: true, // Display a hint on error messages (default: true) - diagnosticLinks: false, // Hide links to error-code documentation (default: true) - }, securityConfig: { - maxIo: 100, // Maximum number of I/O operations allowed (default: 100) - maxImport: 3, // Maximum number of allowed module imports (default: 3) - maxAlloc: 50, // Maximum number of memory allocations allowed (default: 50) - maxCall: 200, // Maximum number of nested function calls allowed (default: 200) - maxJump: 100, // Maximum number of control flow jumps allowed (default: 100) - maxTicks: 1_000_000, // Maximum number of execution ticks before stopping (default: 1,000,000) - maxStackSize: 128, // Maximum number of items the stack can hold (default: 128) - allowedImports: ['math', 'time', 'utils'], // Whitelist of modules that can be imported - timeBudget: TimeBudget.Cheap, // Sets the execution time budget limit to prevent infinite loops (Default: Cheap) - unsafeMode: false, // Enable or disable system-level unsafe operations (default: false) + maxTicks: 1_000_000, + timeBudget: TimeBudget.Cheap, }, }); - -const tools = vm.tools(); diff --git a/docs/examples/getStarted/object_pattern.rs b/docs/examples/getStarted/object_pattern.rs index 523bf2e8..9d84cb46 100644 --- a/docs/examples/getStarted/object_pattern.rs +++ b/docs/examples/getStarted/object_pattern.rs @@ -1,8 +1,6 @@ use lightvm::LightVM; use lightvm::types::{ vmconfig::VmConfig, - runtime_config::RuntimeConfig, - error_options::ErrorOptions, security_config::SecurityConfig, capability::Capability, time_budget::TimeBudget @@ -11,28 +9,11 @@ use lightvm::types::{ fn main() { let mut vm = LightVM::new(VmConfig { caps: vec![Capability::Control, Capability::Observe], - runtime_config: Some(RuntimeConfig { - nightly: false // Allow nightly features (default: false) - }), - error_options: Some(ErrorOptions { - backtrace: false, // Display backtrace details in error messages (default: false) - explain: false, // Display a more detailed hint in the error message (default: false) - hint: true, // Display a hint on error messages (default: true) - diagnostic_links: false // Hide links to error-code documentation (default: true) - }), security_config: Some(SecurityConfig { - max_io: 100, // Maximum number of I/O operations allowed (default: 100) - max_import: 3, // Maximum number of allowed module imports (default: 3) - max_alloc: 50, // Maximum number of memory allocations allowed (default: 50) - max_call: 200, // Maximum number of nested function calls allowed (default: 200) - max_jump: 100, // Maximum number of control flow jumps allowed (default: 100) - max_ticks: 1_000_000, // Maximum number of execution ticks before stopping (default: 1,000,000) - max_stack_size: 128, // Maximum number of items the stack can hold (default: 128) - allowed_imports: vec!["math".into(), "time".into(), "utils".into()], // Whitelist of modules that can be imported - time_budget: TimeBudget::Cheap, // Sets the execution time budget limit to prevent infinite loops (Default: Cheap) - unsafe_mode: false // Enable or disable system-level unsafe operations (default: false) - }) + max_ticks: 1_000_000, + time_budget: TimeBudget::Cheap, + ..Default::default() + }), + ..Default::default() }); - - let tools = vm.tools(); } diff --git a/docs/examples/methodFunctions/compileWithArray.ts b/docs/examples/methodFunctions/compileWithArray.ts index 242cf7e1..4d6674d0 100644 --- a/docs/examples/methodFunctions/compileWithArray.ts +++ b/docs/examples/methodFunctions/compileWithArray.ts @@ -1,15 +1,20 @@ import { Capability, FileType, LightVM, TargetArch } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control] }); const tools = vm.tools(); const raw = [ ['push', 5], ['val', 'x'], ['set', 'x'], + ['get', 'x'], + ['println'] ]; + const optimized = tools.optimizeBytecode(raw); -vm.load(optimized).compile({ +vm.load(optimized); + +vm.compile({ targetArch: TargetArch.AArch64, fileType: FileType.Binary, path: './bin/output', diff --git a/docs/examples/methodFunctions/compile_with_raw_string.rs b/docs/examples/methodFunctions/compile_with_raw_string.rs index fd75f38b..cddf80d1 100644 --- a/docs/examples/methodFunctions/compile_with_raw_string.rs +++ b/docs/examples/methodFunctions/compile_with_raw_string.rs @@ -9,7 +9,7 @@ use lightvm::types::{ fn main() { let vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); @@ -17,7 +17,9 @@ fn main() { let raw = r#"[ ["push", 5], ["val", "x"], - ["set", "x"] + ["set", "x"], + ["get", "x"], + ["println"] ]"#; let optimized = tools.optimize_bytecode(raw); diff --git a/docs/examples/methodFunctions/compile_with_serde.rs b/docs/examples/methodFunctions/compile_with_serde.rs index 85bb893c..de8e3550 100644 --- a/docs/examples/methodFunctions/compile_with_serde.rs +++ b/docs/examples/methodFunctions/compile_with_serde.rs @@ -9,7 +9,7 @@ use lightvm::types::{ fn main() { let vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); @@ -17,7 +17,9 @@ fn main() { let raw = serde_json::json!([ ["push", 5], ["val", "x"], - ["set", "x"] + ["set", "x"], + ["get", "x"], + ["println"] ]); let optimized = tools.optimize_bytecode(raw); diff --git a/docs/examples/methodFunctions/embeddedCode.ts b/docs/examples/methodFunctions/embeddedCode.ts index bc871f6f..634129af 100644 --- a/docs/examples/methodFunctions/embeddedCode.ts +++ b/docs/examples/methodFunctions/embeddedCode.ts @@ -1,10 +1,16 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control, Capability.Observe] }); const tools = vm.tools(); -const raw = [['push', 42], ['stop']]; +const raw = [ + ['push', 42], + ['stop'] +]; + const optimized = tools.optimizeBytecode(raw); vm.load(optimized); + const result = vm.embedded(); + console.log(result); diff --git a/docs/examples/methodFunctions/embedded_with_raw_string.rs b/docs/examples/methodFunctions/embedded_with_raw_string.rs index 40401a1a..676baf7f 100644 --- a/docs/examples/methodFunctions/embedded_with_raw_string.rs +++ b/docs/examples/methodFunctions/embedded_with_raw_string.rs @@ -3,7 +3,7 @@ use lightvm::{vmconfig::VmConfig, capability::Capability}; fn main() { let vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control, Capability::Observe], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/embedded_with_serde.rs b/docs/examples/methodFunctions/embedded_with_serde.rs index ff9e6f06..b14b8b2c 100644 --- a/docs/examples/methodFunctions/embedded_with_serde.rs +++ b/docs/examples/methodFunctions/embedded_with_serde.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control, Capability::Observe], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/exportFunction.ts b/docs/examples/methodFunctions/exportFunction.ts index 827ef016..71552b18 100644 --- a/docs/examples/methodFunctions/exportFunction.ts +++ b/docs/examples/methodFunctions/exportFunction.ts @@ -1,6 +1,6 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control] }); const tools = vm.tools(); const raw = [ @@ -13,7 +13,10 @@ const raw = [ ['stop'], ['export', 'add'], ]; + const optimized = tools.optimizeBytecode(raw); vm.load(optimized); + const addFunc = vm.export('add'); + console.log(addFunc.call(5, 6)); diff --git a/docs/examples/methodFunctions/exportVariable.ts b/docs/examples/methodFunctions/exportVariable.ts index 06127598..2a6f08d2 100644 --- a/docs/examples/methodFunctions/exportVariable.ts +++ b/docs/examples/methodFunctions/exportVariable.ts @@ -1,6 +1,9 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ + caps: [Capability.Control, Capability.Observe], + runtimeConfig: { nightly: true }, +}); const tools = vm.tools(); const raw = [ @@ -9,7 +12,10 @@ const raw = [ ['set', 'score'], ['export', 'score'], ]; + const optimized = tools.optimizeBytecode(raw); vm.load(optimized); + const scoreVar = vm.export('score'); + console.log(scoreVar.call()); diff --git a/docs/examples/methodFunctions/export_function.rs b/docs/examples/methodFunctions/export_function.rs index 27b98734..8409ba59 100644 --- a/docs/examples/methodFunctions/export_function.rs +++ b/docs/examples/methodFunctions/export_function.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/export_variable.rs b/docs/examples/methodFunctions/export_variable.rs index cd9040bc..cb164104 100644 --- a/docs/examples/methodFunctions/export_variable.rs +++ b/docs/examples/methodFunctions/export_variable.rs @@ -1,9 +1,12 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{ + capability::Capability, runtime_config::RuntimeConfig, vmconfig::VmConfig, +}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control, Capability::Observe], + runtime_config: Some(RuntimeConfig { nightly: true }), ..Default::default() }); let tools = vm.tools(); @@ -19,6 +22,6 @@ fn main() { vm.load(optimized); let score_variable = vm.export("score".to_string()); - + println!("{:?}", score_variable.call(&mut vm, vec![])); } diff --git a/docs/examples/methodFunctions/haltCode.ts b/docs/examples/methodFunctions/haltCode.ts index 1325c298..06d041ff 100644 --- a/docs/examples/methodFunctions/haltCode.ts +++ b/docs/examples/methodFunctions/haltCode.ts @@ -1,7 +1,8 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Unsafe] }); vm.halt(); vm.run(); // will not be executed + console.log('The VM has been terminated.'); diff --git a/docs/examples/methodFunctions/halt_code.rs b/docs/examples/methodFunctions/halt_code.rs index 54b3b716..8a4f2935 100644 --- a/docs/examples/methodFunctions/halt_code.rs +++ b/docs/examples/methodFunctions/halt_code.rs @@ -3,12 +3,12 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Unsafe], ..Default::default() }); vm.halt(); vm.run(None); // will not be executed - + println!("The VM has been terminated."); } diff --git a/docs/examples/methodFunctions/infoCode.ts b/docs/examples/methodFunctions/infoCode.ts index 8d32f8b6..c0a54a64 100644 --- a/docs/examples/methodFunctions/infoCode.ts +++ b/docs/examples/methodFunctions/infoCode.ts @@ -1,5 +1,5 @@ -import { Capability, LightVM } from 'lightvm'; +import { LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [] }); console.log(vm.info()); diff --git a/docs/examples/methodFunctions/info_code.rs b/docs/examples/methodFunctions/info_code.rs index 9e3c30b0..f669dcf1 100644 --- a/docs/examples/methodFunctions/info_code.rs +++ b/docs/examples/methodFunctions/info_code.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); diff --git a/docs/examples/methodFunctions/inspectCode.ts b/docs/examples/methodFunctions/inspectCode.ts index dfc33ff8..08c064ed 100644 --- a/docs/examples/methodFunctions/inspectCode.ts +++ b/docs/examples/methodFunctions/inspectCode.ts @@ -1,5 +1,7 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Observe] }); + const report = vm.inspect(); + console.log(report); diff --git a/docs/examples/methodFunctions/inspect_code.rs b/docs/examples/methodFunctions/inspect_code.rs index 2b18a155..eabe62ba 100644 --- a/docs/examples/methodFunctions/inspect_code.rs +++ b/docs/examples/methodFunctions/inspect_code.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Observe], ..Default::default() }); diff --git a/docs/examples/methodFunctions/onEventFinish.ts b/docs/examples/methodFunctions/onEventFinish.ts index 4cccf168..8140e05b 100644 --- a/docs/examples/methodFunctions/onEventFinish.ts +++ b/docs/examples/methodFunctions/onEventFinish.ts @@ -1,6 +1,7 @@ -import { Capability, LightVM, VMEvent } from 'lightvm'; +import { LightVM, VMEvent } from 'lightvm'; + +const vm = new LightVM({ caps: [] }); -const vm = new LightVM({ caps: [Capability.Debug] }); vm.on(VMEvent.Finish, (data) => { console.log('Event: ', data.event); console.log('Payload: ', data.payload); diff --git a/docs/examples/methodFunctions/onEventHalt.ts b/docs/examples/methodFunctions/onEventHalt.ts index 7046d7a7..367a134c 100644 --- a/docs/examples/methodFunctions/onEventHalt.ts +++ b/docs/examples/methodFunctions/onEventHalt.ts @@ -1,6 +1,7 @@ -import { Capability, LightVM, VMEvent } from 'lightvm'; +import { LightVM, VMEvent } from 'lightvm'; + +const vm = new LightVM({ caps: [] }); -const vm = new LightVM({ caps: [Capability.Debug] }); vm.on(VMEvent.Halt, (data) => { console.log('Event: ', data.event); console.log('Payload: ', data.payload); diff --git a/docs/examples/methodFunctions/onEventStart.ts b/docs/examples/methodFunctions/onEventStart.ts index 3edea97f..524b8c5a 100644 --- a/docs/examples/methodFunctions/onEventStart.ts +++ b/docs/examples/methodFunctions/onEventStart.ts @@ -1,6 +1,7 @@ -import { Capability, LightVM, VMEvent } from 'lightvm'; +import { LightVM, VMEvent } from 'lightvm'; + +const vm = new LightVM({ caps: [] }); -const vm = new LightVM({ caps: [Capability.Debug] }); vm.on(VMEvent.Start, (data) => { console.log('Event: ', data.event); console.log('Payload: ', data.payload); diff --git a/docs/examples/methodFunctions/onEventTick.ts b/docs/examples/methodFunctions/onEventTick.ts index eb1d357f..612d7722 100644 --- a/docs/examples/methodFunctions/onEventTick.ts +++ b/docs/examples/methodFunctions/onEventTick.ts @@ -1,6 +1,7 @@ -import { Capability, LightVM, VMEvent } from 'lightvm'; +import { LightVM, VMEvent } from 'lightvm'; + +const vm = new LightVM({ caps: [] }); -const vm = new LightVM({ caps: [Capability.Debug] }); vm.on(VMEvent.Tick, (data) => { console.log('Event: ', data.event); console.log('Payload: ', data.payload); diff --git a/docs/examples/methodFunctions/on_event_finish.rs b/docs/examples/methodFunctions/on_event_finish.rs index c7993902..22bd4c03 100644 --- a/docs/examples/methodFunctions/on_event_finish.rs +++ b/docs/examples/methodFunctions/on_event_finish.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig, vmevent::VmEven fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug, Capability::Control], + caps: vec![Capability::Control], ..Default::default() }); diff --git a/docs/examples/methodFunctions/on_event_halt.rs b/docs/examples/methodFunctions/on_event_halt.rs index 3bf14a6e..7f2c0401 100644 --- a/docs/examples/methodFunctions/on_event_halt.rs +++ b/docs/examples/methodFunctions/on_event_halt.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig, vmevent::VmEven fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug, Capability::Unsafe], + caps: vec![Capability::Unsafe], ..Default::default() }); diff --git a/docs/examples/methodFunctions/on_event_start.rs b/docs/examples/methodFunctions/on_event_start.rs index 9407bf41..7ccc0136 100644 --- a/docs/examples/methodFunctions/on_event_start.rs +++ b/docs/examples/methodFunctions/on_event_start.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig, vmevent::VmEven fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug, Capability::Control], + caps: vec![Capability::Control], ..Default::default() }); diff --git a/docs/examples/methodFunctions/on_event_tick.rs b/docs/examples/methodFunctions/on_event_tick.rs index 6c2e0dbb..8a9e1073 100644 --- a/docs/examples/methodFunctions/on_event_tick.rs +++ b/docs/examples/methodFunctions/on_event_tick.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig, vmevent::VmEvent}; +use lightvm::types::{vmconfig::VmConfig, vmevent::VmEvent}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); diff --git a/docs/examples/methodFunctions/provideWithArray.ts b/docs/examples/methodFunctions/provideWithArray.ts index c9a3b94a..78192891 100644 --- a/docs/examples/methodFunctions/provideWithArray.ts +++ b/docs/examples/methodFunctions/provideWithArray.ts @@ -1,8 +1,20 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control] }); +const tools = vm.tools(); + vm.provide({ name: 'John Doe', force: 2021, }); -const raw = [['get', 'name'], ['println'], ['get', 'force'], ['println']]; + +const raw = [ + ['get', 'name'], + ['println'], + ['get', 'force'], + ['println'] +]; + +const optimized = tools.optimizeBytecode(raw); +vm.load(optimized) + .run(); diff --git a/docs/examples/methodFunctions/provide_with_raw_string.rs b/docs/examples/methodFunctions/provide_with_raw_string.rs index 7dafec99..03ca1a43 100644 --- a/docs/examples/methodFunctions/provide_with_raw_string.rs +++ b/docs/examples/methodFunctions/provide_with_raw_string.rs @@ -3,9 +3,10 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug, Capability::Control], + caps: vec![Capability::Control], ..Default::default() }); + let tools = vm.tools(); vm.provide(serde_json::json!({ "name": "John Doe", @@ -19,7 +20,7 @@ fn main() { ["println"] ]"#; - let optimized = vm.tools().optimize_bytecode(raw); + let optimized = tools.optimize_bytecode(raw); vm.load(optimized) .run(None); } diff --git a/docs/examples/methodFunctions/provide_with_serde.rs b/docs/examples/methodFunctions/provide_with_serde.rs index 5f81a19c..6580603a 100644 --- a/docs/examples/methodFunctions/provide_with_serde.rs +++ b/docs/examples/methodFunctions/provide_with_serde.rs @@ -3,9 +3,10 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug, Capability::Control], + caps: vec![Capability::Control], ..Default::default() }); + let tools = vm.tools(); vm.provide(serde_json::json!({ "name": "John Doe", @@ -19,7 +20,7 @@ fn main() { ["println"] ]); - let optimized = vm.tools().optimize_bytecode(raw); + let optimized = tools.optimize_bytecode(raw); vm.load(optimized) .run(None); } diff --git a/docs/examples/methodFunctions/runWithArray.ts b/docs/examples/methodFunctions/runWithArray.ts index fb5192c1..0fa7cedc 100644 --- a/docs/examples/methodFunctions/runWithArray.ts +++ b/docs/examples/methodFunctions/runWithArray.ts @@ -1,12 +1,16 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control] }); const tools = vm.tools(); const raw = [ ['push', 5], ['val', 'x'], ['set', 'x'], + ['get', 'x'], + ['println'] ]; + const optimized = tools.optimizeBytecode(raw); -vm.load(optimized).run(); +vm.load(optimized) + .run(); diff --git a/docs/examples/methodFunctions/run_with_raw_string.rs b/docs/examples/methodFunctions/run_with_raw_string.rs index ebdbe966..f2bfb81e 100644 --- a/docs/examples/methodFunctions/run_with_raw_string.rs +++ b/docs/examples/methodFunctions/run_with_raw_string.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); @@ -11,7 +11,9 @@ fn main() { let raw = r#"[ ["push", 5], ["val", "x"], - ["set", "x"] + ["set", "x"], + ["get", "x"], + ["println"] ]"#; let optimized = tools.optimize_bytecode(raw); diff --git a/docs/examples/methodFunctions/run_with_serde.rs b/docs/examples/methodFunctions/run_with_serde.rs index d4fce344..2eb3d7fa 100644 --- a/docs/examples/methodFunctions/run_with_serde.rs +++ b/docs/examples/methodFunctions/run_with_serde.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); @@ -11,7 +11,9 @@ fn main() { let raw = serde_json::json!([ ["push", 5], ["val", "x"], - ["set", "x"] + ["set", "x"], + ["get", "x"], + ["println"] ]); let optimized = tools.optimize_bytecode(raw); diff --git a/docs/examples/methodFunctions/toolsMethod/optimizeBytecodeWithArray.ts b/docs/examples/methodFunctions/toolsMethod/optimizeBytecodeWithArray.ts index 7adf4ed7..3ec914d1 100644 --- a/docs/examples/methodFunctions/toolsMethod/optimizeBytecodeWithArray.ts +++ b/docs/examples/methodFunctions/toolsMethod/optimizeBytecodeWithArray.ts @@ -1,6 +1,6 @@ import { Capability, LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [Capability.Control] }); const tools = vm.tools(); const raw = [ @@ -8,5 +8,7 @@ const raw = [ ['val', 'x'], ['set', 'x'], ]; + const optimized = tools.optimizeBytecode(raw); + console.log(optimized); diff --git a/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_raw_string.rs b/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_raw_string.rs index 64aa120b..ee488331 100644 --- a/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_raw_string.rs +++ b/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_raw_string.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_serde.rs b/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_serde.rs index d005392d..11075d9b 100644 --- a/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_serde.rs +++ b/docs/examples/methodFunctions/toolsMethod/optimize_bytecode_with_serde.rs @@ -3,7 +3,7 @@ use lightvm::types::{capability::Capability, vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![Capability::Control], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/toolsMethod/parseArrayCode.ts b/docs/examples/methodFunctions/toolsMethod/parseArrayCode.ts index 37a91689..3e973388 100644 --- a/docs/examples/methodFunctions/toolsMethod/parseArrayCode.ts +++ b/docs/examples/methodFunctions/toolsMethod/parseArrayCode.ts @@ -1,6 +1,6 @@ -import { Capability, LightVM } from 'lightvm'; +import { LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [] }); const tools = vm.tools(); const strVal = ` @@ -8,5 +8,7 @@ const strVal = ` val x; ;; IP=1 set x; ;; IP=2 `; + const parsed = tools.parseLTCArray(strVal); + console.log(parsed); diff --git a/docs/examples/methodFunctions/toolsMethod/parseCode.ts b/docs/examples/methodFunctions/toolsMethod/parseCode.ts index 9a2ece9a..afe453bb 100644 --- a/docs/examples/methodFunctions/toolsMethod/parseCode.ts +++ b/docs/examples/methodFunctions/toolsMethod/parseCode.ts @@ -1,6 +1,6 @@ -import { Capability, LightVM } from 'lightvm'; +import { LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [] }); const tools = vm.tools(); const strVal = ` @@ -8,5 +8,7 @@ const strVal = ` val x; ;; IP=1 set x; ;; IP=2 `; + const parsed = tools.parseLTC(strVal); + console.log(parsed); diff --git a/docs/examples/methodFunctions/toolsMethod/parse_array_code.rs b/docs/examples/methodFunctions/toolsMethod/parse_array_code.rs index 79452396..3f24ab6f 100644 --- a/docs/examples/methodFunctions/toolsMethod/parse_array_code.rs +++ b/docs/examples/methodFunctions/toolsMethod/parse_array_code.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/toolsMethod/parse_code.rs b/docs/examples/methodFunctions/toolsMethod/parse_code.rs index bcd10772..aaa742b5 100644 --- a/docs/examples/methodFunctions/toolsMethod/parse_code.rs +++ b/docs/examples/methodFunctions/toolsMethod/parse_code.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/toolsMethod/stringifyWithArray.ts b/docs/examples/methodFunctions/toolsMethod/stringifyWithArray.ts index dc6220dc..3a2ae716 100644 --- a/docs/examples/methodFunctions/toolsMethod/stringifyWithArray.ts +++ b/docs/examples/methodFunctions/toolsMethod/stringifyWithArray.ts @@ -1,6 +1,6 @@ -import { Capability, LightVM } from 'lightvm'; +import { LightVM } from 'lightvm'; -const vm = new LightVM({ caps: [Capability.Debug] }); +const vm = new LightVM({ caps: [] }); const tools = vm.tools(); const raw = [ @@ -8,5 +8,7 @@ const raw = [ ['val', 'x'], ['set', 'x'], ]; + const stringify = tools.stringifyLTC(raw); + console.log(stringify); diff --git a/docs/examples/methodFunctions/toolsMethod/stringify_with_raw_string.rs b/docs/examples/methodFunctions/toolsMethod/stringify_with_raw_string.rs index 6faad88d..b98ecfb6 100644 --- a/docs/examples/methodFunctions/toolsMethod/stringify_with_raw_string.rs +++ b/docs/examples/methodFunctions/toolsMethod/stringify_with_raw_string.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/examples/methodFunctions/toolsMethod/stringify_with_serde.rs b/docs/examples/methodFunctions/toolsMethod/stringify_with_serde.rs index 6be8c642..84fb54bd 100644 --- a/docs/examples/methodFunctions/toolsMethod/stringify_with_serde.rs +++ b/docs/examples/methodFunctions/toolsMethod/stringify_with_serde.rs @@ -1,9 +1,9 @@ use lightvm::LightVM; -use lightvm::types::{capability::Capability, vmconfig::VmConfig}; +use lightvm::types::{vmconfig::VmConfig}; fn main() { let mut vm = LightVM::new(VmConfig { - caps: vec![Capability::Debug], + caps: vec![], ..Default::default() }); let tools = vm.tools(); diff --git a/docs/id/api-reference/capabilities.md b/docs/id/api-reference/capabilities.md deleted file mode 100644 index a7d3582e..00000000 --- a/docs/id/api-reference/capabilities.md +++ /dev/null @@ -1,26 +0,0 @@ -# Kapabilitas - -`Capability` memberi izin kepada operasi host untuk mengakses fungsi `LightVM` yang dilindungi. Teruskan nilai yang diperlukan melalui `VMConfig.caps`. TypeScript menggunakan `Observe` secara bawaan. - -| Kapabilitas | Nilai numerik | Operasi yang dilindungi | -| --- | ---: | --- | -| `Control` | `0` | `run`, `compile`, `embedded`, ekspor fungsi, `provide`, menghapus output, dan optimasi bytecode | -| `Observe` | `1` | `inspect`, membaca output, dan ekspor variabel | -| `Debug` | `2` | Benchmark | -| `Unsafe` | `3` | `halt` | - -## Konfigurasi - -::: code-group - -<<< @/examples/capsConfig.ts{ts:line-numbers}[TypeScript] - -<<< @/examples/caps_config.rs{rs:line-numbers}[Rust] - -::: - -Kapabilitas yang tidak diberikan menyebabkan operasi terlindungi gagal. Kapabilitas tidak menggantikan batas sumber daya dalam `SecurityConfig`; konfigurasikan keduanya untuk bytecode yang tidak tepercaya. - -::: warning -Berikan hanya kapabilitas yang diperlukan aplikasi host. `Unsafe` mengizinkan penghentian eksternal, tetapi tidak mengaktifkan `SecurityConfig.unsafeMode`. -::: diff --git a/docs/id/api-reference/configuration-reference/rust-configuration.md b/docs/id/api-reference/configuration-reference/rust-configuration.md new file mode 100644 index 00000000..121af7ee --- /dev/null +++ b/docs/id/api-reference/configuration-reference/rust-configuration.md @@ -0,0 +1,32 @@ +# Konfigurasi Rust +Halaman ini menyediakan referensi komprehensif untuk semua opsi konfigurasi, batasan, dan kontrol keamanan yang tersedia saat menginisialisasi instance `LightVM`. +## Contoh Konfigurasi Lengkap +Contoh berikut mendemonstrasikan cara mengonfigurasi semua batas, bendera keamanan, dan opsi error yang tersedia menggunakan pola builder maupun object. +::: code-group +<<< @/examples/configuration-reference/builder_pattern.rs{rs:line-numbers}[Builder Pattern] +<<< @/examples/configuration-reference/object_pattern.rs{rs:line-numbers}[Object Pattern] +::: +## Rincian Opsi Konfigurasi + +| Method / Properti | Tipe | Default | Deskripsi | +| :--- | :--- | :--- | :--- | +| `caps` | `Vec` | `vec![]` (memberikan `Capability::Observe`) | Menentukan kapabilitas aktif yang diberikan ke virtual machine. | +| `set_max_io` / `max_io` | `usize` | `100` | Jumlah maksimum operasi I/O yang diizinkan selama eksekusi. | +| `set_max_import` / `max_import` | `usize` | `3` | Jumlah maksimum impor modul yang diizinkan. | +| `set_max_alloc` / `max_alloc` | `usize` | `50` | Jumlah maksimum alokasi memori yang diizinkan. | +| `set_max_call` / `max_call` | `usize` | `200` | Jumlah maksimum pemanggilan fungsi bersarang yang diizinkan. | +| `set_max_jump` / `max_jump` | `usize` | `100` | Jumlah maksimum lompatan control flow yang diizinkan. | +| `set_max_ticks` / `max_ticks` | `u64` | `1_000_000` | Jumlah maksimum tick eksekusi sebelum berhenti untuk mencegah infinite loop. | +| `set_max_stack_size` / `max_stack_size` | `usize` | `128` | Jumlah maksimum item yang dapat ditampung oleh evaluation stack. | +| `set_allowed_imports` / `allowed_imports` | `Vec` | `vec!["math".into(), "time".into(), "utils".into()]` | Daftar putih nama modul yang diizinkan untuk diimpor. | +| `set_time_budget` / `time_budget` | `TimeBudget` | `TimeBudget::Cheap` | Menetapkan batas tingkatan anggaran waktu eksekusi. | +| `with_unsafe_mode` / `unsafe_mode` | `bool` | `false` | Mengaktifkan atau menonaktifkan operasi tingkat sistem yang tidak aman (unsafe). | +| `with_nightly` / `nightly` | `bool` | `false` | Mengizinkan penggunaan fitur nightly eksperimental. | +| `with_backtrace` / `backtrace` | `bool` | `false` | Menampilkan detail backtrace internal dalam pesan error. | +| `with_explain` / `explain` | `bool` | `false` | Menampilkan petunjuk penjelasan yang lebih rinci dalam pesan error. | +| `with_hint` / `hint` | `bool` | `true` | Menampilkan petunjuk penggunaan umum pada pesan error. | +| `with_diagnostic_links` / `diagnostic_links` | `bool` | `true` | Menyertakan tautan metadata yang mengarah ke dokumentasi kode error. | + +::: info Dokumentasi Terkait +Perlu memeriksa kode error individual yang disebutkan dalam pesan error? Kunjungi [Referensi Kode Error](/api-reference/error-codes/lvm001-code). +::: diff --git a/docs/id/api-reference/configuration-reference/typescript-configuration.md b/docs/id/api-reference/configuration-reference/typescript-configuration.md new file mode 100644 index 00000000..1d42a9a6 --- /dev/null +++ b/docs/id/api-reference/configuration-reference/typescript-configuration.md @@ -0,0 +1,32 @@ +# Konfigurasi TypeScript +Halaman ini menyediakan referensi komprehensif untuk semua opsi konfigurasi, batasan, dan kontrol keamanan yang tersedia saat menginisialisasi instance `LightVM`. +## Contoh Konfigurasi Lengkap +Contoh berikut mendemonstrasikan cara mengonfigurasi semua batas, bendera keamanan, dan opsi error yang tersedia menggunakan pola builder maupun object. +::: code-group +<<< @/examples/configuration-reference/builderPattern.ts{ts:line-numbers}[Builder Pattern] +<<< @/examples/configuration-reference/objectPattern.ts{ts:line-numbers}[Object Pattern] +::: +## Rincian Opsi Konfigurasi + +| Method / Properti | Tipe | Default | Deskripsi | +| :--- | :--- | :--- | :--- | +| `caps` | `Capability[]` | `[Capability.Observe]` | Menentukan kapabilitas aktif yang diberikan ke virtual machine. | +| `setMaxIo` / `maxIo` | `number` | `100` | Jumlah maksimum operasi I/O yang diizinkan selama eksekusi. | +| `setMaxImport` / `maxImport` | `number` | `3` | Jumlah maksimum impor modul yang diizinkan. | +| `setMaxAlloc` / `maxAlloc` | `number` | `50` | Jumlah maksimum alokasi memori yang diizinkan. | +| `setMaxCall` / `maxCall` | `number` | `200` | Jumlah maksimum pemanggilan fungsi bersarang yang diizinkan. | +| `setMaxJump` / `maxJump` | `number` | `100` | Jumlah maksimum lompatan control flow yang diizinkan. | +| `setMaxTicks` / `maxTicks` | `number` | `1_000_000` | Jumlah maksimum tick eksekusi sebelum berhenti untuk mencegah infinite loop. | +| `setMaxStackSize` / `maxStackSize` | `number` | `128` | Jumlah maksimum item yang dapat ditampung oleh evaluation stack. | +| `setAllowedImports` / `allowedImports` | `string[]` | `[]` | Daftar putih nama modul yang diizinkan untuk diimpor. | +| `setTimeBudget` / `timeBudget` | `TimeBudget` | `TimeBudget.Cheap` | Menetapkan batas tingkatan anggaran waktu eksekusi. | +| `withUnsafeMode` / `unsafeMode` | `boolean` | `false` | Mengaktifkan atau menonaktifkan operasi tingkat sistem yang tidak aman (unsafe). | +| `withNightly` / `nightly` | `boolean` | `false` | Mengizinkan penggunaan fitur nightly eksperimental. | +| `withBacktrace` / `backtrace` | `boolean` | `false` | Menampilkan detail backtrace internal dalam pesan error. | +| `withExplain` / `explain` | `boolean` | `false` | Menampilkan petunjuk penjelasan yang lebih rinci dalam pesan error. | +| `withHint` / `hint` | `boolean` | `true` | Menampilkan petunjuk penggunaan umum pada pesan error. | +| `withDiagnosticLinks` / `diagnosticLinks` | `boolean` | `true` | Menyertakan tautan metadata yang mengarah ke dokumentasi kode error. | + +::: info Dokumentasi Terkait +Perlu memeriksa kode error individual yang disebutkan dalam pesan error? Kunjungi [Referensi Kode Error](/api-reference/error-codes/lvm001-code). +::: diff --git a/docs/id/api-reference/data-types/capabilities.md b/docs/id/api-reference/data-types/capabilities.md new file mode 100644 index 00000000..fa5e0894 --- /dev/null +++ b/docs/id/api-reference/data-types/capabilities.md @@ -0,0 +1,16 @@ +# Kapabilitas + +`Capability` memberi izin kepada operasi host untuk mengakses fungsi `LightVM` yang dilindungi. Teruskan nilai yang diperlukan melalui `VMConfig.caps`. TypeScript menggunakan `Observe` secara bawaan. + +| Kapabilitas | Nilai numerik | Operasi yang dilindungi | +| --- | ---: | --- | +| `Control` | `0` | `run`, `compile`, `embedded`, ekspor fungsi, `provide`, menghapus output, dan optimasi bytecode | +| `Observe` | `1` | `inspect`, membaca output, dan ekspor variabel | +| `Debug` | `2` | Benchmark, membaca catatan panic, dan menghapus catatan panic | +| `Unsafe` | `3` | `halt`, yang menghentikan VM | + +`unsafeMode` (atau `unsafe_mode` pada **Rust**) menonaktifkan pemeriksaan keamanan seperti pembatasan impor dan kuota sumber daya untuk I/O, impor, alokasi, pemanggilan fungsi, dan lompatan, tetapi tidak memberikan izin kapabilitas. Verifikasi batas tetap aktif. Pemanggilan `halt` tetap memerlukan kapabilitas `Unsafe` dalam `VMConfig.caps`, bahkan dengan mode ini diaktifkan. + +::: warning +Kegagalan memberikan kapabilitas yang sesuai akan menyebabkan operasi host yang dilindungi gagal dijalankan atau memicu error saat runtime. Pastikan untuk selalu memberikan izin kapabilitas minimum yang dibutuhkan oleh aplikasi Anda. +::: diff --git a/docs/id/api-reference/primitive-types.md b/docs/id/api-reference/data-types/primitive-types.md similarity index 100% rename from docs/id/api-reference/primitive-types.md rename to docs/id/api-reference/data-types/primitive-types.md diff --git a/docs/id/api-reference/data-types/time-budget.md b/docs/id/api-reference/data-types/time-budget.md new file mode 100644 index 00000000..f9df8269 --- /dev/null +++ b/docs/id/api-reference/data-types/time-budget.md @@ -0,0 +1,9 @@ +# Anggaran Waktu + +`TimeBudget` menentukan waktu yang dapat digunakan Gazle untuk mengoptimalkan bytecode. Nilai ini tidak membatasi waktu eksekusi VM. + +| Nilai | Nilai numerik | Batas optimizer | +| :--- | :--- | :--- | +| `Cheap` (bawaan) | `0` | 200 ms | +| `Normal` | `1` | 1.000 ms | +| `Expensive` | `2` | 5.000 ms | diff --git a/docs/id/api-reference/method-functions/info-method.md b/docs/id/api-reference/method-functions/info-method.md index e47f39fe..aff0d108 100644 --- a/docs/id/api-reference/method-functions/info-method.md +++ b/docs/id/api-reference/method-functions/info-method.md @@ -18,3 +18,7 @@ Dalam **Rust**, Anda dapat menquery instance VM yang telah diinisialisasi untuk <<< @/examples/methodFunctions/info_code.rs{rust:line-numbers}[Kode] ::: + +::: info +**Kapabilitas yang Dibutuhkan**: tidak ada kapabilitas khusus +::: diff --git a/docs/id/api-reference/time-budget.md b/docs/id/api-reference/time-budget.md deleted file mode 100644 index 80d43a0b..00000000 --- a/docs/id/api-reference/time-budget.md +++ /dev/null @@ -1,17 +0,0 @@ -# Anggaran Waktu - -`TimeBudget` menentukan waktu yang dapat digunakan Gazle untuk mengoptimalkan bytecode. Nilai ini tidak membatasi waktu eksekusi VM. - -| Nilai | Nilai numerik | Batas optimizer | -| :--- | :--- | :--- | -| `Cheap` (bawaan) | `0` | 200 ms | -| `Normal` | `1` | 1.000 ms | -| `Expensive` | `2` | 5.000 ms | - -Atur anggaran sebelum memulai optimasi. Gunakan `setTimeBudget(TimeBudget.Cheap)` sebelum `tools().optimizeBytecode(...)`, atau `set_time_budget(TimeBudget::Cheap)` sebelum `tools().optimize_bytecode(...)` untuk Rust. - -Anggaran yang lebih besar memungkinkan optimasi berlangsung lebih lama. Nilai ini tidak menjamin hasil tertentu. - -::: info -`SecurityConfig.maxTicks` membatasi pekerjaan eksekusi VM secara terpisah dari `TimeBudget`. -::: diff --git a/docs/id/get-started/installation.md b/docs/id/get-started/installation.md index 045f6f9d..d4c3356b 100644 --- a/docs/id/get-started/installation.md +++ b/docs/id/get-started/installation.md @@ -38,7 +38,3 @@ Jika Anda menggunakan **Rust**, gunakan **Cargo** untuk mengintegrasikan **Light <<< @/examples/installation/cargo-specific.sh{sh:line-numbers}[Versi Spesifik] ::: - -## Hasil yang diharapkan - -Paket ditambahkan ke manifest proyek dan siap diimpor. Lanjutkan ke [Penggunaan Cepat](/id/get-started/quick-usage) untuk membuat instance `LightVM`. diff --git a/docs/id/get-started/quick-usage.md b/docs/id/get-started/quick-usage.md index 8c6de527..c263e9a0 100644 --- a/docs/id/get-started/quick-usage.md +++ b/docs/id/get-started/quick-usage.md @@ -24,57 +24,6 @@ Untuk proyek Rust, konfigurasikan `VmConfig` sebelum membuat VM. ::: -## Tautan diagnostik - -Error VM yang diformat menyertakan baris metadata `documentation:` secara default. URL-nya berasal dari kode `LVM` error dan mengarah ke halaman yang sesuai dalam [referensi kode error](/id/api-reference/error-codes/lvm001-code). - -Nonaktifkan baris tersebut melalui konfigurasi konstruktor atau API fluent: - -::: code-group - -```rust [Native configuration] -let vm = LightVM::new(VmConfig { - error_options: Some(ErrorOptions { - diagnostic_links: false, - ..Default::default() - }), - ..Default::default() -}); - -let vm = LightVM::new(VmConfig::default()) - .with_diagnostic_links(false); -``` - -```ts [Node.js] -const vm = new LightVM({ - errorOptions: { - backtrace: false, - explain: false, - hint: true, - diagnosticLinks: false, - }, -}); - -vm.withDiagnosticLinks(false); -``` - -```ts [WASM] -const vm = new LightVM({ - caps: [], - errorOptions: { diagnosticLinks: false }, -}); - -vm.withDiagnosticLinks(false); -``` - -::: - -Pengaturan yang sama dipertahankan oleh `tools()` dan berlaku untuk error dari operasi alat, termasuk optimasi bytecode. - -## Hasil yang diharapkan - -Anda memiliki instance VM terkonfigurasi yang siap memuat bytecode. Lanjutkan ke [Metode Run](/id/api-reference/method-functions/run-method), atau tinjau [Kapabilitas](/id/api-reference/capabilities) sebelum memberikan akses. - -::: info Referensi API Terkait -`TimeBudget` membatasi waktu optimasi bytecode. Gunakan `SecurityConfig.maxTicks` untuk membatasi pekerjaan eksekusi. +::: tip Detail Referensi Konfigurasi +Untuk rincian komprehensif mengenai setiap opsi konfigurasi, parameter, dan detail tipe dalam TypeScript, cek [Referensi Konfigurasi TypeScript](/id/api-reference/configuration-reference/typescript-configuration) atau [Referensi Konfigurasi Rust](/id/api-reference/configuration-reference/rust-configuration). ::: diff --git a/docs/id/index.md b/docs/id/index.md index 9c61cf5a..f7ab4e6b 100644 --- a/docs/id/index.md +++ b/docs/id/index.md @@ -33,7 +33,7 @@ hero: link: /id/get-started/installation - theme: alt text: Referensi API - link: /id/api-reference/method-functions/run-method + link: /id/api-reference/configuration-reference/typescript-configuration features: - title: Zero Magic (Deterministik) diff --git a/docs/public/assets/dark/box.svg b/docs/public/assets/dark/box.svg new file mode 100644 index 00000000..525ad167 --- /dev/null +++ b/docs/public/assets/dark/box.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/assets/dark/lock.svg b/docs/public/assets/dark/lock.svg new file mode 100644 index 00000000..d7286c0f --- /dev/null +++ b/docs/public/assets/dark/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/assets/dark/wand-magic.svg b/docs/public/assets/dark/wand-magic.svg new file mode 100644 index 00000000..a196714d --- /dev/null +++ b/docs/public/assets/dark/wand-magic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/assets/light/box.svg b/docs/public/assets/light/box.svg new file mode 100644 index 00000000..525ad167 --- /dev/null +++ b/docs/public/assets/light/box.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/assets/light/lock.svg b/docs/public/assets/light/lock.svg new file mode 100644 index 00000000..d7286c0f --- /dev/null +++ b/docs/public/assets/light/lock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/assets/light/wand-magic.svg b/docs/public/assets/light/wand-magic.svg new file mode 100644 index 00000000..e604c509 --- /dev/null +++ b/docs/public/assets/light/wand-magic.svg @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/ts/src/index.ts b/ts/src/index.ts index f8c2af27..e715ee31 100644 --- a/ts/src/index.ts +++ b/ts/src/index.ts @@ -103,6 +103,7 @@ export class LightVM { capsRaw: this.config.caps, runtimeConfig: this.config.runtimeConfig, errorOptions: this.config.errorOptions, + securityConfig: this.config.securityConfig, }), ); }