Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add bool type corresponding to the llvm i1/ C99 bool #220
@yallop Okay, I have a preliminary version now. The type-printing test passes, but I have no idea if it really works. How do I ask my Makefile to use this instead of the opam version? I tried prepending
I think the implementation is correct, but rather than introducing a new type
Switching to the builtin
Some other consequences of switching to the standard
It'd be nice to print bool values as
Thanks, @artagnon. There's a test still failing; it looks like it just needs
I'm not very familiar with the details of LLVM. Does it give some guarantees about how
Defining a view requires conversion functions in both directions:
# let bool_of_int i = i <> 0 and int_of_bool b = if b then 1 else 0;; val bool_of_int : int -> bool = <fun> val int_of_bool : bool -> int = <fun> # let i1 = view int8_t ~read:bool_of_int ~write:int_of_bool;; val i1 : bool typ = int8_t
The top-level printer gives a clue to what's going on: the type of
# i1 @-> i1 @-> returning void;; - : (bool -> bool -> unit) fn = void(int8_t, int8_t)
That is, describing a function using the
The view implementation doesn't need any changes to ctypes itself, since it only uses functions in the public API. I'd like to go ahead and merge this pull request, since having a
Sorry about that: fixed the tests now. You can merge it, but the commit message may be incorrect.
I'll do some research on how llvm represents i1 and get back to you. I assumed that C99 bool = llvm i1 = uint8; the language uses this type information to say what operation is valid and what isn't. I mean what other way is there to represent 1 bit? You essentially waste 7 bits and put it in a byte, right?
added a commit
this pull request
Nov 25, 2014
I've merged the changeset and added a note to the commit message: d662070. Thanks for your contribution!
Regarding possible ways to represent 1 bit: implementations are obliged to waste at least 7 bits, since bools must be addressable, but I understand that they're at liberty to waste even more. I don't see anything in the standard that requires