Commit graph

114 commits

Author SHA1 Message Date
Wanda 05cb82b8fc ast: fix const-castable expression handling in Signal(reset=).
The code to accept const-castable expressions was previously added in
0c4fda92fe, but it was untested and had
a few bugs.

Fixes #911.
2023-09-24 02:46:43 +00:00
Catherine 4e078322a0 lib.io: make Pin an interface object.
Tracking #879.

The directions of signals in `Pin` make it convenient to use a pin
signature in a component, such as in:

    class LEDDriver(Component):
        pins: Out(Signature({"o": Out(1)}))

    led_driver = LEDDriver()
    connect(led_driver.pins, platform.request("led"))

The `platform.request` call, correspondingly, returns a flipped `Pin`
object.
2023-09-04 20:48:36 +00:00
Catherine 87fbcedecf lib.wiring: implement Signature.flatten. 2023-09-04 19:05:49 +00:00
Catherine f135226a79 hdl: disallow signed(0) values with unclear semantics.
Fixes #807.
2023-09-03 04:37:59 +00:00
Catherine 21b5451036 ast: ensure Part offset is unsigned.
Co-authored-by: Marcelina Kościelnicka <mwk@0x04.net>
2023-09-03 04:25:08 +00:00
Marcelina Kościelnicka 8c4a15ab92 hdl.mem: lower Memory directly to $mem_v2 RTLIL cell.
The design decision of using split memory ports in the internal
representation (copied from Yosys) was misguided and caused no end
of misery. Remove any uses of `$memrd`/`$memwr` and lower memories
directly to a combined memory cell, currently the RTLIL one.
2023-09-03 03:27:51 +00:00
Catherine f28b20fc84 lib.wiring: ensure flipped(flipped(intf)) is intf. 2023-09-01 05:42:04 +00:00
Catherine 5a17f94fdc hdl.rec: deprecate in favor of lib.data and lib.wiring.
Tracking #879.
2023-09-01 04:20:16 +00:00
Catherine cd4ea96bd1 Implement RFC 19: Remove amaranth.lib.scheduler 2023-09-01 00:56:12 +00:00
Catherine 44d5fac01c lib.wiring: fix equality of FlippedSignature with other object.
Fixes #882.
2023-08-31 19:26:07 +00:00
Catherine f95fe45186 Implement RFC 22: Add ValueCastable.shape().
Fixes #794.
Closes #876.
2023-08-23 10:48:48 +00:00
Catherine 4ffadff20d lib.wiring: implement amaranth-lang/rfcs#2.
Co-authored-by: Charlotte <charlotte@lottia.net>
2023-08-22 16:22:09 +00:00
Marcelina Kościelnicka f6c38061ff lib.data: fix Layout.const masking for signed fields.
Fixes #846.
2023-07-22 00:35:42 +00:00
Catherine d1ca9c46a5 lib.data: allow Const as value of Layout.const(...) field.
Fixes #838.
2023-07-18 14:35:57 +00:00
Catherine 385b10d743 lib.data: improve diagnostics for field access on array layout view.
Fixes #837.
2023-07-18 14:35:49 +00:00
Charlotte 7e438180e0 lib.enum: allow empty enums. 2023-07-04 10:28:22 +00:00
Adam Greig 45b9730786 Implement RFC 6: CRC Generator
See amaranth-lang/rfcs#6 and #681.
2023-06-29 02:42:47 +00:00
Charlotte fd4e25df42 test_sim: failing test case. 2023-06-29 01:28:44 +00:00
Catherine b77e33f16a Drop support for Python 3.7. 2023-06-28 14:50:30 +00:00
Charlotte 59a83cf7eb test_sim: add failing test case for bitwise binary ops.
See https://github.com/amaranth-lang/amaranth/pull/826#event-9609577585.
2023-06-24 06:34:48 +00:00
Charlotte 4ec9cbbffe sim._pyrtl: py3.12+: convert to int before bitwise negating.
Amaranth bitwise negation `~` compiles to Python bitwise negation `~` in
simulation; the same holds for comparison operators such as `==`. Thus
an expression such as `~(a == b)` in simulation will compile to Python
that takes the bitwise negation of the comparison result, which will be
an actual bool.

On 3.12, the result is a `DeprecationWarning` emitted only at simulation
run-time.

When negating in simulation, coerce the value to an int. `mask` is
sufficient as we do no further arithmetic here.
2023-06-22 17:37:30 +00:00
Charlotte 63f9976267 tests.test_sim.SimulatorRegressionTestCase.test_bug_588: fix for Windows paths. 2023-06-22 03:52:55 +00:00
Charlotte d218273b9b hdl.ast: deprecate Repl and remove from AST; add Value.replicate. 2023-06-22 03:52:55 +00:00
Marcelina Kościelnicka b1cce87630 hdl.ast: make Value.__abs__ return unsigned shape. 2023-06-07 23:20:26 +00:00
Marcelina Kościelnicka 1d5e090580 hdl.ast: fix shape for subtraction.
Fixes #813.
2023-06-07 12:34:30 +00:00
Marcelina Kościelnicka 3180a17fd9 hdl.ast: fix Slice validation.
Fixes #810.
2023-06-07 12:26:36 +00:00
Marcelina Kościelnicka c7984463c7 hdl.ast: fix range handling in Shape.cast.
Fixes #803.
2023-06-07 12:26:30 +00:00
Marcelina Kościelnicka a6e33abc5f hdl.ast: guard rotate_* against 0-width values.
Fixes #808.
2023-06-07 12:12:24 +01:00
Marcelina Kościelnicka 656db317d2 hdl.ast: fix signed Const normalization.
Fixes #805.
2023-06-07 11:22:52 +01:00
Catherine a4402b507f hdl.dsl: py3.12+: turn off heuristic warning on ~True and ~False.
There is now an upstream deprecation warning for the same.
We don't have to duplicate it.
2023-06-02 13:45:15 +01:00
Catherine 58b8acac0d _toolchain.cxx: remove.
This is causing issues on Python 3.12 and in any case should be
based on the Python `ziglang` package instead of this cursed
setuptools hack.
2023-06-02 13:45:15 +01:00
Marcelina Kościelnicka c343e879d3 tracer: fix STORE_DEREF handling, add EXTENDED_ARG support.
This fixes the following issues:

