-
Notifications
You must be signed in to change notification settings - Fork 63
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 #2450 from lf-lang/reactor-names
Make reactor names available at runtime
- Loading branch information
Showing
3 changed files
with
116 additions
and
1 deletion.
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
Submodule reactor-c
updated
5 files
+32 −0 | core/reactor_common.c | |
+21 −0 | include/api/reaction_macros.h | |
+3 −0 | include/api/reaction_macros_undef.h | |
+5 −2 | include/core/lf_types.h | |
+21 −0 | include/core/reactor.h |
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,58 @@ | ||
target C { | ||
build-type: debug | ||
} | ||
|
||
preamble {= | ||
#include <string.h> | ||
=} | ||
|
||
reactor A(parent_bank_index: size_t = 0) { | ||
reaction(startup) {= | ||
const char* name = lf_reactor_full_name(self); | ||
lf_print("name: %s", name); | ||
char buffer[20]; | ||
snprintf(buffer, 20, "ReactorName.b[%zu].a", self->parent_bank_index); | ||
if (strcmp(buffer, name) != 0) { | ||
lf_print_error_and_exit("full name does not match"); | ||
} | ||
name = lf_reactor_name(self); | ||
if (strcmp("a", name) != 0) { | ||
lf_print_error_and_exit("name does not match"); | ||
} | ||
=} | ||
} | ||
|
||
reactor B(bank_index: size_t = 0) { | ||
a = new A(parent_bank_index=bank_index) | ||
|
||
reaction(startup) {= | ||
const char* name = lf_reactor_full_name(self); | ||
lf_print("name: %s", name); | ||
char buffer[20]; | ||
snprintf(buffer, 20, "ReactorName.b[%zu]", self->bank_index); | ||
if (strcmp(buffer, name) != 0) { | ||
lf_print_error_and_exit("full name does not match"); | ||
} | ||
name = lf_reactor_name(self); | ||
snprintf(buffer, 20, "b[%zu]", self->bank_index); | ||
if (strcmp(buffer, name) != 0) { | ||
lf_print_error_and_exit("name does not match"); | ||
} | ||
=} | ||
} | ||
|
||
main reactor { | ||
b = new[3] B() | ||
|
||
reaction(startup) {= | ||
const char* name = lf_reactor_full_name(self); | ||
lf_print("name: %s", name); | ||
if (strcmp("ReactorName", name) != 0) { | ||
lf_print_error_and_exit("full name does not match"); | ||
} | ||
name = lf_reactor_name(self); | ||
if (strcmp("ReactorName", name) != 0) { | ||
lf_print_error_and_exit("name does not match"); | ||
} | ||
=} | ||
} |