~lbnz/xr0

a733c5aa68e349edf3f80a8a3f488f79e5835690 — Claude Betz 3 months ago 9ea4869
change .alloc -> .malloc, .dealloc -> .free
38 files changed, 120 insertions(+), 120 deletions(-)

M editors/vim/syntax.vim
M libx/stdlib.h
M src/0v/ast/lex.l
M tests/0-basic/030-alloc.x
M tests/0-basic/041-FAIL-false-alloc-void.x
M tests/0-basic/050-two-variables.x
M tests/0-basic/060-FAIL-two-allocs.x
M tests/0-basic/160-one-free-one-alloc.x
M tests/0-basic/180-FAIL-alloc-freed.x
M tests/0-basic/200-free-param.x
M tests/1-branches/0100-body-trivial.x
M tests/1-branches/0200-conditional-allocation.x
M tests/1-branches/0300-conditional-allocation-body.x
M tests/1-branches/0310-FAIL-conditional-allocation-body.x
M tests/1-branches/0320-FAIL-conditional-allocation-body.x
M tests/1-branches/0400-strcmp-conditional-allocation.x
M tests/1-branches/0500-strcmp-conditional-allocation-body.x
M tests/1-branches/0600-indirect.x
M tests/1-branches/0700-indirect.x
M tests/1-branches/0800-indirect.x
M tests/1-branches/0900-subsequent.x
M tests/1-branches/1000-chaining-functions.x
M tests/3-topological/001-valid-sort-matrix.x
M tests/3-topological/002-valid-sort-parse.x
M tests/4-linking/000-internal-prototype-abstract.x
M tests/4-linking/010-internal-two-matching-abstracts.x
M tests/4-linking/020-FAIL-internal-mismatch-abstracts.x
M tests/4-linking/030-FAIL-internal-missing-definition.x
M tests/4-linking/040-FAIL-multiple-definitions.x
M tests/4-linking/050-multiple-prototype.x
M tests/6-preconditions/100-FAIL-need-alloced-lval.x
M tests/6-preconditions/101-FAIL-need-alloced-rval.x
M tests/7-use-after-free/000-read-and-write.x
M tests/7-use-after-free/001-read-and-write-arbitrary.x
M tests/7-use-after-free/120-FAIL-freed-ptr-maybe-dangling-return.x
M tests/7-use-after-free/300-FAIL-struct-free-ptr-dangling.x
M tests/99-program/000-matrix.x
M tests/99-program/100-lex/parse.x
M editors/vim/syntax.vim => editors/vim/syntax.vim +1 -1
@@ 12,7 12,7 @@ syntax keyword	Keyword	        const exit
syntax keyword	Type	        unsigned int char double void bool size_t FILE
syntax keyword	Structure	struct enum union
syntax keyword	Conditional	if else for some while switch assume pre
syntax keyword	Include	        axiom alloc dealloc realloc clump
syntax keyword	Include	        axiom malloc free realloc clump
syntax keyword	Label		case default
syntax keyword	Boolean		true false
syntax keyword	Exception	return result undefined

M libx/stdlib.h => libx/stdlib.h +2 -2
@@ 4,10 4,10 @@
#include <stddef.h>

axiom void *
malloc(int size) ~ [ return .alloc(size); ];
malloc(int size) ~ [ return .malloc(size); ];

axiom void
free(void *ptr) ~ [ .dealloc(ptr); ];
free(void *ptr) ~ [ .free(ptr); ];

axiom void
exit(int status);

M src/0v/ast/lex.l => src/0v/ast/lex.l +2 -2
@@ 30,8 30,8 @@ check_type();
%%
"#"			{ preproc(); }
"/*"			{ comment(); }
".alloc"		{ count(); return(TK_ALLOC); }
".dealloc"		{ count(); return(TK_DEALLOC); }
".malloc"		{ count(); return(TK_ALLOC); }
".free"			{ count(); return(TK_DEALLOC); }
".clump"		{ count(); return(TK_CLUMP); }

"auto"			{ count(); return(AUTO); }

