Skip to content

Support expression-sized array declarations #62

@associate-1

Description

@associate-1

Difficulty: Medium — Parser must accept expressions as array sizes; codegen must emit make() for non-literal sizes since Go arrays require compile-time constants.

Summary

Occam allows array sizes to be arbitrary expressions (typically referencing variables or constants), not just integer literals. Currently the parser only accepts literal integers as array sizes.

Occam syntax

VAL INT max.delay IS 100:
[max.delay]BYTE buffer:

[total - 1]BYTE temp:

Proposed Go mapping

maxDelay := 100
buffer := make([]byte, maxDelay)

temp := make([]byte, total - 1)

Since Go arrays require compile-time constant sizes, expression-sized arrays should map to slices via make().

Affected files

  • sort_inside.occ (lines 309, 333, 336)

Work required

  1. Parser: Parse the array size as a full expression instead of requiring an integer literal
  2. Codegen: When array size is not a literal, generate make([]type, expr) instead of a fixed-size array

Part of #43.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions