OSDN Git Service

joypy/Thun.git
4 years agoAdd assoc to kinda sorta track the values in the registers.
Simon Forman [Wed, 29 Jan 2020 02:04:51 +0000 (18:04 -0800)]
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?

4 years agoswap, pop, and +
Simon Forman [Wed, 29 Jan 2020 01:16:17 +0000 (17:16 -0800)]
swap, pop, and +

compiling is tricky

4 years agodup, add_ref/3.
Simon Forman [Tue, 28 Jan 2020 20:44:19 +0000 (12:44 -0800)]
dup, add_ref/3.

4 years agoTHread through a context to track registers.
Simon Forman [Tue, 28 Jan 2020 20:24:04 +0000 (12:24 -0800)]
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.

4 years agoSort of compile '+'.
Simon Forman [Tue, 28 Jan 2020 19:01:28 +0000 (11:01 -0800)]
Sort of compile '+'.

4 years agoMove immediate to register for int literal.
Simon Forman [Tue, 28 Jan 2020 18:46:38 +0000 (10:46 -0800)]
Move immediate to register for int literal.

4 years agoblep.
Simon Forman [Tue, 28 Jan 2020 18:37:13 +0000 (10:37 -0800)]
blep.

4 years agoA start on machine code generation.
Simon Forman [Tue, 28 Jan 2020 18:21:37 +0000 (10:21 -0800)]
A start on machine code generation.

Just the initial messing around...

4 years agoFix a bug in step.
Simon Forman [Mon, 27 Jan 2020 20:56:26 +0000 (12:56 -0800)]
Fix a bug in step.

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

4 years agodocs, formatter
Simon Forman [Mon, 27 Jan 2020 19:54:24 +0000 (11:54 -0800)]
docs, formatter

4 years agoFix a bug in rest.
Simon Forman [Mon, 27 Jan 2020 01:06:21 +0000 (17:06 -0800)]
Fix a bug in rest.

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

Also, spell out bool for true cases.

4 years agoMinor cleanup.
Simon Forman [Mon, 27 Jan 2020 00:50:49 +0000 (16:50 -0800)]
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.)

4 years agoExperiments with partial reduction are very promising.
Simon Forman [Sun, 26 Jan 2020 21:21:47 +0000 (13:21 -0800)]
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.

4 years agoPartial reduction of thun/3 in the thun/4 relation.
Simon Forman [Sun, 26 Jan 2020 20:48:38 +0000 (12:48 -0800)]
Partial reduction of thun/3 in the thun/4 relation.

It mostly works.

4 years agoMap combinator works with types.
Simon Forman [Sun, 26 Jan 2020 18:15:32 +0000 (10:15 -0800)]
Map combinator works with types.

4 years agoRemove '==' from definitions. (Bools)
Simon Forman [Sun, 26 Jan 2020 17:48:30 +0000 (09:48 -0800)]
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.

4 years agoDefinition for 'not' in terms of 'branch'.
Simon Forman [Sun, 26 Jan 2020 16:44:57 +0000 (08:44 -0800)]
Definition for 'not' in terms of 'branch'.

4 years agoProper types, checking, inference.
Simon Forman [Sun, 26 Jan 2020 16:43:52 +0000 (08:43 -0800)]
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.

4 years agoDon't assert defs twice.
Simon Forman [Sun, 26 Jan 2020 00:13:06 +0000 (16:13 -0800)]
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.

4 years agoChange back to CLP(FD) semantics.
Simon Forman [Sat, 25 Jan 2020 23:50:50 +0000 (15:50 -0800)]
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!)

4 years agoDocs and minor cleanup to the grammar.
Simon Forman [Sat, 25 Jan 2020 22:35:44 +0000 (14:35 -0800)]
Docs and minor cleanup to the grammar.

4 years agoMinor cleanup.
Simon Forman [Tue, 3 Dec 2019 16:41:42 +0000 (08:41 -0800)]
Minor cleanup.

4 years agoMake parser REs into module-level "constants".
Simon Forman [Mon, 2 Dec 2019 22:26:07 +0000 (14:26 -0800)]
Make parser REs into module-level "constants".

4 years agoSome helper scripts for windows.
Simon Forman [Mon, 2 Dec 2019 22:14:38 +0000 (14:14 -0800)]
Some helper scripts for windows.

4 years agoMinor docs update.
Simon Forman [Mon, 2 Dec 2019 22:13:50 +0000 (14:13 -0800)]
Minor docs update.

