-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from adamhutchings/token
Add output capabilities
- Loading branch information
Showing
3 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/** | ||
* Main C source code file for the JabaCat C Compiler. | ||
* Initial commit: June 17, 2024 | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include <util/out.h> | ||
|
||
int main(int argc, char **argv) { | ||
printf("%s\n", "Hello, World!"); | ||
PRINT_DEFAULT("JabaCat C Compiler 2024"); | ||
PRINT_DEBUG("Compilation not supported yet -- coming soon!"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* This provides facilities for properly-formatted output. This is just taken | ||
* from yfc's output facilities. | ||
*/ | ||
|
||
#pragma once | ||
|
||
// All of the color codes. | ||
#define CODE_RED 31 | ||
#define CODE_YELLOW 33 | ||
#define CODE_GREEN 32 | ||
#define CODE_BLUE 34 | ||
#define CODE_MAGENTA 35 | ||
#define CODE_CYAN 36 | ||
#define CODE_WHITE 37 | ||
|
||
// Print things with colors. | ||
#define OUTPUT_STREAM stderr | ||
#define SET_COLOR(color) fprintf(OUTPUT_STREAM, "\033[%dm", color) | ||
#define RESET_COLOR(color) fprintf(OUTPUT_STREAM, "\033[0m") | ||
|
||
#define PRINT_WITH_COLOR(color, ...) do { \ | ||
SET_COLOR(color); \ | ||
fprintf(OUTPUT_STREAM, __VA_ARGS__); \ | ||
RESET_COLOR(color); \ | ||
} while (0) | ||
|
||
#define PRINT_ERROR(msg, ...) \ | ||
PRINT_WITH_COLOR(CODE_RED, "Error: jccc: " msg "\n" ,##__VA_ARGS__) | ||
|
||
#define PRINT_WARNING(msg, ...) \ | ||
PRINT_WITH_COLOR(CODE_YELLOW, "Warning: jccc: " msg "\n" ,##__VA_ARGS__) | ||
|
||
#define PRINT_DEBUG(msg, ...) \ | ||
PRINT_WITH_COLOR(CODE_BLUE, "Debug: jccc: " msg "\n" ,##__VA_ARGS__) | ||
|
||
#define PRINT_DEFAULT(msg, ...) \ | ||
PRINT_WITH_COLOR(CODE_WHITE, "jccc: " msg "\n" ,##__VA_ARGS__) |