From 70543fc1ef9733fb754cecda96805349cb36de32 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 21 Dec 2024 15:13:05 -0400 Subject: Add shebangs and x bit to executables With run.sh, we can build and run the file in one go. This means we can also use it as an interpreter in a shebang line and properly use the Unix executable bit. This is pretty cool and gives a few advantages: running any executable file is just `exec file.hs` or even `./file.hs`, finding all executables is `fd -t x`, you don't need to specify or know an `out` name to run something, execution of a program is standardized. There is a hack to get this to work. In C and Common Lisp, `#!` is illegal syntax, so I had to use shell syntax to invoke run.sh, call it on the current file, and then exit the shell script. Meanwhile, run.sh takes the file and evals the whole thing, building and running it. As long as either `//` or `;` is a comment character in the target language, then this works. Maybe a better thing to do would be to pre-process the file and remove the `#!` before passing it to the C compiler, like [ryanmjacobs/c][1] and [tcc][2]? However this won't work in Lisp because then I can't just load the file directly into the repl, so maybe the comment hack needs to stay. [1]: https://github.com/ryanmjacobs/c/tree/master [2]: https://repo.or.cz/tinycc.git/blob/HEAD:/tccrun.c --- Omni/Namespace.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Omni/Namespace.hs') diff --git a/Omni/Namespace.hs b/Omni/Namespace.hs index ef8cefd..5884507 100644 --- a/Omni/Namespace.hs +++ b/Omni/Namespace.hs @@ -17,6 +17,7 @@ module Omni.Namespace fromPythonModule, isCab, groupByExt, + dotSeparated, ) where @@ -93,13 +94,17 @@ fromHaskellContent c = case Regex.findFirstInfix haskellModule c of Regex.many (name <|> dot)) <*> pure Hs +dotSeparated :: [String] -> String +dotSeparated = joinWith "." + toModule :: Namespace -> String -toModule (Namespace parts Hs) = joinWith "." parts -toModule (Namespace parts Py) = joinWith "." parts +toModule (Namespace parts Hs) = dotSeparated parts +toModule (Namespace parts Py) = dotSeparated parts toModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")" toModule (Namespace parts Rs) = joinWith "::" parts toModule (Namespace parts C) = joinWith "/" parts <> ".c" toModule (Namespace parts Nix) = joinWith "/" parts <> ".nix" +toModule (Namespace parts Lisp) = "(" ++ joinWith " " parts ++ ")" toModule (Namespace {..}) = panic <| "toModule not implemented for " <> show ext toHaskellModule :: Namespace -> String -- cgit v1.2.3