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

Update the SET, tag and schedule APIs and deprecate old ones #68

Merged
merged 24 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ab42775
add lowercase variants of SETs and deprecate uppercase versions
housengw Apr 19, 2022
9f49a15
add #undef file for ctarget macros to prevent naming collisions
housengw Apr 19, 2022
3261932
prevent duplicate definition of schedule functions
housengw Apr 19, 2022
bd88690
update author info
housengw Apr 19, 2022
6e35c0b
move #include in ctarget.h
housengw Apr 19, 2022
d21dc5e
factor ctarget.h into schedule and set subfiles
housengw Apr 20, 2022
247e0c3
change up-to-date api to 'lf_' prefixed names
housengw Apr 20, 2022
42d3665
add 'lf_' prefix to schedule functions
housengw Apr 20, 2022
9069512
move DEPRECATED macro to platform.h
housengw Apr 20, 2022
e90fd25
add lf_ to schedule_int
housengw Apr 20, 2022
fa1599a
rename tag API
housengw Apr 20, 2022
5a75995
do not rename APIs that can be replaced by lf_set
housengw Apr 21, 2022
e13e50c
Merge branch 'schedule-lf-prefix' into deprecate-uppercase-set
housengw Apr 21, 2022
c04636a
Merge branch 'tag-lf-prefix' into deprecate-uppercase-set
housengw Apr 21, 2022
7e9c673
change internal tag functions to _lf prefix
housengw Apr 22, 2022
8005233
first implementation of lf_tag and lf_time
housengw Apr 22, 2022
182d7d3
apply suggestion from code review
housengw Apr 22, 2022
edea132
do not allow lf_time_flag as argument to lf_tag
housengw Apr 22, 2022
94d7eba
change references of compare_tags to lf_compare_tags
housengw Apr 22, 2022
b6a3830
replace references of get_current_tag() to lf_tag()
housengw Apr 22, 2022
19638f3
update ci file to point to deprecate-uppercase-set
housengw Apr 22, 2022
b657dbe
replace deprecated API references to up-to-date ones
housengw Apr 22, 2022
9e17f8a
update cmake lists for unit tests
housengw Apr 22, 2022
b871004
update lingua-franca-ref.txt
housengw Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions include/ctarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* reactor in form input_name.port_name.
* @param value The value to insert into the self struct.
*/
#define SET(out, val) _LF_SET(out, val)
#define set(out, val) _LF_SET(out, val)
#define SET(out, val) \
_Pragma ("Warning \"'SET' is deprecated. Use 'set' instead.\"") \
_LF_SET(out, val)

/**
* Version of set for output types given as 'type[]' where you
Expand All @@ -90,7 +93,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @param length The length of the array to send.
* @see lf_token_t
*/
#define SET_ARRAY(out, val, length) _LF_SET_ARRAY(out, val, length)
#define set_array(out, val, length) _LF_SET_ARRAY(out, val, length)
#define SET_ARRAY(out, val, elem_size, length) \
_Pragma ("Warning \"'SET_ARRAY' is deprecated. Use 'set_array' instead.\"") \
_LF_SET_ARRAY(out, val, length)

/**
* Version of set() for output types given as 'type*' that
Expand All @@ -106,7 +112,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* struct to true (which causes the object message to be sent),
* @param out The output port (by name).
*/
#define SET_NEW(out) _LF_SET_NEW(out)
#define set_new(out) _LF_SET_NEW(out)
#define SET_NEW(out) \
_Pragma ("Warning \"'SET_NEW' is deprecated. Use 'set_new' instead.\"") \
_LF_SET_NEW(out)

/**
* Version of set() for output types given as 'type[]'.
Expand All @@ -121,7 +130,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @param out The output port (by name).
* @param len The length of the array to be sent.
*/
#define SET_NEW_ARRAY(out, len) _LF_SET_NEW_ARRAY(out, len)
#define set_new_array(out, len) _LF_SET_NEW_ARRAY(out, len)
#define SET_NEW_ARRAY(out, len) \
_Pragma ("Warning \"'SET_NEW_ARRAY' is deprecated. Use 'set_new_array' instead.\"") \
_LF_SET_NEW_ARRAY(out, len)

/**
* Version of set() for output types given as 'type[number]'.
Expand All @@ -132,7 +144,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* after this is called.
* @param out The output port (by name).
*/
#define SET_PRESENT(out) _LF_SET_PRESENT(out)
#define set_present(out) _LF_SET_PRESENT(out)
#define SET_PRESENT(out) \
_Pragma ("Warning \"'SET_PRESENT' is deprecated. Use 'set_present' instead.\"") \
_LF_SET_PRESENT(out)

