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

Conditional code #8

Closed
andymcn opened this issue Sep 1, 2014 · 3 comments
Closed

Conditional code #8

andymcn opened this issue Sep 1, 2014 · 3 comments
Assignees

Comments

@andymcn
Copy link
Contributor

andymcn commented Sep 1, 2014

We need to allow conditional code, both platform / hardware specific and for debug vs release.

We could switch at the expression, method, type or file level.
We need to provide system / build info (OS, CPU capabilities, debug / release).
Should we also allow programmer configurable info? This could be to allow the aardvark build to be different to the wombat build. It could also be used to make complex decisions based on OS, CPU, etc jsut once, rather than in every file, function, etc.

@andymcn
Copy link
Contributor Author

andymcn commented Sep 23, 2014

Conclusion of long discussion:

  1. In builtin we define functions of the form:
    class Platform fun tag linux(): Bool => compiler_intrinsic
    Currently defined functions are linux, windows, osx and debug.
  2. We add a condition clause to "use" commands, which is currently only legal for the lib: scheme. This allows the use of the Platform functions to specify whether to the use command should be included in each build.
  3. The code generator / llvm branch optimisor completely removes any branches in the code whose condition only depends on the Platform functions. Note that we still fully type check all code paths.
  4. We explicitly do not provide any mechanism for conditional code based on CPU capabilities (eg SSE), endianness or other factor that can only be determined at runtime. Standard if expressions can of course be used, with the associated overhead.

sylvanc added a commit that referenced this issue Sep 23, 2014
sylvanc added a commit that referenced this issue Sep 23, 2014
sylvanc added a commit that referenced this issue Sep 23, 2014
@sylvanc
Copy link
Contributor

sylvanc commented Sep 23, 2014

This is in the code generator now. It works with if expressions and anything the compiler can determine to be a constant expression, so you can combine Platform booleans with other booleans, and if that results in a branch that can never execute, that branch won't be generated.

This isn't implemented for while loops.

Andy, that leaves the "use lib" conditional guard implementation to you.

@andymcn
Copy link
Contributor Author

andymcn commented Sep 26, 2014

The "lib:" handler for use commands isn't in yet, but the conditional guards are.

I've actually made it so that all use commands can have a condition, including using packages. The condition is evaluated in the scope pass (ie where we already handled use commands). If the condition fails we pretend that use command doesn't exist.

This allows entire packages to be platform specific if you want to.

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

No branches or pull requests

2 participants