Commit Graph

108 Commits

Author SHA1 Message Date
51c2175c80 core/codegen/stmt: Convert assertion values to i1 2024-07-19 14:42:14 +08:00
0a732691c9 core: refactor typecheck/magic_methods.rs operators & add op symbol name 2024-07-05 16:27:20 +08:00
075536d7bd core: Add BreakContinueHooks for gen_for_callback 2024-07-04 15:32:18 +08:00
2194dbddd5 core/type_annotation: Refactor List type to TObj
In preparation for operators on lists.
2024-07-04 15:32:18 +08:00
134af79fd6 core: add support for class attributes 2024-06-25 16:06:33 +08:00
23974feae7 meta: Restrict number of allowed lints 2024-06-12 16:10:57 +08:00
40a3bded36 meta: Set clippy lints in {main,lib}.rs
So that this does not have to be manually passed to the `cargo clippy`
command-line every single time. Also allows incrementally addressing
these lints by removing and fixing them one-by-one.
2024-06-12 16:10:57 +08:00
fd36f78005 core: refactor PrimitiveDefinitionId into enum PrimDef 2024-06-12 15:01:01 +08:00
8168692cc3 apply cargo fmt 2024-06-12 14:45:03 +08:00
2d4329e23c core/stmt: Use BB of last statement in if-else in phi 2024-06-11 15:30:06 +08:00
a176c3eb70 core/irrt: Change handle_slice_indices to instead take length of object
So that all other array-like datatypes (e.g. ndarray) can also take
advantage of it.
2024-06-03 16:40:05 +08:00
2cf79510c2 core/numpy: Add more helper functions 2024-06-03 16:40:05 +08:00
588c15f80d core/stmt: Add gen_for_range_callback
For generating for loops over range objects or array slices.
2024-06-03 16:40:05 +08:00
847615fc2f core: Implement numpy.matmul for 2D-2D ndarrays 2024-04-23 10:27:37 +08:00
5dfcc63978 core/classes: Take reference of indexes 2024-04-16 17:20:24 +08:00
025b3cd02f core/stmt: Remove gen_if_chained*
Turns out it is really difficult to get lifetimes and closures right, so
let's just provide the most rudimentary if-else codegen and we can nest
them if necessary.
2024-04-16 17:16:50 +08:00
f0715e2b6d core/stmt: Add gen_if* functions
For generating if-constructs in IR.
2024-04-15 12:20:34 +08:00
e7fca67786 core/stmt: Do not generate jumps if bb is already terminated
Future-proofs gen_*_callback functions in case other codegen functions
will delegate to it in the future.
2024-04-15 12:20:34 +08:00
6af13a8261 core: Implement elementwise binary operators
Including immediate variants of these operators.
2024-04-03 00:07:33 +08:00
3a6c53d760 core/toplevel/numpy: Split ndarray type var utilities 2024-04-03 00:07:33 +08:00
f0da9c0283 core: Add ArrayLikeValue
For exposing LLVM values that can be accessed like an array.
2024-03-22 15:51:06 +08:00
2c4bf3ce59 core: Allow unsized CodeGenerator to be passed to some codegen functions
Enables codegen_callback to call these codegen functions as well.
2024-03-22 15:07:28 +08:00
cfbc37c1ed core: Add gen_for_callback_incrementing
Simplifies generation of monotonically increasing for loops.
2024-03-22 15:07:28 +08:00
c8866b1534 core/classes: Rename get_* functions to remove prefix
As suggested by Rust API Guidelines.
2024-03-21 15:46:10 +08:00
234a6bde2a core: Use TObj for NDArray 2024-03-01 15:41:55 +08:00
49de81ef1e core: Apply clippy suggestions 2024-02-23 15:41:06 +08:00
8492503af2 core: Update cargo dependencies 2024-02-23 15:41:04 +08:00
148900302e core: Add RangeValue and helper functions 2024-01-25 15:51:39 +08:00
5ee08b585f core: Add ListValue and helper functions 2024-01-25 15:51:39 +08:00
140f8f8a08 core: Implement most ndarray-creation functions 2023-12-22 16:29:55 +08:00
27fcf8926e core: Implement ndarray constructor and numpy.empty 2023-12-22 16:29:54 +08:00
c395472094 core: Initial infrastructure for ndarray 2023-12-21 15:39:46 +08:00
b47ac1b89b core: Minor formatting cleanup 2023-12-15 17:46:44 +08:00
a19f1065e3 meta: Refactor to use more let-else bindings 2023-12-12 16:31:14 +08:00
02933753ca core: Apply clippy pedantic changes 2023-12-11 15:16:23 +08:00
d304afd333 meta: Apply clippy suggested changes 2023-12-11 15:16:23 +08:00
c93ad152d7 core: Codegen for ellipsis expression as NotImplemented
A lot of refactoring was performed, specifically with relaxing
expression codegen to return Option in case where ellipsis are used
within a subexpression.
2023-12-08 18:00:51 +08:00
0a84f7ac31 Add CodeGenerator::gen_block and refactor to use it 2023-11-04 13:42:44 +08:00
e95586f61e core: Fix IR generation of for loop containing break/continue
Fix cases where the body BB would have two terminators because of a
preceding continue/break statement already emitting a terminator.
2023-11-01 13:21:27 +08:00
50230e61f3 core: Simplify loop condition check for list comprehension 2023-10-06 12:24:03 +08:00
1a54aaa1c0 core: Restore debug location when generating allocas
Debug location is lost when moving the builder cursor.
2023-10-06 11:11:50 +08:00
48c6498d1f core: Fix restoration of loop target in try statement
old_loop_target is only assigned if ctx.loop_target is overwritten,
meaning that if ctx.loop_target is never overwritten, ctx.loop_target
will always be overwritten to None.

We fix this by only restoring from old_loop_target if we previously
assigned to old_loop_target.
2023-09-28 20:00:02 +08:00
acdb1de6fe meta: Improve documentation for various modified classes 2023-09-25 15:42:07 +08:00
31dcd2dde9 core: Use i8 for boolean variable allocation
In LLVM, i1 represents a 1-byte integer with a single valid bit; The
rest of the 7 upper bits are undefined. This causes problems when
using these variables in memory operations (e.g. memcpy/memmove as
needed by List slicing and assignment).

We fix this by treating all local boolean variables as i8 so that they
are well-defined for memory operations. Function ABIs will continue to
use i1, as memory operations cannot be directly performed on function
arguments or return types, instead they are always converted back into
local boolean variables (which are i8s anyways).

Fixes #315.
2023-09-25 15:42:07 +08:00
6dfc43c8b0 core: Add name to build_gep_and_load 2023-09-22 17:16:29 +08:00
4481d48709 core: Use C-style for loop logic for iterables
Index increment is now performed at the end of the loop body.
2023-09-06 20:09:38 +08:00
b4983526bd core: Remove redundant for.cond BB for iterable loops
Simplifies logic for creating basic blocks.
2023-09-06 20:09:37 +08:00
b4a9616648 core: Add assertion for when range has step of 0
Aligns with the behavior in Python.
2023-09-06 20:09:36 +08:00
e0de82993f core: Preserve value of variable shadowed by for loop
Previously, the final value of the target expression would be one after
the last element of the loop, which does not match Python's behavior.

This commit fixes this problem while also preserving the last assigned
value of the loop beyond the loop, matching Python's behavior.
2023-09-06 20:09:36 +08:00
6805253515 core: Use AST var name for IR name
Aids debugging IR.
2023-09-06 20:09:36 +08:00