fixed compiler warnings for release builds
This commit is contained in:
+44
-37
@@ -28,7 +28,6 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -37,15 +36,17 @@
|
|||||||
#include "basic.h"
|
#include "basic.h"
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include "../utils/utf8.h"
|
#include "../utils/utf8.h"
|
||||||
|
#include "../utils/defs.h"
|
||||||
#include "../objects/objects.h"
|
#include "../objects/objects.h"
|
||||||
#include "../compiler/compile.h"
|
#include "../compiler/compile.h"
|
||||||
#include "../runtime/runtime.h"
|
#include "../runtime/runtime.h"
|
||||||
|
|
||||||
static int bin_print(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_print(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
(void) runtime;
|
UNUSED(runtime);
|
||||||
(void) rets;
|
UNUSED(rets);
|
||||||
(void) maxretc;
|
UNUSED(maxretc);
|
||||||
(void) error;
|
UNUSED(error);
|
||||||
|
|
||||||
for(int i = 0; i < (int) argc; i += 1)
|
for(int i = 0; i < (int) argc; i += 1)
|
||||||
Object_Print(argv[i], stdout);
|
Object_Print(argv[i], stdout);
|
||||||
@@ -54,9 +55,11 @@ static int bin_print(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
|
|
||||||
static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
Heap *heap = Runtime_GetHeap(runtime);
|
Heap *heap = Runtime_GetHeap(runtime);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
|
|
||||||
Object *o_path = argv[0];
|
Object *o_path = argv[0];
|
||||||
const char *path;
|
const char *path;
|
||||||
@@ -73,7 +76,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
assert(n >= 0);
|
ASSERT(n >= 0);
|
||||||
path_len = (size_t) n;
|
path_len = (size_t) n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
case CompilationErrorType_SYNTAX: errname = "Syntax"; break;
|
case CompilationErrorType_SYNTAX: errname = "Syntax"; break;
|
||||||
case CompilationErrorType_SEMANTIC: errname = "Semantic"; break;
|
case CompilationErrorType_SEMANTIC: errname = "Semantic"; break;
|
||||||
}
|
}
|
||||||
(void) errname;
|
UNUSED(errname);
|
||||||
|
|
||||||
{
|
{
|
||||||
if(maxretc == 0)
|
if(maxretc == 0)
|
||||||
@@ -170,7 +173,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
{
|
{
|
||||||
const char *errname = "Runtime";
|
const char *errname = "Runtime";
|
||||||
// Snapshot?
|
// Snapshot?
|
||||||
(void) errname;
|
UNUSED(errname);
|
||||||
{
|
{
|
||||||
if(maxretc == 0)
|
if(maxretc == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -194,7 +197,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(retc == 1);
|
ASSERT(retc == 1);
|
||||||
|
|
||||||
if(maxretc == 0)
|
if(maxretc == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -206,9 +209,10 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
|
|
||||||
static int bin_type(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_type(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
ASSERT(argc == 1);
|
||||||
(void) runtime;
|
UNUSED(runtime);
|
||||||
(void) error;
|
UNUSED(error);
|
||||||
|
UNUSED(argc);
|
||||||
|
|
||||||
if(maxretc == 0)
|
if(maxretc == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -218,10 +222,10 @@ static int bin_type(Runtime *runtime, Object **argv, unsigned int argc, Object *
|
|||||||
|
|
||||||
static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
(void) runtime;
|
UNUSED(runtime);
|
||||||
(void) error;
|
UNUSED(error);
|
||||||
|
UNUSED(argc);
|
||||||
assert(argc == 1);
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
uint32_t ret = 0;
|
uint32_t ret = 0;
|
||||||
|
|
||||||
@@ -245,7 +249,8 @@ static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Objec
|
|||||||
|
|
||||||
|
|
||||||
int k = utf8_sequence_to_utf32_codepoint(string,n,&ret);
|
int k = utf8_sequence_to_utf32_codepoint(string,n,&ret);
|
||||||
assert(k >= 0);
|
UNUSED(k);
|
||||||
|
ASSERT(k >= 0);
|
||||||
|
|
||||||
Object *temp = Object_FromInt(ret,Runtime_GetHeap(runtime),error);
|
Object *temp = Object_FromInt(ret,Runtime_GetHeap(runtime),error);
|
||||||
|
|
||||||
@@ -260,17 +265,15 @@ static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Objec
|
|||||||
|
|
||||||
static int bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
assert(argc == 1);
|
|
||||||
|
|
||||||
|
|
||||||
if(!Object_IsInt(argv[0]))
|
if(!Object_IsInt(argv[0]))
|
||||||
{
|
{
|
||||||
Error_Report(error, 0, "Argument #%d is not an integer", 1);
|
Error_Report(error, 0, "Argument #%d is not an integer", 1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char buff[32];
|
char buff[32];
|
||||||
|
|
||||||
int value = Object_ToInt(argv[0],error);
|
int value = Object_ToInt(argv[0],error);
|
||||||
@@ -300,7 +303,8 @@ static int bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Object **
|
|||||||
|
|
||||||
static int bin_count(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_count(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
int n = Object_Count(argv[0], error);
|
int n = Object_Count(argv[0], error);
|
||||||
|
|
||||||
@@ -320,9 +324,9 @@ static int bin_count(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
|
|
||||||
static int bin_input(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_input(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
(void) argv;
|
UNUSED(argv);
|
||||||
|
UNUSED(argc);
|
||||||
assert(argc == 0);
|
ASSERT(argc == 0);
|
||||||
|
|
||||||
char maybe[256];
|
char maybe[256];
|
||||||
char *str = maybe;
|
char *str = maybe;
|
||||||
@@ -372,9 +376,9 @@ static int bin_input(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
|
|
||||||
static int bin_assert(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_assert(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
(void) runtime;
|
UNUSED(runtime);
|
||||||
(void) rets;
|
UNUSED(rets);
|
||||||
(void) maxretc;
|
UNUSED(maxretc);
|
||||||
|
|
||||||
for(unsigned int i = 0; i < argc; i += 1)
|
for(unsigned int i = 0; i < argc; i += 1)
|
||||||
if(!Object_ToBool(argv[i], error))
|
if(!Object_ToBool(argv[i], error))
|
||||||
@@ -388,10 +392,10 @@ static int bin_assert(Runtime *runtime, Object **argv, unsigned int argc, Object
|
|||||||
|
|
||||||
static int bin_error(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_error(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
(void) rets;
|
UNUSED(argc);
|
||||||
(void) maxretc;
|
UNUSED(rets);
|
||||||
|
UNUSED(maxretc);
|
||||||
assert(argc == 1);
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
int length;
|
int length;
|
||||||
const char *string;
|
const char *string;
|
||||||
@@ -471,7 +475,8 @@ done:
|
|||||||
|
|
||||||
static int bin_newBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_newBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
long long int size = Object_ToInt(argv[0], error);
|
long long int size = Object_ToInt(argv[0], error);
|
||||||
|
|
||||||
@@ -491,7 +496,8 @@ static int bin_newBuffer(Runtime *runtime, Object **argv, unsigned int argc, Obj
|
|||||||
|
|
||||||
static int bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 3);
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 3);
|
||||||
|
|
||||||
long long int offset = Object_ToInt(argv[1], error);
|
long long int offset = Object_ToInt(argv[1], error);
|
||||||
if(error->occurred == 1) return -1;
|
if(error->occurred == 1) return -1;
|
||||||
@@ -512,7 +518,8 @@ static int bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int argc, O
|
|||||||
|
|
||||||
static int bin_bufferToString(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
static int bin_bufferToString(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error)
|
||||||
{
|
{
|
||||||
assert(argc == 1);
|
UNUSED(argc);
|
||||||
|
ASSERT(argc == 1);
|
||||||
|
|
||||||
void *buffaddr;
|
void *buffaddr;
|
||||||
int buffsize;
|
int buffsize;
|
||||||
|
|||||||
+57
-55
@@ -28,70 +28,72 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "../utils/defs.h"
|
||||||
|
|
||||||
#define WRAP_FUNC(name) \
|
#define WRAP_FUNC(name) \
|
||||||
static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \
|
static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \
|
||||||
{ \
|
{ \
|
||||||
assert(argc == 1); \
|
UNUSED(argc); \
|
||||||
\
|
ASSERT(argc == 1); \
|
||||||
if(Object_IsFloat(argv[0])) \
|
\
|
||||||
{ \
|
if(Object_IsFloat(argv[0])) \
|
||||||
double v = Object_ToFloat(argv[0], error); \
|
{ \
|
||||||
\
|
double v = Object_ToFloat(argv[0], error); \
|
||||||
if(error->occurred) \
|
\
|
||||||
return -1; \
|
if(error->occurred) \
|
||||||
\
|
return -1; \
|
||||||
if(maxretc > 0) \
|
\
|
||||||
{ \
|
if(maxretc > 0) \
|
||||||
rets[0] = Object_FromFloat(name(v), Runtime_GetHeap(runtime), error); \
|
{ \
|
||||||
if(rets[0] == NULL) \
|
rets[0] = Object_FromFloat(name(v), Runtime_GetHeap(runtime), error); \
|
||||||
return -1; \
|
if(rets[0] == NULL) \
|
||||||
return 1; \
|
return -1; \
|
||||||
} \
|
return 1; \
|
||||||
return 0; \
|
} \
|
||||||
} \
|
return 0; \
|
||||||
else \
|
} \
|
||||||
{ \
|
else \
|
||||||
Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0]));\
|
{ \
|
||||||
return -1; \
|
Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0])); \
|
||||||
} \
|
return -1; \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WRAP_FUNC_2(name) \
|
#define WRAP_FUNC_2(name) \
|
||||||
static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \
|
static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \
|
||||||
{ \
|
{ \
|
||||||
assert(argc == 2); \
|
UNUSED(argc); \
|
||||||
\
|
ASSERT(argc == 2); \
|
||||||
if(!Object_IsFloat(argv[0])) \
|
\
|
||||||
{ \
|
if(!Object_IsFloat(argv[0])) \
|
||||||
Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0]));\
|
{ \
|
||||||
return -1; \
|
Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0])); \
|
||||||
} \
|
return -1; \
|
||||||
\
|
} \
|
||||||
if(!Object_IsFloat(argv[1])) \
|
\
|
||||||
{ \
|
if(!Object_IsFloat(argv[1])) \
|
||||||
Error_Report(error, 0, "Expected second argument to be a float, but it's a %s", Object_GetName(argv[1]));\
|
{ \
|
||||||
return -1; \
|
Error_Report(error, 0, "Expected second argument to be a float, but it's a %s", Object_GetName(argv[1])); \
|
||||||
} \
|
return -1; \
|
||||||
\
|
} \
|
||||||
double v1 = Object_ToFloat(argv[0], error); \
|
\
|
||||||
\
|
double v1 = Object_ToFloat(argv[0], error); \
|
||||||
if(error->occurred) \
|
\
|
||||||
return -1; \
|
if(error->occurred) \
|
||||||
\
|
return -1; \
|
||||||
double v2 = Object_ToFloat(argv[1], error); \
|
\
|
||||||
\
|
double v2 = Object_ToFloat(argv[1], error); \
|
||||||
if(error->occurred) \
|
\
|
||||||
return -1; \
|
if(error->occurred) \
|
||||||
\
|
return -1; \
|
||||||
Object *res = Object_FromFloat(name(v1, v2), Runtime_GetHeap(runtime), error); \
|
\
|
||||||
if(res == NULL) return -1; \
|
Object *res = Object_FromFloat(name(v1, v2), Runtime_GetHeap(runtime), error); \
|
||||||
if(maxretc == 0) return 0; \
|
if(res == NULL) return -1; \
|
||||||
rets[0] = res; \
|
if(maxretc == 0) return 0; \
|
||||||
return 1; \
|
rets[0] = res; \
|
||||||
|
return 1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
WRAP_FUNC(ceil)
|
WRAP_FUNC(ceil)
|
||||||
|
|||||||
+23
-24
@@ -117,7 +117,7 @@ _Bool Executable_GetOpcodeBinaryFromName(const char *name, size_t name_len, Opco
|
|||||||
// so to simplify things we duplicate it to add
|
// so to simplify things we duplicate it to add
|
||||||
// an extra null byte.
|
// an extra null byte.
|
||||||
char buff[128]; // No opcode should have a name this big.
|
char buff[128]; // No opcode should have a name this big.
|
||||||
assert(name_len < sizeof(buff)); // If this is triggered, [buff] should be made bigger.
|
ASSERT(name_len < sizeof(buff)); // If this is triggered, [buff] should be made bigger.
|
||||||
|
|
||||||
memcpy(buff, name, name_len);
|
memcpy(buff, name, name_len);
|
||||||
buff[name_len] = '\0';
|
buff[name_len] = '\0';
|
||||||
@@ -125,7 +125,7 @@ _Bool Executable_GetOpcodeBinaryFromName(const char *name, size_t name_len, Opco
|
|||||||
name = buff;
|
name = buff;
|
||||||
|
|
||||||
// Now name is zero terminated.
|
// Now name is zero terminated.
|
||||||
assert(name[name_len] == '\0');
|
ASSERT(name[name_len] == '\0');
|
||||||
|
|
||||||
for(size_t i = 0; i < sizeof(instr_table)/sizeof(instr_table[0]); i += 1) {
|
for(size_t i = 0; i < sizeof(instr_table)/sizeof(instr_table[0]); i += 1) {
|
||||||
if(!strcmp(name, instr_table[i].name)) {
|
if(!strcmp(name, instr_table[i].name)) {
|
||||||
@@ -143,7 +143,7 @@ const char *Executable_GetOpcodeName(Opcode opcode)
|
|||||||
|
|
||||||
Executable *Executable_Copy(Executable *exe)
|
Executable *Executable_Copy(Executable *exe)
|
||||||
{
|
{
|
||||||
assert(exe != NULL);
|
ASSERT(exe != NULL);
|
||||||
|
|
||||||
exe->refs += 1;
|
exe->refs += 1;
|
||||||
return exe;
|
return exe;
|
||||||
@@ -152,7 +152,7 @@ Executable *Executable_Copy(Executable *exe)
|
|||||||
void Executable_Free(Executable *exe)
|
void Executable_Free(Executable *exe)
|
||||||
{
|
{
|
||||||
exe->refs -= 1;
|
exe->refs -= 1;
|
||||||
assert(exe->refs >= 0);
|
ASSERT(exe->refs >= 0);
|
||||||
|
|
||||||
if(exe->refs == 0)
|
if(exe->refs == 0)
|
||||||
{
|
{
|
||||||
@@ -243,7 +243,7 @@ int Executable_GetInstrLength(Executable *exe, int index)
|
|||||||
|
|
||||||
_Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops, int *opc)
|
_Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops, int *opc)
|
||||||
{
|
{
|
||||||
assert(index >= 0);
|
ASSERT(index >= 0);
|
||||||
|
|
||||||
if(index >= exe->bodyl)
|
if(index >= exe->bodyl)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -263,7 +263,7 @@ _Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops,
|
|||||||
for(i = 0; i < k; i += 1)
|
for(i = 0; i < k; i += 1)
|
||||||
{
|
{
|
||||||
OperandType type = info->optypes[i];
|
OperandType type = info->optypes[i];
|
||||||
assert(type != OPTP_PROMISE);
|
ASSERT(type != OPTP_PROMISE);
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
@@ -271,7 +271,7 @@ _Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops,
|
|||||||
{
|
{
|
||||||
int data_offset = instr->operands[i].as_int;
|
int data_offset = instr->operands[i].as_int;
|
||||||
|
|
||||||
assert(data_offset < exe->headl);
|
ASSERT(data_offset < exe->headl);
|
||||||
|
|
||||||
ops[i].type = OPTP_STRING;
|
ops[i].type = OPTP_STRING;
|
||||||
ops[i].as_string = exe->head + data_offset;
|
ops[i].as_string = exe->head + data_offset;
|
||||||
@@ -337,16 +337,16 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char
|
|||||||
// same, the number of operands must be
|
// same, the number of operands must be
|
||||||
// the same too. (Their type must be
|
// the same too. (Their type must be
|
||||||
// the same too.)
|
// the same too.)
|
||||||
assert(exe1_opc == exe2_opc);
|
ASSERT(exe1_opc == exe2_opc);
|
||||||
|
|
||||||
for(int opno = 0; opno < exe1_opc; opno += 1) {
|
for(int opno = 0; opno < exe1_opc; opno += 1) {
|
||||||
|
|
||||||
assert(exe1_opv[opno].type == exe2_opv[opno].type);
|
ASSERT(exe1_opv[opno].type == exe2_opv[opno].type);
|
||||||
|
|
||||||
// Also, an executable can never have
|
// Also, an executable can never have
|
||||||
// a promise operand. That's only used
|
// a promise operand. That's only used
|
||||||
// when building the executable.
|
// when building the executable.
|
||||||
assert(exe1_opv[opno].type != OPTP_PROMISE);
|
ASSERT(exe1_opv[opno].type != OPTP_PROMISE);
|
||||||
|
|
||||||
switch(exe1_opv[opno].type) {
|
switch(exe1_opv[opno].type) {
|
||||||
|
|
||||||
@@ -392,8 +392,7 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTP_PROMISE:
|
case OPTP_PROMISE:
|
||||||
/* Unreachable */
|
UNREACHABLE;
|
||||||
assert(0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,7 +404,7 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char
|
|||||||
|
|
||||||
ExeBuilder *ExeBuilder_New(BPAlloc *alloc)
|
ExeBuilder *ExeBuilder_New(BPAlloc *alloc)
|
||||||
{
|
{
|
||||||
assert(alloc != NULL);
|
ASSERT(alloc != NULL);
|
||||||
|
|
||||||
ExeBuilder *exeb = BPAlloc_Malloc(alloc, sizeof(ExeBuilder));
|
ExeBuilder *exeb = BPAlloc_Malloc(alloc, sizeof(ExeBuilder));
|
||||||
|
|
||||||
@@ -423,7 +422,7 @@ ExeBuilder *ExeBuilder_New(BPAlloc *alloc)
|
|||||||
|
|
||||||
Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error)
|
Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error)
|
||||||
{
|
{
|
||||||
assert(exeb != NULL);
|
ASSERT(exeb != NULL);
|
||||||
|
|
||||||
if(exeb->promc > 0)
|
if(exeb->promc > 0)
|
||||||
{
|
{
|
||||||
@@ -436,7 +435,7 @@ Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error)
|
|||||||
int data_size = BucketList_Size(exeb->data);
|
int data_size = BucketList_Size(exeb->data);
|
||||||
int code_size = BucketList_Size(exeb->code);
|
int code_size = BucketList_Size(exeb->code);
|
||||||
|
|
||||||
assert(code_size % sizeof(Instruction) == 0);
|
ASSERT(code_size % sizeof(Instruction) == 0);
|
||||||
|
|
||||||
void *temp = malloc(sizeof(Executable) + data_size + code_size);
|
void *temp = malloc(sizeof(Executable) + data_size + code_size);
|
||||||
|
|
||||||
@@ -463,18 +462,18 @@ Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error)
|
|||||||
|
|
||||||
static void promise_callback(void *userp)
|
static void promise_callback(void *userp)
|
||||||
{
|
{
|
||||||
assert(userp != NULL);
|
ASSERT(userp != NULL);
|
||||||
|
|
||||||
ExeBuilder *exeb = userp;
|
ExeBuilder *exeb = userp;
|
||||||
|
|
||||||
exeb->promc -= 1;
|
exeb->promc -= 1;
|
||||||
assert(exeb->promc >= 0);
|
ASSERT(exeb->promc >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *opv, int opc, int off, int len)
|
_Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *opv, int opc, int off, int len)
|
||||||
{
|
{
|
||||||
assert(exeb != NULL);
|
ASSERT(exeb != NULL);
|
||||||
assert(opc >= 0);
|
ASSERT(opc >= 0);
|
||||||
|
|
||||||
static const char *operand_type_names[] = {
|
static const char *operand_type_names[] = {
|
||||||
[OPTP_IDX] = "index",
|
[OPTP_IDX] = "index",
|
||||||
@@ -508,7 +507,7 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(opc <= MAX_OPS);
|
ASSERT(opc <= MAX_OPS);
|
||||||
|
|
||||||
{
|
{
|
||||||
Instruction *instr = BucketList_Append2(exeb->code, NULL, sizeof(Instruction));
|
Instruction *instr = BucketList_Append2(exeb->code, NULL, sizeof(Instruction));
|
||||||
@@ -532,11 +531,11 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *
|
|||||||
OperandType expected_type = info->optypes[i];
|
OperandType expected_type = info->optypes[i];
|
||||||
OperandType provided_type = opv[i].type;
|
OperandType provided_type = opv[i].type;
|
||||||
|
|
||||||
assert(expected_type != OPTP_PROMISE);
|
ASSERT(expected_type != OPTP_PROMISE);
|
||||||
|
|
||||||
if(provided_type == OPTP_PROMISE)
|
if(provided_type == OPTP_PROMISE)
|
||||||
{
|
{
|
||||||
assert(opv[i].as_promise != NULL);
|
ASSERT(opv[i].as_promise != NULL);
|
||||||
|
|
||||||
if(expected_type == OPTP_STRING)
|
if(expected_type == OPTP_STRING)
|
||||||
{
|
{
|
||||||
@@ -588,7 +587,7 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPTP_PROMISE:
|
case OPTP_PROMISE:
|
||||||
assert(info->optypes[i] != OPTP_STRING);
|
ASSERT(info->optypes[i] != OPTP_STRING);
|
||||||
|
|
||||||
// This must be incremented before subscribing
|
// This must be incremented before subscribing
|
||||||
// since the counter-decrementing callback may
|
// since the counter-decrementing callback may
|
||||||
@@ -630,7 +629,7 @@ int ExeBuilder_InstrCount(ExeBuilder *exeb)
|
|||||||
{
|
{
|
||||||
int raw_size = BucketList_Size(exeb->code);
|
int raw_size = BucketList_Size(exeb->code);
|
||||||
|
|
||||||
assert(raw_size % sizeof(Instruction) == 0);
|
ASSERT(raw_size % sizeof(Instruction) == 0);
|
||||||
|
|
||||||
return raw_size / sizeof(Instruction);
|
return raw_size / sizeof(Instruction);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ Promise *Label_ToPromise(Label *label)
|
|||||||
|
|
||||||
static void okNowJump(CodegenContext *ctx)
|
static void okNowJump(CodegenContext *ctx)
|
||||||
{
|
{
|
||||||
assert(ctx->env_set == true);
|
ASSERT(ctx->env_set == true);
|
||||||
longjmp(*ctx->env, 1);
|
longjmp(*ctx->env, 1);
|
||||||
UNREACHABLE;
|
UNREACHABLE;
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ void CodegenContext_ReportErrorAndJump_(CodegenContext *ctx, const char *file,
|
|||||||
|
|
||||||
void CodegenContext_SetJumpDest(CodegenContext *ctx, jmp_buf *env)
|
void CodegenContext_SetJumpDest(CodegenContext *ctx, jmp_buf *env)
|
||||||
{
|
{
|
||||||
assert(ctx->env_set == false);
|
ASSERT(ctx->env_set == false);
|
||||||
ctx->env = env;
|
ctx->env = env;
|
||||||
ctx->env_set = true;
|
ctx->env_set = true;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-14
@@ -28,9 +28,9 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
#include "../utils/defs.h"
|
||||||
|
|
||||||
static _Bool to_bool(Object *obj, Error *err);
|
static _Bool to_bool(Object *obj, Error *err);
|
||||||
static void print(Object *obj, FILE *fp);
|
static void print(Object *obj, FILE *fp);
|
||||||
@@ -62,13 +62,13 @@ static Object the_false_object = {
|
|||||||
|
|
||||||
static int hash(Object *self)
|
static int hash(Object *self)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_bool);
|
ASSERT(self->type == &t_bool);
|
||||||
|
|
||||||
if(self == &the_true_object)
|
if(self == &the_true_object)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
assert(self == &the_false_object);
|
ASSERT(self == &the_false_object);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,19 +81,20 @@ static Object *copy(Object *self, Heap *heap, Error *err)
|
|||||||
|
|
||||||
static _Bool op_eql(Object *self, Object *other)
|
static _Bool op_eql(Object *self, Object *other)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_bool);
|
ASSERT(self->type == &t_bool);
|
||||||
assert(other != NULL);
|
ASSERT(other != NULL);
|
||||||
assert(other->type == &t_bool);
|
ASSERT(other->type == &t_bool);
|
||||||
|
|
||||||
return self == other;
|
return self == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _Bool to_bool(Object *obj, Error *err)
|
static _Bool to_bool(Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(obj);
|
UNUSED(err);
|
||||||
assert(err);
|
ASSERT(obj);
|
||||||
assert(Object_GetType(obj) == &t_bool);
|
ASSERT(err);
|
||||||
|
ASSERT(Object_GetType(obj) == &t_bool);
|
||||||
return obj == &the_true_object;
|
return obj == &the_true_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,9 +112,9 @@ Object *Object_FromBool(_Bool val, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static void print(Object *obj, FILE *fp)
|
static void print(Object *obj, FILE *fp)
|
||||||
{
|
{
|
||||||
assert(fp != NULL);
|
ASSERT(fp != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type == &t_bool);
|
ASSERT(obj->type == &t_bool);
|
||||||
|
|
||||||
fprintf(fp, obj == &the_true_object ? "true" : "false");
|
fprintf(fp, obj == &the_true_object ? "true" : "false");
|
||||||
}
|
}
|
||||||
+33
-32
@@ -29,7 +29,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../utils/defs.h"
|
#include "../utils/defs.h"
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
@@ -94,7 +93,7 @@ _Bool Object_IsBuffer(Object *obj)
|
|||||||
|
|
||||||
Object *Object_NewBuffer(int size, Heap *heap, Error *error)
|
Object *Object_NewBuffer(int size, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(size >= 0);
|
ASSERT(size >= 0);
|
||||||
|
|
||||||
// Make the thing.
|
// Make the thing.
|
||||||
BufferObject *obj;
|
BufferObject *obj;
|
||||||
@@ -189,7 +188,7 @@ Object *Object_SliceBuffer(Object *buffer, int offset, int length, Heap *heap, E
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(buffer->type == &t_buffer_slice);
|
ASSERT(buffer->type == &t_buffer_slice);
|
||||||
|
|
||||||
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error);
|
||||||
|
|
||||||
@@ -243,7 +242,7 @@ void *Object_GetBufferAddrAndSize(Object *obj, int *size, Error *error)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(obj->type == &t_buffer_slice);
|
ASSERT(obj->type == &t_buffer_slice);
|
||||||
|
|
||||||
BufferSliceObject *slice = (BufferSliceObject*) obj;
|
BufferSliceObject *slice = (BufferSliceObject*) obj;
|
||||||
|
|
||||||
@@ -256,11 +255,11 @@ void *Object_GetBufferAddrAndSize(Object *obj, int *size, Error *error)
|
|||||||
|
|
||||||
static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error)
|
static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_buffer);
|
ASSERT(self->type == &t_buffer);
|
||||||
assert(key != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(!Object_IsInt(key))
|
if(!Object_IsInt(key))
|
||||||
{
|
{
|
||||||
@@ -269,7 +268,7 @@ static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
BufferObject *buffer = (BufferObject*) self;
|
BufferObject *buffer = (BufferObject*) self;
|
||||||
|
|
||||||
@@ -286,11 +285,11 @@ static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error
|
|||||||
|
|
||||||
static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error)
|
static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_buffer_slice);
|
ASSERT(self->type == &t_buffer_slice);
|
||||||
assert(key != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(!Object_IsInt(key))
|
if(!Object_IsInt(key))
|
||||||
{
|
{
|
||||||
@@ -299,7 +298,7 @@ static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
BufferSliceObject *slice = (BufferSliceObject*) self;
|
BufferSliceObject *slice = (BufferSliceObject*) self;
|
||||||
|
|
||||||
@@ -316,12 +315,13 @@ static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(error != NULL);
|
UNUSED(heap);
|
||||||
assert(key != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(val != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(val != NULL);
|
||||||
assert(self != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(self->type == &t_buffer);
|
ASSERT(self != NULL);
|
||||||
|
ASSERT(self->type == &t_buffer);
|
||||||
|
|
||||||
BufferObject *buffer = (BufferObject*) self;
|
BufferObject *buffer = (BufferObject*) self;
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, E
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
if(idx < 0 || idx >= buffer->size)
|
if(idx < 0 || idx >= buffer->size)
|
||||||
{
|
{
|
||||||
@@ -359,12 +359,13 @@ static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, E
|
|||||||
|
|
||||||
static _Bool slice_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
static _Bool slice_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(error != NULL);
|
UNUSED(heap);
|
||||||
assert(key != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(val != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(val != NULL);
|
||||||
assert(self != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(self->type == &t_buffer_slice);
|
ASSERT(self != NULL);
|
||||||
|
ASSERT(self->type == &t_buffer_slice);
|
||||||
|
|
||||||
BufferSliceObject *slice = (BufferSliceObject*) self;
|
BufferSliceObject *slice = (BufferSliceObject*) self;
|
||||||
|
|
||||||
@@ -375,7 +376,7 @@ static _Bool slice_insert(Object *self, Object *key, Object *val, Heap *heap, Er
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
if(idx < 0 || idx >= slice->length)
|
if(idx < 0 || idx >= slice->length)
|
||||||
{
|
{
|
||||||
@@ -426,8 +427,8 @@ static void print_bytes(FILE *fp, unsigned char *addr, int size)
|
|||||||
low = byte & 0xf;
|
low = byte & 0xf;
|
||||||
high = byte >> 4;
|
high = byte >> 4;
|
||||||
|
|
||||||
assert(low < 16);
|
ASSERT(low < 16);
|
||||||
assert(high < 16);
|
ASSERT(high < 16);
|
||||||
|
|
||||||
char c1, c2;
|
char c1, c2;
|
||||||
|
|
||||||
|
|||||||
+20
-20
@@ -28,7 +28,6 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../utils/defs.h"
|
#include "../utils/defs.h"
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
@@ -64,8 +63,8 @@ static TypeObject t_list = {
|
|||||||
|
|
||||||
static int hash(Object *self)
|
static int hash(Object *self)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_list);
|
ASSERT(self->type == &t_list);
|
||||||
|
|
||||||
ListObject *ls = (ListObject*) self;
|
ListObject *ls = (ListObject*) self;
|
||||||
|
|
||||||
@@ -81,8 +80,8 @@ static int hash(Object *self)
|
|||||||
|
|
||||||
static Object *copy(Object *self, Heap *heap, Error *err)
|
static Object *copy(Object *self, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
(void) heap;
|
UNUSED(heap);
|
||||||
(void) err;
|
UNUSED(err);
|
||||||
|
|
||||||
ListObject *ls = (ListObject*) self;
|
ListObject *ls = (ListObject*) self;
|
||||||
ListObject *ls2 = (ListObject*) Object_NewList(ls->count, heap, err);
|
ListObject *ls2 = (ListObject*) Object_NewList(ls->count, heap, err);
|
||||||
@@ -131,7 +130,7 @@ Object *Object_NewList(int capacity, Heap *heap, Error *error)
|
|||||||
|
|
||||||
Object *Object_NewList2(int num, Object **items, Heap *heap, Error *error)
|
Object *Object_NewList2(int num, Object **items, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(num > -1);
|
ASSERT(num > -1);
|
||||||
|
|
||||||
ListObject *list = (ListObject*) Object_NewList(num, heap, error);
|
ListObject *list = (ListObject*) Object_NewList(num, heap, error);
|
||||||
|
|
||||||
@@ -161,11 +160,12 @@ static void walkexts(Object *self, void (*callback)(void **referer, unsigned int
|
|||||||
|
|
||||||
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
UNUSED(heap);
|
||||||
assert(self->type == &t_list);
|
ASSERT(self != NULL);
|
||||||
assert(key != NULL);
|
ASSERT(self->type == &t_list);
|
||||||
assert(heap != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(heap != NULL);
|
||||||
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(!Object_IsInt(key))
|
if(!Object_IsInt(key))
|
||||||
{
|
{
|
||||||
@@ -174,7 +174,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
ListObject *list = (ListObject*) self;
|
ListObject *list = (ListObject*) self;
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ static unsigned int calc_new_capacity(unsigned int old_capacity)
|
|||||||
|
|
||||||
static _Bool grow(ListObject *list, Heap *heap, Error *error)
|
static _Bool grow(ListObject *list, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(list != NULL);
|
ASSERT(list != NULL);
|
||||||
|
|
||||||
int new_capacity = calc_new_capacity(list->capacity);
|
int new_capacity = calc_new_capacity(list->capacity);
|
||||||
|
|
||||||
@@ -213,12 +213,12 @@ static _Bool grow(ListObject *list, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(key != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(val != NULL);
|
ASSERT(val != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_list);
|
ASSERT(self->type == &t_list);
|
||||||
|
|
||||||
ListObject *list = (ListObject*) self;
|
ListObject *list = (ListObject*) self;
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
if(idx < 0 || idx > list->count)
|
if(idx < 0 || idx > list->count)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-16
@@ -28,7 +28,6 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include "../utils/defs.h"
|
#include "../utils/defs.h"
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
|
||||||
@@ -164,7 +163,7 @@ static void walk(Object *self, void (*callback)(Object **referer, void *userp),
|
|||||||
|
|
||||||
static void walkexts(Object *self, void (*callback)(void **referer, unsigned int size, void *userp), void *userp)
|
static void walkexts(Object *self, void (*callback)(void **referer, unsigned int size, void *userp), void *userp)
|
||||||
{
|
{
|
||||||
assert(self->type == &t_map);
|
ASSERT(self->type == &t_map);
|
||||||
|
|
||||||
MapObject *map = (MapObject*) self;
|
MapObject *map = (MapObject*) self;
|
||||||
|
|
||||||
@@ -177,11 +176,12 @@ static void walkexts(Object *self, void (*callback)(void **referer, unsigned int
|
|||||||
|
|
||||||
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
UNUSED(heap);
|
||||||
assert(self->type == &t_map);
|
ASSERT(self != NULL);
|
||||||
assert(key != NULL);
|
ASSERT(self->type == &t_map);
|
||||||
assert(heap != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(heap != NULL);
|
||||||
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
MapObject *map = (MapObject*) self;
|
MapObject *map = (MapObject*) self;
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
// Found an item.
|
// Found an item.
|
||||||
// Is it the right one?
|
// Is it the right one?
|
||||||
|
|
||||||
assert(k >= 0);
|
ASSERT(k >= 0);
|
||||||
|
|
||||||
if(Object_Compare(key, map->keys[k], error))
|
if(Object_Compare(key, map->keys[k], error))
|
||||||
// Found it!
|
// Found it!
|
||||||
@@ -229,7 +229,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static _Bool grow(MapObject *map, Heap *heap, Error *error)
|
static _Bool grow(MapObject *map, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(map != NULL);
|
ASSERT(map != NULL);
|
||||||
|
|
||||||
int new_mapper_size = map->mapper_size << 1;
|
int new_mapper_size = map->mapper_size << 1;
|
||||||
int new_capacity = calc_capacity(new_mapper_size);
|
int new_capacity = calc_capacity(new_mapper_size);
|
||||||
@@ -289,12 +289,12 @@ static _Bool grow(MapObject *map, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(key != NULL);
|
ASSERT(key != NULL);
|
||||||
assert(val != NULL);
|
ASSERT(val != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_map);
|
ASSERT(self->type == &t_map);
|
||||||
|
|
||||||
MapObject *map = (MapObject*) self;
|
MapObject *map = (MapObject*) self;
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(k >= 0);
|
ASSERT(k >= 0);
|
||||||
|
|
||||||
if(Object_Compare(key, map->keys[k], error))
|
if(Object_Compare(key, map->keys[k], error))
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-12
@@ -28,9 +28,9 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
#include "../utils/defs.h"
|
||||||
|
|
||||||
static _Bool op_eql(Object *self, Object *other);
|
static _Bool op_eql(Object *self, Object *other);
|
||||||
static void print(Object *obj, FILE *fp);
|
static void print(Object *obj, FILE *fp);
|
||||||
@@ -64,37 +64,39 @@ _Bool Object_IsNone(Object *obj)
|
|||||||
|
|
||||||
static int hash(Object *self)
|
static int hash(Object *self)
|
||||||
{
|
{
|
||||||
assert(self == &the_none_object);
|
UNUSED(self);
|
||||||
|
ASSERT(self == &the_none_object);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object *copy(Object *self, Heap *heap, Error *err)
|
static Object *copy(Object *self, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
(void) heap;
|
UNUSED(heap);
|
||||||
(void) err;
|
UNUSED(err);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *Object_NewNone(Heap *heap, Error *error)
|
Object *Object_NewNone(Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
(void) heap;
|
UNUSED(heap);
|
||||||
(void) error;
|
UNUSED(error);
|
||||||
return &the_none_object;
|
return &the_none_object;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print(Object *obj, FILE *fp)
|
static void print(Object *obj, FILE *fp)
|
||||||
{
|
{
|
||||||
assert(fp != NULL);
|
UNUSED(obj);
|
||||||
assert(obj != NULL);
|
ASSERT(fp != NULL);
|
||||||
assert(obj->type == &t_none);
|
ASSERT(obj != NULL);
|
||||||
|
ASSERT(obj->type == &t_none);
|
||||||
|
|
||||||
fprintf(fp, "none");
|
fprintf(fp, "none");
|
||||||
}
|
}
|
||||||
|
|
||||||
static _Bool op_eql(Object *self, Object *other)
|
static _Bool op_eql(Object *self, Object *other)
|
||||||
{
|
{
|
||||||
(void) self;
|
UNUSED(self);
|
||||||
|
UNUSED(other);
|
||||||
assert(other->type == &t_none);
|
ASSERT(other->type == &t_none);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
+27
-26
@@ -29,7 +29,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
#include "../utils/defs.h"
|
#include "../utils/defs.h"
|
||||||
#include "../utils/hash.h"
|
#include "../utils/hash.h"
|
||||||
#include "../utils/utf8.h"
|
#include "../utils/utf8.h"
|
||||||
@@ -83,17 +82,17 @@ static int char_index_to_offset(StringObject *str, int idx)
|
|||||||
scanned_bytes += last_code_len;
|
scanned_bytes += last_code_len;
|
||||||
idx -= 1;
|
idx -= 1;
|
||||||
|
|
||||||
assert(scanned_bytes <= str->bytes);
|
ASSERT(scanned_bytes <= str->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(idx == 0);
|
ASSERT(idx == 0);
|
||||||
return scanned_bytes;
|
return scanned_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(self != NULL && self->type == &t_string);
|
ASSERT(self != NULL && self->type == &t_string);
|
||||||
assert(key != NULL && heap != NULL && error != NULL);
|
ASSERT(key != NULL && heap != NULL && error != NULL);
|
||||||
|
|
||||||
if(!Object_IsInt(key))
|
if(!Object_IsInt(key))
|
||||||
{
|
{
|
||||||
@@ -102,7 +101,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int idx = Object_ToInt(key, error);
|
int idx = Object_ToInt(key, error);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
StringObject *str = (StringObject*) self;
|
StringObject *str = (StringObject*) self;
|
||||||
|
|
||||||
@@ -120,8 +119,8 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static char *to_string(Object *self, int *size, Heap *heap, Error *err)
|
static char *to_string(Object *self, int *size, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_string);
|
ASSERT(self->type == &t_string);
|
||||||
|
|
||||||
(void) heap;
|
(void) heap;
|
||||||
(void) err;
|
(void) err;
|
||||||
@@ -141,9 +140,9 @@ TypeObject *Object_GetStringType()
|
|||||||
|
|
||||||
Object *Object_FromString(const char *str, int len, Heap *heap, Error *error)
|
Object *Object_FromString(const char *str, int len, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(str != NULL);
|
ASSERT(str != NULL);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(len < 0)
|
if(len < 0)
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
@@ -177,8 +176,8 @@ Object *Object_FromString(const char *str, int len, Heap *heap, Error *error)
|
|||||||
|
|
||||||
static int count(Object *self)
|
static int count(Object *self)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_string);
|
ASSERT(self->type == &t_string);
|
||||||
|
|
||||||
StringObject *strobj = (StringObject*) self;
|
StringObject *strobj = (StringObject*) self;
|
||||||
|
|
||||||
@@ -187,8 +186,8 @@ static int count(Object *self)
|
|||||||
|
|
||||||
static int hash(Object *self)
|
static int hash(Object *self)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_string);
|
ASSERT(self->type == &t_string);
|
||||||
|
|
||||||
StringObject *strobj = (StringObject*) self;
|
StringObject *strobj = (StringObject*) self;
|
||||||
|
|
||||||
@@ -197,20 +196,22 @@ static int hash(Object *self)
|
|||||||
|
|
||||||
static Object *copy(Object *self, Heap *heap, Error *err)
|
static Object *copy(Object *self, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
UNUSED(heap);
|
||||||
assert(self->type == &t_string);
|
UNUSED(err);
|
||||||
assert(heap != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(err != NULL);
|
ASSERT(self->type == &t_string);
|
||||||
|
ASSERT(heap != NULL);
|
||||||
|
ASSERT(err != NULL);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static _Bool op_eql(Object *self, Object *other)
|
static _Bool op_eql(Object *self, Object *other)
|
||||||
{
|
{
|
||||||
assert(self != NULL);
|
ASSERT(self != NULL);
|
||||||
assert(self->type == &t_string);
|
ASSERT(self->type == &t_string);
|
||||||
assert(other != NULL);
|
ASSERT(other != NULL);
|
||||||
assert(other->type == &t_string);
|
ASSERT(other->type == &t_string);
|
||||||
|
|
||||||
StringObject *s1 = (StringObject*) self;
|
StringObject *s1 = (StringObject*) self;
|
||||||
StringObject *s2 = (StringObject*) other;
|
StringObject *s2 = (StringObject*) other;
|
||||||
@@ -222,9 +223,9 @@ static _Bool op_eql(Object *self, Object *other)
|
|||||||
|
|
||||||
static void print(Object *obj, FILE *fp)
|
static void print(Object *obj, FILE *fp)
|
||||||
{
|
{
|
||||||
assert(fp != NULL);
|
ASSERT(fp != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type == &t_string);
|
ASSERT(obj->type == &t_string);
|
||||||
|
|
||||||
StringObject *str = (StringObject*) obj;
|
StringObject *str = (StringObject*) obj;
|
||||||
|
|
||||||
|
|||||||
+68
-68
@@ -28,7 +28,6 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include "../utils/defs.h"
|
#include "../utils/defs.h"
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
|
||||||
@@ -53,42 +52,43 @@ static _Bool op_eql(Object *self, Object *other)
|
|||||||
|
|
||||||
const char *Object_GetName(const Object *obj)
|
const char *Object_GetName(const Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
const char *name = type->name;
|
const char *name = type->name;
|
||||||
assert(name);
|
ASSERT(name);
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeObject *Object_GetType(const Object *obj)
|
const TypeObject *Object_GetType(const Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type != NULL);
|
ASSERT(obj->type != NULL);
|
||||||
return obj->type;
|
return obj->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Object_GetSize(const Object *obj, Error *err)
|
unsigned int Object_GetSize(const Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(err != NULL);
|
UNUSED(err);
|
||||||
assert(obj != NULL);
|
ASSERT(err != NULL);
|
||||||
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
return type->size;
|
return type->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Object_GetDeepSize(const Object *obj, Error *err)
|
unsigned int Object_GetDeepSize(const Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(err != NULL);
|
ASSERT(err != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->deepsize == NULL)
|
if(type->deepsize == NULL)
|
||||||
{
|
{
|
||||||
@@ -101,20 +101,20 @@ unsigned int Object_GetDeepSize(const Object *obj, Error *err)
|
|||||||
|
|
||||||
int Object_Hash(Object *obj)
|
int Object_Hash(Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type != NULL);
|
ASSERT(type != NULL);
|
||||||
assert(type->hash != NULL);
|
ASSERT(type->hash != NULL);
|
||||||
return type->hash(obj);
|
return type->hash(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *Object_Copy(Object *obj, Heap *heap, Error *err)
|
Object *Object_Copy(Object *obj, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err != NULL);
|
ASSERT(err != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type != NULL);
|
ASSERT(type != NULL);
|
||||||
|
|
||||||
if(type->copy == NULL)
|
if(type->copy == NULL)
|
||||||
{
|
{
|
||||||
@@ -127,10 +127,10 @@ Object *Object_Copy(Object *obj, Heap *heap, Error *err)
|
|||||||
|
|
||||||
int Object_Call(Object *obj, Object **argv, unsigned int argc, Object **rets, unsigned int maxrets, Heap *heap, Error *err)
|
int Object_Call(Object *obj, Object **argv, unsigned int argc, Object **rets, unsigned int maxrets, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err != NULL && obj != NULL);
|
ASSERT(err != NULL && obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->call == NULL)
|
if(type->call == NULL)
|
||||||
{
|
{
|
||||||
@@ -143,10 +143,10 @@ int Object_Call(Object *obj, Object **argv, unsigned int argc, Object **rets, un
|
|||||||
|
|
||||||
void Object_Print(Object *obj, FILE *fp)
|
void Object_Print(Object *obj, FILE *fp)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->print == NULL)
|
if(type->print == NULL)
|
||||||
fprintf(fp, "<%s is unprintable>", Object_GetName(obj));
|
fprintf(fp, "<%s is unprintable>", Object_GetName(obj));
|
||||||
@@ -156,12 +156,12 @@ void Object_Print(Object *obj, FILE *fp)
|
|||||||
|
|
||||||
Object *Object_Select(Object *coll, Object *key, Heap *heap, Error *err)
|
Object *Object_Select(Object *coll, Object *key, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(key);
|
ASSERT(key);
|
||||||
assert(coll);
|
ASSERT(coll);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(coll);
|
const TypeObject *type = Object_GetType(coll);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->select == NULL)
|
if(type->select == NULL)
|
||||||
{
|
{
|
||||||
@@ -174,12 +174,12 @@ Object *Object_Select(Object *coll, Object *key, Heap *heap, Error *err)
|
|||||||
|
|
||||||
Object *Object_Delete(Object *coll, Object *key, Heap *heap, Error *err)
|
Object *Object_Delete(Object *coll, Object *key, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(key);
|
ASSERT(key);
|
||||||
assert(coll);
|
ASSERT(coll);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(coll);
|
const TypeObject *type = Object_GetType(coll);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->delete == NULL)
|
if(type->delete == NULL)
|
||||||
{
|
{
|
||||||
@@ -192,12 +192,12 @@ Object *Object_Delete(Object *coll, Object *key, Heap *heap, Error *err)
|
|||||||
|
|
||||||
_Bool Object_Insert(Object *coll, Object *key, Object *val, Heap *heap, Error *err)
|
_Bool Object_Insert(Object *coll, Object *key, Object *val, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(key);
|
ASSERT(key);
|
||||||
assert(coll);
|
ASSERT(coll);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(coll);
|
const TypeObject *type = Object_GetType(coll);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->insert == NULL)
|
if(type->insert == NULL)
|
||||||
{
|
{
|
||||||
@@ -210,11 +210,11 @@ _Bool Object_Insert(Object *coll, Object *key, Object *val, Heap *heap, Error *e
|
|||||||
|
|
||||||
int Object_Count(Object *coll, Error *err)
|
int Object_Count(Object *coll, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(coll);
|
ASSERT(coll);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(coll);
|
const TypeObject *type = Object_GetType(coll);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->count == NULL)
|
if(type->count == NULL)
|
||||||
{
|
{
|
||||||
@@ -227,11 +227,11 @@ int Object_Count(Object *coll, Error *err)
|
|||||||
|
|
||||||
Object *Object_Next(Object *iter, Heap *heap, Error *err)
|
Object *Object_Next(Object *iter, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(iter);
|
ASSERT(iter);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(iter);
|
const TypeObject *type = Object_GetType(iter);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->next == NULL)
|
if(type->next == NULL)
|
||||||
{
|
{
|
||||||
@@ -244,11 +244,11 @@ Object *Object_Next(Object *iter, Heap *heap, Error *err)
|
|||||||
|
|
||||||
Object *Object_Prev(Object *iter, Heap *heap, Error *err)
|
Object *Object_Prev(Object *iter, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(iter);
|
ASSERT(iter);
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(iter);
|
const TypeObject *type = Object_GetType(iter);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->prev == NULL)
|
if(type->prev == NULL)
|
||||||
{
|
{
|
||||||
@@ -261,36 +261,36 @@ Object *Object_Prev(Object *iter, Heap *heap, Error *err)
|
|||||||
|
|
||||||
_Bool Object_IsInt(Object *obj)
|
_Bool Object_IsInt(Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type != NULL);
|
ASSERT(obj->type != NULL);
|
||||||
return obj->type->atomic == ATMTP_INT;
|
return obj->type->atomic == ATMTP_INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool Object_IsBool(Object *obj)
|
_Bool Object_IsBool(Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type != NULL);
|
ASSERT(obj->type != NULL);
|
||||||
return obj->type->atomic == ATMTP_BOOL;
|
return obj->type->atomic == ATMTP_BOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool Object_IsFloat(Object *obj)
|
_Bool Object_IsFloat(Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type != NULL);
|
ASSERT(obj->type != NULL);
|
||||||
return obj->type->atomic == ATMTP_FLOAT;
|
return obj->type->atomic == ATMTP_FLOAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool Object_IsString(Object *obj)
|
_Bool Object_IsString(Object *obj)
|
||||||
{
|
{
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
assert(obj->type != NULL);
|
ASSERT(obj->type != NULL);
|
||||||
return obj->type->atomic == ATMTP_STRING;
|
return obj->type->atomic == ATMTP_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int Object_ToInt(Object *obj, Error *err)
|
long long int Object_ToInt(Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(obj);
|
ASSERT(obj);
|
||||||
|
|
||||||
if(!Object_IsInt(obj))
|
if(!Object_IsInt(obj))
|
||||||
{
|
{
|
||||||
@@ -299,7 +299,7 @@ long long int Object_ToInt(Object *obj, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->to_int == NULL)
|
if(type->to_int == NULL)
|
||||||
{
|
{
|
||||||
@@ -312,8 +312,8 @@ long long int Object_ToInt(Object *obj, Error *err)
|
|||||||
|
|
||||||
_Bool Object_ToBool(Object *obj, Error *err)
|
_Bool Object_ToBool(Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(obj);
|
ASSERT(obj);
|
||||||
|
|
||||||
if(!Object_IsBool(obj))
|
if(!Object_IsBool(obj))
|
||||||
{
|
{
|
||||||
@@ -322,7 +322,7 @@ _Bool Object_ToBool(Object *obj, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->to_bool == NULL)
|
if(type->to_bool == NULL)
|
||||||
{
|
{
|
||||||
@@ -335,8 +335,8 @@ _Bool Object_ToBool(Object *obj, Error *err)
|
|||||||
|
|
||||||
double Object_ToFloat(Object *obj, Error *err)
|
double Object_ToFloat(Object *obj, Error *err)
|
||||||
{
|
{
|
||||||
assert(err);
|
ASSERT(err);
|
||||||
assert(obj);
|
ASSERT(obj);
|
||||||
|
|
||||||
if(!Object_IsFloat(obj))
|
if(!Object_IsFloat(obj))
|
||||||
{
|
{
|
||||||
@@ -345,7 +345,7 @@ double Object_ToFloat(Object *obj, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->to_float == NULL)
|
if(type->to_float == NULL)
|
||||||
{
|
{
|
||||||
@@ -358,8 +358,8 @@ double Object_ToFloat(Object *obj, Error *err)
|
|||||||
|
|
||||||
const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err)
|
const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err)
|
||||||
{
|
{
|
||||||
assert(err != NULL);
|
ASSERT(err != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
if(!Object_IsString(obj))
|
if(!Object_IsString(obj))
|
||||||
{
|
{
|
||||||
@@ -368,7 +368,7 @@ const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TypeObject *type = Object_GetType(obj);
|
const TypeObject *type = Object_GetType(obj);
|
||||||
assert(type);
|
ASSERT(type);
|
||||||
|
|
||||||
if(type->to_string == NULL)
|
if(type->to_string == NULL)
|
||||||
{
|
{
|
||||||
@@ -381,9 +381,9 @@ const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err)
|
|||||||
|
|
||||||
_Bool Object_Compare(Object *obj1, Object *obj2, Error *error)
|
_Bool Object_Compare(Object *obj1, Object *obj2, Error *error)
|
||||||
{
|
{
|
||||||
assert(obj1 != NULL);
|
ASSERT(obj1 != NULL);
|
||||||
assert(obj2 != NULL);
|
ASSERT(obj2 != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(obj1->type != obj2->type)
|
if(obj1->type != obj2->type)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -399,14 +399,14 @@ _Bool Object_Compare(Object *obj1, Object *obj2, Error *error)
|
|||||||
|
|
||||||
void Object_WalkReferences(Object *parent, void (*callback)(Object **referer, void *userp), void *userp)
|
void Object_WalkReferences(Object *parent, void (*callback)(Object **referer, void *userp), void *userp)
|
||||||
{
|
{
|
||||||
assert(parent != NULL);
|
ASSERT(parent != NULL);
|
||||||
if(parent->type->walk != NULL)
|
if(parent->type->walk != NULL)
|
||||||
parent->type->walk(parent, callback, userp);
|
parent->type->walk(parent, callback, userp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object_WalkExtensions(Object *parent, void (*callback)(void **referer, unsigned int size, void *userp), void *userp)
|
void Object_WalkExtensions(Object *parent, void (*callback)(void **referer, unsigned int size, void *userp), void *userp)
|
||||||
{
|
{
|
||||||
assert(parent != NULL);
|
ASSERT(parent != NULL);
|
||||||
if(parent->type->walkexts != NULL)
|
if(parent->type->walkexts != NULL)
|
||||||
parent->type->walkexts(parent, callback, userp);
|
parent->type->walkexts(parent, callback, userp);
|
||||||
}
|
}
|
||||||
@@ -105,8 +105,11 @@ static int call(Object *self, Object **argv, unsigned int argc, Object **rets, u
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
UNREACHABLE;
|
||||||
|
argv2 = NULL;
|
||||||
|
argc2 = -1;
|
||||||
}
|
}
|
||||||
else UNREACHABLE;
|
|
||||||
|
|
||||||
assert(func->callback != NULL);
|
assert(func->callback != NULL);
|
||||||
int retc = func->callback(func->runtime, argv2, argc2, rets, maxretc, error);
|
int retc = func->callback(func->runtime, argv2, argc2, rets, maxretc, error);
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
|||||||
if(!strcmp(name, map->slots[i].name))
|
if(!strcmp(name, map->slots[i].name))
|
||||||
{
|
{
|
||||||
StaticMapSlot slot = map->slots[i];
|
StaticMapSlot slot = map->slots[i];
|
||||||
Object *obj;
|
Object *obj = NULL;
|
||||||
switch(slot.kind)
|
switch(slot.kind)
|
||||||
{
|
{
|
||||||
case SM_BOOL: return Object_FromBool(slot.as_bool, heap, error);
|
case SM_BOOL: return Object_FromBool(slot.as_bool, heap, error);
|
||||||
|
|||||||
+130
-126
@@ -78,20 +78,20 @@ size_t Runtime_GetCurrentScriptFolder(Runtime *runtime, char *buff, size_t buffs
|
|||||||
{
|
{
|
||||||
// This is buggy code!!
|
// This is buggy code!!
|
||||||
size_t path_len = strlen(path);
|
size_t path_len = strlen(path);
|
||||||
assert(path_len > 0); // Not empty
|
ASSERT(path_len > 0); // Not empty
|
||||||
assert(Path_IsAbsolute(path)); // Is absolute
|
ASSERT(Path_IsAbsolute(path)); // Is absolute
|
||||||
assert(path[path_len-1] != '/'); // Doesn't end with a slash.
|
ASSERT(path[path_len-1] != '/'); // Doesn't end with a slash.
|
||||||
|
|
||||||
size_t popped = 0;
|
size_t popped = 0;
|
||||||
while(path[path_len-1-popped] != '/')
|
while(path[path_len-1-popped] != '/')
|
||||||
popped += 1;
|
popped += 1;
|
||||||
|
|
||||||
assert(path_len > popped);
|
ASSERT(path_len > popped);
|
||||||
|
|
||||||
dir_len = path_len - popped;
|
dir_len = path_len - popped;
|
||||||
|
|
||||||
assert(dir_len < path_len);
|
ASSERT(dir_len < path_len);
|
||||||
assert(path[dir_len-1] == '/');
|
ASSERT(path[dir_len-1] == '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dir_len >= buffsize)
|
if(dir_len >= buffsize)
|
||||||
@@ -105,7 +105,7 @@ size_t Runtime_GetCurrentScriptFolder(Runtime *runtime, char *buff, size_t buffs
|
|||||||
const char *Runtime_GetCurrentScriptAbsolutePath(Runtime *runtime)
|
const char *Runtime_GetCurrentScriptAbsolutePath(Runtime *runtime)
|
||||||
{
|
{
|
||||||
Executable *exe = Runtime_GetCurrentExecutable(runtime);
|
Executable *exe = Runtime_GetCurrentExecutable(runtime);
|
||||||
assert(exe != NULL);
|
ASSERT(exe != NULL);
|
||||||
|
|
||||||
Source *src = Executable_GetSource(exe);
|
Source *src = Executable_GetSource(exe);
|
||||||
if(src == NULL)
|
if(src == NULL)
|
||||||
@@ -115,7 +115,7 @@ const char *Runtime_GetCurrentScriptAbsolutePath(Runtime *runtime)
|
|||||||
if(path == NULL)
|
if(path == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
assert(path[0] != '\0');
|
ASSERT(path[0] != '\0');
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +207,9 @@ void Runtime_SetBuiltins(Runtime *runtime, Object *builtins)
|
|||||||
|
|
||||||
_Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj)
|
_Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj)
|
||||||
{
|
{
|
||||||
assert(runtime != NULL);
|
ASSERT(runtime != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
if(runtime->depth == 0)
|
if(runtime->depth == 0)
|
||||||
{
|
{
|
||||||
@@ -217,7 +217,7 @@ _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(runtime->frame->used <= MAX_FRAME_STACK);
|
ASSERT(runtime->frame->used <= MAX_FRAME_STACK);
|
||||||
|
|
||||||
if(runtime->frame->used == MAX_FRAME_STACK)
|
if(runtime->frame->used == MAX_FRAME_STACK)
|
||||||
{
|
{
|
||||||
@@ -237,8 +237,8 @@ _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj)
|
|||||||
|
|
||||||
_Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n)
|
_Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n)
|
||||||
{
|
{
|
||||||
assert(runtime != NULL);
|
ASSERT(runtime != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
|
|
||||||
if(runtime->depth == 0)
|
if(runtime->depth == 0)
|
||||||
{
|
{
|
||||||
@@ -246,7 +246,7 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(runtime->frame->used >= 0);
|
ASSERT(runtime->frame->used >= 0);
|
||||||
|
|
||||||
if((unsigned int) runtime->frame->used < n)
|
if((unsigned int) runtime->frame->used < n)
|
||||||
{
|
{
|
||||||
@@ -261,7 +261,7 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n)
|
|||||||
|
|
||||||
runtime->frame->used -= n;
|
runtime->frame->used -= n;
|
||||||
|
|
||||||
assert(runtime->frame->used >= 0);
|
ASSERT(runtime->frame->used >= 0);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -278,7 +278,7 @@ struct xSnapshot {
|
|||||||
|
|
||||||
Snapshot *Snapshot_New(Runtime *runtime)
|
Snapshot *Snapshot_New(Runtime *runtime)
|
||||||
{
|
{
|
||||||
assert(runtime->depth >= 0);
|
ASSERT(runtime->depth >= 0);
|
||||||
|
|
||||||
Snapshot *snapshot = malloc(sizeof(Snapshot) + sizeof(SnapshotNode) * runtime->depth);
|
Snapshot *snapshot = malloc(sizeof(Snapshot) + sizeof(SnapshotNode) * runtime->depth);
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ Snapshot *Snapshot_New(Runtime *runtime)
|
|||||||
|
|
||||||
while(snapshot->depth < runtime->depth)
|
while(snapshot->depth < runtime->depth)
|
||||||
{
|
{
|
||||||
assert(f != NULL);
|
ASSERT(f != NULL);
|
||||||
|
|
||||||
SnapshotNode *node = snapshot->nodes + snapshot->depth;
|
SnapshotNode *node = snapshot->nodes + snapshot->depth;
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ Snapshot *Snapshot_New(Runtime *runtime)
|
|||||||
snapshot->depth += 1;
|
snapshot->depth += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(f == NULL);
|
ASSERT(f == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return snapshot;
|
return snapshot;
|
||||||
@@ -328,8 +328,8 @@ void Snapshot_Free(Snapshot *snapshot)
|
|||||||
|
|
||||||
void Snapshot_Print(Snapshot *snapshot, FILE *fp)
|
void Snapshot_Print(Snapshot *snapshot, FILE *fp)
|
||||||
{
|
{
|
||||||
assert(snapshot != NULL);
|
ASSERT(snapshot != NULL);
|
||||||
assert(fp != NULL);
|
ASSERT(fp != NULL);
|
||||||
|
|
||||||
fprintf(fp, "Stack trace:\n");
|
fprintf(fp, "Stack trace:\n");
|
||||||
|
|
||||||
@@ -385,8 +385,8 @@ void Snapshot_Print(Snapshot *snapshot, FILE *fp)
|
|||||||
|
|
||||||
static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error)
|
static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
|
|
||||||
#define APPLY(x, y, z, id) \
|
#define APPLY(x, y, z, id) \
|
||||||
switch(opcode) \
|
switch(opcode) \
|
||||||
@@ -402,7 +402,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
} \
|
} \
|
||||||
(z) = (x) / (y); \
|
(z) = (x) / (y); \
|
||||||
break; \
|
break; \
|
||||||
default: assert(0); break; \
|
default: UNREACHABLE; break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *res;
|
Object *res;
|
||||||
@@ -422,7 +422,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
if(error->occurred)
|
if(error->occurred)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
long long int raw_res;
|
long long int raw_res = 0;
|
||||||
|
|
||||||
APPLY(raw_lop, raw_rop, raw_res, id)
|
APPLY(raw_lop, raw_rop, raw_res, id)
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
if(error->occurred)
|
if(error->occurred)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
double raw_res;
|
double raw_res = 0;
|
||||||
|
|
||||||
APPLY((double) raw_lop, raw_rop, raw_res, id)
|
APPLY((double) raw_lop, raw_rop, raw_res, id)
|
||||||
|
|
||||||
@@ -463,7 +463,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
if(error->occurred)
|
if(error->occurred)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
double raw_res;
|
double raw_res = 0;
|
||||||
|
|
||||||
APPLY(raw_lop, (double) raw_rop, raw_res, id)
|
APPLY(raw_lop, (double) raw_rop, raw_res, id)
|
||||||
|
|
||||||
@@ -477,7 +477,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
if(error->occurred)
|
if(error->occurred)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
double raw_res;
|
double raw_res = 0;
|
||||||
|
|
||||||
APPLY(raw_lop, raw_rop, raw_res, id)
|
APPLY(raw_lop, raw_rop, raw_res, id)
|
||||||
|
|
||||||
@@ -502,20 +502,20 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E
|
|||||||
|
|
||||||
static Object *do_relational_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error)
|
static Object *do_relational_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error)
|
||||||
{
|
{
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
|
|
||||||
#define APPLY(x, y, z, id) \
|
#define APPLY(x, y, z, id) \
|
||||||
switch(opcode) \
|
switch(opcode) \
|
||||||
{ \
|
{ \
|
||||||
case OPCODE_LSS: (z) = (x) < (y); break; \
|
case OPCODE_LSS: (z) = (x) < (y); break; \
|
||||||
case OPCODE_GRT: (z) = (x) > (y); break; \
|
case OPCODE_GRT: (z) = (x) > (y); break; \
|
||||||
case OPCODE_LEQ: (z) = (x) <= (y); break; \
|
case OPCODE_LEQ: (z) = (x) <= (y); break; \
|
||||||
case OPCODE_GEQ: (z) = (x) >= (y); break; \
|
case OPCODE_GEQ: (z) = (x) >= (y); break; \
|
||||||
default: assert(0); break; \
|
default: UNREACHABLE; break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
_Bool res;
|
_Bool res = 0;
|
||||||
|
|
||||||
if(Object_IsInt(lop))
|
if(Object_IsInt(lop))
|
||||||
{
|
{
|
||||||
@@ -596,8 +596,8 @@ static Object *do_relational_op(Object *lop, Object *rop, Opcode opcode, Heap *h
|
|||||||
|
|
||||||
static _Bool step(Runtime *runtime, Error *error)
|
static _Bool step(Runtime *runtime, Error *error)
|
||||||
{
|
{
|
||||||
assert(runtime != NULL);
|
ASSERT(runtime != NULL);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
Opcode opcode;
|
Opcode opcode;
|
||||||
Operand ops[3];
|
Operand ops[3];
|
||||||
int opc = sizeof(ops) / sizeof(ops[0]);
|
int opc = sizeof(ops) / sizeof(ops[0]);
|
||||||
@@ -618,7 +618,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_POS:
|
case OPCODE_POS:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used == 0)
|
if(runtime->frame->used == 0)
|
||||||
{
|
{
|
||||||
@@ -632,7 +632,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_NEG:
|
case OPCODE_NEG:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used == 0)
|
if(runtime->frame->used == 0)
|
||||||
{
|
{
|
||||||
@@ -641,13 +641,13 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object *top = Stack_Top(runtime->stack, 0);
|
Object *top = Stack_Top(runtime->stack, 0);
|
||||||
assert(top != NULL);
|
ASSERT(top != NULL);
|
||||||
|
|
||||||
if(!Runtime_Pop(runtime, error, 1))
|
if(!Runtime_Pop(runtime, error, 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Heap *heap = Runtime_GetHeap(runtime);
|
Heap *heap = Runtime_GetHeap(runtime);
|
||||||
assert(heap != NULL);
|
ASSERT(heap != NULL);
|
||||||
|
|
||||||
if(Object_IsInt(top))
|
if(Object_IsInt(top))
|
||||||
{
|
{
|
||||||
@@ -683,7 +683,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_NOT:
|
case OPCODE_NOT:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used == 0)
|
if(runtime->frame->used == 0)
|
||||||
{
|
{
|
||||||
@@ -696,7 +696,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
if(!Runtime_Pop(runtime, error, 1))
|
if(!Runtime_Pop(runtime, error, 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(top != NULL);
|
ASSERT(top != NULL);
|
||||||
|
|
||||||
_Bool v = Object_ToBool(top, error);
|
_Bool v = Object_ToBool(top, error);
|
||||||
|
|
||||||
@@ -718,7 +718,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
case OPCODE_MUL:
|
case OPCODE_MUL:
|
||||||
case OPCODE_DIV:
|
case OPCODE_DIV:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *rop = Stack_Top(runtime->stack, 0);
|
Object *rop = Stack_Top(runtime->stack, 0);
|
||||||
Object *lop = Stack_Top(runtime->stack, -1);
|
Object *lop = Stack_Top(runtime->stack, -1);
|
||||||
@@ -728,8 +728,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
// We managed to pop rop and lop,
|
// We managed to pop rop and lop,
|
||||||
// so we know they're not NULL.
|
// so we know they're not NULL.
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
|
|
||||||
Object *res = do_math_op(lop, rop, opcode, runtime->heap, error);
|
Object *res = do_math_op(lop, rop, opcode, runtime->heap, error);
|
||||||
|
|
||||||
@@ -744,7 +744,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
case OPCODE_EQL:
|
case OPCODE_EQL:
|
||||||
case OPCODE_NQL:
|
case OPCODE_NQL:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *rop = Stack_Top(runtime->stack, 0);
|
Object *rop = Stack_Top(runtime->stack, 0);
|
||||||
Object *lop = Stack_Top(runtime->stack, -1);
|
Object *lop = Stack_Top(runtime->stack, -1);
|
||||||
@@ -754,8 +754,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
// We managed to pop rop and lop,
|
// We managed to pop rop and lop,
|
||||||
// so we know they're not NULL.
|
// so we know they're not NULL.
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
|
|
||||||
_Bool rawres = Object_Compare(lop, rop, error);
|
_Bool rawres = Object_Compare(lop, rop, error);
|
||||||
|
|
||||||
@@ -780,7 +780,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
case OPCODE_LEQ:
|
case OPCODE_LEQ:
|
||||||
case OPCODE_GEQ:
|
case OPCODE_GEQ:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *rop = Stack_Top(runtime->stack, 0);
|
Object *rop = Stack_Top(runtime->stack, 0);
|
||||||
Object *lop = Stack_Top(runtime->stack, -1);
|
Object *lop = Stack_Top(runtime->stack, -1);
|
||||||
@@ -790,8 +790,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
// We managed to pop rop and lop,
|
// We managed to pop rop and lop,
|
||||||
// so we know they're not NULL.
|
// so we know they're not NULL.
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
|
|
||||||
Object *res = do_relational_op(lop, rop, opcode, runtime->heap, error);
|
Object *res = do_relational_op(lop, rop, opcode, runtime->heap, error);
|
||||||
|
|
||||||
@@ -806,7 +806,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
case OPCODE_AND:
|
case OPCODE_AND:
|
||||||
case OPCODE_OR:
|
case OPCODE_OR:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *rop = Stack_Top(runtime->stack, 0);
|
Object *rop = Stack_Top(runtime->stack, 0);
|
||||||
Object *lop = Stack_Top(runtime->stack, -1);
|
Object *lop = Stack_Top(runtime->stack, -1);
|
||||||
@@ -816,8 +816,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
// We managed to pop rop and lop,
|
// We managed to pop rop and lop,
|
||||||
// so we know they're not NULL.
|
// so we know they're not NULL.
|
||||||
assert(rop != NULL);
|
ASSERT(rop != NULL);
|
||||||
assert(lop != NULL);
|
ASSERT(lop != NULL);
|
||||||
|
|
||||||
_Bool raw_rop, raw_lop, raw_res;
|
_Bool raw_rop, raw_lop, raw_res;
|
||||||
raw_lop = Object_ToBool(lop, error);
|
raw_lop = Object_ToBool(lop, error);
|
||||||
@@ -828,7 +828,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
{
|
{
|
||||||
case OPCODE_AND: raw_res = raw_lop && raw_rop; break;
|
case OPCODE_AND: raw_res = raw_lop && raw_rop; break;
|
||||||
case OPCODE_OR: raw_res = raw_lop || raw_rop; break;
|
case OPCODE_OR: raw_res = raw_lop || raw_rop; break;
|
||||||
default: assert(0); break;
|
default:
|
||||||
|
UNREACHABLE;
|
||||||
|
raw_res = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *res = Object_FromBool(raw_res, runtime->heap, error);
|
Object *res = Object_FromBool(raw_res, runtime->heap, error);
|
||||||
@@ -843,8 +846,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_ASS:
|
case OPCODE_ASS:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_STRING);
|
ASSERT(ops[0].type == OPTP_STRING);
|
||||||
|
|
||||||
if(runtime->frame->used == 0)
|
if(runtime->frame->used == 0)
|
||||||
{
|
{
|
||||||
@@ -853,7 +856,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object *val = Stack_Top(runtime->stack, 0);
|
Object *val = Stack_Top(runtime->stack, 0);
|
||||||
assert(val != NULL);
|
ASSERT(val != NULL);
|
||||||
|
|
||||||
Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
||||||
|
|
||||||
@@ -867,7 +870,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_POP:
|
case OPCODE_POP:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
|
|
||||||
if(!Runtime_Pop(runtime, error, ops[0].as_int))
|
if(!Runtime_Pop(runtime, error, ops[0].as_int))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -876,13 +879,13 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_CALL:
|
case OPCODE_CALL:
|
||||||
{
|
{
|
||||||
assert(opc == 2);
|
ASSERT(opc == 2);
|
||||||
assert(ops[0].type == OPTP_INT);
|
ASSERT(ops[0].type == OPTP_INT);
|
||||||
assert(ops[1].type == OPTP_INT);
|
ASSERT(ops[1].type == OPTP_INT);
|
||||||
|
|
||||||
int argc = ops[0].as_int;
|
int argc = ops[0].as_int;
|
||||||
int retc = ops[1].as_int;
|
int retc = ops[1].as_int;
|
||||||
assert(argc >= 0 && retc > 0);
|
ASSERT(argc >= 0 && retc > 0);
|
||||||
|
|
||||||
if(runtime->frame->used < argc + 1)
|
if(runtime->frame->used < argc + 1)
|
||||||
{
|
{
|
||||||
@@ -891,7 +894,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object *callable = Stack_Top(runtime->stack, 0);
|
Object *callable = Stack_Top(runtime->stack, 0);
|
||||||
assert(callable != NULL);
|
ASSERT(callable != NULL);
|
||||||
|
|
||||||
Object *argv[8];
|
Object *argv[8];
|
||||||
|
|
||||||
@@ -905,12 +908,12 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
for(int i = 0; i < argc; i += 1)
|
for(int i = 0; i < argc; i += 1)
|
||||||
{
|
{
|
||||||
argv[i] = Stack_Top(runtime->stack, -(i+1));
|
argv[i] = Stack_Top(runtime->stack, -(i+1));
|
||||||
assert(argv[i] != NULL);
|
ASSERT(argv[i] != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
(void) Runtime_Pop(runtime, error, argc+1);
|
(void) Runtime_Pop(runtime, error, argc+1);
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
Object *rets[8];
|
Object *rets[8];
|
||||||
unsigned int maxrets = sizeof(rets)/sizeof(rets[0]);
|
unsigned int maxrets = sizeof(rets)/sizeof(rets[0]);
|
||||||
@@ -922,7 +925,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
// NOTE: Every local object reference is invalidated from here.
|
// NOTE: Every local object reference is invalidated from here.
|
||||||
|
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
for(int g = 0; g < MIN(num_rets, retc); g += 1)
|
for(int g = 0; g < MIN(num_rets, retc); g += 1)
|
||||||
if(!Runtime_Push(runtime, error, rets[g]))
|
if(!Runtime_Push(runtime, error, rets[g]))
|
||||||
@@ -943,7 +946,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_SELECT:
|
case OPCODE_SELECT:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used < 2)
|
if(runtime->frame->used < 2)
|
||||||
{
|
{
|
||||||
@@ -954,12 +957,12 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
Object *col = Stack_Top(runtime->stack, -1);
|
Object *col = Stack_Top(runtime->stack, -1);
|
||||||
Object *key = Stack_Top(runtime->stack, 0);
|
Object *key = Stack_Top(runtime->stack, 0);
|
||||||
|
|
||||||
assert(col != NULL && key != NULL);
|
ASSERT(col != NULL && key != NULL);
|
||||||
|
|
||||||
if(!Runtime_Pop(runtime, error, 2))
|
if(!Runtime_Pop(runtime, error, 2))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
Error dummy;
|
Error dummy;
|
||||||
Error_Init(&dummy); // We want to catch the error reported by this Object_Select.
|
Error_Init(&dummy); // We want to catch the error reported by this Object_Select.
|
||||||
@@ -976,18 +979,18 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
|
|
||||||
if(!Runtime_Push(runtime, error, val))
|
if(!Runtime_Push(runtime, error, val))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(error->occurred == 0);
|
ASSERT(error->occurred == 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OPCODE_INSERT:
|
case OPCODE_INSERT:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used < 3)
|
if(runtime->frame->used < 3)
|
||||||
{
|
{
|
||||||
@@ -999,7 +1002,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
Object *key = Stack_Top(runtime->stack, -1);
|
Object *key = Stack_Top(runtime->stack, -1);
|
||||||
Object *val = Stack_Top(runtime->stack, 0);
|
Object *val = Stack_Top(runtime->stack, 0);
|
||||||
|
|
||||||
assert(col != NULL && key != NULL && val != NULL);
|
ASSERT(col != NULL && key != NULL && val != NULL);
|
||||||
|
|
||||||
if(!Runtime_Pop(runtime, error, 2))
|
if(!Runtime_Pop(runtime, error, 2))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1011,7 +1014,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_INSERT2:
|
case OPCODE_INSERT2:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used < 3)
|
if(runtime->frame->used < 3)
|
||||||
{
|
{
|
||||||
@@ -1023,7 +1026,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
Object *col = Stack_Top(runtime->stack, -1);
|
Object *col = Stack_Top(runtime->stack, -1);
|
||||||
Object *key = Stack_Top(runtime->stack, 0);
|
Object *key = Stack_Top(runtime->stack, 0);
|
||||||
|
|
||||||
assert(col != NULL && key != NULL && val != NULL);
|
ASSERT(col != NULL && key != NULL && val != NULL);
|
||||||
|
|
||||||
if(!Runtime_Pop(runtime, error, 2))
|
if(!Runtime_Pop(runtime, error, 2))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1035,8 +1038,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHINT:
|
case OPCODE_PUSHINT:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_INT);
|
ASSERT(ops[0].type == OPTP_INT);
|
||||||
|
|
||||||
Object *obj = Object_FromInt(ops[0].as_int, runtime->heap, error);
|
Object *obj = Object_FromInt(ops[0].as_int, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1050,8 +1053,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHFLT:
|
case OPCODE_PUSHFLT:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_FLOAT);
|
ASSERT(ops[0].type == OPTP_FLOAT);
|
||||||
|
|
||||||
Object *obj = Object_FromFloat(ops[0].as_float, runtime->heap, error);
|
Object *obj = Object_FromFloat(ops[0].as_float, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1065,8 +1068,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHSTR:
|
case OPCODE_PUSHSTR:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_STRING);
|
ASSERT(ops[0].type == OPTP_STRING);
|
||||||
|
|
||||||
Object *obj = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
Object *obj = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1080,8 +1083,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHVAR:
|
case OPCODE_PUSHVAR:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_STRING);
|
ASSERT(ops[0].type == OPTP_STRING);
|
||||||
|
|
||||||
Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1120,7 +1123,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHNNE:
|
case OPCODE_PUSHNNE:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *obj = Object_NewNone(runtime->heap, error);
|
Object *obj = Object_NewNone(runtime->heap, error);
|
||||||
|
|
||||||
@@ -1134,7 +1137,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHTRU:
|
case OPCODE_PUSHTRU:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *obj = Object_FromBool(1, runtime->heap, error);
|
Object *obj = Object_FromBool(1, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1148,7 +1151,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHFLS:
|
case OPCODE_PUSHFLS:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *obj = Object_FromBool(0, runtime->heap, error);
|
Object *obj = Object_FromBool(0, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1162,9 +1165,9 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHFUN:
|
case OPCODE_PUSHFUN:
|
||||||
{
|
{
|
||||||
assert(opc == 2);
|
ASSERT(opc == 2);
|
||||||
assert(ops[0].type == OPTP_IDX);
|
ASSERT(ops[0].type == OPTP_IDX);
|
||||||
assert(ops[1].type == OPTP_INT);
|
ASSERT(ops[1].type == OPTP_INT);
|
||||||
|
|
||||||
Object *closure = Object_NewClosure(runtime->frame->closure, runtime->frame->locals, Runtime_GetHeap(runtime), error);
|
Object *closure = Object_NewClosure(runtime->frame->closure, runtime->frame->locals, Runtime_GetHeap(runtime), error);
|
||||||
|
|
||||||
@@ -1183,8 +1186,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHLST:
|
case OPCODE_PUSHLST:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_INT);
|
ASSERT(ops[0].type == OPTP_INT);
|
||||||
|
|
||||||
Object *obj = Object_NewList(ops[0].as_int, runtime->heap, error);
|
Object *obj = Object_NewList(ops[0].as_int, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1198,8 +1201,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHMAP:
|
case OPCODE_PUSHMAP:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_INT);
|
ASSERT(ops[0].type == OPTP_INT);
|
||||||
|
|
||||||
Object *obj = Object_NewMap(ops[0].as_int, runtime->heap, error);
|
Object *obj = Object_NewMap(ops[0].as_int, runtime->heap, error);
|
||||||
|
|
||||||
@@ -1213,10 +1216,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHTYPTYP:
|
case OPCODE_PUSHTYPTYP:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *obj = (Object*) Object_GetTypeType();
|
Object *obj = (Object*) Object_GetTypeType();
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
if(!Runtime_Push(runtime, error, obj))
|
if(!Runtime_Push(runtime, error, obj))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1225,10 +1228,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHNNETYP:
|
case OPCODE_PUSHNNETYP:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *obj = (Object*) Object_GetNoneType();
|
Object *obj = (Object*) Object_GetNoneType();
|
||||||
assert(obj != NULL);
|
ASSERT(obj != NULL);
|
||||||
|
|
||||||
if(!Runtime_Push(runtime, error, obj))
|
if(!Runtime_Push(runtime, error, obj))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1237,7 +1240,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_PUSHTYP:
|
case OPCODE_PUSHTYP:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
if(runtime->frame->used < 1)
|
if(runtime->frame->used < 1)
|
||||||
{
|
{
|
||||||
@@ -1246,10 +1249,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object *top = Stack_Top(runtime->stack, 0);
|
Object *top = Stack_Top(runtime->stack, 0);
|
||||||
assert(top != NULL);
|
ASSERT(top != NULL);
|
||||||
|
|
||||||
Object *typ = (Object*) Object_GetType(top);
|
Object *typ = (Object*) Object_GetType(top);
|
||||||
assert(typ != NULL);
|
ASSERT(typ != NULL);
|
||||||
|
|
||||||
if(!Runtime_Push(runtime, error, typ))
|
if(!Runtime_Push(runtime, error, typ))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1258,10 +1261,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_EXIT:
|
case OPCODE_EXIT:
|
||||||
{
|
{
|
||||||
assert(opc == 0);
|
ASSERT(opc == 0);
|
||||||
|
|
||||||
Object *vars = runtime->frame->locals;
|
Object *vars = runtime->frame->locals;
|
||||||
assert(vars != NULL);
|
ASSERT(vars != NULL);
|
||||||
|
|
||||||
if(!Runtime_Push(runtime, error, vars))
|
if(!Runtime_Push(runtime, error, vars))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1270,33 +1273,34 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_RETURN:
|
case OPCODE_RETURN:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_INT);
|
ASSERT(ops[0].type == OPTP_INT);
|
||||||
int retc = ops[0].as_int;
|
int retc = ops[0].as_int;
|
||||||
assert(retc >= 0);
|
UNUSED(retc);
|
||||||
assert(retc == runtime->frame->used);
|
ASSERT(retc >= 0);
|
||||||
|
ASSERT(retc == runtime->frame->used);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OPCODE_ERROR:
|
case OPCODE_ERROR:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_STRING);
|
ASSERT(ops[0].type == OPTP_STRING);
|
||||||
const char *msg = ops[0].as_string;
|
const char *msg = ops[0].as_string;
|
||||||
Error_Report(error, 0, "%s", msg);
|
Error_Report(error, 0, "%s", msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case OPCODE_JUMP:
|
case OPCODE_JUMP:
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_IDX);
|
ASSERT(ops[0].type == OPTP_IDX);
|
||||||
runtime->frame->index = ops[0].as_int;
|
runtime->frame->index = ops[0].as_int;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case OPCODE_JUMPIFANDPOP:
|
case OPCODE_JUMPIFANDPOP:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_IDX);
|
ASSERT(ops[0].type == OPTP_IDX);
|
||||||
|
|
||||||
long long int target = ops[0].as_int;
|
long long int target = ops[0].as_int;
|
||||||
|
|
||||||
@@ -1311,7 +1315,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
if(!Runtime_Pop(runtime, error, 1))
|
if(!Runtime_Pop(runtime, error, 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(top != NULL);
|
ASSERT(top != NULL);
|
||||||
|
|
||||||
if(!Object_IsBool(top))
|
if(!Object_IsBool(top))
|
||||||
{
|
{
|
||||||
@@ -1327,8 +1331,8 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
|
|
||||||
case OPCODE_JUMPIFNOTANDPOP:
|
case OPCODE_JUMPIFNOTANDPOP:
|
||||||
{
|
{
|
||||||
assert(opc == 1);
|
ASSERT(opc == 1);
|
||||||
assert(ops[0].type == OPTP_IDX);
|
ASSERT(ops[0].type == OPTP_IDX);
|
||||||
|
|
||||||
long long int target = ops[0].as_int;
|
long long int target = ops[0].as_int;
|
||||||
|
|
||||||
@@ -1343,7 +1347,7 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
if(!Runtime_Pop(runtime, error, 1))
|
if(!Runtime_Pop(runtime, error, 1))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(top != NULL);
|
ASSERT(top != NULL);
|
||||||
|
|
||||||
if(!Object_IsBool(top))
|
if(!Object_IsBool(top))
|
||||||
{
|
{
|
||||||
@@ -1384,7 +1388,7 @@ static _Bool collect(Runtime *runtime, Error *error)
|
|||||||
for(unsigned int i = 0; i < Stack_Size(runtime->stack); i += 1)
|
for(unsigned int i = 0; i < Stack_Size(runtime->stack); i += 1)
|
||||||
{
|
{
|
||||||
Object **ref = (Object**) Stack_TopRef(runtime->stack, -i);
|
Object **ref = (Object**) Stack_TopRef(runtime->stack, -i);
|
||||||
assert(ref != NULL);
|
ASSERT(ref != NULL);
|
||||||
|
|
||||||
Heap_CollectReference(ref, runtime->heap);
|
Heap_CollectReference(ref, runtime->heap);
|
||||||
}
|
}
|
||||||
@@ -1398,11 +1402,11 @@ int run(Runtime *runtime, Error *error,
|
|||||||
Object **argv, int argc,
|
Object **argv, int argc,
|
||||||
Object **rets, int maxretc)
|
Object **rets, int maxretc)
|
||||||
{
|
{
|
||||||
assert(runtime != NULL);
|
ASSERT(runtime != NULL);
|
||||||
assert(error != NULL);
|
ASSERT(error != NULL);
|
||||||
assert(exe != NULL);
|
ASSERT(exe != NULL);
|
||||||
assert(index >= 0);
|
ASSERT(index >= 0);
|
||||||
assert(argc >= 0);
|
ASSERT(argc >= 0);
|
||||||
|
|
||||||
if(runtime->depth == MAX_FRAMES)
|
if(runtime->depth == MAX_FRAMES)
|
||||||
{
|
{
|
||||||
@@ -1410,7 +1414,7 @@ int run(Runtime *runtime, Error *error,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(runtime->depth < MAX_FRAMES);
|
ASSERT(runtime->depth < MAX_FRAMES);
|
||||||
|
|
||||||
// Initialize the frame.
|
// Initialize the frame.
|
||||||
Frame frame;
|
Frame frame;
|
||||||
@@ -1485,7 +1489,7 @@ int run(Runtime *runtime, Error *error,
|
|||||||
for(int i = 0; i < retc; i += 1)
|
for(int i = 0; i < retc; i += 1)
|
||||||
{
|
{
|
||||||
rets[i] = Stack_Top(runtime->stack, i - retc + 1);
|
rets[i] = Stack_Top(runtime->stack, i - retc + 1);
|
||||||
assert(rets[i] != NULL);
|
ASSERT(rets[i] != NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-11
@@ -29,7 +29,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "bpalloc.h"
|
#include "bpalloc.h"
|
||||||
@@ -117,8 +116,8 @@ BPAlloc *BPAlloc_Init3(void *mem, int mem_size, int chunk_size,
|
|||||||
void *(*fn_malloc)(void *userp, int size),
|
void *(*fn_malloc)(void *userp, int size),
|
||||||
void (*fn_free )(void *userp, void *addr))
|
void (*fn_free )(void *userp, void *addr))
|
||||||
{
|
{
|
||||||
assert(mem != NULL);
|
ASSERT(mem != NULL);
|
||||||
assert(mem_size >= 0);
|
ASSERT(mem_size >= 0);
|
||||||
|
|
||||||
if(chunk_size < 0)
|
if(chunk_size < 0)
|
||||||
chunk_size = CHUNK_SIZE;
|
chunk_size = CHUNK_SIZE;
|
||||||
@@ -161,7 +160,7 @@ BPAlloc *BPAlloc_Init3(void *mem, int mem_size, int chunk_size,
|
|||||||
|
|
||||||
void BPAlloc_Free(BPAlloc *alloc)
|
void BPAlloc_Free(BPAlloc *alloc)
|
||||||
{
|
{
|
||||||
assert(alloc != NULL);
|
ASSERT(alloc != NULL);
|
||||||
|
|
||||||
#if USING_VALGRIND
|
#if USING_VALGRIND
|
||||||
VALGRIND_DESTROY_MEMPOOL(alloc);
|
VALGRIND_DESTROY_MEMPOOL(alloc);
|
||||||
@@ -186,8 +185,8 @@ void BPAlloc_Free(BPAlloc *alloc)
|
|||||||
|
|
||||||
void *BPAlloc_Malloc(BPAlloc *alloc, int req_size)
|
void *BPAlloc_Malloc(BPAlloc *alloc, int req_size)
|
||||||
{
|
{
|
||||||
assert(alloc != NULL);
|
ASSERT(alloc != NULL);
|
||||||
assert(req_size >= 0);
|
ASSERT(req_size >= 0);
|
||||||
|
|
||||||
alloc->used += PADDING;
|
alloc->used += PADDING;
|
||||||
|
|
||||||
@@ -201,7 +200,7 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size)
|
|||||||
// size to the requested size.
|
// size to the requested size.
|
||||||
int chunk_size = MAX(alloc->minsize, req_size + PADDING);
|
int chunk_size = MAX(alloc->minsize, req_size + PADDING);
|
||||||
|
|
||||||
assert(alloc->fn_malloc != NULL);
|
ASSERT(alloc->fn_malloc != NULL);
|
||||||
BPAllocChunk *chunk = alloc->fn_malloc(alloc->userp, sizeof(BPAllocChunk) + chunk_size);
|
BPAllocChunk *chunk = alloc->fn_malloc(alloc->userp, sizeof(BPAllocChunk) + chunk_size);
|
||||||
|
|
||||||
if(chunk == NULL)
|
if(chunk == NULL)
|
||||||
@@ -218,7 +217,7 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size)
|
|||||||
|
|
||||||
void *addr = alloc->tail->body + alloc->used;
|
void *addr = alloc->tail->body + alloc->used;
|
||||||
|
|
||||||
assert(((intptr_t) addr) % 8 == 0);
|
ASSERT(((intptr_t) addr) % 8 == 0);
|
||||||
|
|
||||||
alloc->used += req_size;
|
alloc->used += req_size;
|
||||||
|
|
||||||
@@ -233,15 +232,17 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size)
|
|||||||
|
|
||||||
static void *default_fn_malloc(void *userp, int size)
|
static void *default_fn_malloc(void *userp, int size)
|
||||||
{
|
{
|
||||||
assert(userp == NULL);
|
UNUSED(userp);
|
||||||
assert(size >= 0);
|
ASSERT(userp == NULL);
|
||||||
|
ASSERT(size >= 0);
|
||||||
|
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void default_fn_free(void *userp, void *addr)
|
static void default_fn_free(void *userp, void *addr)
|
||||||
{
|
{
|
||||||
assert(userp == NULL);
|
UNUSED(userp);
|
||||||
|
ASSERT(userp == NULL);
|
||||||
|
|
||||||
free(addr);
|
free(addr);
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-3
@@ -28,8 +28,6 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
@@ -42,6 +40,26 @@
|
|||||||
#define NULL ((void*) 0)
|
#define NULL ((void*) 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define UNREACHABLE assert(0);
|
#define UNUSED(x) ((void) (x))
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define ASSERT(X) \
|
||||||
|
do { \
|
||||||
|
if(!(X)) { \
|
||||||
|
fprintf(stderr, "Assertion failure %s:%d (in %s): [" #X "] is false\n", __FILE__, __LINE__, __func__); \
|
||||||
|
abort(); \
|
||||||
|
} \
|
||||||
|
} while(0);
|
||||||
|
#define UNREACHABLE \
|
||||||
|
do { \
|
||||||
|
if(!(x)) { \
|
||||||
|
fprintf(stderr, "ABORT at %s:%d (in %s): Reached code assumed to be unreachable\n", __FILE__, __LINE__, __func__); \
|
||||||
|
abort(); \
|
||||||
|
} \
|
||||||
|
} while(0);
|
||||||
|
#else
|
||||||
|
#define ASSERT(x)
|
||||||
|
#define UNREACHABLE
|
||||||
|
#endif
|
||||||
|
|
||||||
#define membersizeof(type, member) (sizeof(((type*) 0)->member))
|
#define membersizeof(type, member) (sizeof(((type*) 0)->member))
|
||||||
@@ -55,7 +55,7 @@ void *Stack_New(int size)
|
|||||||
if(s == NULL)
|
if(s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
assert((intptr_t) s % 8 == 0);
|
ASSERT((intptr_t) s % 8 == 0);
|
||||||
|
|
||||||
s->size = size;
|
s->size = size;
|
||||||
s->used = 0;
|
s->used = 0;
|
||||||
@@ -70,7 +70,7 @@ static Stack *unmark(Stack *s)
|
|||||||
|
|
||||||
void *Stack_Top(Stack *s, int n)
|
void *Stack_Top(Stack *s, int n)
|
||||||
{
|
{
|
||||||
assert(n <= 0);
|
ASSERT(n <= 0);
|
||||||
|
|
||||||
// Remove readonly bit.
|
// Remove readonly bit.
|
||||||
s = unmark(s);
|
s = unmark(s);
|
||||||
@@ -86,7 +86,7 @@ void *Stack_Top(Stack *s, int n)
|
|||||||
|
|
||||||
void **Stack_TopRef(Stack *s, int n)
|
void **Stack_TopRef(Stack *s, int n)
|
||||||
{
|
{
|
||||||
assert(n <= 0);
|
ASSERT(n <= 0);
|
||||||
|
|
||||||
if(Stack_IsReadOnlyCopy(s))
|
if(Stack_IsReadOnlyCopy(s))
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -118,8 +118,8 @@ _Bool Stack_Pop(Stack *s, unsigned int n)
|
|||||||
|
|
||||||
_Bool Stack_Push(Stack *s, void *item)
|
_Bool Stack_Push(Stack *s, void *item)
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
ASSERT(s != NULL);
|
||||||
assert(item != NULL);
|
ASSERT(item != NULL);
|
||||||
|
|
||||||
if(Stack_IsReadOnlyCopy(s))
|
if(Stack_IsReadOnlyCopy(s))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -159,7 +159,7 @@ void Stack_Free(Stack *s)
|
|||||||
s = unmark(s);
|
s = unmark(s);
|
||||||
|
|
||||||
s->refs -= 1;
|
s->refs -= 1;
|
||||||
assert(s->refs >= 0);
|
ASSERT(s->refs >= 0);
|
||||||
|
|
||||||
if(s->refs == 0)
|
if(s->refs == 0)
|
||||||
free(s);
|
free(s);
|
||||||
|
|||||||
+14
-12
@@ -28,8 +28,8 @@
|
|||||||
** +--------------------------------------------------------------------------+
|
** +--------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stddef.h> // NULL
|
#include <stddef.h> // NULL
|
||||||
|
#include "defs.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
// If this is turned on, these functions will assume
|
// If this is turned on, these functions will assume
|
||||||
@@ -137,8 +137,8 @@ int utf8_sequence_from_utf32_codepoint(char *utf8_data, int nbytes, uint32_t utf
|
|||||||
*/
|
*/
|
||||||
int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t *utf32_code)
|
int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t *utf32_code)
|
||||||
{
|
{
|
||||||
assert(utf8_data != NULL);
|
ASSERT(utf8_data != NULL);
|
||||||
assert(nbytes >= 0);
|
ASSERT(nbytes >= 0);
|
||||||
|
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
if(utf32_code == NULL)
|
if(utf32_code == NULL)
|
||||||
@@ -204,7 +204,7 @@ int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t
|
|||||||
= (((uint32_t) utf8_data[0] & 0x1f) << 6)
|
= (((uint32_t) utf8_data[0] & 0x1f) << 6)
|
||||||
| (((uint32_t) utf8_data[1] & 0x3f));
|
| (((uint32_t) utf8_data[1] & 0x3f));
|
||||||
|
|
||||||
assert(*utf32_code <= 0x10ffff);
|
ASSERT(*utf32_code <= 0x10ffff);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,8 +248,8 @@ int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t
|
|||||||
*/
|
*/
|
||||||
int utf8_strlen(const char *utf8_data, int nbytes)
|
int utf8_strlen(const char *utf8_data, int nbytes)
|
||||||
{
|
{
|
||||||
assert(utf8_data != NULL);
|
ASSERT(utf8_data != NULL);
|
||||||
assert(nbytes >= 0);
|
ASSERT(nbytes >= 0);
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
@@ -324,8 +324,10 @@ int utf8_strlen(const char *utf8_data, int nbytes)
|
|||||||
*/
|
*/
|
||||||
int utf8_prev(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
int utf8_prev(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
||||||
{
|
{
|
||||||
assert(idx >= 0);
|
UNUSED(nbytes);
|
||||||
assert(idx <= nbytes);
|
ASSERT(idx >= 0);
|
||||||
|
ASSERT(idx <= nbytes);
|
||||||
|
|
||||||
|
|
||||||
// [idx] currently refers to the head byte
|
// [idx] currently refers to the head byte
|
||||||
// of a UTF-8 sequence. We need to first
|
// of a UTF-8 sequence. We need to first
|
||||||
@@ -384,13 +386,13 @@ int utf8_prev(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
|||||||
// The sequence wasn't valid UTF-8.
|
// The sequence wasn't valid UTF-8.
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
assert(n > 0);
|
ASSERT(n > 0);
|
||||||
|
|
||||||
if(n < aux + 1)
|
if(n < aux + 1)
|
||||||
// Not all of the auxiliary bytes were considered while parsing.
|
// Not all of the auxiliary bytes were considered while parsing.
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
assert(n == aux + 1);
|
ASSERT(n == aux + 1);
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
@@ -444,8 +446,8 @@ int utf8_next(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
|||||||
|
|
||||||
int utf8_curr(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
int utf8_curr(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code)
|
||||||
{
|
{
|
||||||
assert(idx >= 0);
|
ASSERT(idx >= 0);
|
||||||
assert(idx < nbytes);
|
ASSERT(idx < nbytes);
|
||||||
|
|
||||||
int n = utf8_sequence_to_utf32_codepoint(utf8_data + idx, nbytes - idx, utf32_code);
|
int n = utf8_sequence_to_utf32_codepoint(utf8_data + idx, nbytes - idx, utf32_code);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user