Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

methods cannot be composed in balls #29

Open
disruptek opened this issue Jan 11, 2021 · 1 comment
Open

methods cannot be composed in balls #29

disruptek opened this issue Jan 11, 2021 · 1 comment
Assignees
Labels
wontfix This will not be worked on

Comments

@disruptek
Copy link
Owner

edit: code in the results branch

I'm trying to write the result operator such that the following test works
as you might expect:

  block:
    ## assignment shim with constant
    r = 0
    proc bar(a: int): int {.cps: Cont.} =
      inc r
      noop()
      return a * 2

    proc foo() {.cps: Cont.} =
      inc r
      let x = ... bar(4)  # ie. resolve the continuation
      inc r
      check x == 8

    trampoline foo()
    check r == 3

The ... should resolve the result stashed in the continuation into x.

I get the following error message because my output (a statement list)
does not allow me to raise the method definition to top level. I don't
expect a statement list to be a level, per se, and I don't know how a
macro could ever return more than a single method unless this limit
is lifted.

/home/adavidoff/git/cps/tests/taste.nim(48, 1) template/generic instantiation of `testes` from here
/home/adavidoff/git/cps/tests/taste.nim(539, 31) template/generic instantiation of `cps` from here
/home/adavidoff/git/cps/cps/environment.nim(214, 16) Error: 'method' is only allowed at top level

For clarity, here's a tree dump of the before/after AST.

=== .cps. on bar(original)  === /home/adavidoff/git/cps/tests/taste.nim(539, 6)
ProcDef
  Sym "bar"
  Empty
  Empty
  FormalParams
    Sym "int"
    IdentDefs
      Sym "a"
      Sym "int"
      Empty
  Empty
  Empty
  StmtList
    Command
      Sym "inc"
      Sym "r"
      IntLit 1
    Call
      Sym "noop"
    ReturnStmt
      Asgn
        Sym "result"
        Infix
          Sym "*"
          Sym "a"
          IntLit 2
  Sym "result"
nnkIdentDefs	a: int
storing type env_402657855
next type env_402657858
=== .cps. on bar(transform) === /home/adavidoff/git/cps/tests/taste.nim(539, 6)
StmtList
  MethodDef
    AccQuoted
      Ident "..."
    Empty
    Empty
    FormalParams
      Ident "int"
      IdentDefs
        Ident "continuation"
        Ident "env_402657855"
        Empty
    Pragma
      Sym "cpsLift"
    Empty
    DotExpr
      Call
        Ident "env_402657855"
        Ident "continuation"
      Ident "result_402657854"
  TypeSection
    TypeDef
      Ident "env_402657855"
      Empty
      RefTy
        ObjectTy
          Empty
          OfInherit
            Ident "Cont"
          RecList
            IdentDefs
              Ident "result_402657854"
              Ident "int"
              Empty
            IdentDefs
              Ident "a_402657856"
              Ident "int"
              Empty
  ProcDef
    Ident "afterCall_402657857"
    Empty
    Empty
    FormalParams
      Ident "Cont"
      IdentDefs
        Ident "continuation"
        Ident "Cont"
        Empty
    Pragma
      Sym "cpsLift"
    Empty
    Empty
  ProcDef
    Ident "afterCall_402657857"
    Empty
    Empty
    FormalParams
      Ident "Cont"
      IdentDefs
        Ident "continuation"
        Ident "Cont"
        Empty
    Pragma
      Sym "cpsLift"
    Empty
    StmtList
      CommentStmt "saften at 866 of cps.nim"
      StmtList
        Asgn
          DotExpr
            Call
              Ident "env_402657855"
              Ident "continuation"
            Ident "result_402657854"
          Infix
            Ident "*"
            DotExpr
              Call
                Ident "env_402657855"
                Ident "continuation"
              Ident "a_402657856"
            IntLit 2
        ReturnStmt
          Empty
      CommentStmt "omit return call from nnkStmtList"
  ProcDef
    Ident "bar"
    Empty
    Empty
    FormalParams
      Sym "Cont"
      IdentDefs
        Ident "continuation"
        Sym "Cont"
        Empty
    Pragma
      Ident "cpsCall"
    Empty
    StmtList
      CommentStmt "saften at 539 of taste.nim"
      StmtList
        CommentStmt "saften at 540 of taste.nim"
        Command
          Ident "inc"
          Ident "r"
          IntLit 1
        StmtList
          CommentStmt "re-use the local continuation by setting the fn"
          Asgn
            DotExpr
              Ident "continuation"
              Ident "fn"
            Ident "afterCall_402657857"
          ReturnStmt
            Call
              Ident "noop"
              Ident "continuation"
      CommentStmt "omit return call from nnkStmtList"
  ProcDef
    Ident "bar"
    Empty
    Empty
    FormalParams
      Ident "Cont"
      IdentDefs
        Ident "a"
        Ident "int"
        Empty
    Empty
    Empty
    StmtList
      Asgn
        Ident "result"
        ObjConstr
          Ident "env_402657855"
          ExprColonExpr
            Ident "fn"
            Ident "bar"
          ExprColonExpr
            Ident "a_402657856"
            Ident "a"
@disruptek disruptek changed the title macros can never output more than a single method methods cannot be composed in testes Jan 11, 2021
@disruptek
Copy link
Owner Author

So, yeah, it works if you're not a nimpleton who's trying to write tests using a unittest framework that might move methods out of toplevel because, what the fuck, why not?

@disruptek disruptek transferred this issue from nim-works/cps Jan 11, 2021
@disruptek disruptek self-assigned this Jan 11, 2021
@disruptek disruptek added the wontfix This will not be worked on label Jan 11, 2021
@disruptek disruptek changed the title methods cannot be composed in testes methods cannot be composed in balls May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants