Commit Graph

478 Commits

Author SHA1 Message Date
sforman 64d9bb75a4 Format. 2023-07-30 07:47:26 -07:00
sforman 9963a73322 inscribe, definitions. 2023-07-30 07:45:06 -07:00
sforman 200c390fd5 Initialize dict with defs.
Just sqr for now, but it shows that it works.

I would like to return Results from add_def but it makes using foldl
slightly tricky,  not a lot, just slightly, and my brainpower is low at
the mo'.
2023-07-29 17:10:45 -07:00
sforman edfd7c526f Look up words in the dictionary.
If they are not built-in, which means you can't "shadow" built-ins with
"inscribe", which may or may not turn out to be what we want?
2023-07-29 12:35:47 -07:00
sforman 4acdec71ed Thread the dictionary through the call stack. 2023-07-29 12:30:22 -07:00
sforman 4d6230e01d Empty string is not an unknown word. 2023-07-29 12:11:43 -07:00
sforman 9220361871 Gotta keep a Dict around. 2023-07-29 12:09:08 -07:00
sforman b1d4c3c5b8 Logical ops. 2023-07-29 11:37:07 -07:00
sforman 2c9d5cf4bf Left- and Right-shift. 2023-07-29 11:32:22 -07:00
sforman a69b988684 Comparison ops. 2023-07-29 11:07:50 -07:00
sforman 36dc5b619f loop 2023-07-29 10:44:51 -07:00
sforman 8fb48008cd branch 2023-07-29 10:38:12 -07:00
sforman ed8f8f9edf dip 2023-07-29 10:28:31 -07:00
sforman 9c381f0e8f i 2023-07-29 10:23:06 -07:00
sforman 99a5fd93b1 truthy
I have to check into this: the Python version has "bool" and no
"truthy".
2023-07-29 10:19:39 -07:00
sforman 7c9ea764ea swap 2023-07-29 10:09:40 -07:00
sforman fcdf916013 stack, swaack 2023-07-29 10:00:16 -07:00
sforman c50f2a7541 pop 2023-07-29 09:55:28 -07:00
sforman 4a0fce2492 first, rest 2023-07-29 09:53:00 -07:00
sforman b50be3b64b dup 2023-07-29 09:22:26 -07:00
sforman eb8b282bc2 cons 2023-07-29 09:17:27 -07:00
sforman 70c5223319 clear, concat 2023-07-29 09:06:14 -07:00
sforman af882e2be4 Minor cleanup. 2023-07-29 08:57:58 -07:00
sforman e9f971460f Type alias JList 2023-07-29 08:49:31 -07:00
sforman 9917a2cfba Refactor pop_int.
I don't like passing the stack through isnt_int but that let's you chain
with andThen.

