Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
89 lines (75 loc) · 2.63 KB

File metadata and controls

89 lines (75 loc) · 2.63 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include "devs_internal.h"
value_t prop_Array_length(devs_ctx_t *ctx, value_t self) {
if (!devs_is_array(ctx, self))
return devs_throw_expecting_error(ctx, DEVS_BUILTIN_STRING_ARRAY, self);
devs_array_t *arr = devs_handle_ptr_value(ctx, self);
return devs_value_from_int(arr->length);
}
static devs_array_t *devs_arg_self_array(devs_ctx_t *ctx) {
value_t s = devs_arg_self(ctx);
if (devs_is_array(ctx, s))
return (devs_array_t *)devs_handle_ptr_value(ctx, s);
devs_throw_expecting_error(ctx, DEVS_BUILTIN_STRING_ARRAY, s);
return NULL;
}
void meth2_Array_insert(devs_ctx_t *ctx) {
devs_array_t *self = devs_arg_self_array(ctx);
if (self) {
uint32_t idx = devs_arg_int(ctx, 0);
int32_t count = devs_arg_int(ctx, 1);
devs_array_insert(ctx, self, idx, count);
}
}
void fun1_Array_isArray(devs_ctx_t *ctx) {
devs_ret_bool(ctx, devs_is_array(ctx, devs_arg(ctx, 0)));
}
void methX_Array_push(devs_ctx_t *ctx) {
devs_array_t *self = devs_arg_self_array(ctx);
if (!self)
return;
for (int i = 0; i < ctx->stack_top_for_gc - 1; ++i) {
devs_array_set(ctx, self, self->length, devs_arg(ctx, i));
}
devs_ret_int(ctx, self->length);
}
void meth1_Array_pushRange(devs_ctx_t *ctx) {
devs_array_t *self = devs_arg_self_array(ctx);
if (!self)
return;
value_t other = devs_arg(ctx, 0);
if (!devs_is_array(ctx, other)) {
devs_throw_expecting_error(ctx, DEVS_BUILTIN_STRING_ARRAY, other);
return;
}
devs_array_t *src = devs_value_to_gc_obj(ctx, other);
if (src->length) {
// note that self and src can alias
unsigned len_src = src->length;
unsigned len0 = self->length;
if (devs_array_insert(ctx, self, self->length, len_src) == 0) {
memcpy(self->data + len0, src->data, len_src * sizeof(value_t));
}
}
devs_ret_int(ctx, self->length);
}
void methX_Array_slice(devs_ctx_t *ctx) {
devs_array_t *self = devs_arg_self_array(ctx);
unsigned numargs = ctx->stack_top_for_gc - 1;
int32_t len = self->length;
int32_t start = numargs > 0 ? devs_arg_int(ctx, 0) : 0;
if (start < 0)
start = len + start;
if (start < 0)
start = 0;
int32_t end = numargs > 1 && !devs_is_undefined(devs_arg(ctx, 1)) ? devs_arg_int(ctx, 1) : len;
if (end < 0)
end = len + end;
if (end > len)
end = len;
if (start > end)
start = end;
devs_array_t *res = devs_array_try_alloc(ctx, end - start);
if (res)
memcpy(res->data, self->data + start, (end - start) * sizeof(value_t));
devs_ret_gc_ptr(ctx, res);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.