Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 8 commits
  • 15 files changed
  • 0 comments
  • 1 contributor
Dec 12, 2011
Werner Almesberger compiler/ptest/: FNP parser tester
ptest/ allows the FNP parser to run on the host, thus enabling easy
regression testing.
f02bee2
Werner Almesberger compiler/test/: regression test framework and a few test cases 11e24d0
Werner Almesberger patches/: fix various typos (PLEASE REVIEW !)
The strict syntax checking introduced with the following commit will
reject some patches. This is an attempt to correct the syntax errors
in what is hopefully a sensible way.
d897d81
Werner Almesberger parser.y: make syntax errors fatal
While the lemon documentation [1] claims that, in the absence of
explicit error handling, all errors are fatal, this isn't true.
Instead, if the parser could enter a valid state by just ignoring
tokens, it would do so. This made things like  a = b + + c
"valid" expressions.

[1] At the end of http://www.hwaci.com/sw/lemon/lemon.html
e59ff46
Werner Almesberger compiler: allow semicolons at the end of assignments
Semicolons are optional, but if they are used, they must appear at
the end of an assignment. (We may generalize this in the future.)
2d669f9
Werner Almesberger compiler: added //-type comments 2c3f8c4
Werner Almesberger compiler: added /*...*/-type comments 83d3ad0
Werner Almesberger compiler: a bare "." is not a number
Before this patch, we accepted . as a synonym for zero. This is
probably not a good idea, and we may have better uses for it later.
2aa0d1f
2  patches/Idiot & Rovastar - Altars Of Madness 2 (X42 Mix).fnp
@@ -63,5 +63,5 @@ per_frame=fVideoEchoZoom=fVideoEchoZoom-.3*sin(time*(q5*0.01));
63 63
 per_vertex=box=abs(x*2-0.4*sin(q3)) + abs(y*2+0.4*sin(q5));
64 64
 per_vertex=q1 = 4.05+(sin(x+0.237*time)-cos(y+0.513*time));
65 65
 per_vertex=zoom = if(above(box,1),q1*.1,zoom);
66  
-per_vertex=rot = if(above(box,1),sin(0.885*time),0)*(x+y)-rad)*sin(q5)*0.5
  66
+per_vertex=rot = if(above(box,1),sin(0.885*time),0)*(x+y)-rad*sin(q5)*0.5
67 67
 
2  patches/Lekernel & Rozzor & Aderassi - Video Cannon.fnp
@@ -52,7 +52,7 @@ per_frame=dx_r = equal(kick,2)*0.018*sin(6*time) + (1-equal(kick,2))*dx_r;
52 52
 per_frame=dy_r = equal(kick,2)*0.015*sin(7*time) + (1-equal(kick,2))*dy_r;
53 53
 per_frame=dy = dy + 2*dy_r * 0.5*sin(0.8*time);
54 54
 per_frame=dx = dx + 2*dx_r * 0.5*sin(time);
55  
-per_frame=warp = warp + if (below(kick,0), + 0.5*treb, 0);
  55
+per_frame=warp = warp + if (below(kick,0), 0.5*treb, 0);
56 56
 per_frame=q2 = kick;
57 57
 per_frame=decay=below(sin(1.5*time),0.95)*0.15+0.85
58 58
 per_vertex=rot = rot + 0.3*(0.2*sin(1-rad)*5 - 0.2*sin(0.05*rad)*5) * q2;
2  patches/Rovastar & Idiot24-7 - Balk Acid.fnp
@@ -50,7 +50,7 @@ per_frame=rot=rot+0.10*sin(time);
50 50
 per_frame=mv_r=0.5 +0.5*sin(time*1.23);
51 51
 per_frame=mv_b=0.5 + 0.5*sin(time*1.26);
52 52
 per_frame=mv_g=0.5+ 0.5*sin(time*1.19);
53  
-per_frame=wave_g=wave_g*+.20*sin(time*.13);
  53
+per_frame=wave_g=wave_g+.20*sin(time*.13);
54 54
 per_frame=wave_r=wave_r+.13*sin(time);
55 55
 per_frame=wave_b=wave_b*sin(time);
56 56
 per_frame=wave_x=wave_x-.5*sin(time*.13);
2  patches/Rozzor & Aderrasi - Canon (DMX out).fnp
@@ -62,7 +62,7 @@ per_frame=dx_r = equal(kick,2)*0.018*sin(6*time) + (1-equal(kick,2))*dx_r;
62 62
 per_frame=dy_r = equal(kick,2)*0.015*sin(7*time) + (1-equal(kick,2))*dy_r;
63 63
 per_frame=dy = dy + 2*dy_r * 0.5*sin(0.8*time);
64 64
 per_frame=dx = dx + 2*dx_r * 0.5*sin(time);
65  
-per_frame=warp = warp + if (below(kick,0), + 0.5*treb, 0);
  65
+per_frame=warp = warp + if (below(kick,0), 0.5*treb, 0);
66 66
 per_frame=q2 = kick;
67 67
 per_vertex=rot = rot + 0.3*(0.2*sin(1-rad)*5 - 0.2*sin(0.05*rad)*5) * q2;
68 68
 per_vertex=cx = if(above(dy,-.5),1-rot * 2,rot*q2);
23  src/compiler/Makefile
... ...
@@ -0,0 +1,23 @@
  1
+.PHONY:		all clean
  2
+.PHONY:		test tests valgrind
  3
+
  4
+all:
  5
+		$(MAKE) -C ptest
  6
+
  7
+# ----- Tests -----------------------------------------------------------------
  8
+
  9
+test tests:     all
  10
+		LANG= sh -c \
  11
+		    'passed=0 && cd test && \
  12
+		    for n in [a-z]*; do \
  13
+		    [ $$n != core ] && SCRIPT=$$n . ./$$n; done; \
  14
+		    echo "Passed all $$passed tests"'
  15
+
  16
+valgrind:
  17
+		VALGRIND="valgrind -q" $(MAKE) tests
  18
+
  19
+# ----- Cleanup ---------------------------------------------------------------
  20
+
  21
+clean:
  22
+		$(MAKE) -C ptest clean
  23
+		rm -f test/core
7  src/compiler/parser.y
@@ -85,6 +85,7 @@
85 85
 
86 86
 %type node {struct ast_node *}
87 87
 %destructor node { free($$); }
  88
+%syntax_error { yy_parse_failed(yypParser); }
88 89
 
