1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-01 08:03:02 +00:00

Add symbol function

This commit is contained in:
bakpakin
2017-07-03 11:21:10 -04:00
parent 0cf278994d
commit 961275116f
5 changed files with 27 additions and 25 deletions

View File

@@ -161,14 +161,12 @@ static GstValue build_token(GstParser *p, GstBuffer *buf) {
if (buf->data[0] >= '0' && buf->data[0] <= '9') {
p_error(p, "symbols cannot start with digits");
x.type = GST_NIL;
} else if (buf->data[0] == ':' && buf->count >= 2) {
x.type = GST_STRING;
x.data.string = gst_string_b(p->vm, buf->data + 1, buf->count - 1);
} else {
if (buf->data[0] == ':' && buf->count >= 2) {
x.type = GST_STRING;
x.data.string = gst_string_b(p->vm, buf->data + 1, buf->count - 1);
} else {
x.type = GST_SYMBOL;
x.data.string = gst_buffer_to_string(p->vm, buf);
}
x.type = GST_SYMBOL;
x.data.string = gst_buffer_to_string(p->vm, buf);
}
}
return x;
@@ -238,11 +236,6 @@ static int string_state(GstParser *p, uint8_t c) {
top->buf.string.count = 0;
top->buf.string.accum = 0;
return 1;
case 'u':
top->buf.string.state = STRING_STATE_ESCAPE_HEX;
top->buf.string.count = 0;
top->buf.string.accum = 0;
return 1;
default:
p_error(p, "unknown string escape sequence");
return 1;

View File

@@ -443,6 +443,15 @@ int gst_stl_string(Gst *vm) {
gst_c_return(vm, gst_wrap_string(gst_string_end(vm, str)));
}
/* Create a symbol */
int gst_stl_symbol(Gst *vm) {
int ret = gst_stl_string(vm);
if (ret == GST_RETURN_OK) {
vm->ret.type = GST_SYMBOL;
}
return ret;
}
/* Create a thread */
int gst_stl_thread(Gst *vm) {
GstThread *t;
@@ -598,8 +607,6 @@ int gst_stl_print(Gst *vm) {
uint32_t len = gst_string_length(string);
for (i = 0; i < len; ++i)
fputc(string[i], stdout);
if (j < count - 1)
fputc(' ', stdout);
}
fputc('\n', stdout);
return GST_RETURN_OK;
@@ -1087,6 +1094,7 @@ static const GstModuleItem std_module[] = {
{"struct", gst_stl_struct},
{"buffer", gst_stl_buffer},
{"string", gst_stl_string},
{"symbol", gst_stl_symbol},
{"thread", gst_stl_thread},
{"status", gst_stl_status},
{"current", gst_stl_current},