Skip to content

Commit

Permalink
Merge pull request #40 from taiyakihitotsu/compiler
Browse files Browse the repository at this point in the history
#19 Compiler
  • Loading branch information
taiyakihitotsu authored Aug 8, 2024
2 parents f19d11b + fda8062 commit 6a74a55
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 538 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v2
with:
node-version: '20.x'
- run: npm ci
- run: npm run biome
- run: npm run build --if-present
node-version: '14'

- name: Install TypeScript
run: npm install

- name: Build
run: npm run build --if-present
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist/
.ignore
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# RoadMap

## Goal
```typescript
(let [a 'a'
f (fn [c] (str '+' c '+'))]
(if (eq '+a+' (f a)) 'this_is_true' 'this_is_false'))
```

```typescript
type Sexpr =
`(let [c {:status "in"
Expand All @@ -23,36 +28,50 @@ const message: Return<Eval<Compile<Sexpr>>> = "message"
- [x] fn
- [x] fn >1 args
- [x] vector (= list / array here)
- [x] hashmap
- [ ] hashmap
- [x] if
- [x] eq
- [x] map
- [x] filter
- [x] get
- [x] get with a key
- [x] first
- [ ] logical operation: and, or, not, >, <, =, >=, <=.
- [ ] number (bit operators)
only for 2bit and lack of div in current.
- [ ] arrow macro
- [ ] Compiler
- [ ] string parser
- [x] Compiler

# Builtin
## Definition
They are listed in implemented of usable in Sexpr level.
Some of them are usable only in AST though, not should it be called as implemented.
## Implemented Already
if, fn, let, eq, str.
## Not Implemented Currently
and, or, not, >, <, =, >=, <=, inc, dec, +, -, *, /, mod, map, filter, remove, vec, nil.
## Thinking about whether to implement or not
- about vector:
keep, set, conj, concat, first, second, get, rest, butlast, partition, range, repeat, reduce.
- about hashmap:
assoc, dissoc, update, hash-map, zipmap, keys, vals, zipmap, into.
## No plan to implement
- transducers such like (map f)
- lazy-seq
- R\Q
- list (because of the same role of vec in typelevel)
- loop, recur (I think it's enough of map or something)
- macro
- things I've forgot to list

# Run
```bash
$ npm run build:watch
```

# Env
- ts-node: 9.6.5
- tsc: 5.4.5

# Author
https://github.com/taiyakihitotsu/
taiyakihitotsu

# License
3-clause BSD license






35 changes: 0 additions & 35 deletions biome.json

This file was deleted.

33 changes: 26 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const appendTest = [`prim`, "'+test'"];
// test str
const strtest1 = [
`prim`,
`test+tail`,
`'test+tail'`,
];
const strtest2 = [`prim`, `test`];
const strtest2 = [`prim`, `'test'`];
// test
const lispeqtest = [`prim`, "'a'"];
const lispeqtest1 = [`prim`, true];
Expand Down Expand Up @@ -130,7 +130,7 @@ const testinterleave0 = [1, 4, 2, 5, 3, 6];
const testinterleave1 = [1, 4, 2, 5];
const testinterleave2 = [1, 2];
// multiarg fn test
const testmultiargfn0 = [`prim`, `'0''1'`];
const testmultiargfn0 = [`prim`, `'01'`];
// test raw
const evalTest = [`prim`, "'+test'"];
const evalTest2 = {
Expand Down Expand Up @@ -187,15 +187,15 @@ const evallftest0 = [
`'+test'`,
];
// test interleaved let form
const testiletform = [`prim`, `'1''2'`];
const testiletform = [`prim`, `'12'`];
const evaliftest2 = [`prim`, true];
const evaliftest3 = [`prim`, false];
const evalifrectest0 = [`prim`, true];
const evalifrectest1 = [`prim`, false];
const evalifretfntest = [`prim`, `'+test'`];
// test str
const evalstrtest = [`prim`, `head/tail`];
const evalletmoretest1 = [`prim`, `text-a/text-b`];
const evalstrtest = [`prim`, `'head/tail'`];
const evalletmoretest1 = [`prim`, `'text-a/text-b'`];
const aaaaaaaaa = [
`let`,
[
Expand Down Expand Up @@ -237,4 +237,23 @@ const rbiTest5 = [`prim`, "'+test'"];
// biome-ignore lint/suspicious/noExplicitAny:
const defined = null;
const readdef = [`sym`, `test`]; // null as any
// const readdef2: typeof defined = [`sym`, `tet`] // null as any
const parseaaaaa = ['(', 'x', '(', '(', 'if', 'a', 'b', 'c', ')', 'y', ')', ')'];
const parsebbbbb = ['(', 'x', '(', 'if', 'a', 'b', 'c', ')', 'y', ')'];
const parseccccc = ['(', '(', 'f', ')', ')'];
const parseddddd = ['(', '(', '(', '(', '(', '(', 'x', ')', ')', ')', ')', ')', ')'];
const parseeeeee = ['(', 'let', '[', 'a', '1', 'b', '2', ']', '(', 'if', 'true', 't', 'f', ')', ')'];
const compileraaaa = [['sym', '+'], ['prim', '0'], [['sym', 'inc'], ['prim', '1']]];
const compilerbbbb = ['let', [['sym', 'a'], ['prim', '1']], ['if', ['prim', true], ['sym', 't'], ['sym', 'f']]];
// ----------------------------
// -- Main
// ----------------------------
const maintest0 = [`prim`, false];
const maintest1 = [`prim`, true];
const maintest2 = [`prim`, true];
const maintest3 = [`prim`, false];
// todo :
// string split works but not correctly, in current.
// Use _ as space until I will have implemented a string parser.
const maintest4 = [`prim`, "'this_is_false'"];
const maintest5 = ['prim', '01'];
const maintest6 = ['prim', `'astrbstr'`];
34 changes: 0 additions & 34 deletions dist/let.js

This file was deleted.

109 changes: 0 additions & 109 deletions dist/tslisp.js

This file was deleted.

Loading

0 comments on commit 6a74a55

Please sign in to comment.