forked from HuoLanguage/huo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply_core_function.c
47 lines (45 loc) · 1.16 KB
/
apply_core_function.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
#include "constants.h"
#include "structures.h"
#include "core_functions.h"
#include "base_util.h"
struct Value apply_core_function(struct Tree * ast, struct Value a, struct Value b){
if(ast->type == 'k'){
if(string_matches(&ast->content.data.str, &concat_const)){
a = concat(a, b);
}
else if(string_matches(&ast->content.data.str, &index_const)){
a = array_index(a, b);
}
else if(string_matches(&ast->content.data.str, &push_const)){
a = array_push(a, b);
}
else if(string_matches(&split_const, &ast->content.data.str)){
a = split_string(a, b);
}
}
else if(ast->type == '*'){
a = mul(a, b);
}
else if(ast->type == '+'){
a = add(a, b);
}
else if(ast->type == '-'){
a = sub(a, b);
}
else if(ast->type == '/'){
a = divide(a, b);
}
else if(ast->type == '!'){
a = not(a, b);
}
else if(ast->type == '='){
a = equals(a, b);
}
else if(ast->type == '>'){
a = greater_than(a, b);
}
else if(ast->type == '<'){
a = greater_than(b, a);
}
return a;
}