haskell/*.o
lua/lib
lua/linenoise.so
+nim/nimcache
+.lein
+.m2
+.ivy2
+.sbt
local print_readably="${2}"
if [[ "${s:0:1}" = "${__keyw}" ]]; then
r=":${s:1}"
+ elif [[ "${s:0:2}" = "${__keyw}" ]]; then
+ r=":${s:2}"
elif [ "${print_readably}" == "yes" ]; then
s="${s//\\/\\\\}"
r="\"${s//\"/\\\"}\""
READLINE_EOF=
READLINE_HISTORY_FILE=${HOME}/.mal-history
READLINE () {
- history -r "${READLINE_HISTORY_FILE}"
+ history -r "${READLINE_HISTORY_FILE}" 2>/dev/null || true
read -r -e -p "${1}" r || return "$?"
history -s -- "${r}"
- history -a "${READLINE_HISTORY_FILE}"
+ history -a "${READLINE_HISTORY_FILE}" 2>/dev/null || true
}
fi
declare -A ANON
__obj_magic=__5bal7
-__keyw=$(echo -en "\u029e")
+__keyw=$(echo -en "\xCA\x9E") # \u029E
__obj_hash_code=${__obj_hash_code:-0}
__new_obj_hash_code () {
#else
HIST_ENTRY *he = history_get(history_length-1);
FILE *fp = fopen(hf, "a");
- fprintf(fp, "%s\n", he->line);
- fclose(fp);
+ if (fp) {
+ fprintf(fp, "%s\n", he->line);
+ fclose(fp);
+ }
#endif
free(hf);
}
(ns readline
(:require [clojure.string :refer [split]]
+ [clojure.java.io :refer [file]]
[net.n01se.clojure-jna :as jna]))
(defonce history-loaded (atom nil))
(defn readline [prompt & [lib]]
(when (not @history-loaded)
(reset! history-loaded true)
- (load-history HISTORY-FILE))
+ (when (.canRead (file HISTORY-FILE))
+ (load-history HISTORY-FILE)))
(let [line (readline-call prompt)]
(when line
(add-history line)
- (spit HISTORY-FILE (str line "\n") :append true))
+ (when (.canWrite (file HISTORY-FILE))
+ (spit HISTORY-FILE (str line "\n") :append true)))
line))
line = rllib.readline prompt
if line
rllib.add_history line
- fs.appendFileSync HISTORY_FILE, line + "\n"
+ try
+ fs.appendFileSync HISTORY_FILE, line + "\n"
+ catch exc
+ true
line
-- BSD license
--import qualified System.Console.Editline.Readline as RL
-import System.Directory (getHomeDirectory)
+import Control.Monad (when)
+import System.Directory (getHomeDirectory, doesFileExist)
import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout)
+import System.IO.Error (tryIOError)
history_file = do
home <- getHomeDirectory
load_history = do
hfile <- history_file
- content <- readFile hfile
- mapM RL.addHistory (lines content)
+ fileExists <- doesFileExist hfile
+ when fileExists $ do
+ content <- readFile hfile
+ mapM RL.addHistory (lines content)
+ return ()
+ return ()
readline prompt = do
hfile <- history_file
maybeLine <- RL.readline prompt
case maybeLine of
Just line -> do
- appendFile hfile (line ++ "\n")
RL.addHistory line
+ res <- tryIOError (appendFile hfile (line ++ "\n"))
return maybeLine
_ -> return maybeLine
var line = rllib.readline(prompt);
if (line) {
rllib.add_history(line);
- fs.appendFileSync(HISTORY_FILE, line + "\n");
+ try {
+ fs.appendFileSync(HISTORY_FILE, line + "\n");
+ } catch (exc) {
+ // ignored
+ }
}
return line;
function M.readline(prompt)
if not history_loaded then
history_loaded = true
- for line in io.lines(history_file) do
- LN.historyadd(line)
- end
+ xpcall(function()
+ for line in io.lines(history_file) do
+ LN.historyadd(line)
+ end
+ end, function(exc)
+ return true -- ignore the error
+ end)
end
if M.raw then
end
if line then
LN.historyadd(line)
- local f = io.open(history_file, "a")
- f:write(line.."\n")
- f:close()
+ xpcall(function()
+ local f = io.open(history_file, "a")
+ f:write(line.."\n")
+ f:close()
+ end, function(exc)
+ return true -- ignore the error
+ end)
end
return line
end
# have readline history.
READLINE_EOF :=
READLINE_HISTORY_FILE := $${HOME}/.mal-history
-READLINE = $(eval __readline_temp := $(shell history -r $(READLINE_HISTORY_FILE); read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && history -s -- "$${line}" && history -a $(READLINE_HISTORY_FILE) && echo "$${line}" || echo "__||EOF||__"))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
+READLINE = $(eval __readline_temp := $(shell history -r $(READLINE_HISTORY_FILE); read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && history -s -- "$${line}" && echo "$${line}" || echo "__||EOF||__"; history -a $(READLINE_HISTORY_FILE) 2>/dev/null || true))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
endif
}
when(/^HashMap/) {
my @elems = ();
- foreach my $key (keys $obj->{val}) {
+
+ foreach my $key (keys %{ $obj->{val} }) {
push(@elems, _pr_str(String->new($key), $_r));
push(@elems, _pr_str($obj->{val}->{$key}, $_r));
}
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
}
when (/^HashMap/) {
my $new_hm = {};
- foreach my $k (keys($ast->{val})) {
+ foreach my $k (keys( %{ $ast->{val} })) {
$new_hm->{$k} = EVAL($ast->get($k), $env);
}
return HashMap->new($new_hm);
{
package Integer;
- sub new { my $class = shift; bless \$_[0] => $class }
+ sub new { my $class = shift; bless \do { my $x=$_[0] }, $class }
}
{
package Symbol;
- sub new { my $class = shift; bless \$_[0] => $class }
+ sub new { my $class = shift; bless \do { my $x=$_[0] }, $class }
}
sub _symbol_Q { (ref $_[0]) =~ /^Symbol/ }
// Load the history file
if (! $history_loaded) {
$history_loaded = true;
- if ($file = fopen($HISTORY_FILE, "r")) {
- while (!feof($file)) {
- $line = fgets($file);
- if ($line) { readline_add_history($line); }
+ if (is_readable($HISTORY_FILE)) {
+ if ($file = fopen($HISTORY_FILE, "r")) {
+ while (!feof($file)) {
+ $line = fgets($file);
+ if ($line) { readline_add_history($line); }
+ }
+ fclose($file);
}
- fclose($file);
}
}
readline_add_history($line);
// Append to the history file
- if ($file = fopen($HISTORY_FILE, "a")) {
- fputs($file, $line . "\n");
- fclose($file);
+ if (is_writable($HISTORY_FILE)) {
+ if ($file = fopen($HISTORY_FILE, "a")) {
+ fputs($file, $line . "\n");
+ fclose($file);
+ }
}
return $line;
pyreadline.add_history(line)
with open(histfile, "a") as hf:
hf.write(line + "\n")
- return line
+ except IOError:
+ pass
except EOFError:
return None
+ return line
"character"={
if (substring(exp,1,1) == "\u029e") {
concat(":", substring(exp,2))
+ } else if (substring(exp,1,8) == "<U+029E>") {
+ # terrible hack, appears in 3.1.1 on Utopic
+ concat(":", substring(exp,9))
} else if (print_readably) {
paste("\"",
gsub("\\n", "\\\\n",
if (!.state$rl_history_loaded) {
.state$rl_history_loaded <- TRUE
- lines <- scan(HISTORY_FILE, what="", sep="\n", quiet=TRUE)
- for(add_line in lines) {
- .dyncall(.call_add_history, "Z)v", add_line)
+ if (file.access(HISTORY_FILE, 4) == 0) {
+ lines <- scan(HISTORY_FILE, what="", sep="\n", quiet=TRUE)
+ for(add_line in lines) {
+ .dyncall(.call_add_history, "Z)v", add_line)
+ }
}
}
line <- .readline(prompt)
if (is.null(line)) return(NULL)
.dyncall(.call_add_history, "Z)v", line)
- write(line, file=HISTORY_FILE, append=TRUE)
+ if (file.access(HISTORY_FILE, 2) == 0) {
+ write(line, file=HISTORY_FILE, append=TRUE)
+ }
line
}
(define HISTORY-FILE (format "~a/.mal-history" (find-system-path 'home-dir)))
(define (load-history path)
- (map
- (lambda (line) (readline:add-history line))
- (string-split
- (port->string (open-input-file path))
- #px"\n")))
+ (with-handlers
+ ([exn:fail? (lambda (e) #t)])
+ (map
+ (lambda (line) (readline:add-history line))
+ (string-split
+ (port->string (open-input-file path))
+ #px"\n"))))
(define (readline prompt)
(when (not history-loaded)
nil
(begin
(readline:add-history line)
- (with-output-to-file
- HISTORY-FILE
- (lambda () (printf "~a~n" line))
- #:exists 'append)
+ (with-handlers
+ ([exn:fail? (lambda (e) #t)])
+ (with-output-to-file
+ HISTORY-FILE
+ (lambda () (printf "~a~n" line))
+ #:exists 'append))
line))))
def _readline(prompt)
if !$history_loaded && File.exist?($histfile)
$history_loaded = true
- File.readlines($histfile).each {|l| Readline::HISTORY.push(l.chomp)}
+ if File.readable?($histfile)
+ File.readlines($histfile).each {|l| Readline::HISTORY.push(l.chomp)}
+ end
end
if line = Readline.readline(prompt, true)
- File.open($histfile, 'a+') {|f| f.write(line+"\n")}
+ if File.writable?($histfile)
+ File.open($histfile, 'a+') {|f| f.write(line+"\n")}
+ end
return line
else
return nil
--- /dev/null
+#!/bin/bash
+
+IMAGE_NAME=${IMAGE_NAME:-mal-test-ubuntu-utopic}
+GIT_TOP=$(git rev-parse --show-toplevel)
+
+docker build -t "${IMAGE_NAME}" "${GIT_TOP}/tests/"
--- /dev/null
+#!/bin/bash
+
+IMAGE_NAME=${IMAGE_NAME:-mal-test-ubuntu-utopic}
+GIT_TOP=$(git rev-parse --show-toplevel)
+
+docker run -it --rm -u ${EUID} \
+ --volume=${GIT_TOP}:/mal \
+ ${IMAGE_NAME} \
+ "${@}"
--- /dev/null
+FROM ubuntu:utopic
+MAINTAINER Joel Martin <github@martintribe.org>
+
+ENV DEBIAN_FRONTEND noninteractive
+
+RUN echo "deb http://dl.bintray.com/sbt/debian /" > /etc/apt/sources.list.d/sbt.list
+RUN apt-get -y update
+
+#
+# General dependencies
+#
+VOLUME /mal
+
+RUN apt-get -y install make wget curl git
+
+# Deps for compiled languages (C, Go, Rust, Nim, etc)
+RUN apt-get -y install gcc pkg-config
+
+# Deps for Java-based languages (Clojure, Scala, Java)
+RUN apt-get -y install openjdk-7-jre-headless
+ENV MAVEN_OPTS -Duser.home=/mal
+
+# Deps for Mono-based languages (C#, VB.Net)
+RUN apt-get -y install mono-runtime mono-mcs mono-vbnc
+
+# Deps for node.js languages (JavaScript, CoffeeScript, miniMAL, etc)
+RUN apt-get -y install nodejs npm
+RUN ln -sf nodejs /usr/bin/node
+
+
+#
+# Implementation specific installs
+#
+
+# Bash
+RUN apt-get -y install bash
+
+# C
+RUN apt-get -y install libglib2.0 libglib2.0-dev
+RUN apt-get -y install libffi-dev libreadline-dev libedit2 libedit-dev
+
+# Clojure
+ADD https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
+ /usr/local/bin/lein
+RUN sudo chmod 0755 /usr/local/bin/lein
+ENV LEIN_HOME /mal/.lein
+
+# CoffeeScript
+RUN npm install -g coffee-script
+RUN touch /.coffee_history && chmod go+w /.coffee_history
+
+# C#
+RUN apt-get -y install mono-mcs
+
+# Forth
+RUN apt-get -y install gforth
+
+# Go
+RUN apt-get -y install golang
+
+# Haskell
+RUN apt-get -y install ghc haskell-platform libghc-readline-dev libghc-editline-dev
+
+# Java
+RUN apt-get -y install maven2
+
+# JavaScript
+# Already satisfied above
+
+# Lua
+RUN apt-get -y install lua5.1 lua-rex-pcre luarocks
+RUN luarocks install linenoise
+
+# Mal
+# N/A: self-hosted on other language implementations
+
+# GNU Make
+# Already satisfied as a based dependency for testing
+
+# miniMAL
+RUN npm install -g minimal-lisp
+
+# Nim
+RUN git clone -b devel git://github.com/Araq/Nim.git /tmp/Nim
+RUN cd /tmp/Nim && git clone -b devel --depth 1 git://github.com/nim-lang/csources
+RUN cd /tmp/Nim/csources && sh build.sh
+RUN cd /tmp/Nim && bin/nim c koch
+RUN cd /tmp/Nim && ./koch boot -d:release
+RUN cd /tmp/Nim && ./koch install /usr/local/bin
+RUN rm -r /tmp/Nim
+
+# OCaml
+RUN apt-get -y install ocaml-batteries-included
+
+# perl
+RUN apt-get -y install perl
+
+# PHP
+RUN apt-get -y install php5-cli
+
+# PostScript/ghostscript
+RUN apt-get -y install ghostscript
+
+# python
+RUN apt-get -y install python
+
+# R
+RUN apt-get -y install r-base-core
+
+# Racket
+RUN apt-get -y install racket
+
+# Ruby
+RUN apt-get -y install ruby
+
+# Rust
+RUN curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sh
+
+# Scala
+RUN apt-get -y --force-yes install sbt
+RUN apt-get -y install scala
+ENV SBT_OPTS -Duser.home=/mal
+
+# VB.Net
+RUN apt-get -y install mono-vbnc
+
+# TODO: move this up with Clojure
+ENV LEIN_JVM_OPTS -Duser.home=/mal
+
+ENV DEBIAN_FRONTEND newt
+ENV HOME /
+
+WORKDIR /mal