• R/O
  • SSH

Joypy: コミット一覧

Main interpreter and library.


RSS
Rev. 日時 作者
b3a17986bab2 tip 2020-02-01 05:06:31 Simon Forman

Minor edits.

f3e04b7b897e 2020-02-01 05:01:13 Simon Forman

Minor edits.

6a98a3a4a83c 2020-02-01 01:30:10 Simon Forman

Remove unused predicates appears_only_once/2 and reg_used_once/2.

801e1c92a555 2020-02-01 01:26:10 Simon Forman

Freeing registers before using them is simpler.

https://todo.sr.ht/~sforman/thun-der/3

e8fcdbf066e2 2020-01-31 03:25:12 Simon Forman

Partial reduction for combinator rule works after all.

It just looked weird to me and I didn't think it through.
Once I checked it I realized it was okay.

14698a72fd89 2020-01-30 04:04:22 Simon Forman

Uncovered and fixed a subtle bug in free_reg//3.

non_alloc/1 for words that don't change the ref count of registers and can be delegated to their semantic relation.

c5070e683545 2020-01-30 02:48:08 Simon Forman

Cons. I should research Lisp compilers...

I think I should emit high-level code and reduce it to actual
machine code later under whatever model (cons cell heap, etc.)

a03395e38717 2020-01-29 11:04:51 Simon Forman

Add assoc to kinda sorta track the values in the registers.

But it doesn't update e.g. if you add two numbers, the value int(N) stays the same.

It could be modified to track the value as it computes? But then why keep them in registers at all? Sometimes a value must arrive at runtime, eh?

3e3aa5df0d83 2020-01-29 10:16:17 Simon Forman

swap, pop, and +

compiling is tricky

a7bd9deb7864 2020-01-29 05:44:19 Simon Forman

dup, add_ref/3.

eeff4cb90202 2020-01-29 05:24:04 Simon Forman

THread through a context to track registers.

It seems to work to allocate and free registers with a kind of reference counting
by membership in an auxilliary list.

adb9999034b3 2020-01-29 04:01:28 Simon Forman

Sort of compile '+'.

048373876de8 2020-01-29 03:46:38 Simon Forman

Move immediate to register for int literal.

38c60411847b 2020-01-29 03:37:13 Simon Forman

blep.

ae2c21f96e49 2020-01-29 03:21:37 Simon Forman

A start on machine code generation.

Just the initial messing around...

6afef79d49ec 2020-01-28 05:56:26 Simon Forman

Fix a bug in step.

You think it would be easy to find all the places where the type tags are needed.

984bef299541 2020-01-28 04:54:24 Simon Forman

docs, formatter

bdcb770bfa2f 2020-01-27 10:06:21 Simon Forman

Fix a bug in rest.

It didn't tag the tail list as a list.

Also, spell out bool for true cases.

139b05f21d38 2020-01-27 09:50:49 Simon Forman

Minor cleanup.

I feel like I should keep the un-partially-reduced thun/4 but
you can still read it, and the reduced forms are more efficient.
(And not too much more wordy.)

3c5e91d9c319 2020-01-27 06:21:47 Simon Forman

Experiments with partial reduction are very promising.

Functions become clauses like these:

thun(symbol(rolldown), [], [C, A, B|D], [A, B, C|D]).
thun(symbol(rolldown), [A|B], [E, C, D|F], G) :-
thun(A, B, [C, D, E|F], G).
thun(symbol(dupd), [], [A, B|C], [A, B, B|C]).
thun(symbol(dupd), [A|B], [C, D|E], F) :-
thun(A, B, [C, D, D|E], F).
thun(symbol(over), [], [B, A|C], [A, B, A|C]).7
thun(symbol(over), [A|B], [D, C|E], F) :-
thun(A, B, [C, D, C|E], F).


Definitions become

thun(symbol(of), A, D, E) :-
append([symbol(swap), symbol(at)], A, [B|C]),
thun(B, C, D, E).
thun(symbol(pam), A, D, E) :-
append([list([symbol(i)]), symbol(map)], A, [B|C]),
thun(B, C, D, E).
thun(symbol(popd), A, D, E) :-
append([list([symbol(pop)]), symbol(dip)], A, [B|C]),
thun(B, C, D, E).


These are tail-recursive and allow for better indexing so I would expect
them to be more efficient than the originals.

Notice the difference between the original thun/4 rule for definitions
and this other one that actually works.

thun(symbol(Def), E, Si, So) :- def(Def, Body), append(Body, E, E o), thun(Eo, Si, So).
thun(symbol(Def), E, Si, So) :- def(Def, Body), append(Body, E, [T|Eo]), thun(T, Eo, Si, So)


The latter reduces to:

thun(symbol(A), C, F, G) :-
def(A, B),
append(B, C, [D|E]),
thun(D, E, F, G).


We want something like...

thun(symbol(B), [], A, D) :- def(B, [H|C]), thun(H, C, A, D).
thun(symbol(A), [H|E0], Si, So) :-
def(A, [DH|DE]),
append(DE, [H|E0], E),
thun(DH, E, Si, So).

But it's good enough. The earlier version doesn't transform into
correct code:

thun(symbol(B), D, A, A) :- def(B, C), append(C, D, []).
thun(symbol(A), C, F, G) :- def(A, B), append(B, C, [D|E]), thun(D, E, F, G).

It would probably be good to investigate what goes wrong there.)

It doesn't seem to work right for thun/4 combinator rules either. Dunno what's
up there.

62cee285d3bb 2020-01-27 05:48:38 Simon Forman

Partial reduction of thun/3 in the thun/4 relation.

It mostly works.

fd361cbbf2bb 2020-01-27 03:15:32 Simon Forman

Map combinator works with types.

2f5f23da06d3 2020-01-27 02:48:30 Simon Forman

Remove '==' from definitions. (Bools)

I decided that the conceptual simplicity of omitting '==' is more useful
than the cosmetic value of keeping it. The defs.txt file is now just one
definition per line with the first symbol giving the name.

Also, bools are literals.

0743343d5758 2020-01-27 01:44:57 Simon Forman

Definition for 'not' in terms of 'branch'.

0198a3994125 2020-01-27 01:43:52 Simon Forman

Proper types, checking, inference.

When I first translated Joy into Prolog I was so blown away by the Prolog
unification over list structures and Triska's CLP(FD) semantics for math
(both in the sense that he wrote CLP(FD) for SWI Prolog and he suggested
it for Joy-in-Prolog specifically) that I didn't realize that it wasn't
quite type inference.

It's kind of like type inference, in that lists are handled correctly and
the CLP(FD) library creates and maintains a kind of context for
constraints, which are sort-of like "dependent types" if you squint a
little. But you can still do things like 'cons' a number to a number and
get (a Prolog term) like [2|3] which is almost certainly a bug.

So I went through and added type "tags" as Prolog terms: int/1, list/1,
and symbol/1. The parser assigns them and all the primitive functions
and combinators use them (and so all the definitions do too.) With this
information Prolog can e.g. prevent attempts to add numbers and lists, and
so on.

This also allows for the thun/3 relation to be implemented a little more
efficiently (without much loss of beauty) by looking ahead one term in
the pending expression and dispatching on structural "type" in a thun/4
relation. I miss the elegance of the previous version, but this lets
Prolog index on the structural type tags that the parser produces.

(This might mess up tail recursion because now we have a loop between
thun/3 and thun/4 but we can eliminate that problem by partial reduction
on thun/3. TODO.)

Now that literals are tagged by the parser there's no need for literal/1.

8a75bc49e0c0 2020-01-26 09:13:06 Simon Forman

Don't assert defs twice.

Each definition is getting parsed with the name of the next one as part
of its body, then the next one fails to parse and the thing backtracks.
So each definition (but the last) gets asserted twice.

def(--,[1,-,?])
def(--,[1,-])
def(?,[dup,bool,++])
def(?,[dup,bool])
def(++,[1,+,anamorphism])
def(++,[1,+])
def(anamorphism,[[pop,[]],swap,[dip,swons],genrec,app1])
def(anamorphism,[[pop,[]],swap,[dip,swons],genrec])
def(app1,[grba,infrst,app2])
def(app1,[grba,infrst])
def(app2,[[grba,swap,grba,swap],dip,[infrst],cons,ii,app3])
def(app2,[[grba,swap,grba,swap],dip,[infrst],cons,ii])

...and so on.

b3389729e910 2020-01-26 08:50:50 Simon Forman

Change back to CLP(FD) semantics.

Minor changes to parser to make it less logical but a little firmer.
(E.g. ints can't be backtracked into becoming symbols!)

b34066c76c48 2020-01-26 07:35:44 Simon Forman

Docs and minor cleanup to the grammar.

d2571b683d1b 2019-12-04 01:41:42 Simon Forman

Minor cleanup.

bbb66da2e831 2019-12-03 07:26:07 Simon Forman

Make parser REs into module-level "constants".

旧リポジトリブラウザで表示