Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCPL implementation #511

Open
wants to merge 148 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
69a09c6
bcpl: Basic infrastructure for a new port.
bjh21 May 25, 2019
ff2ae72
runtest: Even grottier change to not be fooled by Cintsys prompt.
bjh21 May 25, 2019
b49408c
bcpl: Rough implementation of step 0.
bjh21 May 25, 2019
0333096
bcpl: Add a mal string type and use it in step 0.
bjh21 May 28, 2019
27c7e73
bcpl: Add a nil type and value, and use them in step 0.
bjh21 May 29, 2019
b868b1d
bcpl: Minimal definition of lists.
bjh21 May 29, 2019
9e9fb41
bcpl: Add .DELETE_ON_ERROR to Makefile.
bjh21 May 29, 2019
d8f6623
bcpl: Beginnings of step 1: printer and tokenizer mostly done.
bjh21 Jun 2, 2019
e16e262
bcpl: Fix SLCT expressions.
bjh21 Jun 2, 2019
697d9cc
bcpl: Minimum viable reader.
bjh21 Jun 2, 2019
6be477c
bcpl: Support for reading of strings and integers.
bjh21 Jun 3, 2019
fbbb9f1
bcpl: Simplify tokenizing SWITCHON.
bjh21 Jun 5, 2019
3980c87
bcpl: Helpful comment at the top of the big tokenize() SWITCHON.
bjh21 Jun 5, 2019
2e05ad9
bcpl: Simplify string tokenizer.
bjh21 Jun 5, 2019
809ae63
bcpl: Add support for printing integers.
bjh21 Jun 6, 2019
90f64be
bcpl: Support for throwing exceptions and trapping them in the REPL.
bjh21 Jun 6, 2019
dc8ce27
bcpl: Slightly better handling of EOF in reader.
bjh21 Jun 6, 2019
ab3034b
bcpl: Add a vector type with reading and printing machinery.
bjh21 Jun 11, 2019
a58d7a6
bcpl: Add support for reader macros.
bjh21 Jun 11, 2019
510e71c
bcpl: Step 2 completed (apart from hash-maps).
bjh21 Jun 11, 2019
6862de8
bcpl: Re-organise type codes to add a "compound" flag.
bjh21 Jun 11, 2019
4e55e79
bcpl: Implementation of hash-maps. As yet completely untested.
bjh21 Jun 14, 2019
25bada0
bcpl: 90% of step 3.
bjh21 Jul 4, 2019
023825b
bcpl: Support vectors as bindings in 'let*'.
bjh21 Jul 6, 2019
f5846da
bcpl: Support for reading and printing hash-maps.
bjh21 Jul 7, 2019
53f3591
bcpl: Sort hash-map keys slightly more sensibly.
bjh21 Jul 7, 2019
294b197
bcpl: Minor cleanups and tightening of hash-map code.
bjh21 Jul 8, 2019
295f276
bcpl: with-meta support for reader.
bjh21 Jul 8, 2019
5861d8d
bcpl: Support for evaluating hash-maps.
bjh21 Jul 8, 2019
92362cb
bcpl: Better naming of hash-map-printing functions.
bjh21 Jul 8, 2019
6934c97
bcpl: Add symbol name to the "not found" error message to satisfy tests.
bjh21 Jul 9, 2019
8bd4913
bcpl: Use throwf() for all exceptions generated by mal.
bjh21 Jul 9, 2019
03acbd3
bcpl: Start of step 4: Add 'binds' and 'exprs' arguments to env_new().
bjh21 Jul 9, 2019
76fc3eb
bcpl: Add main file and Makefile machinery for step 4.
bjh21 Jul 9, 2019
5f8b28a
bcpl: Add print syntax for functions.
bjh21 Jul 9, 2019
d064c01
bcpl: Add boolean type and read/print of nil, true, and false.
bjh21 Jul 10, 2019
e6ef075
bcpl: Implement 'if' and 'do'.
bjh21 Jul 10, 2019
152e131
bcpl: Start of function redesign.
bjh21 Jul 11, 2019
02be8e8
bcpl: Implement 'fn*'.
bjh21 Jul 12, 2019
8be3d76
bcpl: More function reworking: arithmetic functions no longer special.
bjh21 Jul 12, 2019
1d13bb1
bcpl: Improve "incomparable value" error message.
bjh21 Jul 12, 2019
0ddf31b
bcpl: Split off core.b and make alloc_fun() more user-friendly.
bjh21 Jul 12, 2019
885b69e
bcpl: Explicitly test for division by zero.
bjh21 Jul 12, 2019
025c51b
bcpl: Tighten and comment core_env(), and propagate changes to earlie…
bjh21 Jul 13, 2019
8aa2b73
bcpl: Minimal implementation of 'prn'.
bjh21 Jul 13, 2019
39d00aa
bcpl: Implement 'list' function.
bjh21 Jul 13, 2019
8fdff0a
bcpl: Implement 'list?' and 'empty?'.
bjh21 Jul 13, 2019
0a07e60
bcpl: Implement 'count' function.
bjh21 Jul 13, 2019
dd7ab9c
bcpl: Implement '=' function, extending equal() to cover lists.
bjh21 Jul 13, 2019
e492997
bcpl: Correct value of compoundflag; mark functions as compound.
bjh21 Jul 13, 2019
f18990c
bcpl: Refuse compound values as hash-map keys.
bjh21 Jul 13, 2019
ab55168
bcpl: Implement integer comparison functions.
bjh21 Jul 13, 2019
e05830d
bcpl: Support '&' in argument lists.
bjh21 Jul 13, 2019
beb3e78
bcpl: Define 'not' function.
bjh21 Jul 13, 2019
5a81ddb
bcpl: Make '=' work for comparing vectors.
bjh21 Jul 16, 2019
27fcee5
bcpl: Extend 'count' to handle vectors.
bjh21 Jul 16, 2019
58f3178
bcpl: Permit vector parameter lists in 'fn*'.
bjh21 Jul 16, 2019
7ae3965
bcpl: Extend 'empty?' to cover vectors.
bjh21 Jul 17, 2019
534dcc5
bcpl: Make '=' work when one argument is a list and on a vector.
bjh21 Jul 17, 2019
17a0ef9
bcpl: Split out list/vector comparision into its own function.
bjh21 Jul 17, 2019
4568327
bcpl: More efficient list/vector comparison.
bjh21 Jul 17, 2019
78543b2
bcpl: Replace (tail) recursion in equal_lst with a loop.
bjh21 Jul 17, 2019
f602398
bcpl: Support for keywords.
bjh21 Jul 17, 2019
9b18b17
bcpl: Be more careful about truth values.
bjh21 Jul 18, 2019
18d72ac
bcpl: Add 'pr-str' core function.
bjh21 Jul 18, 2019
92b8e6c
bcpl: Printing system rework. Now printer context is in a vector.
bjh21 Jul 23, 2019
c0edf25
bcpl: Add 'str' and 'println' core functions.
bjh21 Jul 23, 2019
999859c
bcpl: Tail-call optimisation for 'let*', 'do', and 'if'.
bjh21 Jul 23, 2019
9deddf3
bcpl: Beginnings of garbage collector
bjh21 Sep 19, 2019
4561cdd
bcpl: Move the global object chain to the start of each object
bjh21 Apr 26, 2020
d63e60a
bcpl: Add a debugging routine for dumping a hashmap
bjh21 Apr 26, 2020
87f1da0
bcpl: Implement step 1 of my new garbage-collector guide
bjh21 Apr 27, 2020
211aec6
bcpl: Convert step 2 to use a hash-map as "env"
bjh21 Apr 28, 2020
4cca619
bcpl: Adjust steps to align better
bjh21 Apr 28, 2020
3a96374
bcpl: Garbage collector up to step 2
bjh21 Apr 29, 2020
9f1dab1
bcpl: Convert environments into a type of mal object
bjh21 Apr 30, 2020
cc0e685
bcpl: Add garbage-collection to step 3
bjh21 Apr 30, 2020
d6624e7
bcpl: Extend garbage-collection to user-defined functions
bjh21 May 2, 2020
e7399e9
bcpl: Enable once-per-rep garbage-collection in step 4
bjh21 May 2, 2020
702ec23
bcpl: Add gc_root parameter to EVAL and eval_ast
bjh21 May 2, 2020
bc17c7d
bcpl: GC step 4 except for user-defined functions
bjh21 May 2, 2020
bb3e0b2
bcpl: Minor enhancements to hm_dump
bjh21 May 2, 2020
f2d73e4
bcpl: Finish off GC for step 4
bjh21 May 3, 2020
a809568
bcpl: Add GC to the bit of step 5 that's already implemented
bjh21 May 3, 2020
1d57473
bcpl: Update to match the latest GC guide
bjh21 May 6, 2020
85c020f
bcpl: Step 5 complete, with garbage collection
bjh21 May 8, 2020
7b45507
bcpl: Start of step 6, implementin read-string
bjh21 May 8, 2020
be4176e
bcpl: Fix embarrasing throwf bug causing occasional crashes
bjh21 May 8, 2020
70a471e
bcpl: Implement "slurp" function
bjh21 May 8, 2020
cc874b4
bcpl: Implement the "eval" builtin
bjh21 May 8, 2020
cef1b5f
bcpl: Add load-file
bjh21 May 8, 2020
2c5c28b
bcpl: Atoms, with the exception of swap!
bjh21 May 8, 2020
9e8b7c2
bcpl: swap! function
bjh21 May 8, 2020
8dfe886
bcpl: Extract newsubstr() from reader.b and call it str_substr()
bjh21 May 10, 2020
0c80247
bcpl: Skeleton of *ARGV* support
bjh21 May 10, 2020
cb014f4
bcpl: Avoid a buffer over-read in the reader
bjh21 May 10, 2020
3197800
bcpl: Pass gc_root properly into eval_ast
bjh21 May 10, 2020
2c3568e
bcpl: Don't pass repl_env to rep(); it doesn't use it
bjh21 May 13, 2020
b7d4481
bcpl: argv handling in step 6
bjh21 May 13, 2020
401cb2c
bcpl: Start step 7
bjh21 May 15, 2020
1e19232
bcpl: Add "cons" core function
bjh21 May 15, 2020
f2c9a5f
bcpl: Add "concat" core function
bjh21 May 16, 2020
3228d7f
bcpl: Add "quote" form
bjh21 May 16, 2020
80c19f2
bcpl: Use the trick I used in concat to simplify tokenizer
bjh21 May 16, 2020
e04bdff
bcpl: Implement quasiquote; step 7 complete
bjh21 May 16, 2020
63cba0f
bcpl: Start step 8
bjh21 May 16, 2020
791e7f1
bcpl: Set up exception handler earlier
bjh21 May 18, 2020
7c91c04
bcpl: Working macros for step 8
bjh21 May 18, 2020
8c39829
bcpl: nth, first, and rest core functions
bjh21 May 18, 2020
290e0c4
bcpl: Make sure to preserve the temporary binding list in let*
bjh21 May 18, 2020
b7b361b
bcpl: Add "cond" macro; step 8 completed
bjh21 May 18, 2020
2e28281
bcpl: Set up for step 9
bjh21 May 19, 2020
c3ca3d1
bcpl: Make dependencies more compact in Makefile
bjh21 May 19, 2020
d037768
bcpl: Use "rm -f" for "make clean"
bjh21 May 19, 2020
e66c8d7
bcpl: Functional try*/catch*
bjh21 May 19, 2020
e69e2c9
bcpl: Core "apply" function
bjh21 May 19, 2020
3bf9263
bcpl: "map" core function
bjh21 May 19, 2020
75dfd99
bcpl: A bunch of single-argument predicates
bjh21 May 19, 2020
0ed037b
bcpl: "symbol" and "keyword" conversion functions
bjh21 May 19, 2020
d58328c
bcpl: Add "vector" core function
bjh21 May 19, 2020
89cbe02
bcpl: "hash-map" core function
bjh21 May 19, 2020
c02fa92
bcpl: "assoc", "dissoc", and "get" core functions
bjh21 May 19, 2020
a685f3d
bcpl: "contains?" core function
bjh21 May 19, 2020
df676e6
bcpl: Add "keys" and "vals" core functions
bjh21 May 25, 2020
35f4f32
Rename assert_hashmap to as_hashmap and add conversion from nil
bjh21 May 25, 2020
66e1cb8
bcpl: Initialise step A
bjh21 May 25, 2020
cd5e6d4
bcpl: Complete the set of string conversions with as_str()
bjh21 May 25, 2020
c4652a8
bcpl: Add "readline" core function
bjh21 May 25, 2020
97310c9
bcpl: Improved hash-map dumper
bjh21 May 25, 2020
90a981c
bcpl: Add *host-language* and startup banner
bjh21 May 25, 2020
8c5b260
bcpl: Add remaining type predicates
bjh21 May 25, 2020
a99915a
bcpl: Add "conj" core function
bjh21 May 25, 2020
654eb9c
bcpl: Add "seq" core function
bjh21 May 25, 2020
9ee46c0
bcpl: Prefer to detect empty hashmaps with "= empty_hashmap"
bjh21 May 25, 2020
59fa59e
bcpl: Add "time-ms" core function
bjh21 May 25, 2020
c0ae918
bcpl: Re-implement readline() to be more like slurp
bjh21 May 25, 2020
5083069
bcpl: Add unimplemented stubs of "meta" and "with-meta"
bjh21 May 25, 2020
4fcff5e
bcpl: Replace calls to gc_mark() and gc_sweep() with calls to gc()
bjh21 May 25, 2020
3981b4b
bcpl: Propagate some important GC changes through all the steps
bjh21 May 25, 2020
8e739fd
bcpl: Fix a gc_root in eval_ast
bjh21 May 25, 2020
1a25002
bcpl: Update gc_inner_root after macro expansion
bjh21 May 27, 2020
6f8d409
bcpl: Fix step 0 to print a newline after output
bjh21 May 27, 2020
410f584
bcpl: Lengthen test timeout
bjh21 May 27, 2020
c4174c4
bcpl: Garbage-collect less often for speed.
bjh21 May 27, 2020
8c2dcf9
bcpl: Exit properly on error when loading file
bjh21 May 27, 2020
e7b35a6
bcpl: Equality tests for hash-maps
bjh21 May 27, 2020
c319955
bcpl: Add Dockerfile and Travis matrix entry
bjh21 May 27, 2020
59f9ca9
bcpl: Remove downloaded tgz to reduce Docker image size
bjh21 May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- {env: IMPL=basic basic_MODE=cbm NO_SELF_HOST=1, services: [docker]} # step4 OOM
- {env: IMPL=basic basic_MODE=qbasic NO_SELF_HOST=1, services: [docker]} # step4 OOM
- {env: IMPL=bbc-basic, services: [docker]}
- {env: IMPL=bcpl, services: [docker]}
- {env: IMPL=c, services: [docker]}
- {env: IMPL=cpp, services: [docker]}
- {env: IMPL=coffee, services: [docker]}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ DOCKERIZE =
# Implementation specific settings
#

