Commit Graph

66 Commits

Author SHA1 Message Date
23b2fee4e7 standalone: Add test case for ndarray slicing 2024-06-03 16:40:05 +08:00
520e1adc56 core/builtins: Add np_minimum/np_maximum 2024-05-09 15:01:20 +08:00
73e81259f3 core/builtins: Add np_min/np_max 2024-05-09 15:01:20 +08:00
30c6cffbad core/builtins: Refactored numpy builtins to accept scalar and ndarrays 2024-05-06 15:38:29 +08:00
9566047241 standalone: Fix cbrt never tested 2024-05-06 13:21:54 +08:00
847615fc2f core: Implement numpy.matmul for 2D-2D ndarrays 2024-04-23 10:27:37 +08:00
e0f440040c core/expr: Implement negative indices for ndarray 2024-04-15 12:49:42 +08:00
52c731c312 core: Implement Not/UAdd/USub for booleans
Not sure if this is deliberate or an oversight, but we implement it
anyway for consistency with other Python implementations.
2024-04-12 18:29:58 +08:00
00d1b9be9b core: Fix __inv__ for i8-based boolean operands 2024-04-12 15:35:54 +08:00
a920fe0501 core: Implement elementwise comparison operators 2024-04-03 00:07:33 +08:00
727a1886b3 core: Implement elementwise unary operators 2024-04-03 00:07:33 +08:00
6af13a8261 core: Implement elementwise binary operators
Including immediate variants of these operators.
2024-04-03 00:07:33 +08:00
2edc1de0b6 standalone: Update ndarray.py to output all elements in ndarrays 2024-03-07 14:59:13 +08:00
96b7f29679 core: Implement ndarray.fill 2024-03-07 14:59:13 +08:00
22e831cb76 core: Add test for indexing into ndarray 2024-02-19 17:13:10 +08:00
5cecb2bb74 core: Fix Literal use in variable type annotation 2024-02-06 18:16:14 +08:00
fef4b2a5ce standalone: Disable tests requiring return of non-primitive values 2024-01-29 12:49:50 +08:00
c679474f5c standalone: Fix redefinition of ndarray consumer functions 2024-01-17 09:38:13 +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
6dccb343bb Revert "core: Do not keep unification result for function arguments"
This reverts commit f09f3c27a5.
2023-12-18 10:01:23 +08:00
f09f3c27a5 core: Do not keep unification result for function arguments
For some reason, when unifying a function call parameter with an
argument, subsequent calls to the same function will only accept the
type of the substituted argument.

This affect snippets like:

```
def make1() -> C[Literal[1]]:
    return ...

def make2() -> C[Literal[2]]:
    return ...

def consume(instance: C[Literal[1, 2]]):
    pass

consume(make1())
consume(make2())
```

The last statement will result in a compiler error, as the parameter of
consume is replaced with C[Literal[1]].

We fix this by getting a snapshot before performing unification, and
restoring the snapshot after unification succeeds.
2023-12-16 18:40:48 +08:00
457d3b6cd7 core: Refactor generic constants to Literal
Better matches the syntax of `typing.Literal`.
2023-12-16 18:40:48 +08:00
031e660f18 core: Initial implementation for const generics 2023-12-08 18:02:11 +08:00
68b97347b1 core: Infer builtins name list using builtin declaration list 2023-12-08 17:29:34 +08:00
5c5620692f core: Add np_{round,floor,ceil}
These functions are NumPy variants of round/floor/ceil, which returns
floats instead of ints.
2023-11-23 13:45:07 +08:00
0af1e37e99 core: Prefix all NumPy/SciPy functions with np_/sp_spec 2023-11-23 13:35:23 +08:00
d322c91697 core: Change bitshift operators to accept int32/uint32 for RHS operand 2023-11-09 12:16:20 +08:00
fd787ca3f5 core: Remove trunc
The behavior of trunc is already implemented by casts and is therefore
redundant.
2023-11-04 13:35:53 +08:00
4dbe07a0c0 core: Revert breaking changes to round-family functions
These functions should return ints as the math.* functions do instead of
following the convention of numpy.* functions.
2023-11-04 13:35:53 +08:00
9d737743c1 standalone: Add regression test for numeric primitive operations 2023-11-03 16:24:26 +08:00
7e4dab15ae standalone: Add math tests for non-number arguments 2023-11-01 18:03:29 +08:00
2b635a0b97 core: Implement numpy and scipy functions 2023-11-01 18:03:29 +08:00
60ad100fbb core: Implement and expose {isinf,isnan} 2023-11-01 18:03:29 +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
bb5147521f standalone: Fix indentation of test files 2023-11-01 13:20:26 +08:00
c7de22287e core: Fix restoration of stack address
All allocas for temporary objects are now placed in the beginning of the
function. Allocas for on-temporary objects are not modified because
these variables may appear in a loop and thus must be uniquely
represented.
2023-10-06 11:34:23 +08:00
a79286113e standalone: Add output_bool in demo library 2023-10-06 10:19:22 +08:00
2a775d822e core: Demote dead code into a stdout warning 2023-10-04 18:03:25 +08:00
059d3da58b standalone: Add float64 output tests 2023-09-30 09:31:18 +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
b39831b388 standalone: Update demos
- Add `output_str` for printing a string
- Add demo_test.py to test interop
2023-09-28 19:58:53 +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
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
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
17b4686260 standalone: Adapt loop example to output loop variable 2023-09-06 18:56:45 +08:00
8addf2b55e nac3standalone: add more tests 2022-06-01 17:58:16 +08:00
44199781dc nac3standalone: add tests for operators 2022-04-18 15:31:56 +08:00
86ce513cb5 nac3standalone: fix broken test
previously this test unexpectedly passed because it is a slice assignment to extend the list, which is valid in CPython and hence in interpret_demo, and which also happened to give the same output in nac3 by memmove the elements in the list of bool
2022-04-05 18:21:46 +08:00
23b7f4ef18 nac3standalone: add tests for power 2022-04-04 22:10:56 +08:00