1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 02:45:44 +03:00

TypeScript: setup initial environment

This commit is contained in:
vvakame 2017-02-23 00:03:21 +09:00
parent 186471a32c
commit 571eb786b4
14 changed files with 122 additions and 1 deletions

View File

@ -81,7 +81,7 @@ IMPLS = ada awk bash basic c d chuck clojure coffee common-lisp cpp crystal cs d
erlang elisp elixir es6 factor forth fsharp go groovy guile haskell \
haxe io java julia js kotlin logo lua make mal ocaml matlab miniMAL \
nim objc objpascal perl perl6 php pil plpgsql plsql powershell ps \
python r racket rpython ruby rust scala skew swift swift3 tcl vb vhdl \
python r racket rpython ruby rust scala skew swift swift3 tcl ts vb vhdl \
vimscript
EXTENSION = .mal
@ -210,6 +210,7 @@ skew_STEP_TO_PROG = skew/$($(1)).js
swift_STEP_TO_PROG = swift/$($(1))
swift3_STEP_TO_PROG = swift3/$($(1))
tcl_STEP_TO_PROG = tcl/$($(1)).tcl
ts_STEP_TO_PROG = ts/$($(1)).js
vb_STEP_TO_PROG = vb/$($(1)).exe
vhdl_STEP_TO_PROG = vhdl/$($(1))
vimscript_STEP_TO_PROG = vimscript/$($(1)).vim

5
ts/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
node_modules/
npm-debug.log
*.js

34
ts/Makefile Normal file
View File

@ -0,0 +1,34 @@
SOURCES_BASE = types.ts reader.ts printer.ts
SOURCES_LISP = env.ts core.ts stepA_mal.ts
SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
all: node_modules dist
node_modules:
npm install
dist: mal.js mal
%.js: %.js
./node_modules/.bin/tsc -p ./
mal.js: $(SOURCES)
./node_modules/.bin/tsc -p ./
mal: mal.js
echo "#!/usr/bin/env node" > $@
cat $< >> $@
chmod +x $@
clean:
rm -f *.js mal
.PHONY: stats tests $(TESTS)
stats: $(SOURCES)
@wc $^
@printf "%5s %5s %5s %s\n" `egrep "^\w*#|^\w*$$" $^ | wc` "[comments/blanks]"
stats-lisp: $(SOURCES_LISP)
@wc $^
@printf "%5s %5s %5s %s\n" `egrep "^\w*#|^\w*$$" $^ | wc` "[comments/blanks]"

0
ts/core.ts Normal file
View File

0
ts/env.ts Normal file
View File

0
ts/mal.ts Normal file
View File

45
ts/node_readline.ts Normal file
View File

@ -0,0 +1,45 @@
import * as path from "path";
import * as ffi from "ffi";
import * as fs from "fs";
// IMPORTANT: choose one
const RL_LIB = "libreadline"; // NOTE: libreadline is GPL
//var RL_LIB = "libedit";
const HISTORY_FILE = path.join(process.env.HOME, ".mal-history");
const rllib = ffi.Library(RL_LIB, {
"readline": ["string", ["string"]],
"add_history": ["int", ["string"]],
});
let rlHistoryLoaded = false;
export function readline(prompt?: string): string | null {
prompt = prompt || "user> ";
if (!rlHistoryLoaded) {
rlHistoryLoaded = true;
let lines: string[] = [];
if (fs.existsSync(HISTORY_FILE)) {
lines = fs.readFileSync(HISTORY_FILE).toString().split("\n");
}
// Max of 2000 lines
lines = lines.slice(Math.max(lines.length - 2000, 0));
for (let i = 0; i < lines.length; i++) {
if (lines[i]) { rllib.add_history(lines[i]); }
}
}
const line = rllib.readline(prompt);
if (line) {
rllib.add_history(line);
try {
fs.appendFileSync(HISTORY_FILE, line + "\n");
} catch (exc) {
// ignored
}
}
return line;
};

19
ts/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "mal",
"private": true,
"version": "1.0.0",
"description": "Make a Lisp (mal) language implemented in TypeScript",
"scripts": {
"test": "npm run test:step0",
"test:step0": "cd .. && make 'test^ts^step0'"
},
"dependencies": {
"ffi": "^2.2.0"
},
"devDependencies": {
"@types/ffi": "0.0.19",
"@types/node": "^7.0.5",
"typescript": "^2.1.6",
"typescript-formatter": "^4.1.1"
}
}

0
ts/printer.ts Normal file
View File

0
ts/reader.ts Normal file
View File

2
ts/run Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
exec node $(dirname $0)/${STEP:-stepA_mal}.js "${@}"

0
ts/step0_repl.ts Normal file
View File

15
ts/tsconfig.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"noImplicitAny": true,
"noEmitOnError": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"newLine": "LF",
"strictNullChecks": true,
"sourceMap": false
}
}

0
ts/types.ts Normal file
View File