Skip to content

Implement C++ code writer - #703

Open
adazem009 wants to merge 16 commits into
masterfrom
cpp_code_writer
Open

adazem009 wants to merge 16 commits into
masterfrom
cpp_code_writer

Conversation

@adazem009

@adazem009 adazem009 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #664
Resolves: #665
Resolves: #666

@adazem009
adazem009 marked this pull request as ready for review November 18, 2026 23:05

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 5 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +528 to +532
case ValueType::String:
return "\"" + escapeCppString(value.toString()) + "\"";

default:
throw std::runtime_error("unsupported constant type");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Pointer arguments abort code generation

For blocks such as reset timer, toCppConstant rejects the pointer argument with “unsupported constant type.” compileResetTimer supplies its timer through addConstValue, so generation aborts.

Learn more

The compiler supports pointer constants as references to runtime objects. compileResetTimer records the engine's timer this way. castConstValue preserves that pointer, but createCall then sends it to this serializer, which throws.

Example: Compile a script containing only reset timer. Its sensing_resettimer call has a constant timer pointer and fails before finalization.

Recommended fix: Implement pointer-constant lowering using runtime object references appropriate for generated C++, rather than rejecting ValueType::Pointer. Avoid embedding process-specific addresses if the output must run in another process. Cover timer, target, variable, and list pointer arguments.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

if (value->type() == targetType)
return source;

const CppNamedIdentifier *result = getNamedIdentifier(value, m_valueTypeMap.at(targetType), "castRawValue", false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Conversion destinations alias their source values

For cross-type conversions, getNamedIdentifier returns the source identifier because m_identifiers keys only on the original value. castValue, castRawValue, and raw boxing reuse incompatible representations. Conversion assignments reject immutable sources or overwrite mutable sources.

Learn more

A compiler value can need several generated representations without changing its original value. getNamedIdentifier returns any existing identifier for the compiler value, regardless of the requested type. Consequently the conversion destination is the source itself. The generic-value conversion in castValue and raw boxing in createValue repeat this pattern. Allowing assignments alone does not resolve the aliasing.

Example: A numeric reporter value of 42 needs a boolean argument and later a numeric argument. The conversion destination resolves to the original numeric identifier, so enabling the assignment would replace 42 with 1 instead of preserving 42 and creating a separate boolean temporary.

Recommended fix: Allocate separate mutable conversion temporaries with createNamedIdentifier, or maintain distinct representations keyed by compiler value and destination type. Preserve the source mapping. Test repeated uses of one reporter across multiple argument types, including ValueData boxing.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CppCodeBuilder: constants CppCodeBuilder: function calls Implement C++ code writer

1 participant