More autotest
This commit is contained in:
parent
bb4680845e
commit
87ccd5e221
|
@ -84,6 +84,12 @@ if %errorlevel% neq 0 goto :error
|
|||
..\release\oscar64 -i=../include -rt=../include/crt.c -e -n floatstringtest.c
|
||||
if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -i=../include -rt=../include/crt.c -e qsorttest.c
|
||||
if %errorlevel% neq 0 goto :error
|
||||
|
||||
..\release\oscar64 -i=../include -rt=../include/crt.c -e -n qsorttest.c
|
||||
if %errorlevel% neq 0 goto :error
|
||||
|
||||
exit /b 0
|
||||
:error
|
||||
echo Failed with error #%errorlevel%.
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct Node
|
||||
{
|
||||
int a;
|
||||
char s[10];
|
||||
};
|
||||
|
||||
void qsort(Node * n, int s)
|
||||
{
|
||||
if (s > 1)
|
||||
{
|
||||
Node pn = n[0];
|
||||
int pi = 0;
|
||||
for(int i=1; i<s; i++)
|
||||
{
|
||||
if (strcmp(n[i].s, pn.s) < 0)
|
||||
{
|
||||
n[pi] = n[i];
|
||||
pi++;
|
||||
n[i] = n[pi]
|
||||
}
|
||||
}
|
||||
n[pi] = pn;
|
||||
|
||||
qsort(n, pi);
|
||||
qsort(n + pi + 1, s - pi - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void shuffle(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
int t = rand() % s;
|
||||
Node nt = n[i]; n[i] = n[t]; n[t] = nt;
|
||||
}
|
||||
}
|
||||
|
||||
void init(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
n[i].a = i;
|
||||
sprintf(n[i].s, "%.5d", i);
|
||||
}
|
||||
}
|
||||
|
||||
static const int size = 1000;
|
||||
|
||||
Node field[size];
|
||||
|
||||
void show(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
printf("%3d : %3d, %s\n", i, n[i].a, n[i].s);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void check(Node * n, int s)
|
||||
{
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
assert(n[i].a == i);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init(field, size);
|
||||
// show(field, size);
|
||||
shuffle(field, size);
|
||||
// show(field, size);
|
||||
qsort(field, size);
|
||||
// show(field, size);
|
||||
check(field, size);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -269,7 +269,7 @@ void nformf(const sinfo * si, char * str, float f, char type)
|
|||
}
|
||||
}
|
||||
|
||||
void sformat(void * data, putstrfn fn, const char * fmt, int * fps)
|
||||
void * sformat(void * data, putstrfn fn, const char * fmt, int * fps)
|
||||
{
|
||||
const char * p = fmt;
|
||||
char c, buff[21];
|
||||
|
@ -381,6 +381,8 @@ void sformat(void * data, putstrfn fn, const char * fmt, int * fps)
|
|||
data = fn(data, buff);
|
||||
bi = 0;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void printf(const char * fmt, ...)
|
||||
|
|
|
@ -1852,6 +1852,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
// no need for actual operation when casting pointer to pointer
|
||||
return ExValue(exp->mLeft->mDecType, vr.mTemp, vr.mReference);
|
||||
}
|
||||
else if (exp->mLeft->mDecType->mType != DT_TYPE_VOID && vr.mType->mType == DT_TYPE_VOID)
|
||||
{
|
||||
mErrors->Error(exp->mLocation, "Cannot cast void object to non void object");
|
||||
return ExValue(exp->mLeft->mDecType, vr.mTemp, vr.mReference);
|
||||
}
|
||||
else
|
||||
{
|
||||
vr = Dereference(proc, block, vr);
|
||||
|
|
|
@ -604,8 +604,8 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
}
|
||||
else
|
||||
{
|
||||
mErrors->Error(mScanner->mLocation, "Struct/Array constant expression expected");
|
||||
dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
|
||||
exp = ParseRExpression();
|
||||
return exp;
|
||||
}
|
||||
|
||||
exp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||
|
|
Loading…
Reference in New Issue