-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrb_runtime.c
More file actions
51 lines (42 loc) · 957 Bytes
/
crb_runtime.c
File metadata and controls
51 lines (42 loc) · 957 Bytes
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
#include "crb_runtime.h"
#include "util/crb_util.h"
#include <stdio.h>
#include <string.h>
int crb_add_gloabl_function(struct crb_interpreter *itp,
char *name, crb_native_function func)
{
crb_assert(itp != NULL && name != NULL && func != NULL, return -1);
struct crb_function f = {
.is_native_function = 1,
.u = {
.native_function = func
}
};
struct crb_value v = {
.type = CRB_FUNCTION_VALUE,
.u = {
.function_value = f
}
};
return crb_interpreter_set_global_variable(itp, name, v);
}
int crb_setup_interpreter(struct crb_interpreter *itp)
{
crb_assert(itp != NULL, return -1);
return crb_add_gloabl_function(itp, strdup("print"), crb_print);
}
struct crb_value crb_print(void *self, int argc, struct crb_value *args)
{
for (int i = 0; i < argc; ++i) {
crb_value_print(args[i]);
// printf(" ");
}
//printf("\n");
struct crb_value v = {
.type = CRB_INT_VALUE,
.u = {
.int_value = argc
}
};
return v;
}