Skip to content

Commit

Permalink
Merge tag '1.9' into debian
Browse files Browse the repository at this point in the history
Snek version 1.9
  • Loading branch information
keith-packard committed Dec 24, 2022
2 parents 0c52ae3 + 79076ee commit b5aaaa8
Show file tree
Hide file tree
Showing 45 changed files with 378 additions and 134 deletions.
58 changes: 34 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ described below.

Here's some places that have seen recent work

* [Mu](https://codewith.mu/) version 1.2.0 has Snek support built in
now. Mu is an IDE designed for new Python users that offers a more
polished alternative to the simple Snek IDE provide with snek.

* Fixed a couple of `input` bugs compared with Python—input
returned None instead of the empty string when nothing was
typed before the return and input printed an arbitrary list of
parameters rather than just the first one. Thanks to Justin Miller
and Mikael Bonnier for reporting these issues.

* Store the most recently printed repl value in `_`. Thanks to Justin
Miller for this suggestion.

* For the Windows native port, add the input module and increase the
heap size to 256kB.

* Update the docs to format correctly with asciidoctor-pdf version 2.3

* [LilyPad Arduino 328](https://www.sparkfun.com/products/13342)
port. This is a round ATmega328p-based board designed for wearable
projects. This board runs at 8MHz, which can't run the serial port
Expand All @@ -121,28 +139,6 @@ Here's some places that have seen recent work
* Fixed incorrect precedence between bitwise and (&) and bitwise xor
(^) operators.

* Lots of improvements to the EV3 port making it more like
other Snek devices.

* [Narrow 1284](https://www.crowdsupply.com/pandauino/narrow) port.
This is a small board with the ATmega1284 SoC which is like the
ATmega328 but with much more Flash and RAM which provides way more
room for Snek to run.

* [Seeed Grove Beginner Kit](https://www.seeedstudio.com/Grove-Beginner-Kit-for-Arduino-p-4549.html)
port. This is another ATmega328p based board but with a range of
devices provided in the kit. Snek supports the LED, Buzzer, Light,
Sound, OLED Display, Button, Rotary Potentiometer and 3-axis
Accelerometer.

* [Seeeduino XIAO](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)
port. This is a SAMD21-based device on a tiny board with a USB-C
connector.

* [Arduino Nano Every](https://store.arduino.cc/usa/nano-every) port.
This uses the ATmega4809 which has 6kB of RAM, providing much more
space for Snek programs.

## Build and Run!

If you want to build Snek yourself, you'll need to have the build
Expand All @@ -157,17 +153,31 @@ To build Snek you need these dependencies:
* [avr-libc](https://www.nongnu.org/avr-libc/)
* [gcc-arm-none-eabi](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
* [gcc-riscv64-unknown-elf](https://github.com/sifive/freedom-tools/)
* [gcc-arm-linux-gnueabi](https://developer.arm.com/downloads/-/gnu-a)
* [picolibc](https://keithp.com/picolibc/)
* [python3](https://www.python.org/)
* [pyserial](https://github.com/pyserial/)
* [python curses](https://docs.python.org/3/library/curses.html)
* [readline](https://www.gnu.org/software/readline/)
* [asciidoctor](https://asciidoctor.org/)
* [asciidoctor-pdf](https://docs.asciidoctor.org/pdf-converter/latest/)

On Debian unstable, you can get everything from the main archive:

# apt install lola gcc-avr avr-libc python3-serial \
# apt install lola gcc-avr avr-libc python3-serial gawk \
gcc-arm-none-eabi gcc-riscv64-unknown-elf libreadline-dev \
picolibc-arm-none-eabi picolibc-riscv64-unknown-elf
picolibc-arm-none-eabi picolibc-riscv64-unknown-elf \
asciidoctor ruby-asciidoctor-pdf gcc-arm-linux-gnueabi

Debian stable has too old a version of lola, so if you're using that,
you'll need to install lola from the git repository above.

The snek build scripts use the GNU awk implementation, `gawk`,
including a GNU extension, `strtonum`, which is not available in other
awk implementations. It's not critical to compiling the code as it's
only used to print out ROM usage for AVR targets so you can tell how
much space is still available, but if you don't have gawk, you will
get build failures.

### Building and install

Expand Down
2 changes: 1 addition & 1 deletion chips/avr/ao-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#define ao_arch_reboot() /* XXX */

#define ao_arch_nop() asm("nop")
#define ao_arch_nop() __asm__("nop")

#define ao_arch_interrupt(n) /* nothing */

Expand Down
2 changes: 1 addition & 1 deletion chips/avr/snek-avr.defs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ OPT=-Os -frename-registers -funsigned-char -fno-jump-tables -mcall-prologues
SNEK_CFLAGS = $(SNEK_MOST_WARNINGS) $(SNEK_BASE_CFLAGS)

AO_CFLAGS=\
-std=gnu99 $(OPT) -g
-std=c99 $(OPT) -g

AVR_CFLAGS=-DF_CPU=$(AVR_CLOCK) -mmcu=atmega32u4 -g $(SNEK_CFLAGS) -Waddr-space-convert \
-I. -I$(SNEK_PORT) -I$(SNEK_AVR) -I$(SNEK_AO) -I$(SNEK_ROOT) $(AO_CFLAGS)
Expand Down
21 changes: 21 additions & 0 deletions chips/qemu/snek-qemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,24 @@ main(int argc, char **argv)
fflush(stdout);
exit(ret);
}

#ifdef _SNEK_NEED_STRFROMF
int
strfromf(char *__restrict str, size_t n,
const char *__restrict format, float fp)
{
return snprintf(str, n, format, __printf_float(fp));
}
#endif


#ifdef _SNEK_NEED_STRTOF
float
strtof(const char *restrict nptr, char **restrict endptr)
{
float f;
(void) sscanf(nptr, "%f", &f);
(void) endptr;
return f;
}
#endif
12 changes: 10 additions & 2 deletions chips/qemu/snek-qemu.defs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ PICOLIBC_CFLAGS= \

OPT?=-Os

CFLAGS=$(ARCH_CFLAGS) --oslib=semihost --crt0=semihost \
-std=gnu99 $(OPT) -g \
# Add --crt0=semihost for picolibc >= 1.6
CRT0_FLAG=$(shell \
(echo '#include "picolibc.h"'; \
echo '_PICOLIBC__ _PICOLIBC_MINOR__ __PICOLIBC_PATCHLEVEL__') | \
arm-none-eabi-gcc -E - --specs=picolibc.specs | \
grep '^[0-9]' | \
awk '{ if ($$1 > 1 || ($$1 == 1 && $$2 >= 6)) print "--crt0=semihost";}')

CFLAGS=$(ARCH_CFLAGS) --oslib=semihost $(CRT0_FLAG) \
-std=c18 $(OPT) -g \
-I. -I$(SNEK_QEMU) -I$(SNEK_ROOT) $(PICOLIBC_CFLAGS) $(SNEK_CFLAGS)

LDFLAGS=$(SNEK_LDFLAGS) $(CFLAGS) -n
Expand Down
12 changes: 12 additions & 0 deletions chips/qemu/snek-qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@
extern int snek_qemu_getc(void);

#define abort() exit(1)

#if _PICOLIBC__ == 1 && (_PICOLIBC_MINOR__ < 6 || __PICOLIBC_PATCHLEVEL__ < 1)
#define _SNEK_NEED_STRFROMF
int
strfromf(char *__restrict str, size_t n,
const char *__restrict format, float fp);
#endif

#if _PICOLIBC__ == 1 && (_PICOLIBC_MINOR__ < 7 || __PICOLIBC_PATCHLEVEL__ < 5)
#define _SNEK_NEED_STRTOF
#endif

10 changes: 5 additions & 5 deletions chips/samd21/ao-arch-funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,25 @@ typedef uint32_t ao_arch_irq_t;
static inline uint32_t
ao_arch_irqsave(void) {
uint32_t primask;
asm("mrs %0,primask" : "=&r" (primask));
__asm__("mrs %0,primask" : "=&r" (primask));
ao_arch_block_interrupts();
return primask;
}

static inline void
ao_arch_irqrestore(uint32_t primask) {
asm("msr primask,%0" : : "r" (primask));
__asm__("msr primask,%0" : : "r" (primask));
}

static inline void
ao_arch_memory_barrier(void) {
asm volatile("" ::: "memory");
__asm__ volatile("" ::: "memory");
}

#define ao_arch_wait_interrupt() do { \
asm("\twfi\n"); \
__asm__("\twfi\n"); \
ao_arch_release_interrupts(); \
asm(".global ao_idle_loc\nao_idle_loc:"); \
__asm__(".global ao_idle_loc\nao_idle_loc:"); \
ao_arch_block_interrupts(); \
} while (0)

Expand Down
6 changes: 3 additions & 3 deletions chips/samd21/ao-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
(samd21_scb.aircr = ((SAMD21_SCB_AIRCR_VECTKEY_KEY << SAMD21_SCB_AIRCR_VECTKEY) | \
(1 << SAMD21_SCB_AIRCR_SYSRESETREQ)))

#define ao_arch_nop() asm("nop")
#define ao_arch_nop() __asm__("nop")
#define ao_arch_interrupt(n) /* nothing */
#define ao_arch_block_interrupts() asm("cpsid i")
#define ao_arch_release_interrupts() asm("cpsie i")
#define ao_arch_block_interrupts() __asm__("cpsid i")
#define ao_arch_release_interrupts() __asm__("cpsie i")

/*
* ao_timer.c
Expand Down
12 changes: 12 additions & 0 deletions chips/samd21/ao-snek.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ ao_snek_apa102_write(void *gpio_d, uint8_t pin_d,
int npixel,
struct snek_neopixel *pixels);


#if _PICOLIBC__ == 1 && (_PICOLIBC_MINOR__ < 6 || __PICOLIBC_PATCHLEVEL__ < 1)
#define _SNEK_NEED_STRFROMF
int
strfromf(char *__restrict str, size_t n,
const char *__restrict format, float fp);
#endif

#if _PICOLIBC__ == 1 && (_PICOLIBC_MINOR__ < 7 || __PICOLIBC_PATCHLEVEL__ < 5)
#define _SNEK_NEED_STRTOF
#endif

#endif /* _AO_SNEK_H_ */
21 changes: 21 additions & 0 deletions chips/samd21/ao-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ STDIO_ALIAS(stderr);
#else
FILE *const __iob[3] = { &__stdio, &__stdio, &__stdio };
#endif

#ifdef _SNEK_NEED_STRFROMF
int
strfromf(char *__restrict str, size_t n,
const char *__restrict format, float fp)
{
return snprintf(str, n, format, __printf_float(fp));
}
#endif


#ifdef _SNEK_NEED_STRTOF
float
strtof(const char *restrict nptr, char **restrict endptr)
{
float f;
(void) sscanf(nptr, "%f", &f);
(void) endptr;
return f;
}
#endif
2 changes: 1 addition & 1 deletion chips/samd21/snek-samd21.defs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ PICOLIBC_CFLAGS= \
OPT?=-Os

AO_CFLAGS=\
-std=gnu99 $(OPT) -g
-std=c18 $(OPT) -g

SAMD21_CFLAGS=-mlittle-endian -mcpu=cortex-m0 -mthumb\
-I$(SNEK_SAMD21) -I$(SNEK_AO) -I$(SNEK_ROOT) -I. $(AO_CFLAGS) $(PICOLIBC_CFLAGS)
Expand Down
3 changes: 3 additions & 0 deletions chips/samd21/snek-samd21.ld
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ SECTIONS {
} >ram AT>ram :tls :ram
PROVIDE(__tbss_size = SIZEOF(.tbss));
PROVIDE(__tls_size = __tls_end - __tls_base);
PROVIDE( __tls_align = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss)) );
PROVIDE( __arm32_tls_tcb_offset = MAX(8, __tls_align) );
PROVIDE( __arm64_tls_tcb_offset = MAX(16, __tls_align) );

/*
* The linker special cases .tbss segments which are
Expand Down
4 changes: 2 additions & 2 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ BOOK_FILES=snek-book.pdf snek-cover.pdf snek-book-book.pdf snek-cover-book.pdf

book: $(BOOK_FILES)

LETTER_ATTRIBUTES=--attribute='pdf-style=snek'
BOOK_ATTRIBUTES=--attribute='pdf-style=snek-book'
LETTER_ATTRIBUTES=--attribute='pdf-theme=snek'
BOOK_ATTRIBUTES=--attribute='pdf-theme=snek-book'
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)"

.adoc.html:
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ THEME_FILE=snek-theme.yml

all: $(HTML_FILES) $(PDF_FILES)

LETTER_ATTRIBUTES=--attribute='pdf-style=snek'
LETTER_ATTRIBUTES=--attribute='pdf-theme=snek'
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)"

.adoc.html:
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-1/lesson-1-snekboard.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Keith Packard <keithp@keithp.com>; Michael Ward <michaelward@sprintmail.com>
:stylesheet: snek.css
:linkcss:
:toc:
:pdf-stylesdir: .
:pdf-themesdir: .
:pdf-fontsdir: ../../fonts
:source-highlighter: coderay
:media: prepress
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ THEME_FILE=snek-theme.yml

all: $(HTML_FILES) $(PDF_FILES) $(CSS_FILES) snek.svg snek.css

LETTER_ATTRIBUTES=--attribute='pdf-style=snek'
LETTER_ATTRIBUTES=--attribute='pdf-theme=snek'
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)"

.adoc.html:
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-2/lesson-2-line-bug.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Keith Packard <keithp@keithp.com>; Michael Ward <michaelward@sprintmail.com>
:stylesheet: snek.css
:linkcss:
:toc:
:pdf-stylesdir: .
:pdf-themesdir: .
:pdf-fontsdir: ../../fonts
:source-highlighter: coderay
:media: prepress
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ INC_FILES=steps.adoc

all: $(HTML_FILES) $(PDF_FILES)

LETTER_ATTRIBUTES=--attribute='pdf-style=snek'
LETTER_ATTRIBUTES=--attribute='pdf-theme=snek'
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)"

.adoc.html:
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-3/lesson-3-bumper-car.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Keith Packard <keithp@keithp.com>; Michael Ward <michaelward@sprintmail.com>
:stylesheet: snek.css
:linkcss:
:toc:
:pdf-stylesdir: ../..
:pdf-themesdir: ../..
:pdf-fontsdir: ../../fonts
:source-highlighter: coderay
:media: prepress
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ INC_FILES=steps.adoc

all: $(HTML_FILES) $(PDF_FILES)

LETTER_ATTRIBUTES=--attribute='pdf-style=snek'
LETTER_ATTRIBUTES=--attribute='pdf-theme=snek'
ATTRIBUTES=--attribute="revdate=$(SNEK_DATE)" --attribute="version=$(SNEK_VERSION)"

.adoc.html:
Expand Down
2 changes: 1 addition & 1 deletion doc/lessons/lesson-4/lesson-4-washing-machine.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Keith Packard <keithp@keithp.com>; Michael Ward <michaelward@sprintmail.com>
:stylesheet: snek.css
:linkcss:
:toc:
:pdf-stylesdir: ../..
:pdf-themesdir: ../..
:pdf-fontsdir: ../../fonts
:source-highlighter: coderay
:media: prepress
Expand Down

0 comments on commit b5aaaa8

Please sign in to comment.