Skip to content

Commit

Permalink
Merge branch 'master' into debian
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-packard committed May 22, 2020
2 parents 4d9c521 + 5be0ef2 commit 6c28cc8
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/snek.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
docker run --rm \
--mount type=bind,source=`pwd`/artifacts,destination=/artifacts \
snek \
make DESTDIR=/artifacts PREFIX=/opt/snek check install
make DESTDIR=/artifacts PREFIX=/opt/snek SNEK_RISCV_TEST=1 check install
- name: 'Upload results'
uses: actions/upload-artifact@v2
Expand Down
34 changes: 2 additions & 32 deletions Makefile
Expand Up @@ -36,35 +36,9 @@ FORCE:

check: all
+cd test && make $@
+black --check --exclude 'fail-syntax-.*\.py' .
+black --check --exclude 'fail-syntax-.*\.py|.*/hosts/.*.py' .

SHAREFILES = \
snek.defs \
$(SNEK_SRC) \
$(SNEK_EXT_SRC) \
$(SNEK_RAW_INC) \
$(SNEK_EXT_INC) \
$(SNEK_BUILTINS) \
$(SNEK_EXT_BUILTINS) \
$(SNEK_ROOT)/snek-gram.ll \
$(SNEK_ROOT)/snek-builtin.py

IMAGEFILES = \
snek.svg

DOCFILES = \
$(IMAGEFILES)

PKGFILES = \
snek.pc

install: $(SHAREFILES) $(PKGFILES) $(DOCFILES)
install -d $(DESTDIR)$(SHAREDIR)
for i in $(SHAREFILES); do install --mode=644 "$$i" $(DESTDIR)$(SHAREDIR) || exit 1; done
install -d $(DESTDIR)$(PKGCONFIG)
for i in $(PKGFILES); do install --mode=644 "$$i" $(DESTDIR)$(PKGCONFIG) || exit 1; done
install -d $(DESTDIR)$(DOCDIR)
for i in $(DOCFILES); do install --mode=644 "$$i" $(DESTDIR)$(DOCDIR) || exit 1; done
install:
+for dir in $(SUBDIRS); do (cd $$dir && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@) || exit 1; done
+for snek in $(SNEKS); do (cd `dirname $$snek` && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@) || exit 1; done

Expand All @@ -76,16 +50,12 @@ otheros: $(SNEKS)
+cd doc && make
+for otheros in $(SNEK_OTHEROS_DIR); do (cd "$$otheros" && make); done

snek.pc: snek.pc.in
$(SNEK_SED) $^ > $@

snek-mu.py:
find . -name '*.builtin' -print0 | xargs -0 python3 ./snek-builtin.py --mu -o $@

docker:
docker build -t phsilva/snek .

clean:
rm -f snek.pc
+for dir in $(SUBDIRS); do (cd $$dir && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@); done
+for snek in $(SNEKS); do (cd `dirname $$snek` && make PREFIX=$(PREFIX) DESTDIR=$(DESTDIR) $@); done
3 changes: 2 additions & 1 deletion chips/avr/snek-avr.defs
Expand Up @@ -56,7 +56,8 @@ CFLAGS = $(AVR_CFLAGS) $(SNEK_CFLAGS)

LDSCRIPT=$(SNEK_AVR)/snek-avr51.x

LDFLAGS=-Wl,-uvfprintf -lprintf_flt -lm \
LDFLAGS=$(SNEK_LDFLAGS) \
-Wl,-uvfprintf -lprintf_flt -lm \
-Wl,--defsym -Wl,__TEXT_REGION_LENGTH__=0x8000 \
-Wl,--defsym -Wl,__DATA_REGION_LENGTH__=0x880 \
-Wl,--defsym -Wl,__EEPROM_REGION_LENGTH__=0x400 \
Expand Down
2 changes: 1 addition & 1 deletion chips/qemu/snek-qemu.defs
Expand Up @@ -40,7 +40,7 @@ CFLAGS=$(ARCH_CFLAGS) --oslib=semihost \
-std=gnu99 $(OPT) -g \
-I. -I$(SNEK_QEMU) -I$(SNEK_ROOT) $(PICOLIBC_CFLAGS) $(SNEK_CFLAGS)

LDFLAGS=$(CFLAGS) -n
LDFLAGS=$(SNEK_LDFLAGS) $(CFLAGS) -n

LIBS=-lm

Expand Down
2 changes: 1 addition & 1 deletion chips/samd21/snek-samd21.defs
Expand Up @@ -81,7 +81,7 @@ CFLAGS = $(SAMD21_CFLAGS) $(SNEK_CFLAGS)

