Merge branch 'master' of 10.24.0.1:Projects/hammer. Also, licenses for everything!

Conflicts:
	src/hammer.c
This commit is contained in:
Meredith L. Patterson 2012-05-12 22:26:59 +01:00
commit 0164ddc98d
9 changed files with 153 additions and 30 deletions

View file

@ -1,3 +1,20 @@
/* Arena allocator for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <glib.h> #include <glib.h>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>

View file

@ -1,3 +1,20 @@
/* Arena allocator for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef HAMMER_ALLOCATOR__H__ #ifndef HAMMER_ALLOCATOR__H__
#define HAMMER_ALLOCATOR__H__ #define HAMMER_ALLOCATOR__H__
#include <sys/types.h> #include <sys/types.h>

View file

@ -1,3 +1,20 @@
/* Bit-parsing operations for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "internal.h" #include "internal.h"

View file

@ -72,6 +72,7 @@ parse_result_t* do_parse(const parser_t* parser, parse_state_t *state) {
parse_result_t* make_result(parse_state_t *state, parsed_token_t *tok) { parse_result_t* make_result(parse_state_t *state, parsed_token_t *tok) {
parse_result_t *ret = a_new(parse_result_t, 1); parse_result_t *ret = a_new(parse_result_t, 1);
ret->ast = tok; ret->ast = tok;
ret->arena = state->arena;
return ret; return ret;
} }
@ -80,6 +81,23 @@ typedef struct {
uint8_t len; uint8_t len;
} token_t; } token_t;
static parse_result_t* parse_unimplemented(void* env, parse_state_t *state) {
(void) env;
(void) state;
static parsed_token_t token = {
.token_type = TT_ERR
};
static parse_result_t result = {
.ast = &token
};
return &result;
}
static parser_t unimplemented = {
.fn = parse_unimplemented,
.env = NULL
};
static parse_result_t* parse_token(void *env, parse_state_t *state) { static parse_result_t* parse_token(void *env, parse_state_t *state) {
token_t *t = (token_t*)env; token_t *t = (token_t*)env;
for (int i=0; i<t->len; ++i) { for (int i=0; i<t->len; ++i) {
@ -144,7 +162,7 @@ const parser_t* whitespace(const parser_t* p) {
return ret; return ret;
} }
const parser_t* action(const parser_t* p, const action_t a) { return NULL; } const parser_t* action(const parser_t* p, const action_t a) { return &unimplemented; }
static parse_result_t* parse_charset(void *env, parse_state_t *state) { static parse_result_t* parse_charset(void *env, parse_state_t *state) {
uint8_t in = read_bits(&state->input_stream, 8, false); uint8_t in = read_bits(&state->input_stream, 8, false);
@ -440,35 +458,16 @@ const parser_t* xor(const parser_t* p1, const parser_t* p2) {
return ret; return ret;
} }
const parser_t* repeat0(const parser_t* p) { return NULL; } const parser_t* repeat0(const parser_t* p) { return &unimplemented; }
const parser_t* repeat1(const parser_t* p) { return NULL; } const parser_t* repeat1(const parser_t* p) { return &unimplemented; }
const parser_t* repeat_n(const parser_t* p, const size_t n) { return NULL; } const parser_t* repeat_n(const parser_t* p, const size_t n) { return &unimplemented; }
const parser_t* optional(const parser_t* p) { return &unimplemented; }
static parse_result_t* parse_optional(void *env, parse_state_t *state) { const parser_t* ignore(const parser_t* p) { return &unimplemented; }
return NULL; const parser_t* list(const parser_t* p, const parser_t* sep) { return &unimplemented; }
} const parser_t* epsilon_p() { return &unimplemented; }
const parser_t* attr_bool(const parser_t* p, attr_bool_t a) { return &unimplemented; }
const parser_t* optional(const parser_t* p) { const parser_t* and(const parser_t* p) { return &unimplemented; }
parser_t *ret = g_new(parser_t, 1); const parser_t* not(const parser_t* p) { return &unimplemented; }
ret->fn = parse_optional; ret->env = NULL;
return ret;
}
static parse_result_t* parse_ignore(void *env, parse_state_t *state) {
return NULL;
}
const parser_t* ignore(const parser_t* p) {
parser_t *ret = g_new(parser_t, 1);
ret->fn = parse_ignore; ret->env = NULL;
return ret;
}
const parser_t* list(const parser_t* p, const parser_t* sep) { return NULL; }
const parser_t* epsilon_p() { return NULL; }
const parser_t* attr_bool(const parser_t* p, attr_bool_t a) { return NULL; }
const parser_t* and(const parser_t* p) { return NULL; }
const parser_t* not(const parser_t* p) { return NULL; }
static guint cache_key_hash(gconstpointer key) { static guint cache_key_hash(gconstpointer key) {
return djbhash(key, sizeof(parser_cache_key_t)); return djbhash(key, sizeof(parser_cache_key_t));

View file

@ -57,6 +57,7 @@ typedef enum token_type {
TT_SINT, TT_SINT,
TT_UINT, TT_UINT,
TT_SEQUENCE, TT_SEQUENCE,
TT_ERR,
TT_MAX TT_MAX
} token_type_t; } token_type_t;
@ -80,6 +81,7 @@ typedef struct parsed_token {
*/ */
typedef struct parse_result { typedef struct parse_result {
const parsed_token_t *ast; const parsed_token_t *ast;
arena_t arena;
} parse_result_t; } parse_result_t;
/* Type of an action to apply to an AST, used in the action() parser. */ /* Type of an action to apply to an AST, used in the action() parser. */

View file

@ -1,3 +1,20 @@
/* Internals for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef HAMMER_INTERNAL__H #ifndef HAMMER_INTERNAL__H
#define HAMMER_INTERNAL__H #define HAMMER_INTERNAL__H
#include <glib.h> #include <glib.h>

View file

@ -1,3 +1,20 @@
/* Pretty-printer for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <glib.h> #include <glib.h>
@ -102,6 +119,9 @@ static void unamb_sub(const parsed_token_t* tok, struct result_buf *buf) {
len = asprintf(&tmpbuf, "s%#lx", tok->uint); len = asprintf(&tmpbuf, "s%#lx", tok->uint);
append_buf(buf, tmpbuf, len); append_buf(buf, tmpbuf, len);
break; break;
case TT_ERR:
append_buf(buf, "ERR", 3);
break;
case TT_SEQUENCE: { case TT_SEQUENCE: {
GSequenceIter *it; GSequenceIter *it;
int at_begin = 1; int at_begin = 1;

View file

@ -1,3 +1,20 @@
/* Test suite for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "hammer.h" #include "hammer.h"
#include "test_suite.h" #include "test_suite.h"

View file

@ -1,3 +1,20 @@
/* Test suite for Hammer.
* Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef HAMMER_TEST_SUITE__H #ifndef HAMMER_TEST_SUITE__H
#define HAMMER_TEST_SUITE__H #define HAMMER_TEST_SUITE__H