75 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
d051160244 Bit shifting 2022-08-16 20:55:20 +02:00
Johan B.W. de Vries
75d7e05519 First uint cast, more options for folding 2022-08-16 20:38:41 +02:00
Johan B.W. de Vries
ad6ca71c53 More bitwise ops. Steps towards CRC32 2022-08-12 21:50:42 +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
a13713d709 Cleanup to helpers, making use of runners 2022-08-09 19:04:40 +02:00
Johan B.W. de Vries
41b47e43d6 Implements RunnerWasmer, makes uses of its wat2wasm 2022-08-07 14:46:20 +02:00
Johan B.W. de Vries
0edd04c207 Adds RunnerWasmtime 2022-08-07 14:12:37 +02:00
Johan B.W. de Vries
58424cf2a0 Adds runner for pywasm 2022-08-06 20:50:43 +02:00
Johan B.W. de Vries
253974df24 Adds runner classes to tests, implements xor for u8, u32, u64 2022-08-06 20:11:39 +02:00
Johan B.W. de Vries
fea817ca00 Added more robust and easy way to generate WASM 2022-08-06 12:43:46 +02:00
Johan B.W. de Vries
e03f038cf9 More work on allocator 2022-08-04 20:51:59 +02:00
Johan B.W. de Vries
b42ae275b9 Start on new allocator 2022-08-04 20:09: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
d32613d9b8 We have a name \o/ 2022-07-09 12:35:32 +02:00
Johan B.W. de Vries
14eede6b06 Cleanup to wasm.py 2022-07-09 12:30:28 +02:00
Johan B.W. de Vries
c181c61040 Extended the import example a bit for sanity's sake 2022-07-09 11:34:20 +02:00
Johan B.W. de Vries
76d80f57cb Imports 2022-07-08 21:06:13 +02:00
Johan B.W. de Vries
374231d206 bytes, u8 types 2022-06-25 20:45:33 +02:00
Johan B.W. de Vries
467d409d80 Add tests for static checks 2022-06-24 21:53:18 +02:00
Johan B.W. de Vries
0da309a280 Remove old code 2022-06-19 17:04:20 +02:00
Johan B.W. de Vries
ac0c49a92c Now runs on new code 2022-06-19 16:54:14 +02:00
Johan B.W. de Vries
9dbdb11732 Simple calls 2022-06-19 15:25:58 +02:00