LDSCRIPT=$(SNEK_SAMD21)/snek-samd21.ld

LDFLAGS=$(CFLAGS) -Wl,-T$(SNEK_SAMD21)/registers.ld -T$(LDSCRIPT) -n
LDFLAGS=$(SNEK_LDFLAGS) $(CFLAGS) -Wl,-T$(SNEK_SAMD21)/registers.ld -T$(LDSCRIPT) -n

LIBS=-lm

Expand Down
2 changes: 1 addition & 1 deletion hosts/macosx/Makefile
Expand Up @@ -64,7 +64,7 @@ snek-bits: $(SNEK_FILES) macosx
cp -p $(SNEK_SCRIPTS) macosx/snek.app/Contents/MacOS/
endif

$(MACOSX_DIST): $(MACOSX_FILES) macosx
$(MACOSX_DIST): $(MACOSX_FILES) macosx snek-bits
rm -f $@
cp -a $(MACOSX_DOCS) macosx
cp -a $(MACOSX_INSTALL) macosx
Expand Down
3 changes: 2 additions & 1 deletion hosts/macosx/build-mac
Expand Up @@ -28,12 +28,13 @@ esac

build="$1"
builddir=`echo $build | sed 's/^[^:]*://'`
buildhost=`echo $build | sed 's/:.*$//'`
echo builddir "$builddir"

target="$2"

rsync -Ravz --delete `git ls-files` "$build"

ssh imac-remote "cd '$builddir'/ports/posix && make"
ssh $buildhost "cd '$builddir'/ports/posix && make"

rsync -avz "$build"/ports/posix/snek "$curdir"/"$target"
3 changes: 2 additions & 1 deletion ports/duemilanove/Makefile
Expand Up @@ -44,7 +44,8 @@ CC=avr-gcc
OPT=-Os -frename-registers -funsigned-char -fno-jump-tables -mcall-prologues

CFLAGS=$(OPT) -DF_CPU=16000000UL -mmcu=atmega328p -I. -I$(SNEK_LOCAL_VPATH) -g $(SNEK_CFLAGS) -Waddr-space-convert
LDFLAGS=-Wl,-uvfprintf -lprintf_flt -lm \
LDFLAGS=$(SNEK_LDFLAGS) \
-Wl,-uvfprintf -lprintf_flt -lm \
-Wl,--defsym -Wl,__TEXT_REGION_LENGTH__=0x7e00 \
-Wl,--defsym -Wl,__DATA_REGION_LENGTH__=0x7a0 \
-Wl,--defsym -Wl,__EEPROM_REGION_LENGTH__=0x400 \
Expand Down
4 changes: 2 additions & 2 deletions ports/duemilanove/snek-duemilanove-install.1
Expand Up @@ -23,8 +23,8 @@ Duemilanove board.
.SH OPTIONS
.TP
\-isp <ISP model>
Specifies the programmer to use, common options are 'optiboot',
'usbtiny', and 'avrisp2'. The default is 'optiboot'.
Specifies the programmer to use, common options are optiboot,
usbtiny, and avrisp2. The default is optiboot.
.TP
\-hex <snek.hex>
Specifies the hex file to load to the board. The default is the
Expand Down
1 change: 1 addition & 0 deletions ports/esp32/.gitignore
@@ -1,3 +1,4 @@
build
sdkconfig
sdkconfig.old
*.bin
7 changes: 6 additions & 1 deletion ports/esp32/Makefile
Expand Up @@ -12,7 +12,8 @@
# General Public License for more details.
#

include ../../snek.defs
SNEK_ROOT = ../..
include ../../snek-install.defs

ESP32_IDF ?= ./esp32-idf

Expand All @@ -37,3 +38,7 @@ load:

connect:
minicom -D /dev/ttyUSB1 -b 115200

install: $(TARGET)
install -d $(DESTDIR)$(SHAREDIR)
install -m 0644 $(TARGET) $(DESTDIR)$(SHAREDIR)
2 changes: 1 addition & 1 deletion ports/hifive1revb/Makefile
Expand Up @@ -63,7 +63,7 @@ HIFIVE1REVB_CFLAGS=-march=rv32imac -mabi=ilp32 \

CFLAGS = $(HIFIVE1REVB_CFLAGS) $(SNEK_CFLAGS) $(AO_CFLAGS)

LDFLAGS=$(CFLAGS) -n -Wl,--gc-sections
LDFLAGS=$(SNEK_LDFLAGS) $(CFLAGS) -n