IMPLS = ada ada.2 awk bash basic bbc-basic c chuck clojure coffee common-lisp cpp crystal cs d dart \
IMPLS = ada ada.2 awk bash basic bbc-basic bcpl c chuck clojure coffee common-lisp cpp crystal cs d dart \
elisp elixir elm erlang es6 factor fantom forth fsharp go groovy gnu-smalltalk \
guile haskell haxe hy io java js jq julia kotlin livescript logo lua make mal \
matlab miniMAL nasm nim objc objpascal ocaml perl perl6 php picolisp pike plpgsql \
Expand Down Expand Up @@ -191,6 +191,7 @@ awk_STEP_TO_PROG = impls/awk/$($(1)).awk
bash_STEP_TO_PROG = impls/bash/$($(1)).sh
basic_STEP_TO_PROG = $(basic_STEP_TO_PROG_$(basic_MODE))
bbc-basic_STEP_TO_PROG = impls/bbc-basic/$($(1)).bas
bcpl_STEP_TO_PROG = impls/bcpl/$($(1))
c_STEP_TO_PROG = impls/c/$($(1))
chuck_STEP_TO_PROG = impls/chuck/$($(1)).ck
clojure_STEP_TO_PROG = $(clojure_STEP_TO_PROG_$(clojure_MODE))
Expand Down
38 changes: 38 additions & 0 deletions impls/bcpl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM ubuntu:18.04
MAINTAINER Joel Martin <github@martintribe.org>

