-
Notifications
You must be signed in to change notification settings - Fork 27
Add stddef.h #487
Add stddef.h #487
Conversation
let is_convertible_to_any_pointer = |expr: &Expr| { | ||
expr.ctype.is_void_pointer() || expr.ctype.is_char_pointer() || expr.is_null() | ||
}; | ||
if left.ctype == right.ctype { | ||
true | ||
} else if left.ctype.is_void_pointer() || left.ctype.is_char_pointer() || left.is_null() { | ||
} else if is_convertible_to_any_pointer(left) && right.ctype.is_pointer() { | ||
left.ctype = right.ctype.clone(); | ||
true | ||
} else if right.ctype.is_void_pointer() || right.ctype.is_char_pointer() || right.is_null() { | ||
} else if is_convertible_to_any_pointer(right) && left.ctype.is_pointer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what these do. Can I get a link to the relevant spec section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a comment at the start of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should have been a separate pull request but oh well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I had #define va_arg(ap, type) (0 ? "va_arg is not currently supported by saltwater" : 0.0)
. But it turns out that I don't give any sort of reasonable errors from macro expansion, so it didn't really matter.
stdarg_example.c:4:5 error: invalid program: incompatible types in ternary expression: 'char *' cannot be converted to 'double'
va_start(args, n);
^^^^^^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I improved the error messages a bit in the latest commit:
stddef_example.c:5:21 error: invalid syntax: expected ')', got 'not_currently_supported'
printf("%ul\n", offsetof(struct s { int i; }, i));
^^^^^^^^
Still not great but better than before.
Err(not_found) => { | ||
let filename = match filename.file_name().and_then(|f| f.to_str()) { | ||
None => return Err(not_found), | ||
Some(f) => f, | ||
}; | ||
match get_builtin_header(filename) { | ||
Some(file) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you really override stddef.h? If so that's disgusting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning here is that if the standard library provides stddef.h, that's probably more accurate than the one I hacked together. The standard doesn't treat the compiler and library separately so it's up to us which we want to do.
This is C. Headers are included many times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Idea adding the proper header guards. LGTM
- Move va_list to stdarg.h - Give _slightly_ better error message when using an unsupported macro
Closes #388. Gives a reasonable way to add additional header files.
Saltwater can, for the first time after 14 months, compile hello world with a GNU userland!
r? @pythondude325