Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the installation process #534

Merged
merged 8 commits into from
May 19, 2022
Merged

Rework the installation process #534

merged 8 commits into from
May 19, 2022

Conversation

hugomg
Copy link
Member

@hugomg hugomg commented May 14, 2022

This pull request allows the Pallene compiler to be called from any directory, not just the root of the repository. This fixes #16. Hooray! To accomplish this, I did the following things:

The first thing I did was move the custom Lua interpreter to a separate repository. This custom Lua only exposes the Lua internals and can be used for both Pallene and LuaAOT. This custom Lua only needs to be updated sporadically, whenever a new version of Lua comes out.

The second thing I did was to move all the things in the pallene_core.c into the pallene_core.h. Effectively, this statically links the pallene standard library into the generated modules. Maybe it is a bit bloated, but it has the advantage that when we build pallenec itself, we don't need to compile any C code.

The third thing I did was to copy paste the contents of the pallene_core.h into the generated C code, instead of using an #include directive. (Btw, I also renamed it from pallene_core.h to pallenelib.lua) This produces a larger C file but has the advantage that we don't need to worry about passing any -I flags to the compiler.

Some limitations that we can fix later:

  1. The custom Lua must be installed to /usr or /usr/local. This way the C compiler can find the header files. To support other Lua installation locations we will need to add a way to customize the C compiler flags. Or find a way to ask Luarocks to compile the files for us (#516).
  2. We still need to add some code to check if the Lua release matches the one that Pallene expects (#18).
  3. If the Pallene library grows, we may want to create a reusable shared library for the parts that aren't inline functions. (We could also find ways to reduce the size of the library. For example, by reducing the number of builtins that we implement)
  4. The test suite is running substantially slower. I don't know the cause yet. Maybe it is slower compilation of the generated file?

@hugomg hugomg marked this pull request as draft May 14, 2022 20:47
@hugomg hugomg force-pushed the lua-core branch 9 times, most recently from b6cb540 to b59124b Compare May 14, 2022 23:56
CONTRIBUTING.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@@ -0,0 +1,623 @@
-- /*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning C code from a Lua code is a bit weird when viewing in a text editor 😅
How would you feel if this was a regular old C file and we read it using io before returning the code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is certainly awkward. I have to manually switch the syntax highlighting color in my editor. The main problem is where to install the file, and how to find the path to the file after it is installed. I believe that with Luarocks you need to use a third-party library: https://github.com/hishamhm/datafile. I didn't want to add a dependency just so we could use this one file, but maybe it's clearer than the current hack... What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also in favor of having inline C code over adding a dependency.
But I also wonder why we can't just do io.open("./pallene.h", "r") to read the header.

Copy link
Member Author

@hugomg hugomg May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things I want to achieve with this PR is to no longer care about the current working directory (issue #16). From now on, using relative paths is forbidden.

We are moving that to a separate repository
This makes it easier to compiler the generated C code because it no
longer needs to #include the pallene_core.h, passing the right -I flags.
We also don't have to compile & install the Pallene standard library,
meaning that the Pallene compiler is now a pure Lua project.

The catch here is that we now statically link the Pallene standard
library, which adds up to 10 KB of extra size to every binary produced
with Pallene. I think that is an acceptable tradeoff for now, to
keep things simple. If this turns out to be a problem later then we can
reintroduce the pallenelib.so.
As well as some old files that were also missing...
Dunno why these showed up now, but might was well.
Since we have custom Lua & Luarocks now, we can't use the leafo actions.
@hugomg hugomg marked this pull request as ready for review May 17, 2022 22:52
@hugomg hugomg requested a review from srijan-paul May 18, 2022 14:40
@hugomg
Copy link
Member Author

hugomg commented May 18, 2022

I think I'm happy enough with this branch to remove the "draft" flag now. I think it is a great step towards making easier to install Pallene, but it does have some quirky aspects. For example, you need to separately install our patched version of Lua... Would love to hear if this kind of thing is OK or if it runs into problems for any of you.

@srijan-paul
Copy link
Member

I'm on a macbook rn (work machine).
I'll can test these changes out on a mac later today

@hugomg
Copy link
Member Author

hugomg commented May 19, 2022

Cool. The next step I'm planning after this PR is #516 and it will be very helpful to be able to test that on a Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the compiler to be called from any directory
2 participants