Commit Graph

218 Commits

Author SHA1 Message Date
Kayne Ruse
3c0a50c4cd Tweaked AST bitness test 2025-02-01 10:04:19 +11:00
Kayne Ruse
481d17f040 Tests are passing, added preserveScope to VM API 2025-01-31 13:51:53 +11:00
Kayne Ruse
bfed4e23f3 Repl works, also fixed a few small bugs 2025-01-31 10:16:06 +11:00
Kayne Ruse
002651f95d WIP, adjusting architecture, read more
The 'source' directory compiles, but the repl and tests are almost
untouched so far. There's no guarantee that the code in 'source' is
correct, so I'm branching this for a short time, until I'm confident the
whole project passes the CI again.

I'm adjusting the concepts of routines and bytecode to make them more
consistent, and tweaking the VM so it loads from an instance of
'Toy_Module'.

* 'Toy_ModuleBuilder' (formally 'Toy_Routine')

This is where the AST is compiled, producing a chunk of memory that can
be read by the VM. This will eventually operate on individual
user-defined functions as well.

* 'Toy_ModuleBundle' (formally 'Toy_Bytecode')

This collects one or more otherwise unrelated modules into one chunk of
memory, stored in sequence. It is also preprended with the version data for
Toy's reference implementation:

For each byte in the bytecode:

    0th: TOY_VERSION_MAJOR
    1st: TOY_VERSION_MINOR
    2nd: TOY_VERSION_PATCH
    3rd: (the number of modules in the bundle)
    4th and onwards: TOY_VERSION_BUILD

TOY_VERSION_BUILD has always been a null terminated C-string, but from
here on, it begins at the word-alignment, and continues until the first
word-alignment after the null terminator.

As for the 3rd byte listed, since having more than 256 modules in one
bundle seems unlikely, I'm storing the count here, as it was otherwise
unused. This is a bit janky, but it works for now.

* 'Toy_Module'

This new structure represents a single complete unit of operation, such
as a single source file, or a user-defined function. It is divided into
three main sections, with various sub-sections.

    HEADER (all members are unsigned ints):
        total module size in bytes
        jumps count
        param count
        data count
        subs count
        code addr
        jumps addr (if jumps count > 0)
        param addr (if param count > 0)
        data addr (if data count > 0)
        subs addr (if subs count > 0)
    BODY:
        <raw opcodes, etc.>
    DATA:
        jumps table
            uint array, pointing to addresses in 'data' or 'subs'
        param table
            uint array, pointing to addresses in 'data'
        data
            heterogeneous data, including strings
        subs
            an array of modules, using recursive logic

The reference implementation as a whole uses a lot of recursion, so this
makes sense.

The goal of this rework is so 'Toy_Module' can be added as a member of
'Toy_Value', as a simple and logical way to handle functions. I'll
probably use the union pattern, similarly to Toy_String, so functions
can be written in C and Toy, and used without needing to worry which is
which.
2025-01-29 10:21:33 +11:00
Kayne Ruse
a1f6f147c5 Tweaked timetable 2025-01-29 10:16:55 +11:00
Kayne Ruse
f9715c2016 Too buggered to think today. 2025-01-15 14:05:31 +11:00
Kayne Ruse
6c293cfc62 tweaked README 2025-01-15 08:59:40 +11:00
Kayne Ruse
05451af8d7 What is the most bullshit error you've ever seen?
'error: no newline at end of file'

This only occurs in the MacOS builds.
2025-01-15 08:40:22 +11:00
Kayne Ruse
730353342d Updated license date, tweaked an error message 2025-01-14 13:23:23 +11:00
Kayne Ruse
513d8f130c Fixed obscure EOF bug in lexer 2025-01-14 12:45:11 +11:00
Kayne Ruse
13daf95933 Added docs link 2025-01-12 16:26:24 +11:00
Kayne Ruse
9141102f2e Fixed stack overflow caused by assignments, read more
Variable declaration was also causing this issue.

It was caused by a value being left on the stack after these statements.
It wasn't a quick fix, as chained assignments depended on it. Now, the
assignment opcode has a configuration option, indicating if the last
value should be left on the stack or not.

This also means the benchmark in 'scripts/benchpress.toy' will no longer
cause a stack overflow.

Fixed #171
2025-01-11 15:07:29 +11:00
Kayne Ruse
ce03a342c9 Fixed a missing ';' required at the end of var statements 2025-01-11 13:27:06 +11:00
Kayne Ruse
c6d8766bc3 Added scripts/benchpress.toy
This file works in Toy v1 and Toy v2, but currently causes an SO.

See #171
2025-01-10 04:08:10 +11:00
Kayne Ruse
14696833fd Postfix '++' & '--' works (prefix & postfix are both tested) 2025-01-09 18:33:10 +11:00
Kayne Ruse
6f16c31f24 Prefix '++' working (postfix is next) 2025-01-09 16:45:48 +11:00
Kayne Ruse
3aee2ba664 Added quotemarks to internal string elements
This applies to strings within arrays and tables.
2025-01-09 12:11:23 +11:00
Kayne Ruse
b55192e513 Removed stubs for types as values
Also potentially fixed a bug in the previous commit, not certain
2025-01-09 11:46:29 +11:00
Kayne Ruse
90ffe9b40e Disallow empty bodies in control flow statements, added 'pass' keyword
Fixed #170
2025-01-09 11:03:03 +11:00
Kayne Ruse
9de9c85bea Update README.md 2025-01-01 21:21:14 +11:00
Kayne Ruse
23eb3e45df Keywords 'break' & 'continue' tested
There were a couple bugs - I'm glad I'm so thorough with these tests.

