Windows users historically have run PicoLisp using cygwin or miniPicoLisp. PicoLisp does not run well under windows because forking is unstable under cygwin.

An alternative recently appeared, flinux.

Foreign LINUX is a dynamic binary translator and a Linux system call interface emulator for the Windows platform. It is capable of running unmodified Linux binaries on Windows without any drivers or modifications to the system. This provides another way of running Linux applications under Windows in constrast to Cygwin and other tools.

PicoLisp can run under flinux in two ways:
  1. statically compiled without a linux environment
  2. dynamically compiled (default) with a linux environment
To understand the differences, we need to understand a little more about how flinux works. flinux reads the binary and translates the instructions on-the-fly. System calls are intercepted and executed in the flinux translation layer. For example, the linux syscall connect() is implemented using windows sockets.

Dynamically linked binaries require the linux libraries installed as those calls are not compiled into the binary and instead are invoked through dlopen("libc...").

Static vs Dynamic

Static is smaller, but has a few more steps, and currently cannot resolve hostnames due to how gethostbyname gets linked Dynamic requires the arch distro from flinux and is roughly 600mb uncompressed.

Installation - static

The following steps roughly outline what's necessary to build PicoLisp on linux for running on flinux. PicoLisp can also on flinux using the arch linux distribution.

Windows

  1. Download http://software-lab.de/picoLisp.tgz and uncompress
  2. Download flinux binary (or compile from github which has some patches to the official version

Linux

PicoLisp can be built from the latest sources, however we need to replace net.c with an older version that supports IPv4.

wget http://software-lab.de/picoLisp.tgz
wget http://software-lab.de/picoLisp-3.0.8.tgz
tar -zxvf picoLisp-3.0.8.tgz picoLisp/src/net.c

cd src


patch the Makefile

# added ht.c and ext.c
picoFiles = main.c gc.c apply.c flow.c sym.c subr.c big.c io.c net.c tab.c ht.c ext.c

CC = gcc
# CCLD is the cc (compiler frontend) to use for the link step.
CCLD = gcc

CFLAGS = -c -O2 -pipe 
        -falign-functions=32 -fomit-frame-pointer -fno-strict-aliasing 
        -W -Wimplicit -Wreturn-type -Wunused -Wformat 
        -Wuninitialized -Wstrict-prototypes 
        -D_GNU_SOURCE  -D_FILE_OFFSET_BITS=64


# added static
ifeq ($(shell uname), Linux)
        OS = Linux
        CFLAGS += -m32
        PICOLISP-FLAGS = -m32 -rdynamic
        LIB-FLAGS = -lm -ldl -lcrypt --static
        DYNAMIC-LIB-FLAGS = -m32 -shared -export-dynamic
        LCRYPT = -lcrypt
        STRIP = strip


patch tab.c

top of file

typedef struct symInit {fun code; char *name;} symInit;

extern any Pack (any);
extern any Out (any);
extern any In (any);
extern any Fmt (any);
extern any Prin (any);
extern any Read (any);
extern any Snx (any);

static symInit Symbols[] = {
   //add externals
   {Pack, "ht:Pack"},
   {In, "ht:In"},
   {Out, "ht:Out"},
   {Fmt, "ht:Fmt"},
   {Prin, "ht:Prin"},
   {Read, "ht:Read"},
   {Snx, "ext:Snx"},
   //begin core file
   {doAbs, "abs"},
   {doAccept, "accept"},
   {doAdd, "+"},
   {doAdr, "adr"},
   ...

}


(optional) patch net.c

tcpAccept seems to have trouble occasionally getting caught in a loop.
    static any tcpAccept(int sd) {
       int i, f, sd2;
       struct sockaddr_in addr;

       //add shutdown to make sure socket is closed
       shutdown(sd, SHUT_WR);
       f = nonblocking(sd);
       //change loop counter to 10 to indicate 1 second instead of 20 seconds
       i = 10; do
    }


make and copy the picoLisp binary down to windows

Launching

The minimal db example can be run as:
C:\dev\picoLisp>flinux bin/picoLisp lib.l @ext.l min.l -main -go -wait


Installation - dynamic

Windows

  1. Download flinux arch enviroment
  2. Download flinux binary (or compile from github which has some patches to the official version
  3. , replace flinux binary from step #1 with this one
  4. Launch run_bash.cmd and download picoLisp as normal, patch net.c, compile

http://www.picolisp.com/wiki/?flinuxpicolisp

11mar16    joebo