4 years agoDebugging this sucks.
Simon Forman [Thu, 28 Nov 2019 15:58:42 +0000 (07:58 -0800)]
Debugging this sucks.

Even with the RISC emu GUI.

Redesign vm?  Add more tooling?  Use MetaII?

Happy Thanksgiving!

4 years agoEmit a sort of symbol table.
Simon Forman [Thu, 14 Nov 2019 05:15:33 +0000 (21:15 -0800)]
Emit a sort of symbol table.

4 years ago4 is already an offset
Simon Forman [Wed, 13 Nov 2019 23:07:27 +0000 (15:07 -0800)]
4 is already an offset

4 years agoDefinitions.
Simon Forman [Wed, 13 Nov 2019 19:41:41 +0000 (11:41 -0800)]
Definitions.

4 years ago"swap" word.
Simon Forman [Wed, 13 Nov 2019 00:09:13 +0000 (16:09 -0800)]
"swap" word.

4 years ago"new" word.
Simon Forman [Tue, 12 Nov 2019 23:47:33 +0000 (15:47 -0800)]
"new" word.

4 years agoRefactor sub_base_merge_and_store.
Simon Forman [Tue, 12 Nov 2019 19:42:24 +0000 (11:42 -0800)]
Refactor sub_base_merge_and_store.

4 years agodup cons i
Simon Forman [Tue, 12 Nov 2019 17:23:31 +0000 (09:23 -0800)]
dup cons i

4 years agoForgot to "return" from i combinator.
Simon Forman [Tue, 12 Nov 2019 17:18:58 +0000 (09:18 -0800)]
Forgot to "return" from i combinator.

4 years agoEven "nicer".
Simon Forman [Tue, 12 Nov 2019 17:06:22 +0000 (09:06 -0800)]
Even "nicer".

4 years agoCharming.
Simon Forman [Tue, 12 Nov 2019 17:03:54 +0000 (09:03 -0800)]
Charming.

4 years agodexpr//1
Simon Forman [Tue, 12 Nov 2019 17:02:19 +0000 (09:02 -0800)]
dexpr//1

4 years agoThe i combinator.
Simon Forman [Tue, 12 Nov 2019 16:37:20 +0000 (08:37 -0800)]
The i combinator.

4 years agohead_addr
Simon Forman [Mon, 11 Nov 2019 15:51:58 +0000 (07:51 -0800)]
head_addr

4 years agoSimple push of empty list.
Simon Forman [Mon, 11 Nov 2019 15:45:22 +0000 (07:45 -0800)]
Simple push of empty list.

4 years agoDup.
Simon Forman [Sun, 10 Nov 2019 22:35:57 +0000 (14:35 -0800)]
Dup.

ANd portray_clause to stablize output logical variable names.

4 years agohalt.
Simon Forman [Sun, 10 Nov 2019 18:58:47 +0000 (10:58 -0800)]
halt.

4 years agoword works with negative numbers now.
Simon Forman [Sun, 10 Nov 2019 18:53:55 +0000 (10:53 -0800)]
word works with negative numbers now.

symbols moved to head of machine code.

4 years agomerge_and_store, chain_link
Simon Forman [Sun, 10 Nov 2019 05:55:01 +0000 (21:55 -0800)]
merge_and_store, chain_link

4 years agoMinor refactor.
Simon Forman [Sun, 10 Nov 2019 05:20:31 +0000 (21:20 -0800)]
Minor refactor.

It doesn't save space (but if I reuse it once it will.)

4 years agoPass through label.
Simon Forman [Sun, 10 Nov 2019 04:19:15 +0000 (20:19 -0800)]
Pass through label.

4 years agoif_literal and lookup
Simon Forman [Sun, 10 Nov 2019 02:39:39 +0000 (18:39 -0800)]
if_literal and lookup

4 years agoincr stack
Simon Forman [Sun, 10 Nov 2019 02:28:01 +0000 (18:28 -0800)]
incr stack

Really decr, but I'm abstracting.

4 years agoRefactoring and cleanup.
Simon Forman [Sun, 10 Nov 2019 02:15:56 +0000 (18:15 -0800)]
Refactoring and cleanup.

4 years agoload
Simon Forman [Sun, 10 Nov 2019 02:02:07 +0000 (18:02 -0800)]
load

4 years agoBleah.
Simon Forman [Sat, 9 Nov 2019 23:20:06 +0000 (15:20 -0800)]
Bleah.

4 years agoBase address in unpack_pair.
Simon Forman [Sat, 9 Nov 2019 23:12:44 +0000 (15:12 -0800)]
Base address in unpack_pair.

4 years agounpack_pair
Simon Forman [Sat, 9 Nov 2019 23:03:17 +0000 (15:03 -0800)]
unpack_pair

4 years agoMinor refactor.
Simon Forman [Sat, 9 Nov 2019 22:02:18 +0000 (14:02 -0800)]
Minor refactor.

4 years agoRefactoring, with oddball quoting "symbols".
Simon Forman [Sat, 9 Nov 2019 21:59:06 +0000 (13:59 -0800)]
Refactoring, with oddball quoting "symbols".

4 years agoThat works nicely, again.
Simon Forman [Sat, 9 Nov 2019 21:42:14 +0000 (13:42 -0800)]
That works nicely, again.

4 years agoConvert to ? DCG and it's macro-time!
Simon Forman [Sat, 9 Nov 2019 21:34:51 +0000 (13:34 -0800)]
Convert to ? DCG and it's macro-time!

4 years agoI think that does it for cons.
Simon Forman [Sat, 9 Nov 2019 20:14:51 +0000 (12:14 -0800)]
I think that does it for cons.

Offsets in pair records can be negative.

4 years agoThat's the mainloop converted to permit negative offsets.
Simon Forman [Sat, 9 Nov 2019 20:03:13 +0000 (12:03 -0800)]
That's the mainloop converted to permit negative offsets.

4 years agoMinor cleanup, bug fixes.
Simon Forman [Sat, 9 Nov 2019 19:27:29 +0000 (11:27 -0800)]
Minor cleanup, bug fixes.

4 years agoMinor bugfix.
Simon Forman [Fri, 8 Nov 2019 23:24:09 +0000 (15:24 -0800)]
Minor bugfix.

asr not ror.

4 years agoCons
Simon Forman [Fri, 8 Nov 2019 22:06:28 +0000 (14:06 -0800)]
Cons

4 years agoJust do it in asm.
Simon Forman [Fri, 8 Nov 2019 16:08:53 +0000 (08:08 -0800)]
Just do it in asm.

4 years agohmm...
Simon Forman [Fri, 8 Nov 2019 04:21:26 +0000 (20:21 -0800)]
hmm...

4 years agoWIth push2 finished that's the mainloop converted.
Simon Forman [Fri, 8 Nov 2019 01:25:04 +0000 (17:25 -0800)]
WIth push2 finished that's the mainloop converted.

4 years agolookup
Simon Forman [Fri, 8 Nov 2019 00:28:28 +0000 (16:28 -0800)]
lookup

4 years agoif_literal
Simon Forman [Fri, 8 Nov 2019 00:15:41 +0000 (16:15 -0800)]
if_literal

4 years agoA start on converting the mainloop.
Simon Forman [Thu, 7 Nov 2019 23:53:07 +0000 (15:53 -0800)]
A start on converting the mainloop.

4 years agoTake two on the compiler.
Simon Forman [Thu, 7 Nov 2019 22:57:41 +0000 (14:57 -0800)]
Take two on the compiler.

4 years agoMinor cleanup.
Simon Forman [Thu, 7 Nov 2019 15:55:01 +0000 (07:55 -0800)]
Minor cleanup.

4 years agoModify error reporting a lil; words word.
Simon Forman [Thu, 7 Nov 2019 15:54:04 +0000 (07:54 -0800)]
Modify error reporting a lil; words word.

4 years agoDefinition of ii combinator.
Simon Forman [Thu, 7 Nov 2019 15:53:21 +0000 (07:53 -0800)]
Definition of ii combinator.

    ii == [dip] dupdip i

         a [F] ii
      --------------
          F a F

4 years agoCall for_serial/2
Simon Forman [Thu, 7 Nov 2019 15:43:21 +0000 (07:43 -0800)]
Call for_serial/2

4 years agoUsing partial deduction to inline literals, functions, and combinators.
Simon Forman [Thu, 22 Aug 2019 22:45:24 +0000 (15:45 -0700)]
Using partial deduction to inline literals, functions, and combinators.

4 years agominor cleanup
Simon Forman [Wed, 21 Aug 2019 05:00:27 +0000 (22:00 -0700)]
minor cleanup

