35 Commits

Author SHA1 Message Date
Johan B.W. de Vries
5643c340d2 Notes 2025-08-02 16:17:35 +02:00
Johan B.W. de Vries
38294497cb Moves the prelude to runtime
Previously, it was hardcoded at 'compile' time (in as much
Python has that). This would make it more difficult to add
stuff to it. Also, in a lot of places we made assumptions
about prelude instead of checking properly.
2025-05-29 16:43:37 +02:00
Johan B.W. de Vries
b48260ccfa Removes the special casing for foldl
Now both dynamic and static arrays can be fully fold'ed.

Also adds support for type classes that have a function
argument.

Also, various usability improvements to WasmGenerator.

Also, integration tests now don't dump their stuff without
VERBOSE=1, this speeds up the tests suite by a factor of 9.

Also, tests can now set with_traces to add a number of
tracing functions for help debugging your code.
2025-05-21 18:28:37 +02:00
Johan B.W. de Vries
83186cce78 Reworks bytes into dynamic array
bytes continues to be the preferred name for u8[...].
Also, putting bytes values into the VM and taking them
out still uses Python bytes values.

This also lets used use the len function on them, for
whatever that's worth.
2025-05-18 15:37:13 +02:00
Johan B.W. de Vries
a72bd60de2 Adds functions as passable values 2025-05-17 19:43:52 +02:00
Johan B.W. de Vries
ac4b46bbe7 Fix: You could assign structs to each other
As long as the arguments matched at least.
2025-05-12 20:00:56 +02:00
Johan B.W. de Vries
f8d107f4fa Replaces did_construct with a proper router
By annotating types with the constructor application
that was used to create them.

Later on we can use the router to replace compiler's
INSTANCES or for user defined types.
2025-05-10 16:49:10 +02:00
Johan B.W. de Vries
d9a08cf0f7 Chore: Placeholders are now internal
They were exposed on AST, causing confusion.
Now they're only used in constraints.
2025-05-07 19:07:51 +02:00
Johan B.W. de Vries
bee0c845a8 Removes UnaryOp
It was no longer used.
2025-05-02 21:12:25 +02:00
Johan B.W. de Vries
c8009403c4 Separates out TypeVariable and constraints
They look a lot like placeholders, but they exist before
the typing system takes place. And there's a (much smaller)
context to deal with.

For now, removes Placeholders in user function definitions
as they were not implemented.

Adds signature to function to try to get them closer to
type class methods. Already seeing some benefit in the
constraint generator.

Stricter zipping for safety.
2025-04-27 15:28:08 +02:00
Johan B.W. de Vries
d3e38b96b2 Removed the len special casing 2025-04-27 12:37:17 +02:00
Johan B.W. de Vries
292c9548fb Removes some hardcoded references to prelude 2025-04-27 12:10:27 +02:00
Johan B.W. de Vries
faaf7912b1 Various cleanup to type system
- Make struct into a type constuctor
- Rework placeholders
- Got rid of 'PrimitiveType' as a concept
- Moved out the prelude to its own folder
2025-04-21 16:49:04 +02:00
Johan B.W. de Vries
234bfaa8df Changes AppliedType to TypeConstructor
First to be more in line with how the literature
treats these types. But also to make them workable with
type classes.
2025-04-21 11:14:30 +02:00
Johan B.W. de Vries
20c507a9ec Adds the Bits type class
Also adds the remaining unexposed WebAssembly opcodes as
comments (eqz, clz, ctz, popcnt, copysign).

This also means that BinaryOp.operator is now always
a type class method.
2025-04-09 15:40:20 +02:00
Johan B.W. de Vries
46dbc90475 Implements ceil, floor, trunc, nearest
To round of the f32 / f64 wasm supported opcodes.

