Skip to content

Conversation

@emilbon99
Copy link
Contributor

@emilbon99 emilbon99 commented Dec 24, 2025

Issue Pull Request

Linear Issue

SY-####

Description

Basic Readiness

  • I have performed a self-review of my code.
  • I have added relevant tests to cover the changes to CI.
  • I have added needed QA steps to the release candidate template that cover these changes.
  • I have updated in-code documentation to reflect the changes.
  • I have updated user-facing documentation to reflect the changes.

Greptile Summary

Implemented comprehensive string support in Arc, including literals, concatenation, and equality operations across the Go compiler and C++ runtime.

Key Changes:

  • Added string literal parsing with proper escape sequence handling via strconv.Unquote
  • Implemented WASM data section for storing string literal bytes in linear memory
  • Added C++ runtime string operations: string_concat, string_equal, string_len, string_create, string_get
  • Implemented string concatenation (+) and equality (==, !=) operators in Arc expressions
  • Created shared LEB128 encoding utilities to eliminate code duplication
  • Fixed string handle generation to pre-increment counter (avoiding handle 0)
  • Added comprehensive C++ tests for all string operations with edge cases

Issues Found:

  • Critical syntax error in arc/go/compiler/wasm/module.go:171 - incorrect package reference binary.binary.WriteLEB128Unsigned will cause compilation failure

Test Coverage:

  • Excellent C++ runtime test coverage (8 test cases covering normal, edge, and error conditions)
  • Good Go literal parsing tests (10 test cases for various string formats)
  • Missing: No Go compiler tests for string concatenation/equality expressions

Confidence Score: 1/5

  • This PR cannot be merged - contains a critical compilation error that will break the build
  • The syntax error binary.binary.WriteLEB128Unsigned in module.go:171 will cause immediate compilation failure. While the implementation is otherwise solid with good test coverage, this blocking issue prevents the PR from being functional
  • arc/go/compiler/wasm/module.go requires immediate fix before merge

Important Files Changed

Filename Overview
arc/go/compiler/wasm/module.go Added data section support for string literals, but contains critical syntax error (binary.binary.)
arc/cpp/runtime/wasm/bindings.cpp Implemented string operations (concat, equal, len, create, get) with proper handle management
arc/go/compiler/expression/binary.go Added string concatenation (+) and equality (==, !=) operators
arc/go/literal/literal.go Added ParseString function using strconv.Unquote for proper escape handling
x/go/binary/leb128.go New utility for LEB128 encoding (signed and unsigned) used in WASM binary generation

Sequence Diagram

sequenceDiagram
    participant User as Arc Source Code
    participant Parser as Arc Parser
    participant Compiler as Expression Compiler
    participant Module as WASM Module
    participant Runtime as C++ Runtime
    
    User->>Parser: Parse string literal "hello"
    Parser->>Compiler: STR_LITERAL token
    Compiler->>Compiler: ParseString() - unescape & validate
    Compiler->>Module: AddData(bytes) - add to data section
    Module-->>Compiler: Return offset in memory
    Compiler->>Module: Emit i32.const offset
    Compiler->>Module: Emit i32.const length
    Compiler->>Module: Emit call $string_from_literal
    
    Note over User,Runtime: String Concatenation ("a" + "b")
    User->>Compiler: Binary + expression
    Compiler->>Module: Compile left operand (handle1)
    Compiler->>Module: Compile right operand (handle2)
    Compiler->>Module: Emit call $string_concat
    Module->>Runtime: string_concat(h1, h2)
    Runtime->>Runtime: Find strings, concat, create new handle
    Runtime-->>Module: Return new handle
    
    Note over User,Runtime: String Equality ("a" == "b")
    User->>Compiler: Binary == expression
    Compiler->>Module: Compile operands
    Compiler->>Module: Emit call $string_equal
    Module->>Runtime: string_equal(h1, h2)
    Runtime->>Runtime: Compare strings
    Runtime-->>Module: Return 1 or 0
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

14 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

func (m *Module) writeTypeSection() {
var section bytes.Buffer
WriteLEB128(&section, uint64(len(m.types)))
binary.binary.WriteLEB128Unsigned(&section, uint64(len(m.types)))
Copy link

Choose a reason for hiding this comment

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

syntax: binary.binary is incorrect - the import is aliased as binary, so it should just be binary.WriteLEB128Unsigned

Suggested change
binary.binary.WriteLEB128Unsigned(&section, uint64(len(m.types)))
binary.WriteLEB128Unsigned(&section, uint64(len(m.types)))

@emilbon99 emilbon99 force-pushed the sy-3242-implement-string-literal-parsing-in-arc branch from ec5ad7a to 898e1f3 Compare December 24, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants