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

C: Properly implement defined rules using the empty list. #365

Closed
wants to merge 1 commit into from

Conversation

shlevy
Copy link
Contributor

@shlevy shlevy commented Apr 30, 2021

Part of #363.

@andreasabel
Copy link
Member

andreasabel commented Apr 30, 2021

Thanks.
My suggestion would be to generalize Exp in CF.hs to

type Exp = Exp' String
data Exp' f
  = App f [Exp]       -- ^ (Possibly defined) label applied to expressions.
  | Var String        -- ^ Function parameter.
  | LitInt Integer
  | LitDouble Double
  | LitChar Char
  | LitString String
  deriving (Eq, Functor)

Then replace, in the C backend, [] by Null and (:) by the respective make_ListXXX, using fmap. (Btw. there is isNilFun and isConsFun to check for these special labels.)
This is likely still not enough, we need to have the list type XXX. This could be saved in the TypeChecker.hs, producing a Exp' (String,Cat) remembering the target type of the App f es. Spinning this further, the Cat is only needed for list constructors, so maybe Exp' Label would be sufficient where

data Label
  = OrdinaryLabel String
  | NilLabel  Cat    -- ^ []
  | ConsLabel Cat   -- ^ (:)
  | OneLabel  Cat    -- ^ (:[])

@andreasabel andreasabel added this to the 2.9.2 milestone Apr 30, 2021
@andreasabel andreasabel added C define Issue with define pragma labels Apr 30, 2021
@shlevy
Copy link
Contributor Author

shlevy commented May 1, 2021

Makes sense, will try to carve out some time!

@andreasabel andreasabel self-assigned this May 18, 2021
@andreasabel
Copy link
Member

I fixed this problem in a way similar as I wrote in the comment.
Mainly, we remember the typing information from the type checker, so we

  • do not need to run the type checker again (was so in the OO backends) when translating the definitions
  • can use the typing information to select the right list constructors.

@shlevy
Copy link
Contributor Author

shlevy commented May 18, 2021

Awesome! Sorry this sat for so long, I only have a little time here and there to work on the project using BNFC at the moment. Hopefully will be able to pick up the rust backend soon!

@andreasabel
Copy link
Member

Yeah, looking forward to the Rust backend!

If you find any more bugs, do not hesitate to report them! (Trying to understand how things work is the best way to discover bugs...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C define Issue with define pragma
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants