Skip to content

Commit

Permalink
Change signatures of string functions (#401)
Browse files Browse the repository at this point in the history
Change signatures of string functions
  • Loading branch information
TimaFrolov authored Aug 7, 2023
1 parent 95d0b6d commit 35783b1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 100 deletions.
9 changes: 2 additions & 7 deletions docs/Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -1872,10 +1872,6 @@ char[] strcat(char[] s1, char[] s2);
char[] STRCAT(char[] s1, char[] s2);
char[] конкат_строки(char[] s, int n);
char[] КОНКАТ_СТРОКИ(char[] s, int n);
char[] strncat(char[] s1, char[] s2, int n);
char[] STRNCAT(char[] s1, char[] s2, int n);
char[] конкат_н_симв(char[] s, int n);
char[] КОНКАТ_Н_СИМВ(char[] s, int n);
int strcmp(char[] s1, char[] s2);
int STRCMP(char[] s1, char[] s2);
char[] сравн_строк(char[] s, int n);
Expand All @@ -1886,13 +1882,12 @@ char[] сравн_н_симв(char[] s, int n);
char[] СРАВН_Н_СИМВ(char[] s, int n);
int strstr(char[] str, char[] substr);
int STRSTR(char[] str, char[] substr);
char[] нач_подстрок(char[] str, char[] substr);
char[] НАЧ_ПОДСТРОК(char[] str, char[] substr);
int нач_подстрок(char[] str, char[] substr);
int НАЧ_ПОДСТРОК(char[] str, char[] substr);
```
* **Семантика**
* Функция `strncpy` (`копир_н_симв`, `STRNCPY`, `КОПИР_Н_СИМВ`) - возвращает копию первых `n` символов строки `s`
* Функция `strcat` (`конкат_строки`, `STRCAT`, `КОНКАТ_СТРОКИ`) - возвращает результат конкатенации строк `s1` и `s2`
* Функция `strncat` (`конкат_н_симв`, `STRNCAT`, `КОНКАТ_Н_СИМВ`) - возвращает результат конкатенации строки `s1` и первых `n` символов строки `s2`
* Функция `strcmp` (`сравн_строк` `STRCMP`, `СРАВН_СТРОК`) - возвращает результат лексикографического сравнения строк `s1` и `s2`: если s1 лексикографически чем s2, результат отрицательный. Если s2 лексикографически меньше, чем s1, результат положительный. Если строки равны, результат равен 0
* Функция `strncmp` (`сравн_н_симв`, `STRNCMP`, `СРАВН_Н_СИМВ`) - возвращает результат лексикографического сравнения первых `n` символов строк s1 и s2
* Функция `strstr` (`нач_подстрок`, `STRSTR`, `НАЧ_ПОДСТРОК`) - возвращает индекс первого вхождения строки `substr` в строку `str`
Expand Down
3 changes: 0 additions & 3 deletions libs/compiler/instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ instruction_t builtin_to_instruction(const builtin_t func)
case BI_ASIN: return IC_ASIN;
case BI_RAND: return IC_RAND;
case BI_ROUND: return IC_ROUND;
case BI_STRCPY: return IC_STRCPY;
case BI_STRNCPY: return IC_STRNCPY;
case BI_STRCAT: return IC_STRCAT;
case BI_STRNCAT: return IC_STRNCAT;
case BI_STRCMP: return IC_STRCMP;
case BI_STRNCMP: return IC_STRNCMP;
case BI_STRSTR: return IC_STRSTR;
case BI_STRLEN: return IC_STRLEN;
case BI_ASSERT: return IC_ASSERT;
case BI_MSG_SEND: return IC_MSG_SEND;
case BI_MSG_RECEIVE: return IC_MSG_RECEIVE;
Expand Down
69 changes: 33 additions & 36 deletions libs/compiler/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,52 +173,49 @@ typedef enum builtin
BI_ROUND = 38,

// String functions
BI_STRCPY = 42,
BI_STRNCPY = 46,
BI_STRCAT = 50,
BI_STRNCAT = 54,
BI_STRCMP = 58,
BI_STRNCMP = 62,
BI_STRSTR = 66,
BI_STRLEN = 70,
BI_STRNCPY = 42,
BI_STRCAT = 46,
BI_STRCMP = 50,
BI_STRNCMP = 54,
BI_STRSTR = 58,

// Robot functions
BI_ROBOT_SEND_INT = 74,
BI_ROBOT_SEND_FLOAT = 78,
BI_ROBOT_SEND_STRING = 82,
BI_ROBOT_RECEIVE_INT = 86,
BI_ROBOT_RECEIVE_FLOAT = 90,
BI_ROBOT_RECEIVE_STRING = 94,
BI_ROBOT_SEND_INT = 62,
BI_ROBOT_SEND_FLOAT = 66,
BI_ROBOT_SEND_STRING = 70,
BI_ROBOT_RECEIVE_INT = 74,
BI_ROBOT_RECEIVE_FLOAT = 78,
BI_ROBOT_RECEIVE_STRING = 82,

// Thread functions
BI_T_CREATE = 98,
BI_T_GETNUM = 102,
BI_T_SLEEP = 106,
BI_T_JOIN = 110,
BI_T_EXIT = 114,
BI_T_INIT = 118,
BI_T_DESTROY = 122,
BI_T_CREATE = 86,
BI_T_GETNUM = 90,
BI_T_SLEEP = 94,
BI_T_JOIN = 98,
BI_T_EXIT = 102,
BI_T_INIT = 106,
BI_T_DESTROY = 110,

BI_SEM_CREATE = 126,
BI_SEM_WAIT = 130,
BI_SEM_POST = 134,
BI_SEM_CREATE = 114,
BI_SEM_WAIT = 118,
BI_SEM_POST = 122,

BI_MSG_SEND = 138,
BI_MSG_RECEIVE = 142,
BI_MSG_SEND = 126,
BI_MSG_RECEIVE = 130,

BI_FOPEN = 146,
BI_FGETC = 150,
BI_FPUTC = 154,
BI_FCLOSE = 158,
BI_FOPEN = 134,
BI_FGETC = 138,
BI_FPUTC = 142,
BI_FCLOSE = 146,

BI_EXIT = 162,
BI_EXIT = 150,

BI_PRINTF = 166,
BI_PRINT = 170,
BI_PRINTID = 174,
BI_GETID = 178,
BI_PRINTF = 154,
BI_PRINT = 158,
BI_PRINTID = 162,
BI_GETID = 166,

BEGIN_USER_FUNC = 182,
BEGIN_USER_FUNC = 170,
} builtin_t;


Expand Down
7 changes: 2 additions & 5 deletions libs/compiler/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,11 @@ static void ident_init(syntax *const sx)
builtin_add(sx, U"rand", U"случ", type_function(sx, TYPE_FLOATING, ""));
builtin_add(sx, U"round", U"округл", type_function(sx, TYPE_INTEGER, "f"));

builtin_add(sx, U"strcpy", U"копир_строку", type_function(sx, TYPE_VOID, "Ss"));
builtin_add(sx, U"strncpy", U"копир_н_симв", type_function(sx, TYPE_VOID, "Ssi"));
builtin_add(sx, U"strcat", U"конкат_строки", type_function(sx, TYPE_VOID, "Ss"));
builtin_add(sx, U"strncat", U"конкат_н_симв", type_function(sx, TYPE_VOID, "Ssi"));
builtin_add(sx, U"strncpy", U"копир_н_симв", type_function(sx, type_string(sx), "si"));
builtin_add(sx, U"strcat", U"конкат_строки", type_function(sx, type_string(sx), "ss"));
builtin_add(sx, U"strcmp", U"сравн_строк", type_function(sx, TYPE_INTEGER, "ss"));
builtin_add(sx, U"strncmp", U"сравн_н_симв", type_function(sx, TYPE_INTEGER, "ssi"));
builtin_add(sx, U"strstr", U"нач_подстрок", type_function(sx, TYPE_INTEGER, "ss"));
builtin_add(sx, U"strlen", U"длина", type_function(sx, TYPE_INTEGER, "s"));

builtin_add(sx, U"send_int_to_robot", U"послать_цел_на_робот", type_function(sx, TYPE_VOID, "iI"));
builtin_add(sx, U"send_float_to_robot", U"послать_вещ_на_робот", type_function(sx, TYPE_VOID, "iF"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ void main()

printid(s1);
printid(s2);
strcat(&s1, s2);
char s3[] = strcat(s1, s2);

printid(s1);
strcat(&s1, "123");
printid(s1);
printid(s3);
char s4[] = strcat(s1, "123");
printid(s4);


}

This file was deleted.

8 changes: 0 additions & 8 deletions tests/codegen/executable/arrays/string/strlen/egor.c

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ void main()
char s2[] = "werty";
printid(s1);
printid(s2);
STRNCPY(&s1, "dfgh", 3);
s1 = STRNCPY("dfgh", 3);
print(s1);
}
}

0 comments on commit 35783b1

Please sign in to comment.