This also means we can remove the now outdated
WEBASSEMBLY_BUILTIN_FLOAT_OPS.
2025-04-06 16:38:57 +02:00
Johan B.W. de Vries
74ab3b47fd Adds Floating type class with sqrt as method 2025-04-06 14:02:45 +02:00
Johan B.W. de Vries
be28450658 Converted fractional, fixed integral 2025-04-06 12:58:40 +02:00
Johan B.W. de Vries
ffd11c4f72 Started on a type class system 2025-04-06 12:58:40 +02:00
Johan B.W. de Vries
97b61e3ee1 Test generation framework with typing improvements
Prior to this PR, each type would have its own handwritten
test suite. The end result was that not all types were tested
for all situations.

This PR adds a framework based on a Markdown file, which
generates the basic tests for the types defined in json
files. These are auto generated and updated by the Makefile
before the test suite is run.

Also, a number of unsupported type combinations are now
supported.

Also, we now support negative literals.

Also, allocation calculation fixes for nested types.

Also, the test helpers can now properly import and export
typed variables such as bytes, static arrays and tuples. This
may come in handy when it comes to phasm platform wanting to
route data.

Also, adds better support for i8 type.

Also, started on a runtime.py, since there's quite some code
now that deals with compile time handling of WebAssembly stuff.

Also, minor improvement to the type constrains, namely we
better match 'tuple' literals with static array types.

Also, reduced spam when printing the type analysis results;
constraints that go back on the backlog are now no longer
printed one by one. It now also prints the end results of
the typing analysis.

Also, reorganized the big test_primitives test into type
classes.

Also, replaced pylint with ruff.
2023-11-15 12:52:23 +01:00
Johan B.W. de Vries
fd3939a680 Feat: Use struct in tuple 2023-11-10 15:35:16 +01:00
Johan B.W. de Vries
16ec664cb6 Feature: Tuples with tuples in constants 2023-11-10 15:23:10 +01:00
Johan B.W. de Vries
de92504394 Cleanup: DataBlock as part of the constants
As they can refer to other constants which are stored in
memory.
2023-11-10 15:02:07 +01:00
Johan B.W. de Vries
1536ea0bbb Enable use of bytes in constants
Including using them in tuple constants.
2023-11-10 14:54:22 +01:00
Johan B.W. de Vries
0aa8207987 Import service names 2023-11-07 10:51:55 +01:00
Johan B.W. de Vries
cea236494f Bytes constants 2023-11-07 10:51:43 +01:00
Johan B.W. de Vries
205897101f Adds a typing system to Phasm 2023-01-07 16:24:50 +01:00
Johan B.W. de Vries
e589223dbb Static Arrays. CRC32 compiles \o/
Doesn't give right answer yet and out of bound check fails.
No constructor yet for static arrays, but module constants
work. Which don't work yet for tuples and structs.

Also, u32 for indexing please.

Also, more module constant types.
2022-08-18 20:53:21 +02:00
Johan B.W. de Vries
c4ee2ab3dc Memory initialization is now done during compilation
Also, the user can now define tuple module constants
2022-08-17 21:07:33 +02:00
Johan B.W. de Vries
bac17f47eb ModuleConstant definitions and references 2022-08-16 21:25:03 +02:00
Johan B.W. de Vries
0cf8a246fe Reworked compiler so it uses WasmGenerator
Also, started work on foldl

Also, added a missing FIXME
2022-08-10 20:51:01 +02:00
Johan B.W. de Vries
a83858aca7 Adds u32 and u64
Also, adds some range checks to constants.
2022-07-09 14:22:38 +02:00
Johan B.W. de Vries
89ad648f34 Moved rendering to codestyle, parsing to parser
Also, removed name argument when parsing, wasn't used.
2022-07-09 14:04:40 +02:00
Johan B.W. de Vries
cc762cfa44 Typing is a chapter of its own 2022-07-09 12:48:54 +02:00
Johan B.W. de Vries
d32613d9b8 We have a name \o/ 2022-07-09 12:35:32 +02:00