Squashed 'lispBM/lispBM/' changes from 31d4edfd..a5683c69

a5683c69 bug fix related to string literal lengths
53aeb0bf tweak changelog
6a8ef376 added tests
7bbd22e7 updated lbmref and changelog

git-subtree-dir: lispBM/lispBM
git-subtree-split: a5683c692e2f005495db2baee9a90d86798151e9
This commit is contained in:
Benjamin Vedder 2022-11-09 15:48:58 +01:00
parent 84e25a1fcf
commit 54b662c15b
6 changed files with 55 additions and 5 deletions

View File

@ -157,6 +157,12 @@ expression evaluates to `t`.
(eq '(1 (1 2)) '(1 (1 2)))
```
---
### not-eq
`not-eq` implements the negation of eq. In other words, `(not-eq a b c)` evaluates
to the same result as `(not (eq a b c))`.
---
@ -179,6 +185,13 @@ Example of `=` comparison.
```
---
### !=
The `!=` operation implements the negation of `=`. So, `(!= a b)` evaluates
to the same result as `(not (= a b))`.
---
### >

View File

@ -33,6 +33,13 @@ extern "C" {
/*! \page changelog Changelog
Nov 9: Version 0.7.1
- not-eq and != added.
- Corrected behaviour for eval when applied to no argument.
- lbm_memory operations are protected by mutex.
- Fixes to eval-program.
- Added multiple condition conditional function called cond.
Oct 31: Version 0.7.1
- Added optional boolean guards to pattern matches.
- Built in map and reverse.

View File

@ -229,7 +229,7 @@ static char translate_escape_char(char c) {
}
}
int tok_string(lbm_char_channel_t *chan) {
int tok_string(lbm_char_channel_t *chan, unsigned int *string_len) {
unsigned int n = 0;
unsigned int len = 0;
@ -264,6 +264,7 @@ int tok_string(lbm_char_channel_t *chan) {
if (r == CHANNEL_MORE) return TOKENIZER_NEED_MORE;
if (c != '\"') return TOKENIZER_STRING_ERROR;
*string_len = len;
n ++;
return (int)n;
}
@ -604,16 +605,17 @@ lbm_value lbm_get_next_token(lbm_char_channel_t *chan, bool peek) {
return lbm_enc_sym(SYM_TOKENIZER_WAIT);
}
n = tok_string(chan);
unsigned int string_len = 0;
n = tok_string(chan, &string_len);
if (n >= 2) {
if (!peek) lbm_channel_drop(chan, (unsigned int)n);
// TODO: Proper error checking here!
// TODO: Check if anything has to be allocated for the empty string
lbm_heap_allocate_array(&res, (unsigned int)(n-2)+1, LBM_TYPE_CHAR);
lbm_heap_allocate_array(&res, (unsigned int)(string_len+1), LBM_TYPE_CHAR);
lbm_array_header_t *arr = (lbm_array_header_t*)lbm_car(res);
char *data = (char *)arr->data;
memset(data, 0, (unsigned int)((n-2)+1) * sizeof(char));
memcpy(data, sym_str, (unsigned int)(n - 2) * sizeof(char));
memset(data, 0, (string_len+1) * sizeof(char));
memcpy(data, sym_str, string_len * sizeof(char));
return res;
} else if (n == TOKENIZER_NEED_MORE) {
return lbm_enc_sym(SYM_TOKENIZER_WAIT);

View File

@ -0,0 +1,13 @@
(define a 10)
(define b 20)
(define c 30)
(and (eq (not (eq a b c)) (not-eq a b c))
(eq (not (eq a a c)) (not-eq a a c))
(eq (not (eq a a a)) (not-eq a a a))
(eq (not (eq b b c)) (not-eq b b c))
(eq (not (eq b b b)) (not-eq b b b))
(eq (not (eq c b c)) (not-eq c b c))
(eq (not (eq c c c)) (not-eq c c c)))

View File

@ -0,0 +1,11 @@
(define a 10)
(define b 20)
(define c 30)
(and (eq (not (= a b c)) (!= a b c))
(eq (not (= a a c)) (!= a a c))
(eq (not (= a a a)) (!= a a a))
(eq (not (= b b c)) (!= b b c))
(eq (not (= b b b)) (!= b b b))
(eq (not (= c b c)) (!= c b c))
(eq (not (= c c c)) (!= c c c)))

4
tests/test_string_1.lisp Normal file
View File

@ -0,0 +1,4 @@
(and (= (array-size "apa") 4)
(= (array-size "bepa") 5)
(= (array-size "kurt1") 6))