53 Commits

Author SHA1 Message Date
Kayne Ruse
e24823924a Comment tweaks 2026-04-12 15:02:07 +10:00
Kayne Ruse
c0c03a4110 Functions are working, tests incomplete
This required a massive cross-cutting rework to the scope system,
multiple subtle bugfixes and relearning of the parser internals, but it
does appear that functions are working correctly.

A few caveats: for now, parameters are always constant, regardless of
type, return values can't be specified, and some script tests have been
written.

Most importantly, a key feature is working: closures.
2026-04-12 11:52:58 +10:00
Kayne Ruse
6f27d07829 Added a few opcodes to the inspector 2026-04-12 00:19:20 +10:00
Kayne Ruse
b32ea9f309 Started working on a decompiler, called 'bytecode inspector'
It only has a few instructions for now, but I can flesh it out over
time.
2026-04-11 13:37:26 +10:00
Kayne Ruse
66155fa213 Tweak, but I need a decompiler now 2026-04-10 16:19:03 +10:00
Kayne Ruse
547229e150 Script tests re-added, all tests can run under gdb
Also fixed a minor bug with printing, and removed the ability to
configure the parser.

Added and updated QUICKSTART.md as a quick way to get people started.

There's some broken scripts under 'scripts/' that require functions to
work properly.
2026-04-10 15:28:56 +10:00
Kayne Ruse
211744535e Tweak 2026-04-10 12:15:02 +10:00
Kayne Ruse
1ae3fcbf73 WIP: Scopes weren't tracking their content sizes
'print' no longer segfaults from a long chain of indirect memory frees.

It still doesn't work though, which is odd.
2026-04-06 21:50:41 +10:00
Kayne Ruse
57fe9bb00d WIP: Compiles but still very broken 2026-04-05 17:04:30 +10:00
Kayne Ruse
d3b59eb0da WIP functions working, untested, memory issues, read more
I've ripped out the deep copying, and flattened the bucket usage, but
this results in no memory being freed or reused for the lifetime of the
program.

This is shown most clearly with this script:

```toy
fn makeCounter() {
	var counter: int = 0;

	fn increment() {
		return ++counter;
	}

	return increment;
}

var tally = makeCounter();

while (true) {
	var result = tally();

	if (result >= 10_000_000) {
		break;
	}
}
```

The number of calls vs amount of memory consumed is:

```
function calls -> memory used in megabytes
1_000 -> 0.138128
10_000 -> 2.235536
100_000 -> 21.7021
1_000_000 -> 216.1712
10_000_000 -> 1520.823
```

Obviously this needs to be fixed, as ballooning to gigabytes of memory
in only a moment isn't practical. That will be the next task - to find
some way to free memory that isn't needed anymore.

See #163, #160
2025-02-21 11:41:27 +11:00
Kayne Ruse
9fe6d6b218 WIP bad approach, read more
I build a self-referential system, then tried to copy only parts. I need
to step back and adjust my approach.

'Toy_private_deepCopyValue' and 'Toy_private_deepCopyScope' need to be
ripped out, and I need to simply accept there will be only one instance
of 'Toy_Bucket' that isn't freed until the top-level VM is.

I need an hour's break before I'll tackle this again.

See #163
2025-02-18 13:06:15 +11:00
Kayne Ruse
3a82593e4d Adjusted timetable 2025-02-18 08:34:29 +11:00
Kayne Ruse
639250f028 WIP return keyword, read more
Functions are having issues with being copied around, especially
between buckets, leading to the scopes getting looped. The program gets
stuck in 'incrementRefCount()'.

It's past my time limit, so I'll keep working on it tomorrow with a
fresh mind.

All function stuff is still untested.

See #163
2025-02-17 19:10:24 +11:00
Kayne Ruse
02dfc996b4 Functions are successfully called, read more
Return keyword is not yet implemented.

Functions are untested.

See #163
2025-02-17 14:05:07 +11:00
Kayne Ruse
258968d7a4 WIP, Functions are declared, still not called 2025-02-11 11:55:35 +11:00
Kayne Ruse
7a8c415b3f Functions are written, but not yet executed, untested 2025-02-10 20:17:53 +11:00
Kayne Ruse
e2a284d9ce Ensured parser is reading functions correctly, read more
Parameter lists are read manually, rather than delegating to
parsePrecedence, because that was causing issues.

function bodies are read as block-level statements, just like the entire
files.
2025-02-08 12:00:55 +11:00
Kayne Ruse
212eca1825 Tweaked README 2025-02-06 11:25:53 +11:00
Kayne Ruse
b93ea5006c Functions are WIP, read more
They're no-ops in compilation for now, and param types aren't parsed.

'return' keyword needs to be implemented.

Was distracted by bugfixes in v2 and v2-docs.
2025-02-02 17:26:47 +11:00
Kayne Ruse
63cc530899 Fixed continue keyword, was pointing at break's target 2025-02-02 16:15:20 +11:00
Kayne Ruse
513d8f130c Fixed obscure EOF bug in lexer 2025-01-14 12:45:11 +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
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
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
9cb138a7d6 Added tables to integration tests, tweaked a lot of comments 2024-12-25 11:04:18 +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
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
62ca7a1fb7 WIP: Implementing arrays into the script, read more
I had intended to solve the Advent of Code puzzles in Toy, but they
don't work without arrays. I wasn't able to enable arrays in time, so
I need to focus on doing things correctly.

