mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-20 01:04:08 +10:00
Cleared out some unneeded notes
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
while (a) { //stored in an array
|
|
||||||
while (b) { //stored in an array
|
|
||||||
while(c) { //stored in an array
|
|
||||||
|
|
||||||
//just peek at the array's top
|
|
||||||
continue;
|
|
||||||
|
|
||||||
//these are stored in a second array
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
} //breaks are updated here
|
|
||||||
|
|
||||||
//but what about these?
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,9 @@ The bytecode format
|
|||||||
|
|
||||||
===
|
===
|
||||||
|
|
||||||
There are four components in the bytecode header:
|
NOTE: This datestamp header is currently not implemented
|
||||||
|
|
||||||
|
There are four components in the datestamp header:
|
||||||
|
|
||||||
TOY_VERSION_MAJOR
|
TOY_VERSION_MAJOR
|
||||||
TOY_VERSION_MINOR
|
TOY_VERSION_MINOR
|
||||||
@@ -27,47 +29,36 @@ Please note that in the final bytecode, if the null terminator of TOY_VERSION_BU
|
|||||||
|
|
||||||
===
|
===
|
||||||
|
|
||||||
At this time, a 'module' consists of a single 'routine', which acts as its global scope.
|
Bytecode Format Structure
|
||||||
|
|
||||||
Additional information may be added later, or multiple 'modules' listed sequentially may be a possibility.
|
|
||||||
|
|
||||||
===
|
|
||||||
|
|
||||||
# the routine structure, which is potentially recursive
|
|
||||||
|
|
||||||
# symbol shorthand : 'module::identifier'
|
|
||||||
# where 'module' can be omitted if it's local to this module ('identifier' within the symbols is calculated at the module level, it's always unique)
|
|
||||||
|
|
||||||
.header:
|
.header:
|
||||||
N total size # size of this routine, including all data and subroutines
|
N total size # size of this routine, including all data and subroutines
|
||||||
N .jumps count # the number of entries in the jump table (should be data count + routine count)
|
N .jumps count # the number of entries in the jump table (should be data count + routine count)
|
||||||
N .param count # the number of parameter fields expected
|
N .param count # the number of parameter fields expected (used for subroutines)
|
||||||
N .data count # the number of data fields expected
|
N .data count # the number of data fields present
|
||||||
N .routine count # the number of routines present
|
N .subs count # the number of subroutines present
|
||||||
.code start # absolute address of .code; mandatory
|
.code start # absolute address of .code; mandatory
|
||||||
.param start # absolute addess of .param; omitted if not needed
|
.param start # absolute addess of .param; omitted if not needed
|
||||||
.datatable start # absolute address of .datatable; omitted if not needed
|
.datatable start # absolute address of .datatable; omitted if not needed
|
||||||
.data start # absolute address of .data; omitted if not needed
|
.data start # absolute address of .data; omitted if not needed
|
||||||
.routine start # absolute address of .routine; omitted if not needed
|
.subs start # absolute address of .subs; omitted if not needed
|
||||||
# additional metadata fields can be added later
|
# additional metadata fields can be added later
|
||||||
|
|
||||||
.code:
|
.code:
|
||||||
# instructions read and 'executed' by the interpreter
|
# opcode instructions read and 'executed' by the interpreter (aligned to 4-byte widths)
|
||||||
READ 0
|
[READ, TOY_VALUE_STRING, Toy_StringType, stringLength] [jumpIndex]
|
||||||
LOAD 0
|
|
||||||
ASSERT
|
|
||||||
|
|
||||||
.param:
|
.param:
|
||||||
# a list of symbols to be used as keys in the environment
|
# a list of names, stored in .data, to be used for any provided function arguments
|
||||||
|
|
||||||
.jumptable:
|
.jumptable:
|
||||||
# a 'symbol -> pointer' jumptable for quickly looking up values in .data and .routines
|
# a layer of indirection for quickly looking up values in .data and .subs
|
||||||
0 -> {string, 0x00}
|
0 -> {string, 0x00}
|
||||||
1 -> {fn, 0xFF}
|
4 -> {fn, 0xFF}
|
||||||
|
|
||||||
.data:
|
.data:
|
||||||
# data that can't really be embedded into .code
|
# data that can't be cleanly embedded into .code, such as strings
|
||||||
<STRING>,"Hello world"
|
"Hello world\0"
|
||||||
|
|
||||||
.routines:
|
.subs:
|
||||||
# inner routines, each of which conforms to this spec
|
# an extension of .data, used exclusively for subroutines (they also follow this spec, recursively)
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
types:
|
|
||||||
if-then-else
|
|
||||||
ternary ?:
|
|
||||||
while
|
|
||||||
do-while
|
|
||||||
for
|
|
||||||
foreach (compounds)
|
|
||||||
switch-case-default (and continue/break?)
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
|
|
||||||
if-then:
|
|
||||||
cond-branch
|
|
||||||
if false jump end
|
|
||||||
{
|
|
||||||
then-branch
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
if-then-else: (also ternary)
|
|
||||||
cond-branch
|
|
||||||
if false jump else
|
|
||||||
{
|
|
||||||
then-branch
|
|
||||||
}
|
|
||||||
jump end
|
|
||||||
{
|
|
||||||
else-branch
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
while:
|
|
||||||
begin
|
|
||||||
cond-branch
|
|
||||||
if false jump end
|
|
||||||
{
|
|
||||||
then-branch
|
|
||||||
}
|
|
||||||
jump begin
|
|
||||||
end
|
|
||||||
|
|
||||||
do-while:
|
|
||||||
begin
|
|
||||||
{
|
|
||||||
then-branch
|
|
||||||
}
|
|
||||||
cond-branch
|
|
||||||
if true jump begin
|
|
||||||
end
|
|
||||||
|
|
||||||
for:
|
|
||||||
{
|
|
||||||
pre-branch
|
|
||||||
begin
|
|
||||||
cond-branch
|
|
||||||
if false jump end
|
|
||||||
{
|
|
||||||
then-branch
|
|
||||||
}
|
|
||||||
post-branch
|
|
||||||
jump begin
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach:
|
|
||||||
...needs more planning
|
|
||||||
|
|
||||||
switch-case-default:
|
|
||||||
...needs more planning
|
|
||||||
|
|
||||||
continue:
|
|
||||||
jump begin
|
|
||||||
unwind scopes
|
|
||||||
|
|
||||||
break:
|
|
||||||
jump end
|
|
||||||
unwind scopes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
The additional scope in 'for' is to safely encapsulate pre-branch, as variables can be declared here.
|
|
||||||
do-while's 'end' is only there for the break/continue keywords.
|
|
||||||
break and continue will also unwind scopes, up to the innermost control-flow level.
|
|
||||||
|
|
||||||
break/continue within nested scopes:
|
|
||||||
Because control flows can be nested, a stack of scope depths may be needed for break/continue...
|
|
||||||
However, this would get more complicated with closures.
|
|
||||||
To fix this, scopes may need to remember their own depth, and the depth of the innermost control-flow level.
|
|
||||||
If a scope's depth is 10 and the inner control-flow-level is 7, then calling break/continue will jump AND unwind to the inner control-flow level.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
JUMP word:
|
|
||||||
opcode
|
|
||||||
type (absolute, relative)
|
|
||||||
conditional (always, if_true, if_false)
|
|
||||||
-
|
|
||||||
|
|
||||||
value
|
|
||||||
|
|
||||||
absolute:
|
|
||||||
"value" is relative to the code sections starting position
|
|
||||||
|
|
||||||
relative:
|
|
||||||
"value" is relative to the program counter, after this opcode has been read from the bytecode
|
|
||||||
|
|
||||||
always:
|
|
||||||
Always jump
|
|
||||||
|
|
||||||
if_true:
|
|
||||||
pop the stack top
|
|
||||||
if the popped value is true, then jump
|
|
||||||
else ignore
|
|
||||||
|
|
||||||
if_false:
|
|
||||||
pop the stack top
|
|
||||||
if the popped value is true, then ignore
|
|
||||||
else jump
|
|
||||||
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
|
|
||||||
shared:
|
|
||||||
* Functions can be stored within Toy_Value & loaded by Toy_VM
|
|
||||||
* They have a list of parameters
|
|
||||||
* They can return a number of values
|
|
||||||
|
|
||||||
|
|
||||||
```toy
|
|
||||||
fn makeCounter() {
|
|
||||||
var count = 0;
|
|
||||||
|
|
||||||
fn next() {
|
|
||||||
return ++count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return next;
|
|
||||||
}
|
|
||||||
|
|
||||||
var tally = makeCounter();
|
|
||||||
|
|
||||||
print tally(); //1
|
|
||||||
print tally(); //2
|
|
||||||
print tally(); //3
|
|
||||||
```
|
|
||||||
|
|
||||||
```toy
|
|
||||||
import standard as std;
|
|
||||||
|
|
||||||
print std.clock();
|
|
||||||
```
|
|
||||||
|
|
||||||
bytecode_functions:
|
|
||||||
* They point to a raw chunk of bytecode (the module)
|
|
||||||
* Closures are supported via scopes (they have a persistent scope)
|
|
||||||
|
|
||||||
c_functions:
|
|
||||||
* Delegates to user code & APIs
|
|
||||||
* invoked via 'hooks' (which are called with the 'import' keyword)
|
|
||||||
|
|
||||||
```
|
|
||||||
typedef struct Toy_Module {
|
|
||||||
Toy_Scope* scopePtr;
|
|
||||||
|
|
||||||
unsigned char* code;
|
|
||||||
unsigned int codeSize;
|
|
||||||
|
|
||||||
unsigned int paramSize;
|
|
||||||
unsigned int jumpsSize;
|
|
||||||
unsigned int dataSize;
|
|
||||||
unsigned int subsSize;
|
|
||||||
|
|
||||||
unsigned int paramAddr;
|
|
||||||
unsigned int codeAddr;
|
|
||||||
unsigned int jumpsAddr;
|
|
||||||
unsigned int dataAddr;
|
|
||||||
unsigned int subsAddr;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
flow:
|
|
||||||
compile module from AST ->
|
|
||||||
append module to bundle ->
|
|
||||||
bind VM (takes module) ->
|
|
||||||
run VM
|
|
||||||
|
|
||||||
Definitions:
|
|
||||||
bundles have version info (MAJOR, MINOR, PATCH, BUILD) and may have more than 1 modules.
|
|
||||||
Modules are chunks of usable memory, loadable into VMs.
|
|
||||||
VMs run the actual code.
|
|
||||||
Functions are unions, either pointers to modules, or pointers to user-defined C callbacks.
|
|
||||||
Functions are packed into values.
|
|
||||||
|
|
||||||
API:
|
|
||||||
init bundle
|
|
||||||
verify bundle
|
|
||||||
|
|
||||||
append bundle with module
|
|
||||||
extract module from bundle
|
|
||||||
|
|
||||||
# Notes
|
|
||||||
|
|
||||||
* Scopes, buckets, strings, etc. will persist until the root VM is cleared
|
|
||||||
* The parameters are...
|
|
||||||
Reference in New Issue
Block a user