mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python] Malloc the syntax-highlighting uPy heap
This commit is contained in:
committed by
EmilieNumworks
parent
29cacbc44f
commit
6cd18cca89
@@ -5,7 +5,7 @@ extern "C" {
|
||||
#include "py/lexer.h"
|
||||
}
|
||||
#include <python/port/port.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Code {
|
||||
|
||||
@@ -58,6 +58,18 @@ static inline int TokenLength(mp_lexer_t * lex) {
|
||||
}
|
||||
}
|
||||
|
||||
PythonTextArea::ContentView::ContentView(KDText::FontSize fontSize) :
|
||||
TextArea::ContentView(fontSize)
|
||||
{
|
||||
m_pythonHeap = static_cast<char *>(malloc(k_pythonHeapSize));
|
||||
}
|
||||
|
||||
PythonTextArea::ContentView::~ContentView() {
|
||||
if (m_pythonHeap) {
|
||||
free(m_pythonHeap);
|
||||
}
|
||||
}
|
||||
|
||||
void PythonTextArea::ContentView::clearRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, BackgroundColor);
|
||||
}
|
||||
@@ -73,9 +85,20 @@ void PythonTextArea::ContentView::clearRect(KDContext * ctx, KDRect rect) const
|
||||
void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char * text, size_t length, int fromColumn, int toColumn) const {
|
||||
LOG_DRAW("Drawing \"%.*s\"\n", length, text);
|
||||
|
||||
char m_pythonHeap[4096];
|
||||
if (!m_pythonHeap) {
|
||||
drawStringAt(
|
||||
ctx,
|
||||
line,
|
||||
fromColumn,
|
||||
text + fromColumn,
|
||||
min(length - fromColumn, toColumn - fromColumn),
|
||||
KDColorBlack,
|
||||
KDColorWhite
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
MicroPython::init(m_pythonHeap, m_pythonHeap + 4096);
|
||||
MicroPython::init(m_pythonHeap, m_pythonHeap + k_pythonHeapSize);
|
||||
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
|
||||
@@ -15,14 +15,19 @@ public:
|
||||
protected:
|
||||
class ContentView : public TextArea::ContentView {
|
||||
public:
|
||||
ContentView(KDText::FontSize fontSize) : TextArea::ContentView(fontSize) {}
|
||||
ContentView(KDText::FontSize fontSize);
|
||||
~ContentView();
|
||||
void clearRect(KDContext * ctx, KDRect rect) const override;
|
||||
void drawLine(KDContext * ctx, int line, const char * text, size_t length, int fromColumn, int toColumn) const override;
|
||||
KDRect dirtyRectFromCursorPosition(size_t index, bool lineBreak) const override;
|
||||
private:
|
||||
static constexpr size_t k_pythonHeapSize = 4096;
|
||||
char * m_pythonHeap;
|
||||
};
|
||||
private:
|
||||
const ContentView * nonEditableContentView() const override { return &m_contentView; }
|
||||
ContentView m_contentView;
|
||||
char * m_pythonHeap;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user