Commit 160557ab authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

always load some builtin functions

parent 31b4810d
App1 f a1 = f a1
App2 f a1 a2 = f a1 a2
App3 f a1 a2 a3 = f a1 a2 a3
App4 f a1 a2 a3 a4 = f a1 a2 a3 a4
App5 f a1 a2 a3 a4 a5 = f a1 a2 a3 a4 a5
\ No newline at end of file
......@@ -337,10 +337,20 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
Thunk** bt = &peek_a();
(*bt)->desc->eval();
Desc* baseDesc = (*bt)->desc->type == FT_SLICE ?
((SliceEntry*) (*bt)->desc)->forward_ptr : (*bt)->desc;
int newArity = (*bt)->desc->arity + expr->nr_args;
if(newArity > baseDesc->arity)
{
}
Desc* slice =
get_slice((*bt)->desc->type == FT_SLICE ?
((SliceEntry*) (*bt)->desc)->forward_ptr : (*bt)->desc, (*bt)->desc->arity + expr->nr_args);
get_slice(baseDesc, newArity);
switch(slice->type) {
case FT_PRIM1:
case FT_PRIM2:
......@@ -662,7 +672,6 @@ void eval_fun()
}
exec(((FunEntry*) thunk->desc)->body, frame_ptr, frame_ptr);
//stack_a[frame_ptr] = stack_a[stack_top_a];
}
void eval_prim()
......
......@@ -11,7 +11,8 @@
#include "code.h"
#include "mem.h"
long readfile(char **string, FILE *f) {
long readfile(char **string, FILE *f)
{
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
......@@ -23,31 +24,18 @@ long readfile(char **string, FILE *f) {
return fsize;
}
int main ( int argc, char *argv[] )
{
init_mem();
init_desc();
init_prim();
char* input = "..\\tests\\queens2.bsapl";
if ( argc == 2 )
{
input = argv[1];
}
int loadFile(char* input, char** content)
{
FILE* file = fopen(input, "r");
char* line = NULL;
long len = 0;
if ( file == 0 )
{
printf( "Could not open file\n" );
exit(-1);
return -1;
}
else
{
len = readfile(&line, file);
len = readfile(content, file);
if(len < 0)
{
......@@ -55,14 +43,51 @@ int main ( int argc, char *argv[] )
}
fclose( file );
if(len < 0) exit(-1);
if(len < 0) return -1;
}
return len;
}
int main ( int argc, char *argv[] )
{
init_mem();
init_desc();
init_prim();
#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
char* line = NULL;
long len = 0;
char* input = "c:\\Users\\Laszlo\\Documents\\personal\\projects\\sapl-interpreter\\interpreter\\builtin.bsapl";
len = loadFile(input, &line);
if(len <= 0)
{
printf( "Could not load builtin.bsapl\n" );
exit(-1);
}
parse(&line, len);
input = "..\\tests\\Cichelli.bsapl";
if ( argc == 2 )
{
input = argv[1];
}
len = loadFile(input, &line);
if(len <= 0)
{
printf( "Could not open file\n" );
exit(-1);
}
int nrfuns = parse(&line, len);
#ifdef DEBUG
......
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