1
0
forked from M-Labs/nac3
Commit Graph

175 Commits

Author SHA1 Message Date
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
32746c37be core: Refactor to return errors by HashSet 2023-12-12 15:41:59 +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
ef04696b02 meta: Lift return out of conditional statement 2023-12-11 15:16:23 +08:00
4dc5dbb856 meta: Replace equality assertion with assert_eq
Emits a more useful assertion message.
2023-12-11 15:16:23 +08:00
fd9f66b8d9 meta: Remove redundant casts and brackets 2023-12-11 15:16:23 +08:00
5182453bd9 meta: Remove redundant path prefixes 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
3231eb0d78 core: Add compile-time error and runtime assertion for negative shifts 2023-11-09 12:16:20 +08:00
92d6f0a5d3 core: Implement bitwise not for unsigned ints and fix implementation 2023-11-03 16:24:26 +08:00
50230e61f3 core: Simplify loop condition check for list comprehension 2023-10-06 12:24:03 +08:00
0205161e35 core: Simplify list creation for comprehension 2023-10-06 12:22:38 +08:00
a2fce49b26 core: Allocate exceptions at the beginning of function
Only one instance of exception is necessary, as exceptions will always
be initialized before being thrown.
2023-10-06 12:13:20 +08:00
60a503a791 core: Allocate more stack variables at the beginning of function
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
allocated by different allocas.
2023-10-06 11:42:47 +08:00
0c49b30a90 core: Restore debug info before function call is invoked
Previously, the IR which sets up the call to the target function will
have its debug location pointing at the last argument of the function
call instead of the function call itself.
2023-10-06 11:35:23 +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
480a4bc0ad core: Implement comparison operators for unsigned types 2023-10-05 17:13:10 +08:00
cb39f61e79 core: Fix passing structure arguments to extern functions
All parameters with a structure type in extern functions are marked as
`byref` instead of `byval`, as most ABIs require the first several
arguments to be passed in registers before spilling into the stack.

`byval` breaks this contract by explicitly requiring all arguments to be
 passed in the stack, breaking interop with libraries written in other
 languages.
