Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions translation_issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation Issues Found

This report documents issues found when transpiling five test files from to V using the CLI.

## Files Transpiled
1. `test_match_pattern.py`
2. `test_walrus.py`
3. `test_fstrings_312.py`
4. `test_any_all.py`
5. `test_aug_assign.py`

---

## 1. test_match_pattern.py

### Issues Found:
- **Missing Imports**: The generated V code uses `py2v_transpiler.core.parser.PyASTParser()` and `ast.py_Module`, but neither `py2v_transpiler` nor `ast` modules are imported in the V file.
- **Dynamic Type Check (`is`)**: The use of `if !tree is ast.py_Module` assumes that `ast.py_Module` is a valid V type at that point, which it isn't without proper module mapping or definition.
- **Exception Handling**: Uses `vexc.raise`, which is part of the non-idiomatic `div72.vexc` approach.

---

## 2. test_walrus.py

### Issues Found:
- **String Interpolation in println**: The transpiler correctly uses `println('${x}')`. No major issues found here, though complex walrus expressions in `while` loops are transformed into a `for { ... }` block with a break, which is idiomatic for V but might be complex to read.

---

## 3. test_fstrings_312.py

### Issues Found:
- **C.try() and vexc**: Uses `if C.try() { ... } else { ... }` for Python's `try/except` blocks. This requires `div72.vexc` and C interop, which is not idiomatic V.
- **Nested F-Strings**: Transpiles `f"Val: {f'nested {x}'}"` to `'Val: ${\"nested ${x}\"}'`. While V supports some interpolation, double nested interpolations with quotes might be tricky for the V compiler depending on the version.
- **Missing Helper Reference**: In `test_fstring_312_debug`, it asserts `println('x=${py_repr(x)}')`, but `py_repr` is not defined in the generated `*_helpers.v` file (based on the `cat` output, it was missing in the emitted helpers).

---

## 4. test_any_all.py

### Issues Found:
- **Missing Imports**: Similar to `test_match_pattern.py`, it uses `py2v_transpiler.core.parser.PyASTParser()` and `ast.py_Module` without imports.
- **Native Method Assumption**: Transpiles `any(a)` to `a.any(it)`. This assumes that the V array type has an `.any()` method or that a suitable extension method is provided. V's standard library arrays do NOT have `.any()` or `.all()` by default (they use `.any()` in some experimental/iter modules, but not on standard arrays without helper injection). However, no such helper was found in the `*_helpers.v` file.

---

## 5. test_aug_assign.py

### Issues Found:
- **Math Module**: Correctly identifies the need for `import math` when using `**=`, but relies on the transpiler to inject this into the V file.
- **Cast to int**: For `x **= 3` where `x` is an int, it generates `x = int(math.pow(x, 3))`. This is correct for V since `math.pow` returns `f64`.
- **Complex Subscripts**: Uses `py_aug_tmp_1 := f()` to avoid side effects when evaluating the target of an augmented assignment. This is a good implementation of Python's behavior.

---

## General Observations (Across all files)

1. **Helper Completeness**: Many "built-in" Python functions (like `any`, `all`, `py_repr`) are transpiled to V method calls or helper calls that are not actually present in the generated `*_helpers.v` file.
2. **Module Mapping**: The transpiler often leaves Python-specific module paths (like `py2v_transpiler.core.parser`) in the V code, which will not compile in V.
3. **V-Idiomatic Error Handling**: The use of `C.try()` and `vexc` remains a significant hurdle for idiomatic V code generation.
4. **LLM Markers**: The transpiler correctly inserts `//##LLM@@` warnings for known limitations like `try/except` or complex formatting.
Loading