From 8610ac2529267ac5c263cc7c5bfdc3c9dc4f520e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 14 Jan 2025 13:21:09 +1100 Subject: [PATCH] Started writing some docs --- _c_api/{placeholder.md => debug.md} | 0 _c_api/parser.md | 5 ++ _getting_started/quick-start-guide.md | 66 +++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) rename _c_api/{placeholder.md => debug.md} (100%) create mode 100644 _c_api/parser.md diff --git a/_c_api/placeholder.md b/_c_api/debug.md similarity index 100% rename from _c_api/placeholder.md rename to _c_api/debug.md diff --git a/_c_api/parser.md b/_c_api/parser.md new file mode 100644 index 0000000..6e3b426 --- /dev/null +++ b/_c_api/parser.md @@ -0,0 +1,5 @@ +--- +layout: page +--- + +Watch this space. \ No newline at end of file diff --git a/_getting_started/quick-start-guide.md b/_getting_started/quick-start-guide.md index ce48939..01825f8 100644 --- a/_getting_started/quick-start-guide.md +++ b/_getting_started/quick-start-guide.md @@ -10,15 +10,81 @@ To help you start using Toy as fast as possible, here are the most useful elemen ## Keyword 'print' +The `print` keyword takes one value as a parameter, which is sent to stdout by default. + +The value can be redirected elsewhere using the [debug C API](c_api/debug). + +```toy +print "Hello World!"; +``` + ## Keyword 'assert' +The `assert` keyword takes two values as parameters, separated by a comma. If the first value is `null` or `false`, the second parameter is sent to stderr by default. Otherwise, this statement is ignored. + +The second value, which is replaced by a default error message if omitted, can be redirected elsewhere using the [debug C API](c_api/debug). + +The generation of assert statements can be disabled using the [parser C API](c_api/parser). + +```toy +assert 1 < 2; + +assert null, "Hello world!"; +``` + ## Variables and Types +Values can be stored in variables, by specifying a name with the `var` keyword. The name can also be declared with a type, which restricts what kind of value can be stored in the name. Types are optional, and defaults to `any` when not used. + +```toy +var answer = 42; + +var question: string = "How many roads must a man walk down?"; +``` + +To make a variable unchangeable after declaration, you can add the `const` keyword after the type. + +```toy +var quote: string const = "War. War never changes."; +``` + +The usable types are as follows: + +| type | name | description | +| --- | --- | --- | +| `bool` | boolean | Either `true` or `false`. | +| `int` | integer | Any whole number, representable by a signed 32-bit integer. | +| `float` | float | A decimal number, represented by 32-bits for floating-point arithmetic. | +| `string` | string | A piece of text, supports UTF-8. | +| `array` | array | A series of values stored in sequential memory. | +| `table` | table | A series key-value pairs stored in such a way that allows for fast lookups. Booleans, functions and opaques can't be used as keys. | +| `function` | function | A chunk of code to be called. It can take multiple parameters, and provide multiple return values. Unlike other variables, functions are declared with the `fn` keyword. | +| `opaque` | opaque | The contents of this value is unusable in the script, but can be passed from one API to another. | +| `any` | any | The default type used when none is specified. This type can hold any value. | + +*Note: Functions and opaques are not yet implemented at the time of writing.* + ## Control Flow +Watch this space. + +``` +if-then-else +while +for //not yet implemented +continue +break +``` + ## Functions +Watch this space. + ## External Libraries and Extending Toy +Watch this space. + ## Reserved Keywords & Operators +Watch this space. +