starting lisp core

This commit is contained in:
Kyle Isom 2023-10-01 16:36:22 -07:00
parent 25c76c67ce
commit 21ac50c94a
7 changed files with 147 additions and 52 deletions

39
stage2/include/lisp.h Normal file
View File

@ -0,0 +1,39 @@
#pragma once
#include <cstdint>
#define SYMBOL_TABLE_SIZE 2048
typedef char * symbol_t;
#define TYPE_SYMBOL 1
#define TYPE_NUMBER 2
#define TYPE_STRING 3
#define TYPE_FLOAT 4
#define TYPE_LIST 5
#define symbolp(x) (x->type == TYPE_SYMBOL)
#define numberp(x) (x->type == TYPE_NUMBER)
#define stringp(x) (x->type == TYPE_STRING)
#define floatp(x) (x->type == TYPE_FLOAT)
#define listp(x) (x->type == TYPE_LIST)
typedef struct cell {
uint8_t type;
union {
struct {
cell *head;
cell *tail;
};
struct {
union {
symbol_t sym;
int num;
char *str;
float fnum;
};
};
};
} cell_t;

10
stage2/include/memory.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <cstddef>
// memory.h contains the memory management code for the system.
// right now, it uses the stdlib malloc/free directly.
//
// TODO(kyle): switch to arena memory.
void *sys_malloc(size_t);
void sys_free(void *);

View File

@ -0,0 +1,8 @@
#pragma once
namespace neopxl {
void start();
bool blink(bool);
} // namespace neopxl

5
stage2/src/lisp.cc Normal file
View File

@ -0,0 +1,5 @@
#include "lisp.h"
static char SymbolTable[SYMBOL_TABLE_SIZE];

View File

@ -1,9 +1,9 @@
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h> #include <Adafruit_ILI9341.h>
#include <Fonts/FreeSans12pt7b.h> #include <Fonts/FreeSans12pt7b.h>
#include "colors.h" #include "colors.h"
#include "neopixel.h"
#define TFT_CS 9 #define TFT_CS 9
#define TFT_DC 10 #define TFT_DC 10
@ -12,20 +12,13 @@
Adafruit_ILI9341 tft(TFT_CS, TFT_DC); Adafruit_ILI9341 tft(TFT_CS, TFT_DC);
Adafruit_NeoPixel pixels(1, 11, NEO_GRB + NEO_KHZ800);
auto cOff = pixels.Color(0, 0, 0);
auto cGreen = pixels.Color(0, 255, 0);
auto cRed = pixels.Color(255, 0, 0);
auto cBlue = pixels.Color(0, 0, 255);
void void
setup() setup()
{ {
Serial.begin(115200); Serial.begin(115200);
pixels.begin();
pixels.clear(); neopxl::start();
pixels.show();
tft.begin(); tft.begin();
tft.setRotation(1); tft.setRotation(1);
@ -42,52 +35,11 @@ setup()
} }
bool
blink(bool on)
{
if (on) {
for (int i = 10; i < 255; i++) {
auto c = pixels.Color(0, (uint8_t)i, 0);
pixels.setPixelColor(0, c);
pixels.show();
delay(4);
}
on = false;
} else {
for (int i = 255; i > 9; i--) {
auto c = pixels.Color(0, (uint8_t)i, 0);
pixels.setPixelColor(0, c);
pixels.show();
delay(4);
}
on = true;
}
return on;
}
void
pixelOn(uint32_t c)
{
pixels.setPixelColor(0, c);
pixels.show();
}
void
pixelOff()
{
pixels.setPixelColor(0, cOff);
pixels.show();
}
void void
loop() loop()
{ {
static bool on = false; static bool on = false;
on = blink(on); on = neopxl::blink(on);
delayMicroseconds(100); delayMicroseconds(100);
} }

17
stage2/src/memory.cc Normal file
View File

@ -0,0 +1,17 @@
#include "memory.h"
#include <cstddef>
#include <cstdlib>
void *
sys_malloc(size_t size)
{
return std::malloc(size);
}
void
sys_free(void *ptr)
{
return std::free(ptr);
}

64
stage2/src/neopixel.cc Normal file
View File

@ -0,0 +1,64 @@
#include "neopixel.h"
#include <Adafruit_NeoPixel.h>
namespace neopxl {
Adafruit_NeoPixel pixels(1, 11, NEO_GRB + NEO_KHZ800);
auto cOff = pixels.Color(0, 0, 0);
auto cGreen = pixels.Color(0, 255, 0);
auto cRed = pixels.Color(255, 0, 0);
auto cBlue = pixels.Color(0, 0, 255);
static void
pixelOn(uint32_t c)
{
pixels.setPixelColor(0, c);
pixels.show();
}
static void
pixelOff()
{
pixels.setPixelColor(0, cOff);
pixels.show();
}
void
start()
{
pixels.begin();
pixels.clear();
pixels.show();
}
bool
blink(bool on)
{
if (on) {
for (int i = 10; i < 255; i++) {
auto c = pixels.Color(0, (uint8_t)i, 0);
pixels.setPixelColor(0, c);
pixels.show();
delay(4);
}
on = false;
} else {
for (int i = 255; i > 9; i--) {
auto c = pixels.Color(0, (uint8_t)i, 0);
pixels.setPixelColor(0, c);
pixels.show();
delay(4);
}
on = true;
}
return on;
}
}; // namespace neopxl