M tests/0-basic/030-alloc.x => tests/0-basic/030-alloc.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
unit() ~ [ return .alloc(1); ]
unit() ~ [ return .malloc(1); ]
{
	void *p;


M tests/0-basic/041-FAIL-false-alloc-void.x => tests/0-basic/041-FAIL-false-alloc-void.x +1 -1
@@ 1,6 1,6 @@
#include <stdlib.h>

void *
unit() ~ [ return .alloc(1); ]
unit() ~ [ return .malloc(1); ]
{
}

M tests/0-basic/050-two-variables.x => tests/0-basic/050-two-variables.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
unit() ~ [ return .alloc(1); ]
unit() ~ [ return .malloc(1); ]
{
	void *p; void *q;


M tests/0-basic/060-FAIL-two-allocs.x => tests/0-basic/060-FAIL-two-allocs.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
leak() ~ [ return .alloc(1); ]
leak() ~ [ return .malloc(1); ]
{
	void *p; void *q;


M tests/0-basic/160-one-free-one-alloc.x => tests/0-basic/160-one-free-one-alloc.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
unit() ~ [ return .alloc(1); ]
unit() ~ [ return .malloc(1); ]
{
	void *p; void *q;


M tests/0-basic/180-FAIL-alloc-freed.x => tests/0-basic/180-FAIL-alloc-freed.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
unit() ~ [ return .alloc(1); ]
unit() ~ [ return .malloc(1); ]
{
	void *p;


M tests/0-basic/200-free-param.x => tests/0-basic/200-free-param.x +2 -2
@@ 2,9 2,9 @@

void
unit(void *p) ~ [
	pre: p = .alloc(1);
	pre: p = .malloc(1);

	.dealloc(p);
	.free(p);
]{
	free(p);
}

M tests/1-branches/0100-body-trivial.x => tests/1-branches/0100-body-trivial.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
test(int x) ~ [ return .alloc(1); ]
test(int x) ~ [ return .malloc(1); ]
{
	if (x) {
		return malloc(1);

M tests/1-branches/0200-conditional-allocation.x => tests/1-branches/0200-conditional-allocation.x +2 -2
@@ 3,10 3,10 @@
void *
test(int x) ~ [
	if (x) {
		return .alloc(1);
		return .malloc(1);
	}
	if (!x) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	return malloc(1);

M tests/1-branches/0300-conditional-allocation-body.x => tests/1-branches/0300-conditional-allocation-body.x +1 -1
@@ 3,7 3,7 @@
void *
test(int x) ~ [
	if (x) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	if (x) {

M tests/1-branches/0310-FAIL-conditional-allocation-body.x => tests/1-branches/0310-FAIL-conditional-allocation-body.x +1 -1
@@ 3,7 3,7 @@
void *
test(int x) ~ [
	if (x) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	return NULL;

M tests/1-branches/0320-FAIL-conditional-allocation-body.x => tests/1-branches/0320-FAIL-conditional-allocation-body.x +1 -1
@@ 3,7 3,7 @@
void *
test(int x) ~ [
	if (x) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	return malloc(1);

M tests/1-branches/0400-strcmp-conditional-allocation.x => tests/1-branches/0400-strcmp-conditional-allocation.x +2 -2
@@ 4,10 4,10 @@
void *
test(char *s) ~ [
	if (strcmp(s, "yes") == 0) {
		return .alloc(1);
		return .malloc(1);
	}
	if (!(strcmp(s, "yes") == 0)) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	return malloc(1);

M tests/1-branches/0500-strcmp-conditional-allocation-body.x => tests/1-branches/0500-strcmp-conditional-allocation-body.x +1 -1
@@ 4,7 4,7 @@
void *
test(char *s) ~ [
	if (strcmp(s, "yes") == 0) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	if (strcmp(s, "yes") == 0) {

M tests/1-branches/0600-indirect.x => tests/1-branches/0600-indirect.x +2 -2
@@ 3,7 3,7 @@
void *
alloc_if(int num) ~ [
	if (num) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	if (num) {


@@ 15,7 15,7 @@ alloc_if(int num) ~ [
void *
test(int x) ~ [
	if (x) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	void *p;

M tests/1-branches/0700-indirect.x => tests/1-branches/0700-indirect.x +2 -2
@@ 6,14 6,14 @@ number();
void *
alloc_if(int num) ~ [
	if (num) {
		return .alloc(1);
		return .malloc(1);
	}
];

void *
test() ~ [
	if (number()) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	int num;

M tests/1-branches/0800-indirect.x => tests/1-branches/0800-indirect.x +2 -2
@@ 6,14 6,14 @@ number(int param);
void *
alloc_if(int num) ~ [
	if (num) {
		return .alloc(1);
		return .malloc(1);
	}
];

void *
test(int x) ~ [
	if (number(x)) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	int n;

M tests/1-branches/0900-subsequent.x => tests/1-branches/0900-subsequent.x +2 -2
@@ 9,14 9,14 @@ g(int param);
void *
alloc_if(int num) ~ [
	if (num) {
		return .alloc(1);
		return .malloc(1);
	}
];

void *
test(int x) ~ [
	if (f(g(x))) {
		return .alloc(1);
		return .malloc(1);
	}
]{
	int m;

M tests/1-branches/1000-chaining-functions.x => tests/1-branches/1000-chaining-functions.x +2 -2
@@ 11,10 11,10 @@ tuple_create() ~ [
];

void *
conditional_alloc(int x) ~ [ if (x) { return .alloc(1); } ];
conditional_alloc(int x) ~ [ if (x) { return .malloc(1); } ];

void *
test() ~ [ if (tuple_create().x) { return .alloc(1); } ]
test() ~ [ if (tuple_create().x) { return .malloc(1); } ]
{
	struct tuple t;


M tests/3-topological/001-valid-sort-matrix.x => tests/3-topological/001-valid-sort-matrix.x +11 -11
@@ 11,12 11,12 @@ matrix_create(int rows, int cols) ~ [
	int i;
	struct matrix *m;

	m = .alloc(sizeof(struct matrix));
	m = .malloc(sizeof(struct matrix));
	m->rows = rows;
	m->cols = cols;
	m->data = .alloc(sizeof(int *) * rows);
	m->data = .malloc(sizeof(int *) * rows);
	for (i = 0; i < m->rows; i++) {
		m->data[i] = .alloc(1);	
		m->data[i] = .malloc(1);	
	}
	return m;
];


@@ 33,7 33,7 @@ matrix_create(int rows, int cols)
	m->cols = cols;

	m->data = malloc(sizeof(int *) * rows);
	for (i = 0; i < m->rows; i++) ~ [ m->data[i] = .alloc(1); ] {
	for (i = 0; i < m->rows; i++) ~ [ m->data[i] = .malloc(1); ] {
		m->data[i] = malloc(sizeof(int) * cols);
	}



@@ 47,14 47,14 @@ matrix_destroy(struct matrix *m) ~ [
	pre: m = matrix_create($, $);

	for (i = 0; i < m->rows; i++) {
		.dealloc(m->data[i]);
		.free(m->data[i]);
	}
	.dealloc(m->data);
	.dealloc(m);
	.free(m->data);
	.free(m);
]{
	int i;

	for (i = 0; i < m->rows; i++) ~ [ .dealloc(m->data[i]); ] {
	for (i = 0; i < m->rows; i++) ~ [ .free(m->data[i]); ] {
		free(m->data[i]);
	}
	free(m->data);


@@ 71,12 71,12 @@ matrix_add(struct matrix *m1, struct matrix *m2) ~ [
		m2 = matrix_create($, $);
	}

	sum = .alloc(sizeof(struct matrix));
	sum = .malloc(sizeof(struct matrix));
	sum->rows = m1->rows;
	sum->cols = m1->cols;
	sum->data = .alloc(sizeof(int *) * rows);
	sum->data = .malloc(sizeof(int *) * rows);
	for (i = 0; i < sum->rows; i++) {
		sum->data[i] = .alloc(1);	
		sum->data[i] = .malloc(1);	
	}
	return sum;
]{

M tests/3-topological/002-valid-sort-parse.x => tests/3-topological/002-valid-sort-parse.x +25 -25
@@ 7,7 7,7 @@
#define true 1

char *
read_file(char *path) ~ [ return .alloc(1); ];
read_file(char *path) ~ [ return .malloc(1); ];

struct lexer;



@@ 31,9 31,9 @@ lexer_destroy(struct lexer *l) ~ [
			$, malloc(1)
		);
	}
	.dealloc(l->pattern);
	.dealloc(l->token);
	.dealloc(l);
	.free(l->pattern);
	.free(l->token);
	.free(l);
];

void


@@ 41,8 41,8 @@ lexer_print(struct lexer *l) ~ [
	pre: {
		l = lexer_create(
			.clump(1), .clump(1),
			$, .alloc(1),
			$, .alloc(1)
			$, .malloc(1),
			$, .malloc(1)
		);
	}
];


@@ 109,7 109,7 @@ struct lexer *
lexer_create(char *pre, char *post, int npat, struct pattern *pattern,
		int ntok, struct token *token) ~ [
	struct lexer *l;
	l = .alloc(sizeof(struct lexer)); 
	l = .malloc(sizeof(struct lexer)); 
	l->pre = pre;
	l->post = post;
	l->pattern = pattern;


@@ 185,10 185,10 @@ struct defsresult
parse_defs(char *input) ~ [
	struct defsresult res;
	if (beginsdefs(skipws(input))) {
		res.pre = .alloc(1);
		res.pre = .malloc(1);
	}
	if (count_patterns(input)) {
		res.pattern = .alloc(1);
		res.pattern = .malloc(1);
	}
	return res;
];


@@ 210,14 210,14 @@ parse_rules(char *pos) ~ [
	struct rulesresult res;
	res.token = $; /* TODO: put in else block */
	if (count_tokens(pos)) {
		res.token = .alloc(sizeof(struct token));
		res.token = .malloc(sizeof(struct token));
	}
	res.pos = $;
	return res;
];

char *
parse_toeof(char *input) ~ [ return .alloc(1); ];
parse_toeof(char *input) ~ [ return .malloc(1); ];

struct lexer *
parse(char *pos)


@@ 246,7 246,7 @@ parse(char *pos)
}

char *
substr(char *s, int n) ~ [ return .alloc(1); ]
substr(char *s, int n) ~ [ return .malloc(1); ]
{
	int len;
	char *ss;


@@ 273,7 273,7 @@ skiplinespace(char *s)
}

char *
parse_id(char *input) ~ [ return .alloc(1); ];
parse_id(char *input) ~ [ return .malloc(1); ];

char *
skipoptions(char *pos)


@@ 312,7 312,7 @@ parse_id(char *input)
}

char *
parse_tonewline(char *input) ~ [ return .alloc(1); ]
parse_tonewline(char *input) ~ [ return .malloc(1); ]
{
	char *s;
	s = input; /* must be here because not seen with skip loop hack */


@@ 333,7 333,7 @@ parse_defsraw(char *input) ~ [

	res.s = $;
	if (beginsdefs(input)) {
		res.s = .alloc(1);
		res.s = .malloc(1);
	}
	res.pos = $;
	return res;


@@ 350,7 350,7 @@ parse_defsproper(char *input) ~ [
	struct patternet res;
	res.pattern = $; /* TODO: put in else block */
	if (count_patterns(input)) {
		res.pattern = .alloc(1);
		res.pattern = .malloc(1);
	}
	res.npat = $;
	res.pos = $;


@@ 405,7 405,7 @@ parse_defsraw(char *input)
struct pattern *
pattern_create(char *name, char *pattern) ~ [
	struct pattern p;
	p = .alloc(sizeof(struct pattern));
	p = .malloc(sizeof(struct pattern));
	p->name = name;
	p->pattern = pattern;
	return p;


@@ 444,7 444,7 @@ parse_defs_n(char *pos, int npat) ~ [
	struct patternpos res;
	res.p = $; /* TODO: put in else block */
	if (npat) {
		res.p = .alloc(1);
		res.p = .malloc(1);
	}
	res.pos = $;
	return res;


@@ 527,7 527,7 @@ parse_defs_n(char *pos, int npat)
struct token *
token_create(int isliteral, char *name, char *action) ~ [
	struct token *tk;
	tk = .alloc(sizeof(struct token));
	tk = .malloc(sizeof(struct token));
	tk->isliteral = isliteral;
	tk->name = name;
	tk->action = action;


@@ 565,7 565,7 @@ parse_rules_n(char *pos, int ntok) ~ [
	struct tokenpos tpos;
	tpos.t = $; /* TODO: put in else block */
	if (ntok) {
		tpos.t = .alloc(1);
		tpos.t = .malloc(1);
	}
	tpos.pos = $;
	return tpos;


@@ 645,7 645,7 @@ struct tknameresult {
struct tknameresult
parse_name(char *pos) ~ [
	struct tknameresult res;
	res.name = .alloc(1);
	res.name = .malloc(1);
	res.isliteral = $;
	res.pos = $;
	return res;


@@ 654,7 654,7 @@ parse_name(char *pos) ~ [
struct stringresult
parse_action(char *input) ~ [
	struct stringresult res;
	res.s = .alloc(1);
	res.s = .malloc(1);
	res.pos = $;
	return res;
];


@@ 677,21 677,21 @@ parse_token(char *pos)
struct tknameresult
parse_token_id(char *pos) ~ [
	struct tknameresult res;
	res.name = .alloc(1);
	res.name = .malloc(1);
	return res;
];

struct tknameresult
parse_token_literal(char *input) ~ [
	struct tknameresult res;
	res.name = .alloc(1);
	res.name = .malloc(1);
	return res;
];

struct tknameresult
parse_token_pattern(char *pos) ~ [
	struct tknameresult res;
	res.name = .alloc(1);
	res.name = .malloc(1);
	return res;
];


M tests/4-linking/000-internal-prototype-abstract.x => tests/4-linking/000-internal-prototype-abstract.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
allocating() ~ [ return .alloc(1); ];
allocating() ~ [ return .malloc(1); ];

int
main()

M tests/4-linking/010-internal-two-matching-abstracts.x => tests/4-linking/010-internal-two-matching-abstracts.x +2 -2
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
allocating() ~ [ return .alloc(1); ];
allocating() ~ [ return .malloc(1); ];

int
main()


@@ 13,7 13,7 @@ main()
}

void *
allocating() ~ [ return .alloc(1); ]
allocating() ~ [ return .malloc(1); ]
{
	void *p;


M tests/4-linking/020-FAIL-internal-mismatch-abstracts.x => tests/4-linking/020-FAIL-internal-mismatch-abstracts.x +2 -2
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
allocating() ~ [ .dealloc(result); ];
allocating() ~ [ .free(result); ];

int
main()


@@ 13,7 13,7 @@ main()
}

void *
allocating() ~ [ return .alloc(1); ]
allocating() ~ [ return .malloc(1); ]
{
	void *p;


M tests/4-linking/030-FAIL-internal-missing-definition.x => tests/4-linking/030-FAIL-internal-missing-definition.x +1 -1
@@ 1,4 1,4 @@
#include <stdlib.h>

static void *
allocating() ~ [ return .alloc(1); ];
allocating() ~ [ return .malloc(1); ];

M tests/4-linking/040-FAIL-multiple-definitions.x => tests/4-linking/040-FAIL-multiple-definitions.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
allocating() ~ [ return .alloc(1); ];
allocating() ~ [ return .malloc(1); ];

void *
allocating() { }

M tests/4-linking/050-multiple-prototype.x => tests/4-linking/050-multiple-prototype.x +1 -1
@@ 1,7 1,7 @@
#include <stdlib.h>

void *
allocating() ~ [ return .alloc(1); ];
allocating() ~ [ return .malloc(1); ];

void *
nonallocating();

M tests/6-preconditions/100-FAIL-need-alloced-lval.x => tests/6-preconditions/100-FAIL-need-alloced-lval.x +1 -1
@@ 2,7 2,7 @@

int
func(int *x) ~ [ 
	pre: x = .alloc(1);
	pre: x = .malloc(1);
	*x = 5;
]{
	*x = 5;	

M tests/6-preconditions/101-FAIL-need-alloced-rval.x => tests/6-preconditions/101-FAIL-need-alloced-rval.x +1 -1
@@ 4,7 4,7 @@ int
func(int *x) ~ [ 
	int i;
	pre: {
		x = .alloc(1);
		x = .malloc(1);
		*x = $;
	}
	return *x;

M tests/7-use-after-free/000-read-and-write.x => tests/7-use-after-free/000-read-and-write.x +1 -1
@@ 3,7 3,7 @@
int *
read_and_write_definite() ~ [
	int *p;
	p = .alloc(sizeof(int));
	p = .malloc(sizeof(int));
	*p = 1;
	return p;
] {

M tests/7-use-after-free/001-read-and-write-arbitrary.x => tests/7-use-after-free/001-read-and-write-arbitrary.x +1 -1
@@ 3,7 3,7 @@
int *
read_and_write_arbitrary() ~ [
	int *p;
	p = .alloc(sizeof(int));
	p = .malloc(sizeof(int));
	*p = 1;
	return p;
] {

M tests/7-use-after-free/120-FAIL-freed-ptr-maybe-dangling-return.x => tests/7-use-after-free/120-FAIL-freed-ptr-maybe-dangling-return.x +2 -2
@@ 3,9 3,9 @@
int *
func(int x) ~ [
	int *p;
	p = .alloc(sizeof(int));
	p = .malloc(sizeof(int));
	if (x) {
		.dealloc(p);	
		.free(p);	
	}
	return p;
] {

M tests/7-use-after-free/300-FAIL-struct-free-ptr-dangling.x => tests/7-use-after-free/300-FAIL-struct-free-ptr-dangling.x +2 -2
@@ 15,9 15,9 @@ struct score *
create_score(char *subject, int grade) ~ [
	struct score *s;

	pre: subject = .alloc(sizeof(char *) * 100);
	pre: subject = .malloc(sizeof(char *) * 100);

	s = .alloc(sizeof(struct score));
	s = .malloc(sizeof(struct score));
	s->subject = subject;
	s->grade = grade;
	return s;

M tests/99-program/000-matrix.x => tests/99-program/000-matrix.x +11 -11
@@ 11,12 11,12 @@ matrix_create(int rows, int cold) ~ [
	struct matrix *m;
	int i;

	m = .alloc(sizeof(struct matrix));
	m->data = .alloc(sizeof(int *) * rows);
	m = .malloc(sizeof(struct matrix));
	m->data = .malloc(sizeof(int *) * rows);
	m->rows = rows;
	m->cols = cols;
	for (i = 0; i < m->rows; i++) {
		m->data[i] = .alloc(sizeof(int));	
		m->data[i] = .malloc(sizeof(int));	
	}
	return m;
];


@@ 33,7 33,7 @@ matrix_create(int rows, int cols)
	m->cols = cols;

	m->data = malloc(sizeof(int *) * rows);
	for (i = 0; i < rows; i++) ~ [ m->data[i] = .alloc(sizeof(int *) * cols); ] {
	for (i = 0; i < rows; i++) ~ [ m->data[i] = .malloc(sizeof(int *) * cols); ] {
		m->data[i] = malloc(sizeof(int *) * cols);
	}
	return m;


@@ 46,14 46,14 @@ matrix_destroy(struct matrix *m) ~ [
	pre: m = matrix_create($, $);

	for (i = 0; i < m->rows; i++) {
		.dealloc(m->data[i]);
		.free(m->data[i]);
	}
	.dealloc(m->data);
	.dealloc(m);
	.free(m->data);
	.free(m);
]{
	int i;

	for (i = 0; i < m->rows; i++) ~ [ .dealloc(m->data[i]); ] {
	for (i = 0; i < m->rows; i++) ~ [ .free(m->data[i]); ] {
		free(m->data[i]);
	}
	free(m->data);


@@ 70,12 70,12 @@ matrix_add(struct matrix *m1, struct matrix *m2) ~ [
		m2 = matrix_create($, $);
	}

	sum = .alloc(sizeof(struct matrix *));
	sum->data = .alloc(sizeof(int *) * m1->rows);
	sum = .malloc(sizeof(struct matrix *));
	sum->data = .malloc(sizeof(int *) * m1->rows);
	sum->rows = m1->rows;
	sum->cols = m1->cols;
	for (i = 0; i < sum->rows; i++) {
		sum->data[i] = .alloc(sizeof(int));
		sum->data[i] = .malloc(sizeof(int));
	}
	return sum;
]{

M tests/99-program/100-lex/parse.x => tests/99-program/100-lex/parse.x +25 -25
@@ 8,7 8,7 @@
#define true 1

char *
read_file(char *path) ~ [ .alloc result; ];
read_file(char *path) ~ [ .malloc result; ];

struct lexer {
	char *pre; char *post;


@@ 19,7 19,7 @@ struct lexer {
struct lexer *
lexer_create(char *pre, char *post, int npat, struct pattern *pattern,
		int ntok, struct token *token) ~ [
	.alloc result; 
	.malloc result; 
	result->pre = pre;
	result->post = post;
	result->pattern = pattern;


@@ 40,7 40,7 @@ struct stringresult {

struct stringresult
parse_defsraw(char *input) ~ [
	.alloc result.s;
	.malloc result.s;
	result.pos = $;
];



@@ 70,11 70,11 @@ lexer_destroy(struct lexer *l) ~ [
		);
	}

	.dealloc l->pre;
	.dealloc l->post;
	.dealloc l->pattern;
	.dealloc l->token;
	.dealloc l;
	.free l->pre;
	.free l->post;
	.free l->pattern;
	.free l->token;
	.free l;
];

void


@@ 219,8 219,8 @@ count_patterns(char *pos);

struct defsresult
parse_defs(char *pos) ~ [
	.alloc result.pre;
	.alloc result.pattern;
	.malloc result.pre;
	.malloc result.pattern;
	result.pos = $;
	result.npat = $;
];


@@ 242,13 242,13 @@ count_tokens(char *pos);

struct rulesresult
parse_rules(char *pos) ~ [
	.alloc result.token;
	.malloc result.token;
	result.pos = $;
	result.ntok = $;
];

char *
parse_toeof(char *input) ~ [ .alloc result; ];
parse_toeof(char *input) ~ [ .malloc result; ];

struct lexer *
parse(char *pos)


@@ 278,7 278,7 @@ isboundary(char *s)
}

char *
substr(char *s, int n) ~ [ .alloc result; ]
substr(char *s, int n) ~ [ .malloc result; ]
{
	int len;
	char *ss;


@@ 305,7 305,7 @@ skiplinespace(char *s)
}

char *
parse_id(char *input) ~ [ .alloc result; ];
parse_id(char *input) ~ [ .malloc result; ];

char *
skipoptions(char *pos)


@@ 345,7 345,7 @@ parse_id(char *input)
}

char *
parse_tonewline(char *input) ~ [ .alloc result; ]
parse_tonewline(char *input) ~ [ .malloc result; ]
{
	char *s;
	s = input; /* must be here because not seen with skip loop hack */


@@ 363,7 363,7 @@ struct patternet {

struct patternet
parse_defsproper(char *input) ~ [
	.alloc result.pattern;
	.malloc result.pattern;
	result.npat = $;
	result.pos = $;
];


@@ 414,7 414,7 @@ parse_defsraw(char *input)

struct pattern *
pattern_create(char *name, char *pattern) ~ [
	.alloc result;
	.malloc result;
	result->name = name;
	result->pattern = pattern;
]{


@@ 449,7 449,7 @@ struct patternpos {

struct patternpos
parse_defs_n(char *pos, int npat) ~ [
	.alloc result.p;
	.malloc result.p;
	result.pos = $;
];



@@ 534,7 534,7 @@ parse_defs_n(char *pos, int npat)

struct token *
token_create(int isliteral, char *name, char *action) ~ [
	.alloc result;
	.malloc result;
	result->isliteral = isliteral;
	result->name = name;
	result->action = action;


@@ 565,7 565,7 @@ struct tokenpos {

struct tokenpos
parse_rules_n(char *pos, int ntok) ~ [
	.alloc result.t;
	.malloc result.t;
	result.pos = $;
];



@@ 645,14 645,14 @@ struct tknameresult {

struct tknameresult
parse_name(char *pos) ~ [
	.alloc result.name;
	.malloc result.name;
	result.isliteral = $;
	result.pos = $;
];

struct stringresult
parse_action(char *input) ~ [
	.alloc result.s;
	.malloc result.s;
	result.pos = $;
];



@@ 672,13 672,13 @@ parse_token(char *pos)
}

struct tknameresult
parse_token_id(char *pos) ~ [ .alloc result.name; ];
parse_token_id(char *pos) ~ [ .malloc result.name; ];

struct tknameresult
parse_token_literal(char *input) ~ [ .alloc result.name; ];
parse_token_literal(char *input) ~ [ .malloc result.name; ];

struct tknameresult
parse_token_pattern(char *pos) ~ [ .alloc result.name; ];
parse_token_pattern(char *pos) ~ [ .malloc result.name; ];

struct tknameresult
parse_name(char *pos)