slang-users mailing list

[2021 Date Index] [2021 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Using the tcc module


On Sat, 23 Jan 2021 at 20:37, Αγαθοκλής <aga.chatzimanikas@xxxxxxxxx> wrote:

> Hi Sebastian,
>
> On Thu, Jan 21, at 04:15 Sebastian Gniazdowski wrote:
> > Hi,
> > I saw some exciting posts in the archives about an embedded, jit C
> compiler
> > – tcc. I wonder how the support is going, is the module in the main
> S-Lang
> > distribution maybe?
>
> I wrote that code, mostly because i wanted constant String Type (char *)
> objects
> generated at runtime.
>

Could you elaborate, i.e.: why it isn't to do so with S-Lang only code?

Sure, you can run any C code that tinycc can complile, but this is an
> inherently
> unsafe operation by default, since an access violation will crash the
> interpreter.
>

I think that this is not a problem. It's up to the user to write a
segfault-free C code, and that's not that hard.


> > In general I would like to know how to run my first C code
> (`printf("hi");`,
> > probably) from within a S-Lang script.
>
> Assuming you've compiled the code, it is easy as that:
>
> slsh> () = evalfile ("./Tcc.sl");
> slsh> variable s = Tcc.init ();
> slsh> s.execute_string  (`
> #include <stdio.h>
> int main (int argc, char **argv) {
>   return fprintf (stdout, "%s", argv[0]);
> }`, ["my message\n"]);
>
> or if you want to add an intrinsic function:
>
> slsh> s.sladd_intrinsic_function  ("myprint", 1, "c_myprint",
> Integer_Type, [String_Type], `#include <stdio.h>
>         int c_myprint (char *msg) {return fprintf (stdout, "%s", msg);}`);
> 0
> slsh> myprint ("my message\n");
>

Thanks, I'll be adding the tcc support today, I will let you know how it
went.

Be aware that you can not reuse a state, that's a tcc limitation, so you
> have to
> run s.delete () to free that state, and call the s.new () method to
> instantiate it
> again.
>

Does s.new() return some object, or does it initialize `s`?


> > I'm working on a S-Lang support in Midnight Commander (mcedit, mainly),
> I think that
> > such C support would be a nice extension/sophistication of it.
>
> But it's been a long since i've used that code, and i do not know if
> current tcc
> development, broke some code. This is used to compile, against the
> development git
> tree, the so called mob branch. The last formal release is quite ancient,
> and i
> think most people, that are using the compiler use that branch, but
> distributions
> might package the formal release.
>

I'm going to ship the tcc module with MC.

Because of this, i believe it will be quite hard for proper user support
> and guarantee
> stabilization and correctness.
>

I will see how it'll go, the top performance of compiled C code is the
azimuth for me.

Best regards,
>  ag
>
> p.s.,
> Hi John :-). Strange, a week ago, i was thinking to write you after so
> much time!
> Still i use the S-Lang enviroment, but I'm developing in C nowadays.
>
> Hopefully everyone of you, will stay safe.
>

-- 
Sebastian Gniazdowski

[2021 date index] [2021 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]