Update README.md; Clean up
This commit is contained in:
parent
63312cf08a
commit
c7a18b1d39
61
README.md
61
README.md
@ -117,13 +117,13 @@ Options:
|
|||||||
|
|
||||||
#### Running a program
|
#### Running a program
|
||||||
|
|
||||||
If not specified, the CLI will use `run` mode. This mode compiles and executes the Dust program,
|
If not specified, the CLI will use `run` command. This mode compiles and executes the Dust program,
|
||||||
printing the return value to the console. You can also run Dust code directly from the command line
|
printing the return value to the console. You can also run Dust code directly from the command line
|
||||||
using the `--command` or `-c` flag.
|
using the `--eval` or `-e` flag.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dust foobar.ds
|
dust foobar.ds
|
||||||
dust -c 'let x = 42; x'
|
dust -e 'let x = 42; x'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Disassembly
|
#### Disassembly
|
||||||
@ -133,7 +133,7 @@ representation of the Dust program. It shows every piece of information that the
|
|||||||
the virtual machine and explains what each instruction does and what data it uses.
|
the virtual machine and explains what each instruction does and what data it uses.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dust -d example.ds
|
dust compile example.ds
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@ -141,38 +141,38 @@ dust -d example.ds
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
╭──────────────────────────────────────────────────────────────────────────────────╮
|
╭──────────────────────────────────────────────────────────────────────────────────╮
|
||||||
│ example.ds <---- file name │
|
│ example.ds │
|
||||||
│ │
|
│ │
|
||||||
│ let mut i = 0; while i < 10 { i += 1 }; <---- source code │
|
│ let mut i = 0; while i < 10 { i += 1 } │
|
||||||
│ │
|
│ │
|
||||||
│ 6 instructions, 4 constants, 1 locals, returns none <---- summary │
|
│ 6 instructions, 4 constants, 1 locals, returns none │
|
||||||
│ │
|
│ │
|
||||||
│ Instructions │
|
│ Instructions │
|
||||||
│ ╭─────┬────────────┬─────────────────┬─────────────────────────────────────────╮ │
|
│ ╭─────┬────────────┬─────────────────┬─────────────────────────────────────────╮ │
|
||||||
│ │ i │ POSITION │ OPERATION │ INFO │ │
|
│ │ i │ POSITION │ OPERATION │ INFO │ │
|
||||||
│ ├─────┼────────────┼─────────────────┼─────────────────────────────────────────┤ │
|
│ ├─────┼────────────┼─────────────────┼─────────────────────────────────────────┤ │
|
||||||
│ │ 0 │ (12, 13) │ LOAD_CONSTANT │ R_INT_0 = C_INT_0 │ │
|
│ │ 0 │ (12, 13) │ LOAD_CONSTANT │ R_INT_0 = C0 │ │
|
||||||
│ │ 1 │ (23, 24) │ LESS │ if R_INT_0 < C_INT_1 { JUMP +1 } │ │
|
│ │ 1 │ (23, 24) │ LESS │ if R_INT_0 < C_2 { JUMP +1 } │ │
|
||||||
│ │ 2 │ (38, 39) │ JUMP │ JUMP +2 │ │
|
│ │ 2 │ (38, 38) │ JUMP │ JUMP +2 │ │
|
||||||
│ │ 3 │ (32, 34) │ ADD │ R_INT_0 = R_INT_0 + C_INT_2 │ │
|
│ │ 3 │ (30, 36) │ ADD │ R_INT_0 = R_INT_0 + C_3 │ │
|
||||||
│ │ 4 │ (38, 39) │ JUMP │ JUMP -3 │ │
|
│ │ 4 │ (38, 38) │ JUMP │ JUMP -3 │ │
|
||||||
│ │ 5 │ (39, 39) │ RETURN │ RETURN │ │
|
│ │ 5 │ (38, 38) │ RETURN │ RETURN │ │
|
||||||
│ ╰─────┴────────────┴─────────────────┴─────────────────────────────────────────╯ │
|
│ ╰─────┴────────────┴─────────────────┴─────────────────────────────────────────╯ │
|
||||||
│ Locals │
|
│ Locals │
|
||||||
│ ╭─────┬────────────────┬────────────────┬──────────┬───────┬───────╮ │
|
│ ╭─────┬────────────────┬──────────────────────────┬────────────┬───────┬───────╮ │
|
||||||
│ │ i │ identifier │ type │ register │ scope │mutable│ │
|
│ │ i │ IDENTIFIER │ TYPE │ REGISTER │ SCOPE │MUTABLE│ │
|
||||||
│ ├─────┼────────────────┼────────────────┼──────────┼───────┼───────┤ │
|
│ ├─────┼────────────────┼──────────────────────────┼────────────┼───────┼───────┤ │
|
||||||
│ │ 0 │ i │ int │ R_INT_0 │ 0.0 │ true │ │
|
│ │ 0 │ i │ int │ R_INT_0 │ 0.0 │ true │ │
|
||||||
│ ╰─────┴────────────────┴────────────────┴──────────┴───────┴───────╯ │
|
│ ╰─────┴────────────────┴──────────────────────────┴────────────┴───────┴───────╯ │
|
||||||
│ Constants │
|
│ Constants │
|
||||||
│ ╭────────┬──────────────────────────┬──────────────────────────╮ │
|
│ ╭─────┬──────────────────────────┬──────────────────────────╮ │
|
||||||
│ │ i │ TYPE │ VALUE │ │
|
│ │ i │ TYPE │ VALUE │ │
|
||||||
│ ├────────┼──────────────────────────┼──────────────────────────┤ │
|
│ ├─────┼──────────────────────────┼──────────────────────────┤ │
|
||||||
│ │ INT_0 │ int │ 0 │ │
|
│ │ 0 │ int │ 0 │ │
|
||||||
│ │ INT_1 │ int │ 10 │ │
|
│ │ 1 │ str │ i │ │
|
||||||
│ │ INT_2 │ int │ 1 │ │
|
│ │ 2 │ int │ 10 │ │
|
||||||
│ │ STR_0 │ str │ i │ │
|
│ │ 3 │ int │ 1 │ │
|
||||||
│ ╰────────┴──────────────────────────┴──────────────────────────╯ │
|
│ ╰─────┴──────────────────────────┴──────────────────────────╯ │
|
||||||
╰──────────────────────────────────────────────────────────────────────────────────╯
|
╰──────────────────────────────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -180,18 +180,17 @@ dust -d example.ds
|
|||||||
|
|
||||||
The instruction notation reflects the Dust VM's register-based architecture. Values are referred to
|
The instruction notation reflects the Dust VM's register-based architecture. Values are referred to
|
||||||
by their address in the register or constant table. For example, `R_INT_42` refers to the
|
by their address in the register or constant table. For example, `R_INT_42` refers to the
|
||||||
forty-second integer register, and `C_INT_0` refers to the first integer constant.
|
forty-second integer register, and `C_0` refers to the first constant.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
R_INT_0 = R_INT_0 + C_INT_2
|
R_INT_0 = R_INT_0 + C_3
|
||||||
```
|
```
|
||||||
|
|
||||||
The info section for the ADD instruction shows what the instruction does: it adds the value at
|
The info section for the ADD instruction shows what the instruction does: it adds the value at
|
||||||
`R_INT_0` to the value at `C_INT_2` and stores the result in `R_INT_0`. As the "Constants" section
|
`R_INT_0` to the value at `C_2` and stores the result in `R_INT_0`. As the "Constants" section
|
||||||
shows, `C_INT_2` is the integer constant `1`. This means that this add instruction increments the
|
shows, `C_2` is the integer constant `1`. This means that this add instruction increments the value
|
||||||
value in `R_INT_0` by `1`. In the "Locals" section, we can see that `R_INT_0` is the register used
|
in `R_INT_0` by `1`. In the "Locals" section, we can see that `R_INT_0` is the register used by the
|
||||||
by the `i` variable.
|
`i` variable.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -1512,15 +1512,6 @@ impl<'src> Compiler<'src> {
|
|||||||
self.instructions
|
self.instructions
|
||||||
.insert(if_block_start, (jump, Type::None, if_block_start_position));
|
.insert(if_block_start, (jump, Type::None, if_block_start_position));
|
||||||
|
|
||||||
let if_block_last_instruction_index = self.instructions.len() - else_block_distance;
|
|
||||||
let else_block_last_instruction_index = self.instructions.len() - 1;
|
|
||||||
|
|
||||||
let if_block_last_instruction = self.instructions[if_block_last_instruction_index].0;
|
|
||||||
let else_block_last_instruction =
|
|
||||||
&mut self.instructions[else_block_last_instruction_index].0;
|
|
||||||
|
|
||||||
else_block_last_instruction.set_a_field(if_block_last_instruction.a_field());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2062,7 +2053,7 @@ impl<'src> Compiler<'src> {
|
|||||||
if let Some(prefix_parser) = ParseRule::from(&self.current_token).prefix {
|
if let Some(prefix_parser) = ParseRule::from(&self.current_token).prefix {
|
||||||
debug!(
|
debug!(
|
||||||
"{} is prefix with precedence {precedence}",
|
"{} is prefix with precedence {precedence}",
|
||||||
self.current_token.to_string(),
|
self.current_token,
|
||||||
);
|
);
|
||||||
|
|
||||||
prefix_parser(self)?;
|
prefix_parser(self)?;
|
||||||
@ -2074,7 +2065,7 @@ impl<'src> Compiler<'src> {
|
|||||||
if let Some(infix_parser) = infix_rule.infix {
|
if let Some(infix_parser) = infix_rule.infix {
|
||||||
debug!(
|
debug!(
|
||||||
"{} is infix with precedence {precedence}",
|
"{} is infix with precedence {precedence}",
|
||||||
self.current_token.to_string(),
|
self.current_token,
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.current_token == Token::Equal {
|
if self.current_token == Token::Equal {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user