mirror of https://github.com/rusefi/bldc.git
Merge commit '8701f9ad0695f86b3e7bf514d829119cb72d4427'
This commit is contained in:
commit
0d60c633c9
|
@ -1667,6 +1667,97 @@ Example that changes mailbox size to 100 elements.
|
|||
|
||||
---
|
||||
|
||||
## Flat values
|
||||
|
||||
Lisp values can be "flattened" into an array representation. The flat
|
||||
representation of a value contains all information needed so that the
|
||||
value can be recreated, "unflattened", in another instance of the
|
||||
runtime system (for example running on another microcontroller).
|
||||
|
||||
Not all values can be flattened, custom types for example cannot.
|
||||
|
||||
### flatten
|
||||
|
||||
The `flatten` function takes a value as single argument and returns the flat representation if
|
||||
successful. A flatten expression has the form `(flatten expr)`. Note that `expr` is evaluated
|
||||
before the flattening.
|
||||
|
||||
Example:
|
||||
```
|
||||
# (define a (flatten (+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
```
|
||||
The example above creates a `~FLATVAL~` representation of the the value `3`.
|
||||
|
||||
```
|
||||
# (define a (flatten '(+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
```
|
||||
|
||||
Now the `~FLATVAL~` contains a representation of the list `(+ 1 2)`
|
||||
|
||||
---
|
||||
|
||||
### unflatten
|
||||
|
||||
`unflatten` converts a flat value back into a lisp value. Te form of an
|
||||
`unflatten` expression is `(unflatten flat-value)`
|
||||
|
||||
Example:
|
||||
```
|
||||
# (define a (flatten (+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
# (unflatten a)
|
||||
> 3
|
||||
```
|
||||
|
||||
and:
|
||||
```
|
||||
# (define a (flatten '(+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
# (unflatten a)
|
||||
> (+ 1 2)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### fv-to-a
|
||||
|
||||
Convert a flat value to a byte-array by applying `fv-to-a`. The form of
|
||||
an `fv-to-a` expression is `(fv-to-a flat-value)`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# (define a (flatten '(1 2 3)))
|
||||
> ~FLATVAL~
|
||||
# (fv-to-a a)
|
||||
> ""
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### a-to-fv
|
||||
|
||||
Convert an array representing a valid flat value into a flat value. The form
|
||||
of an `a-to-fv` expression is `(a-to-fv array)`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
# (define a (flatten '(1 2 3)))
|
||||
> ~FLATVAL~
|
||||
# (define b (fv-to-a a))
|
||||
> ""
|
||||
# (define c (a-to-fv b))
|
||||
> ~FLATVAL~
|
||||
# (unflatten c)
|
||||
> (1 2 3)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
## Macros
|
||||
|
||||
lispBM macros are created using the `macro` keyword. A macro
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
#define SYM_IND_F_TYPE 0x36
|
||||
#define SYM_CHANNEL_TYPE 0x37
|
||||
#define SYM_CUSTOM_TYPE 0x38
|
||||
#define SYM_FLATVAL_TYPE 0x39
|
||||
#define SYM_FLATVAL_TYPE SYM_ARRAY_TYPE
|
||||
#define TYPE_CLASSIFIER_ENDS 0x39
|
||||
#define SYM_NONSENSE 0x3A
|
||||
|
||||
|
@ -281,7 +281,9 @@
|
|||
#define SYM_REG_EVENT_HANDLER 0x245
|
||||
#define SYM_TAKE 0x246
|
||||
#define SYM_DROP 0x247
|
||||
#define FUNDAMENTALS_END 0x247
|
||||
#define SYM_FLAT_TO_ARRAY 0x248
|
||||
#define SYM_ARRAY_TO_FLAT 0x249
|
||||
#define FUNDAMENTALS_END 0x249
|
||||
|
||||
#define SPECIAL_SYMBOLS_START 0
|
||||
#define SPECIAL_SYMBOLS_END 0xFFFF
|
||||
|
@ -462,7 +464,8 @@
|
|||
#define ENC_SYM_REG_EVENT_HANDLER ENC_SYM(SYM_REG_EVENT_HANDLER)
|
||||
#define ENC_SYM_TAKE ENC_SYM(SYM_TAKE)
|
||||
#define ENC_SYM_DROP ENC_SYM(SYM_DROP)
|
||||
|
||||
#define ENC_SYM_FLAT_TO_ARRAY ENC_SYM(SYM_FLAT_TO_ARRAY)
|
||||
#define ENC_SYM_ARRAY_TO_FLAT ENC_SYM(SYM_ARRAY_TO_FLAT)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1209,6 +1209,26 @@ static lbm_value fundamental_drop(lbm_value *args, lbm_uint nargs, eval_context_
|
|||
return lbm_list_drop(lbm_dec_as_u32(args[1]), args[0]);
|
||||
}
|
||||
|
||||
static lbm_value fundamental_fv_to_a(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||
(void) ctx;
|
||||
if (nargs == 1 && lbm_type_of(args[0]) == LBM_TYPE_FLATVAL) {
|
||||
lbm_value res = args[0];
|
||||
res = lbm_set_ptr_type(res, LBM_TYPE_ARRAY);
|
||||
return res;
|
||||
}
|
||||
return ENC_SYM_TERROR;
|
||||
}
|
||||
|
||||
static lbm_value fundamental_a_to_fv(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||
(void) ctx;
|
||||
if (nargs == 1 && lbm_type_of(args[0]) == LBM_TYPE_ARRAY) {
|
||||
lbm_value res = args[0];
|
||||
res = lbm_set_ptr_type(res, LBM_TYPE_FLATVAL);
|
||||
return res;
|
||||
}
|
||||
return ENC_SYM_TERROR;
|
||||
}
|
||||
|
||||
const fundamental_fun fundamental_table[] =
|
||||
{fundamental_add,
|
||||
fundamental_sub,
|
||||
|
@ -1267,5 +1287,7 @@ const fundamental_fun fundamental_table[] =
|
|||
fundamental_range,
|
||||
fundamental_reg_event_handler,
|
||||
fundamental_take,
|
||||
fundamental_drop
|
||||
fundamental_drop,
|
||||
fundamental_fv_to_a,
|
||||
fundamental_a_to_fv,
|
||||
};
|
||||
|
|
|
@ -688,7 +688,7 @@ int lbm_gc_sweep_phase(void) {
|
|||
case SYM_IND_F_TYPE:
|
||||
lbm_memory_free((lbm_uint*)heap[i].car);
|
||||
break;
|
||||
case SYM_FLATVAL_TYPE:
|
||||
//case SYM_FLATVAL_TYPE:
|
||||
case SYM_ARRAY_TYPE:{
|
||||
lbm_array_header_t *arr = (lbm_array_header_t*)heap[i].car;
|
||||
if (lbm_memory_ptr_inside((lbm_uint*)arr->data)) {
|
||||
|
|
|
@ -223,6 +223,8 @@ special_sym const special_symbols[] = {
|
|||
{"type-f32" , SYM_TYPE_FLOAT},
|
||||
{"type-f64" , SYM_TYPE_DOUBLE},
|
||||
{"array-create" , SYM_ARRAY_CREATE},
|
||||
{"fv-to-a" , SYM_FLAT_TO_ARRAY},
|
||||
{"a-to-fv" , SYM_ARRAY_TO_FLAT},
|
||||
};
|
||||
|
||||
static lbm_uint *symlist = NULL;
|
||||
|
|
Loading…
Reference in New Issue