-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltins.h
44 lines (35 loc) · 1.56 KB
/
builtins.h
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
#include "arithmetica.h"
#include "namespace.h"
/**
* The module for the built-ins functions of Viper language.
* Each function represents the structure with name, pointer & count of input arguments.
* The type of input arguments is always the container Constant
*/
#ifndef VIPER_V4_BUILTINS_H
#define VIPER_V4_BUILTINS_H
#define BUILTIN_FUNCTION_LEN_INVALID_TYPE "the built-in function `len` having invalid arg. type"
#define BUILTIN_FUNCTION_INPUT_INVALID_TYPE "the built-in function `input` having invalid arg. type"
#define BUILTIN_FUNCTION_TO_STRING_INVALID_TYPE "the built-in function 'string' having invalid arg. type"
#define BUILTIN_FUNCTION_TO_INTEGER_SYNTAX_ERROR "the string representing of integer value have syntax error"
#define BUILTIN_FUNCTION_TO_INTEGER_INVALID_TYPE "the built-in function 'integer' having invalid arg. type"
typedef struct BuiltIn {
char * name;
void * function_pointer;
int args;
} BuiltIn;
/* Create the new BuiltIn structure */
BuiltIn * new_builtin(char * name, void * function_pointer, int args);
/* Execute the builtin function */
Constant * builtin_function_execute(BuiltIn * builtin, Array ** input_args);
/* Download the built-in function into namespace */
void import_builtins(Node * namespace);
/* Input/Output */
Constant * output(Constant * value);
Constant * input(Constant * value);
/* Get length of array */
Constant * len(Constant * value);
/* Typecasting */
Constant * to_string(Constant * value);
Constant * to_int(Constant * value);
Constant * to_float(Constant * value);
#endif //VIPER_V4_BUILTINS_H