Embed C or ASM in newLISP

Notices and updates

Embed C or ASM in newLISP

Postby Lutz » Mon Jan 02, 2012 3:07 am

Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Embed newlisp into a speed champion web server?

Postby unixtechie » Mon Jan 02, 2012 3:20 pm

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/
.
Last edited by unixtechie on Mon Jan 02, 2012 8:27 pm, edited 1 time in total.
unixtechie
 
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

Re: Embed C or ASM in newLISP

Postby rowanthorpe » Mon Jan 02, 2012 4:46 pm

...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...).
rowanthorpe
 
Posts: 1
Joined: Mon Jan 02, 2012 12:13 pm

Re: Embed C or ASM in newLISP

Postby VadimTukaev » Sat Jun 14, 2014 10:04 am

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.
VadimTukaev
 
Posts: 2
Joined: Sat Jun 14, 2014 7:58 am

Re: Embed C or ASM in newLISP

Postby ralph.ronnquist » Sat Jun 14, 2014 11:34 am

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/shared-libraries-linux-gcc.html
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Embed C or ASM in newLISP

Postby VadimTukaev » Sat Jun 14, 2014 12:43 pm

Apparently you have not read the previous posts. It was about the framework "define-ext" - https://github.com/rowanthorpe/define-e ... /USAGE.txt
VadimTukaev
 
Posts: 2
Joined: Sat Jun 14, 2014 7:58 am

Re: Embed C or ASM in newLISP

Postby ralph.ronnquist » Sat Jun 14, 2014 1:31 pm

Right. My apologies.
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Embed C or ASM in newLISP

Postby abaddon1234 » Thu Nov 19, 2015 4:02 am

how to write newLisp code for utilizing that function?
สมัครบาคาร่าออนไลน์
abaddon1234
 
Posts: 21
Joined: Mon Sep 14, 2015 3:09 am


Return to newLISP newS

Who is online

Users browsing this forum: No registered users and 1 guest

cron