Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Add stddef.h #487

Merged
merged 5 commits into from
Jul 24, 2020
Merged

Add stddef.h #487

merged 5 commits into from
Jul 24, 2020

Conversation

jyn514
Copy link
Owner

@jyn514 jyn514 commented Jul 24, 2020

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

Comment on lines +914 to +922
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() {
Copy link
Collaborator

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?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Copy link
Owner Author

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);
    ^^^^^^^^

Copy link
Owner Author

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.

Comment on lines +1079 to +1085
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) => {
Copy link
Collaborator

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.

Copy link
Owner Author

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.
Copy link
Collaborator

@pythongirl325 pythongirl325 left a 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
@jyn514 jyn514 merged commit ca7a8a0 into master Jul 24, 2020
@jyn514 jyn514 deleted the stddef branch July 24, 2020 14:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing stddef.h
3 participants