-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evaluate all if statements at compile time when possible (#710)
- Loading branch information
Showing
5 changed files
with
150 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
.../should_succeed/if_WINDOWS_at_runtime.jou → tests/should_succeed/WINDOWS_at_runtime.jou
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
if WINDOWS: | ||
import "stdlib/io.jou" | ||
else: | ||
import "stdlib/str.jou" | ||
# Low level function for writing to file. Does not exist on Windows. | ||
declare write(fd: int, buf: byte*, count: long) -> long | ||
|
||
|
||
class EnterprisePrintWriterFactory: | ||
if WINDOWS: | ||
windows_message: byte* | ||
|
||
def set_message(self, m: byte*) -> None: | ||
self->windows_message = m | ||
|
||
def show_message(self) -> None: | ||
puts(self->windows_message) | ||
|
||
else: | ||
posix_message: byte* | ||
|
||
def set_message(self, m: byte*) -> None: | ||
self->posix_message = m | ||
|
||
def show_message(self) -> None: | ||
write(1, self->posix_message, strlen(self->posix_message)) | ||
write(1, "\n", 1) | ||
|
||
|
||
def main() -> int: | ||
e = EnterprisePrintWriterFactory{} | ||
e.set_message("hello") | ||
e.show_message() # Output: hello | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
if WINDOWS: | ||
import "stdlib/io.jou" | ||
else: | ||
# Low level function for writing to file. Does not exist on Windows. | ||
declare write(fd: int, buf: byte*, count: long) -> long | ||
|
||
def main() -> int: | ||
# Output: hello | ||
if WINDOWS: | ||
printf("hello\n") | ||
else: | ||
# If this code is compiled on Windows, there will be linker errors. | ||
write(1, "hello\n", 6) | ||
|
||
return 0 |