Skip to content

Closure types #195

Closed
Closed
@philberty

Description

@philberty

https://doc.rust-lang.org/reference/types/closure.html
https://doc.rust-lang.org/rust-by-example/fn/closures.html
https://doc.rust-lang.org/nomicon/hrtb.html

I think there is stuff in GCC we can take inspiration from the C++ implementation of closures for example:

int test() {
    int capture = 456;
    auto a = [&](int a) -> int {
        return a + capture;
    };
    return a(123);
}

will give us

int test ()
{
  int D.2400;
  int capture;
  struct ._anon_0 a;
  typedef struct ._anon_0 ._anon_0;

  try
    {
      capture = 456;
      a.__capture = &capture;
      D.2400 = test()::<lambda(int)>::operator() (&a, 123);
      return D.2400;
    }
  finally
    {
      capture = {CLOBBER};
      a = {CLOBBER};
    }
}

int test()::<lambda(int)>::operator() (const struct ._anon_0 * const __closure, int a)
{
  int D.2403;
  int & capture [value-expr: __closure->__capture];

  _1 = __closure->__capture;
  _2 = *_1;
  D.2403 = a + _2;
  return D.2403;
}

The task list breaks down into:

I am currently blocked on this until we get lang-item support into the compiler from my operator overloading branch,

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions