Skip to content

Commit

Permalink
Define boolean constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Sep 2, 2024
1 parent 27a6379 commit ef14dc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/capi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ pub const asSymbolId = c.clAsSymbolId;
pub fn asString(val: Value) []const u8 {
return fromStr(c.clAsString(val));
}
pub const clTrue = c.clTrue;
pub const clFalse = c.clFalse;
pub const Void = c.CL_VOID;
pub const True = c.CL_TRUE;
pub const False = c.CL_FALSE;
pub const bool_ = c.clBool;
pub const asBoxInt = c.clAsBoxInt;
pub const int = c.clInt;
pub const asBool = c.clAsBool;
Expand Down
4 changes: 2 additions & 2 deletions src/include/cyber.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef struct CLModule CLModule;

#define CL_NULLID UINT32_MAX
#define CL_VOID 0x7FFC000100000000
#define CL_TRUE 0x7FFC000200000001
#define CL_FALSE 0x7FFC000200000000
#define CL_INTERRUPT 0x7ffc00030000ffff

typedef int CLResultCode;
Expand Down Expand Up @@ -532,8 +534,6 @@ CLAllocator clGetAllocator(CLVM* vm);
// -----------------------------------

// Create values.
CLValue clTrue(void);
CLValue clFalse(void);
CLValue clBool(bool b);

CLValue clInt(int64_t n); // Unboxed.
Expand Down
8 changes: 4 additions & 4 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,17 @@ test "clToBool()" {
i = vm.newInt(1);
try t.eq(c.toBool(i), true);

try t.eq(c.toBool(c.clTrue()), true);
try t.eq(c.toBool(c.clFalse()), false);
try t.eq(c.toBool(c.True), true);
try t.eq(c.toBool(c.False), false);
}

export fn clAsBool(val: Value) bool {
return val.asBool();
}

test "clAsBool()" {
try t.eq(c.asBool(c.clTrue()), true);
try t.eq(c.asBool(c.clFalse()), false);
try t.eq(c.asBool(c.True), true);
try t.eq(c.asBool(c.False), false);
}

export fn clAsBoxInt(val: Value) i64 {
Expand Down

0 comments on commit ef14dc7

Please sign in to comment.