Skip to content

Add a block1 operator that returns the values of the first expression and discards the rest. #650

@ghost

Description

The block operator returns the values of the last expression but it is a common pattern to need to return values from other expressions in a block and this current requires the use of local variables. Adding a block1 operator that returns the values of the first expression would allow these pattern to be expressed as expressions without using local variables. The combination of block and block1 allows the results of an arbitrary expression to be returned.

For example to return the values of the second expression in an effective block of expressions the following is currently required:

(block
  (expression1)
  (set_local $v1 (expression2))
  (expression3)
  (get_local $v1))

With a block1 operator this could be:

(block
  (expression1)
  (block1
     (expression2)
     (expression 3)))

When the result expression has multiple values, using local variables in this pattern becomes even more verbose making block1 more compelling.

@sunfishcode Can you see an obvious way for the llvm backend to exploit this?

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