Skip to content

Commit 009e2ed

Browse files
committed
Add Platform methods for BSD distros
1 parent 2103f7c commit 009e2ed

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

core/Platform.savi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
:: If true, it implies that `is_posix` is also true.
3535
:const is_bsd Bool: compiler intrinsic
3636

37+
:: Returns `True` if the target platform uses a FreeBSD operating system.
38+
:const is_freebsd Bool: compiler intrinsic
39+
40+
:: Returns `True` if the target platform uses a OpenBSD operating system.
41+
:const is_openbsd Bool: compiler intrinsic
42+
43+
:: Returns `True` if the target platform uses a NetBSD operating system.
44+
:const is_netbsd Bool: compiler intrinsic
45+
46+
:: Returns `True` if the target platform uses a Dragonfly operating system.
47+
:const is_dragonfly Bool: compiler intrinsic
48+
3749
:: Returns `True` if the target platform uses a MacOS operating system.
3850
::
3951
:: This is mutually exclusive with `is_linux`, `is_bsd`, and `is_windows`.

spec/core/Platform.Spec.savi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
if Platform.is_macos (1 | 0) +
1010
if Platform.is_windows (1 | 0)
1111

12+
:it "detects FreeBSD, OpenBSD, NetBSD and Dragonfly"
13+
if Platform.is_bsd (assert: (
14+
Platform.is_freebsd ||
15+
Platform.is_openbsd ||
16+
Platform.is_netbsd ||
17+
Platform.is_dragonfly
18+
))
19+
1220
:it "returns True for is_posix on POSIX platforms"
1321
if Platform.is_linux (assert: Platform.is_posix)
1422
if Platform.is_bsd (assert: Platform.is_posix)

src/savi/compiler/code_gen.cr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,14 @@ class Savi::Compiler::CodeGen
10031003
gen_bool(target.linux?)
10041004
when "is_bsd"
10051005
gen_bool(target.bsd?)
1006+
when "is_freebsd"
1007+
gen_bool(target.freebsd?)
1008+
when "is_openbsd"
1009+
gen_bool(target.openbsd?)
1010+
when "is_netbsd"
1011+
gen_bool(target.netbsd?)
1012+
when "is_dragonfly"
1013+
gen_bool(target.dragonfly?)
10061014
when "is_macos"
10071015
gen_bool(target.macos?)
10081016
when "is_posix"

0 commit comments

Comments
 (0)