-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.conversion.c
157 lines (130 loc) · 3.02 KB
/
interpreter.conversion.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* The MIT License (MIT)
*
* Copyright (c) 2021 - 2022 TheVice
*
*/
#include "conversion.h"
#include "common.h"
#include "range.h"
enum conversion_function
{
parse, to_string,
UNKNOWN_CONVERSION
};
uint8_t conversion_get_function(
const uint8_t* name_start, const uint8_t* name_finish)
{
static const uint8_t* conversion_str[] =
{
(const uint8_t*)"parse",
(const uint8_t*)"to-string"
};
/**/
return common_string_to_enum(
name_start, name_finish,
conversion_str, UNKNOWN_CONVERSION);
}
uint8_t bool_exec_function(
uint8_t function, const void* arguments, uint8_t arguments_count,
void* output)
{
if (UNKNOWN_CONVERSION <= function ||
!arguments ||
1 != arguments_count ||
!output)
{
return 0;
}
struct range argument;
if (!common_get_arguments(arguments, arguments_count, &argument, 0))
{
return 0;
}
switch (function)
{
case parse:
case to_string:
if (!bool_parse(argument.start, argument.finish, &function))
{
break;
}
return bool_to_string(function, output);
case UNKNOWN_CONVERSION:
default:
break;
}
return 0;
}
enum conversion_name_space
{
double_functions, int_functions,
long_functions, int64_functions,
UNKNOWN_FUNCTIONS
};
uint8_t conversion_exec_function(
uint8_t name_space, uint8_t function,
const void* arguments, uint8_t arguments_count, void* output)
{
if (UNKNOWN_CONVERSION <= function ||
!arguments ||
1 != arguments_count ||
!output)
{
return 0;
}
struct range argument;
if (!common_get_arguments(arguments, arguments_count, &argument, 1))
{
return 0;
}
switch (function)
{
case parse:
case to_string:
switch (name_space)
{
case double_functions:
return double_to_string(double_parse(argument.start), output);
case int_functions:
return int_to_string(int_parse(argument.start, argument.finish), output);
case long_functions:
#if !defined(_WIN32)
return long_to_string(long_parse(argument.start, argument.finish), output);
#endif
case int64_functions:
return int64_to_string(int64_parse(argument.start, argument.finish), output);
case UNKNOWN_FUNCTIONS:
default:
break;
}
case UNKNOWN_CONVERSION:
default:
break;
}
return 0;
}
uint8_t double_exec_function(
uint8_t function, const void* arguments, uint8_t arguments_count,
void* output)
{
return conversion_exec_function(double_functions, function, arguments, arguments_count, output);
}
uint8_t int_exec_function(
uint8_t function, const void* arguments, uint8_t arguments_count,
void* output)
{
return conversion_exec_function(int_functions, function, arguments, arguments_count, output);
}
uint8_t long_exec_function(
uint8_t function, const void* arguments, uint8_t arguments_count,
void* output)
{
return conversion_exec_function(long_functions, function, arguments, arguments_count, output);
}
uint8_t int64_exec_function(
uint8_t function, const void* arguments, uint8_t arguments_count,
void* output)
{
return conversion_exec_function(int64_functions, function, arguments, arguments_count, output);
}