-
Notifications
You must be signed in to change notification settings - Fork 1
/
dictnext.c
73 lines (65 loc) · 2.03 KB
/
dictnext.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
#include <stdlib.h>
#include "amyplanyyutils.h"
char *str =
"@function $test()\n"
" @locvar $dict = {\"a\": 1, \"c\": 3, \"b\": 2}\n"
" @locvar $k = @nil\n"
" @locvar $v = @nil\n"
" @dump(\"Next begin\")\n"
" @dump(@dictnext($dict, @nil))\n"
" @dump(@dictnext($dict, \"a\"))\n"
" @dump(@dictnext($dict, \"b\"))\n"
" @dump(@dictnext($dict, \"c\"))\n"
" @dump(\"Next end\")\n"
" @dump(\"Prev begin\")\n"
" @dump(@dictprev($dict, @nil))\n"
" @dump(@dictprev($dict, \"c\"))\n"
" @dump(@dictprev($dict, \"b\"))\n"
" @dump(@dictprev($dict, \"a\"))\n"
" @dump(\"Prev end\")\n"
" @dump(\"Iter begin\")\n"
" @fordict $k, $v ($dict)\n"
" @dump(\"Pair:\")\n"
" @dump($k)\n"
" @dump($v)\n"
" @endfor\n"
" @dump(\"Iter end\")\n"
" @dump(\"Rev Iter begin\")\n"
" @fordictprev $k, $v ($dict)\n"
" @dump(\"Pair:\")\n"
" @dump($k)\n"
" @dump($v)\n"
" @endfor\n"
" @dump(\"Rev Iter end\")\n"
"@endfunction\n";
int main(int argc, char **argv)
{
FILE *f = fmemopen(str, strlen(str), "r");
struct amyplanyy amyplanyy = {};
unsigned char tmpbuf[1024] = {0};
size_t tmpsiz = 0;
amyplanyy_init(&amyplanyy);
if (!f)
{
abort();
}
amyplanyydoparse(f, &amyplanyy);
fclose(f);
{
tmpsiz = 0;
amyplanyy.abce.sp = 0;
abce_add_ins_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), ABCE_OPCODE_PUSH_DBL);
abce_add_double_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf),
abce_sc_get_rec_str_fun(&amyplanyy.abce.dynscope, "test", 1));
abce_add_ins_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), ABCE_OPCODE_FUNIFY);
abce_add_ins_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), ABCE_OPCODE_PUSH_DBL);
abce_add_double_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), 0); // arg cnt
abce_add_ins_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), ABCE_OPCODE_CALL);
abce_add_ins_alt(tmpbuf, &tmpsiz, sizeof(tmpbuf), ABCE_OPCODE_EXIT);
printf("ret %d\n", abce_engine(&amyplanyy.abce, tmpbuf, tmpsiz));
printf("sp %zu\n", amyplanyy.abce.sp);
printf("\n");
}
amyplanyy_free(&amyplanyy);
return 0;
}