Squashed 'lispBM/lispBM/' changes from 7756d581..b3d8a6b2

b3d8a6b2 removed functions that nolonger have a purpose
306722dc remove the possibility to step through program and reorganize the most critical loop structure
aa6eb5ca  remove encode, decode from refman
899d8579 update README and plot script
132e9364 updated readme with more detailed intro

git-subtree-dir: lispBM/lispBM
git-subtree-split: b3d8a6b21af4683af8837ad1a5106cf0d2d7eac9
This commit is contained in:
Benjamin Vedder 2022-10-06 13:58:38 +02:00
parent e8748c33d6
commit dccfe15135
7 changed files with 81 additions and 143 deletions

View File

@ -1,7 +1,14 @@
# lispBM (LBM)
A concurrent lisp-like language with message-passing and
pattern-matching implemented in C for 32 bit and 64 bit platforms.
LispBM is a lisp or scheme like programming language for
microcontrollers. LispBM also borrows a couple of ideas from Erlang
when it comes to concurrency, message passing, pattern matching and
process monitoring. The LispBM runtime system can be compiled for
either 32 or 64 bit platforms and runs on a wide range of hardware
such as for example STM32, NRF52, ESP32 or X86. When running the
LispBM runtime system on a microcontroller it can be built on top of
ChibiOS, FreeRTOS or ZephyrOS and it can also be built to run on top
of a regular linux.
![LispBM mascot](https://github.com/svenssonjoel/lispBM/blob/master/mascot/lispbm_llama_small.png)

View File

@ -36,7 +36,9 @@ for bench in benches:
lgd = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax = plt.gca()
for tick in ax.get_xticklabels():
tick.set_rotation(45)
tick.set_rotation(90)
ax.tick_params(axis='both', which='major', labelsize=6)
ax.tick_params(axis='both', which='minor', labelsize=4)
plt.ylabel("Sec")
plt.grid()
plt.savefig('benchresults.png', dpi=600, bbox_extra_artists=(lgd,), bbox_inches='tight')

View File

@ -347,53 +347,6 @@ the argument.
## Low level operations
### encode-i32
The `encode-i32` function converts a list of four (byte sized) values
into an i32 value.
Example that evaluates to the i32 value 1024.
```clj
(encode-i32 (list 0 0 4 0))
```
---
### encode-u32
The `encode-u32` function converts a list of four (byte sized) values
into an u32 value.
Example that evaluates to the u32 value 1024.
```clj
(encode-u32 (list 0 0 4 0))
```
---
### encode-float
The `encode-float` function converts a list four (byte sized) values
into a float value.
Example that evaluates to 3.14.
```clj
(encode-float (list 64 72 245 195))
```
---
### decode
The `decode` function decodes a value into a list of four (byte sized) values.
Example that decodes float 3.14 into the list (64 72 245 195).
```clj
(decode 3.14)
```
---
## nil and t

View File

@ -141,16 +141,6 @@ void lbm_pause_eval(void);
* \param num_free Perform GC if there are less than this many elements free on the heap.
*/
void lbm_pause_eval_with_gc(uint32_t num_free);
/** Perform a single step of evaluation.
* The evaluator should be in EVAL_CPS_STATE_PAUSED before running this function.
* After taking one step of evaluation, the evaluator will return to being in the
* EVAL_CPS_STATE_PUASED state.
*/
void lbm_step_eval(void);
/** Perform multiple steps of evaluation.
* \param n Number of eval steps to perform.
*/
void lbm_step_n_eval(uint32_t n);
/** Resume from being in EVAL_CPS_STATE_PAUSED.
*
*/

View File

@ -833,12 +833,6 @@ int main(int argc, char **argv) {
} else if (strncmp(str, ":continue", 9) == 0) {
lbm_continue_eval();
free(str);
} else if (strncmp(str, ":step", 5) == 0) {
int num = atoi(str + 5);
lbm_step_n_eval((uint32_t)num);
free(str);
} else if (strncmp(str, ":inspect", 8) == 0) {
int i = 8;

View File

@ -137,9 +137,10 @@ void lbm_set_eval_step_quota(uint32_t quota) {
eval_steps_refill = quota;
}
static uint32_t eval_cps_run_state = EVAL_CPS_STATE_INIT;
static volatile uint32_t eval_cps_next_state = EVAL_CPS_STATE_INIT;
static uint32_t eval_cps_run_state = EVAL_CPS_STATE_RUNNING;
static volatile uint32_t eval_cps_next_state = EVAL_CPS_STATE_RUNNING;
static volatile uint32_t eval_cps_next_state_arg = 0;
static volatile bool eval_cps_state_changed = false;
/*
On ChibiOs the CH_CFG_ST_FREQUENCY setting in chconf.h sets the
@ -2884,29 +2885,23 @@ static void evaluation_step(void){
void lbm_pause_eval(void ) {
eval_cps_next_state_arg = 0;
eval_cps_next_state = EVAL_CPS_STATE_PAUSED;
if (eval_cps_next_state != eval_cps_run_state) eval_cps_state_changed = true;
}
void lbm_pause_eval_with_gc(uint32_t num_free) {
eval_cps_next_state_arg = num_free;
eval_cps_next_state = EVAL_CPS_STATE_PAUSED;
}
void lbm_step_eval(void) {
eval_cps_next_state_arg = 1;
eval_cps_next_state = EVAL_CPS_STATE_STEP;
}
void lbm_step_n_eval(uint32_t n) {
eval_cps_next_state_arg = n;
eval_cps_next_state = EVAL_CPS_STATE_STEP;
if (eval_cps_next_state != eval_cps_run_state) eval_cps_state_changed = true;
}
void lbm_continue_eval(void) {
eval_cps_next_state = EVAL_CPS_STATE_RUNNING;
if (eval_cps_next_state != eval_cps_run_state) eval_cps_state_changed = true;
}
void lbm_kill_eval(void) {
eval_cps_next_state = EVAL_CPS_STATE_KILL;
if (eval_cps_next_state != eval_cps_run_state) eval_cps_state_changed = true;
}
uint32_t lbm_get_eval_state(void) {
@ -2920,19 +2915,8 @@ uint32_t lbm_get_eval_state(void) {
void lbm_run_eval(void){
while (eval_running) {
eval_cps_state_changed = false;
switch (eval_cps_next_state) {
case EVAL_CPS_STATE_INIT:
eval_cps_run_state = EVAL_CPS_STATE_RUNNING;
break;
case EVAL_CPS_STATE_STEP:
if (eval_cps_next_state_arg > 1) {
eval_cps_next_state = EVAL_CPS_STATE_STEP;
eval_cps_next_state_arg --;
} else {
eval_cps_next_state = EVAL_CPS_STATE_PAUSED;
}
break;
case EVAL_CPS_STATE_PAUSED:
if (eval_cps_run_state != EVAL_CPS_STATE_PAUSED) {
if (lbm_heap_num_free() < eval_cps_next_state_arg) {
@ -2946,13 +2930,18 @@ void lbm_run_eval(void){
case EVAL_CPS_STATE_KILL:
eval_running = false;
continue;
default:
default: // running state
eval_cps_run_state = eval_cps_next_state;
break;
}
while (true) {
eval_context_t *next_to_run = NULL;
if (eval_steps_quota <= 0 || !ctx_running) {
if (eval_steps_quota && ctx_running) {
eval_steps_quota--;
evaluation_step();
} else {
if (eval_cps_state_changed) break;
uint32_t us = EVAL_CPS_MIN_SLEEP;
if (is_atomic) {
@ -2983,9 +2972,7 @@ void lbm_run_eval(void){
continue;
}
}
eval_steps_quota--;
evaluation_step();
}
}
}
@ -3010,7 +2997,7 @@ int lbm_eval_init() {
done.last = NULL;
ctx_running = NULL;
eval_cps_run_state = EVAL_CPS_STATE_INIT;
eval_cps_run_state = EVAL_CPS_STATE_RUNNING;
mutex_init(&qmutex);

View File

@ -427,6 +427,11 @@ int main(int argc, char **argv) {
//lbm_create_char_stream_from_string(&string_tok_state,
// &string_tok,
// code_buffer);
lbm_pause_eval_with_gc(20);
while (lbm_get_eval_state() != EVAL_CPS_STATE_PAUSED) {
sleep_callback(1000);
}
if (stream_source) {
lbm_create_buffered_char_channel(&buffered_tok_state,
&string_tok);