/**
* Version of set() for output types given as 'type*' or 'type[]' where you want
Expand All @@ -143,7 +158,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @param out The output port (by name).
* @param token A pointer to token obtained from an input or action.
*/
#define SET_TOKEN(out, newtoken) _LF_SET_TOKEN(out, newtoken)
#define set_token(out, newtoken) _LF_SET_TOKEN(out, newtoken)
#define SET_TOKEN(out, newtoken) \
_Pragma ("Warning \"'SET_TOKEN' is deprecated. Use 'set_token' instead.\"") \
_LF_SET_TOKEN(out, newtoken)

/**
* Set the destructor used to free "token->value" set on "out".
Expand All @@ -155,7 +173,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @param dtor A pointer to a void function that takes a pointer argument
* or NULL to use the default void free(void*) function.
*/
#define SET_DESTRUCTOR(out, dtor) _LF_SET_DESTRUCTOR(out, dtor)
#define set_destructor(out, dtor) _LF_SET_DESTRUCTOR(out, dtor)
#define SET_DESTRUCTOR(out, dtor) \
_Pragma ("Warning \"'SET_DESTRUCTOR' is deprecated. Use 'set_destructor' instead.\"") \
_LF_SET_DESTRUCTOR(out, dtor)


/**
Expand All @@ -167,7 +188,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @param cpy_ctor A pointer to a void* function that takes a pointer argument
* or NULL to use the memcpy operator.
*/
#define SET_COPY_CONSTRUCTOR(out, cpy_ctor) _LF_SET_COPY_CONSTRUCTOR(out, cpy_ctor)
#define set_copy_constructor(out, cpy_ctor) _LF_SET_COPY_CONSTRUCTOR(out, cpy_ctor)
#define SET_COPY_CONSTRUCTOR(out, cpy_ctor) \
_Pragma ("Warning \"'SET_COPY_CONSTRUCTOR' is deprecated. Use 'set_copy_constructor' instead.\"") \
_LF_SET_COPY_CONSTRUCTOR(out, cpy_ctor)

//////////////////////////////////////////////////////////////
///////////// SET_MODE Function (to switch a mode)
Expand Down
120 changes: 120 additions & 0 deletions include/ctarget_end.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @file
* @author Edward A. Lee (eal@berkeley.edu)
housengw marked this conversation as resolved.
Show resolved Hide resolved
*
* @section LICENSE
Copyright (c) 2020, The University of California at Berkeley.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* @section DESCRIPTION
* Undefining the macros in the ctarget.h
* Refer to ctarget.h for details of the macros
*
* Note for target language developers. This is one way of developing a target language where
* the C core runtime is adopted. This file is a translation layer that implements Lingua Franca
* APIs which interact with the internal _lf_SET and _lf_schedule APIs. This file can act as a
* template for future runtime developement for target languages.
* For source generation, see xtext/org.icyphy.linguafranca/src/org/icyphy/generator/CCppGenerator.xtend.
*/


#ifndef CTARGET_END_H
#define CTARGET_END_H

//////////////////////////////////////////////////////////////
///////////// SET Functions (to produce an output)

// NOTE: According to the "Swallowing the Semicolon" section on this page:
// https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html
// the following macros should use an odd do-while construct to avoid
// problems with if ... else statements that do not use braces around the
// two branches.

/**
* Set the specified output (or input of a contained reactor)
* to the specified value.
*/
#undef set
#undef SET

/**
* Version of set for output types given as 'type[]' where you
* want to send a previously dynamically allocated array.
*/
#undef set_array
#undef SET_ARRAY

/**
* Version of set() for output types given as 'type*' that
* allocates a new object of the type of the specified output port.
*/
#undef set_new
#undef SET_NEW

/**
* Version of set() for output types given as 'type[]'.
*/
#undef set_new_array
#undef SET_NEW_ARRAY

/**
* Version of set() for output types given as 'type[number]'.
*/
#undef set_present
#undef SET_PRESENT

/**
* Version of set() for output types given as 'type*' or 'type[]' where you want
* to forward an input or action without copying it.
*/
#undef set_token
#undef SET_TOKEN

/**
* Set the destructor used to free "token->value" set on "out".
* That memory will be automatically freed once all downstream
* reactions no longer need the value.
*/
#undef set_destructor
#undef SET_DESTRUCTOR


/**
* Set the destructor used to copy construct "token->value" received
* by "in" if "in" is mutable.
*/
#undef set_copy_constructor
#undef SET_COPY_CONSTRUCTOR

//////////////////////////////////////////////////////////////
///////////// SET_MODE Function (to switch a mode)

/**
* Sets the next mode of a modal reactor. Same as SET for outputs, only
* the last value will have effect if invoked multiple times.
* Works only in reactions with the target mode declared as effect.
*/
#ifdef MODAL_REACTORS
#undef SET_MODE
#endif

#endif // CTARGET_H