##########################################################
# General requirements for testing or common across many
# implementations
##########################################################

RUN apt-get -y update

# Required for running tests
RUN apt-get -y install make python

# Some typical implementation and test requirements
RUN apt-get -y install curl libreadline-dev libedit-dev

RUN mkdir -p /mal
WORKDIR /mal

##########################################################
# Specific implementation requirements
##########################################################

RUN apt-get -y install gcc mesa-common-dev libglu1-mesa-dev freeglut3-dev

RUN cd /usr/local && \
curl -o bcpl.tgz https://www.cl.cam.ac.uk/~mr10/BCPL/bcpl.tgz && \
tar zxf bcpl.tgz && chmod -R a+rX BCPL && rm bcpl.tgz

ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\
/usr/local/BCPL/cintcode/bin
ENV BCPLROOT /usr/local/BCPL/cintcode
ENV BCPLPATH /usr/local/BCPL/cintcode/cin
ENV BCPLHDRS /usr/local/BCPL/cintcode/g
ENV BCPLSCRIPTS /usr/local/BCPL/cintcode/s

RUN cd /usr/local/BCPL/cintcode && make clean && make

18 changes: 18 additions & 0 deletions impls/bcpl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
all: step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \
step5_tco step6_file step7_quote step8_macros step9_try stepA_mal

