29 Commits

Author SHA1 Message Date
Johan B.W. de Vries
6a1f4fc010 Replaces type3 with type5
type5 is much more first principles based, so we get a lot
of weird quirks removed:

- FromLiteral no longer needs to understand AST
- Type unifications works more like Haskell
- Function types are just ordinary types, saving a lot of
  manual busywork

and more.
2025-08-21 19:26:42 +02:00
Johan B.W. de Vries
3cb4860973 Subscriptable is now less hardcoded
Now only the tuple variant is hardcoded. The rest is via
a typeclass.
2025-06-02 19:01:20 +02:00
Johan B.W. de Vries
6f40276a9c Fix: Subscript all dynamic arrays
The type checker would only allow bytes.
2025-06-02 18:06:12 +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
fdaa680572 Cleanup todo 2025-05-21 19:01:15 +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
46b06dbcf1 Cleanup: TYPE_INFO_MAP
This also removes the InternalPassAsPointer experiment.

This also fixes that u8 values were stores as 32 bits
in structs and tuples (but not dynamic arrays since that
is special cased as bytes).

Also, fixes allocation issue wi	th dynamic arrays, it
would allocate quadratic amount of memory.
2025-05-19 21:04:13 +02:00
Johan B.W. de Vries
b5f0fda133 Implements sum for Foldable types
Foldable take a TypeConstructor. The first argument must be a
NatNum.

The FunctionSignatureRouter wasn't completely on point, instead
this commit adds an TypeClassArgsRouter lookup router. This
makes sense since the only available arguments we have to find
a router is the list of type class arguments.
2025-05-12 18:36:37 +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
42cb38d67d Clean up todo list 2025-05-02 21:29:24 +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
d3e38b96b2 Removed the len special casing 2025-04-27 12:37:17 +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
87866cff55 More ideas 2025-04-09 16:02:47 +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
7544055a94 Split Num into NatNum and IntNum
This is because Haskell defines negate, abs and signum
for Num, but they don't work with our unsigned number
types. (abs would be a noop.) Haskell has Word32 / Word64,
but there negate doesn't make much sense to me.

Implemented neg and abs.

Implemented a type class inheritance check.

Removed Integral from u8 and i8 since it wasn't implemented.
2025-04-06 16:12:36 +02:00
Johan B.W. de Vries
111cb0f702 Review 2025-04-06 13:37:12 +02:00
Johan B.W. de Vries
5d9ef0e276 Code review
Added a test, simplified another and added
a lot of TODO's.
2025-04-06 12:58:20 +02:00
Johan B.W. de Vries
e6610a6e96 Adds a todo note 2023-01-29 12:42:38 +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
7a8b1baa25 Some repo cleanup 2022-08-20 18:21:23 +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
b6fb0d45b6 Implements foldl 2022-08-11 19:56:47 +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
451a8e9158 Removes the old ___new_reference___ allocator 2022-08-09 20:42:02 +02:00
Johan B.W. de Vries
a0d575f61f Implements __alloc_bytes__, uses it in the buffer example
Also, updated todo, remove broken code from buffer example
2022-08-09 20:21:59 +02:00
Johan B.W. de Vries
a13713d709 Cleanup to helpers, making use of runners 2022-08-09 19:04:40 +02:00
Johan B.W. de Vries
ac0c49a92c Now runs on new code 2022-06-19 16:54:14 +02:00