From 81c95ff69d84229d1804d94b6feeb707a4c7e6c5 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 17 Apr 2026 09:25:18 +1000 Subject: [PATCH] Cleared out some unneeded notes --- .notes/break-continue-theory.toy | 19 ----- .notes/bytecode-format.txt | 43 +++++------ .notes/control-flow-opcodes.txt | 120 ------------------------------- .notes/functions.md | 83 --------------------- 4 files changed, 17 insertions(+), 248 deletions(-) delete mode 100644 .notes/break-continue-theory.toy delete mode 100644 .notes/control-flow-opcodes.txt delete mode 100644 .notes/functions.md diff --git a/.notes/break-continue-theory.toy b/.notes/break-continue-theory.toy deleted file mode 100644 index bf71254..0000000 --- a/.notes/break-continue-theory.toy +++ /dev/null @@ -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; - } -} diff --git a/.notes/bytecode-format.txt b/.notes/bytecode-format.txt index 19b6159..251d8ad 100644 --- a/.notes/bytecode-format.txt +++ b/.notes/bytecode-format.txt @@ -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_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. - -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) +Bytecode Format Structure .header: 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 .param count # the number of parameter fields expected - N .data count # the number of data fields expected - N .routine count # the number of routines present + N .param count # the number of parameter fields expected (used for subroutines) + N .data count # the number of data fields present + N .subs count # the number of subroutines present .code start # absolute address of .code; mandatory .param start # absolute addess of .param; omitted if not needed .datatable start # absolute address of .datatable; 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 .code: - # instructions read and 'executed' by the interpreter - READ 0 - LOAD 0 - ASSERT + # opcode instructions read and 'executed' by the interpreter (aligned to 4-byte widths) + [READ, TOY_VALUE_STRING, Toy_StringType, stringLength] [jumpIndex] .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: - # 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} - 1 -> {fn, 0xFF} + 4 -> {fn, 0xFF} .data: - # data that can't really be embedded into .code - ,"Hello world" + # data that can't be cleanly embedded into .code, such as strings + "Hello world\0" -.routines: - # inner routines, each of which conforms to this spec +.subs: + # an extension of .data, used exclusively for subroutines (they also follow this spec, recursively) diff --git a/.notes/control-flow-opcodes.txt b/.notes/control-flow-opcodes.txt deleted file mode 100644 index 5ea6673..0000000 --- a/.notes/control-flow-opcodes.txt +++ /dev/null @@ -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 - diff --git a/.notes/functions.md b/.notes/functions.md deleted file mode 100644 index a89a7cc..0000000 --- a/.notes/functions.md +++ /dev/null @@ -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... \ No newline at end of file