LIBS=-lm

Expand Down
3 changes: 2 additions & 1 deletion ports/mega/Makefile
Expand Up @@ -48,7 +48,8 @@ HEX=$(BASE).hex
MAP=$(BASE).map
CC=avr-gcc
CFLAGS=-Os -DF_CPU=16000000UL -mmcu=atmega2560 -I. -I$(SNEK_LOCAL_VPATH) -g -fno-jump-tables $(SNEK_CFLAGS) -mcall-prologues -Waddr-space-convert
LDFLAGS=-Wl,-uvfprintf -lprintf_flt -lm \
LDFLAGS=$(SNEK_LDFLAGS) \
-Wl,-uvfprintf -lprintf_flt -lm \
-Wl,--defsym -Wl,__TEXT_REGION_LENGTH__=0x3e000 \
-Wl,--defsym -Wl,__DATA_REGION_LENGTH__=0x1e00 \
-Wl,--defsym -Wl,__EEPROM_REGION_LENGTH__=0x1000 \
Expand Down
42 changes: 19 additions & 23 deletions ports/posix/snek-main.c
Expand Up @@ -21,15 +21,15 @@ FILE *snek_posix_input;

static const struct option options[] = {
{ .name = "version", .has_arg = 0, .val = 'v' },
{ .name = "file", .has_arg = 1, .val = 'f' },
{ .name = "interactive", .has_arg = 0, .val = 'i' },
{ .name = "help", .has_arg = 0, .val = '?' },
{ .name = NULL, .has_arg = 0, .val = 0 },
};

static void
usage (char *program, int val)
{
fprintf(stderr, "usage: %s [--version] [--help] [--file <file.py>] <program.py>\n", program);
fprintf(stderr, "usage: %s [--version] [--help] [--interactive] <program.py>\n", program);
exit(val);
}