The most immediate tasks are marked with 'URGENT', and a lot of tests
need writing.
2024-12-02 11:58:03 +11:00
Kayne Ruse
bb2e85e350 Updated README.md 2024-11-29 12:16:10 +11:00
Kayne Ruse
6cc331d462 While is working but untested, read more
* TODO: break and continue keywords need to be implemented
* TODO: while-then needs testing
* Fixed the parser not liking zero-length strings
2024-11-26 14:48:24 +11:00
Kayne Ruse
0b559ecb74 Fixed the lines marked as 'URGENT' 2024-11-23 10:07:05 +11:00
Kayne Ruse
b29a87840d EMERGENCY: Computer is dying, this is an incomplete commit, do not use 2024-11-22 15:48:44 +11:00
Kayne Ruse
b2b2ca7e53 If-then-else is working, untested 2024-11-20 12:50:27 +11:00
Kayne Ruse
34577ecfe1 WIP: if-then-else, incomplete 2024-11-19 17:14:39 +11:00
Kayne Ruse
2f9489d5fd Fixed a 'malformed assignment' issue, read more
I've also added some support for compiler errors in general, but these
will get expanded on later.

I've also quickly added a valgrind option to the tests and found a few
leaks. I'll deal with these later.

Summary of changes:

* Clarified the lifetime of the bytecode in memory
* Erroneous routines exit without compiling
* Empty VMs don't run
* Added a check for malformed assignments
* Renamed "routine" to "module" within the VM
* VM no longer tries to free the bytecode - must be done manually
* Started experimenting with valgrind, not yet ready
2024-11-16 21:02:37 +11:00
Kayne Ruse
b74aa63c1c Added verbose debugging option to the REPL 2024-11-12 11:16:50 +11:00
Kayne Ruse
7173f7770f Added types and constness
Fixed #144
2024-11-02 11:39:47 +11:00
Kayne Ruse
3cb2132bfa Escaped characters stored in strings correctly
Fixed #147
2024-10-30 21:13:57 +11:00
Kayne Ruse
d19ca1bcee Reworked variable equality and comparisons
Fixed #146
2024-10-30 19:58:55 +11:00
Kayne Ruse
c5206daaea Implemented scopes 2024-10-27 13:44:09 +11:00
Kayne Ruse
09e4cb7b03 Squashed: Added integration and standalone tests, read more
This wasn't an easy fix, as it was primarily the test pipelines that
were failing. I resorted to using forced pushes to run the CI, to try
and track down the problems.

The primary cause seems to be the differences in how each supported
platform handles file paths, specifically, slash vs. backslash.

I've also added gdb scripts to set up automated breakpoints, and to run
operations on them to check for issues - the 'gdb_init' files are mostly
empty for the time being.

commit a34b0ff5d407bbe7d70ff9504aa035ec6fbecb7c
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Fri Oct 18 11:45:40 2024 +1100

    Restored the workflows

commit eb3d94f30d4dc4150139517f44cc874f2901124f
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Fri Oct 18 11:35:39 2024 +1100

    I think the library path on macos is fixed

commit 964572b5e93c7cb464686f19ddbe3e9d315f391b
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Fri Oct 18 11:22:56 2024 +1100

    I think the file paths are fixed

commit 1721f3da7252b4063f4347926e800ef4f7c9bf4c
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Thu Oct 17 15:57:28 2024 +1100

    Added standalone tests

commit 90c783f4059d88f4a7bbaf18215a9b414f3ab66f
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Thu Oct 17 15:01:18 2024 +1100

    Trying to fix the integration test pipeline

commit fccced1396568a55c1385e2f1b04fedf7c2585a5
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Wed Oct 16 00:31:39 2024 +1100

    Workflow integration tests are not passing

commit 6b1e0d1e0f89291e89768bf6102f4f7ed4581496
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Tue Oct 15 20:07:20 2024 +1100

    Fixed file paths in workflow

commit c0f1ec78fe79a5abb34c3e05308236cb18c23b97
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Tue Oct 15 19:46:14 2024 +1100

    Moved example scripts into proper integration tests

    Also adjusted makefiles to allow easy invoking of the tests.

    Adjusted and updated CI to invoke tests correctly.

    Fixed #141
2024-10-18 12:04:29 +11:00
Kayne Ruse
a51c5591ee Fixed declarations without initial value 2024-10-13 15:18:48 +11:00
Kayne Ruse
80734563b9 Implemented and tested variable declaration
Assignment, etc. is still to come, as are types.
2024-10-13 15:02:42 +11:00
Kayne Ruse
4bcf8e84a9 String literals are being parsed, compiled and printed, read more
Strings, due to their potentially large size, are stored outside of a
routine's code section, in the data section. To access the correct
string, you must read the jump index, then the real address from the
jump table - and extra layer of indirection will result in more flexible
data down the road, I hope.

Other changes include:

* Added string concat operator ..
* Added TOY_STRING_MAX_LENGTH
* Strings can't be created or concatenated longer than the max length
* The parser will display a warning if the bucket is too small for a
  string at max length, but it will continue
* Added TOY_BUCKET_IDEAL to correspend with max string length
* The bucket now allocates an address that is 4-byte aligned
* Fixed missing entries in the parser rule table
* Corrected some failing TOY_BITNESS tests
2024-10-08 00:33:36 +11:00