summaryrefslogtreecommitdiff
path: root/src/lang.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lang.c')
-rw-r--r--src/lang.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/lang.c b/src/lang.c
index 6959af80fbfeb..bd287c75ee78f 100644
--- a/src/lang.c
+++ b/src/lang.c
@@ -1,9 +1,9 @@
/*
* *****************************************************************************
*
- * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * All rights reserved.
+ * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -96,37 +96,41 @@ void bc_func_init(BcFunc *f, const char *name) {
bc_vec_init(&f->code, sizeof(uchar), NULL);
- // This is necessary for not allocating memory where it isn't used.
- // dc does not use strings except in the main function. The else part
- // is necessary to stop uninitiazed data errors in valgrind.
- if (BC_IS_BC || !strcmp(name, bc_func_main))
- bc_vec_init(&f->strs, sizeof(char*), bc_string_free);
-#if BC_ENABLE_FUNC_FREE
- else bc_vec_clear(&f->strs);
-#endif // BC_ENABLE_FUNC_FREE
-
bc_vec_init(&f->consts, sizeof(BcConst), bc_const_free);
+
#if BC_ENABLED
if (BC_IS_BC) {
+
+ bc_vec_init(&f->strs, sizeof(char*), bc_string_free);
+
bc_vec_init(&f->autos, sizeof(BcLoc), NULL);
bc_vec_init(&f->labels, sizeof(size_t), NULL);
+
f->nparams = 0;
f->voidfn = false;
}
#endif // BC_ENABLED
+
f->name = name;
}
void bc_func_reset(BcFunc *f) {
+
BC_SIG_ASSERT_LOCKED;
assert(f != NULL);
+
bc_vec_npop(&f->code, f->code.len);
- bc_vec_npop(&f->strs, f->strs.len);
+
bc_vec_npop(&f->consts, f->consts.len);
+
#if BC_ENABLED
if (BC_IS_BC) {
+
+ bc_vec_npop(&f->strs, f->strs.len);
+
bc_vec_npop(&f->autos, f->autos.len);
bc_vec_npop(&f->labels, f->labels.len);
+
f->nparams = 0;
f->voidfn = false;
}
@@ -134,17 +138,24 @@ void bc_func_reset(BcFunc *f) {
}
void bc_func_free(void *func) {
+
#if BC_ENABLE_FUNC_FREE
BcFunc *f = (BcFunc*) func;
+
BC_SIG_ASSERT_LOCKED;
assert(f != NULL);
+
bc_vec_free(&f->code);
- bc_vec_free(&f->strs);
+
bc_vec_free(&f->consts);
+
#if BC_ENABLED
#ifndef NDEBUG
if (BC_IS_BC) {
+
+ bc_vec_free(&f->strs);
+
bc_vec_free(&f->autos);
bc_vec_free(&f->labels);
}
@@ -245,13 +256,13 @@ void bc_result_copy(BcResult *d, BcResult *src) {
break;
}
- case BC_RESULT_CONSTANT:
case BC_RESULT_STR:
{
memcpy(&d->d.n, &src->d.n, sizeof(BcNum));
break;
}
+ case BC_RESULT_ZERO:
case BC_RESULT_ONE:
{
// Do nothing.
@@ -299,7 +310,7 @@ void bc_result_free(void *result) {
#endif // BC_ENABLED
case BC_RESULT_ARRAY_ELEM:
case BC_RESULT_STR:
- case BC_RESULT_CONSTANT:
+ case BC_RESULT_ZERO:
case BC_RESULT_ONE:
#if BC_ENABLED
case BC_RESULT_VOID: