forked from microsoft/devicescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm_util.c
More file actions
47 lines (39 loc) · 1.19 KB
/
vm_util.c
File metadata and controls
47 lines (39 loc) · 1.19 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
#include "devs_internal.h"
#include "devs_vm_internal.h"
//
// Pop utils
//
static inline value_t pop_arg(devs_ctx_t *ctx) {
if (ctx->stack_top == 0)
return devs_invalid_program(ctx, 60108);
return ctx->the_stack[--ctx->stack_top];
}
value_t devs_vm_pop_arg(devs_ctx_t *ctx) {
return pop_arg(ctx);
}
uint32_t devs_vm_pop_arg_u32(devs_ctx_t *ctx) {
// TODO int vs uint?
return devs_value_to_int(ctx, pop_arg(ctx));
}
int32_t devs_vm_pop_arg_i32(devs_ctx_t *ctx) {
return devs_value_to_int(ctx, pop_arg(ctx));
}
double devs_vm_pop_arg_f64(devs_ctx_t *ctx) {
return devs_value_to_double(ctx, pop_arg(ctx));
}
value_t devs_vm_pop_arg_buffer(devs_ctx_t *ctx, int flags) {
value_t tmp = pop_arg(ctx);
if (!devs_is_buffer(ctx, tmp)) {
if ((flags & DEVS_BUFFER_STRING_OK) && devs_is_string(ctx, tmp)) {
// OK
} else {
devs_throw_expecting_error(ctx, DEVS_BUILTIN_STRING_BUFFER, tmp);
return devs_undefined;
}
}
if ((flags & DEVS_BUFFER_RW) && !devs_buffer_is_writable(ctx, tmp)) {
devs_throw_expecting_error_ext(ctx, "mutable Buffer", tmp);
return devs_undefined;
}
return tmp;
}