Page 1 of 1

Embed C or ASM in newLISP

Posted: Mon Jan 02, 2012 3:07 am
by Lutz

Embed newlisp into a speed champion web server?

Posted: Mon Jan 02, 2012 3:20 pm
by unixtechie
ah, 'tcc', a brilliant piece of software (by the author of QEMU emulator), which allows on-the-fly compilation and execution.

There exists a whole web server based on tcc, which is number one in speed comparisons (pushing several hundred thousand responses per second), called G-WAN.
The authors distribute it as a compiled bundle, do not allow to look inside nor change anything, but at the same time give it away for free and prohibit charging money for it.

That server does static pages of course, but relies mostly on tcc on-the-fly compilation for the 'application server' part of it. This whole speed champion server is scripted in C, which scriplet handlers or filters are included as a source code and rely in the built-in tcc to run.

Actually, taking one of the sample C scriplets and slightly modifying it one could turn Newlisp into a persistent server language for G-WAN.
They could communicate over a pair of pipes, as one example, with web headers and (RESTful) requests sent over in the simplest format possible.

One could go the other way, i.e. compile and include newlisp as a shared library into the G-WAN file hierarchy, so that C scriplets would be able to use embedded newlisp from C - but somehow that seems to me a more cumbersome approach.

http://gwan.ch/
.

Re: Embed C or ASM in newLISP

Posted: Mon Jan 02, 2012 4:46 pm
by rowanthorpe
...although TCC is awesome and deserves all the credit and attention it gets, and more (as do Fabrice Ballard's other creations like FFmpeg, etc) one of the most important - but not immediately apparent - features of the "define-ext" module is that it has been written in a modular fashion to allow easy extension for arbitrary compilable languages (not just C and ASM). The "plugins" for ASM and C were just provided bundled-in (using imported functions from tinycc) as an example, and should provide easy templates for adapting to embed any language for which there is a dynamic lib compiler, or even to implement ASM or C using other libraries if you prefer... Also, it simplifies embedding (pre-compiled?) object code too, making it as easy as writing a (define...).

Re: Embed C or ASM in newLISP

Posted: Sat Jun 14, 2014 10:04 am
by VadimTukaev
It seems to be "killer-feature" to me. I have some C-code and I want to link it by high-level language.

Unfortunately, I can't understand, how to use it to embed obj files. I read USAGE.txt already! Example:

Code: Select all

#define MAX_SIZ 100

static double per[MAX_SIZ];

double* c_percents(double* arr, int siz)
{
    if( siz > MAX_SIZ) siz = MAX_SIZ;
    double sum = 0.0;
    int i;
    for( i = 0; i < siz; ++i ) {
        sum += arr[i];
    }
    sum = 100.0 / sum;
    for( i = 0; i < siz; ++i ) {
        per[i] = arr[i] * sum;
    }
    return per;
}
I compiled it to object file c_percents.o. So, how to write newLisp code for utilizing that function? It must convert any of the lists (1 2 3 4), (300 600 900 1200) or (0.15 0.3 0.45 0.6) to (10 20 30 40). Plizzz! :)

P.S. Sorry for my ugly english, I'm russian.

Re: Embed C or ASM in newLISP

Posted: Sat Jun 14, 2014 11:34 am
by ralph.ronnquist
You need to make it into "shared libraries", then run newlisp with LD_LIBRARY_PATH set up, then declare the imported functions with (import ...), then Bob's your uncle.
It's amazingly simple (until you come to the data sharing)
Maybe this is a help
http://www.cprogramming.com/tutorial/sh ... x-gcc.html

Re: Embed C or ASM in newLISP

Posted: Sat Jun 14, 2014 12:43 pm
by VadimTukaev
Apparently you have not read the previous posts. It was about the framework "define-ext" - https://github.com/rowanthorpe/define-e ... /USAGE.txt

Re: Embed C or ASM in newLISP

Posted: Sat Jun 14, 2014 1:31 pm
by ralph.ronnquist
Right. My apologies.

Re: Embed C or ASM in newLISP

Posted: Thu Nov 19, 2015 4:02 am
by abaddon1234
how to write newLisp code for utilizing that function?
สมัครบาคาร่าออนไลน์