-
Notifications
You must be signed in to change notification settings - Fork 33
Description
The concore wire format is defined implicitly as "whatever Python's ast.literal_eval can parse." Python nodes can exchange nested lists, strings, tuples, dicts, booleans, and mixed-type arrays. The C++ parser() and Verilog literal_eval only handle flat arrays of numeric values they cannot parse any of the following valid concore payloads:
[10.0, "start", 0.5] # string element
[10.0, [0.5, 0.3], [0.1]] # nested list
[10.0, True, 0.5] # boolean
[10.0, (0.5, 0.3)] # tuple
Technical Analysis
C++ parser() (concore.hpp):
vector<double> parser(string f){
vector<double> temp;
f[f.length()-1]=','; // replace ] with ,
for(int i=1;i<f.length();i++){
if(f[i]!=',') value+=f[i];
else temp.push_back(stod(value)); // stod — only parses doubles
}
return temp;
}This splits on commas and calls stod() on every token. A string element like "start" will cause std::invalid_argument from stod, which is caught by a generic catch(...) — silently discarding data.
Verilog literal_eval (concore.v):
datasize = $sscanf(curs,"%c%e%c%e%c%e%c%e...", lb, x0, c00, x1, ...);Uses $sscanf with %e (float) format specifiers and a hardcoded maximum of 10 elements (x0–x9). Cannot handle non-numeric tokens, nested brackets, or more than 9 data elements.
MATLAB concore_read.m:
result = sscanf(clean_str, '%f').'; % only parses floatsSame limitation: sscanf('%f') skips non-numeric tokens.
Proposed Improvement
- Define the concore wire format explicitly as a protocol specification: either "flat numeric arrays only" (lowest common denominator) or "Python list literals" (current implicit standard).
- If flat-numeric-only: add validation in Python's
write()to reject non-numeric payloads with a clear error. - If full-literal: C++ needs a minimal literal parser (at least supporting nested lists and strings), and Verilog needs documented limitations.
- The Julia implementation should validate at write-time that payloads are cross-language-compatible.
Impact
- Reliability: A Python study that works fine breaks silently when one node is ported to C++
- Cross-language: No formal wire format spec compatibility is coincidental
- Julia impl: Must decide parser scope; should enforce write-time validation
- Extensibility: Adding new data types to the protocol is impossible without updating all parsers