Commit Graph

182 Commits

Author SHA1 Message Date
Kayne Ruse eb33775314 FIX: compounds assigned to themselves would cause self-references 2026-04-28 09:23:43 +10:00
Kayne Ruse 6ebbcc45a3 Tweaked build paths 2026-04-27 10:07:16 +10:00
Kayne Ruse b718b35097 FIX: Substrings had corner-cases with incorrect results, read more
I found this while writing unit tests for Toy_Function, where one
(native) function was named 'identity' and another (custom) was named
'ident' to avoid a naming clash. The rename didn't resolve the clash, so
after some digging, I found that strings compared to substrings would
return a match, despite being different.

This took some awkward corner-case handling, as it turns out
'deepCompareUtil' only returns zero when no differences have been found,
not when a match has been found. I also added checks for this to
Toy_String's unit test, with the parameters checked in both orders i.e.
(a,b) and (b,a), because paranoia is your friend.

The rope pattern is powerful, but also gives you enough rope to hang
yourself.
2026-04-26 22:52:24 +10:00
Kayne Ruse af30246e0c Implemented array.forEach(fn) 2026-04-26 11:59:15 +10:00
Kayne Ruse efc9fe1406 Tweaked stack allocation when inheriting VMs 2026-04-26 10:14:19 +10:00
Kayne Ruse c9a34e2259 Corrected usage of 'Toy_allocateTable' 2026-04-26 09:55:11 +10:00
Kayne Ruse 0c24a7609e Added the following attributes:
* table.length
* table.insert(key,value)
* table.hasKey(key)
* table.remove(key)

There's basically only iteration and sorting left.
2026-04-24 23:01:57 +10:00
Kayne Ruse 88e9794952 Implemented the following attributes:
* String.length
* String.asUpper
* String.asLower
* array.length
* array.pushBack(x)
* array.popBack()

The remaining attributes are listed in 'toy_attributes.h'
2026-04-24 17:33:10 +10:00
Kayne Ruse b589392b9e Comment tweaks 2026-04-24 13:01:38 +10:00
Kayne Ruse 21819b2d62 Capitalized type names 2026-04-24 12:46:27 +10:00
Kayne Ruse 4aec343b6c BUGFIX: scopes weren't expanding as intended 2026-04-24 12:46:05 +10:00
Kayne Ruse 9a75226491 Implemented the attribute operator, using a period 2026-04-24 11:31:54 +10:00
Kayne Ruse accb7f9fb4 Started work on an AST inspector 2026-04-22 15:57:55 +10:00
Kayne Ruse 47c5d49069 Updated parser unit test, fixed a missing stack pop for binary exprStmt 2026-04-22 11:40:53 +10:00
Kayne Ruse 2c92f829e1 Fixed stack overflow caused by expression statements
This is a longstanding bug, so I'm glad its fixed, even if its only a
bandaid.

This does break some tests, but I'm too tired and these tests are out of
date.
2026-04-17 23:43:30 +10:00
Kayne Ruse 5b101d763e Expanded bytecode inspector, added functions to Toy_copyValue 2026-04-17 11:55:46 +10:00
Kayne Ruse 88100b128a Implemented native C functions called from Toy scripts
There's only example functions for now, but I'll add type-specific
functions later.
2026-04-16 21:14:42 +10:00
Kayne Ruse 3a0f11ebb4 Added string type check 2026-04-16 19:30:23 +10:00
Kayne Ruse f9790b99ce Moved type coersion check, functions can be compared
Also updated some tagged comments
2026-04-15 15:04:54 +10:00
Kayne Ruse 8eefbc8a0c Added remaining opcodes to inspector
Also used some coloring for terminal outputs
2026-04-12 23:04:31 +10:00
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 49a825aaf9 Removed some old notes 2026-04-11 02:06:59 +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 842f041a50 VM test is passing 2026-04-07 21:34:05 +10:00
Kayne Ruse 09fc6d5279 Compiler test is passing 2026-04-07 20:36:58 +10:00
Kayne Ruse 48072f0dd1 AST test is passing 2026-04-07 20:06:44 +10:00
Kayne Ruse 522fc3e64b Value test is passing 2026-04-07 19:44:28 +10:00
Kayne Ruse f4ce6ad9f1 String test is passing
Note: String fragmentation is no longer supported
2026-04-07 19:22:31 +10:00
Kayne Ruse f06218b9cd 'print' now works as expected
String literals are now stored in the bucket mid-compilation, but this
is fine, as the buckets are freed one the bytecode is complete.
2026-04-06 23:08:17 +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 fbb7e1bc54 WIP: Retreived the unit tests (formerly test cases)
Some of these still work, others have just been dummied out for now.

Also added tests for console colors tool, and tweaked it to work
properly.
2026-04-05 18:42:56 +10:00
Kayne Ruse 57fe9bb00d WIP: Compiles but still very broken 2026-04-05 17:04:30 +10:00
Kayne Ruse 914ee6fcfa WIP: Fixed strings and scopes, still reworking impacted areas 2026-04-05 10:13:58 +10:00
Kayne Ruse ba9418f365 Removed unneeded files and console colors are disabled 2026-04-04 20:35:12 +11:00
Kayne Ruse 4b21e61df0 Updated README 2025-02-28 11:30:01 +11: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 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 76d89fe0ad Reduced excessive calls to Toy_unwrapValue()
In practice, references only point to arrays or tables.

Fixed #176
2025-02-17 04:42:22 +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 344c265918 Parameters are immutable
It took me a whole day to change one line.
2025-02-09 14:34:44 +11:00
NishiOwO 1006b6e216 Add bitness definitions, and platform definitions 2025-02-08 22:14:32 +09:00
NishiOwO a1cfc095a7 Compile on NetBSD 2025-02-08 22:09:28 +09:00
Kayne Ruse 7c054db9e6 Compiler now reuses existing strings in the data, read more
If a string exists in the data, instead of being written, the function
'emitCStringToData()' will instead return the address of the match
within the data section.

Then, I can search the jump table for that address, and use the existing
jump entry or append a new one.

Fixes #168
2025-02-08 17:27:47 +11:00