Skip to content

Commit 4f0388d

Browse files
committed
Added lispbm test module (disabled by default)
1 parent 3856631 commit 4f0388d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+8601
-7
lines changed

Makefile

+17-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# NOTE: Can be overridden externally.
44
#
55

6+
USE_LISPBM=0
7+
68
# Compiler options here.
79
ifeq ($(USE_OPT),)
810
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -D_GNU_SOURCE
@@ -112,7 +114,11 @@ include imu/imu.mk
112114
include lora/lora.mk
113115
include lzo/lzo.mk
114116
include blackmagic/blackmagic.mk
115-
#include lispBM/lispbm.mk
117+
118+
ifeq ($(USE_LISPBM),1)
119+
include lispBM/lispbm.mk
120+
USE_OPT += -DUSE_LISPBM
121+
endif
116122

117123
# Define linker script file here
118124
LDSCRIPT= ld_eeprom_emu.ld
@@ -170,8 +176,11 @@ CSRC = $(STARTUPSRC) \
170176
$(LORASRC) \
171177
$(LZOSRC) \
172178
$(BLACKMAGICSRC) \
173-
qmlui/qmlui.c \
174-
$(LISPBMSRC)
179+
qmlui/qmlui.c
180+
181+
ifeq ($(USE_LISPBM),1)
182+
CSRC += $(LISPBMSRC)
183+
endif
175184

176185
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
177186
# setting.
@@ -216,8 +225,11 @@ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
216225
$(BLACKMAGICINC) \
217226
qmlui \
218227
qmlui/hw \
219-
qmlui/app \
220-
$(LISPBMINC)
228+
qmlui/app
229+
230+
ifeq ($(USE_LISPBM),1)
231+
INCDIR += $(LISPBMINC)
232+
endif
221233

222234
ifdef app_custom_mkfile
223235
include $(app_custom_mkfile)

commands.c

+4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@
5858

5959
// Threads
6060
static THD_FUNCTION(blocking_thread, arg);
61+
#ifdef USE_LISPBM
62+
static THD_WORKING_AREA(blocking_thread_wa, 6000);
63+
#else
6164
static THD_WORKING_AREA(blocking_thread_wa, 2048);
65+
#endif
6266
static thread_t *blocking_tp;
6367

6468
// Private variables

lispBM/include/bytecode.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2020 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef BYTECODE_H_
19+
#define BYTECODE_H_
20+
21+
typedef struct {
22+
char* symbol_str;
23+
VALUE symbol_indirection;
24+
} symbol_indirection_t;
25+
26+
typedef struct {
27+
unsigned int code_size;
28+
uint8_t *code;
29+
unsigned int num_indirections;
30+
symbol_indirection_t *indirections;
31+
} bytecode_t;
32+
33+
34+
#endif

lispBM/include/compression.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2019 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef COMPRESSION_H_
19+
#define COMPRESSION_H_
20+
21+
#include <stdint.h>
22+
#include <stdbool.h>
23+
#include "lispbm_types.h"
24+
25+
typedef struct {
26+
uint32_t compressed_bits;
27+
uint32_t i;
28+
bool string_mode;
29+
char last_string_char;
30+
char *src;
31+
} decomp_state;
32+
33+
34+
extern void compression_init_state(decomp_state *s, char *src);
35+
36+
/*
37+
Compress performs destructive changes to
38+
the input string and cannot be called on constant string literal pointers
39+
for example.
40+
41+
Compress returns an array that caller must free
42+
*/
43+
extern char *compression_compress(char *string, uint32_t *res_size);
44+
extern int compression_decompress_incremental(decomp_state *s, char *dest_buff, uint32_t dest_n);
45+
extern bool compression_decompress(char *dest, uint32_t dest_n, char *src);
46+
47+
/* parse compressed code */
48+
extern VALUE compression_parse(char *bytes);
49+
50+
#endif

lispBM/include/ec_eval.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright 2020 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef _EC_EVAL_H_
19+
#define _EC_EVAL_H_
20+
21+
extern VALUE ec_eval_program(VALUE prg);
22+
extern VALUE ec_eval_get_env(void);
23+
24+
#endif

lispBM/include/env.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2018 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef ENV_H_
19+
#define ENV_H_
20+
21+
#include "lispbm_types.h"
22+
23+
extern int env_init(void);
24+
extern VALUE *env_get_global_ptr(void);
25+
extern VALUE env_copy_shallow(VALUE env);
26+
extern VALUE env_lookup(VALUE sym, VALUE env);
27+
extern VALUE env_set(VALUE env, VALUE key, VALUE val);
28+
extern VALUE env_modify_binding(VALUE env, VALUE key, VALUE val);
29+
extern VALUE env_build_params_args(VALUE params,
30+
VALUE args,
31+
VALUE env0);
32+
33+
#endif

