Skip to content

Commit ec7f18a

Browse files
committed
fix: update java stub in init interactive, make DEV-GUIDE.md containing guide for future julia integration for init --interactive
1 parent 6c4f0f4 commit ec7f18a

2 files changed

Lines changed: 129 additions & 8 deletions

File tree

DEV-GUIDE.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Concore Developer Guide
2+
3+
## `concore init --interactive`
4+
5+
The interactive init wizard lets users scaffold a new multi-language concore project without writing any boilerplate by hand.
6+
7+
### Usage
8+
9+
```bash
10+
concore init <project-name> --interactive
11+
# or shorthand
12+
concore init <project-name> -i
13+
```
14+
15+
The wizard prompts for each supported language with a `y/n` question (default: yes):
16+
17+
```
18+
Select the node types to include (Enter = yes)
19+
20+
Include Python node? [Y/n]
21+
Include C++ node? [Y/n]
22+
Include Octave/MATLAB node? [Y/n]
23+
Include Verilog node? [Y/n]
24+
Include Java node? [Y/n]
25+
```
26+
27+
### What gets generated
28+
29+
For each selected language, the wizard:
30+
31+
1. Creates a **source stub** in `src/` with the correct concore API calls for that language.
32+
2. Adds an **unconnected node** to `workflow.graphml`, colour-coded and vertically positioned for easy viewing in yEd.
33+
34+
Example output for Python + Java selected:
35+
36+
```
37+
my_project/
38+
├── workflow.graphml ← 2 unconnected nodes
39+
├── src/
40+
│ ├── script.py ← Python stub
41+
│ └── Script.java ← Java stub
42+
├── README.md
43+
└── STUDY.json
44+
```
45+
46+
### Architecture
47+
48+
The feature lives entirely in `concore_cli/commands/init.py`:
49+
50+
| Symbol | Role |
51+
|---|---|
52+
| `LANGUAGE_NODES` | Dict mapping language key → `label`, `filename`, node `color`, source `stub` |
53+
| `GRAPHML_HEADER` | XML template for the GraphML wrapper; `project_name` is escaped via `xml.sax.saxutils.quoteattr` |
54+
| `GRAPHML_NODE` | XML template for a single node block |
55+
| `run_wizard()` | Prompts y/n for each language; returns list of selected keys |
56+
| `_build_graphml()` | Assembles the full GraphML string from selected languages |
57+
| `init_project_interactive()` | Orchestrates directory creation, file writes, and success output |
58+
59+
---
60+
61+
## Adding a New Language
62+
63+
Adding Julia (or any other language) to the interactive wizard is a **one-file change** — just add an entry to the `LANGUAGE_NODES` dictionary in `concore_cli/commands/init.py`.
64+
65+
### Step-by-step: adding Julia
66+
67+
**1. Add the entry to `LANGUAGE_NODES`** in `concore_cli/commands/init.py`:
68+
69+
```python
70+
"julia": {
71+
"label": "Julia",
72+
"filename": "script.jl",
73+
"color": "#9558b2", # Julia purple
74+
"stub": (
75+
"using Concore\n\n"
76+
"Concore.state.delay = 0.02\n"
77+
"Concore.state.inpath = \"./in\"\n"
78+
"Concore.state.outpath = \"./out\"\n\n"
79+
"maxtime = default_maxtime(100.0)\n"
80+
'init_val = "[0.0, 0.0]"\n\n'
81+
"while Concore.state.simtime < maxtime\n"
82+
" while unchanged()\n"
83+
' val = Float64.(concore_read(1, "data", init_val))\n'
84+
" end\n"
85+
" # TODO: process val\n"
86+
" result = val .* 2\n"
87+
' concore_write(1, "result", result, 0.0)\n'
88+
"end\n"
89+
"println(\"retry=$(Concore.state.retrycount)\")\n"
90+
),
91+
},
92+
```
93+
94+
Key Julia API points (based on real concore Julia scripts):
95+
96+
| Element | Julia equivalent |
97+
|---|---|
98+
| Import | `using Concore` |
99+
| Setup | `Concore.state.delay`, `.inpath`, `.outpath` |
100+
| Max time | `default_maxtime(100.0)` — returns the value |
101+
| Sim time | `Concore.state.simtime` |
102+
| Unchanged check | `unchanged()` — no module prefix |
103+
| Read | `concore_read(port, name, initstr)` — snake\_case, no prefix |
104+
| Write | `concore_write(port, name, val, delta)` — snake\_case, no prefix |
105+
| Type cast | `Float64.(concore_read(...))` to ensure numeric type |
106+
107+
**2. That's it.** No other files need to change — the wizard, GraphML builder, and file writer all iterate over `LANGUAGE_NODES` dynamically.
108+
109+
### Node colours used
110+
111+
| Language | Hex colour |
112+
|---|---|
113+
| Python | `#ffcc00` (yellow) |
114+
| C++ | `#ae85ca` (purple) |
115+
| Octave/MATLAB | `#6db3f2` (blue) |
116+
| Verilog | `#f28c8c` (red) |
117+
| Java | `#a8d8a8` (green) |
118+
| Julia *(proposed)* | `#9558b2` (Julia purple) |
119+
120+
---

concore_cli/commands/init.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,20 @@
154154
"filename": "Script.java",
155155
"color": "#a8d8a8",
156156
"stub": (
157+
"import java.util.List;\n\n"
157158
"public class Script {\n"
158159
" public static void main(String[] args) throws Exception {\n"
159-
" concoredocker cd = new concoredocker();\n"
160160
" double maxtime = 100;\n"
161-
" double delay = 0.02;\n"
162161
' String init_val = "[0.0, 0.0]";\n\n'
163-
" String val = cd.initval(init_val);\n"
164-
" while (cd.simtime() < maxtime) {\n"
165-
" while (cd.unchanged()) {\n"
166-
' val = cd.read(1, "data", init_val);\n'
162+
" // All concore methods are static\n"
163+
" List<Object> val = concore.initVal(init_val);\n"
164+
" while (concore.getSimtime() < maxtime) {\n"
165+
" while (concore.unchanged()) {\n"
166+
' concore.ReadResult r = concore.read(1, "data", init_val);\n'
167+
" val = r.data;\n"
167168
" }\n"
168-
" // TODO: process val\n"
169-
' cd.write(1, "result", val, 0);\n'
169+
" // TODO: process val (List<Object>)\n"
170+
' concore.write(1, "result", val, 0);\n'
170171
" }\n"
171172
" }\n"
172173
"}\n"

0 commit comments

Comments
 (0)