122 Commits

Author SHA1 Message Date
Johan B.W. de Vries
0953975980 Chore: Placeholders are now internal
They were exposed on AST, causing confusion.
Now they're only used in constraints.
2025-05-05 17:33:21 +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
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
74ab3b47fd Adds Floating type class with sqrt as method 2025-04-06 14:02:45 +02:00
Johan B.W. de Vries
111cb0f702 Review 2025-04-06 13:37:12 +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
4001b086db Cleanup, got rid of OPERATOR_MAP 2025-04-06 12:58:40 +02:00
Johan B.W. de Vries
19a29b7327 Migrated Num 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
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
521171540b Properly implemented test_crc32
Also extended the hack around u8 to u32 cast used
in crc32 - its type was lost, so it would just cast
to whatever the environment was expecting.

Had to do_format_check=False since the file has
some comments and such.
2025-04-05 16:41:46 +02:00
Johan B.W. de Vries
3e916a242e Minor fixes
- Fix python version in docs
- Made a note on which CRC32 we're using in the example
- Removed a redundant parameter
2025-04-05 16:19:26 +02:00
Johan B.W. de Vries
96f52a274c Minor cleanup
- Removed unused stubs
- Removed wabt dependency since wasmtime can compile
  wat2wasm as well.
- Removed wasm2c references, it was never tested.
2025-04-05 16:02:55 +02:00
Johan B.W. de Vries
5c537f712e Project update
Various updates to bring the project uptodate.

- Updated required packages
- Removed runtimes that are not being updated
- wasmtime is for now the only supported runtime
- Implements imports for wasmtime runtime
- Fixes a memory access bug for wasmtime runtime
- compile_wasm is now optional - runtimes have to
  implement and call this themselves
- Typing fixes
- Linting fixes
2025-04-05 15:43:49 +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
20d177e2c5 Add partial tuple of tuple support 2023-11-10 14:00:29 +01:00
Johan B.W. de Vries
a85129254d Adds partial additional debugging info 2023-11-10 12:52:14 +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
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
c02afb05f4 Merge pull request 'Speedup foldl over bytes' (#2) from optimize_fold_bytes_inline_subscript_bytes_call into master
Reviewed-on: #2
2022-08-21 13:39:44 +00:00
Johan B.W. de Vries
5ad5a9c064 Speedup foldl over bytes
Prior to this PR, the compiler would call stdlib.types's
__subscript_bytes__.

However, that function performs some checks we do not need.

After this MR, folding iterates directly over the bytes
memory, saving the memory access checks and the function
calls. This gets us a speedup of about 43% less CPU time
used on Firefox.

Also, by default, the CRC32 page runs a shorter timing test.
2022-08-21 15:38:11 +02:00
2970093c8f Merge pull request 'MVP' (#1) from idea_crc32 into master
Reviewed-on: #1
2022-08-21 12:59:20 +00:00
Johan B.W. de Vries
f683961af8 Timing results
Looks like WebAssembly in Chromium is about 35% faster, but the
Javascript engine in Firefox is another 59% faster
2022-08-21 14:57:43 +02:00
Johan B.W. de Vries
7a8b1baa25 Some repo cleanup 2022-08-20 18:21:23 +02:00