See #152
2024-12-30 16:56:57 +11:00
Kayne Ruse
b84a70cc34 Keywords 'break' and 'continue' are working, untested
See #152
2024-12-30 09:50:51 +11:00
Kayne Ruse
6d25beea03 Removed minPsl from tables, not needed (always zero)
Closes #166
2024-12-27 17:24:28 +11:00
Kayne Ruse
e96f87ff45 Merge remote-tracking branch 'refs/remotes/origin/v2' into v2 2024-12-27 13:07:19 +11:00
Kayne Ruse
0192b60338 Updated README.md, filled out issue tracker, planning ahead 2024-12-27 13:04:44 +11:00
Kayne Ruse
c3a737eae5 Added a reference file to notes 2024-12-26 17:13:46 +11:00
Kayne Ruse
cc4ff3f6d8 Fixed logical AND and OR operators, read more
The definition of '&&':
  Return the first falsy value, or the last value, skipping the evaluation of other operands.

The definition of '||':
  Return the first truthy value, or the last value, skipping the evaluation of other operands.

Toy now follows these definitions.

Fixed #154
2024-12-26 16:09:16 +11:00
Kayne Ruse
153ab54be6 Fixed some incorrect precedence rules 2024-12-26 14:46:12 +11:00
Kayne Ruse
24cfe7f539 Fixed some error states and error messages, read more
By leaving 'null' on the stack, it won't cause stack underflows in a
bunch of erroneous situations. This will allow the repl (and other
situations) to continue if they want to.

I've also fixed some error messages in toy_table.c, which were formatted
badly.

Closes #162
2024-12-26 14:33:26 +11:00
Kayne Ruse
3ca816439e Swapped some if-checks for asserts, closes #161
Thanks 'devast8a' on discord
2024-12-26 13:09:21 +11:00
Kayne Ruse
9cb138a7d6 Added tables to integration tests, tweaked a lot of comments 2024-12-25 11:04:18 +11:00
Kayne Ruse
9e2cbb1f59 Quick fix for some self-referential table bugs 2024-12-24 16:47:58 +11:00
Kayne Ruse
b092b8ce50 Added tables to the scripts, untested
This also has a lot of bugfixing.
2024-12-24 16:08:42 +11:00
Kayne Ruse
4faa0c0476 Fixed nested assignment bug 2024-12-24 11:58:51 +11:00
Kayne Ruse
223db840c8 Benchmarked memory models for Toy_Array, read more
The results can be found in
'tests/benchmarks/array_allocation/results.md'

The results are disappointing, as 'malloc()' is simply faster in every
possible situation compared to my custom arena allocator.
2024-12-24 10:37:54 +11:00
Kayne Ruse
8b5cc3b493 Wrote a benchmark to test TOY_BUCKET_IDEAL sizes 2024-12-18 00:40:17 +11:00
Kayne Ruse
04c799954c Tweaked standard bucket sizes, see #160
Hyacinth: It's pronounced "Bouquet"!
2024-12-17 22:25:33 +11:00
Kayne Ruse
3e17916a4a Prepped for #160, fixed a stack-shrink bug 2024-12-17 21:18:45 +11:00
Kayne Ruse
a28053d4e9 Reworked Toy_String as a union, enabled -Wpedantic
Toy now fits into the C spec.

Fixed #158

Addendum: MacOS test caught an error:

error: a function declaration without a prototype is deprecated in all versions of C

That took 3 attempts to fix correctly.

Addendum: 'No new line at the end of file' are you shitting me?
2024-12-15 15:52:06 +11:00
Kayne Ruse
93fce94e9c Locales are hard, sorry!
Fixed #159
2024-12-14 12:57:53 +11:00
Kayne Ruse
7be63c8ccc Added -Wpointer-arith to CFLAGS, read more
I attempted to add '-Wpedantic' to CFLAGS, but it seems that my usage of
the variable length arrays within unions is causing an error that can't
be selectively disabled:

error: invalid use of structure with flexible array member [-Werror=pedantic]

This is the offending code: /source/toy_string.h#L9-L37

It seems that tagged unions, with VLAs within, is simply not allowed.
Unfortunately, my whole string system depends on it. I'll have to find some way
around it.

I've also updated the debugging output in repl/main.c.
2024-12-12 18:23:44 +11:00
Kayne Ruse
cf9affe190 Fixed unused param
Accidentally used a c23 feature.

MacOS runner didn't like that.
2024-12-12 16:23:09 +11:00
Kayne Ruse
fce71a6cda Tweaked CFLAGS, and fixed related errors 2024-12-12 16:18:41 +11:00
Kayne Ruse
5f4dfdccc5 Updated docs and comments 2024-12-11 17:07:49 +11:00
Kayne Ruse
476a79b746 Updated README.md syntax examples 2024-12-10 17:10:09 +11:00
Kayne Ruse
5f75b5f1a3 Allowed for empty arrays and trailing commas 2024-12-10 10:44:13 +11:00
Kayne Ruse
1a36c14247 Expanded array tests, read more
Getting the array's length is still not available yet, so I'm not
marking arrays as done - but everything that is there is tested.

I've also tweaked the assert output callbacks to also print 'assert failure'.
2024-12-09 12:11:31 +11:00
Kayne Ruse
61a105db2d Compound assignment for arrays is working, untested, read more
I added reference values in 62ca7a1fb7,
but forgot to mention it. I'm now using references to assign to the
internals of an array, no matter how many levels deep it is.
2024-12-07 15:35:06 +11:00
Kayne Ruse
2324150fd5 Update CODE_OF_CONDUCT.md 2024-12-07 07:43:28 +11:00
Kayne Ruse
03dce296cb Assignment target is now an AST node
This will make assigning to arbitrary targets easier.
2024-12-04 19:24:58 +11:00