Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions flamingo/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,6 @@ static inline flamingo_val_t* val_incref(flamingo_val_t* val);
*/
static inline flamingo_val_t* val_init(flamingo_val_t* val);

/**
* Get the string representation of a value's type.
*
* @param val The value to get the type string of.
* @return The string representation of the value's type (e.g. "integer", "string", "vector").
*/
static inline char const* val_type_str(flamingo_val_t const* val);

/**
* Get the string representation of a value's role.
*
Expand Down
10 changes: 9 additions & 1 deletion flamingo/flamingo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This Source Form is subject to the terms of the AQUA Software License, v. 1.0.
// Copyright (c) 2024 Aymeric Wibo
// Copyright (c) 2024-2026 Aymeric Wibo

#pragma once

Expand Down Expand Up @@ -474,6 +474,14 @@ flamingo_val_t* flamingo_val_make_cstr(char* str);
*/
flamingo_val_t* flamingo_val_make_bool(bool boolean);

/**
* Get the string representation of a value's type.
*
* @param val The value to get the type string of.
* @return The string representation of the value's type (e.g. "integer", "string", "vector"). This string is in .rodata.
*/
char const* flamingo_val_kind_str(flamingo_val_t const* val);

/**
* Compare two strings.
*
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int access_find_var(flamingo_t* flamingo, TSNode node, flamingo_var_t** v
}

if (*var == NULL) {
return error(flamingo, "primitive type member '%.*s' doesn't exist on expression of type %s", (int) size, accessor, val_type_str(*accessed_val));
return error(flamingo, "primitive type member '%.*s' doesn't exist on expression of type %s", (int) size, accessor, flamingo_val_kind_str(*accessed_val));
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int parse_assert(flamingo_t* flamingo, TSNode node) {
}

if (val->kind != FLAMINGO_VAL_KIND_BOOL) {
return error(flamingo, "expected boolean value for test, got %s", val_type_str(val));
return error(flamingo, "expected boolean value for test, got %s", flamingo_val_kind_str(val));
}

// If the test succeeded, exit now.
Expand Down
4 changes: 2 additions & 2 deletions flamingo/grammar/assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int parse_assignment(flamingo_t* flamingo, TSNode node) {
// - TODO This is also where the const qualifier will be checked too (but this feature is to be defined).

flamingo_val_kind_t const prev_type = val->kind;
char const* const prev_type_str = val_type_str(val);
char const* const prev_type_str = flamingo_val_kind_str(val);

if (prev_type == FLAMINGO_VAL_KIND_FN && var != NULL) {
return error(flamingo, "cannot assign to %s '%.*s'", val_role_str(val), (int) lhs_size, lhs);
Expand All @@ -100,7 +100,7 @@ static int parse_assignment(flamingo_t* flamingo, TSNode node) {
val_decref(val);
}

return error(flamingo, "cannot assign %s to '%.*s' (%s)", val_type_str(rhs), (int) lhs_size, lhs, prev_type_str);
return error(flamingo, "cannot assign %s to '%.*s' (%s)", flamingo_val_kind_str(rhs), (int) lhs_size, lhs, prev_type_str);
}

if (var != NULL) {
Expand Down
4 changes: 2 additions & 2 deletions flamingo/grammar/binary_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**
bool const none_comparison = left_val->kind == FLAMINGO_VAL_KIND_NONE || right_val->kind == FLAMINGO_VAL_KIND_NONE;

if (!same_types && !none_comparison) {
return error(flamingo, "operands have incompatible types: %s and %s", val_type_str(left_val), val_type_str(right_val));
return error(flamingo, "operands have incompatible types: %s and %s", flamingo_val_kind_str(left_val), flamingo_val_kind_str(right_val));
}

flamingo_val_kind_t const kind = left_val->kind; // Same as 'right_val->kind' by this point.
Expand Down Expand Up @@ -314,7 +314,7 @@ static int parse_binary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**
// XXX We don't actually need to decref if there's an error, as the flamingo engine will anyway be entirely freed.
// This is robust w.r.t. failures in imported flamingo engines, since we fail if the imported program fails (so the scope is freed instantly).

return error(flamingo, "unknown operator '%.*s' for type %s", (int) op_size, op, val_type_str(left_val));
return error(flamingo, "unknown operator '%.*s' for type %s", (int) op_size, op, flamingo_val_kind_str(left_val));

done:

Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int parse_call(flamingo_t* flamingo, TSNode node, flamingo_val_t** val) {
}

if (callable->kind != FLAMINGO_VAL_KIND_FN) {
return error(flamingo, "callable expression is of type %s, which is not callable", val_type_str(callable));
return error(flamingo, "callable expression is of type %s, which is not callable", flamingo_val_kind_str(callable));
}

// Evaluate arguments.
Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/for_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int parse_for_loop(flamingo_t* flamingo, TSNode node) {
elems = iterator->map.keys;
break;
default:
return error(flamingo, "expected vector or map for iterable, got %s", val_type_str(iterator));
return error(flamingo, "expected vector or map for iterable, got %s", flamingo_val_kind_str(iterator));
}

assert(elems != NULL);
Expand Down
4 changes: 2 additions & 2 deletions flamingo/grammar/if_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int parse_if_chain(flamingo_t* flamingo, TSNode node) {
}

if (val->kind != FLAMINGO_VAL_KIND_BOOL) {
return error(flamingo, "expected boolean value for if condition, got %s", val_type_str(val));
return error(flamingo, "expected boolean value for if condition, got %s", flamingo_val_kind_str(val));
}

bool const pass = val->boolean.boolean;
Expand Down Expand Up @@ -102,7 +102,7 @@ static int parse_if_chain(flamingo_t* flamingo, TSNode node) {
}

if (val->kind != FLAMINGO_VAL_KIND_BOOL) {
return error(flamingo, "expected boolean value for elif condition, got %s", val_type_str(val));
return error(flamingo, "expected boolean value for elif condition, got %s", flamingo_val_kind_str(val));
}

bool const pass = val->boolean.boolean;
Expand Down
4 changes: 2 additions & 2 deletions flamingo/grammar/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static int parse_index(flamingo_t* flamingo, TSNode node, flamingo_val_t** val,
bool const is_map = indexed_val->kind == FLAMINGO_VAL_KIND_MAP;

if (!is_vec && !is_map) {
rv = error(flamingo, "can only index vectors and maps, got %s", val_type_str(indexed_val));
rv = error(flamingo, "can only index vectors and maps, got %s", flamingo_val_kind_str(indexed_val));
goto cleanup;
}

Expand All @@ -58,7 +58,7 @@ static int parse_index(flamingo_t* flamingo, TSNode node, flamingo_val_t** val,
}

if (is_vec && index_val->kind != FLAMINGO_VAL_KIND_INT) {
rv = error(flamingo, "can only use integers as indices, got %s", val_type_str(index_val));
rv = error(flamingo, "can only use integers as indices, got %s", flamingo_val_kind_str(index_val));
goto cleanup;
}

Expand Down
2 changes: 1 addition & 1 deletion flamingo/grammar/unary_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static int parse_unary_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t**
// XXX We don't actually need to decref if there's an error, as the flamingo engine will anyway be entirely freed.
// This is robust w.r.t. failures in imported flamingo engines, since we fail if the imported program fails (so the scope is freed instantly).

return error(flamingo, "unknown operator '%.*s' for type %s", (int) op_size, op, val_type_str(operand_val));
return error(flamingo, "unknown operator '%.*s' for type %s", (int) op_size, op, flamingo_val_kind_str(operand_val));

done:

Expand Down
4 changes: 2 additions & 2 deletions flamingo/primitive_type_member.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int primitive_type_member_add(flamingo_t* flamingo, flamingo_val_kind_t t
flamingo_var_t* const var = &vars[i];

if (flamingo_strcmp(var->key, key, var->key_size, key_size) == 0) {
// XXX A little hacky and I needn't forget to update this if 'val_type_str' gets more stuff but eh.
// XXX A little hacky and I needn't forget to update this if 'flamingo_val_kind_str' gets more stuff but eh.

flamingo_val_t const dummy = {
.kind = type,
Expand All @@ -63,7 +63,7 @@ static int primitive_type_member_add(flamingo_t* flamingo, flamingo_val_kind_t t
},
};

return error(flamingo, "primitive type member '%.*s' already exists on type %s", (int) key_size, key, val_type_str(&dummy));
return error(flamingo, "primitive type member '%.*s' already exists on type %s", (int) key_size, key, flamingo_val_kind_str(&dummy));
}
}

Expand Down
6 changes: 3 additions & 3 deletions flamingo/ptm/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static inline int vec_map(flamingo_t* flamingo, flamingo_val_t* self, flamingo_a
flamingo_val_t* const fn = args->args[0];

if (fn->kind != FLAMINGO_VAL_KIND_FN) {
return error(flamingo, "'vec.map' expected 'fn' argument to be a function, got a %s", val_type_str(fn));
return error(flamingo, "'vec.map' expected 'fn' argument to be a function, got a %s", flamingo_val_kind_str(fn));
}

// Actually map the vector.
Expand Down Expand Up @@ -74,7 +74,7 @@ static inline int vec_where(flamingo_t* flamingo, flamingo_val_t* self, flamingo
flamingo_val_t* const fn = args->args[0];

if (fn->kind != FLAMINGO_VAL_KIND_FN) {
return error(flamingo, "'vec.where' expected 'fn' argument to be a function, got a %s", val_type_str(fn));
return error(flamingo, "'vec.where' expected 'fn' argument to be a function, got a %s", flamingo_val_kind_str(fn));
}

// Actually filter the vector.
Expand Down Expand Up @@ -103,7 +103,7 @@ static inline int vec_where(flamingo_t* flamingo, flamingo_val_t* self, flamingo
if (keep->kind != FLAMINGO_VAL_KIND_BOOL) {
val_free(keep);
val_free(vec);
return error(flamingo, "'vec.where' expected 'fn' to return a boolean, got a %s", val_type_str(keep));
return error(flamingo, "'vec.where' expected 'fn' to return a boolean, got a %s", flamingo_val_kind_str(keep));
}

if (!keep->boolean.boolean) {
Expand Down
4 changes: 2 additions & 2 deletions flamingo/repr.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int repr_inner(flamingo_t* flamingo, flamingo_val_t* val, char** res, boo
break;
}

asprintf(res, "<%s %.*s>", val_type_str(val), (int) val->name_size, val->name);
asprintf(res, "<%s %.*s>", flamingo_val_kind_str(val), (int) val->name_size, val->name);
break;
case FLAMINGO_VAL_KIND_INST:;
flamingo_val_t* const class = val->inst.class;
Expand All @@ -112,7 +112,7 @@ static int repr_inner(flamingo_t* flamingo, flamingo_val_t* val, char** res, boo
asprintf(res, "<instance of %.*s>", (int) class->name_size, class->name);
break;
default:
return error(flamingo, "can't print expression kind: %s (%d)", val_type_str(val), val->kind);
return error(flamingo, "can't print expression kind: %s (%d)", flamingo_val_kind_str(val), val->kind);
}

assert(*res != NULL);
Expand Down
4 changes: 2 additions & 2 deletions flamingo/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static flamingo_val_t* val_init(flamingo_val_t* val) {
return val;
}

static char const* val_type_str(flamingo_val_t const* val) {
char const* flamingo_val_kind_str(flamingo_val_t const* val) {
switch (val->kind) {
case FLAMINGO_VAL_KIND_BOOL:
return "boolean";
Expand Down Expand Up @@ -87,7 +87,7 @@ static char const* val_role_str(flamingo_val_t* val) {
case FLAMINGO_VAL_KIND_INST:
return "variable";
case FLAMINGO_VAL_KIND_FN:
return val_type_str(val);
return flamingo_val_kind_str(val);
default:
return "unknown";
}
Expand Down
Loading