89 90
 start ::= TOK_START_EXPR node(N). {
90 91
 	state->comm->parseout = N;
@@ -99,11 +100,15 @@ assignments ::= assignments assignment.
99 100
 
100 101
 assignments ::= .
101 102
 
102  
-assignment ::= ident(I) TOK_ASSIGN node(N). {
  103
+assignment ::= ident(I) TOK_ASSIGN node(N) opt_semi. {
103 104
 	fpvm_do_assign(state->comm->fragment, I->label, N);
104 105
 	fpvm_parse_free(N);
105 106
 }
106 107
 
  108
+opt_semi ::= opt_semi TOK_SEMI.
  109
+
  110
+opt_semi ::= .
  111
+
107 112
 node(N) ::= TOK_CONSTANT(C). {
108 113
 	N = node(TOK_CONSTANT, "", NULL, NULL, NULL);
109 114
 	N->contents.constant = C->constant;
63  src/compiler/ptest/Makefile
... ...
@@ -0,0 +1,63 @@
  1
+RTEMS_VERSION ?= 4.11
  2
+RTEMS_MAKEFILE_PATH ?= \
  3
+    /opt/rtems-$(RTEMS_VERSION)/lm32-rtems$(RTEMS_VERSION)/milkymist/
  4
+RTEMS_FPVM_H = $(RTEMS_MAKEFILE_PATH)/lib/include/fpvm
  5
+
  6
+CFLAGS = -Wall -g -I.. -I.
  7
+OBJS = ptest.o scanner.o parser.o parser_helper.o unique.o
  8
+
  9
+# ----- Verbosity control -----------------------------------------------------
  10
+
  11
+CC_normal	:= $(CC)
  12
+
  13
+CC_quiet	= @echo "  CC       " $@ && $(CC_normal)
  14
+GEN_quiet       = @echo "  GENERATE " $@ &&
  15
+
  16
+ifeq ($(V),1)
  17
+    CC		= $(CC_normal)
  18
+    GEN		=
  19
+else
  20
+    CC		= $(CC_quiet)
  21
+    GEN		= $(GEN_quiet)
  22
+endif
  23
+
  24
+# ----- Rules -----------------------------------------------------------------
  25
+
  26
+.PHONY:		all clean
  27
+
  28
+all:		fpvm ptest
  29
+
  30
+fpvm:
  31
+		$(GEN) ln -s $(RTEMS_FPVM_H) fpvm
  32
+
  33
+ptest:		$(OBJS)
  34
+		$(CC) $(CFLAGS) -o $@ $^
  35
+
  36
+%.o:		../%.c
  37
+		$(CC) $(CFLAGS) -c -o $@ $<
  38
+
  39
+%.c:		%.re
  40
+		$(GEN) re2c -o $@ $<
  41
+
  42
+%.c:		%.y
  43
+		$(GEN) lemon $<
  44
+
  45
+%.h %.inc:	%.ids
  46
+		$(GEN) cd .. && ./idgen `basename $<`
  47
+
  48
+# ----- Dependencies ----------------------------------------------------------
  49
+
  50
+../parser.h:	../parser.c
  51
+scanner.o:	../parser.h
  52
+parser_helper.o: ../parser.h
  53
+ptest.o:	../parser.h
  54
+unique.o:	../fnp.inc
  55
+
  56
+# ----- Cleanup ---------------------------------------------------------------
  57
+
  58
+clean:
  59
+		rm -f $(OBJS)
  60
+		rm -f ../scanner.c
  61
+		rm -f ../parser.c ../parser.h ../parser.out
  62
+		rm -f ../fnp.h ../fnp.inc
  63
+		rm -f fpvm
211  src/compiler/ptest/ptest.c
... ...
@@ -0,0 +1,211 @@
  1
+/*
  2
+ * ptest.c - FNP parser tester
  3
+ *
  4
+ * Copyright 2011 by Werner Almesberger
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ */
  10
+
  11
+
  12
+#include <stdlib.h>
  13
+#include <stdio.h>
  14
+#include <unistd.h>
  15
+
  16
+#include "../fpvm.h"
  17
+#include "../parser_helper.h"
  18
+#include "../parser.h"
  19
+
  20
+
  21
+static int quiet = 0;
  22
+
  23
+
  24
+static void dump_ast(const struct ast_node *ast);
  25
+
  26
+
  27
+static void branch(const struct ast_node *ast)
  28
+{
  29
+	if (ast) {
  30
+		putchar(' ');
  31
+		dump_ast(ast);
  32
+	}
  33
+}
  34
+
  35
+
  36
+static void op(const char *s, const struct ast_node *ast)
  37
+{
  38
+	printf("(%s", s);
  39
+	branch(ast->contents.branches.a);
  40
+	branch(ast->contents.branches.b);
  41
+	branch(ast->contents.branches.c);
  42
+	putchar(')');
  43
+}
  44
+
  45
+
  46
+static void dump_ast(const struct ast_node *ast)
  47
+{
  48
+	switch (ast->op) {
  49
+        case op_ident:
  50
+		printf("%s", ast->label);
  51
+		break;
  52
+	case op_constant:
  53
+		printf("%g", ast->contents.constant);
  54
+		break;
  55
+        case op_plus:
  56
+		op("+", ast);
  57
+		break;
  58
+        case op_minus:
  59
+		op("-", ast);
  60
+		break;
  61
+        case op_multiply:
  62
+		op("*", ast);
  63
+		break;
  64
+        case op_divide:
  65
+		op("/", ast);
  66
+		break;
  67
+        case op_percent:
  68
+		op("%", ast);
  69
+		break;
  70
+	case op_abs:
  71
+		op("abs", ast);
  72
+		break;
  73
+        case op_isin:
  74
+		op("isin", ast);
  75
+		break;
  76
+        case op_icos:
  77
+		op("icos", ast);
  78
+		break;
  79
+        case op_sin:
  80
+		op("sin", ast);
  81
+		break;
  82
+        case op_cos:
  83
+		op("cos", ast);
  84
+		break;
  85
+        case op_above:
  86
+		op("above", ast);
  87
+		break;
  88
+        case op_below:
  89
+		op("below", ast);
  90
+		break;
  91
+        case op_equal:
  92
+		op("equal", ast);
  93
+		break;
  94
+        case op_i2f:
  95
+		op("i2f", ast);
  96
+		break;
  97
+        case op_f2i:
  98
+		op("f2i", ast);
  99
+		break;
  100
+        case op_if:
  101
+		op("if", ast);
  102
+		break;
  103
+        case op_tsign:
  104
+		op("tsign", ast);
  105
+		break;
  106
+        case op_quake:
  107
+		op("quake", ast);
  108
+		break;
  109
+	case op_not:
  110
+		op("!", ast);
  111
+		break;
  112
+	case op_sqr:
  113
+		op("sqr", ast);
  114
+		break;
  115
+	case op_sqrt:
  116
+		op("sqrt", ast);
  117
+		break;
  118
+	case op_invsqrt:
  119
+		op("invsqrt", ast);
  120
+		break;
  121
+	case op_min:
  122
+		op("min", ast);
  123
+		break;
  124
+        case op_max:
  125
+		op("max", ast);
  126
+		break;
  127
+        case op_int:
  128
+		op("int", ast);
  129
+		break;
  130
+	default:
  131
+		abort();
  132
+	}
  133
+}
  134
+
  135
+
  136
+int fpvm_do_assign(struct fpvm_fragment *fragment, const char *dest,
  137
+    struct ast_node *ast)
  138
+{
  139
+	if (!quiet) {
  140
+		printf("%s = ", dest);
  141
+		dump_ast(ast);
  142
+		putchar('\n');
  143
+	}
  144
+	return 1;
  145
+}
  146
+
  147
+
  148
+static const char *read_stdin(void)
  149
+{
  150
+	char *buf = NULL;
  151
+	int len = 0, size = 0;
  152
+	ssize_t got;
  153
+
  154
+	do {
  155
+		if (len == size) {
  156
+			size += size ? size : 1024;
  157
+			buf = realloc(buf, size+1);
  158
+			if (!buf) {
  159
+				perror("realloc");
  160
+				exit(1);
  161
+			}
  162
+		}
  163
+		got = read(0, buf+len, size-len);
  164
+		if (got < 0) {
  165
+			perror("read");
  166
+			exit(1);
  167
+		}
  168
+		len += got;
  169
+	}
  170
+	while (got);
  171
+
  172
+	buf[len] = 0;
  173
+
  174
+	return buf;
  175
+}
  176
+
  177
+
  178
+static void usage(const char *name)
  179
+{
  180
+	fprintf(stderr, "usage: %s [-q] [expr]\n", name);
  181
+	exit(1);
  182
+}
  183
+
  184
+
  185
+int main(int argc, char **argv)
  186
+{
  187
+	int c;
  188
+	const char *buf;
  189
+	union parser_comm comm;
  190
+
  191
+	while ((c = getopt(argc, argv, "q")) != EOF)
  192
+		switch (c) {
  193
+		case 'q':
  194
+			quiet = 1;
  195
+			break;
  196
+		default:
  197
+			usage(*argv);
  198
+		}
  199
+	switch (argc-optind) {
  200
+	case 0:
  201
+		buf = read_stdin();
  202
+		break;
  203
+	case 1:
  204
+		buf = argv[optind];
  205
+		break;
  206
+	default:
  207
+		usage(*argv);
  208
+	}
  209
+
  210
+	return !fpvm_parse(buf, TOK_START_ASSIGN, &comm);
  211
+}
9  src/compiler/scanner.re
@@ -58,8 +58,14 @@ int scan(struct scanner *s)
58 58
 	
59 59
 	/*!re2c
60 60
 		[\x20\n\r\t]		{ goto std; }
  61
+
  62
+		"//"[^\n\x00]*		{ goto std; }
  63
+		"/*"("*"*[^/\x00]|[^*\x00])*"*"+"/"
  64
+					{ goto std; }
  65
+
61 66
 		[0-9]+			{ return TOK_CONSTANT; }
62  
-		[0-9]* "." [0-9]*	{ return TOK_CONSTANT; }
  67
+		[0-9]+ "." [0-9]*	{ return TOK_CONSTANT; }
  68
+		[0-9]* "." [0-9]+	{ return TOK_CONSTANT; }
63 69
 
64 70
 		"above"			{ return TOK_ABOVE; }
65 71
 		"abs"			{ return TOK_ABS; }
@@ -91,6 +97,7 @@ int scan(struct scanner *s)
91 97
 		")"			{ return TOK_RPAREN; }
92 98
 		","			{ return TOK_COMMA; }
93 99
 		"="			{ return TOK_ASSIGN; }
  100
+		";"			{ return TOK_SEMI; }
94 101
 		[\x00-\xff]		{ return TOK_ERROR; }
95 102
 	*/
96 103
 }
52  src/compiler/test/Common
... ...
@@ -0,0 +1,52 @@
  1
+#!/bin/sh
  2
+#
  3
+# Common - Elements shared by all regression tests for the FNP parser
  4
+#
  5
+# Written 2010, 2011 by Werner Almesberger
  6
+# Copyright 2010, 2011 Werner Almesberger
  7
+#
  8
+# This program is free software; you can redistribute it and/or modify
  9
+# it under the terms of the GNU General Public License as published by
  10
+# the Free Software Foundation; either version 2 of the License, or
  11
+# (at your option) any later version.
  12
+#
  13
+
  14
+
  15
+ptest()
  16
+{
  17
+    echo -n "$1: " 1>&2
  18
+    shift
  19
+    $VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 || {
  20
+	echo FAILED "($SCRIPT)" 1>&2
  21
+	cat _out
  22
+	rm -f _out
  23
+	exit 1
  24
+    }
  25
+}
  26
+
  27
+
  28
+ptest_fail()
  29
+{
  30
+    echo -n "$1: " 1>&2
  31
+    shift
  32
+    $VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 && {
  33
+	echo FAILED "($SCRIPT)" 1>&2
  34
+	cat _out
  35
+	rm -f _out
  36
+	exit 1
  37
+    }
  38
+}
  39
+
  40
+
  41
+expect()
  42
+{
  43
+    diff -u - "$@" _out >_diff || {
  44
+	echo FAILED "($SCRIPT)" 1>&2
  45
+	cat _diff 1>&2
  46
+	rm -f _out _diff
  47
+	exit 1
  48
+    }
  49
+    echo PASSED 1>&2
  50
+    rm -f _out _diff
  51
+    passed=`expr ${passed:-0} + 1`
  52
+}
49  src/compiler/test/arith
... ...
@@ -0,0 +1,49 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "arithmetic: x = a+b" <<EOF
  7
+x = a+b
  8
+EOF
  9
+expect <<EOF
  10
+x = (+ a b)
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest "arithmetic: x = a-b" <<EOF
  16
+x = a-b
  17
+EOF
  18
+expect <<EOF
  19
+x = (- a b)
  20
+EOF
  21
+
  22
+#------------------------------------------------------------------------------
  23
+
  24
+ptest "arithmetic: x = a*b" <<EOF
  25
+x = a*b
  26
+EOF
  27
+expect <<EOF
  28
+x = (* a b)
  29
+EOF
  30
+
  31
+#------------------------------------------------------------------------------
  32
+
  33
+ptest "arithmetic: x = a/b" <<EOF
  34
+x = a/b
  35
+EOF
  36
+expect <<EOF
  37
+x = (/ a b)
  38
+EOF
  39
+
  40
+#------------------------------------------------------------------------------
  41
+
  42
+ptest "arithmetic: x = a%b" <<EOF
  43
+x = a/b
  44
+EOF
  45
+expect <<EOF
  46
+x = (/ a b)
  47
+EOF
  48
+
  49
+###############################################################################
136  src/compiler/test/comment
... ...
@@ -0,0 +1,136 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "comment: line with just // " <<EOF
  7
+// this is a comment
  8
+a = b + c
  9
+EOF
  10
+expect <<EOF
  11
+a = (+ b c)
  12
+EOF
  13
+
  14
+#------------------------------------------------------------------------------
  15
+
  16
+ptest "comment: line ending with // comment" <<EOF
  17
+a = b + c // comment
  18
+d = e + f
  19
+EOF
  20
+expect <<EOF
  21
+a = (+ b c)
  22
+d = (+ e f)
  23
+EOF
  24
+
  25
+#------------------------------------------------------------------------------
  26
+
  27
+ptest "comment: // after //" <<EOF
  28
+a = b + c // comment // more
  29
+d = e + f
  30
+EOF
  31
+expect <<EOF
  32
+a = (+ b c)
  33
+d = (+ e f)
  34
+EOF
  35
+
  36
+#------------------------------------------------------------------------------
  37
+
  38
+ptest "comment: // ending with EOF" "a = b// end"
  39
+expect <<EOF
  40
+a = b
  41
+EOF
  42
+
  43
+#------------------------------------------------------------------------------
  44
+
  45
+ptest "comment: /* ... */" <<EOF
  46
+a = b + c /* comment */
  47
+d = e + f
  48
+EOF
  49
+expect <<EOF
  50
+a = (+ b c)
  51
+d = (+ e f)
  52
+EOF
  53
+
  54
+#------------------------------------------------------------------------------
  55
+
  56
+ptest "comment: /* ... newline ... */" <<EOF
  57
+a = b + c /* comment
  58
+more */ d = e + f
  59
+EOF
  60
+expect <<EOF
  61
+a = (+ b c)
  62
+d = (+ e f)
  63
+EOF
  64
+
  65
+#------------------------------------------------------------------------------
  66
+
  67
+ptest "comment: /* ... * ... */" <<EOF
  68
+a = 1 /* comment * more */
  69
+b = 2
  70
+EOF
  71
+expect <<EOF
  72
+a = 1
  73
+b = 2
  74
+EOF
  75
+
  76
+#------------------------------------------------------------------------------
  77
+
  78
+ptest "comment: /* ... ** ... */" <<EOF
  79
+a = 3 /* comment ** more */
  80
+b = 4
  81
+EOF
  82
+expect <<EOF
  83
+a = 3
  84
+b = 4
  85
+EOF
  86
+
  87
+#------------------------------------------------------------------------------
  88
+
  89
+ptest "comment: /* ... **/" <<EOF
  90
+a = 5 /* comment **/
  91
+b = 6
  92
+EOF
  93
+expect <<EOF
  94
+a = 5
  95
+b = 6
  96
+EOF
  97
+
  98
+#------------------------------------------------------------------------------
  99
+
  100
+ptest "comment: /**/" <<EOF
  101
+a = 7 /**/
  102
+b = 8
  103
+EOF
  104
+expect <<EOF
  105
+a = 7
  106
+b = 8
  107
+EOF
  108
+
  109
+#------------------------------------------------------------------------------
  110
+
  111
+ptest_fail "comment: /*/ (error)" <<EOF
  112
+a = 9 /*/
  113
+b = a
  114
+EOF
  115
+expect <<EOF
  116
+FPVM: parse error
  117
+EOF
  118
+
  119
+#------------------------------------------------------------------------------
  120
+
  121
+ptest_fail "comment: unterminated /* ... with newline" <<EOF
  122
+a = b + c /* comment
  123
+d = e + f
  124
+EOF
  125
+expect <<EOF
  126
+FPVM: parse error
  127
+EOF
  128
+
  129
+#------------------------------------------------------------------------------
  130
+
  131
+ptest_fail "comment: unterminated /* ... without newline" "a = b+c /* comment"
  132
+expect <<EOF
  133
+FPVM: parse error
  134
+EOF
  135
+
  136
+###############################################################################
32  src/compiler/test/error
... ...
@@ -0,0 +1,32 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest_fail "syntax error: x = backtick" <<EOF
  7
+x = \`
  8
+EOF
  9
+expect <<EOF
  10
+FPVM: scan error
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest_fail "syntax error: x = a b" <<EOF
  16
+x = a b
  17
+EOF
  18
+expect <<EOF
  19
+x = a
  20
+FPVM: parse error
  21
+EOF
  22
+
  23
+#------------------------------------------------------------------------------
  24
+
  25
+ptest_fail "syntax error: x = a + + b" <<EOF
  26
+x = a + + b
  27
+EOF
  28
+expect <<EOF
  29
+FPVM: parse error
  30
+EOF
  31
+
  32
+###############################################################################
59  src/compiler/test/number
... ...
@@ -0,0 +1,59 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "number: a = 1" <<EOF
  7
+a = 1
  8
+EOF
  9
+expect <<EOF
  10
+a = 1
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest "number: b = 1.2" <<EOF
  16
+b = 1.2
  17
+EOF
  18
+expect <<EOF
  19
+b = 1.2
  20
+EOF
  21
+
  22
+#------------------------------------------------------------------------------
  23
+#------------------------------------------------------------------------------
  24
+
  25
+ptest "number: c = .3" <<EOF
  26
+c = .3
  27
+EOF
  28
+expect <<EOF
  29
+c = 0.3
  30
+EOF
  31
+
  32
+#------------------------------------------------------------------------------
  33
+
  34
+ptest "number: d = 4." <<EOF
  35
+d = 4.
  36
+EOF
  37
+expect <<EOF
  38
+d = 4
  39
+EOF
  40
+
  41
+#------------------------------------------------------------------------------
  42
+
  43
+ptest "number: e = 51.23" <<EOF
  44
+e = 51.23
  45
+EOF
  46
+expect <<EOF
  47
+e = 51.23
  48
+EOF
  49
+
  50
+#------------------------------------------------------------------------------
  51
+
  52
+ptest_fail "number: f = ." <<EOF
  53
+f = .
  54
+EOF
  55
+expect <<EOF
  56
+FPVM: scan error
  57
+EOF
  58
+
  59
+###############################################################################
91  src/compiler/test/wrap
... ...
@@ -0,0 +1,91 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "wrap: baseline" <<EOF
  7
+a = b + c
  8
+EOF
  9
+expect <<EOF
  10
+a = (+ b c)
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest "wrap: with newline" <<EOF
  16
+a = b +
  17
+c
  18
+EOF
  19
+expect <<EOF
  20
+a = (+ b c)
  21
+EOF
  22
+
  23
+#------------------------------------------------------------------------------
  24
+
  25
+ptest "wrap: two assignments on two lines" <<EOF
  26
+a = b + c
  27
+d = e + f
  28
+EOF
  29
+expect <<EOF
  30
+a = (+ b c)
  31
+d = (+ e f)
  32
+EOF
  33
+
  34
+#------------------------------------------------------------------------------
  35
+
  36
+ptest "wrap: two assignments on one line" <<EOF
  37
+a = b + c  d = e + f
  38
+EOF
  39
+expect <<EOF
  40
+a = (+ b c)
  41
+d = (+ e f)
  42
+EOF
  43
+
  44
+#------------------------------------------------------------------------------
  45
+
  46
+ptest "wrap: one assignment ending with semicolon" <<EOF
  47
+a = b + c;
  48
+EOF
  49
+expect <<EOF
  50
+a = (+ b c)
  51
+EOF
  52
+
  53
+#------------------------------------------------------------------------------
  54
+
  55
+ptest "wrap: one assignment ending with multiple semicolons" <<EOF
  56
+a = b + c;;;;;;;;;;;
  57
+EOF
  58
+expect <<EOF
  59
+a = (+ b c)
  60
+EOF
  61
+
  62
+#------------------------------------------------------------------------------
  63
+
  64
+ptest "wrap: two assignments separated by semicolon" <<EOF
  65
+a = b + c; d = e + f
  66
+EOF
  67
+expect <<EOF
  68
+a = (+ b c)
  69
+d = (+ e f)
  70
+EOF
  71
+
  72
+#------------------------------------------------------------------------------
  73
+
  74
+ptest_fail "wrap: one assignment containing semicolon (1)" <<EOF
  75
+a = b +; c
  76
+EOF
  77
+expect <<EOF
  78
+FPVM: parse error
  79
+EOF
  80
+
  81
+#------------------------------------------------------------------------------
  82
+
  83
+ptest_fail "wrap: one assignment containing semicolon (2)" <<EOF
  84
+a = b; + c
  85
+EOF
  86
+expect <<EOF
  87
+a = b
  88
+FPVM: parse error
  89
+EOF
  90
+
  91
+###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.