Skip to content

Commit cda6f18

Browse files
committed
Project moved from hg(http://bitbucket.org/) repository.
0 parents  commit cda6f18

26 files changed

+2918
-0
lines changed

LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2010 Nedokushev grouzen Michael <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is licensed under the terms of MIT license, see LICENSE file.
2+
3+
target = src/fflisp
4+
objs = src/fflisp.o src/environment.o src/eval.o src/read.o \
5+
src/print.o src/heap.o src/object.o src/subr.o src/repl.o
6+
headers = include/fflisp.h include/environment.h include/eval.h include/read.h \
7+
include/print.h include/heap.h include/object.h include/subr.h \
8+
include/repl.h
9+
10+
LDFLAGS +=
11+
CFLAGS += -g
12+
13+
.PHONY: all clean
14+
all: $(objs)
15+
gcc -o $(target) $(objs) $(LDFLAGS)
16+
17+
$(objs): $(headers)
18+
19+
clean:
20+
rm -fv $(objs) $(target)

README

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
(IN LISP WE TRUST)
3+
__________ __________ (*)
4+
/ __/ __/ / /_/ __/ _ / /_\
5+
/ __/ __/ /_/ /__ / __/ /___\
6+
/_/ /_/ /___/_/___/_/ /_____\

TODO

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
;;;
3+
;;;
4+
;;;
5+
;;;;;
6+
;;; ;;;
7+
;;; ;;;
8+
9+
+Memoization
10+
+Lazy evaluation
11+
+Big numbers
12+
+Floating numbers
13+
+Tail recursion
14+
-Let form
15+
-Cond form
16+
+Make readable (a . b) exps
17+
+repl via readline library
18+
+call/cc

include/environment.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __ENVIRONMENT_H__
4+
#define __ENVIRONMENT_H__
5+
6+
#define ENV_FIRST(env) (CAR((env)))
7+
#define ENV_REST(env) (CDR((env)))
8+
9+
struct lispobj *env_var_lookup(struct lispobj*, struct lispobj*);
10+
struct lispobj *env_var_assign(struct lispobj*, struct lispobj*, struct lispobj*);
11+
struct lispobj *env_var_define(struct lispobj*, struct lispobj*, struct lispobj*);
12+
struct lispobj *env_val_list(struct lispobj*, struct lispobj*);
13+
struct lispobj *env_proc_make(struct lispobj*, struct lispobj*, struct lispobj*);
14+
struct lispobj *env_frame_make(struct lispobj*, struct lispobj*);
15+
struct lispobj *env_init(void);
16+
#ifdef __DEBUG_ENV__
17+
void env_debug(void);
18+
#endif /* __DEBUG_ENV__ */
19+
20+
#endif /* __ENVIRONMENT_H__ */

include/eval.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __EVAL_H__
4+
#define __EVAL_H__
5+
6+
struct lispobj *eval(struct lispobj*, struct lispobj*);
7+
struct lispobj *apply(struct lispobj*, struct lispobj*);
8+
9+
#endif /* __EVAL_H__ */

include/fflisp.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __FFLISP_H__
4+
#define __FFLIST_H__
5+
6+
extern struct lispobj *symbol_table;
7+
extern struct lispobj *environment;
8+
extern struct lispobj *nil;
9+
extern struct lispobj *t;
10+
extern struct heap *heap;
11+
12+
#endif /* __FFLISP_H__ */

include/heap.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __HEAP_H__
4+
#define __HEAP_H__
5+
6+
struct heap {
7+
struct lispobj **data;
8+
int index;
9+
int size;
10+
};
11+
12+
struct heap *heap_init(void);
13+
struct lispobj *heap_add(struct lispobj*);
14+
void heap_remove(struct lispobj*);
15+
void heap_clean(void);
16+
struct lispobj *heap_grab(struct lispobj*);
17+
void heap_release(struct lispobj*);
18+
struct lispobj *symbol_table_intern(struct lispobj*);
19+
struct lispobj *symbol_table_lookup(char*);
20+
#ifdef __DEBUG_SYMT__
21+
void symbol_table_debug(void);
22+
#endif /* __DEBUG_SYMT__ */
23+
#ifdef __DEBUG_HEAP__
24+
void heap_debug(void);
25+
#endif /* __DEBUG_HEAP__ */
26+
27+
#define HEAP_SIZE (2 << 10)
28+
29+
#endif /* __HEAP_H__ */

include/object.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __OBJECT_H__
4+
#define __OBJECT_H__
5+
6+
enum {
7+
CONS = 0,
8+
NUMBER,
9+
SYMBOL,
10+
STRING,
11+
ERROR,
12+
};
13+
14+
struct lispobj {
15+
int refs;
16+
int type;
17+
union {
18+
int number;
19+
char *symbol;
20+
char *string;
21+
char *error;
22+
struct cons {
23+
struct lispobj *car;
24+
struct lispobj *cdr;
25+
} *cons;
26+
} value;
27+
};
28+
29+
#include "../include/fflisp.h"
30+
31+
#define OBJ_TRUE t
32+
#define OBJ_FALSE nil
33+
34+
#define SYMBOL_VALUE(x) ((x)->value.symbol)
35+
#define NUMBER_VALUE(x) ((x)->value.number)
36+
#define STRING_VALUE(x) ((x)->value.string)
37+
#define ERROR_VALUE(x) ((x)->value.error)
38+
#define CONS_VALUE(x) ((x)->value.cons)
39+
40+
#define NEW_SYMBOL(o) (object_create(SYMBOL, (o)))
41+
#define NEW_NUMBER(o) (object_create(NUMBER, (o)))
42+
#define NEW_STRING(o) (object_create(STRING, (o)))
43+
#define NEW_ERROR(o) (object_create(ERROR, (o)))
44+
#define NEW_CONS(car, cdr) (cons((car), (cdr)))
45+
46+
#define CAR(x) (CONS_VALUE((x))->car) // 1st element of list/cons
47+
#define CDR(x) (CONS_VALUE((x))->cdr) // 2d element of cons
48+
#define CADR(x) (CAR(CDR((x)))) // 2d element of list
49+
#define CDDR(x) (CDR(CDR((x)))) // 2d element of cons which it's 2d element of list
50+
#define CADDR(x) (CAR(CDR(CDR((x))))) // 3d element of list
51+
#define CDDDR(x) (CDR(CDR(CDR((x)))))
52+
#define CADDDR(x) (CAR(CDR(CDR(CDR((x))))))
53+
54+
#define OBJ_TYPE(x) ((x)->type)
55+
#define OBJ_REFS(x) ((x)->refs)
56+
57+
struct lispobj *object_create(int, char*);
58+
void object_delete(struct lispobj*);
59+
60+
#endif /* __OBJECT_H__ */

include/print.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __PRINT_H__
4+
#define __PRINT_H__
5+
6+
void print(struct lispobj*);
7+
8+
#endif /* __PRINT_H__ */

include/read.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __READ_H__
4+
#define __READ_H__
5+
6+
struct lispobj *read(FILE*);
7+
8+
#endif /* __READ_H__ */

include/repl.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __REPL_H__
4+
#define __REPL_H__
5+
6+
int load(const char*);
7+
void repl(FILE*);
8+
9+
#endif /* __REPL_H__ */

include/subr.h

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* This file is licensed under the terms of MIT license, see LICENSE file. */
2+
3+
#ifndef __SUBR_H__
4+
#define __SUBR_H__
5+
6+
int length(struct lispobj*);
7+
struct lispobj *cons(struct lispobj*, struct lispobj*);
8+
struct lispobj *list(int, ...);
9+
10+
struct lispobj *subr_newline(struct lispobj*);
11+
struct lispobj *subr_display(struct lispobj*);
12+
struct lispobj *subr_rplaca(struct lispobj*);
13+
struct lispobj *subr_rplacd(struct lispobj*);
14+
struct lispobj *subr_apply(struct lispobj*);
15+
struct lispobj *subr_error(struct lispobj*);
16+
struct lispobj *subr_eval(struct lispobj*);
17+
struct lispobj *subr_read(struct lispobj*);
18+
struct lispobj *subr_load(struct lispobj*);
19+
struct lispobj *subr_car(struct lispobj*);
20+
struct lispobj *subr_cdr(struct lispobj*);
21+
struct lispobj *subr_cons(struct lispobj*);
22+
struct lispobj *subr_pair(struct lispobj*);
23+
struct lispobj *subr_number(struct lispobj*);
24+
struct lispobj *subr_string(struct lispobj*);
25+
struct lispobj *subr_symbol(struct lispobj*);
26+
struct lispobj *subr_atom(struct lispobj*);
27+
struct lispobj *subr_null(struct lispobj*);
28+
struct lispobj *subr_not(struct lispobj*);
29+
struct lispobj *subr_or(struct lispobj*);
30+
struct lispobj *subr_and(struct lispobj*);
31+
struct lispobj *subr_eq(struct lispobj*);
32+
struct lispobj *subr_eql(struct lispobj*);
33+
struct lispobj *subr_list(struct lispobj*);
34+
struct lispobj *subr_plus(struct lispobj*);
35+
struct lispobj *subr_multi(struct lispobj*);
36+
struct lispobj *subr_compar(struct lispobj*);
37+
struct lispobj *subr_greatthan(struct lispobj*);
38+
struct lispobj *subr_lessthan(struct lispobj*);
39+
struct lispobj *subr_minus(struct lispobj*);
40+
struct lispobj *subr_divide(struct lispobj*);
41+
struct lispobj *subr_equal(struct lispobj*);
42+
struct lispobj *subr_heap(struct lispobj *);
43+
struct lispobj *subr_heap_object(struct lispobj *);
44+
45+
#define ERROR_ARGS object_create(ERROR, "Recieve wrong number of arguments.\n")
46+
47+
/*
48+
#define ERROR_ARGS(n) \
49+
do { \
50+
char error[64]; \
51+
snprintf(error, 64, "Recieve wrong number of arguments: %d.\n", (n)); \
52+
return object_create(ERROR, error); \
53+
} while(0)
54+
*/
55+
#endif /* __SUBR_H__ */

0 commit comments

Comments
 (0)