Embed C or ASM in newLISP

Notices and updates
Post Reply
Lutz
Posts: 5285
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Embed C or ASM in newLISP

Post by Lutz »


unixtechie
Posts: 65
Joined: Sat Sep 06, 2008 6:30 am

Embed newlisp into a speed champion web server?

Post 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/
.
Last edited by unixtechie on Mon Jan 02, 2012 8:27 pm, edited 1 time in total.

rowanthorpe
Posts: 1
Joined: Mon Jan 02, 2012 12:13 pm

Re: Embed C or ASM in newLISP

Post 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...).

VadimTukaev
Posts: 2
Joined: Sat Jun 14, 2014 7:58 am

Re: Embed C or ASM in newLISP

Post 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.

ralph.ronnquist
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Embed C or ASM in newLISP

Post 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

VadimTukaev
Posts: 2
Joined: Sat Jun 14, 2014 7:58 am

Re: Embed C or ASM in newLISP

Post 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

ralph.ronnquist
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: Embed C or ASM in newLISP

Post by ralph.ronnquist »

Right. My apologies.

abaddon1234
Posts: 21
Joined: Mon Sep 14, 2015 3:09 am

Re: Embed C or ASM in newLISP

Post by abaddon1234 »

how to write newLisp code for utilizing that function?
สมัครบาคาร่าออนไลน์

Post Reply