Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CALL for C #41

Open
cayhorstmann opened this issue Oct 28, 2022 · 1 comment
Open

Implement CALL for C #41

cayhorstmann opened this issue Oct 28, 2022 · 1 comment

Comments

@cayhorstmann
Copy link
Owner

Make a progfileCodeCheck.c with the contents

// Student/instructor code

extern int atoi(const char*);
int main(int argc, char *argv[]) {
    int arg = atoi(argv[1]);
    if (arg == 1) print_T(FUN(ARGS));
    ...
}

where T is derived from the return type (print_int, print_double, print_char_pointer, print_bool, print_char, ...). If the return type is something else, the instructor/student code must contain a function print_T.

@cayhorstmann
Copy link
Owner Author

We need to capture the type of the C function, not just its name. Right now, Language.java has a functionName method that finds the name. We'd like functionType. But not all functions have types (e.g. in Python, JavaScript, etc.) So the default in Language should return null, but in CLanguage override to produce a type. The type is everything before the name, with spaces and modifiers (const, static, extern) removed, e.g. int, double, bool, char, char*.

Modify Calls.Call to have a String type field. Set it in addCall to the result of calling functionName. It will be null for all languages other than C. That's ok.

In CLanguage.writeTester, ask for the type of the Call object and produce calls to print_int, print_double, print_char_pointer, print_bool, print_char. Those are the only supported ones. Otherwise call print_unsupported.

Define those functions in a file codecheck_c.h that you include like the C++ language does. They just call printf. Or skip the functions and call printf directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant