Commit a115c3ab authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

add automated tests

parent 8ffe567c
#ifndef DEBUG_H
#define DEBUG_H
#define DEBUG
//#define DEBUG
#ifndef DEBUG
#define NDEBUG
......
/* This code is public domain -- Will Hartung 4/9/09 */
#include <stdio.h>
#include <stdlib.h>
size_t getline(char **lineptr, size_t *n, FILE *stream) {
char *bufptr = NULL;
char *p = bufptr;
size_t size;
int c;
if (lineptr == NULL) {
return -1;
}
if (stream == NULL) {
return -1;
}
if (n == NULL) {
return -1;
}
bufptr = *lineptr;
size = *n;
c = fgetc(stream);
if (c == EOF) {
return -1;
}
if (bufptr == NULL) {
bufptr = (char*) malloc(128);
if (bufptr == NULL) {
return -1;
}
size = 128;
}
p = bufptr;
while(c != EOF) {
if ((p - bufptr) > (size - 1)) {
size = size + 128;
bufptr = (char*) realloc(bufptr, size);
if (bufptr == NULL) {
return -1;
}
}
*p++ = c;
if (c == '\n') {
break;
}
c = fgetc(stream);
}
*p++ = '\0';
*lineptr = bufptr;
*n = size;
return p - bufptr - 1;
}
\ No newline at end of file
#ifndef GETLINE_H
#define GETLINE_H
size_t getline(char **lineptr, size_t *n, FILE *stream);
#endif /* GETLINE_H */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "getline.h"
#include "debug.h"
#include "desc.h"
#include "prim.h"
......@@ -9,71 +12,53 @@
#include "code.h"
#include "mem.h"
int main() {
int main ( int argc, char *argv[] )
{
init_mem();
init_desc();
init_prim();
// char* funstream = "25 F13 example.Start0 0 LI1 29 F4 main0 0 VF13 example.Start";
// 1
// char* funstream = "20 F9 example.c1 1 VA0 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// 1
// char* funstream = "20 F9 example.c2 1 VA0 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// 1
// char* funstream = "20 F9 example.c2 2 VA1 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// 2
// char* funstream = "20 F9 example.c2 2 VA1 40 F13 example.Start0 0 AF9 example.c1 LI2 29 F4 main0 0 VF13 example.Start";
// example.c 2
// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// example.c 1
// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// example.c 1
// char* funstream = "20 F9 example.c3 7 VA1 44 F13 example.Start0 0 AF9 example.c2 LI1 LI2 29 F4 main0 0 VF13 example.Start";
// example.c 1 2
// char* funstream = "20 F9 example.c3 7 VA1 49 F13 example.Start0 0 AF9 example.c3 LI1 LI33 LI2 29 F4 main0 0 VF13 example.Start";
// 33
// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 34 F13 example.Start0 0 VF9 example.B29 F4 main0 0 VF13 example.Start";
// example.B
// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 40 F13 example.Start0 0 AF9 example.A1 LI5 29 F4 main0 0 VF13 example.Start";
// example.A 5
// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 44 F13 example.Start0 0 AF9 example.A2 LI5 LI6 29 F4 main0 0 VF13 example.Start";
// example.A 5 6
// char* funstream = "40 R10 example._R2 1 9 example.a9 example.b46 F13 example.Start0 0 AF10 example._R2 LI6 LI7 29 F4 main0 0 VF13 example.Start";
// example._R 6 7
// char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 1 VA0 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
// 9
// char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 2 VA1 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
// 8
//char* funstream = "26 F9 example.g2 2 AA1 1 VA0 37 F12 example.f_502 3 AF3 add2 VA1 VA0 63 F13 example.Start0 0 AF9 example.g2 AF12 example.f_501 LI8 LI9 29 F4 main0 0 VF13 example.Start";
// 17
//char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 49 F13 example.Start0 0 AF9 example.f1 VF9 example.B57 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.ALI22 ";
// 11
// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 57 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.ALI22 ";
// 22
// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 56 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.AVL0 ";
// 33
// char* funstream = "33 A2 9 example.A2 0 9 example.B0 0 61 F13 example.Start0 0 AF9 example.f1 AF9 example.A2 LI33 LI44 56 F9 example.f1 1 SVA0 2 C9 example.BLI11 C9 example.AVL1 ";
// 44
// char* funstream = "160 F13 example.Start0 0 AF11 example.map2 VF11 example.incAF17 _predefined._Cons2 LI1 AF17 _predefined._Cons2 LI2 AF17 _predefined._Cons2 LI3 VF16 _predefined._Nil36 F11 example.inc1 1 AF3 add2 VA0 LI1 148 F11 example.map2 1 SVA0 2 C16 _predefined._NilVF16 _predefined._NilC17 _predefined._ConsAF17 _predefined._Cons2 AA1 1 VL0 AF11 example.map2 VA1 VL1 50 A2 17 _predefined._Cons2 0 16 _predefined._Nil0 0 ";
// [_predefined._Cons [2] [_predefined._Cons [3] [_predefined._Cons [4] [_predefined._Nil]]]]
//char* funstream = "44 F13 example.Start0 0 AF11 example.fib1 LI36 119 F11 example.fib1 1 IAF2 lt2 VA0 LI2 LI1 AF3 add2 AF11 example.fib1 AF3 sub2 VA0 LI1 AF11 example.fib1 AF3 sub2 VA0 LI2 ";
// fib
char* input = "..\\tests\\Braun.bsapl";
if ( argc == 2 )
{
input = argv[1];
}
FILE* file = fopen(input, "r");
char* line = NULL;
size_t bufsize = 0;
size_t len = 0;
char* funstream = "29 F9 Braun.int1 1 IVA0 LI1 LI0 27 F9 Braun.and2 2 IVA1 VA0 L099 F9 Braun.all2 1 SVA0 2 C9 Flite.NilL1C10 Flite.ConsAF9 Braun.and2 AA1 1 VL0 AF9 Braun.all2 VA1 VL1 98 F16 Braun._c;39;3_203 4 IAF3 eqB2 VA2 L0L0IAF3 eqB2 VA2 L1AF14 Braun.equal_182 VA1 VA0 VF7 nomatch175 F14 Braun.equal_182 3 SVA1 2 C9 Flite.NilSVA0 2 C9 Flite.NilL1C10 Flite.ConsL0C10 Flite.ConsSVA0 2 C9 Flite.NilL0C10 Flite.ConsAF16 Braun._c;39;3_203 AF3 eqI2 VL0 VL2 VL1 VL3 176 F9 Braun.ilv2 3 SVA1 2 C9 Flite.NilVA0 C10 Flite.ConsSVA0 2 C9 Flite.NilAF10 Flite.Cons2 VL0 VL1 C10 Flite.ConsAF10 Flite.Cons2 VL0 AF10 Flite.Cons2 VL2 AF9 Braun.ilv2 VL1 VL3 153 F12 Braun.toList1 1 SVA0 2 C11 Braun.EmptyVF9 Flite.NilC12 Braun.BranchAF10 Flite.Cons2 VL0 AF9 Braun.ilv2 AF12 Braun.toList1 VL1 AF12 Braun.toList1 VL2 40 A2 11 Braun.Empty0 0 12 Braun.Branch3 0 167 F12 Braun.insert2 1 SVA0 2 C11 Braun.EmptyAF12 Braun.Branch3 VA1 VF11 Braun.EmptyVF11 Braun.EmptyC12 Braun.BranchAF12 Braun.Branch3 VA1 AF12 Braun.insert2 VL0 VL2 VL1 119 F14 Braun.fromList1 1 SVA0 2 C9 Flite.NilVF11 Braun.EmptyC10 Flite.ConsAF12 Braun.insert2 VL0 AF14 Braun.fromList1 VL1 90 F13 Braun.prop_171 1 AF14 Braun.equal_182 VA0 AF12 Braun.toList1 AF14 Braun.fromList1 VA0 118 F15 Braun.replicate2 2 IAF3 eqI2 VA1 LI0 VF9 Flite.NilAF10 Flite.Cons2 VA0 AF15 Braun.replicate2 AF3 sub2 VA1 LI1 VA0 44 F11 Braun.<=_162 3 AF3 not1 AF2 lt2 VA0 VA1 35 A2 9 Flite.Nil0 0 10 Flite.Cons2 0 121 F12 Braun.fromTo2 3 IAF11 Braun.<=_162 VA1 VA0 AF10 Flite.Cons2 VA1 AF12 Braun.fromTo2 AF3 add2 VA1 LI1 VA0 VF9 Flite.Nil125 F11 Braun.Start0 0 AF9 Braun.int1 AF9 Braun.all2 VF13 Braun.prop_17AF15 Braun.replicate2 LI6000 AF12 Braun.fromTo2 LI0 LI255 27 F4 main0 0 VF11 Braun.Start";
//braun
if ( file == 0 )
{
printf( "Could not open file\n" );
}
else
{
len = getline(&line, &bufsize, file);
if(len == -1)
{
printf( "No Input\n" );
}
fclose( file );
if(len == -1) exit(-1);
}
#ifdef DEBUG
printf("sizeof(int): %d, sizeof(long): %d, sizeof(void*): %d, sizeof(Thunk): %d\n\n",
sizeof(int), sizeof(long), sizeof(void*), sizeof(Thunk));
#endif
int nrfuns = parse(&funstream, strlen(funstream));
int nrfuns = parse(&line, len);
#ifdef DEBUG
printf("Number of functions parsed: %d\n", nrfuns);
#endif
// TODO: put it into a special "expression" space, instead of "code"
//char *exprstream = "VF13 example.Start";
char *exprstream = "VF11 Braun.Start";
char *exprstream = "VF4 main";
Code* expr = parseTerm(&exprstream);
......
......@@ -11,6 +11,9 @@ import Data.Map
import Text.Unicode.Encodings.JS
//import Text.Unicode.UChar
import System.CommandLine
import System.File
:: VarType = Arg Int | Local Int | Fun String
:: Context = { vars :: Map String VarType
......@@ -89,10 +92,12 @@ where
(<++) a (LBool False) = a <++ "0"
Start world
# (Ok sapl, world) = readFile "example.sapl" world
# (args, world) = getCommandLine world
| length args < 3
= setReturnCode -1 world
# (Ok sapl, world) = readFile (args!!1) world
# tokens = tokensWithPositions sapl
# (Ok (fs, _)) = parse tokens
= (toString (genDefs fs newAppender), world)
# (_, world) = writeFile (args!!2) (toString (genDefs fs newAppender)) world
= world
\ No newline at end of file
......@@ -23,7 +23,7 @@ Global
Time: False
Stack: False
Output
Output: ShowConstructors
Output: NoReturnType
Font: Courier
FontSize: 9
WriteStdErr: False
......@@ -578,6 +578,20 @@ OtherModules
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.CommandLine
Dir: {Application}\iTasks-SDK\Dependencies\Platform\OS-Independent
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.IO
Dir: {Application}\iTasks-SDK\Dependencies\Platform\OS-Independent
......@@ -795,6 +809,20 @@ OtherModules
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.OS
Dir: {Application}\iTasks-SDK\Dependencies\Platform\OS-Windows-32
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.FastString
Dir: {Application}\iTasks-SDK\Dependencies\SAPL
......
[example.A [1] [2]]
\ No newline at end of file
main = example.Start
example.Start = example.A 1 2
:: example.A = example.A a1 a2 | example.B
[example.B]
\ No newline at end of file
main = example.Start
example.Start = example.B
:: example.A = example.A a1 a2 | example.B
nomatch not found
[1]
\ No newline at end of file
main = Braun.Start
Braun.Start = Braun.int (Braun.all Braun.prop_17 (Braun.replicate 6000 (Braun.fromTo 0 255)))
Braun.fromTo !n_0 !m_1 = if (<{Braun.<=_16}> n_0 m_1) (Flite.Cons n_0 (Braun.fromTo (add n_0 1) m_1)) Flite.Nil
:: Flite.List = Flite.Nil | Flite.Cons a1 a2
<{Braun.<=_16}> !x_0 !y_1 = not (lt y_1 x_0)
Braun.replicate !n_0 x_1 = if (eqI n_0 0) Flite.Nil (Flite.Cons x_1 (Braun.replicate (sub n_0 1) x_1))
Braun.prop_17 !xs_0 = Braun.equal_18 xs_0 (Braun.toList (Braun.fromList xs_0))
Braun.fromList !_x_0 = select _x_0 (Flite.Nil -> Braun.Empty) (Flite.Cons x_1_0 xs_1_1 -> Braun.insert x_1_0 (Braun.fromList xs_1_1))
Braun.insert x_0 !_x_1 = select _x_1 (Braun.Empty -> Braun.Branch x_0 Braun.Empty Braun.Empty) (Braun.Branch y_1_0 t0_1_1 t1_1_2 -> Braun.Branch x_0 (Braun.insert y_1_0 t1_1_2) t0_1_1)
:: Braun.Tree = Braun.Empty | Braun.Branch a1 a2 a3
Braun.toList !_x_0 = select _x_0 (Braun.Empty -> Flite.Nil) (Braun.Branch x_1_0 t0_1_1 t1_1_2 -> Flite.Cons x_1_0 (Braun.ilv (Braun.toList t0_1_1) (Braun.toList t1_1_2)))
Braun.ilv !_x_0 !ys_1 = select _x_0 (Flite.Nil -> ys_1) (Flite.Cons x_1_0 xs_1_1 -> select ys_1 (Flite.Nil -> Flite.Cons x_1_0 xs_1_1) (Flite.Cons y_2_0 ys_2_1 -> Flite.Cons x_1_0 (Flite.Cons y_2_0 (Braun.ilv xs_1_1 ys_2_1))) )
Braun.equal_18 !_x_0 !_x_1 = select _x_0 (Flite.Nil -> select _x_1 (Flite.Nil -> True) (Flite.Cons y_2_0 ys_2_1 -> False) ) (Flite.Cons x_1_0 xs_1_1 -> select _x_1 (Flite.Nil -> False) (Flite.Cons y_2_0 ys_2_1 -> <{Braun._c;39;3_20}> (eqI x_1_0 y_2_0) xs_1_1 ys_2_1) )
<{Braun._c;39;3_20}> !_x_0 xs_1 ys_2 = if (eqB _x_0 False) False (if (eqB _x_0 True) (Braun.equal_18 xs_1 ys_2) nomatch)
Braun.all p_0 !_x_1 = select _x_1 (Flite.Nil -> True) (Flite.Cons x_1_0 xs_1_1 -> Braun.and (p_0 x_1_0) (Braun.all p_0 xs_1_1))
Braun.and !_x_0 y_1 = if _x_0 y_1 False
Braun.int !_x_0 = if _x_0 1 0
[1346269]
\ No newline at end of file
main = example.Start
example.Start = example.fib 30
example.fib !n_0 = if (lt n_0 2) 1 (add (example.fib (sub n_0 1)) (example.fib (sub n_0 2)))
[1]
\ No newline at end of file
main = example.Start
example.Start = example.fst 1 2
example.fst !a_0 b_1 = a_0
[17]
\ No newline at end of file
main = example.Start
example.Start = example.g (example.f_50 8) 9
example.f_50 !a_0 !b_1 = add a_0 b_1
example.g !f_0 b_1 = f_0 b_1
[1]
\ No newline at end of file
main = example.Start
example.Start = example.id 1
example.id !a_0 = a_0
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment