mirror of https://github.com/rusefi/bldc.git
Merge commit '902c8139f8aeb5fbf80ee0b537dc9fd37ad4b3ec'
This commit is contained in:
commit
1e8e3f0810
|
@ -1685,16 +1685,16 @@ before the flattening.
|
|||
Example:
|
||||
```
|
||||
# (define a (flatten (+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
> ""
|
||||
```
|
||||
The example above creates a `~FLATVAL~` representation of the the value `3`.
|
||||
The example above creates a byte-array representating the the value `3`.
|
||||
|
||||
```
|
||||
# (define a (flatten '(+ 1 2)))
|
||||
> ~FLATVAL~
|
||||
> "+"
|
||||
```
|
||||
|
||||
Now the `~FLATVAL~` contains a representation of the list `(+ 1 2)`
|
||||
Now the byte-array contains a representation of the list `(+ 1 2)`
|
||||
|
||||
---
|
||||
|
||||
|
@ -1706,58 +1706,20 @@ Now the `~FLATVAL~` contains a representation of the list `(+ 1 2)`
|
|||
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
|
||||
|
|
|
@ -37,10 +37,9 @@
|
|||
#define LBM_TYPE_DOUBLE 0x78000000u
|
||||
#define LBM_TYPE_ARRAY 0x80000000u
|
||||
#define LBM_TYPE_CHANNEL 0x90000000u
|
||||
#define LBM_TYPE_FLATVAL 0xA0000000u
|
||||
#define LBM_TYPE_CUSTOM 0xB0000000u
|
||||
#define LBM_NON_CONS_POINTER_TYPE_LAST 0xBC000000u
|
||||
#define LBM_POINTER_TYPE_LAST 0xBC000000u
|
||||
#define LBM_TYPE_CUSTOM 0xA0000000u
|
||||
#define LBM_NON_CONS_POINTER_TYPE_LAST 0xAC000000u
|
||||
#define LBM_POINTER_TYPE_LAST 0xAC000000u
|
||||
|
||||
#define LBM_CONTINUATION_INTERNAL 0xF8000001u // PTR bit set
|
||||
#define LBM_CONTINUATION_INTERNAL_TYPE 0xF8000000u
|
||||
|
@ -68,9 +67,8 @@
|
|||
#define LBM_TYPE_ARRAY (lbm_uint)0x5000000000000000
|
||||
#define LBM_TYPE_CHANNEL (lbm_uint)0x7000000000000000
|
||||
#define LBM_TYPE_CUSTOM (lbm_uint)0x8000000000000000
|
||||
#define LBM_TYPE_FLATVAL (lbm_uint)0x9000000000000000
|
||||
#define LBM_NON_CONS_POINTER_TYPE_LAST (lbm_uint)0x9000000000000000
|
||||
#define LBM_POINTER_TYPE_LAST (lbm_uint)0x9000000000000000
|
||||
#define LBM_NON_CONS_POINTER_TYPE_LAST (lbm_uint)0x8000000000000000
|
||||
#define LBM_POINTER_TYPE_LAST (lbm_uint)0x8000000000000000
|
||||
|
||||
#define LBM_CONTINUATION_INTERNAL (lbm_uint)0xF800000000000001
|
||||
#define LBM_CONTINUATION_INTERNAL_TYPE (lbm_uint)0xF800000000000000
|
||||
|
@ -125,7 +123,6 @@
|
|||
#define SYM_IND_F_TYPE 0x36
|
||||
#define SYM_CHANNEL_TYPE 0x37
|
||||
#define SYM_CUSTOM_TYPE 0x38
|
||||
#define SYM_FLATVAL_TYPE SYM_ARRAY_TYPE
|
||||
#define TYPE_CLASSIFIER_ENDS 0x39
|
||||
#define SYM_NONSENSE 0x3A
|
||||
|
||||
|
@ -147,7 +144,6 @@
|
|||
#define SYM_TYPE_CHAR 0x5B
|
||||
#define SYM_TYPE_BYTE 0x5C
|
||||
#define SYM_TYPE_CHANNEL 0x5E
|
||||
#define SYM_TYPE_FLATVAL 0x5F
|
||||
|
||||
//Relevant for the tokenizer and reader
|
||||
#define TOKENIZER_SYMBOLS_START 0x70
|
||||
|
@ -281,9 +277,7 @@
|
|||
#define SYM_REG_EVENT_HANDLER 0x245
|
||||
#define SYM_TAKE 0x246
|
||||
#define SYM_DROP 0x247
|
||||
#define SYM_FLAT_TO_ARRAY 0x248
|
||||
#define SYM_ARRAY_TO_FLAT 0x249
|
||||
#define FUNDAMENTALS_END 0x249
|
||||
#define FUNDAMENTALS_END 0x249
|
||||
|
||||
#define SPECIAL_SYMBOLS_START 0
|
||||
#define SPECIAL_SYMBOLS_END 0xFFFF
|
||||
|
@ -325,7 +319,6 @@
|
|||
#define ENC_SYM_IND_F_TYPE ENC_SYM(SYM_IND_F_TYPE)
|
||||
#define ENC_SYM_CHANNEL_TYPE ENC_SYM(SYM_CHANNEL_TYPE)
|
||||
#define ENC_SYM_CUSTOM_TYPE ENC_SYM(SYM_CUSTOM_TYPE)
|
||||
#define ENC_SYM_FLATVAL_TYPE ENC_SYM(SYM_FLATVAL_TYPE)
|
||||
#define ENC_SYM_NONSENSE ENC_SYM(SYM_NONSENSE)
|
||||
|
||||
#define ENC_SYM_NO_MATCH ENC_SYM(SYM_NO_MATCH)
|
||||
|
@ -345,7 +338,6 @@
|
|||
#define ENC_SYM_TYPE_CHAR ENC_SYM(SYM_TYPE_CHAR)
|
||||
#define ENC_SYM_TYPE_BYTE ENC_SYM(SYM_TYPE_BYTE)
|
||||
#define ENC_SYM_TYPE_CHANNEL ENC_SYM(SYM_TYPE_CHANNEL)
|
||||
#define ENC_SYM_TYPE_FLATVAL ENC_SYM(SYM_TYPE_FLATVAL)
|
||||
|
||||
#define ENC_SYM_OPENPAR ENC_SYM(SYM_OPENPAR)
|
||||
#define ENC_SYM_CLOSEPAR ENC_SYM(SYM_CLOSEPAR)
|
||||
|
@ -464,8 +456,5 @@
|
|||
#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
|
||||
|
|
|
@ -2369,7 +2369,7 @@ static void apply_flatten(lbm_value *args, lbm_uint nargs, eval_context_t *ctx)
|
|||
}
|
||||
|
||||
static void apply_unflatten(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
|
||||
if(nargs == 1 && lbm_type_of(args[0]) == LBM_TYPE_FLATVAL) {
|
||||
if(nargs == 1 && lbm_type_of(args[0]) == LBM_TYPE_ARRAY) {
|
||||
lbm_array_header_t *array;
|
||||
array = (lbm_array_header_t *)lbm_car(args[0]);
|
||||
|
||||
|
|
|
@ -1128,7 +1128,6 @@ static lbm_value fundamental_type_of(lbm_value *args, lbm_uint nargs, eval_conte
|
|||
case LBM_TYPE_U: return ENC_SYM_TYPE_U;
|
||||
case LBM_TYPE_CHAR: return ENC_SYM_TYPE_CHAR;
|
||||
case LBM_TYPE_SYMBOL: return ENC_SYM_TYPE_SYMBOL;
|
||||
case LBM_TYPE_FLATVAL: return ENC_SYM_TYPE_FLATVAL;
|
||||
}
|
||||
return ENC_SYM_TERROR;
|
||||
}
|
||||
|
@ -1209,26 +1208,6 @@ 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,
|
||||
|
@ -1288,6 +1267,4 @@ const fundamental_fun fundamental_table[] =
|
|||
fundamental_reg_event_handler,
|
||||
fundamental_take,
|
||||
fundamental_drop,
|
||||
fundamental_fv_to_a,
|
||||
fundamental_a_to_fv,
|
||||
};
|
||||
|
|
|
@ -389,7 +389,7 @@ lbm_value handle_flatten_error(int err_val) {
|
|||
|
||||
lbm_value flatten_value( lbm_value v) {
|
||||
|
||||
lbm_value array_cell = lbm_heap_allocate_cell(LBM_TYPE_CONS, ENC_SYM_NIL, ENC_SYM_FLATVAL_TYPE);
|
||||
lbm_value array_cell = lbm_heap_allocate_cell(LBM_TYPE_CONS, ENC_SYM_NIL, ENC_SYM_ARRAY_TYPE);
|
||||
if (lbm_type_of(array_cell) == LBM_TYPE_SYMBOL) {
|
||||
lbm_set_car_and_cdr(array_cell, ENC_SYM_NIL, ENC_SYM_NIL);
|
||||
return ENC_SYM_MERROR;
|
||||
|
@ -424,7 +424,7 @@ lbm_value flatten_value( lbm_value v) {
|
|||
array->data = (lbm_uint*)fv.buf;
|
||||
array->size = fv.buf_size;
|
||||
lbm_set_car(array_cell, (lbm_uint)array);
|
||||
array_cell = lbm_set_ptr_type(array_cell, LBM_TYPE_FLATVAL);
|
||||
array_cell = lbm_set_ptr_type(array_cell, LBM_TYPE_ARRAY);
|
||||
return array_cell;
|
||||
} else {
|
||||
flatten_set_result(FLATTEN_VALUE_ERROR_FATAL);
|
||||
|
|
|
@ -212,11 +212,6 @@ int print_emit_channel(lbm_char_channel_t *chan, lbm_value v) {
|
|||
return print_emit_string(chan, "~CHANNEL~");
|
||||
}
|
||||
|
||||
int print_emit_flatval(lbm_char_channel_t *chan, lbm_value v) {
|
||||
(void) v;
|
||||
return print_emit_string(chan, "~FLATVAL~");
|
||||
}
|
||||
|
||||
int print_emit_array_data(lbm_char_channel_t *chan, lbm_array_header_t *array) {
|
||||
|
||||
int r = print_emit_char(chan, '[');
|
||||
|
@ -402,9 +397,6 @@ int lbm_print_internal(lbm_char_channel_t *chan, lbm_value v) {
|
|||
case LBM_TYPE_CHANNEL:
|
||||
r = print_emit_channel(chan, curr);
|
||||
break;
|
||||
case LBM_TYPE_FLATVAL:
|
||||
r = print_emit_flatval(chan, curr);
|
||||
break;
|
||||
case LBM_TYPE_ARRAY:
|
||||
r = print_emit_array(chan, curr);
|
||||
break;
|
||||
|
|
|
@ -101,7 +101,6 @@ special_sym const special_symbols[] = {
|
|||
{"$channel" , SYM_CHANNEL_TYPE},
|
||||
{"$recovered" , SYM_RECOVERED},
|
||||
{"$custom" , SYM_CUSTOM_TYPE},
|
||||
{"$flatval" , SYM_FLATVAL_TYPE},
|
||||
{"$nonsense" , SYM_NONSENSE},
|
||||
|
||||
// tokenizer symbols with unparsable names
|
||||
|
@ -135,7 +134,6 @@ special_sym const special_symbols[] = {
|
|||
{"type-char" , SYM_TYPE_CHAR},
|
||||
{"type-byte" , SYM_TYPE_BYTE},
|
||||
{"type-channel" , SYM_TYPE_CHANNEL},
|
||||
{"type-flatval" , SYM_TYPE_FLATVAL},
|
||||
|
||||
// Fundamental operations
|
||||
{"+" , SYM_ADD},
|
||||
|
@ -223,8 +221,6 @@ 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