There's probably a clever or idiomatic way to not do that and couple the
stack to the result without passing it through the type checker function
but I don't know what it is right now, and this works.
2023-07-29 07:51:31 -07:00
sforman b6b3acf350 Binary Math Ops 2023-07-29 07:32:56 -07:00
sforman dc065d1943 I don't think andThen helps here? 2023-07-29 07:19:08 -07:00
sforman 48f6e78196 I can add integers! 2023-07-29 06:54:15 -07:00
sforman 5315edbe83 Parsing working.
Modeled on the OCaml code.
2023-07-28 21:51:34 -07:00
sforman 9d57545533 A start on Joy types. 2023-07-28 15:04:35 -07:00
sforman 590a5b207c In Elm. 2023-07-28 14:18:12 -07:00
sforman 23504f6ede Use Python as SHELL in Makefile.
It's a simple task, but I'm not up on my CLI tools, so I went with
Python instead of sh.  The split command doesn't have '-p' switch on
Ubuntu.  (I'm using Ubuntu on this laptop because it can correctly
configure the WiFi and the laptop has no ethernet port.)
2023-07-27 10:32:45 -07:00
sforman 08262ac861 minor cleanup 2023-07-27 09:55:02 -07:00
sforman ef504aa1c4 Rename joy_to_ast to parser. 2023-07-27 09:19:12 -07:00
sforman 3f9f558ebb the BinInt zero vanished? 2023-07-25 22:01:55 -07:00
sforman ced691279a Working on README, put defs in joy.py
I'm on an Ubuntu system right now and the split command doesn't have the
'-p' switch.  :(   I wasn't happy with that janky solution anyway.
2023-07-25 21:13:35 -07:00
sforman 975924f632 minor edits 2023-07-25 20:03:11 -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
sforman a34a2b1aab Compile on Ubuntu. 2023-07-24 11:29:39 -07:00
sforman 0fa617766f Make it compatible with Xerblin. 2023-07-24 11:29:06 -07:00
sforman 7cd5943d89 Minor edits. 2023-07-24 11:28:45 -07:00
Simon Forman f844dbab6c Minor cleanup. 2023-03-22 14:45:54 -07:00
Simon Forman 23d6fe727e i combinator.
On a lark I implemented it in recursive style, but I'm not going to keep
it that way.  I have to implement next_term() first and then I'll
uncomment i_joy_combinator().
2023-03-22 11:54:17 -07:00
Simon Forman 34798b7f33 concat 2023-03-22 08:41:09 -07:00
Simon Forman e83745e6ec cons 2023-03-21 12:34:28 -07:00
Simon Forman f8016a84e3 minor cleanup 2023-03-21 09:38:50 -07:00
Simon Forman 2841e53d4d first 2023-03-21 09:33:20 -07:00
Simon Forman f2fe704ba6 rest 2023-03-21 09:27:00 -07:00
Simon Forman 8986b8c619 rest CANNOT_TAKE_REST_OF_EMPTY_LIST 2023-03-21 09:19:12 -07:00
Simon Forman 242c98edc4 swap 2023-03-20 16:33:11 -07:00
Simon Forman 290dec513d Check for error after cons'ing term. 2023-03-18 14:13:51 -07:00
Simon Forman 142f17fd37 pop_any() 2023-03-18 12:48:59 -07:00
Simon Forman 83a5bc46df dup 2023-03-18 12:43:30 -07:00
Simon Forman 1600fa210c stack function. 2023-03-18 12:31:36 -07:00
Simon Forman fcdf8d416a pop() 2023-03-18 11:50:18 -07:00
Simon Forman 75ba7db666 Move pop_list(). 2023-03-18 11:41:16 -07:00
Simon Forman 8682135380 No reason to pass expression to function. 2023-03-18 11:40:19 -07:00
Simon Forman 13d9d83383 pop_list()
Kind of a misnomer, you have to take the tail() of the stack yourself.
This function only returns the list from TOS.
2023-03-18 11:31:38 -07:00
Simon Forman e39b9460bb Swaack and error macro. 2023-03-18 11:26:27 -07:00
Simon Forman 61039475a5 Use clear, set up for swaack. 2023-03-18 10:40:49 -07:00
Simon Forman 41438d10d9 Clear. 2023-03-17 12:10:18 -07:00
Simon Forman c9e620c281 Did i not commit this? 2023-03-10 14:11:54 -08:00
Simon Forman 7bfcdd2758 A start on the joy() interpeter. 2023-03-05 23:20:37 -08:00
Simon Forman c8360c7f7a Minor cleanup. 2023-03-05 23:04:56 -08:00
Simon Forman be214ce2b5 Catch unbalanced brackets. 2023-03-05 19:37:15 -08:00
Simon Forman 14e1b9728c Minor cleanup. 2023-03-05 19:26:34 -08:00
Simon Forman 65a2787630 Only allocate strings once.
That for loop in hash_fragment() is the gnarliest I've ever written.
2023-03-05 18:46:05 -08:00
Simon Forman 1a4be19f41 Combine tokenizer and parser.
I'm pretty happy with this. It's iterative rather than recursive so you
won't blow out the call stack if you want to parse a million brackets
(intermediate results are stored on (another) little stack.)  It scans
the string and builds lists and sublists as it goes, without wasting
cons cells.
2023-03-05 17:01:25 -08:00
Simon Forman bf3ba98d72 Thread error handling through tokenizer. 2023-03-05 15:20:22 -08:00
Simon Forman 0af1a9f7b5 It turns out the error machinery was working...
So I was memset'ing the hash table and string table /after/ setting up
the left- and right-bracket tokens! So then when I tried to print the
token list and ht_lookup() dutifully set the error code when it couldn't
find the strings in the hash table, the system properly quit printing
and halted.  D'oh!  That was a subtle one.  Obvious in hindsight.
2023-03-05 14:36:55 -08:00
Simon Forman 0a9cdba456 Fold parser code into joy_types.c
Add some docs, minor cleanup.
2023-03-04 20:50:34 -08:00
Simon Forman 87aef6f06d It seems to be working.
It took all expletive-deleted day but I finally nailed it down.  In the
end the last bug was I was decrementing a stack pointer /after/ trying
to load the item at the (empty) top of the stack.  Classic.

I still need to make it not re-allocate strings that it has already
interned, but beyond that I think it's fine.
2023-03-04 17:48:26 -08:00
Simon Forman 9cde4ed73d tokenate() and reverse_list_in_place() 2023-03-04 17:23:54 -08:00
Simon Forman dfd8f86e7b Use symbols for tokens for brackets.
Try a different tack on the parser.
2023-03-04 15:48:55 -08:00
Simon Forman 8b1db4bea7 Almost working parser. 2023-03-04 11:59:19 -08:00
Simon Forman 5ee30a70f9 Minor cleanup.
Some printing to see the machinery in action.
2023-03-04 08:31:40 -08:00
Simon Forman fc5992c23b Joy parser in NCC. 2023-03-04 08:25:32 -08:00
Simon Forman cf37e52550 A start on error handling. 2023-03-03 19:23:15 -08:00
Simon Forman 7284a7fcf3 Double hashing w/ extra bits of hash. 2023-03-03 14:52:26 -08:00
Simon Forman d8571d2063 A start on a hash table for symbols. 2023-03-03 12:05:40 -08:00
Simon Forman fd2ba3b67d Joy in UVM NCC code. 2023-03-03 07:31:52 -08:00
Simon Forman 5b6185209a A bunch of stuff. 2023-03-03 07:30:55 -08:00
Simon Forman f87ddbfa9e Minor cleanup. 2023-02-28 07:45:38 -08:00
Simon Forman 5423e0b239 Use defines to abstract font choice.
Clunky but now you only have to change the font name four time in one
place rather than N times in N places, eh?

Writing C again for the first time in ages (this and the Joy
interpreter) the using the preprocessor is like stone-age
meta-programming, from the lens of lisp it's like, "you do what to your
source code?".
2023-02-28 07:14:33 -08:00
Simon Forman 144e73ebc3 A different font.
It's easy enough to substitute a different font in the call to
Imagemagick's `convert` tool, but in the case of pixel fonts, it will
scale them, so you're not getting a proper bitmap of the pixels, you're
getting a kind of screenshot of the pixels.

I want to make a different machinery for bitmapped pixel fonts, and I
want to make a simple DEFINE-based way to pick them without having to
edit your source code,  e.g. #define font_data font_PublicPixel_22_data
yeah?

After that, simple affine transforms for fake 3D..
2023-02-28 06:53:31 -08:00
Simon Forman 58f779c430 Wu-ish lines. 2023-02-27 19:27:32 -08:00
Simon Forman 300cf2f24d Mostly working Wu-ish algorithm. 2023-02-27 16:29:45 -08:00
Simon Forman ee8ba58441 Minor cleanup. 2023-02-26 21:46:05 -08:00
Simon Forman 61527f3e64 Cicada bg, needs work.
Not as pretty as I'd hoped.

Putting a pin in Wu lines for tonight.  I'll lick it in the morning when
I'm fresh.
2023-02-26 21:02:57 -08:00
Simon Forman 2c6dc4fee5 I clearly don't know what I'm doing.
Go to sleep!  Think, then type!
2023-02-26 20:39:32 -08:00
Simon Forman 42068ebcb6 Is this fun? Kinda.
I should break out the graph papaer and Abrash's Black Book and figure
out WTF I'm doing rather than just noodling around, eh?
2023-02-26 20:02:14 -08:00
Simon Forman 66d687bba6 Horizontal proto-Wu. 2023-02-26 19:06:15 -08:00
Simon Forman d8e20c0ce9 Horz/vert lines and boxes. 2023-02-26 18:07:47 -08:00
Simon Forman c385ad096b Aw, exit() doesn't work?
In any event, I can live with esc-to-quit (is there a callback to hook
into?)
2023-02-26 16:55:53 -08:00
Simon Forman e18eb36c52 But KEY_BACKSPACE doesn't seem to fire?
Maybe worth a bug report?
2023-02-26 16:53:41 -08:00
Simon Forman 50e34c70cb Ha ha! The escape-to-quit behavior...
...seems to be baked into the UVM.
2023-02-26 16:52:02 -08:00
Simon Forman f8f27ed83e Add if..else ladder for keys.
I just noticed that I have KEY_BACKSPACE for the exit key rather than
KEY_ESCAPE as I had thought, yet escape key surely does exit the
program!
2023-02-26 16:49:11 -08:00
Simon Forman e1c81d2c1c Escape key exits program. 2023-02-26 16:27:23 -08:00
Simon Forman 14e15b08a1 minor edits
I don't think this is any better?
2023-02-26 16:04:54 -08:00