projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altos/lisp: Split out read debug, add memory validation
[fw/altos]
/
src
/
lisp
/
ao_lisp.h
diff --git
a/src/lisp/ao_lisp.h
b/src/lisp/ao_lisp.h
index 858212dd5012fc9659fce01dea1a8ba384a0f4f5..d32e7dcd8da263f8d96377bd8190ded9469a5b22 100644
(file)
--- a/
src/lisp/ao_lisp.h
+++ b/
src/lisp/ao_lisp.h
@@
-17,6
+17,9
@@
#define DBG_MEM 0
#define DBG_EVAL 0
#define DBG_MEM 0
#define DBG_EVAL 0
+#define DBG_READ 0
+#define DBG_FREE_CONS 0
+#define NDEBUG 1
#include <stdint.h>
#include <string.h>
#include <stdint.h>
#include <string.h>
@@
-92,12
+95,13
@@
extern uint8_t ao_lisp_pool[AO_LISP_POOL + AO_LISP_POOL_EXTRA] __attribute__((a
#define AO_LISP_ATOM 4
#define AO_LISP_BUILTIN 5
#define AO_LISP_FRAME 6
#define AO_LISP_ATOM 4
#define AO_LISP_BUILTIN 5
#define AO_LISP_FRAME 6
-#define AO_LISP_LAMBDA 7
-#define AO_LISP_STACK 8
-#define AO_LISP_BOOL 9
-#define AO_LISP_BIGINT 10
-#define AO_LISP_FLOAT 11
-#define AO_LISP_NUM_TYPE 12
+#define AO_LISP_FRAME_VALS 7
+#define AO_LISP_LAMBDA 8
+#define AO_LISP_STACK 9
+#define AO_LISP_BOOL 10
+#define AO_LISP_BIGINT 11
+#define AO_LISP_FLOAT 12
+#define AO_LISP_NUM_TYPE 13
/* Leave two bits for types to use as they please */
#define AO_LISP_OTHER_TYPE_MASK 0x3f
/* Leave two bits for types to use as they please */
#define AO_LISP_OTHER_TYPE_MASK 0x3f
@@
-110,8
+114,9
@@
extern uint16_t ao_lisp_top;
#define AO_LISP_DIVIDE_BY_ZERO 0x02
#define AO_LISP_INVALID 0x04
#define AO_LISP_UNDEFINED 0x08
#define AO_LISP_DIVIDE_BY_ZERO 0x02
#define AO_LISP_INVALID 0x04
#define AO_LISP_UNDEFINED 0x08
-#define AO_LISP_EOF 0x10
-#define AO_LISP_EXIT 0x20
+#define AO_LISP_REDEFINED 0x10
+#define AO_LISP_EOF 0x20
+#define AO_LISP_EXIT 0x40
extern uint8_t ao_lisp_exception;
extern uint8_t ao_lisp_exception;
@@
-154,11
+159,17
@@
struct ao_lisp_val {
ao_poly val;
};
ao_poly val;
};
+struct ao_lisp_frame_vals {
+ uint8_t type;
+ uint8_t size;
+ struct ao_lisp_val vals[];
+};
+
struct ao_lisp_frame {
uint8_t type;
uint8_t num;
ao_poly prev;
struct ao_lisp_frame {
uint8_t type;
uint8_t num;
ao_poly prev;
-
struct ao_lisp_val vals[]
;
+
ao_poly vals
;
};
struct ao_lisp_bool {
};
struct ao_lisp_bool {
@@
-200,6
+211,8
@@
ao_lisp_bigint_int(uint32_t bi) {
#define AO_LISP_MIN_INT (-(1 << (15 - AO_LISP_TYPE_SHIFT)))
#define AO_LISP_MAX_INT ((1 << (15 - AO_LISP_TYPE_SHIFT)) - 1)
#define AO_LISP_MIN_INT (-(1 << (15 - AO_LISP_TYPE_SHIFT)))
#define AO_LISP_MAX_INT ((1 << (15 - AO_LISP_TYPE_SHIFT)) - 1)
+#define AO_LISP_MIN_BIGINT (-(1 << 24))
+#define AO_LISP_MAX_BIGINT ((1 << 24) - 1)
#define AO_LISP_NOT_INTEGER 0x7fffffff
#define AO_LISP_NOT_INTEGER 0x7fffffff
@@
-221,6
+234,16
@@
ao_lisp_frame_poly(struct ao_lisp_frame *frame) {
return ao_lisp_poly(frame, AO_LISP_OTHER);
}
return ao_lisp_poly(frame, AO_LISP_OTHER);
}
+static inline struct ao_lisp_frame_vals *
+ao_lisp_poly_frame_vals(ao_poly poly) {
+ return ao_lisp_ref(poly);
+}
+
+static inline ao_poly
+ao_lisp_frame_vals_poly(struct ao_lisp_frame_vals *vals) {
+ return ao_lisp_poly(vals, AO_LISP_OTHER);
+}
+
enum eval_state {
eval_sexpr, /* Evaluate an sexpr */
eval_val, /* Value computed */
enum eval_state {
eval_sexpr, /* Evaluate an sexpr */
eval_val, /* Value computed */
@@
-367,6
+390,16
@@
static inline int ao_lisp_poly_type(ao_poly poly) {
return type;
}
return type;
}
+static inline int
+ao_lisp_is_cons(ao_poly poly) {
+ return (ao_lisp_poly_base_type(poly) == AO_LISP_CONS);
+}
+
+static inline int
+ao_lisp_is_pair(ao_poly poly) {
+ return poly != AO_LISP_NIL && (ao_lisp_poly_base_type(poly) == AO_LISP_CONS);
+}
+
static inline struct ao_lisp_cons *
ao_lisp_poly_cons(ao_poly poly)
{
static inline struct ao_lisp_cons *
ao_lisp_poly_cons(ao_poly poly)
{
@@
-500,6
+533,11
@@
ao_lisp_alloc(int size);
int
ao_lisp_collect(uint8_t style);
int
ao_lisp_collect(uint8_t style);
+#if DBG_FREE_CONS
+void
+ao_lisp_cons_check(struct ao_lisp_cons *cons);
+#endif
+
void
ao_lisp_cons_stash(int id, struct ao_lisp_cons *cons);
void
ao_lisp_cons_stash(int id, struct ao_lisp_cons *cons);
@@
-528,6
+566,12
@@
ao_lisp_stack_fetch(int id) {
return ao_lisp_poly_stack(ao_lisp_poly_fetch(id));
}
return ao_lisp_poly_stack(ao_lisp_poly_fetch(id));
}
+void
+ao_lisp_frame_stash(int id, struct ao_lisp_frame *frame);
+
+struct ao_lisp_frame *
+ao_lisp_frame_fetch(int id);
+
/* bool */
extern const struct ao_lisp_type ao_lisp_bool_type;
/* bool */
extern const struct ao_lisp_type ao_lisp_bool_type;
@@
-604,7
+648,7
@@
struct ao_lisp_atom *
ao_lisp_atom_intern(char *name);
ao_poly *
ao_lisp_atom_intern(char *name);
ao_poly *
-ao_lisp_atom_ref(
struct ao_lisp_frame *frame,
ao_poly atom);
+ao_lisp_atom_ref(ao_poly atom);
ao_poly
ao_lisp_atom_get(ao_poly atom);
ao_poly
ao_lisp_atom_get(ao_poly atom);
@@
-612,6
+656,9
@@
ao_lisp_atom_get(ao_poly atom);
ao_poly
ao_lisp_atom_set(ao_poly atom, ao_poly val);
ao_poly
ao_lisp_atom_set(ao_poly atom, ao_poly val);
+ao_poly
+ao_lisp_atom_def(ao_poly atom, ao_poly val);
+
/* int */
void
ao_lisp_int_write(ao_poly i);
/* int */
void
ao_lisp_int_write(ao_poly i);
@@
-713,6
+760,7
@@
ao_lisp_read_eval_print(void);
/* frame */
extern const struct ao_lisp_type ao_lisp_frame_type;
/* frame */
extern const struct ao_lisp_type ao_lisp_frame_type;
+extern const struct ao_lisp_type ao_lisp_frame_vals_type;
#define AO_LISP_FRAME_FREE 6
#define AO_LISP_FRAME_FREE 6
@@
-733,12
+781,15
@@
ao_lisp_frame_free(struct ao_lisp_frame *frame);
void
ao_lisp_frame_bind(struct ao_lisp_frame *frame, int num, ao_poly atom, ao_poly val);
void
ao_lisp_frame_bind(struct ao_lisp_frame *frame, int num, ao_poly atom, ao_poly val);
-int
-ao_lisp_frame_add(struct ao_lisp_frame *
*
frame, ao_poly atom, ao_poly val);
+ao_poly
+ao_lisp_frame_add(struct ao_lisp_frame *frame, ao_poly atom, ao_poly val);
void
ao_lisp_frame_write(ao_poly p);
void
ao_lisp_frame_write(ao_poly p);
+void
+ao_lisp_frame_init(void);
+
/* lambda */
extern const struct ao_lisp_type ao_lisp_lambda_type;
/* lambda */
extern const struct ao_lisp_type ao_lisp_lambda_type;
@@
-779,6
+830,12
@@
ao_lisp_stack_eval(void);
/* error */
/* error */
+void
+ao_lisp_vprintf(char *format, va_list args);
+
+void
+ao_lisp_printf(char *format, ...);
+
void
ao_lisp_error_poly(char *name, ao_poly poly, ao_poly last);
void
ao_lisp_error_poly(char *name, ao_poly poly, ao_poly last);
@@
-795,7
+852,7
@@
ao_lisp_error(int error, char *format, ...);
/* debugging macros */
/* debugging macros */
-#if DBG_EVAL
+#if DBG_EVAL
|| DBG_READ || DBG_MEM
#define DBG_CODE 1
int ao_lisp_stack_depth;
#define DBG_DO(a) a
#define DBG_CODE 1
int ao_lisp_stack_depth;
#define DBG_DO(a) a
@@
-803,8
+860,8
@@
int ao_lisp_stack_depth;
#define DBG_IN() (++ao_lisp_stack_depth)
#define DBG_OUT() (--ao_lisp_stack_depth)
#define DBG_RESET() (ao_lisp_stack_depth = 0)
#define DBG_IN() (++ao_lisp_stack_depth)
#define DBG_OUT() (--ao_lisp_stack_depth)
#define DBG_RESET() (ao_lisp_stack_depth = 0)
-#define DBG(...) printf(__VA_ARGS__)
-#define DBGI(...) do {
DBG
("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
+#define DBG(...)
ao_lisp_
printf(__VA_ARGS__)
+#define DBGI(...) do {
printf
("%4d: ", __LINE__); DBG_INDENT(); DBG(__VA_ARGS__); } while (0)
#define DBG_CONS(a) ao_lisp_cons_write(ao_lisp_cons_poly(a))
#define DBG_POLY(a) ao_lisp_poly_write(a)
#define OFFSET(a) ((a) ? (int) ((uint8_t *) a - ao_lisp_pool) : -1)
#define DBG_CONS(a) ao_lisp_cons_write(ao_lisp_cons_poly(a))
#define DBG_POLY(a) ao_lisp_poly_write(a)
#define OFFSET(a) ((a) ? (int) ((uint8_t *) a - ao_lisp_pool) : -1)
@@
-833,6
+890,16
@@
ao_lisp_frames_dump(void)
#define DBG_FRAMES()
#endif
#define DBG_FRAMES()
#endif
+#if DBG_READ
+#define RDBGI(...) DBGI(__VA_ARGS__)
+#define RDBG_IN() DBG_IN()
+#define RDBG_OUT() DBG_OUT()
+#else
+#define RDBGI(...)
+#define RDBG_IN()
+#define RDBG_OUT()
+#endif
+
#define DBG_MEM_START 1
#if DBG_MEM
#define DBG_MEM_START 1
#if DBG_MEM
@@
-840,11
+907,11
@@
ao_lisp_frames_dump(void)
#include <assert.h>
extern int dbg_move_depth;
#define MDBG_DUMP 1
#include <assert.h>
extern int dbg_move_depth;
#define MDBG_DUMP 1
-#define MDBG_OFFSET(a) ((
int) ((uint8_t *) (a) - ao_lisp_pool)
)
+#define MDBG_OFFSET(a) ((
a) ? (int) ((uint8_t *) (a) - ao_lisp_pool) : -1
)
extern int dbg_mem;
extern int dbg_mem;
-#define MDBG_DO(a)
a
+#define MDBG_DO(a)
DBG_DO(a)
#define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
#define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
#define MDBG_MOVE_IN() (dbg_move_depth++)
#define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
#define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
#define MDBG_MOVE_IN() (dbg_move_depth++)