-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating native definitions - Part 1
- Loading branch information
1 parent
511a293
commit 5b091db
Showing
4 changed files
with
60 additions
and
2 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
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,35 @@ | ||
#include "compiler.h" | ||
#include "preprocessor/preprocessor.h" | ||
|
||
int preprocessor_line_macro_evaluate(struct preprocessor_definition* definition, struct preprocessor_function_arguments* arguments) | ||
{ | ||
struct preprocessor* preprocessor = definition->preprocessor; | ||
struct compile_process* compiler = preprocessor->compiler; | ||
|
||
if (arguments) | ||
{ | ||
compiler_error(compiler, "__LINE__ macro expects no arguments"); | ||
} | ||
|
||
struct token* previous_token = preprocessor_previous_token(compiler); | ||
return previous_token->pos.line; | ||
} | ||
|
||
struct vector* preprocessor_line_macro_value(struct preprocessor_definition* definition, struct preprocessor_function_arguments* arguments) | ||
{ | ||
struct preprocessor* preprocessor = definition->preprocessor; | ||
struct compile_process* compiler = preprocessor->compiler; | ||
|
||
if (arguments) | ||
{ | ||
compiler_error(compiler, "__LINE__ macro expects no arguments"); | ||
} | ||
|
||
struct token* previous_token = preprocessor_previous_token(compiler); | ||
return preprocessor_build_value_vector_for_integer(previous_token->pos.line); | ||
} | ||
|
||
void preprocessor_create_definitions(struct preprocessor* preprocessor) | ||
{ | ||
preprocessor_definition_create_native(preprocessor, "__LINE__", preprocessor_line_macro_evaluate, preprocessor_line_macro_value); | ||
} |
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