Expand Down Expand Up @@ -71,16 +71,17 @@ int
main (int argc, char **argv)
{
int c;
char *file = NULL;
bool do_interactive = true;
bool interactive_flag = false;

while ((c = getopt_long(argc, argv, "v?f:", options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "v?i", options, NULL)) != -1) {
switch (c) {
case 'v':
printf("%s version %s\n", argv[0], SNEK_VERSION);
exit(0);
break;
case 'f':
file = optarg;
case 'i':
interactive_flag = true;
break;
case '?':
usage(argv[0], 0);
Expand All @@ -93,15 +94,7 @@ main (int argc, char **argv)

snek_init();

if (file) {
snek_file = file;
snek_posix_input = fopen(snek_file, "r");
if (!snek_posix_input) {
perror(snek_file);
exit(1);
}
snek_parse();
}
bool ret = true;

if (argv[optind]) {
snek_file = argv[optind];
Expand All @@ -110,18 +103,21 @@ main (int argc, char **argv)
perror(snek_file);
exit(1);
}
} else {
if (snek_parse() != snek_parse_success)
ret = false;
fclose(snek_posix_input);
do_interactive = interactive_flag;
}

if (do_interactive) {
printf("Welcome to Snek version %s\n", SNEK_VERSION);
snek_file = "<stdin>";
snek_posix_input = stdin;
snek_interactive = true;
printf("Welcome to Snek version %s\n", SNEK_VERSION);
if (snek_parse() != snek_parse_success)
ret = false;
printf("\n");
}

bool ret = snek_parse() == snek_parse_success;

if (snek_posix_input == stdin)
printf("\n");
else
fclose(snek_posix_input);
return ret ? 0 : 1;
}
21 changes: 18 additions & 3 deletions ports/posix/snek.1
Expand Up @@ -15,14 +15,29 @@
.SH NAME
snek \- Snek Programming Language
.SH SYNOPSIS
.B "snek" {program.py}
.B "snek" [--version|-v] [--help|-?] [--interactive|-i] [program.py]
.SH DESCRIPTION
.I snek
is a small Python-derivative suitable for embedded computers. This
host version is largely designed to help test the Snek system and
applications on larger machines
.SH COMMAND LINE OPTIONS
.TP
\--version or \-v
Reports the version number to stdout and then exits.
.TP
\--help or \-?
Prints usage information to stdout and then exits.
.TP
\--interactive or \-i
When a program is specified on the command line, enter interactive
mode after executing that program.
.SH USAGE
If you specify a program file on the command line, snek will load and
execute this instead of reading from the command line.
When a program is specified on the command line, snek runs it. Then,
if the --interactive flag is passed, it enters interactive
mode. Otherwise, it exits.
.P
When no program is specified on the command line, snek enters
interactive mode.
.SH AUTHOR
Keith Packard
2 changes: 1 addition & 1 deletion snek-list.c
Expand Up @@ -280,7 +280,7 @@ snek_list_imm(snek_offset_t size, snek_list_type_t type)
s -= 2;
snek_poly_t key = snek_stack_pick(s+1);
snek_poly_t value = snek_stack_pick(s);
snek_poly_t *ref = _snek_list_ref(list, key, false, true);
snek_poly_t *ref = _snek_list_ref(list, key, true, true);
if (ref)
*ref = value;
}
Expand Down
4 changes: 3 additions & 1 deletion snek-poly.c
Expand Up @@ -84,11 +84,13 @@ snek_poly_cmp(snek_poly_t a, snek_poly_t b, bool is)
int8_t tdiff = atype - btype;
if (tdiff)
return tdiff;
int sdiff;
switch (atype) {
case snek_float:
return (b.f < a.f) - (a.f < b.f);
case snek_string:
return strcmp(snek_poly_to_string(a), snek_poly_to_string(b));
sdiff = strcmp(snek_poly_to_string(a), snek_poly_to_string(b));
return (sdiff > 0) - (sdiff < 0);
case snek_list:
if (!is)
return snek_list_cmp(snek_poly_to_list(a), snek_poly_to_list(b));
Expand Down
16 changes: 12 additions & 4 deletions snek.defs
Expand Up @@ -7,11 +7,13 @@ vpath %.ll $(SNEK_LOCAL_VPATH):$(SNEK_ROOT)
vpath %.py $(SNEK_LOCAL_VPATH):$(SNEK_ROOT)
vpath %.builtin $(SNEK_LOCAL_VPATH):$(SNEK_ROOT)

SNEK_VERSION = 1.4
SNEK_DATE = 2020-05-13
SNEK_VERSION = 1.4.1
SNEK_DATE = 2020-05-22

SNEK_VERSION_DASH = $(shell echo $(SNEK_VERSION) | sed 's/\./-/g')

SNEK_CLANG = $(shell if $(CC) --version | grep -q -i llvm; then echo yes; else echo no; fi)

SNEK_PORTS = $(SNEK_ROOT)/ports
SNEK_HOSTS = $(SNEK_ROOT)/hosts
SNEK_DOC = $(SNEK_ROOT)/doc
Expand Down Expand Up @@ -79,19 +81,25 @@ SNEK_MOST_WARNINGS = \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Warray-bounds=2 \
-Wshadow

ifeq ($(SNEK_CLANG),yes)
SNEK_MOST_WARNINGS += -Warray-bounds
else
SNEK_MOST_WARNINGS += -Warray-bounds=2
endif

SNEK_WARNINGS = \
$(SNEK_MOST_WARNINGS) \
-Wimplicit-fallthrough

SNEK_BASE_CFLAGS = \
-Wl,--gc-sections \
-D_DEFAULT_SOURCE \
-I$(SNEK_ROOT) $(SNEK_LOCAL_CFLAGS) \
-DSNEK_VERSION='"$(SNEK_VERSION)"'

SNEK_LDFLAGS = -Wl,--gc-sections

SNEK_CFLAGS ?= $(SNEK_WARNINGS) $(SNEK_BASE_CFLAGS)

SNEK_SED = sed \
Expand Down
6 changes: 0 additions & 6 deletions snek.pc.in

This file was deleted.

7 changes: 6 additions & 1 deletion test/Makefile
Expand Up @@ -18,10 +18,14 @@ include $(SNEK_ROOT)/snek.defs

PYTHON3?=python3
SNEK_NATIVE?=$(SNEK_PORTS)/posix/snek
ifdef SNEK_RISCV_TEST
SNEK_RISCV?=$(SNEK_PORTS)/qemu-riscv/snek-riscv
else
SNEK_RISCV=
endif
SNEK_ARM?=$(SNEK_PORTS)/qemu-arm/snek-arm

LANGS=python3 $(SNEK_NATIVE) $(SNEK_ARM)
LANGS=python3 $(SNEK_NATIVE) $(SNEK_ARM) $(SNEK_RISCV)

SUCCESS_TESTS = \
pass-andor.py \
Expand Down Expand Up @@ -72,6 +76,7 @@ FAIL_TESTS = \
fail-interpolate-missing.py \
fail-interpolate-extra.py \
fail-interpolate-badformat.py \
fail-dictionary-mutable.py \
$(SYNTAX_TESTS)

check:
Expand Down

0 comments on commit 6c28cc8

Please sign in to comment.