pointless-lang / pointless

Pointless: a scripting language for learning and fun
https://ptls.dev
MIT License
122 stars 9 forks source link

Running pointless system wide #3

Closed andrewnc closed 4 years ago

andrewnc commented 4 years ago

I want to be able to add an alias in my ~/.bash_profile or ~/.bashrc files that points to the pointless binary and then run pointless files across my machine. However, when running from a different directory, I see the following error.

Assertion failed: (false), function getPrelude, file files/files.c, line 277.
zsh: abort      ./pointless/pointless pointless/programs/frame.ptls

Do you have guidance on how to run the pointless binary system wide?

As an aside, I also attempted to move the pointless binary to my /usr/local/bin without success.

allisio commented 4 years ago

Hey, Andrew.

I ran into the same problem and took a rather heavy-handed approach to fixing it, namely modifying this line in files/files.c to be an absolute path ("/home/$USER/.../pointless/lib/prelude") and recompiling.

The good news is this is a known issue (see the very bottom), and fixing it should just be a matter of settings things up for a proper make install.

andrewnc commented 4 years ago

Ah! Excellent. That fixed my issue no problem. I'm thinking about trying my hand at writing a REPL for pointless. I've never done that before, but always wanted to try. Should I open a new issue to track progress? Are there other things you want done first?

allisio commented 4 years ago

Awesome! Glad you got it sorted.

I've just finished up the foundations of my Pointless environment, which include:

Overall, it's pretty solid, but I concede that there's a lack of "fluidity" that a REPL could certainly help with. I'm making good use of the |> operator to "test as I go", but I still have to comment out one output = ... line in favor of another often enough for it to be a pain point.

The lack of mutable state in Pointless seems like it'd lend itself quite well to a simple append-execute loop where you're just piling definitions into a temporary file, but you'd have to get a little creative with juggling the output variable between evaluations. It definitely seems doable, though, and I think it'd be an excellent way for you to test the waters.

I've run into a handful of bugs/inconsistencies in the VM that I'm trying to wrap my head around fixing at the moment, but I'd be glad to provide what assistance I'm able if you do decide to try your hand at that REPL.

averynortonsmith commented 4 years ago

Thank you both for your interest / contributions! Pointless currently looks for the prelude source files relative to the location of the binary, which is why moving it to another directory doesn't work. I've been looking into the unix xxd command as a way to compile the prelude source into the binary itself to fix this issue and I hope to have a solution soon.

Any effort towards making a REPL would be very welcome. A simple approach could be to try to make a "replay-based" REPL - which, as I understand it works by basically re-running the entire REPL input as a program for each new line of input. The fact that Pointless evaluates definitions lazily could help make this approach more performant. Some things you'd have to solve to get this working: 1) deciding whether the REPL should allow duplicate definitions / shadowing and modifying the compiler to accommodate this and 2) figuring out how to handle errors from compilation / evaluation without having the whole REPL crash (perhaps replace the call to exit() on an error with some form of setjmp / longjmp?).

You could also write a REPL by compiling each new line of input and feeding each resulting chunk of bytecode into the VM, although this would bring its own set of complications.

Either way, you'll have some decisions to make about how exactly the REPL should work - should the REPL accept expressions, or only definitions? How does the REPL respond to output commands?

Happy to help with any questions you have!

averynortonsmith commented 4 years ago

I myself could definitely use some help automating the installation process down the something like make install - it's not something I've done before

averynortonsmith commented 4 years ago

Also, following up on vim syntax highlighting, here are the files I've been using for sublime:

https://gist.github.com/averynortonsmith/bc5c12a0c1f492f4684cd3bcb4bf7eb6 https://gist.github.com/averynortonsmith/97517c8508fff8a576c574b4a7149c0d https://gist.github.com/averynortonsmith/3e4862fad2970370fb8df3f926ceef57

allisio commented 4 years ago

Thank you for making something so interesting and open to contribution! I went ahead and submitted a pull request for a basic installation setup that may or may not sit well with you, but regardless embedding the prelude is an awesome idea that I'd love to see come to fruition, though I don't know how much I'd be able to help on that front; still working up the nerve to look into the guts of this thing. 😅

Aye, what you're calling "replay-based" is what I meant by "append-execute". I went ahead and took that approach for this thing, but it's extremely limited at the moment. Granted, it works, but you have to be fairly careful with what you feed it. It won't crash, mind you‒seeing as how it attempts to swallow all errors and keep on chugging‒but that can be a curse in disguise. I'd like to flesh it out, but I just wanted to fling out a decent first blush to be able to run simple Pointless programs on a whim directly from a command line. It's obvious the much saner approach would be to interface with the compiler, but that's not yet my wheelhouse.

Finally, I went ahead and created a repository for my configs as well. I suppose we should strive for parity on that front at some point, but I suppose it's all subjective preference in the end.

averynortonsmith commented 4 years ago

I'm excited to try your REPL! I've been a bit busy these last couple of days but I'll give it a look tomorrow. Also, do you want me to add your brainfuck example to the Pointless site?

In the process of prototyping Pointless, I wrote a second implementation in Dart - I might try to fix that up and upload it as well. I figure the Dart implementation could be quicker for testing / adding new features than C, although I'm still trying to decide if introducing the second code-base is a good idea. Any thoughts?

andrewnc commented 4 years ago

I definitely agree that a dart implementation would speed up developer time. Are the two implementations at feature parity?

averynortonsmith commented 4 years ago

I'll have to do some work to get the Dart implementation caught up with the C version, but feature parity is the goal. Dart also has a pretty solid Dart -> JS compiler which could be used to make an online Pointless development environment. I'll start working on the Dart code again and hopefully add it to a new branch soon.

averynortonsmith commented 4 years ago

(added a project entry for tracking development ideas / goals: https://github.com/pointless-lang/pointless/projects/1)

averynortonsmith commented 4 years ago

Hey all,

Sorry to keep you waiting - I've made some big updates to the project implementation which should address the issues mentioned above: the Pointless binary can now be run from any directory (although it still uses a relative path to look for the prelude files). This should make it much more amenable to being called from a .bashrc alias.

I'm hoping that the new implementation will be a lot easier to fiddle around with, and I'm hoping to stabilize the language and start working more incrementally (pushing changes as I go). And I'm always happy to accept contributions to the source code, standard library, editor support ... anything!