Interesting project:
http://sourceforge.net/projects/defineext/
Embed C or ASM in newLISP
-
- Posts: 65
- Joined: Sat Sep 06, 2008 6:30 am
Embed newlisp into a speed champion web server?
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/
.
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.
-
- Posts: 1
- Joined: Mon Jan 02, 2012 12:13 pm
Re: Embed C or ASM in newLISP
...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...).
-
- Posts: 2
- Joined: Sat Jun 14, 2014 7:58 am
Re: Embed C or ASM in newLISP
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:
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.
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;
}
P.S. Sorry for my ugly english, I'm russian.
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: Embed C or ASM in newLISP
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
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
-
- Posts: 2
- Joined: Sat Jun 14, 2014 7:58 am
Re: Embed C or ASM in newLISP
Apparently you have not read the previous posts. It was about the framework "define-ext" - https://github.com/rowanthorpe/define-e ... /USAGE.txt
-
- Posts: 228
- Joined: Mon Jun 02, 2014 1:40 am
- Location: Melbourne, Australia
Re: Embed C or ASM in newLISP
Right. My apologies.
-
- Posts: 21
- Joined: Mon Sep 14, 2015 3:09 am
Re: Embed C or ASM in newLISP
how to write newLisp code for utilizing that function?
สมัครบาคาร่าออนไลน์
สมัครบาคาร่าออนไลน์