1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 22:53:16 +00:00

Remove tostring in favor of string.

This commit is contained in:
bakpakin 2017-07-03 22:20:39 -04:00
parent eeeb660120
commit eef8a42ae7
2 changed files with 22 additions and 12 deletions

View File

@ -153,6 +153,7 @@ int gst_stl_##name(Gst *vm) {\
COMPARE_FUNCTION(lessthan, gst_compare(lhs, rhs) < 0) COMPARE_FUNCTION(lessthan, gst_compare(lhs, rhs) < 0)
COMPARE_FUNCTION(greaterthan, gst_compare(lhs, rhs) > 0) COMPARE_FUNCTION(greaterthan, gst_compare(lhs, rhs) > 0)
COMPARE_FUNCTION(equal, gst_equals(lhs, rhs)) COMPARE_FUNCTION(equal, gst_equals(lhs, rhs))
COMPARE_FUNCTION(notequal, !gst_equals(lhs, rhs))
COMPARE_FUNCTION(lessthaneq, gst_compare(lhs, rhs) <= 0) COMPARE_FUNCTION(lessthaneq, gst_compare(lhs, rhs) <= 0)
COMPARE_FUNCTION(greaterthaneq, gst_compare(lhs, rhs) >= 0) COMPARE_FUNCTION(greaterthaneq, gst_compare(lhs, rhs) >= 0)
@ -428,10 +429,15 @@ int gst_stl_string(Gst *vm) {
uint32_t slen; uint32_t slen;
/* Find length and assert string arguments */ /* Find length and assert string arguments */
for (j = 0; j < count; ++j) { for (j = 0; j < count; ++j) {
if (gst_chararray_view(gst_arg(vm, j), &dat, &slen)) if (!gst_chararray_view(gst_arg(vm, j), &dat, &slen)) {
length += slen; GstValue newarg;
else dat = gst_to_string(vm, gst_arg(vm, j));
gst_c_throwc(vm, GST_EXPECTED_STRING); slen = gst_string_length(dat);
newarg.type = GST_STRING;
newarg.data.string = dat;
gst_set_arg(vm, j, newarg);
}
length += slen;
} }
/* Make string */ /* Make string */
str = gst_string_begin(vm, length); str = gst_string_begin(vm, length);
@ -626,13 +632,6 @@ int gst_stl_short_description(Gst *vm) {
gst_c_return(vm, gst_wrap_string(buf)); gst_c_return(vm, gst_wrap_string(buf));
} }
/* To string. Like long description, but if passed a string,
* will retun it unchanged. Buffers will return their contents as a string. */
int gst_stl_tostring(Gst *vm) {
const uint8_t *string = gst_to_string(vm, gst_arg(vm, 0));
gst_c_return(vm, gst_wrap_string(string));
}
/* Exit */ /* Exit */
int gst_stl_exit(Gst *vm) { int gst_stl_exit(Gst *vm) {
int ret; int ret;
@ -1055,6 +1054,7 @@ static const GstModuleItem std_module[] = {
{"<", gst_stl_lessthan}, {"<", gst_stl_lessthan},
{">", gst_stl_greaterthan}, {">", gst_stl_greaterthan},
{"=", gst_stl_equal}, {"=", gst_stl_equal},
{"not=", gst_stl_notequal},
{"<=", gst_stl_lessthaneq}, {"<=", gst_stl_lessthaneq},
{">=", gst_stl_greaterthaneq}, {">=", gst_stl_greaterthaneq},
/* Bitwise arithmetic */ /* Bitwise arithmetic */
@ -1100,7 +1100,6 @@ static const GstModuleItem std_module[] = {
{"current", gst_stl_current}, {"current", gst_stl_current},
{"parent", gst_stl_parent}, {"parent", gst_stl_parent},
{"print", gst_stl_print}, {"print", gst_stl_print},
{"tostring", gst_stl_tostring},
{"description", gst_stl_description}, {"description", gst_stl_description},
{"short-description", gst_stl_short_description}, {"short-description", gst_stl_short_description},
{"exit!", gst_stl_exit}, {"exit!", gst_stl_exit},

View File

@ -391,6 +391,12 @@ int gst_continue(Gst *vm) {
vm->thread->status = GST_THREAD_DEAD; vm->thread->status = GST_THREAD_DEAD;
if (vm->thread->parent) { if (vm->thread->parent) {
vm->thread = vm->thread->parent; vm->thread = vm->thread->parent;
if (vm->thread->status == GST_THREAD_ALIVE) {
/* If the parent thread is still alive,
we are inside a cfunction */
vm->ret = temp;
return GST_RETURN_OK;
}
stack = vm->thread->data + vm->thread->count; stack = vm->thread->data + vm->thread->count;
} else { } else {
vm->ret = temp; vm->ret = temp;
@ -411,6 +417,11 @@ int gst_continue(Gst *vm) {
if (vm->thread->errorParent == NULL) if (vm->thread->errorParent == NULL)
return GST_RETURN_ERROR; return GST_RETURN_ERROR;
vm->thread = vm->thread->errorParent; vm->thread = vm->thread->errorParent;
if (vm->thread->status == GST_THREAD_ALIVE) {
/* If the parent thread is still alive,
we are inside a cfunction */
return GST_RETURN_ERROR;
}
} }
vm->thread->status = GST_THREAD_ALIVE; vm->thread->status = GST_THREAD_ALIVE;
stack = vm->thread->data + vm->thread->count; stack = vm->thread->data + vm->thread->count;