Skip to content

Commit c6f9499

Browse files
committed
Update for Amaranth v0.5.0.
Also, make the demo code per-version, and update it when switching between versions if it is an exact match for whichever version was the previously selected one.
1 parent 6c04620 commit c6f9499

File tree

4 files changed

+74
-30
lines changed

4 files changed

+74
-30
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/d3": "^7.4.3",
2929
"@types/react": "^18.2.55",
3030
"@types/react-dom": "^18.2.19",
31-
"@yowasp/yosys": "^0.39.37-dev.676",
31+
"@yowasp/yosys": "^0.42.733",
3232
"d3-wave": "^1.1.5",
3333
"esbuild": "^0.20.0",
3434
"monaco-editor": "^0.46.0",

src/app.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function AppContent() {
7878
const [amaranthSource, setAmaranthSource] = useState<string>(
7979
query?.s
8080
?? localStorage.getItem('amaranth-playground.source')
81-
?? data.demoCode);
81+
?? data.demoCode[amaranthVersion]);
8282
useEffect(() => localStorage.setItem('amaranth-playground.source', amaranthSource), [amaranthSource]);
8383
const [pythonOutput, setPythonOutput] = useState<TerminalChunk[] | null>(null);
8484
const [pythonOutputWasNull, setPythonOutputWasNull] = useState(true);
@@ -94,10 +94,17 @@ function AppContent() {
9494
useEffect(() => { verilogProductEditorState.current.text = verilogProduct ?? ''; }, [verilogProduct]);
9595

9696
function loadDemoCode() {
97-
amaranthSourceEditorState.current.text = data.demoCode;
97+
amaranthSourceEditorState.current.text = data.demoCode[amaranthVersion];
9898
setActiveTab('amaranth-source');
9999
}
100100

101+
function setAmaranthVersionAndUpdateDemoCode(newAmaranthVersion: string) {
102+
const wasDemoCode = (amaranthSourceEditorState.current.text == data.demoCode[amaranthVersion]);
103+
setAmaranthVersion(newAmaranthVersion);
104+
if (wasDemoCode)
105+
amaranthSourceEditorState.current.text = data.demoCode[newAmaranthVersion];
106+
}
107+
101108
function completeTutorial() {
102109
setTutorialDone(true);
103110
setActiveTab('amaranth-source');
@@ -429,7 +436,7 @@ function AppContent() {
429436
sx={{ borderRadius: 10 }}
430437
variant='outlined'
431438
value={amaranthVersion}
432-
onChange={(_event, value) => setAmaranthVersion(value as string)}
439+
onChange={(_event, value) => setAmaranthVersionAndUpdateDemoCode(value as string)}
433440
>
434441
{data.amaranthVersions.map((version) =>
435442
<Option key={version} value={version}>Amaranth {version}</Option>)}

src/config.ts

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
export default {
2-
amaranthVersions: ['v0.4.5', 'v0.4.4', 'v0.4.3', 'v0.4.2'],
3-
pythonPackages: {
4-
'v0.4.5': [
5-
'https://files.pythonhosted.org/packages/98/8d/a0d8fb2b9611f3ae22ddc98890b346833fa2c645ad21fd282e61ccdad477/pyvcd-0.4.0-py2.py3-none-any.whl',
6-
'https://files.pythonhosted.org/packages/1a/bf/cff5c705f2f5978889e1fa0fc2a70e0fadbb9f2a51db2d3315c3bda7c3ea/amaranth-0.4.5-py3-none-any.whl',
7-
],
8-
'v0.4.4': [
9-
'https://files.pythonhosted.org/packages/98/8d/a0d8fb2b9611f3ae22ddc98890b346833fa2c645ad21fd282e61ccdad477/pyvcd-0.4.0-py2.py3-none-any.whl',
10-
'https://files.pythonhosted.org/packages/ee/66/bbb766873059d8051ddb7e760de80beefd286979bc9a786e7ec4ac524336/amaranth-0.4.4-py3-none-any.whl',
11-
],
12-
'v0.4.3': [
13-
'https://files.pythonhosted.org/packages/98/8d/a0d8fb2b9611f3ae22ddc98890b346833fa2c645ad21fd282e61ccdad477/pyvcd-0.4.0-py2.py3-none-any.whl',
14-
'https://files.pythonhosted.org/packages/72/34/82f76a59f4155e26f42cf9f9d04d80befe774aa8af6d9b6e48d3e7b9f060/amaranth-0.4.3-py3-none-any.whl',
15-
],
16-
'v0.4.2': [
17-
'https://files.pythonhosted.org/packages/98/8d/a0d8fb2b9611f3ae22ddc98890b346833fa2c645ad21fd282e61ccdad477/pyvcd-0.4.0-py2.py3-none-any.whl',
18-
'https://files.pythonhosted.org/packages/27/1c/39881fbd48f9de91d64955f206a7f32fd912d306d18e8c5f74126ee5962f/amaranth-0.4.2-py3-none-any.whl',
19-
],
20-
},
21-
demoCode: `\
1+
const rfc3986_2_0_0 = 'https://files.pythonhosted.org/packages/ff/9a/9afaade874b2fa6c752c36f1548f718b5b83af81ed9b76628329dab81c1b/rfc3986-2.0.0-py2.py3-none-any.whl';
2+
const jschon_0_11_1 = 'https://files.pythonhosted.org/packages/ce/b1/31f454a2ac0d23b0a47283d115f0af4abe2a1ea391f5ccb223e02d685b82/jschon-0.11.1-py3-none-any.whl';
3+
const pyvcd_0_4_0 = 'https://files.pythonhosted.org/packages/98/8d/a0d8fb2b9611f3ae22ddc98890b346833fa2c645ad21fd282e61ccdad477/pyvcd-0.4.0-py2.py3-none-any.whl';
4+
const amaranth_0_4_2 = 'https://files.pythonhosted.org/packages/27/1c/39881fbd48f9de91d64955f206a7f32fd912d306d18e8c5f74126ee5962f/amaranth-0.4.2-py3-none-any.whl';
5+
const amaranth_0_4_3 = 'https://files.pythonhosted.org/packages/72/34/82f76a59f4155e26f42cf9f9d04d80befe774aa8af6d9b6e48d3e7b9f060/amaranth-0.4.3-py3-none-any.whl';
6+
const amaranth_0_4_4 = 'https://files.pythonhosted.org/packages/ee/66/bbb766873059d8051ddb7e760de80beefd286979bc9a786e7ec4ac524336/amaranth-0.4.4-py3-none-any.whl';
7+
const amaranth_0_4_5 = 'https://files.pythonhosted.org/packages/1a/bf/cff5c705f2f5978889e1fa0fc2a70e0fadbb9f2a51db2d3315c3bda7c3ea/amaranth-0.4.5-py3-none-any.whl';
8+
const amaranth_0_5_0 = 'https://files.pythonhosted.org/packages/d3/34/8a21cc1765f1952eb35766cf76ec8a1b3e73f32ae78d9bf1c1a88313bdcd/amaranth-0.5.0-py3-none-any.whl';
9+
const pythonPackages = {
10+
'v0.5.0': [rfc3986_2_0_0, jschon_0_11_1, pyvcd_0_4_0, amaranth_0_5_0],
11+
'v0.4.5': [pyvcd_0_4_0, amaranth_0_4_5],
12+
'v0.4.4': [pyvcd_0_4_0, amaranth_0_4_4],
13+
'v0.4.3': [pyvcd_0_4_0, amaranth_0_4_3],
14+
'v0.4.2': [pyvcd_0_4_0, amaranth_0_4_2],
15+
};
16+
17+
const demoCode_0_4 = `\
2218
from amaranth import *
2319
from amaranth.sim import Simulator, Tick
2420
from amaranth.back import rtlil, verilog
@@ -46,5 +42,46 @@ with amaranth_playground.show_waveforms(sim):
4642
4743
amaranth_playground.show_verilog(verilog.convert(m, ports=[count]))
4844
# amaranth_playground.show_rtlil(rtlil.convert(m, ports=[count]))
49-
`,
45+
`;
46+
const demoCode_0_5 = `\
47+
from amaranth import *
48+
from amaranth.sim import Simulator
49+
from amaranth.back import rtlil, verilog
50+
import amaranth_playground
51+
52+
53+
en = Signal()
54+
count = Signal(4)
55+
m = Module()
56+
with m.If(en):
57+
m.d.sync += count.eq(count + 1)
58+
m.d.comb += en.eq(count < 5)
59+
60+
61+
async def testbench(ctx):
62+
for _ in range(10):
63+
await ctx.tick()
64+
print(f"count: {ctx.get(count)}")
65+
66+
sim = Simulator(m)
67+
sim.add_clock(1e-6)
68+
sim.add_testbench(testbench)
69+
with amaranth_playground.show_waveforms(sim):
70+
sim.run()
71+
72+
amaranth_playground.show_verilog(verilog.convert(m, ports=[count]))
73+
# amaranth_playground.show_rtlil(rtlil.convert(m, ports=[count]))
74+
`;
75+
const demoCode = {
76+
'v0.5.0': demoCode_0_5,
77+
'v0.4.5': demoCode_0_4,
78+
'v0.4.4': demoCode_0_4,
79+
'v0.4.3': demoCode_0_4,
80+
'v0.4.2': demoCode_0_4,
81+
};
82+
83+
export default {
84+
amaranthVersions: Array.from(Object.keys(pythonPackages)),
85+
pythonPackages,
86+
demoCode,
5087
};

0 commit comments

Comments
 (0)