Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Makes match statements work on platform objects (
require platform
) in the interpreter and javascript backend.For example, you could use it to select a platform-specific implementation of some API as I do in backend's main.wyv:
Platform has to be cast up to type
system.Platform
for the match becauserequire platform
creates a platform object with the precise type of the current platform (e.g.system.JavaScript
orsystem.Java
). This could be changed but it breaks the behavior of existing tests and doesn't play well with platform-specific imports. Here's the problem:If we change the behavior of
require platform
so that the platform object has typesystem.Platform
, this code will not compile becauseimport stdout
brings in some module depending on the platform (maybestdlib/platform/java/stdout.wyv
) which has amodule def stdout(java : Java) : Stdout
so it will not like being passed asystem.Platform
. I can think of a few different ways to fix this, but I'm not sure what the best way is. Thoughts?This patch changes how the system object is handled by the compiler in a big way. Instead of adding it to the StandardEvalContext, we add it before every module in the actual SeqExpr so that when bytecode is emitted the system object is present and tag information can be generated. Otherwise, a simple if statement in expression/Match.wyv and getTag() method in expression/FFI.java were all that were added. Thoughts on this? This is one of the more intrusive changes I've made to the compiler.
This patch also fixes a bug where match statements take the last case that matches instead of the first (missing
break
statement). Nearly all match statements in examples/algebra.wyv were reordered to fix this behavior. I confirmed with Justin and tested that this patch doesn't effect algebra.wyv's behavior.