ocaml-sys / config.ml Goto Github PK
View Code? Open in Web Editor NEWconditional compilation via attributes for OCaml
License: Other
conditional compilation via attributes for OCaml
License: Other
Right now we can't use @cfg
in elements defined within modules and signatures.
The expected behavior is that @cfg
can be used in places like this:
module A : sig
val a : unit -> unit [@@cfg disable = true]
end =
let a () = () [@@cfg disable = true]
end
and interface files:
module A : sig
val a : unit -> unit [@@cfg disable = true]
end
Currently, this is unsupported:
let foo a =
match a with
| 0 -> "0"
| 1 -> "1"
[@@cfg (disable=true)]
And the expected behavior is that we can remove that match case with the annotation.
This is mostly important for having good support for conditional constructors and variants, so that we can disable in tandem the pattern matching branches for them.
Context: In DkCoder https://discuss.ocaml.org/t/ann-dkcoder-0-1-0/14327 I'm exposing OS/ABI from https://github.com/diskuv/dkml-c-probe as environment variables to scripts, and I've been planning on exposing a cfg
mechanism.
For a lot of reasons 1 I'll have to fork but thought I would ask regardless. Is there something about config
that needs OCaml 5.1+?
1 OCaml 5 / dkml-c-probe / whitelist control over envvars / restriction to modules for integration with codept / ...
Currently, this is unsupported:
let foo a = function
| 0 -> "0"
| 1 -> "1"
[@@cfg (disable=true)]
And the expected behavior is that we can remove that function branch with the annotation.
It looks like annotating [@config (not(a = 1))]
actually breaks at evaluation time with:
$ dune clean
$ dune build
+ File "cond_type_var_constructor.ml", line 16, characters 17-48:
+ 16 | | `KingCrimson [@config (not(made_up = true))]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ Error: Not expressions must have a single parameter
+
+ [1]
And using a variable to test for it being unset like [@config (not(a))]
, failed with:
$ dune clean
$ dune build
+ File "cond_type_var_constructor.ml", line 16, characters 17-41:
+ 16 | | `KingCrimson [@config (not(made_up))]
+ ^^^^^^^^^^^^^^^^^^^^^^^^
+ Error: Forms any/all/not must parenthesize its arguments
+
+ [1]
The expected behavior is that both of these parse correctly and evaluate as follows:
not(expr)
is equals to false if the expression is true, or true if it is falsenot(varName)
is equals to true if the varName is not defined in the environment or has no value, or false if varName has a valueA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.