lispBM/include/eval_cps.h

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Copyright 2018, 2020, 2021 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
#ifndef EVAL_CPS_H_
18+
#define EVAL_CPS_H_
19+
20+
#include "stack.h"
21+
#include "lispbm_types.h"
22+
23+
#define EVAL_CPS_STATE_INIT 0
24+
#define EVAL_CPS_STATE_PAUSED 1
25+
#define EVAL_CPS_STATE_RUNNING 2
26+
#define EVAL_CPS_STATE_STEP 3
27+
#define EVAL_CPS_STATE_KILL 4
28+
29+
30+
typedef struct eval_context_s{
31+
VALUE program;
32+
VALUE curr_exp;
33+
VALUE curr_env;
34+
VALUE mailbox; /*massage passing mailbox */
35+
VALUE r;
36+
bool done;
37+
bool app_cont;
38+
stack K;
39+
/* Process control */
40+
uint32_t timestamp;
41+
uint32_t sleep_us;
42+
CID id;
43+
/* List structure */
44+
struct eval_context_s *prev;
45+
struct eval_context_s *next;
46+
} eval_context_t;
47+
48+
typedef void (*ctx_fun)(eval_context_t *, void*, void*);
49+
50+
/* Common interface */
51+
extern VALUE eval_cps_get_env(void);
52+
53+
/* Concurrent interface */
54+
extern int eval_cps_init(void);
55+
extern bool eval_cps_remove_done_ctx(CID cid, VALUE *v);
56+
extern VALUE eval_cps_wait_ctx(CID cid);
57+
extern CID eval_cps_program(VALUE lisp);
58+
extern CID eval_cps_program_ext(VALUE lisp, unsigned int stack_size, bool grow_stack);
59+
extern void eval_cps_run_eval(void);
60+
61+
extern void eval_cps_pause_eval(void);
62+
extern void eval_cps_step_eval(void);
63+
extern void eval_cps_continue_eval(void);
64+
extern void eval_cps_kill_eval(void);
65+
extern uint32_t eval_cps_current_state(void);
66+
67+
/* statistics interface */
68+
extern void eval_cps_running_iterator(ctx_fun f, void*, void*);
69+
extern void eval_cps_blocked_iterator(ctx_fun f, void*, void*);
70+
extern void eval_cps_done_iterator(ctx_fun f, void*, void*);
71+
72+
/*
73+
Callback routines for sleeping and timestamp generation.
74+
Depending on target platform these will be implemented in different ways.
75+
Todo: It may become necessary to also add a mutex callback.
76+
*/
77+
extern void eval_cps_set_usleep_callback(void (*fptr)(uint32_t));
78+
extern void eval_cps_set_timestamp_us_callback(uint32_t (*fptr)(void));
79+
extern void eval_cps_set_ctx_done_callback(void (*fptr)(eval_context_t *));
80+
81+
/* Non concurrent interface: */
82+
extern int eval_cps_init_nc(unsigned int stack_size, bool grow_stack);
83+
extern void eval_cps_del_nc(void);
84+
extern VALUE eval_cps_program_nc(VALUE lisp);
85+
#endif

lispBM/include/exp_kind.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2020, 2021 Joel Svensson [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef _EXP_KIND_H_
19+
#define _EXP_KIND_H_
20+
21+
#include "heap.h"
22+
#include "symrepr.h"
23+
24+
typedef enum {
25+
EXP_KIND_ERROR,
26+
EXP_SELF_EVALUATING,
27+
EXP_VARIABLE,
28+
EXP_QUOTED,
29+
EXP_DEFINE,
30+
EXP_LAMBDA,
31+
EXP_IF,
32+
EXP_PROGN,
33+
EXP_NO_ARGS,
34+
EXP_APPLICATION,
35+
EXP_LET,
36+
EXP_AND,
37+
EXP_OR
38+
} exp_kind;
39+
40+
static inline exp_kind exp_kind_of(VALUE exp) {
41+
42+
switch (type_of(exp)) {
43+
case VAL_TYPE_SYMBOL:
44+
if (!is_special(exp))
45+
return EXP_VARIABLE;
46+
// fall through
47+
case PTR_TYPE_BOXED_F:
48+
case PTR_TYPE_BOXED_U:
49+
case PTR_TYPE_BOXED_I:
50+
case VAL_TYPE_I:
51+
case VAL_TYPE_U:
52+
case VAL_TYPE_CHAR:
53+
case PTR_TYPE_ARRAY:
54+
return EXP_SELF_EVALUATING;
55+
case PTR_TYPE_CONS: {
56+
VALUE head = car(exp);
57+
if (type_of(head) == VAL_TYPE_SYMBOL) {
58+
UINT sym_id = dec_sym(head);
59+
switch(sym_id){
60+
case SYM_AND: return EXP_AND;
61+
case SYM_OR: return EXP_OR;
62+
case SYM_QUOTE: return EXP_QUOTED;
63+
case SYM_DEFINE: return EXP_DEFINE;
64+
case SYM_PROGN: return EXP_PROGN;
65+
case SYM_LAMBDA: return EXP_LAMBDA;
66+
case SYM_IF: return EXP_IF;
67+
case SYM_LET: return EXP_LET;
68+
default: break;
69+
}
70+
} // end if symbol
71+
72+
if (type_of(cdr(exp)) == VAL_TYPE_SYMBOL &&
73+
dec_sym(cdr(exp)) == SYM_NIL) {
74+
return EXP_NO_ARGS;
75+
} else {
76+
return EXP_APPLICATION;
77+
}
78+
} // end case PTR_TYPE_CONS:
79+
}
80+
return EXP_KIND_ERROR;
81+
}
82+
83+
#endif

0 commit comments

Comments
 (0)