%: %.b malhdr.h
cintsys -c "bcpl $< to $@"

.DELETE_ON_ERROR:

step0_repl: readline.b types.b
step1_read_print step2_eval: printer.b reader.b readline.b types.b
step3_env: env.b printer.b reader.b readline.b types.b
step4_if_fn_do step5_tco step6_file step7_quote step8_macros step9_try \
stepA_mal: \
core.b env.b printer.b reader.b readline.b types.b

clean:
rm -f step0_repl step1_read_print step2_eval step3_env step4_if_fn_do \
step5_tco step6_file step7_quote step8_macros step9_try stepA_mal
21 changes: 21 additions & 0 deletions impls/bcpl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
* Mal in BCPL

This implementation expects to be built using the Cintcode BCPL
compiler. It may require modifications to work with other BCPL
compilers.

It uses several features that are not mentioned, or are
described as extensions by _BCPL - the language and its compiler_,
including:
* The infixed byte operator `%`
* Using `{` and `}` as section brackets
* Using lower case and `_` in variable names
* Using `?` to indicate an uninitialised value

BCPL does support separate compilation, but running
separately-compiled modules in Cintsys seems to be ill-supported,
requiring use of the run-time dynamic loading mechanism, `loadseg`.
The examples in the manual all use `GET` to textually include library
source code in the main program, so mal does the same. Nonetheless,
in an environment with separate compilation it should be possible to
remove all these `GET` directives and compile each `.b` file separately.
Loading