diff -urN spl-1.0pre5.orig/examples/demo_gpio.spl spl-1.0pre5/examples/demo_gpio.spl --- spl-1.0pre5.orig/examples/demo_gpio.spl 1970-01-01 01:00:00.000000000 +0100 +++ spl-1.0pre5/examples/demo_gpio.spl 2008-11-14 11:11:39.000000000 +0100 @@ -0,0 +1,13 @@ + +load "gpio"; +load "termio"; + +var state = 1; +while (1) { + for (var i=0; i<3; i++) { + gpio_set(i, state); + termio_sleep(1); + } + state = !state; +} + diff -urN spl-1.0pre5.orig/examples/dmeo-inotify.spl spl-1.0pre5/examples/dmeo-inotify.spl --- spl-1.0pre5.orig/examples/dmeo-inotify.spl 1970-01-01 01:00:00.000000000 +0100 +++ spl-1.0pre5/examples/dmeo-inotify.spl 2008-11-10 12:27:37.000000000 +0100 @@ -0,0 +1,17 @@ + +// load "aessd_if"; +// aessd_if('\$PROPERTIES_TAB.ipaddress = "1.2.3.8";'); + +load "inotify"; + +var in = inotify_init(); +inotify_add_watch(in, "/sys/devices/w1_bus_master1/w1_master_slaves", IN_ALL_EVENTS: 1); + +while (1) { + var ev = inotify_wait(in); + debug "----"; + foreach k (ev) + debug "$k: ${ev[k]}"; +} + + diff -urN spl-1.0pre5.orig/GNUmakefile spl-1.0pre5/GNUmakefile --- spl-1.0pre5.orig/GNUmakefile 2008-07-25 07:24:37.000000000 +0200 +++ spl-1.0pre5/GNUmakefile 2008-11-21 13:38:20.000000000 +0100 @@ -39,11 +39,11 @@ INSTALL = install endif -CC = gcc +CC = arm-linux-gcc CXX = g++ YACC = bison -y -HOST_CC = $(CC) +HOST_CC = gcc ifeq ($(CC),$(HOST_CC)) HOST_SPLRUN = splrun @@ -55,8 +55,8 @@ CFLAGS += -Wshadow LDFLAGS = -L$(shell pwd) $(EXTRA_LDFLAGS) -EXTRA_CFLAGS := $(shell sh syscheck.sh extra_cflags) -EXTRA_LDFLAGS := $(shell sh syscheck.sh extra_ldflags) +EXTRA_CFLAGS := +EXTRA_LDFLAGS := # Let the user know where we get the configuration from # @@ -67,29 +67,25 @@ # Autodetecting available libraries # Set this to '1' or '0' to overwrite the test results. # -ENABLE_REGEX_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p pcre) -ENABLE_EXPAT_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p expat) -ENABLE_SQLITE_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p sqlite) -ENABLE_MYSQL_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p mysql) -ENABLE_POSTGRES_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p postgres) -ENABLE_LIBXML2_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libxml2) -ENABLE_LIBXSLT_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libxslt) -ENABLE_LIBSDL_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libsdl) -ENABLE_LIBCURL_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libcurl) -ifeq ($(BUILDING_FOR_BSD),1) - ENABLE_LIBUUID_SUPPORT := 1 -else - ENABLE_LIBUUID_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libuuid) -endif -ENABLE_LIBFANN_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libfann) -ENABLE_WSCONS_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p wscons) -ENABLE_EPFB_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p epfb) -ENABLE_OPENGL_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p opengl) -ENABLE_SMOKE_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p libsmoke) -ENABLE_READLINE_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p readline) -ENABLE_GETTEXT_LIBC_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p gettext_libc) -ENABLE_GETTEXT_INTL_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p gettext_intl) -ENABLE_PTHREAD_SUPPORT := $(shell CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh syscheck.sh -p pthread) +ENABLE_REGEX_SUPPORT := 1 +ENABLE_EXPAT_SUPPORT := 0 +ENABLE_SQLITE_SUPPORT := 1 +ENABLE_MYSQL_SUPPORT := 0 +ENABLE_POSTGRES_SUPPORT := 0 +ENABLE_LIBXML2_SUPPORT := 1 +ENABLE_LIBXSLT_SUPPORT := 1 +ENABLE_LIBSDL_SUPPORT := 0 +ENABLE_LIBCURL_SUPPORT := 0 +ENABLE_LIBUUID_SUPPORT := 0 +ENABLE_LIBFANN_SUPPORT := 0 +ENABLE_WSCONS_SUPPORT := 0 +ENABLE_EPFB_SUPPORT := 0 +ENABLE_OPENGL_SUPPORT := 0 +ENABLE_SMOKE_SUPPORT := 0 +ENABLE_READLINE_SUPPORT := 0 +ENABLE_GETTEXT_LIBC_SUPPORT := 0 +ENABLE_GETTEXT_INTL_SUPPORT := 0 +ENABLE_PTHREAD_SUPPORT := 1 # Set this to '1' if you want to profile the performance # of the SPL compiler and runtime. This is not for profiling @@ -100,7 +96,7 @@ # Set this to '1' if you want to build an unoptimized SPL # library with debug symbols. # -BUILD_WITH_DEBUG = 1 +BUILD_WITH_DEBUG = 0 # Set this to '1' if you are doing SPL core development # diff -urN spl-1.0pre5.orig/spl_modules/mod_gpio.c spl-1.0pre5/spl_modules/mod_gpio.c --- spl-1.0pre5.orig/spl_modules/mod_gpio.c 1970-01-01 01:00:00.000000000 +0100 +++ spl-1.0pre5/spl_modules/mod_gpio.c 2008-11-14 11:04:31.000000000 +0100 @@ -0,0 +1,170 @@ +/* + * SPL - The SPL Programming Language + * Copyright (C) 2004, 2005 Clifford Wolf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * mod_gpio.c: Simple gpio IO library + */ + +/** + * This module provides a simple API for reading and writing gpio + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../modules/gpio/gpio.h" + +#include "spl.h" +#include "compat.h" + +extern void SPL_ABI(spl_mod_gpio_init)(struct spl_vm *vm, struct spl_module *mod, int restore); +extern void SPL_ABI(spl_mod_gpio_done)(struct spl_vm *vm, struct spl_module *mod); + +static void do_exception(struct spl_task *task, char *type, char *filename, char *errmsg) +{ + spl_clib_exception(task, "GpioEx", + "type", SPL_NEW_STRING_DUP(type), + "filename", SPL_NEW_STRING_DUP(filename), + "errmsg", SPL_NEW_STRING_DUP(strerror(errno)), + "description", SPL_NEW_SPL_STRING(spl_string_printf(0, 0, 0, + "Can't %s file '%s': %s", type, filename, + errmsg ? errmsg : strerror(errno))), + NULL); +} + +/** + * This function writes the specified pin. + * + * A [[GpioEx]] exception is thrown on I/O errors. + */ +// builtin gpio_set(gpio, state) +static struct spl_node *handler_gpio_set(struct spl_task *task, void *data UNUSED) +{ + int gpio = spl_clib_get_int(task); + int state = spl_clib_get_int(task); + char filename[100]; + + snprintf(filename, 100, "/dev/gpio/%d", gpio); + + int fd = open(filename, O_RDWR); + if (fd < 0) { + do_exception(task, "open", filename, NULL); + return NULL; + } + + if (ioctl(fd, GPIO_CONFIG_AS_OUT) < 0) { + do_exception(task, "gpio_config_as_out", filename, NULL); + close(fd); + return NULL; + } + + if (ioctl(fd, GPIO_WRITE_PIN_VAL, &state) < 0) { + do_exception(task, "gpio_write_pin_val", filename, NULL); + close(fd); + return NULL; + } + + close(fd); + return NULL; +} + +/** + * This function reads the specified pin and returns its state. + * + * A [[GpioEx]] exception is thrown on I/O errors. + */ +// builtin gpio_get(gpio) +static struct spl_node *handler_gpio_get(struct spl_task *task, void *data UNUSED) +{ + int gpio = spl_clib_get_int(task); + int state; + char filename[100]; + + snprintf(filename, 100, "/dev/gpio/%d", gpio); + + int fd = open(filename, O_RDWR); + if (fd < 0) { + do_exception(task, "open", filename, NULL); + return NULL; + } + + if (ioctl(fd, GPIO_CONFIG_AS_INP) < 0) { + do_exception(task, "gpio_config_as_out", filename, NULL); + close(fd); + return NULL; + } + + if (ioctl(fd, GPIO_READ_PIN_VAL, &state) < 0) { + do_exception(task, "gpio_write_pin_val", filename, NULL); + close(fd); + return NULL; + } + + close(fd); + return SPL_NEW_INT(state); +} + +/** + * An instance of this object is thrown on file I/O errors. + */ +// object GpioEx + +/** + * Specifies the type of operation which failed: + * "write", "read" or "delete" + */ +// var type; + +/** + * The filename of which the operation should have been performed. + */ +// var filename; + +/** + * The error message returned by the operating system + */ +// var errmsg; + +/** + * A full error description including the information from + * [[.type]], [[.filename]] and [[.errmsg]]. + */ +// var description; + +void SPL_ABI(spl_mod_gpio_init)(struct spl_vm *vm, struct spl_module *mod, int restore) +{ + if (!restore) + spl_eval(vm, 0, strdup(mod->name), "object GpioEx { }"); + + spl_clib_reg(vm, "gpio_set", handler_gpio_set, 0); + spl_clib_reg(vm, "gpio_get", handler_gpio_get, 0); +} + +void SPL_ABI(spl_mod_gpio_done)(struct spl_vm *vm UNUSED, struct spl_module *mod UNUSED) +{ + return; +} + diff -urN spl-1.0pre5.orig/spl_modules/mod_inotify.c spl-1.0pre5/spl_modules/mod_inotify.c --- spl-1.0pre5.orig/spl_modules/mod_inotify.c 1970-01-01 01:00:00.000000000 +0100 +++ spl-1.0pre5/spl_modules/mod_inotify.c 2008-11-06 14:27:03.000000000 +0100 @@ -0,0 +1,309 @@ +/* + * SPL - The SPL Programming Language + * Copyright (C) 2004, 2005 Clifford Wolf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * mod_inotify.c: An SPL module for inotify + */ + +/** + * A module for inotify + * + * This module provides a mechanism for registering with the Linux Kernel + * inotify API and wait for changes in the filesystem. + * + * See 'man inotify' for details. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "spl.h" +#include "compat.h" + +#define inotify_init() syscall(__NR_inotify_init) +#define inotify_add_watch(...) syscall(__NR_inotify_add_watch, __VA_ARGS__) +#define inotify_rm_watch(...) syscall(__NR_inotify_rm_watch, __VA_ARGS__) + +extern void SPL_ABI(spl_mod_inotify_init)(struct spl_vm *vm, struct spl_module *mod, int restore); +extern void SPL_ABI(spl_mod_inotify_done)(struct spl_vm *vm, struct spl_module *mod); + +struct inotify_hnode_data { + int fd; + char buffer[4096]; + int buflen; + int bufoff; +}; + +static void handler_inotify_node(struct spl_task *task, struct spl_vm *vm UNUSED, + struct spl_node *node, struct spl_hnode_args *args, void *data UNUSED) +{ + if (args->action == SPL_HNODE_ACTION_PUT) + { + struct inotify_hnode_data *hnd = node->hnode_data; + if (hnd) { + close(hnd->fd); + free(hnd); + } + return; + } +} + +/** + * This function creates a new inotify handle and returns it. + * + * Usage example: + * var in = inotify_init(); + * + * See 'man inotify_init' for details. + */ +// builtin inotify_init() +static struct spl_node *handler_inotify_init(struct spl_task *task, void *data UNUSED) +{ + struct spl_node *n = SPL_NEW_STRING_DUP("INOTIFY DATA"); + struct inotify_hnode_data *hnd = calloc(1, sizeof(struct inotify_hnode_data)); + + n->hnode_name = strdup("inotify"); + n->hnode_data = hnd; + + hnd->fd = inotify_init(); + + return n; +} + +/** + * This function adds a new watch to an inotify handler and returns the new + * watch descriptor. + * + * Usage example: + * var wd = inotify_add_watch(in, "/etc", IN_ALL_EVENTS: 1, IN_MOVE: 0); + * + * See 'man inotify_add_watch' for details. + */ +// builtin inotify_add_watch(in, pathname, %mask); +static struct spl_node *handler_inotify_add_watch(struct spl_task *task, void *data UNUSED) +{ + struct spl_node *hargs = spl_cleanup(task, spl_clib_get_hargs(task)); + struct spl_node *n = spl_cleanup(task, spl_clib_get_node(task)); + const char *pathname = spl_clib_get_string(task); + + if (!n->hnode_name || strcmp(n->hnode_name, "inotify")) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("Called inotify_add_watch() with something not an inotify handler"), + NULL); + return 0; + } + + uint32_t mask = 0; + struct inotify_hnode_data *hnd = n->hnode_data; + +#define X(_m) \ + do { \ + struct spl_node *hn = spl_lookup(task, hargs, #_m, SPL_LOOKUP_TEST); \ + if (hn) { \ + if (spl_get_int(hn)) \ + mask |= _m; \ + else \ + mask &= ~_m; \ + } \ + } while (0) + + X(IN_ACCESS); + X(IN_ALL_EVENTS); + X(IN_ATTRIB); + X(IN_CLOSE); + X(IN_CLOSE_NOWRITE); + X(IN_CLOSE_WRITE); + X(IN_CREATE); + X(IN_DELETE); + X(IN_DELETE_SELF); + X(IN_DONT_FOLLOW); + X(IN_IGNORED); + X(IN_ISDIR); + X(IN_MASK_ADD); + X(IN_MODIFY); + X(IN_MOVE); + X(IN_MOVED_FROM); + X(IN_MOVED_TO); + X(IN_MOVE_SELF); + X(IN_ONESHOT); + X(IN_ONLYDIR); + X(IN_OPEN); + X(IN_Q_OVERFLOW); + X(IN_UNMOUNT); +#undef X + + int wd = inotify_add_watch(hnd->fd, pathname, mask); + + if (wd < 0) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("inotify_add_watch() on '%s' with mask 0x%08x: %s", + pathname, mask, strerror(errno)), + NULL); + return 0; + } + + return SPL_NEW_INT(wd); +} + +/** + * This function removes watch from an inotify handler. + * + * Usage example: + * inotify_rm_watch(in, wd); + * + * See 'man inotify_rm_watch' for details. + */ +// builtin inotify_rm_watch(in, wd); +static struct spl_node *handler_inotify_rm_watch(struct spl_task *task, void *data UNUSED) +{ + struct spl_node *n = spl_cleanup(task, spl_clib_get_node(task)); + int wd = spl_clib_get_int(task); + + if (!n->hnode_name || strcmp(n->hnode_name, "inotify")) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("Called inotify_rm_watch() with something not an inotify handler"), + NULL); + return 0; + } + + struct inotify_hnode_data *hnd = n->hnode_data; + + if (inotify_rm_watch(hnd->fd, wd) < 0) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("inotify_rm_watch(): %s", strerror(errno)), + NULL); + return 0; + } + + return 0; +} + +/** + * This function waits for an inotify event. + * + * Usage example: + * var ev = inotify_wait(in); + * if (ev.IN_MOVE) + * debug("File moved: ${ev.name}"); + * + * See 'man inotify' for details. + */ +// builtin inotify_wait(in); +static struct spl_node *handler_inotify_wait(struct spl_task *task, void *data UNUSED) +{ + struct spl_node *n = spl_cleanup(task, spl_clib_get_node(task)); + + if (!n->hnode_name || strcmp(n->hnode_name, "inotify")) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("Called inotify_wait() with something not an inotify handler"), + NULL); + return 0; + } + + struct inotify_hnode_data *hnd = n->hnode_data; + + while (hnd->bufoff == hnd->buflen) + { + hnd->bufoff = 0; + if ((hnd->buflen = read(hnd->fd, hnd->buffer, sizeof(hnd->buffer))) <= 0) { + spl_clib_exception(task, "InotifyEx", "description", + SPL_NEW_PRINTF("inotify_wait read(): %s", strerror(errno)), + NULL); + hnd->buflen = 0; + return 0; + } + } + + struct inotify_event *ev = (struct inotify_event *)(hnd->buffer + hnd->bufoff); + hnd->bufoff += sizeof(struct inotify_event) + ev->len; + + struct spl_node *ret = spl_get(0); + spl_create(task, ret, "wd", SPL_NEW_INT(ev->wd), SPL_CREATE_LOCAL); + spl_create(task, ret, "mask", SPL_NEW_INT(ev->mask), SPL_CREATE_LOCAL); + spl_create(task, ret, "cookie", SPL_NEW_INT(ev->cookie), SPL_CREATE_LOCAL); + spl_create(task, ret, "name", SPL_NEW_STRING(my_strndup(ev->name, ev->len)), SPL_CREATE_LOCAL); + +#define X(_m) \ + spl_create(task, ret, #_m, SPL_NEW_INT(ev->mask & _m ? 1 : 0), SPL_CREATE_LOCAL) + + X(IN_ACCESS); + X(IN_ALL_EVENTS); + X(IN_ATTRIB); + X(IN_CLOSE); + X(IN_CLOSE_NOWRITE); + X(IN_CLOSE_WRITE); + X(IN_CREATE); + X(IN_DELETE); + X(IN_DELETE_SELF); + X(IN_DONT_FOLLOW); + X(IN_IGNORED); + X(IN_ISDIR); + X(IN_MASK_ADD); + X(IN_MODIFY); + X(IN_MOVE); + X(IN_MOVED_FROM); + X(IN_MOVED_TO); + X(IN_MOVE_SELF); + X(IN_ONESHOT); + X(IN_ONLYDIR); + X(IN_OPEN); + X(IN_Q_OVERFLOW); + X(IN_UNMOUNT); +#undef X + + return ret; +} + +/** + * An instance of this object is thrown on errors. + */ +//object InotifyEx + +/** + * A description text describing the error. + */ +// var description; + +void SPL_ABI(spl_mod_inotify_init)(struct spl_vm *vm, struct spl_module *mod, int restore) +{ + if (!restore) { + spl_eval(vm, 0, strdup(mod->name), "object InotifyEx { }"); + } + + spl_clib_reg(vm, "inotify_init", handler_inotify_init, 0); + spl_clib_reg(vm, "inotify_add_watch", handler_inotify_add_watch, 0); + spl_clib_reg(vm, "inotify_rm_watch", handler_inotify_rm_watch, 0); + spl_clib_reg(vm, "inotify_wait", handler_inotify_wait, 0); + + spl_hnode_reg(vm, "inotify", handler_inotify_node, 0); +} + +void SPL_ABI(spl_mod_inotify_done)(struct spl_vm *vm UNUSED, struct spl_module *mod UNUSED) +{ + return; +} + diff -urN spl-1.0pre5.orig/util.c spl-1.0pre5/util.c --- spl-1.0pre5.orig/util.c 2005-10-28 20:50:53.000000000 +0200 +++ spl-1.0pre5/util.c 2008-11-11 12:18:48.000000000 +0100 @@ -180,10 +180,13 @@ for (int i=0, rc; i