150 Commits

Author SHA1 Message Date
Johan B.W. de Vries
36405d110b 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-19 16:52:07 +02:00
Johan B.W. de Vries
1a3bc19dce Fix linting issues 2025-06-07 14:38:54 +02:00
Johan B.W. de Vries
544bbfac72 Updates the README for clarity 2025-06-07 14:00:03 +02:00
Johan B.W. de Vries
8a1a6af3e7 Reworked the examples to be more welcoming 2025-06-05 19:49:07 +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
d97be81828 Optimise: Remove unused functions
By default, we add a lot of build in functions that may
never get called.

This commit adds a simple reachability graph algorithm
to remove functions that can't be called from outside.

Also, unmarks a lot of functions as being exported. It
was the default to export - now it's the default to not
export.

Also, some general cleanup to the wasm statement calls.
2025-05-25 16:39:25 +02:00
Johan B.W. de Vries
84e7c42ea4 Implements u16 / i16 support
Keep in mind that WebAssembly is u32 native by default,
some operations may be more expensive than you expect
them to be.
2025-05-25 15:31:23 +02:00
Johan B.W. de Vries
d017ebe096 Support tail calls 2025-05-25 14:42:31 +02:00
Johan B.W. de Vries
2c2a96c8a7 Added some more missing test cases for promotable 2025-05-25 14:21:25 +02:00
Johan B.W. de Vries
b670bb02ad Exposes Wasm's convert and trunc(ate) function
Also adds a missing type case for promotable
2025-05-25 14:13:46 +02:00
Johan B.W. de Vries
56ab88db2c Exposes Wasm's reinterpret function 2025-05-25 13:45:18 +02:00
Johan B.W. de Vries
cfdcaa230d Added a missing type check test 2025-05-21 19:22:45 +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
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
99d2b22336 Moved the typeclasse tests. Fix typeclass name. 2025-05-17 18:42:27 +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
67af569448 Cleanup CanBeSubscriptedConstraint
It was using an AST argument, and I'd rather not have those
in the typing system (except the generator).
2025-05-12 19:20:50 +02:00
Johan B.W. de Vries
df5c1911bf Cleans up imports
Rather than accessing the classes from the module, this MR
cleans up the code a bit to use the classes directly.
2025-05-12 18:51:19 +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
6c627bca01 Reworks function lookup
Before this commit, finding the implementation for a type
class method was done with a simple lookup table.

This commit adds a router based on function signature.
This also paves the way for adding type constructor
arguments in function signatures.

And it removes quite a few references to the prelude out
of the compiler.

Also adds a bunch of helper methods to render signatures
as strings.
2025-05-10 19:42:17 +02:00
Johan B.W. de Vries
78c98b1e61 Fix: Type error
That's what I get for cleaning up without running tests.

This removes a intermediate hack to detect missing routes.
2025-05-10 16:51:38 +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
6b66935c67 Chore: Cleanup type checks
A lot of isinstance checks no longer did anything, since
the referred to variable was always a type.

In some places, we used it to check if a type was internal,
it's unclear if we will need to rebuild those checks in
the future.
2025-05-07 19:07:55 +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
f6cb1a8c1d Adds a FIXME for accessing non-struct members 2025-05-05 12:35:49 +02:00
Johan B.W. de Vries
45c38d5f88 Fix: function comment that's no longer true 2025-05-05 12:26:15 +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
44b95af4ba Removes the cast / u32 hacky way of casting. 2025-05-02 21:12:05 +02:00
Johan B.W. de Vries
1da1adac9f Implements Extendable and Promotable 2025-05-02 21:05:07 +02:00
Johan B.W. de Vries
a2e1dfd799 Reworks type class instantiation
Before, a type class was a property of a type.
But that doesn't make any sense for multi parameter
type classes.

Had to make a hacky way for type classes with
type constructors.
2025-04-27 17:45:13 +02:00
Johan B.W. de Vries
11fde4cb9e Add missing fix for generator 2025-04-27 15:30:17 +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
d6b483581b Merge pull request 'Changes AppliedType to TypeConstructor' (#7) from replace-applied-type-by-type-constructors into master
Reviewed-on: #7
2025-04-21 09:22:35 +00: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
99e407c3c0 Adds arithmetic shift shift
"An arithmetic shift is usually equivalent to
multiplying the number by a positive or a negative
integral power of the radix." -- Federal Standard 1037C

"This is the same as multiplying x by 2**y."

"A right shift by n bits is defined as floor division
by pow(2,n). A left shift by n bits is defined as
multiplication with pow(2,n)."
2025-04-09 14:23:51 +02:00
Johan B.W. de Vries
da381e4a48 Made Integral use Python's operators
Rather than Haskell's div and rem methods, we use the
Python operators since these are often used. And we have
as goal to make it 'look like Python'
2025-04-09 13:16:50 +02:00
Johan B.W. de Vries
94c8f9388c Implements the Ord type class 2025-04-09 12:44:32 +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
9bc8d94ffd Implements != 2025-04-06 16:20:01 +02:00