Step 0 of Make-a-Lisp for Erlang

Requires rebar to build.

make test^erlang^step0 passes
This commit is contained in:
Nathan Fiedler 2015-03-15 07:13:47 -07:00
parent 520051615c
commit 2cc3804b19
9 changed files with 141 additions and 3 deletions

3
.gitignore vendored
View file

@ -25,6 +25,9 @@ cs/*.dll
cs/*.mdb
clojure/target
clojure/.lein-repl-history
erlang/ebin
erlang/.rebar
erlang/src/*.beam
go/step*
go/mal
java/target/

View file

@ -10,7 +10,7 @@ PYTHON = python
# Settings
#
IMPLS = bash c clojure coffee cpp cs factor forth go haskell java \
IMPLS = bash c clojure coffee cpp cs erlang factor forth go haskell java \
julia js lua make mal ocaml matlab miniMAL nim perl php ps \
python r racket ruby rust scala swift vb
@ -57,6 +57,7 @@ clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
coffee_STEP_TO_PROG = coffee/$($(1)).coffee
cpp_STEP_TO_PROG = cpp/$($(1))
cs_STEP_TO_PROG = cs/$($(1)).exe
erlang_STEP_TO_PROG = erlang/$($(1))
factor_STEP_TO_PROG = factor/src/$($(1))/$($(1)).factor
forth_STEP_TO_PROG = forth/$($(1)).fs
go_STEP_TO_PROG = go/$($(1))
@ -95,6 +96,7 @@ clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
coffee_RUNSTEP = coffee ../$(2) $(3)
cpp_RUNSTEP = ../$(2) $(3)
cs_RUNSTEP = mono ../$(2) --raw $(3)
erlang_RUNSTEP = ../$(2) $(3)
factor_RUNSTEP = factor ../$(2) $(3)
forth_RUNSTEP = gforth ../$(2) $(3)
go_RUNSTEP = ../$(2) $(3)
@ -211,4 +213,3 @@ $(IMPL_PERF):
$(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
$(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))

View file

@ -4,7 +4,7 @@
Mal is a Clojure inspired Lisp interpreter.
Mal is implemented in 31 different languages:
Mal is implemented in 32 different languages:
* Bash shell
* C
@ -12,6 +12,7 @@ Mal is implemented in 31 different languages:
* C#
* Clojure
* CoffeeScript
* Erlang
* Factor
* Forth
* Go
@ -136,6 +137,16 @@ cd coffee
coffee ./stepX_YYY
```
### Erlang
Requires [rebar](https://github.com/rebar/rebar) to build.
```
cd erlang
MAL_STEP=stepX_YYY rebar compile escriptize
./stepX_YYY
```
### Factor
*The Factor implementation was created by [Jordan Lewis (jordanlewis)](https://github.com/jordanlewis)*

34
erlang/Makefile Normal file
View file

@ -0,0 +1,34 @@
#####################
SOURCES_BASE = src/step0_repl.erl
SOURCES_LISP = src/env.erl
SOURCES = $(SOURCES_BASE) $(word $(words $(SOURCES_LISP)),${SOURCES_LISP})
#####################
SRCS = step0_repl.erl
BINS = $(SRCS:%.erl=%)
#####################
all: $(BINS) mal
mal: $(word $(words $(BINS)),$(BINS))
cp $< $@
define dep_template
$(1): $(SOURCES_BASE) src/$(1).erl
MAL_STEP=$(1) rebar compile escriptize
endef
$(foreach b,$(BINS),$(eval $(call dep_template,$(b))))
clean:
rm -f $(BINS) mal
.PHONY: stats stats-lisp
stats: $(SOURCES)
@wc $^
stats-lisp: $(SOURCES_LISP)
@wc $^

13
erlang/rebar.config Normal file
View file

@ -0,0 +1,13 @@
%%
%% rebar configuration file (https://github.com/rebar/rebar)
%%
{require_otp_vsn, "17"}.
{erl_opts, [debug_info, fail_on_warning]}.
{clean_files, [
"ebin",
"src/*.beam",
"step0_repl"
]}.

View file

@ -0,0 +1,10 @@
%%
%% rebar dynamic configuration file
%% (https://github.com/rebar/rebar/wiki/Dynamic-configuration)
%%
case os:getenv("MAL_STEP") of
false -> CONFIG; % env var not defined
[] -> CONFIG; % env var set to empty string
Step -> CONFIG ++ [{escript_name, Step}]
end.

25
erlang/src/env.erl Normal file
View file

@ -0,0 +1,25 @@
%%%
%%% Environement
%%%
-module(env).
-export([env_new/1, env_bind/3, env_find/2, env_root/1, env_set/3, env_get/2]).
env_new(_Outer) ->
ok.
env_bind(_Env, _Bindings, _Exprs) ->
ok.
env_find(_Env, _Key) ->
ok.
env_root(_Env) ->
ok.
env_set(_Env, _Key, _Value) ->
ok.
env_get(_Env, _Key) ->
ok.

11
erlang/src/mal.app.src Normal file
View file

@ -0,0 +1,11 @@
{application, mal, [
{description, "Make-a-Lisp Erlang"},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, {mal_app, []}},
{env, []}
]}.

30
erlang/src/step0_repl.erl Normal file
View file

@ -0,0 +1,30 @@
%%%
%%% Step 0: REPL
%%%
-module(step0_repl).
-export([main/1]).
main(_) ->
case io:get_line(standard_io, "user> ") of
eof ->
% break out of the loop
io:format("~n"),
ok;
{error, Reason} ->
io:format("Error reading input: ~p~n", [Reason]),
exit(ioerr);
Line ->
io:format("~s~n", [print(eval(read(string:strip(Line, both, $\n))))]),
main("")
end.
read(String) ->
String.
eval(String) ->
String.
print(String) ->
String.