-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathivm-api.c
More file actions
109 lines (91 loc) · 2.05 KB
/
Copy pathivm-api.c
File metadata and controls
109 lines (91 loc) · 2.05 KB
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
// The API of IVM, uses IMM, to compile use make.
#include "ivm.h"
Intcon_t *g_api_init()
{
Intcon_t *ctx = obj_create ();
ctx->pc = 0;
memset (ctx->bytecode, 0, sizeof (ctx->bytecode));
obj_kick (ctx);
return ctx;
}
void g_api_save (Intcon_t *ctx, const char *filename)
{
obj_savefile (ctx, filename);
}
void g_api_load (Intcon_t *ctx, const char *filename)
{
obj_loadfile (ctx, filename);
}
void g_push_int (Intcon_t *ctx, int value)
{
emit_byte (ctx, G_PUSH_INT);
emit_integer (ctx, value);
}
void g_push_double (Intcon_t *ctx, double value)
{
emit_byte (ctx, G_PUSH_DOUBLE);
emit_double (ctx, value);
}
void g_push_float (Intcon_t *ctx, float value)
{
emit_byte (ctx, G_PUSH_FLOAT);
emit_float (ctx, value);
}
void g_push_string (Intcon_t *ctx, const char *string)
{
emit_byte (ctx, G_PUSH_STRING);
emit_string (ctx, string);
}
void g_push_boolean (Intcon_t *ctx, bool value)
{
emit_byte (ctx, G_PUSH_BOOLEAN);
emit_integer (ctx, value);
}
int g_get_label (Intcon_t *ctx)
{
return ctx->ip;
}
void g_push_uint8 (Intcon_t *ctx, uint8_t value)
{
emit_byte (ctx, G_PUSH_UINT);
emit_byte (ctx, value);
}
void g_push_char (Intcon_t *ctx, char character)
{
emit_byte (ctx, G_PUSH_CHAR);
emit_byte (ctx, (uint8_t)character);
}
void g_debug_patch_addr (Intcon_t *ctx, int addresToPatch, int targetValue)
{
memcpy (&ctx->bytecode[addresToPatch], &targetValue, sizeof (int));
}
void g_malloc (Intcon_t *ctx, size_t size)
{
emit_byte (ctx, G_PUSH_INT);
emit_integer (ctx, (int)size);
emit_byte (ctx, G_MEMORY_ALLOCATE);
}
void g_free (Intcon_t *ctx)
{
emit_byte (ctx, G_MEMORY_FREE);
}
void g_mem_get_stats (Intcon_t *ctx)
{
emit_byte (ctx, G_PUSH_INT);
emit_integer (ctx, 1);
emit_byte (ctx, G_MEMORY_TOOL);
}
void g_mem_map (Intcon_t *ctx)
{
emit_byte (ctx, G_PUSH_INT);
emit_integer (ctx, 2);
emit_byte (ctx, G_MEMORY_TOOL);
}
void g_halt (Intcon_t *ctx)
{
emit_byte (ctx, G_HALT);
}
void g_api_corrupt (Intcon_t *ctx)
{
obj_corrupt (ctx);
}