Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/Platform.savi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
:: If true, it implies that `is_posix` is also true.
:const is_bsd Bool: compiler intrinsic

:: Returns `True` if the target platform uses a FreeBSD operating system.
:const is_freebsd Bool: compiler intrinsic

:: Returns `True` if the target platform uses a OpenBSD operating system.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a tiny stupid English nitpick:

Suggested change
:: Returns `True` if the target platform uses a OpenBSD operating system.
:: Returns `True` if the target platform uses an OpenBSD operating system.

:const is_openbsd Bool: compiler intrinsic

:: Returns `True` if the target platform uses a NetBSD operating system.
:const is_netbsd Bool: compiler intrinsic

:: Returns `True` if the target platform uses a Dragonfly operating system.
:const is_dragonfly Bool: compiler intrinsic

:: Returns `True` if the target platform uses a MacOS operating system.
::
:: This is mutually exclusive with `is_linux`, `is_bsd`, and `is_windows`.
Expand Down
8 changes: 8 additions & 0 deletions spec/core/Platform.Spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
if Platform.is_macos (1 | 0) +
if Platform.is_windows (1 | 0)

:it "detects FreeBSD, OpenBSD, NetBSD and Dragonfly"
if Platform.is_bsd (assert: (
Platform.is_freebsd ||
Platform.is_openbsd ||
Platform.is_netbsd ||
Platform.is_dragonfly
))
Comment on lines +13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that of these four platforms are mutually exclusive, right?

If so, then I think a test like the following would be more robust, and cover more failure cases:

Suggested change
if Platform.is_bsd (assert: (
Platform.is_freebsd ||
Platform.is_openbsd ||
Platform.is_netbsd ||
Platform.is_dragonfly
))
is_bsd U8 = if Platform.is_bsd (1 | 0)
assert: is_bsd == U8[0] +
if Platform.is_freebsd (1 | 0) +
if Platform.is_openbsd (1 | 0) +
if Platform.is_netbsd (1 | 0) +
if Platform.is_dragonfly (1 | 0)

That is, this tests that exactly one of those specific BSD platforms is true if and only if the overall platform designation is BSD - and if it's not BSD, then none of them are true.


:it "returns True for is_posix on POSIX platforms"
if Platform.is_linux (assert: Platform.is_posix)
if Platform.is_bsd (assert: Platform.is_posix)
Expand Down
8 changes: 8 additions & 0 deletions src/savi/compiler/code_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,14 @@ class Savi::Compiler::CodeGen
gen_bool(target.linux?)
when "is_bsd"
gen_bool(target.bsd?)
when "is_freebsd"
gen_bool(target.freebsd?)
when "is_openbsd"
gen_bool(target.openbsd?)
when "is_netbsd"
gen_bool(target.netbsd?)
when "is_dragonfly"
gen_bool(target.dragonfly?)
when "is_macos"
gen_bool(target.macos?)
when "is_posix"
Expand Down