2023-09-28 15:02:35 +08:00
176f250bdb core: Fix missing conversion to i1 for IfExp 2023-09-28 10:06:40 +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
dd42022633 core: Minor refactor allocate_list 2023-09-22 17:16:29 +08:00
6dfc43c8b0 core: Add name to build_gep_and_load 2023-09-22 17:16:29 +08:00
f1b0e05b3d core: Rename IR variables
Because it is unclear which variables are expressions and
subexpressions, all variables which are previously anonymous are named
using (1) the control flow statement if available, (2) the possible name
of the variable as inferred from the variable name in Rust, and (3) the
"addr" prefix to indicate that the values are pointers. These three
strings are joint together using '.', forming "for.i.addr" for instance.
2023-09-06 14:02:15 +08:00
ff23968544 core: Add name parameter to gen_{var_alloc,store_target}
This allows variables in the IR to be assigned a custom name as opposed
to names with a default prefix.
2023-09-06 11:00:02 +08:00
aead36f0fd update dependencies 2023-03-08 15:19:09 +08:00
c1c45373a6 update dependencies 2023-01-12 19:31:03 +08:00
085c6ee738 update dependencies 2022-11-18 16:15:46 +08:00
a18d095245 nac3core: codegen fix call parameter type error 2022-07-04 14:39:33 +08:00
5d5e9a5e02 nac3core: fix codegen error of inheritance 2022-06-01 17:58:16 +08:00
76473152e8 nac3core: fix llvm.expect intrinsic name
this might be one of the causes for the random segfault bug
2022-05-27 04:23:49 +08:00
325ba0a408 nac3core: add debug info 2022-05-11 03:53:53 +08:00
1eac111d4c cleanup 2022-04-18 15:55:37 +08:00
711c3d3303 nac3core: support custom operators 2022-04-18 15:31:56 +08:00
722e3df086 nac3core, artiq: optimize kernel invariant for tuple index 2022-04-11 14:58:40 +08:00
ad9ad22cb8 nac3core: optimize unwrap KernelInvariant 2022-04-11 14:58:35 +08:00
f66f66b3a4 nac3core, artiq: remove unnecessary ptr casts 2022-04-10 01:28:46 +08:00
0e0871bc38 nac3core, artiq: to_basic_value_enum takes an argument indicating the expected type 2022-04-10 01:28:22 +08:00
c29cbf6ddd nac3core: add bound check for list slice 2022-04-05 18:21:46 +08:00
7443c5ea0f nac3core: add location information to codegen context 2022-04-05 18:21:46 +08:00
710904f975 nac3core: fix powi with negative integer power 2022-04-04 22:10:56 +08:00
2edeb31d21 nac3core: do not get llvm value too eagerly for kernel invariant 2022-03-31 10:28:16 +08:00
6ab73a223c nac3core/artiq: support default param of option type 2022-03-30 04:05:47 +08:00
a38cc04444 nac3core: assert statement 2022-03-29 06:56:40 +08:00
1f5826d352 fix ternary if (#250)
Use store and load to handle if expression as the blocks might be changed when generating sub-expressions.

Reviewed-on: M-Labs/nac3#250
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2022-03-29 06:54:00 +08:00
8d7e300a4a nac3core: do not use const struct for tuple 2022-03-27 10:13:17 +08:00
10d623e36f nac3core/artiq: fix tuple representation 2022-03-27 07:47:14 +08:00
bf067e2481 nac3artiq: implement attribute writeback
We will only writeback attributes that are supported by the current RPC
implementation: primitives, tuple and lists of lists... of primitives.
2022-03-26 20:13:58 +08:00
26a4834254 fix warnings 2022-03-26 18:52:08 +08:00
80631fc92b Option type support (#224)
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2022-03-26 15:09:15 +08:00
1084ba2158 nac3core: fixed typevar with finite range
1. Function type variables should not include class type variables,
   because they are not bound to the function.
2. Defer type variable constraint evaluation until we get all fields
   definition.
2022-03-24 21:31:51 +08:00
2f85bb3837 nac3core: impl call attributes
sret for returning large structs, and byval for struct args in extern
function calls.
2022-03-09 22:09:36 +08:00
f7e62ab5b7 nac3ast/parser/core: use i128 for u64 constants 2022-03-08 18:21:14 +08:00
79c469301a basic unsigned integer support 2022-03-08 13:34:02 +08:00
323d77a455 nac3artiq: improve error message for out of range error 2022-02-28 23:09:14 +08:00
846d1726ef nac3core: fixed keyword arguments handling 2022-02-26 16:34:30 +08:00
f97f93d92c applied rustfmt and clippy auto fix 2022-02-21 18:27:46 +08:00
d9cb506f6a nac3core: refactored for better error messages 2022-02-21 18:24:19 +08:00
14d25b3b9d Fixed broken tests 2022-02-13 17:21:42 +08:00
750d912eb4 nac3core: do list bound check and negative index handling
Raise error when index out of range. Note that we use llvm.expect to
tell the optimizer that we expect not to raise an exception, so the
normal path performance would be better. If this assumption is violated,
the exception overhead might be slightly larger, but the percentage
increase in overhead should not be high since exception unwinding is
already pretty slow.
2022-02-12 22:50:32 +08:00
7ea5a5f84d nac3core: codegen refactoring
- No longer check if the statement will return. Instead, we check if
  the current basic block is terminated, which is simpler and handles
  exception/break/continue better.
- Use invoke statement when unwind is needed.
- Moved codegen for a block of statements into a separate function.
2022-02-12 22:13:59 +08:00
b267a656a8 nac3core: added exception type and fixed primitive representation
- Added `Exception` primitive type and some builtin exception types.
  Note that all exception types share the same layout, and should
  inherit from the base `Exception` type. There are some hacks in the
  toplevel module for handling exception types, we should revisit and
  fix them later.
- Added new primitive types to concrete type module, otherwise there
  would be some weird type errors.
- Changed the representation of strings to CSlice<u8>, instead of
  CString.
2022-02-12 22:13:59 +08:00
050c862c1a nac3core: function codegen callback changes
Added code generator argument to the callback, so it would be easier to
write complicated codegen with that callback. To prepare for RPC
codegen.
2022-02-12 21:24:41 +08:00
77608346b1 nac3core: handle tuple by value 2022-02-07 02:09:50 +08:00
ace0e2a2c6 nac3core: fix use of size_t in list comprehension, cleanup 2022-01-25 03:35:59 +08:00
4976e89ae2 nac3core: list slice support 2022-01-13 16:53:32 +08:00
1ee857de6a nac3core: format, fix clippy warning 2022-01-09 01:12:18 +08:00
4a65d82db5 introduce IRRT, implement power
based on code by Yijia
M-Labs/nac3#160
2022-01-09 00:57:50 +08:00
7193e3f328 nac3core: codegen fix empty list llvm type 2021-12-30 05:09:21 +08:00
1bd966965e fixed M-Labs/nac3#146 2021-12-27 22:56:50 +08:00
fa04768a77 redo "nac3core: fix #84"
This reverts commit 86005da8e1.
2021-12-27 22:56:26 +08:00
86005da8e1 Revert "nac3core: fix #84"
This reverts commit 0902d8adf4.
2021-12-26 08:35:27 +08:00
80d3ab1b0f remove bigints 2021-12-26 00:23:54 +08:00
9e3f75255e update inkwell. Closes #67 2021-12-25 22:17:06 +08:00
0902d8adf4 nac3core: fix #84 2021-12-23 15:26:48 +08:00
4b17511b4a Merge branch 'master' into KernelInvariant 2021-11-27 21:29:27 +08:00
a9635f0979 nac3core: top level use codegen official get_subst_key 2021-11-21 06:11:55 +08:00
f5ec103c82 nac3artiq: kernel invariant support 2021-11-20 21:15:15 +08:00
ba08deada6 nac3core: refactor codegen 2021-11-20 19:50:25 +08:00
8ab3ee9cce nac3core: AugAssign support (#82) 2021-11-13 12:24:22 +08:00
bf7e2c295a integrate nac3parser 2021-11-03 17:11:00 +08:00
47f563908a basic string support (#30) 2021-11-02 23:22:49 +08:00
558c3f03ef nac3core/codegen: list comprehension support 2021-10-24 16:53:43 +08:00
45673b0ecc nac3core/codegen: cleanup 2021-10-24 16:53:43 +08:00
279f47f633 nac3core/codegen: avoid sending unifiers
Previously, we have to copy types from one unification table to another,
and make the table sendable. This requires cloning (processing) the
whole table 3 times per function call which is not efficient and uses
more memory than required when the unification table is large.

We now use a concrete type table to only copy the type we need. This
reduces the overhead as we only need to process the unification table
for once (when we do the function codegen), and reduces memory usage by
a bit (but not noticeable when the unification table is small, i.e. the
types are simple).
2021-10-17 13:02:18 +08:00
1f5bea2448 nac3core/codegen: refactor according to #23 2021-10-16 22:17:36 +08:00
c4259d14d1 fixed some clippy warnings 2021-10-16 18:08:13 +08:00
11144301ca nac3artiq: added simple host value support 2021-10-06 16:07:42 +08:00
f0fdfe42cb nac3core: better impl of #24 2021-09-30 17:07:48 +08:00
d4ed76d76e nac3core: implementing #24 2021-09-26 22:17:09 +08:00
105d605e6d nac3core: fix clippy warnings 2021-09-22 18:04:06 +08:00
084efe92af nac3core: use string interning 2021-09-22 18:04:06 +08:00
1b5ac3cd25 nac3core: do not alloc call if it is monomorphic 2021-09-22 18:04:06 +08:00
4fe643f45b allows function ending with a number 2021-09-22 14:45:42 +08:00
df6c9c8a35 fix #11 2021-09-21 11:29:51 +08:00
dd1be541b8 nac3core: allow class to have no __init__, function/method name with module path added to ensure uniqueness 2021-09-20 23:36:19 +08:00
4939ff4dbd simple implementation of classes 2021-09-19 22:54:06 +08:00
1300b5ebdd nac3core: clean up and format 2021-09-08 19:45:36 +08:00