mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Updated docs and comments
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
I'm extremely appreciative to have people contribute their time and expertise towards this project. Before I get into the details, let me give some high level goals:
|
I'm extremely appreciative to have people contribute their time and expertise towards this project. Before I get into the details, let me give some high level goals:
|
||||||
|
|
||||||
* Toy is intended to work as an embedded scripting language inside a game engine, tentatively titled "Box".
|
* Toy is intended to work as an embedded scripting language inside a game engine, tentatively titled "Box", but should be general enough to use anywhere.
|
||||||
* Toy's goal is to allow for a great degree of modability for any games developed with the Box engine.
|
* Toy's goal is to allow for a great degree of modability for any games developed with the Box engine.
|
||||||
* As such, using Toy itself should be easy for novice and veteran coders.
|
* As such, using Toy itself should be easy for novice and veteran coders.
|
||||||
* Toy is developed with a focus on speed, efficient resource management, and portability.
|
* Toy is developed with a focus on speed, efficient resource management, and portability.
|
||||||
@@ -12,29 +12,71 @@ I'm extremely appreciative to have people contribute their time and expertise to
|
|||||||
|
|
||||||
First, the main development branch of Toy is 'v2', with the branches 'v1' and 'v1-docs' kept for reference.
|
First, the main development branch of Toy is 'v2', with the branches 'v1' and 'v1-docs' kept for reference.
|
||||||
|
|
||||||
v2 is a ground-up rewrite, with additions, changes and deletions to the language that make sense. If you want to discuss the direction things are going, the [Discussions Tab](https://github.com/Ratstail91/Toy/discussions) is perfect for that.
|
v2 is a ground-up rewrite, with additions, changes and deletions to the language that make sense. If you want to discuss the direction things are going, the [Discussions Tab](https://github.com/Ratstail91/Toy/discussions) is perfect for that (though, maybe a bit outdated at times).
|
||||||
|
|
||||||
The [Issue Tracker](https://github.com/Ratstail91/Toy/issues) is a good place to see what tasks and issues are currently waiting to be addressed. The [toy.h](https://github.com/Ratstail91/Toy/blob/v2/source/toy.h) source file is a quick way to see what building blocks are available in the source code. There are also a number of comments prepended with `TODO` scattered throughout the source code, as reminders of planned features.
|
The [Issue Tracker](https://github.com/Ratstail91/Toy/issues) is a good place to see what tasks and issues are currently waiting to be addressed. The [toy.h](https://github.com/Ratstail91/Toy/blob/v2/source/toy.h) source file is a quick way to see what building blocks are available in the source code. There are also a number of comments prepended with `URGENT` or `TODO` scattered throughout the source code, as reminders to myself.
|
||||||
|
|
||||||
The [tests directory](https://github.com/Ratstail91/Toy/tree/v2/tests), which holds a collection of automated tests for the CI pipeline, can be a good way to see how those parts are used. Likewise, the [REPL](https://github.com/Ratstail91/Toy/tree/v2/repl) shows a practical usage of Toy.
|
The [tests directory](https://github.com/Ratstail91/Toy/tree/v2/tests), which holds a collection of automated tests for the CI pipeline, can be a good way to see how those parts are used. Likewise, the [REPL](https://github.com/Ratstail91/Toy/tree/v2/repl) shows a practical usage of Toy.
|
||||||
|
|
||||||
*v2 is under heavy development, and as such may not be in a working state yet. Your patience and feedback can help, but missing features such as a documentation website are coming, eventually.*
|
*v2 is under heavy development, and as such may not be in a working state yet. Your patience and feedback can help, but a documentation website is coming... eventually.*
|
||||||
|
|
||||||
# Building Blocks
|
# Building Blocks
|
||||||
|
|
||||||
These data structures should be as independent as they can be, but there are some dependencies:
|
The flow from source code to runtime is below - Toy_Bytecode is a thin wrapper for Toy_Routine, that produces the final output.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph LR
|
||||||
|
source[source code]@{ shape: flag }
|
||||||
|
Toy_Lexer@{ shape: card }
|
||||||
|
Toy_Parser@{ shape: card }
|
||||||
|
|
||||||
|
source --->|bound to| Toy_Lexer
|
||||||
|
Toy_Lexer --->|bound to| Toy_Parser
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph LR
|
||||||
|
Toy_Parser@{ shape: card }
|
||||||
|
Toy_Ast@{ shape: card }
|
||||||
|
Toy_Bytecode@{ shape: card }
|
||||||
|
|
||||||
|
Toy_Parser --->|generates| Toy_Ast
|
||||||
|
Toy_Ast --->|compiled to| Toy_Bytecode
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
graph LR
|
||||||
|
intermediate[outputted bytecode]@{ shape: flag }
|
||||||
|
Toy_VM@{ shape: card }
|
||||||
|
|
||||||
|
intermediate --->|used by| Toy_VM
|
||||||
|
```
|
||||||
|
|
||||||
|
The main data structures used at runtime tend to have a top-down dependency graph, as shown below - `Toy_Scope` isn't shown, as it acts more as a wrapper around `Toy_Table`.
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
graph TB
|
graph TB
|
||||||
|
Toy_Bucket@{ shape: card }
|
||||||
|
Toy_Value@{ shape: card }
|
||||||
|
Toy_String@{ shape: card }
|
||||||
|
Toy_Array@{ shape: card }
|
||||||
|
Toy_Stack@{ shape: card }
|
||||||
|
Toy_Table@{ shape: card }
|
||||||
|
Toy_VM@{ shape: card }
|
||||||
|
|
||||||
Toy_Bucket ---> Toy_String
|
Toy_Bucket ---> Toy_String
|
||||||
Toy_Value ---> Toy_String
|
Toy_Value ---> Toy_String
|
||||||
|
Toy_Value ---> Toy_Array
|
||||||
Toy_Value ---> Toy_Stack
|
Toy_Value ---> Toy_Stack
|
||||||
Toy_Value ---> Toy_Table
|
Toy_Value ---> Toy_Table
|
||||||
Toy_Value ---> Toy_Array
|
Toy_Bucket ---> Toy_VM
|
||||||
|
Toy_String ---> Toy_VM
|
||||||
|
Toy_Array ---> Toy_VM
|
||||||
|
Toy_Stack ---> Toy_VM
|
||||||
|
Toy_Table ---> Toy_VM
|
||||||
|
Toy_Value ---> Toy_VM
|
||||||
```
|
```
|
||||||
|
|
||||||
In addition, [toy_common.h](https://github.com/Ratstail91/Toy/blob/v2/source/toy_common.h) grants platform portability and version info, while [toy_console_colors.h](https://github.com/Ratstail91/Toy/blob/v2/source/toy_console_colors.h) provides string constants as macros that can help with console output (where supported).
|
|
||||||
|
|
||||||
# Coding Habits
|
# Coding Habits
|
||||||
|
|
||||||
Here's a few coding habits that I use to keep the source code consistent. While I'd prefer contributors to follow these, breaking these guidelines are ok if you need to.
|
Here's a few coding habits that I use to keep the source code consistent. While I'd prefer contributors to follow these, breaking these guidelines are ok if you need to.
|
||||||
@@ -135,8 +177,9 @@ The directories in the repository's root have certain intended uses. If you find
|
|||||||
| .github | Meta information used by GitHub, such as CI workflows and issue templates. |
|
| .github | Meta information used by GitHub, such as CI workflows and issue templates. |
|
||||||
| .notes | General storage for any kind of scratch notes or reminders, or random bits of source code that aren't needed. Rough ideas and plans are usually found here, but may be outdated. |
|
| .notes | General storage for any kind of scratch notes or reminders, or random bits of source code that aren't needed. Rough ideas and plans are usually found here, but may be outdated. |
|
||||||
| lib | The source directory for various libraries external to Toy, but which can be made available by the host and accessed with the `import` keyword. |
|
| lib | The source directory for various libraries external to Toy, but which can be made available by the host and accessed with the `import` keyword. |
|
||||||
| scripts | Storage for various example scripts written in Toy that can be loaded and executed by the repl. |
|
| repl | The source directory for the default utility provided with the language. It can be used from the command line, and supports several configuration options. |
|
||||||
| source | The source directory for the core of the Toy programming language. |
|
| scripts | Storage for various example and WIP scripts written in Toy that can be loaded and executed by the repl. |
|
||||||
| tests | The source directory for the testing systems. Within, `cases/` is used for test cases, `benchmarks/` for benchmarking, etc. |
|
| source | The source directory for the core of the Toy Programming Language. |
|
||||||
|
| tests | The source directory for the standard tests. Within, `cases/` is used for test cases, `benchmarks/` for benchmarking, etc. |
|
||||||
| tools | The source directory for various standalone tools. |
|
| tools | The source directory for various standalone tools. |
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ fn fib(n: int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 1; i <= 10; i++) {
|
for (var i = 1; i <= 10; i++) {
|
||||||
print i .. ":" .. fib(i); //type coercion syntax isn't final
|
print i.toString() .. ":" .. fib(i).toString();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -41,5 +41,10 @@ TOY_API Toy_Array* Toy_resizeArray(Toy_Array* array, unsigned int capacity);
|
|||||||
#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array), (array)->data[(array)->count++] = (value))
|
#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array), (array)->data[(array)->count++] = (value))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//URGENT: get array length in scripts (dot operator?)
|
//TODO: array.getLength()
|
||||||
//URGENT: array as a type
|
//TODO: array.pushFront(x)
|
||||||
|
//TODO: array.pushBack(x)
|
||||||
|
//TODO: array.popFront()
|
||||||
|
//TODO: array.popBack()
|
||||||
|
//TODO: array.toString()
|
||||||
|
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ static Toy_AstFlag group(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_Ast*
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Toy_AstFlag compound(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_Ast** rootHandle) {
|
static Toy_AstFlag compound(Toy_Bucket** bucketHandle, Toy_Parser* parser, Toy_Ast** rootHandle) {
|
||||||
//read in an array or dictionary compound definition
|
//read in an array or table compound definition
|
||||||
if (parser->previous.type == TOY_TOKEN_OPERATOR_BRACKET_LEFT) {
|
if (parser->previous.type == TOY_TOKEN_OPERATOR_BRACKET_LEFT) {
|
||||||
//BUGFIX: special case for empty arrays
|
//BUGFIX: special case for empty arrays
|
||||||
if (match(parser, TOY_TOKEN_OPERATOR_BRACKET_RIGHT)) {
|
if (match(parser, TOY_TOKEN_OPERATOR_BRACKET_RIGHT)) {
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include "toy_print.h"
|
#include "toy_print.h"
|
||||||
#include "toy_opcodes.h"
|
#include "toy_opcodes.h"
|
||||||
#include "toy_value.h"
|
|
||||||
#include "toy_string.h"
|
|
||||||
#include "toy_array.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
@@ -4,9 +4,14 @@
|
|||||||
|
|
||||||
#include "toy_bytecode.h"
|
#include "toy_bytecode.h"
|
||||||
#include "toy_bucket.h"
|
#include "toy_bucket.h"
|
||||||
#include "toy_stack.h"
|
|
||||||
#include "toy_scope.h"
|
#include "toy_scope.h"
|
||||||
|
|
||||||
|
#include "toy_value.h"
|
||||||
|
#include "toy_string.h"
|
||||||
|
#include "toy_stack.h"
|
||||||
|
#include "toy_array.h"
|
||||||
|
#include "toy_table.h"
|
||||||
|
|
||||||
typedef struct Toy_VM {
|
typedef struct Toy_VM {
|
||||||
//raw instructions to be executed
|
//raw instructions to be executed
|
||||||
unsigned char* module;
|
unsigned char* module;
|
||||||
|
|||||||
@@ -1,30 +1,22 @@
|
|||||||
# Test Instructions
|
# Test Instructions
|
||||||
|
|
||||||
To run these tests, execute the following commands from the repo's root:
|
To run these tests, execute one of the following commands from the repo's root:
|
||||||
|
|
||||||
`make tests`
|
`make tests`
|
||||||
`make test-cases`
|
|
||||||
`make test-integrations`
|
|
||||||
|
|
||||||
Alternatively, to run these tests under GDB, execute the following commands from the repo's root:
|
|
||||||
|
|
||||||
`make tests-gdb`
|
`make tests-gdb`
|
||||||
`make test-cases-gdb`
|
`make tests-valgrind`
|
||||||
`make test-integrations-gdb`
|
|
||||||
|
|
||||||
Remember that `make clean` will remove the build artifacts after testing, and `make tests` and `make-tests-gdb` automatically invoke `make clean` before they begin.
|
|
||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
|
|
||||||
For testing and comparing different potential solutions. This may be left in an incomplete state, so it might not work out of the box.
|
For testing and comparing different potential solutions. These may be left in an incomplete state, so they might not work out of the box.
|
||||||
|
|
||||||
## Cases
|
## Cases
|
||||||
|
|
||||||
For testing individual pieces of the source code in isolation. These are essentially the unit tests.
|
For testing individual pieces of the source code in isolation. These are essentially the unit tests, and are used by the CI pipeline.
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
This compiles the source and repl files into a library and executable, then runs each `*.toy` file through the repl to ensure the Toy code works in practice. These are essentially integration tests.
|
For testing Toy's processes as a complete whole. This will automatically build the repl, and is used by the CI pipeline.
|
||||||
|
|
||||||
## Mustfails
|
## Mustfails
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user