Merge branch 'master' of jackywulf.com:Fcalva/flisp
This commit is contained in:
commit
e05a3e9ff5
5 changed files with 17 additions and 13 deletions
4
Makefile
4
Makefile
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
OUTNAME = flisp
|
OUTNAME = flisp
|
||||||
|
|
||||||
CFLAGS = -std=c99 -O0 -Wall -Wextra -g -pipe -Wno-cast-function-type
|
CFLAGS = -std=c99 -O0 -flto -Wall -Wextra -g -pipe -Wno-cast-function-type
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ builddir:
|
||||||
@- mv $(wildcard $(BUILD_DIR)/*.o) build-tmp/
|
@- mv $(wildcard $(BUILD_DIR)/*.o) build-tmp/
|
||||||
|
|
||||||
yacc: src/parser.y src/parser.l
|
yacc: src/parser.y src/parser.l
|
||||||
cd src && yacc -d -g parser.y && lex parser.l
|
cd src && bison -y -d parser.y && lex parser.l
|
||||||
$(CC) -c src/y.tab.c -o build-tmp/y.tab.o $(CFLAGS)
|
$(CC) -c src/y.tab.c -o build-tmp/y.tab.o $(CFLAGS)
|
||||||
$(CC) -c src/lex.yy.c -o build-tmp/lex.yy.o $(CFLAGS)
|
$(CC) -c src/lex.yy.c -o build-tmp/lex.yy.o $(CFLAGS)
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ Pre-requisites:
|
||||||
- GNU Make
|
- GNU Make
|
||||||
|
|
||||||
### Unix
|
### Unix
|
||||||
Running `make` twice should work on most Unix systems.
|
Running `make` (or `gmake` for BSDs) should work on most Unix systems.
|
||||||
It produces an executable called `flisp.amd64`
|
It produces an executable called `flisp.amd64`
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
To meet the previously mentionned pre-requisites, you need to use mingw.
|
To meet the previously mentionned pre-requisites, you need to use mingw.
|
||||||
I recommend installing w64devkit, then compiling Bison and Flex from source.
|
I recommend installing w64devkit, then compiling Bison and Flex from source.
|
||||||
Run `make win`, twice.
|
Run `make win`
|
||||||
|
|
|
@ -183,7 +183,7 @@ void *get_addr(u32 pos){
|
||||||
return internal_buf + pos;
|
return internal_buf + pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value write(Value a);
|
Value fl_write(Value a);
|
||||||
|
|
||||||
void print_ast1(Statement *base, i32 indent){
|
void print_ast1(Statement *base, i32 indent){
|
||||||
i32 close_parent = 1;
|
i32 close_parent = 1;
|
||||||
|
@ -198,7 +198,7 @@ void print_ast1(Statement *base, i32 indent){
|
||||||
printf("(call<%lx>\n", (u64)base->func);
|
printf("(call<%lx>\n", (u64)base->func);
|
||||||
break;
|
break;
|
||||||
case ST_Const:
|
case ST_Const:
|
||||||
write(base->cons);
|
fl_write(base->cons);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
close_parent = 0;
|
close_parent = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -612,7 +612,8 @@ Value pop(Value a, Value b){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value write(Value a){
|
Value fl_write(Value a){
|
||||||
|
char *nstr;
|
||||||
switch(a.tag.type){
|
switch(a.tag.type){
|
||||||
case T_null:
|
case T_null:
|
||||||
case T_any:
|
case T_any:
|
||||||
|
@ -628,7 +629,6 @@ Value write(Value a){
|
||||||
printf("%f",a.v4B.vfl);
|
printf("%f",a.v4B.vfl);
|
||||||
break;
|
break;
|
||||||
case T_str:
|
case T_str:
|
||||||
char *nstr;
|
|
||||||
nstr = malloc(a.vstr.len+1);
|
nstr = malloc(a.vstr.len+1);
|
||||||
if(a.vstr.len > 4){
|
if(a.vstr.len > 4){
|
||||||
char *str = get_addr(a.vstr.pos);
|
char *str = get_addr(a.vstr.pos);
|
||||||
|
@ -682,7 +682,7 @@ FnSig builtins[] = {
|
||||||
{{tvec} ,1,1,{.bi = BICAST(len)}},
|
{{tvec} ,1,1,{.bi = BICAST(len)}},
|
||||||
{{tvec,tany},2,1,{.bi = BICAST(push)}},
|
{{tvec,tany},2,1,{.bi = BICAST(push)}},
|
||||||
{{tvec,tint},2,1,{.bi = BICAST(pop)}},
|
{{tvec,tint},2,1,{.bi = BICAST(pop)}},
|
||||||
{{tany} ,1,1,{.bi = BICAST(write)}},
|
{{tany} ,1,1,{.bi = BICAST(fl_write)}},
|
||||||
{{0} ,0,1,{.bi = BICAST(nwline)}}
|
{{0} ,0,1,{.bi = BICAST(nwline)}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,16 @@ Value fncall(FnSig *fn, Statement **params){
|
||||||
case 0:
|
case 0:
|
||||||
returnv = fn->bi();
|
returnv = fn->bi();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:{
|
||||||
Value (*fn1)(Value) = (void*)fn->bi;
|
Value (*fn1)(Value) = (void*)fn->bi;
|
||||||
returnv = fn1(execute(params[0]));
|
returnv = fn1(execute(params[0]));
|
||||||
break;
|
break;
|
||||||
case 2:
|
}
|
||||||
|
case 2:{
|
||||||
Value (*fn2)(Value,Value) = (void*)fn->bi;
|
Value (*fn2)(Value,Value) = (void*)fn->bi;
|
||||||
returnv = fn2(execute(params[0]),execute(params[1]));
|
returnv = fn2(execute(params[0]),execute(params[1]));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
runtime_err("Call to builtin with >2 params");
|
runtime_err("Call to builtin with >2 params");
|
||||||
break;
|
break;
|
||||||
|
@ -149,13 +151,14 @@ Value execute(Statement *stat){
|
||||||
case BI_cast:
|
case BI_cast:
|
||||||
returnv = cast(stat->var_type, execute(stat->children[0]));
|
returnv = cast(stat->var_type, execute(stat->children[0]));
|
||||||
break;
|
break;
|
||||||
case ST_Call:
|
case ST_Call:{
|
||||||
FnSig *fn = stat->func;
|
FnSig *fn = stat->func;
|
||||||
Statement **params = NULL;
|
Statement **params = NULL;
|
||||||
if(fn->n_param)
|
if(fn->n_param)
|
||||||
params = (Statement**)((Statement*)stat->children[0])->children;
|
params = (Statement**)((Statement*)stat->children[0])->children;
|
||||||
returnv = fncall(fn, params);
|
returnv = fncall(fn, params);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return returnv;
|
return returnv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
@ -34,7 +35,7 @@ extern FILE *yyin;
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
i32 fpos = 1;
|
i32 fpos = 1;
|
||||||
|
|
||||||
if(argc > 1){
|
if(argc > 1){
|
||||||
if(!strcmp(argv[1], "--tests")){
|
if(!strcmp(argv[1], "--tests")){
|
||||||
fpos++;
|
fpos++;
|
||||||
|
|
Loading…
Add table
Reference in a new issue