Commit Graph

10 Commits

Author SHA1 Message Date
sforman 9f78b6d8fd Messing around with type inference.
What if we insist that both branches of a branch have compatible types?

For one thing `[+] [* +] branch` leads to a circular term which, when
printed, goes into a loop: "int,int,int,...".  Hmm...
2023-08-12 16:45:59 -07:00
sforman 97602ade8d SWIProlog can't not emit '.'.
I would like the GNU Prolog and SWI Prolog versions to be compatible, if
possible.

SWI has bigints, GNU doesn't, so that's a wrinkle...
2023-08-02 22:38:04 -07:00
sforman ef504aa1c4 Rename joy_to_ast to parser. 2023-07-27 09:19:12 -07:00
sforman 18b5d5b497 Minor edits. 2023-07-25 10:04:45 -07:00
sforman f2688e311f Messing around with GNU Prolog.
I have it broken up into three stages: a parser that reads a string from
stdin and emits (Prolog) AST to stdout; an interpreter of sorts that
reads AST from stdin, evaluates it, and then emits the AST of the stack
on stdout; and a printer that reads AST on stdin and prints Joy-ish code
to stdout.

I say Joy-ish because currently math is not evaluated and results of
math appear as expressions, not values.

This is because GNU Prolog doesn't have unbounded integers (it's numbers
are machine integers) so literals that are larger than the machine word
are converted into atoms!  To keep things simple, I made all ints into
atoms, but then you can't evaluate them: '1'+'2' is not '3' (it might be
'12' though.)

So I print them out at expressions:

    $ echo "1 2 3 4 [+ sub /] i" | ./joy_to_ast | ./thun | ./printer

    (1 div (2-(4+3)))

You could almost feed that to, say, Python to evaluate, eh? Or dc with
proper formatting?  (man dc; "Desk Calculator".)

Anyway, it's a start.  The Prolog interpreter is more for things like
type checking and inference, optimizing, compiling, etc.  Symbolic stuff
that's a PITA to express in other languages.  (The old type inference
code in Python was pages long, in Prolog it's just the thun/3 & thun/4
predicates themselves.  At least so far.  There are things we will want
to do eventually that might be a PITA to express in Prolog, eh?
2023-07-25 08:51:27 -07:00
Simon Forman 0d51f7ec1f A simple Joy-to-AST program.
Written in GNU Prolog, doncha know!?  :D
2023-02-17 11:08:43 -08:00
Simon Forman a828169b34 initialization/1 FTW! 2023-02-12 20:39:26 -08:00
Simon Forman caa4461217 Basic system, incomplete.
Still needs the rest of the core functions and defs.
Could read defs from a file at compile-time?
Integer math?  Boolean ops?  Just type inference and maybe compiling?
2022-09-20 17:56:18 -07:00
Simon Forman b49e7458c2 Parse the tokens into a Joy expression. 2022-09-20 17:14:41 -07:00
Simon Forman c8f67f02f9 Parser in GNU Prolog.
Wonky handling of UTF_8 blankspace.
2022-09-20 16:29:35 -07:00