-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces the `TO_<NUM>` library functions, which make use of the already existing and tested `<NUM>_TO_<NUM>` library functions.
- Loading branch information
Showing
3 changed files
with
1,742 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
f = open("to_num.st", "w") | ||
|
||
types = [ | ||
"SINT", | ||
"USINT", | ||
"INT", | ||
"UINT", | ||
"DINT", | ||
"UDINT", | ||
"LINT", | ||
"ULINT", | ||
|
||
"REAL", | ||
"LREAL", | ||
|
||
# "BIT", | ||
# "BOOL", | ||
# "BYTE", | ||
# "WORD", | ||
# "DWORD", | ||
# "LWORD", | ||
|
||
# "STRING", | ||
# "WSTRING", | ||
|
||
# "TIME", | ||
# "LTIME", | ||
# "DATE", | ||
# "LDATE", | ||
# "DT", | ||
# "LDT", | ||
# "TOD", | ||
# "LTOD", | ||
] | ||
|
||
generic = """(******************** | ||
* | ||
* Converts any other numerical value to {0} | ||
* | ||
*********************) | ||
FUNCTION TO_{0}<T: ANY_NUM> : {0} | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
""" | ||
|
||
generic_impl = """(******************** | ||
* | ||
* Converts {0} to {1} | ||
* | ||
*********************) | ||
FUNCTION TO_{1}__{0} : {1} | ||
VAR_INPUT | ||
in : {0}; | ||
END_VAR | ||
TO_{1}__{0} := {0}_TO_{1}(in); | ||
END_FUNCTION | ||
""" | ||
|
||
generic_impl_same = """(******************** | ||
* | ||
* Converts {0} to {1} | ||
* | ||
*********************) | ||
FUNCTION TO_{1}__{0} : {1} | ||
VAR_INPUT | ||
in : {0}; | ||
END_VAR | ||
TO_{1}__{0} := in; | ||
END_FUNCTION | ||
""" | ||
|
||
for type_from in types: | ||
f.write(generic.format(type_from)) | ||
f.write("\n") | ||
|
||
for type_to in types: | ||
if type_from == type_to: | ||
f.write(generic_impl_same.format(type_from, type_to)) | ||
else: | ||
f.write(generic_impl.format(type_from, type_to)) | ||
|
||
f.write("\n") | ||
|
Oops, something went wrong.