From 989c3b576d9c7bd1543721bcd6e26e53c0c88ef9 Mon Sep 17 00:00:00 2001 From: Volkan Sagcan Date: Wed, 13 Nov 2024 11:18:33 +0100 Subject: [PATCH] Self referencing type fucntions and missing WCHAR --- libs/stdlib/iec61131-st/to_bit.st | 48 +++++++++++++++++++++++++++ tests/lit/single/conversion/to_bit.st | 7 ++++ 2 files changed, 55 insertions(+) diff --git a/libs/stdlib/iec61131-st/to_bit.st b/libs/stdlib/iec61131-st/to_bit.st index ec575a9de6..cca90b2c6f 100644 --- a/libs/stdlib/iec61131-st/to_bit.st +++ b/libs/stdlib/iec61131-st/to_bit.st @@ -4,6 +4,14 @@ FUNCTION TO_BOOL : 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; @@ -44,6 +52,14 @@ FUNCTION TO_BYTE : 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; @@ -92,6 +108,14 @@ FUNCTION TO_WORD : 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; @@ -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; @@ -140,6 +172,14 @@ FUNCTION TO_DWORD : 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; @@ -196,6 +236,14 @@ FUNCTION TO_LWORD : 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; diff --git a/tests/lit/single/conversion/to_bit.st b/tests/lit/single/conversion/to_bit.st index ec26d58977..55d0f12487 100644 --- a/tests/lit/single/conversion/to_bit.st +++ b/tests/lit/single/conversion/to_bit.st @@ -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 @@ -12,6 +14,7 @@ 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 @@ -19,13 +22,16 @@ FUNCTION main 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 @@ -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