aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-25 09:54:37 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-25 09:54:37 +0100
commit5df950e0b35207930c645e8ce0c3e9ed1c9fcea5 (patch)
tree8264595bea95b6d0dcc530566168f2030dfe06ff
parent4b2b8d3176e84f76510cc69a627dbfa089c1dd35 (diff)
string view > string ref
-rw-r--r--include/value.h6
-rw-r--r--src/program.c12
-rw-r--r--src/value.c24
3 files changed, 23 insertions, 19 deletions
diff --git a/include/value.h b/include/value.h
index d9c6354..7dd6d28 100644
--- a/include/value.h
+++ b/include/value.h
@@ -12,7 +12,7 @@ typedef enum {
TSL_TYPE_NULL,
TSL_TYPE_NUMBER,
TSL_TYPE_STRING,
- TSL_TYPE_STRING_VIEW,
+ TSL_TYPE_STRING_REF,
TSL_TYPE_BOOL,
TSL_TYPE_LIST,
TSL_TYPE_MAP,
@@ -29,7 +29,7 @@ typedef enum {
} TslBool;
typedef struct {
- uint8_t *data;
+ char *data;
size_t size;
} TslString;
@@ -40,7 +40,7 @@ struct TslValue {
union {
TslNumber number;
TslString *string;
- TslStringView string_view;
+ TslStringView string_ref;
TslBool boolean;
TslBool null;
TslList *list;
diff --git a/src/program.c b/src/program.c
index dc7fe8d..78533f6 100644
--- a/src/program.c
+++ b/src/program.c
@@ -61,6 +61,7 @@ static TslProgramResult tsl_value_create_from_stack_value(TslProgram *self, TslS
break;
}
case TSL_STACK_VALUE_TYPE_STRING: {
+ #if 0
TslString *str = GC_MALLOC_ATOMIC(sizeof(TslString));
str->data = GC_MALLOC_ATOMIC(src->data.str.size + 1);
if(!str) {
@@ -82,6 +83,9 @@ static TslProgramResult tsl_value_create_from_stack_value(TslProgram *self, TslS
dst->data.string = str;
dst->type = TSL_TYPE_STRING;
+ #endif
+ dst->data.string_ref = src->data.str;
+ dst->type = TSL_TYPE_STRING_REF;
break;
}
case TSL_STACK_VALUE_TYPE_FUNCTION: {
@@ -92,8 +96,8 @@ static TslProgramResult tsl_value_create_from_stack_value(TslProgram *self, TslS
case TSL_STACK_VALUE_TYPE_VARIABLE: {
TslValue *var;
TslValue map_key;
- map_key.type = TSL_TYPE_STRING_VIEW;
- map_key.data.string_view = src->data.str;
+ map_key.type = TSL_TYPE_STRING_REF;
+ map_key.data.string_ref = src->data.str;
var = tsl_hash_map_get(self->variables, &map_key);
if(!var) {
@@ -278,8 +282,8 @@ TslProgramResult tsl_program_run(TslProgram *self) {
TslStackValue *stack_value = tsl_buffer_pop(&self->stack_values, sizeof(TslStackValue));
TslValue map_key;
TslValue *map_value;
- map_key.type = TSL_TYPE_STRING_VIEW;
- map_key.data.string_view = instruction_type4->value;
+ map_key.type = TSL_TYPE_STRING_REF;
+ map_key.data.string_ref = instruction_type4->value;
map_value = tsl_hash_map_get_or_create(self->variables, &map_key);
cleanup_if_error(map_value);
diff --git a/src/value.c b/src/value.c
index c08048a..1a76880 100644
--- a/src/value.c
+++ b/src/value.c
@@ -18,9 +18,9 @@ uint64_t tsl_value_hash(const TslValue *key) {
case TSL_TYPE_NUMBER:
return *(uint64_t*)&key->data.number;
case TSL_TYPE_STRING:
- return hash_range(key->data.string->data, key->data.string->size);
- case TSL_TYPE_STRING_VIEW:
- return hash_range((uint8_t*)key->data.string_view.data, key->data.string_view.size);
+ return hash_range((uint8_t*)key->data.string->data, key->data.string->size);
+ case TSL_TYPE_STRING_REF:
+ return hash_range((uint8_t*)key->data.string_ref.data, key->data.string_ref.size);
case TSL_TYPE_BOOL:
return key->data.boolean;
case TSL_TYPE_LIST:
@@ -40,18 +40,18 @@ int tsl_value_equals(const TslValue *lhs, const TslValue *rhs) {
if(lhs->type == TSL_TYPE_STRING) {
return lhs->data.string->size == rhs->data.string->size
&& memcmp(lhs->data.string->data, rhs->data.string->data, lhs->data.string->size) == 0;
- } else if(lhs->type == TSL_TYPE_STRING_VIEW) {
- return lhs->data.string_view.size == rhs->data.string_view.size
- && memcmp(lhs->data.string_view.data, rhs->data.string_view.data, lhs->data.string_view.size) == 0;
+ } else if(lhs->type == TSL_TYPE_STRING_REF) {
+ return lhs->data.string_ref.size == rhs->data.string_ref.size
+ && memcmp(lhs->data.string_ref.data, rhs->data.string_ref.data, lhs->data.string_ref.size) == 0;
} else {
return *(uint64_t*)&lhs->data == *(uint64_t*)&rhs->data;
}
- } else if(lhs->type == TSL_TYPE_STRING && rhs->type == TSL_TYPE_STRING_VIEW) {
- return lhs->data.string->size == rhs->data.string_view.size
- && memcmp(lhs->data.string->data, rhs->data.string_view.data, lhs->data.string->size) == 0;
- } else if(lhs->type == TSL_TYPE_STRING_VIEW && rhs->type == TSL_TYPE_STRING) {
- return lhs->data.string_view.size == rhs->data.string->size
- && memcmp(lhs->data.string_view.data, rhs->data.string->data, lhs->data.string_view.size) == 0;
+ } else if(lhs->type == TSL_TYPE_STRING && rhs->type == TSL_TYPE_STRING_REF) {
+ return lhs->data.string->size == rhs->data.string_ref.size
+ && memcmp(lhs->data.string->data, rhs->data.string_ref.data, lhs->data.string->size) == 0;
+ } else if(lhs->type == TSL_TYPE_STRING_REF && rhs->type == TSL_TYPE_STRING) {
+ return lhs->data.string_ref.size == rhs->data.string->size
+ && memcmp(lhs->data.string_ref.data, rhs->data.string->data, lhs->data.string_ref.size) == 0;
} else {
return 0;
}