make symbols and add nil

This commit is contained in:
Kyle Isom 2023-10-01 18:00:25 -07:00
parent c30e469df9
commit 39b4e049b7
6 changed files with 130 additions and 27 deletions

View File

@ -3,7 +3,7 @@
#define SYMBOL_TABLE_SIZE 2048 #define SYMBOL_TABLE_SIZE 2048
typedef char * symbol_t; typedef unsigned int symbol_t;
#define TYPE_SYMBOL 1 #define TYPE_SYMBOL 1
#define TYPE_NUMBER 2 #define TYPE_NUMBER 2
@ -18,7 +18,6 @@ typedef char * symbol_t;
#define floatp(x) (x->type == TYPE_FLOAT) #define floatp(x) (x->type == TYPE_FLOAT)
#define listp(x) (x->type == TYPE_LIST) #define listp(x) (x->type == TYPE_LIST)
typedef struct cell { typedef struct cell {
uint8_t type; uint8_t type;
union { union {
@ -35,5 +34,14 @@ typedef struct cell {
}; };
}; };
}; };
} cell_t; };
symbol_t intern_symbol(const char *s);
symbol_t make_symbol(const char *s);
static auto NIL = make_symbol("nil");
cell head(cell x);
cell tail(cell x);

View File

@ -3,6 +3,7 @@
namespace neopxl { namespace neopxl {
void start(); void start();
bool blink(bool); void blink();
void stop();
} // namespace neopxl } // namespace neopxl

View File

@ -24,6 +24,7 @@ lib_deps =
adafruit/RTClib @ ^1.12.4 adafruit/RTClib @ ^1.12.4
arduino-libraries/SD @ ^1.2.4 arduino-libraries/SD @ ^1.2.4
arturo182/BBQ10Keyboard arturo182/BBQ10Keyboard
kisom/kasl @ ^1.0.1
SPI SPI
Wire Wire

View File

@ -1,5 +1,80 @@
#include "lisp.h" #include "lisp.h"
#include "memory.h"
#include "neopixel.h"
#include <cstdlib>
#include <cstring>
#define MAX_SYMBOL_LEN 24
static char SymbolTable[SYMBOL_TABLE_SIZE]; static char SymbolTable[SYMBOL_TABLE_SIZE];
static cell CellTable[SYMBOL_TABLE_SIZE]; // TODO(kyle): consider adding
// cell-table specific param.
static void
Abort()
{
neopxl::stop();
abort();
}
symbol_t
intern_symbol(const char *s)
{
char *cursor = SymbolTable;
if (!(std::strncmp(s, cursor+1, MAX_SYMBOL_LEN) == 0)) {
cursor += cursor[0];
}
// cursor has reached the end of the symbol table, which means
// we are out of room.
if (cursor >= SymbolTable+SYMBOL_TABLE_SIZE) {
Abort();
}
// cursor has reached the end of the symbol list, which means it
// should be added to the symbol table.
if (cursor[0] == 0) {
cursor[0] = static_cast<uint8_t>(strnlen(s, MAX_SYMBOL_LEN));
memcpy(cursor+1, s, static_cast<size_t>(cursor[0]));
cursor[cursor[0]+1] = 0;
}
// return the symbol pointed to by the cursor.
return (symbol_t)(cursor);
}
static cell *
FindEmptyCell()
{
auto cursor = CellTable;
while (cursor < (CellTable + SYMBOL_TABLE_SIZE)) {
if (cursor->type == 0) {
return cursor;
}
}
return nullptr;
}
symbol_t
make_symbol(const char *s)
{
cell *cell = FindEmptyCell();
if (cell == nullptr) {
Abort();
}
cell->type = TYPE_SYMBOL;
cell->sym = intern_symbol(s);
return cell->sym;
}

View File

@ -2,6 +2,8 @@
#include <Adafruit_ILI9341.h> #include <Adafruit_ILI9341.h>
#include <Fonts/FreeSans12pt7b.h> #include <Fonts/FreeSans12pt7b.h>
#include <kasl/scheduling.h>
#include "display.h" #include "display.h"
#include "neopixel.h" #include "neopixel.h"
@ -13,7 +15,7 @@ setup()
Serial.begin(115200); Serial.begin(115200);
neopxl::start(); neopxl::start();
tft::Setup; tft::Setup();
tft::SetCursor(0, 8); tft::SetCursor(0, 8);
@ -21,6 +23,9 @@ setup()
tft::Println(" \\ (square 3)"); tft::Println(" \\ (square 3)");
tft::Println(" 9"); tft::Println(" 9");
tft::Println(" \\ "); tft::Println(" \\ ");
kasl::scheduleThread(neopxl::blink);
kasl::startScheduler();
} }
@ -29,6 +34,6 @@ loop()
{ {
static bool on = false; static bool on = false;
on = neopxl::blink(on); kasl::runScheduler();
delayMicroseconds(100); delayMicroseconds(100);
} }

View File

@ -35,9 +35,15 @@ start()
} }
bool static bool run = true;
blink(bool on)
void
blink()
{ {
static bool on = false;
while (run) {
if (on) { if (on) {
for (int i = 10; i < 255; i++) { for (int i = 10; i < 255; i++) {
auto c = pixels.Color(0, (uint8_t)i, 0); auto c = pixels.Color(0, (uint8_t)i, 0);
@ -45,7 +51,6 @@ blink(bool on)
pixels.show(); pixels.show();
delay(4); delay(4);
} }
on = false;
} else { } else {
for (int i = 255; i > 9; i--) { for (int i = 255; i > 9; i--) {
auto c = pixels.Color(0, (uint8_t)i, 0); auto c = pixels.Color(0, (uint8_t)i, 0);
@ -53,12 +58,20 @@ blink(bool on)
pixels.show(); pixels.show();
delay(4); delay(4);
} }
on = true;
} }
return on; on = !on;
}
} }
void
stop()
{
run = false;
delay(980);
pixels.setPixelColor(0, cRed);
pixels.show();
}
}; // namespace neopxl }; // namespace neopxl