4 years agosmall func recognizes [] and [X].
Simon Forman [Tue, 20 Aug 2019 05:02:06 +0000 (22:02 -0700)]
small func recognizes [] and [X].

4 years agoRename bar to korf and some docs.
Simon Forman [Sun, 18 Aug 2019 23:59:31 +0000 (16:59 -0700)]
Rename bar to korf and some docs.

4 years agominor cleanup
Simon Forman [Sun, 18 Aug 2019 19:17:37 +0000 (12:17 -0700)]
minor cleanup

4 years agoreintroduce definition of fork; it doesn't shadow func(fork, ...).
Simon Forman [Sun, 18 Aug 2019 18:47:48 +0000 (11:47 -0700)]
reintroduce definition of fork; it doesn't shadow func(fork, ...).

4 years agoread child output after local thun/3
Simon Forman [Sun, 18 Aug 2019 18:09:36 +0000 (11:09 -0700)]
read child output after local thun/3

4 years agotruly fork, sort of
Simon Forman [Sun, 18 Aug 2019 17:53:25 +0000 (10:53 -0700)]
truly fork, sort of

4 years agominor cleanup
Simon Forman [Tue, 13 Aug 2019 18:58:31 +0000 (11:58 -0700)]
minor cleanup

4 years agoMinor cleanup.
Simon Forman [Tue, 13 Aug 2019 18:51:41 +0000 (11:51 -0700)]
Minor cleanup.

4 years agoMove DCG stuff to own file.
Simon Forman [Tue, 13 Aug 2019 18:48:08 +0000 (11:48 -0700)]
Move DCG stuff to own file.

4 years agoParse ints; move line/{1,2} to main.pl.
Simon Forman [Tue, 13 Aug 2019 18:29:49 +0000 (11:29 -0700)]
Parse ints; move line/{1,2} to main.pl.

4 years agoParse floating point numbers.
Simon Forman [Tue, 13 Aug 2019 18:24:28 +0000 (11:24 -0700)]
Parse floating point numbers.

4 years agominor cleanup
Simon Forman [Tue, 13 Aug 2019 05:29:09 +0000 (22:29 -0700)]
minor cleanup

4 years agominor cleanup
Simon Forman [Tue, 13 Aug 2019 04:59:19 +0000 (21:59 -0700)]
minor cleanup

4 years agoNumbers can be followed by space or [.
Simon Forman [Tue, 13 Aug 2019 04:29:26 +0000 (21:29 -0700)]
Numbers can be followed by space or [.

4 years agoParse negative numbers.
Simon Forman [Tue, 13 Aug 2019 04:13:11 +0000 (21:13 -0700)]
Parse negative numbers.

4 years agoswapd function
Simon Forman [Tue, 13 Aug 2019 04:08:35 +0000 (21:08 -0700)]
swapd function

4 years agoassert_defs/1 got upset about not finding combo/5
Simon Forman [Tue, 13 Aug 2019 04:08:17 +0000 (21:08 -0700)]
assert_defs/1 got upset about not finding combo/5

4 years agoMinor cleanup of the parser.
Simon Forman [Tue, 13 Aug 2019 03:59:02 +0000 (20:59 -0700)]
Minor cleanup of the parser.

4 years agorework parser DCGs
Simon Forman [Tue, 13 Aug 2019 03:12:35 +0000 (20:12 -0700)]
rework parser DCGs

4 years agoOops! Regression.
Simon Forman [Tue, 13 Aug 2019 02:25:13 +0000 (19:25 -0700)]
Oops! Regression.

4 years agominor cleanup
Simon Forman [Tue, 13 Aug 2019 02:17:15 +0000 (19:17 -0700)]
minor cleanup

4 years agoswoncat and fiddling with parser.
Simon Forman [Tue, 13 Aug 2019 02:09:49 +0000 (19:09 -0700)]
swoncat and fiddling with parser.

4 years agoExperiment with putting logic vars on the stack.
Simon Forman [Mon, 12 Aug 2019 04:30:02 +0000 (21:30 -0700)]
Experiment with putting logic vars on the stack.

4 years agoRemove a cut that sucked.
Simon Forman [Mon, 12 Aug 2019 03:45:49 +0000 (20:45 -0700)]
Remove a cut that sucked.

4 years agounstack, least_fraction
Simon Forman [Mon, 12 Aug 2019 02:57:28 +0000 (19:57 -0700)]
unstack, least_fraction