Skip to content

Accept MOD, AND, OR, and XOR in function form - #1936

Closed
biaobiao2233 wants to merge 3 commits into
PLC-lang:masterfrom
biaobiao2233:fix/1934-operator-function-form
Closed

biaobiao2233 wants to merge 3 commits into
PLC-lang:masterfrom
biaobiao2233:fix/1934-operator-function-form

Conversation

@biaobiao2233

@biaobiao2233 biaobiao2233 commented Sep 28, 2026 •

Copy link
Copy Markdown

Problem: MOD, AND, OR, and XOR are parsed as keywords, so their function forms are rejected even though the corresponding infix operators work. Parentheses around a lowered call also skipped that lowering.

Solution: Accept keyword calls and lower them through the existing builtin operator handling, preserving infix syntax and contextual result conversions. A parenthesized call uses its ReplacementAst instead of the raw inner node. MOD takes two numeric arguments and returns the first argument's type; AND, OR, and XOR take two or more ANY_BIT arguments, including BOOL. Runtime regressions cover signed and unsigned widening, surrounding expressions, named arguments, mixed-width bit strings, and parenthesized calls, with matching user documentation.

Validation at b6e966d3193 on ARM64 Linux (Rust 1.95.0, LLVM 21.1.8): cargo test --workspace passed with 4,456 passed and 47 ignored; cargo fmt --all --check and cargo clippy --workspace -- -D warnings passed. ./scripts/build.sh --lit passed at both default and none, each with 542 passed, 4 expected failures, and 2 unsupported tests. All 33 independent operator CLI probes passed.

Validation of 1f9c522bd86 on WSL (Rust 1.98.1, LLVM 21), against the current integration tree plus this branch: parenthesized 4 passed, arithmetic_functions 21 passed, and math_operators 98 passed. The full workspace suite, clippy, and lit were not rerun for this commit.

Fixes #1934

Problem: MOD, AND, OR, and XOR are lexer keywords, so RuSTy rejects the IEC function forms MOD(a, b) and AND(x, y) even though the operator forms work.

Solution: Accept those four keywords only as built-in function names and as calls when the next token is '(', and lower them through the existing arithmetic builtin path. Operator forms stay unchanged.
Co-authored-by: Cursor <cursoragent@cursor.com>
biaobiao2233 and others added 2 commits September 28, 2026 18:23
Problem: MOD results can skip the enclosing expression's type conversion,
producing incorrect signed values and arithmetic results. The operator
builtins also conflict with the updated upstream argument handling.

Solution: Apply the contextual conversion after generating a replacement
expression and reuse the upstream argument ordering and type hints. Add
runtime regressions and document the supported calling forms.
Problem: A parenthesized operator function such as (MOD(17, 5)) skips the ReplacementAst, so codegen never applies the lowered operator.

Solution: Generate the replacement expression when the parenthesized inner node has a ReplacementAst. Add runtime regressions for parenthesized ADD, MOD, AND, OR, and XOR.
Co-authored-by: Cursor <cursoragent@cursor.com>
@volsa

volsa commented Sep 30, 2026

Copy link
Copy Markdown
Member

Superseded by #1949

@volsa volsa closed this Sep 30, 2026
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.

MOD, AND, OR, XOR are not accepted in function form

2 participants