Commit Graph

35 Commits

Author SHA1 Message Date
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
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
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
fce71a6cda Tweaked CFLAGS, and fixed related errors 2024-12-12 16:18:41 +11:00
Kayne Ruse
5f75b5f1a3 Allowed for empty arrays and trailing commas 2024-12-10 10:44:13 +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
03dce296cb Assignment target is now an AST node
This will make assigning to arbitrary targets easier.
2024-12-04 19:24:58 +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
431893bf60 WIP: Started on break & continue, needs Toy_Array in Toy_Value first 2024-11-28 13:43:26 +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
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
1608a13b43 Implemented assert keyword, read more
The assert keyword works, but I want to add a cmd option to suppress or
disable the errors.

The tests need some serious TLC. I know that, but I'm kicking it down
the road for now.
2024-11-09 17:41:29 +11:00
Kayne Ruse
1925d41940 Added indexing to strings, tests still needed 2024-11-09 13:10:54 +11:00
Kayne Ruse
7173f7770f Added types and constness
Fixed #144
2024-11-02 11:39:47 +11:00
Kayne Ruse
c5206daaea Implemented scopes 2024-10-27 13:44:09 +11:00
Kayne Ruse
d22b18ed17 Variable access is working 2024-10-26 10:35:47 +11:00
Kayne Ruse
3148a56ce0 Added simple assignment, read more
I was coding earlier this week, but my brain was so foggy I ended up not
knowing what I was doing. After a few days break, I've cleaned up the
mess, which took hours.

Changes:
* Variables can be assigned
* Added new value types as placeholders
* Added 'compare' and 'assign' to the AST
* Added duplicate opcode
* Added functions to copy and free values
* Max name length is 255 chars
* Compound assigns are squeezed into one word

To be completed:

* Tests for this commit's changes
* Compound assignments
* Variable access
2024-10-25 22:48:24 +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
e6fa345fe6 Cleaned up some comments 2024-10-10 09:10:39 +11:00
Kayne Ruse
ca4073a5ae Removed a couple of small optimisations form the parser 2024-10-10 08:18:27 +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
Kayne Ruse
ff13b5cf38 Implemented print keyword and associated tests 2024-10-07 12:13:06 +11:00
Kayne Ruse
ab1c9b941f Added negate opcode to equality opcode, in the second byte 2024-10-03 10:15:58 +10:00
Kayne Ruse
71c065a6c4 Changed size_t to unsigned int 2024-10-02 03:39:38 +10:00
Kayne Ruse
7b453bc35f Reworked generic structures, read more
The following structures are now more independant:

- Toy_Array
- Toy_Stack
- Toy_Bucket
- Toy_String

I reworked a lot of the memory allocation, so now there are more direct
calls to malloc() or realloc(), rather than relying on the macros from
toy_memory.h.

I've also split toy_memory into proper array and bucket files, because
it makes more sense this way, rather than having them both jammed into
one file. This means the eventual hashtable structure can also stand on
its own.

Toy_Array is a new wrapper around raw array pointers, and all of the
structures have their metadata embedded into their allocated memory now,
using variable length array members.

A lot of 'capacity' and 'count' variables were changed to 'size_t'
types, but this doesn't seem to be a problem anywhere.

If the workflow fails, then I'll leave it for tonight - I'm too tired,
and I don't want to overdo myself.
2024-10-01 20:38:06 +10:00
Kayne Ruse
0504f4af8b Began writing Toy_VM, read more
Toy_VM and Toy_Stack are both considered WIP, and neither has any tests
yet.
2024-09-26 17:17:18 +10:00
Kayne Ruse
a2625fa6d4 Implemented tests for Toy_Bytecode and Toy_Routine 2024-09-22 14:13:50 +10:00
Kayne Ruse
4567484038 Squashed: platform support, bugfixes, GH workflows, read more
I've expanded support to three major platforms:

- linux
- windows
- macos

The CI now runs the test suites for all of these, both under normal
conditions and under GDB (except for macos, which lacks GDB support).

TOY_BITNESS specifies the bit-width of the current platform, either 32
or 64. A value of -1 means the bit-width could not be determined. Some
tests will be disabled if the appropriate bit-width can't be determined,
and a warning is printed to stderr.

TOY_API has been tweaked, and is now dependant on different
preprocessor flags. It is defined as 'extern' on all supported
platforms except windows, which instead specifies DLL support. It
defaults to 'extern' if the platform can't be determined.

commit d0350998ecc80b8925a1962ceb2ab400da50be9d
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sun Sep 22 09:55:42 2024 +1000

    Expanded GDB tests using matrix strategy

commit dc2addacc52830227ddcd0f35997c0e1668b579c
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sun Sep 22 09:05:42 2024 +1000

    Reserved the yield keyword

commit f485c380f74a49092e0c5a41e599fbb06dbce235
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 15:17:11 2024 +1000

    Potential segfault fix

commit d8b19d21c92133feb071e631009a3cf99df0f068
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 14:25:47 2024 +1000

    Added testing on windows under GDB, read more

    I'm hunting a segfault that only appears on windows, but I lack a
    windows machine, so github's runners are all I have right now.

commit 8606db541fb5cbe91b16a39e9815fe4a27ba0c8a
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 13:12:02 2024 +1000

    DLL import/export macros tweaked for windows

    TOY_EXPORT for making a DLL
    TOY_IMPORT for using a DLL

    Defaults to 'extern' if neither option is present

commit a6929666401953a5b3a93dfe83c9398e012beefc
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 12:52:06 2024 +1000

    Investigating bitness issue on windows

commit 8f615f735868a316e8d5a6a77ed899e72fd537f8
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 12:32:55 2024 +1000

    Adjusting bitness tests in test_ast.c

commit 61694f2183ac84ee7c53c855f2f6aa29f360f16c
Author: Kayne Ruse <kayneruse@gmail.com>
Date:   Sat Sep 21 11:46:59 2024 +1000

    Added experimental macOS CI job
2024-09-22 11:27:08 +10:00
Kayne Ruse
78320e53bb Multiple bugfixes, read more
* expand() will only touch the memory once
* fixed missing if-else cascade at toy_routine.c:90
* unary negate will not optimise numbers unless the '-' character is immediately prior
* fixed broken test for unary negation of groups
2024-09-20 21:39:02 +10:00
Kayne Ruse
ad6f1c3067 Bytecode and Routine working, Routine tests incomplete
There may be a build issue on windows
2024-09-20 16:22:52 +10:00
Kayne Ruse
e35af3d84b Fixed buffer overflow, bytecode is WIP 2024-09-19 19:06:49 +10:00
Kayne Ruse
083ee950dd WIP bytecode and routine, read more
The tests are failing in a strange way, with the error message 'corrupted top size'. I don't know what it means, and it seems to be caused by a call to printf() within 'test_bytecode.c'. I need a break, as this is making me dizzy.
2024-09-19 12:45:35 +10:00