Added details of opaque data

This commit is contained in:
2022-10-04 07:45:03 +11:00
committed by GitHub
parent e96f2fe130
commit aca61ae944
2 changed files with 16 additions and 1 deletions

View File

@@ -30,7 +30,7 @@ print tally(); //3
* Simple C-like syntax * Simple C-like syntax
* Bytecode intermediate compilation * Bytecode intermediate compilation
* Optional, but robust type system * Optional, but robust type system (including `opaque` for arbitrary data)
* functions and types are first-class citizens * functions and types are first-class citizens
* `import` and `export` variables from the host program * `import` and `export` variables from the host program
* Fancy slice notation for strings, arrays and dictionaries * Fancy slice notation for strings, arrays and dictionaries

View File

@@ -19,6 +19,7 @@ The types available are:
| dictionary | n/a | A series of key-value pairs stored in a hash-table, indexable with the keys | | dictionary | n/a | A series of key-value pairs stored in a hash-table, indexable with the keys |
| function | fn | A chunk of reusable code, which can potentially return a value of some kind | | function | fn | A chunk of reusable code, which can potentially return a value of some kind |
| type | type | The type of types | | type | type | The type of types |
| opaque | opaque | Arbitrary data passed from the host, which Toy can't natively understand |
| any | any | Can hold any value | | any | any | Can hold any value |
## Specifying Types For Variables ## Specifying Types For Variables
@@ -93,3 +94,17 @@ var t = decide(true);
var number: t = 0; //what if it had been false? var number: t = 0; //what if it had been false?
``` ```
## Opaque Data
Sometimes, you may need to pass data through Toy that Toy can't normally handle. This data is called "opaque" data, and is passed around by reference rather than value. Anything can be passed in as opaque data, as long as it's represented as a void pointer in C.
```c
Literal opaque = TO_OPAQUE_LITERAL(&data);
//...
void* dataPtr = AS_OPAQUE(opaque);
```
Managing and cleaning up opaque data is a task left entirely to the host program.