aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/sloth_vm/src')
-rw-r--r--crates/sloth_vm/src/sloth_std/file.rs12
-rw-r--r--crates/sloth_vm/src/sloth_std/misc.rs6
-rw-r--r--crates/sloth_vm/src/sloth_std/rand.rs11
-rw-r--r--crates/sloth_vm/src/sloth_std/stdio.rs17
-rw-r--r--crates/sloth_vm/src/sloth_std/term.rs11
-rw-r--r--crates/sloth_vm/src/sloth_std/time.rs5
6 files changed, 51 insertions, 11 deletions
diff --git a/crates/sloth_vm/src/sloth_std/file.rs b/crates/sloth_vm/src/sloth_std/file.rs
index 5761f09..dea914a 100644
--- a/crates/sloth_vm/src/sloth_std/file.rs
+++ b/crates/sloth_vm/src/sloth_std/file.rs
@@ -31,7 +31,11 @@ pub const FILE_READ: NativeFunction = NativeFunction {
function: file_read,
arity: 1,
returns_value: true,
- doc: None,
+ doc: Some(
+ "NativeFunction file_read: \n\targs: path (str)\n\tdesc: Returns the contents of a file \
+ at <path>\n\tExample: `var todo = file_read('/home/sloth/todo.txt'); # Assuming the \
+ contents of todo.txt are 'Take a nap' then todo = 'Take a nap'`",
+ ),
};
fn file_write(vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
@@ -71,5 +75,9 @@ pub const FILE_WRITE: NativeFunction = NativeFunction {
function: file_write,
arity: 2,
returns_value: false,
- doc: None,
+ doc: Some(
+ "NativeFunction file_write: \n\targs: path (str), content (str)\n\tdesc: Writes <content> \
+ to file at <path>\n\tExample: `file_write('/home/sloth/todo.txt', 'Take a nap'); # \
+ todo.txt now contains the string 'Take a nap'`",
+ ),
};
diff --git a/crates/sloth_vm/src/sloth_std/misc.rs b/crates/sloth_vm/src/sloth_std/misc.rs
index 72be48f..54d6e37 100644
--- a/crates/sloth_vm/src/sloth_std/misc.rs
+++ b/crates/sloth_vm/src/sloth_std/misc.rs
@@ -35,5 +35,9 @@ pub const GET_DOC: NativeFunction = NativeFunction {
function: get_doc,
arity: 1,
returns_value: true,
- doc: None,
+ doc: Some(
+ "NativeFunction get_doc: \n\targs: name (str)\n\tdesc: Returns documentaiton on a \
+ function with name <str>\n\tExample: `var doc = get_doc('wait'); # Returns the \
+ documentation of the 'wait' function to doc`",
+ ),
};
diff --git a/crates/sloth_vm/src/sloth_std/rand.rs b/crates/sloth_vm/src/sloth_std/rand.rs
index 93da0d7..1718c6d 100644
--- a/crates/sloth_vm/src/sloth_std/rand.rs
+++ b/crates/sloth_vm/src/sloth_std/rand.rs
@@ -16,7 +16,10 @@ pub const GEN_FUNCTION: NativeFunction = NativeFunction {
function: gen,
arity: 0,
returns_value: true,
- doc: None,
+ doc: Some(
+ "NativeFunction rand_gen:\n\tdesc: Returns a random number in the range `0.0 .. \
+ 1.0`\n\tExample: `var num = rand_gen(); # num could be any number from 0.0 to 1.0`",
+ ),
};
fn gen_range(_vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
@@ -37,5 +40,9 @@ pub const GEN_RANGE_FUNCTION: NativeFunction = NativeFunction {
function: gen_range,
arity: 2,
returns_value: true,
- doc: None,
+ doc: Some(
+ "NativeFunction rand_gen_range: \n\targs: min (int), max (int)\n\tdesc: Returns a random \
+ numnber in the range <min> .. <max>\n\tExample: `var num = gen_range(20, 76); # num \
+ could be any number from 20 to 76`",
+ ),
};
diff --git a/crates/sloth_vm/src/sloth_std/stdio.rs b/crates/sloth_vm/src/sloth_std/stdio.rs
index 160d012..f56b604 100644
--- a/crates/sloth_vm/src/sloth_std/stdio.rs
+++ b/crates/sloth_vm/src/sloth_std/stdio.rs
@@ -28,7 +28,10 @@ pub const WRITE_FUNCTION: NativeFunction = NativeFunction {
function: write,
arity: 1,
returns_value: false,
- doc: None,
+ doc: Some(
+ "NativeFunction write: \n\targs: string (str)\n\tdesc: Writes <string> to the \
+ terminal.\n\tExample: `write(\"I'm sleepy...\"); # Output: I'm sleepy...`",
+ ),
};
fn writeln(vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
@@ -55,7 +58,11 @@ pub const WRITELN_FUNCTION: NativeFunction = NativeFunction {
function: writeln,
arity: 1,
returns_value: false,
- doc: None,
+ doc: Some(
+ "NativeFunction writeln: \n\targs: string (str)\n\tdesc: Writes <string> to the terminal \
+ and starts a new line.\n\tExample: `writeln(\"I'm sleepy...\"); # Output: I'm \
+ sleepy...\n # This is a new line`",
+ ),
};
fn read(vm: &mut VM, _args: &[Primitive]) -> NativeFunctionResult {
@@ -76,5 +83,9 @@ pub const READ_FUNCTION: NativeFunction = NativeFunction {
function: read,
arity: 0,
returns_value: true,
- doc: None,
+ doc: Some(
+ "NativeFunction read:\n\tdesc: Reads input from the terminal and returns what was \
+ read.\n\tExample: `var input = read(); # Hello World <execute code> input = 'Hello \
+ World'`",
+ ),
};
diff --git a/crates/sloth_vm/src/sloth_std/term.rs b/crates/sloth_vm/src/sloth_std/term.rs
index 41e6708..16fd86a 100644
--- a/crates/sloth_vm/src/sloth_std/term.rs
+++ b/crates/sloth_vm/src/sloth_std/term.rs
@@ -11,7 +11,10 @@ pub const TERM_CLEAR: NativeFunction = NativeFunction {
},
arity: 0,
returns_value: false,
- doc: None,
+ doc: Some(
+ "NativeFunction term_clear: \n\tdesc: Clears the terminal\n\tExample: `term_clear(); # \
+ Clears the terminal`",
+ ),
};
fn term_setpos(_vm: &mut VM, args: &[Primitive]) -> NativeFunctionResult {
@@ -30,5 +33,9 @@ pub const TERM_SETPOS: NativeFunction = NativeFunction {
function: term_setpos,
arity: 2,
returns_value: false,
- doc: None,
+ doc: Some(
+ "NativeFunction term_setpos: \n\targs: x (int), y (int)\n\tdesc: Sets the cursors \
+ position to (<x>, <y>)\n\tExample: `term_setpos(5, 17); # Sets the position of the \
+ cursor to (5, 17)`",
+ ),
};
diff --git a/crates/sloth_vm/src/sloth_std/time.rs b/crates/sloth_vm/src/sloth_std/time.rs
index d32d860..b27e0b5 100644
--- a/crates/sloth_vm/src/sloth_std/time.rs
+++ b/crates/sloth_vm/src/sloth_std/time.rs
@@ -22,5 +22,8 @@ pub const WAIT: NativeFunction = NativeFunction {
function: wait,
arity: 1,
returns_value: false,
- doc: Some("Use `wait(sec: int)` to sleep for `sec` time"),
+ doc: Some(
+ "NativeFunction wait: \n\targs: sec (int)\n\tdesc: Waits for <sec> seconds.\n\tExample: \
+ `wait(10); # Waits 10 seconds`",
+ ),
};