added stack trace log on error
This commit is contained in:
@@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
#define MAX_HEADERS 16
|
||||||
|
#define MAX_URI 4096
|
||||||
|
#define MAX_BODY (1024 * 1024)
|
||||||
|
#define MAX_HNAME 128
|
||||||
|
#define MAX_HBODY 1024
|
||||||
|
|
||||||
|
#define BUFFER_INIT_SIZE 256
|
||||||
|
#define BUFFER_GROW_FACTOR 2
|
||||||
|
#define BUFFER_GROW_ADDEND 0
|
||||||
|
|
||||||
|
#define BACKLOG 128
|
||||||
|
#define POLL_TIMEOUT 5000
|
||||||
|
#define MAX_POLL_EVENTS 64
|
||||||
|
#define IMPLICIT_LENGTH 1
|
||||||
|
|
||||||
|
#define MAX_CLIENTS 256
|
||||||
|
#define MAX_ALIVE 64
|
||||||
|
|
||||||
|
typedef void llhs_response;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
llhs_HTTP_0_9,
|
||||||
|
llhs_HTTP_1_0,
|
||||||
|
llhs_HTTP_1_1,
|
||||||
|
} llhs_version;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
llhs_GET,
|
||||||
|
llhs_PUT,
|
||||||
|
llhs_POST,
|
||||||
|
llhs_HEAD,
|
||||||
|
llhs_TRACE,
|
||||||
|
llhs_PATCH,
|
||||||
|
llhs_DELETE,
|
||||||
|
llhs_OPTIONS,
|
||||||
|
llhs_CONNECT,
|
||||||
|
} llhs_method;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
const char *body;
|
||||||
|
int namel;
|
||||||
|
int bodyl;
|
||||||
|
} llhs_header;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
llhs_version version;
|
||||||
|
llhs_method method;
|
||||||
|
const char *URI;
|
||||||
|
int URIl;
|
||||||
|
llhs_header headers[MAX_HEADERS];
|
||||||
|
int headerc;
|
||||||
|
const void *body;
|
||||||
|
int bodyl;
|
||||||
|
} llhs_request;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
_Bool occurred;
|
||||||
|
char message[256];
|
||||||
|
int length;
|
||||||
|
const char *file,
|
||||||
|
*func;
|
||||||
|
int line;
|
||||||
|
} llhs_error;
|
||||||
|
|
||||||
|
typedef void (*llhs_callback)(void *userp, const llhs_request *req, llhs_response *res);
|
||||||
|
typedef void (*llhs_logger )(void *userp, const char *level, const char *msg);
|
||||||
|
|
||||||
|
_Bool llhs_serve(unsigned short port, void *userp, llhs_callback callback, llhs_logger logger, llhs_error *error);
|
||||||
|
|
||||||
|
_Bool llhs_match (const char *x, const char *y);
|
||||||
|
_Bool llhs_match2(const char *x, const char *y, int xl, int yl);
|
||||||
|
const char *llhs_getheader(llhs_request *res, const char *name);
|
||||||
|
|
||||||
|
void llhs_setcode (llhs_response *res, int code);
|
||||||
|
_Bool llhs_setbody (llhs_response *res, const void *body, int size);
|
||||||
|
void llhs_setbody2 (llhs_response *res, void *body, int bodyl, void (*free)(void *addr));
|
||||||
|
_Bool llhs_setheader (llhs_response *res, const char *name, const char *body);
|
||||||
|
_Bool llhs_setheader2(llhs_response *res, const char *name, int body);
|
||||||
Binary file not shown.
@@ -4,3 +4,10 @@ l = [1, 2, 3, 4];
|
|||||||
|
|
||||||
print('The list contains ', count(l), ' items.\n');
|
print('The list contains ', count(l), ' items.\n');
|
||||||
print('The list is: ', l, '.\n');
|
print('The list is: ', l, '.\n');
|
||||||
|
|
||||||
|
|
||||||
|
fun fail()
|
||||||
|
assert(false);
|
||||||
|
|
||||||
|
|
||||||
|
fail();
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
fun index(req)
|
||||||
|
return {code: 200, 'body': 'Hello, world!'};
|
||||||
|
|
||||||
|
routes = {
|
||||||
|
'/': index,
|
||||||
|
'/groups': list_groups
|
||||||
|
}
|
||||||
|
|
||||||
|
res = serve(8080, routes);
|
||||||
+15
@@ -218,6 +218,21 @@ int main(int argc, char **argv)
|
|||||||
RuntimeError error;
|
RuntimeError error;
|
||||||
RuntimeError_Init(&error, runtime);
|
RuntimeError_Init(&error, runtime);
|
||||||
|
|
||||||
|
Object *builtins = Object_NewBuiltinsMap(runtime, Runtime_GetHeap(runtime), (Error*) &error);
|
||||||
|
|
||||||
|
if(builtins == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Couldn't initialize runtime.\n");
|
||||||
|
Debug_Free(dbg);
|
||||||
|
Source_Free(src);
|
||||||
|
Executable_Free(exe);
|
||||||
|
RuntimeError_Free(&error);
|
||||||
|
Runtime_Free(runtime);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime_SetBuiltins(runtime, builtins);
|
||||||
|
|
||||||
Object *result = run(runtime, (Error*) &error, exe, 0, NULL, 0);
|
Object *result = run(runtime, (Error*) &error, exe, 0, NULL, 0);
|
||||||
|
|
||||||
if(result == NULL)
|
if(result == NULL)
|
||||||
|
|||||||
+59
-14
@@ -101,17 +101,16 @@ void Runtime_Free(Runtime *runtime)
|
|||||||
free(runtime);
|
free(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *Runtime_GetBuiltins(Runtime *runtime, Error *error)
|
Object *Runtime_GetBuiltins(Runtime *runtime)
|
||||||
{
|
{
|
||||||
if(runtime->builtins == NULL)
|
|
||||||
{
|
|
||||||
runtime->builtins = Object_NewBuiltinsMap(runtime, Runtime_GetHeap(runtime), error);
|
|
||||||
if(runtime->builtins == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return runtime->builtins;
|
return runtime->builtins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Runtime_SetBuiltins(Runtime *runtime, Object *builtins)
|
||||||
|
{
|
||||||
|
runtime->builtins = 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);
|
||||||
@@ -239,7 +238,56 @@ void Snapshot_Print(Snapshot *snapshot, FILE *fp)
|
|||||||
assert(snapshot != NULL);
|
assert(snapshot != NULL);
|
||||||
assert(fp != NULL);
|
assert(fp != NULL);
|
||||||
|
|
||||||
fprintf(fp, " (Snapshot can't be printed yet)\n");
|
fprintf(fp, "Stack trace:\n");
|
||||||
|
|
||||||
|
for(int i = 0; i < snapshot->depth; i += 1)
|
||||||
|
{
|
||||||
|
SnapshotNode node = snapshot->nodes[i];
|
||||||
|
|
||||||
|
Executable *exe = node.exe;
|
||||||
|
Source *src = Executable_GetSource(exe);
|
||||||
|
|
||||||
|
const char *name;
|
||||||
|
{
|
||||||
|
name = NULL;
|
||||||
|
|
||||||
|
if(src != NULL)
|
||||||
|
name = Source_GetName(src);
|
||||||
|
|
||||||
|
if(name == NULL)
|
||||||
|
name = "(unnamed)";
|
||||||
|
}
|
||||||
|
|
||||||
|
int line;
|
||||||
|
{
|
||||||
|
if(src == NULL)
|
||||||
|
line = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line = 1;
|
||||||
|
|
||||||
|
const char *body = Source_GetBody(src);
|
||||||
|
int offset = Executable_GetInstrOffset(exe, node.index);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while(i < offset)
|
||||||
|
{
|
||||||
|
if(body[i] == '\n')
|
||||||
|
line += 1;
|
||||||
|
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(line == 0)
|
||||||
|
fprintf(fp, "\t#%d %s\n", i, name);
|
||||||
|
else
|
||||||
|
fprintf(fp, "\t#%d %s:%d\n", i, name, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
//fprintf(fp, " (Snapshot can't be printed yet)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -793,13 +841,10 @@ static _Bool step(Runtime *runtime, Error *error)
|
|||||||
{
|
{
|
||||||
// Variable not defined locally.
|
// Variable not defined locally.
|
||||||
|
|
||||||
Object *builtins = Runtime_GetBuiltins(runtime, error);
|
Object *builtins = Runtime_GetBuiltins(runtime);
|
||||||
|
|
||||||
if(builtins == NULL)
|
if(builtins != NULL)
|
||||||
// Failed to create builtins map.
|
obj = Object_Select(builtins, key, runtime->heap, error);
|
||||||
return 0;
|
|
||||||
|
|
||||||
obj = Object_Select(runtime->builtins, key, runtime->heap, error);
|
|
||||||
|
|
||||||
if(obj == NULL)
|
if(obj == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n);
|
|||||||
_Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj);
|
_Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj);
|
||||||
Heap* Runtime_GetHeap(Runtime *runtime);
|
Heap* Runtime_GetHeap(Runtime *runtime);
|
||||||
Stack* Runtime_GetStack(Runtime *runtime);
|
Stack* Runtime_GetStack(Runtime *runtime);
|
||||||
Object* Runtime_GetBuiltins(Runtime *runtime, Error *error);
|
Object* Runtime_GetBuiltins(Runtime *runtime);
|
||||||
|
void Runtime_SetBuiltins(Runtime *runtime, Object *builtins);
|
||||||
int Runtime_GetCurrentIndex(Runtime *runtime);
|
int Runtime_GetCurrentIndex(Runtime *runtime);
|
||||||
Executable *Runtime_GetCurrentExecutable(Runtime *runtime);
|
Executable *Runtime_GetCurrentExecutable(Runtime *runtime);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user