lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, 9 Mar 2020 at 21:37, Sean Conner <sean@conman.org> wrote:
> > So I am looking for ideas / suggestions for what the api for this
> > library look like.
> > I need a C api to start with. I have been looking at other libraries
> > to see what they do, but none stands out as ideal.
>
>   Without knowing what you looked at, there's LLVM for the code generation
> part, and clang for more of the lexing and parsing.
>

I am familiar with LLVM api of course. The C api is not bad  but of
course it is for generating LLVM bytecode.
I have only briefly looked at Clang parser api - will look into it in depth.

>   I have worked with TCC (Tiny C Compiler) which can be embedded into a
> larger context as you can call it as a library.  It does all the steps,
> lexer, parser, code generation (but very little optimization). The official
> repo is at <https://repo.or.cz/tinycc.git>.

Does it offer api for each layer?
My intention is that if you just need the lexer, or the parser, then
you should be able to use the library for that without having to
bother with the rest.
The libtcc.h seems more about just using tcc as a black box.

>
>   I have wrapped TCC up as a Lua module.  I'm not sure how well it works
> with the latest TCC (I stopped updating my TCC several years ago---the
> development model of TCC is a bit of a mess really).  But if you just want
> to check it out:
>
>         The low level module:
>
>         https://github.com/spc476/lua-conmanorg/blob/master/src/tcc.c
>
>         The slightly higher module that allows one to load Lua modules
>         directly from C code:
>
>         https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.lua
>
>   I'm not sure if this will help you in any way, but who knows?  It might.
>

Thank you. I had a quick look. As mentioned above my goal is slightly
different. That is, how to expose the lexer? Or the parser?

> > Suggestions welcome. If you know of a great example then I would
> > appreciate if you can give me a reference to the project.
>
>   Hmm ... have you heard of nanopass compilers?
>
>         http://lambda-the-ultimate.org/node/1589
>

No, I hadn't. Thank you for the link.

Regards