- on Python 3.10 and earlier, storing to free variables is now handled
  correctly
- on Python 3.11, `_varname_from_oparg` is now used, fixing problems
  with cell variables that are also arguments
- on all supported versions, EXTENDED_ARG is now parsed, ensuring proper
  handling for long functions

Fixes #792.
2023-06-01 19:18:43 +01:00
Catherine 2a45d0e9ad lib.data: warn if a field is shadowed by an attribute of the view.
Fixes #796.
2023-05-31 13:27:20 +01:00
Catherine f96604f667 lib.data: make all layouts immutable.
This is actually an existing correctness requirement (for the similar
reasons that ValueCastable.as_value() must always return the same
value every time) that for some reason wasn't respected.
2023-05-23 23:19:29 +01:00
Catherine 7d99981d57 Implement RFC 15: Lifting shape-castable objects.
See amaranth-lang/rfcs#15 and #784.

Note that this RFC breaks the existing syntax for initializing a view
with a new signal. Instances of `View(layout)` *must* be changed to
`Signal(layout)`.
2023-05-15 19:42:12 +01:00
Catherine 54d5c4c047 Implement RFC 9: Constant initialization for shape-castable objects.
See amaranth-lang/rfcs#9 and #771.
2023-05-12 23:41:57 +01:00
Catherine 7166455a6a lib.data: implement extensibility as specified in RFC 8.
See amaranth-lang/rfcs#8 and #772.
2023-05-12 20:03:08 +01:00
Catherine 4398575322 lib.enum: accept any const-castable expression as member value.
This behavior was introduced by amaranth-lang/rfcs#4. See #755.
2023-05-12 16:39:02 +01:00
Catherine bf8bbb0f63 lib.enum: check member value shapes before subclassing. NFCI
This commit is a preparation for accepting const-castable expressions
as enum member values.

See #755.
2023-05-12 16:39:02 +01:00
Arusekk 5f094a23eb hdl.ast: Test *Castable subclasses on definition.
The __init_subclass__ method fires on class definition rather than use.
It also has the bonus impact that no __new__ method is defined, so the
classes can be correctly detected as mix-in classes by modules such as
enum.
2023-03-21 23:22:47 +00:00
Catherine 80343d1c4c hdl.ast: warn on fencepost error in Signal(range(x), reset=x).
Also, relax the language reference inset from "warning" to "note"
since this is no longer something developers have to keep in mind
explicitly.
2023-03-13 20:38:41 +00:00
Catherine ae1aeff0f2 lib.data: at most one Union field can have annotation with a default. 2023-03-04 09:34:50 +00:00
Catherine 16be75e02c lib.data: fix typo. 2023-03-03 09:03:53 +00:00
Catherine 0c4fda92fe hdl.ast: accept any constant-castable expression in Signal(reset=).
See amaranth-lang/rfcs#4.

This functionality was not explicitly specified in the RFC but it
falls under "anywhere an integer or an enumeration is accepted".
2023-03-03 06:22:56 +00:00
Catherine f77a335abf lib.enum: change shape mismatch warning category to SyntaxWarning. 2023-03-03 06:14:53 +00:00
Catherine c1b9c64e10 lib.data: ignore Python typing annotations in aggregate base class. 2023-03-03 03:45:12 +00:00
Catherine 14e73a73de hdl.ast: do not cast comparand to shape in Shape.__eq__.
This doesn't match how other Python comparison operators work.
E.g. `1 == int("1")` but `1 != "1"`.
2023-02-28 15:52:50 +00:00
Catherine 35561ea11a lib.data: improve reset value handling for Union.
* Reject union initialization with more than one reset value.
* Replace the reset value specified in the class definition with
  the one provided during initalization instead of merging.
2023-02-28 15:38:20 +00:00
Catherine c7ef05c894 lib.data: improve annotation handling for Struct and Union.
* Annotations like `s: unsigned(4) = 1` are recognized and
  the assigned value is used as the reset value for the implicitly
  created `Signal`.
* Base classes inheriting from `Struct` and `Union` without
  specifying a layout are recognized.
* Classes that both inherit from a base class with a layout and
  specify a layout are rejected.
2023-02-28 15:38:18 +00:00
Catherine 0ee5de036c hdl.ast: deprecate Sample, Past, Rose, Fell, Stable.
See #526.
2023-02-28 14:30:04 +00:00