tcr / corollary

Cross-compiler from Haskell to Rust, plus parser-haskell.
73 stars 5 forks source link

Rework AST #59

Closed pshc closed 7 years ago

pshc commented 7 years ago

I had a lot of free time on my hands yesterday (5 hour plane ride) and while trying to knock out some smaller bugs I noticed we have structural AST issues. Not sure yet if I made it better or worse.

tcr commented 7 years ago

This list would handle a lot of the remaining edge cases, so thank you for tackling them!

The whitespace logic is obviously throwing a wrench in these fixes, and I actually dealt with these issues before. The unsatisfactory result was parsing "where" clauses as any old statement and asserting that they are the last statement, but this prevents successive let clauses or let ... in from being parsed right. I think this PR is a step in the right direction, I'll try to review more in depth tomorrow.

tcr commented 7 years ago

The let ... where ... wrapArgv issue looks slightly worse, the let statement seems to only encapsulate one statement:


     ;let{ ret = Rust.VarName "cmV0"
      };emitItems [Rust.Item [] Rust.Private (
         Rust.Function [] "bWFpbg==" [] (Rust.TypeName "KCk=") (statementsToBlock (
             setup ++
             [ bind Rust.Immutable ret $
                 Rust.UnsafeExpr $ Rust.Block [] $ Just $
                 call realName args ] ++
             exprToStatements (call "OjpzdGQ6OnByb2Nlc3M6OmV4aXQ=" [Rust.Var ret])
         )))]
     }where{

        bind mut var val = Rust.Let mut var Nothing (Just val)

         ;call fn args = Rust.Call (Rust.Var (Rust.VarName fn)) args

         ;chain method args obj = Rust.MethodCall obj (Rust.VarName method) args

     }wrapArgv [] = return ([], [])

I'm unsure how it parses on master, I should check that next. (This was generated by uncommenting the two lines in test_no_regressions that write out test.txt.)

pshc commented 7 years ago

Forgive me if I'm wrong but I think let { ret = Rust.VarName "cmV0" }; is correct?

pshc commented 7 years ago

What I'm wondering is why we get

Error: Unrecognized token `wrapArgv`:
774 |
775 |
776 |      }wrapArgv [] = return ([], [])

does there need to be a semicolon before wrapArgv or something?

pshc commented 7 years ago

Rebased on master. Time for another long plane ride.

tcr commented 7 years ago

Yes, you're right. (I need to pick up a book...) I believe it's a bug in the LHS stripper. Looking into it now.

tcr commented 7 years ago

Fixed the wrapArgv issue! (see 36a155b) I tried to knock out the rest of your list also, feel free to restructure any of those solutions.

There's only three or so remaining issues before this PR passes tests again. Can't wait to have proper let and where output in the generated code.

tcr commented 7 years ago

Passes tests. Merge whenever you're inclined to.

pshc commented 7 years ago

Whoaaa! Awesome! 🥇