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

Support conditional compilation / static if #1359

Open
bsansouci opened this issue Aug 16, 2017 · 14 comments
Open

Support conditional compilation / static if #1359

bsansouci opened this issue Aug 16, 2017 · 14 comments
Labels
KIND: FEATURE REQUEST Parser parsing reason code into an AST

Comments

@bsansouci
Copy link
Contributor

Hey everyone :D
I saw that Bucklescript has support for condition compilation but it's a preprocessor fed into -pp, which means we can't use it in conjuction with Reason (since refmt is also a preprocessor).

How could we support static if statement like Bucklescript does?
It would help the cross platform story a lot in my opinion!

@hcarty
Copy link
Contributor

hcarty commented Aug 16, 2017

https://github.com/mcclure/ppx_const may be a good start. It may need to be updated to use omp and friends.

@bobzhang
Copy link
Contributor

note bucklescript support of conditional compilation is baked in, the -pp is a fallback when you use a normal ocaml compiler. ppx is overkill, it would be nice that reason would have it baked in but it is more challenging to the printer

@IwanKaramazow
Copy link
Contributor

Bucklescript solves this very elegantly in lexing.
I'm not 100% sure how we should/can do this in Reason. Since the printer takes an ast & formats based on the tree, we'll need to augment the ast in some kind of way.

@bsansouci
Copy link
Contributor Author

@hcarty's suggestion seems like the easiest and sanest for now

@bsansouci
Copy link
Contributor Author

bsansouci commented Sep 4, 2017

@IwanKaramazow @jordwalke It seems like refmt doesn't support the syntax for https://github.com/janestreet/ppx_optcomp. Do you know how we'd write that syntax https://github.com/mcclure/ppx_const in Reason? I couldn't find something that refmts.

EDIT:

This works for the first link :)
Now gotta have crossplatform ppx-es

[%const
    if true {
      module FastHelpers = FastHelpersNative;
      ()
    } else {
      module FastHelpers = FastHelpersJs;
      ()
    }
  ];

@yyc-git
Copy link

yyc-git commented Oct 25, 2017

we need "Support conditional compilation / static if" in reason which is baked in!

@chenglou could you have a plan to support it?

@yyc-git
Copy link

yyc-git commented Oct 25, 2017

@bsansouci how to use https://github.com/mcclure/ppx_const in reason? could you give me suggestion?

@bsansouci
Copy link
Contributor Author

bsansouci commented Oct 26, 2017

@yyc-git Hey, right now the only way to use ppx_const would be to depend on it on opam.
You need to run

opam switch 4.02.3+buckle-master
eval `opam config env`

to get the right version of the compiler

then add "ocamlfind-dependencies": ["ppx_const"] to your bsconfig.json

I'm not 100% sure it'll work though, I have not tried it.

EDIT: ping me on discord if you want to chat. I can help better in real time.

@yyc-git
Copy link

yyc-git commented Oct 27, 2017

@bsansouci Thanks for your reply!

@bsansouci
Copy link
Contributor Author

@yyc-git Hey I just landed a change in bsb-native that should allow you to use matchenv. See https://github.com/Schmavery/reprocessing/blob/master/src/Reprocessing_Hotreload.re for the syntax and all.
You just need one file that'll be the one that will have its implementation swapped, and then call include [%matchenv ... like this, and switch to get the different implementation. BSB_BACKEND is a magical value that'll be filed in by bsb-native when compiling to each target :)

@yyc-git
Copy link

yyc-git commented Nov 10, 2017

@bsansouci Thankes a lot.

Is Bsb(js backend) support it? I need it in js backbend anyway.

@bsansouci
Copy link
Contributor Author

Yes, bsb-native is 100% compatible with bsb. Just small extensions to support compiling to bytecode/native :)

@yyc-git
Copy link

yyc-git commented Nov 11, 2017

@bsansouci Good job~

now I'm using Reason 3, which require bsb 2.0. so does bsb-native support reason3? support bsb 2.0?

@bsansouci
Copy link
Contributor Author

Yup bsb-Native supports reason 3 :)

@jaredly jaredly added KIND: FEATURE REQUEST Parser parsing reason code into an AST labels Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
KIND: FEATURE REQUEST Parser parsing reason code into an AST
Projects
None yet
Development

No branches or pull requests

6 participants