Skip to content

Commit

Permalink
Self referencing type fucntions and missing WCHAR
Browse files Browse the repository at this point in the history
  • Loading branch information
volsa committed Nov 13, 2024
1 parent 6a96c7a commit 989c3b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
48 changes: 48 additions & 0 deletions libs/stdlib/iec61131-st/to_bit.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ FUNCTION TO_BOOL<T: ANY> : BOOL
END_VAR
END_FUNCTION

FUNCTION TO_BOOL__BOOL : BOOL
VAR_INPUT
in : BOOL;
END_VAR

TO_BOOL__BOOL := in;
END_FUNCTION

FUNCTION TO_BOOL__BYTE : BOOL
VAR_INPUT
in : BYTE;
Expand Down Expand Up @@ -44,6 +52,14 @@ FUNCTION TO_BYTE<T: ANY> : BYTE
END_VAR
END_FUNCTION

FUNCTION TO_BYTE__BYTE : BYTE
VAR_INPUT
in : BYTE;
END_VAR

TO_BYTE__BYTE := in;
END_FUNCTION

FUNCTION TO_BYTE__BOOL : BYTE
VAR_INPUT
in : BOOL;
Expand Down Expand Up @@ -92,6 +108,14 @@ FUNCTION TO_WORD<T: ANY> : WORD
END_VAR
END_FUNCTION

FUNCTION TO_WORD__WORD : WORD
VAR_INPUT
in : WORD;
END_VAR

TO_WORD__WORD := in;
END_FUNCTION

FUNCTION TO_WORD__BOOL : WORD
VAR_INPUT
in : BOOL;
Expand All @@ -108,6 +132,14 @@ FUNCTION TO_WORD__CHAR : WORD
TO_WORD__CHAR := CHAR_TO_WORD(in);
END_FUNCTION

FUNCTION TO_WORD__WCHAR : WORD
VAR_INPUT
in : WCHAR;
END_VAR

TO_WORD__WCHAR := WCHAR_TO_WORD(in);
END_FUNCTION

FUNCTION TO_WORD__BYTE : WORD
VAR_INPUT
in : BYTE;
Expand Down Expand Up @@ -140,6 +172,14 @@ FUNCTION TO_DWORD<T: ANY> : DWORD
END_VAR
END_FUNCTION

FUNCTION TO_DWORD__DWORD : DWORD
VAR_INPUT
in : DWORD;
END_VAR

TO_DWORD__DWORD := in;
END_FUNCTION

FUNCTION TO_DWORD__BOOL : DWORD
VAR_INPUT
in : BOOL;
Expand Down Expand Up @@ -196,6 +236,14 @@ FUNCTION TO_LWORD<T: ANY> : LWORD
END_VAR
END_FUNCTION

FUNCTION TO_LWORD__LWORD : LWORD
VAR_INPUT
in : LWORD;
END_VAR

TO_LWORD__LWORD := in;
END_FUNCTION

FUNCTION TO_LWORD__BOOL : LWORD
VAR_INPUT
in : BOOL;
Expand Down
7 changes: 7 additions & 0 deletions tests/lit/single/conversion/to_bit.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// RUN: (%COMPILE %s && %RUN) | %CHECK %s
FUNCTION main
printf('%d$N', TO_BOOL(BOOL#FALSE)); // CHECK: 0
printf('%d$N', TO_BOOL(BOOL#TRUE)); // CHECK: 1
printf('%d$N', TO_BOOL(BYTE#0)); // CHECK: 0
printf('%d$N', TO_BOOL(BYTE#5)); // CHECK: 1
printf('%d$N', TO_BOOL(WORD#0)); // CHECK: 0
Expand All @@ -12,20 +14,24 @@ FUNCTION main
printf('%d$N', TO_BOOL(LWORD#0)); // CHECK: 0
printf('%d$N', TO_BOOL(LWORD#5)); // CHECK: 1

printf('%d$N', TO_BYTE(BYTE#5)); // CHECK: 5
printf('%d$N', TO_BYTE(BOOL#FALSE)); // CHECK: 0
printf('%d$N', TO_BYTE(BOOL#TRUE)); // CHECK: 1
printf('%d$N', TO_BYTE(CHAR#'a')); // CHECK: 97
printf('%d$N', TO_BYTE(WORD#5)); // CHECK: 5
printf('%d$N', TO_BYTE(DWORD#5)); // CHECK: 5
printf('%d$N', TO_BYTE(LWORD#5)); // CHECK: 5

printf('%d$N', TO_WORD(WORD#5)); // CHECK: 5
printf('%d$N', TO_WORD(BOOL#FALSE)); // CHECK: 0
printf('%d$N', TO_WORD(BOOL#TRUE)); // CHECK: 1
printf('%d$N', TO_WORD(CHAR#'a')); // CHECK: 97
printf('%d$N', TO_WORD(WCHAR#"a")); // CHECK: 97
printf('%d$N', TO_WORD(BYTE#5)); // CHECK: 5
printf('%d$N', TO_WORD(DWORD#5)); // CHECK: 5
printf('%d$N', TO_WORD(LWORD#5)); // CHECK: 5

printf('%d$N', TO_DWORD(DWORD#5)); // CHECK: 5
printf('%d$N', TO_DWORD(BOOL#FALSE)); // CHECK: 0
printf('%d$N', TO_DWORD(BOOL#TRUE)); // CHECK: 1
printf('%d$N', TO_DWORD(CHAR#'a')); // CHECK: 97
Expand All @@ -34,6 +40,7 @@ FUNCTION main
printf('%d$N', TO_DWORD(WORD#5)); // CHECK: 5
printf('%d$N', TO_DWORD(LWORD#5)); // CHECK: 5

printf('%d$N', TO_LWORD(LWORD#5)); // CHECK: 5
printf('%d$N', TO_LWORD(BOOL#FALSE)); // CHECK: 0
printf('%d$N', TO_LWORD(BOOL#TRUE)); // CHECK: 1
printf('%d$N', TO_LWORD(CHAR#'a')); // CHECK: 97
Expand Down

0 comments on commit 989c3b5

Please sign in to comment.