From 9b7b947b015d733586a7de6159d533cbdb01ac18 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Tue, 7 Jan 2014 09:49:42 -0800 Subject: Updated teensy to use common code from stm directory. Updated mconfigport.h to enable GC --- stm/Makefile | 3 ++- stm/lexerfatfs.c | 46 ++++++++++++++++++++++++++++++++++++++ stm/lexerfatfs.h | 8 +++++++ stm/lexerstm.c | 68 -------------------------------------------------------- stm/lexerstm.h | 16 ------------- stm/lexerstr.c | 28 +++++++++++++++++++++++ stm/lexerstr.h | 8 +++++++ stm/main.c | 3 ++- 8 files changed, 94 insertions(+), 86 deletions(-) create mode 100644 stm/lexerfatfs.c create mode 100644 stm/lexerfatfs.h delete mode 100644 stm/lexerstm.c delete mode 100644 stm/lexerstm.h create mode 100644 stm/lexerstr.c create mode 100644 stm/lexerstr.h (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index fecd52527..478441e04 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -30,7 +30,8 @@ SRC_C = \ string0.c \ malloc0.c \ systick.c \ - lexerstm.c \ + lexerstr.c \ + lexerfatfs.c \ led.c \ lcd.c \ servo.c \ diff --git a/stm/lexerfatfs.c b/stm/lexerfatfs.c new file mode 100644 index 000000000..5dcaca160 --- /dev/null +++ b/stm/lexerfatfs.c @@ -0,0 +1,46 @@ +#include +#include + +#include "ff.h" + +#include "misc.h" +#include "lexer.h" +#include "lexerfatfs.h" + +unichar file_buf_next_char(mp_lexer_file_buf_t *fb) { + if (fb->pos >= fb->len) { + if (fb->len < sizeof(fb->buf)) { + return MP_LEXER_CHAR_EOF; + } else { + UINT n; + f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); + if (n == 0) { + return MP_LEXER_CHAR_EOF; + } + fb->len = n; + fb->pos = 0; + } + } + return fb->buf[fb->pos++]; +} + +void file_buf_close(mp_lexer_file_buf_t *fb) { + f_close(&fb->fp); +} + +mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb) { + FRESULT res = f_open(&fb->fp, filename, FA_READ); + if (res != FR_OK) { + return NULL; + } + UINT n; + f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); + fb->len = n; + fb->pos = 0; + return mp_lexer_new(filename, fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close); +} + +mp_lexer_t *mp_import_open_file(qstr mod_name) { + printf("import not implemented\n"); + return NULL; +} diff --git a/stm/lexerfatfs.h b/stm/lexerfatfs.h new file mode 100644 index 000000000..2b41ed136 --- /dev/null +++ b/stm/lexerfatfs.h @@ -0,0 +1,8 @@ +typedef struct _py_lexer_file_buf_t { + FIL fp; + char buf[20]; + uint16_t len; + uint16_t pos; +} mp_lexer_file_buf_t; + +mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb); diff --git a/stm/lexerstm.c b/stm/lexerstm.c deleted file mode 100644 index 661dfb016..000000000 --- a/stm/lexerstm.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include "ff.h" - -#include "misc.h" -#include "lexer.h" -#include "lexerstm.h" - -unichar str_buf_next_char(mp_lexer_str_buf_t *sb) { - if (sb->src_cur < sb->src_end) { - return *sb->src_cur++; - } else { - return MP_LEXER_CHAR_EOF; - } -} - -void str_buf_free(mp_lexer_str_buf_t *sb) { - if (sb->free) { - m_del(char, (char*)sb->src_beg, 0 /* don't know allocated size of src */); - } -} - -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) { - sb->free = free_str; - sb->src_beg = str; - sb->src_cur = str; - sb->src_end = str + len; - return mp_lexer_new(src_name, sb, (mp_lexer_stream_next_char_t)str_buf_next_char, (mp_lexer_stream_close_t)str_buf_free); -} - -unichar file_buf_next_char(mp_lexer_file_buf_t *fb) { - if (fb->pos >= fb->len) { - if (fb->len < sizeof(fb->buf)) { - return MP_LEXER_CHAR_EOF; - } else { - UINT n; - f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); - if (n == 0) { - return MP_LEXER_CHAR_EOF; - } - fb->len = n; - fb->pos = 0; - } - } - return fb->buf[fb->pos++]; -} - -void file_buf_close(mp_lexer_file_buf_t *fb) { - f_close(&fb->fp); -} - -mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb) { - FRESULT res = f_open(&fb->fp, filename, FA_READ); - if (res != FR_OK) { - return NULL; - } - UINT n; - f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); - fb->len = n; - fb->pos = 0; - return mp_lexer_new(filename, fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close); -} - -mp_lexer_t *mp_import_open_file(qstr mod_name) { - printf("import not implemented\n"); - return NULL; -} diff --git a/stm/lexerstm.h b/stm/lexerstm.h deleted file mode 100644 index 7e090898a..000000000 --- a/stm/lexerstm.h +++ /dev/null @@ -1,16 +0,0 @@ -typedef struct _py_lexer_str_buf_t { - bool free; // free src_beg when done - const char *src_beg; // beginning of source - const char *src_cur; // current location in source - const char *src_end; // end (exclusive) of source -} mp_lexer_str_buf_t; - -typedef struct _py_lexer_file_buf_t { - FIL fp; - char buf[20]; - uint16_t len; - uint16_t pos; -} mp_lexer_file_buf_t; - -mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb); -mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb); diff --git a/stm/lexerstr.c b/stm/lexerstr.c new file mode 100644 index 000000000..cc6be1d1e --- /dev/null +++ b/stm/lexerstr.c @@ -0,0 +1,28 @@ +#include +#include + +#include "misc.h" +#include "lexer.h" +#include "lexerstr.h" + +unichar str_buf_next_char(mp_lexer_str_buf_t *sb) { + if (sb->src_cur < sb->src_end) { + return *sb->src_cur++; + } else { + return MP_LEXER_CHAR_EOF; + } +} + +void str_buf_free(mp_lexer_str_buf_t *sb) { + if (sb->free) { + m_del(char, (char*)sb->src_beg, 0 /* don't know allocated size of src */); + } +} + +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb) { + sb->free = free_str; + sb->src_beg = str; + sb->src_cur = str; + sb->src_end = str + len; + return mp_lexer_new(src_name, sb, (mp_lexer_stream_next_char_t)str_buf_next_char, (mp_lexer_stream_close_t)str_buf_free); +} diff --git a/stm/lexerstr.h b/stm/lexerstr.h new file mode 100644 index 000000000..961a70ada --- /dev/null +++ b/stm/lexerstr.h @@ -0,0 +1,8 @@ +typedef struct _py_lexer_str_buf_t { + bool free; // free src_beg when done + const char *src_beg; // beginning of source + const char *src_cur; // current location in source + const char *src_end; // end (exclusive) of source +} mp_lexer_str_buf_t; + +mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str, mp_lexer_str_buf_t *sb); diff --git a/stm/main.c b/stm/main.c index a038c89b7..a2f3bc7f0 100644 --- a/stm/main.c +++ b/stm/main.c @@ -19,7 +19,8 @@ #include "nlr.h" #include "misc.h" #include "lexer.h" -#include "lexerstm.h" +#include "lexerstr.h" +#include "lexerfatfs.h" #include "parse.h" #include "obj.h" #include "compile.h" -- cgit v1.2.3