Is using luajit vs lua C bindings actually faster? - c

Is using the LuaJIT library better than using the lua C official library in terms of performance ?
From I have read (the only what was possible), the luajit's feature is only the FFI interface. But I have also read that luajit adds some optimizations to the standard lua-c API but could not find any information about this unfortunately.
I don't understand, does it impact the performance when used without its FFI interface? There is also no any information about how it compiles the code, during the lua_loadfile or anywhen else?
To be more concrete, I want to use lua via the C api and not the luajit FFI interface by making a shared library which lua script can use then.

Related

Interacting with the filesystem in a custom programming language

I'm writing a standard library for my programming language which is compiled to LLVM IR. I've also stumbled upon this interesting post Custom Programming Language ~ How to interact with the Operating System but I'm stuck on implementing interaction with the filesystem.
My language is quite similar to C, so I will use C for examples.
In C we have a struct called FILE and we can pass it to fopen, fclose etc...
How can I implement this datatype myself? Do I just create a struct with similar fields and it will work?
How do popular LLVM-based languages implement this? For example Jai, Zig, Swift ...
Generally, you pick the smallest possible base platform and then define matching function and struct types for that interface only. For example, "my language only works on linux for now and my platform is those syscalls I need, and no more" or "my language only uses the exported symbols in this C library that I write myself". I've seen both. The goal is to have a small cross-language interface.
The kernel will use lots of code, the C library may use lots of other libraries or the kernel, but the cross-language interface is kept small, since cross-language calls/types are so ticklish.

Using AMPL C++ Apis for C?

I've looked for C APIs, but I've only found C++ API's that can't be used inside a C code.
Are there any C (not C++ or C#) APIs or another way for using AMPL in a C code?
There being no C API for AMPL as far as I can tell, your best bet is to write C++ wrappers for the tasks you want to perform, assigning them C linkage (extern "C") and building them with a C++ compiler. Done correctly, these will be callable from C code. The C code will not be able to handle AMPL objects directly, however, so your wrappers will need to perform some kind of data marshaling in both directions.
I do recommend wrappers specific to your particular tasks, as opposed to generic wrappers for the whole API. I suspect that you would find the latter a much larger and more difficult task.

Include libraries in other languages in a C application

My general question is this: what's the most common way to include libraries in other languages in a C application?
For example, if I have a Ruby library intended for doing function X, and a Python library for doing function Y, how can I write a program in C (the language, that is) that uses the functions in each?
I've seen wrappers that give access to C libraries in these higher languages, but are there wrappers that go the other way? Is there a common way of handling this in general?
Are these native-code libraries (i.e. have they been compiled?) Or are these source libraries (i.e. a bunch of text files containing Ruby source code)?
If the former, libraries in a language like Ruby or Lua or so usually have a published binary interface ("ABI"). This is low-level documentation that describes how their libraries and its functions work under the hood. Often, those are defined in C or C++, or whatever language was used to implement the interpreter/compiler for Ruby itself.
So you'd have to find that documentation, and find out how to call the parts you are interested in. Some languages even use the same ABI as C does, and you just need to create a header file that matches the contents of the library and you can call it directly (This is how you integrate e.g. assembler and C, or even C++, which you can get to generate straight C functions).
If the latter, you usually need to find an embeddable version of the language, and find out how to run a script from inside your application (This is how Lua is usually used, for example).
But are you sure you need the given Ruby libraries? Often, common libraries are implemented using a C or C++ library under the hood, and then just wrapped for scripting languages, so you can just skip the scripting translation layer and use the (maybe slightly more low-level) library yourself.
PS - there are also automatic wrapper generators, like SWIG, that will read a file in one language and write the translation code for you.

system calls using c library

Generally, systems provide a library or API that sits between normal programs and the operating system. On Unix-like systems, that API is usually part of an implementation of the C library (libc), such as glibc, that provides wrapper functions for the system calls.Functions like write(),read(),open().. are used to make system calls from a C program.Does it mean that if a java program has to make a system call then at the lowest level it has to call these C library functions ?If so, then how..???
If you really need to you can do that with the Java Native Interface (JNI).
Beware it is not for the feint of heart; the JVM usually can do what you want.
One use-case of JNI is using OpenSSL for crypto in Java; this used to be substantially faster when I tested it (it was nearly 10 years ago).
http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html
I assume you don't want to know how to do it in Java since the question is not tagged as a java question.
So the libc is the right way to do it but, for information purposes, in linux, you can use the syscall function. The syscall function can use an Int 0x80 signal, a sysenter instruction or something else depending on the platform.
Introduction to System Calls in Linux
In Java, this is done using native Methods. These are methods declared with the native modifier and (similarly to abstract methods) no body, whose real implementation is written in a platform-dependent language, usually C.
Additional native method implementations may be runtime loaded using System.loadLibrary(String libraryName).

Why is there no C port of LAPACK 3.5.0 available?

My goal is to use LAPACK with Emscripten. Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95.
The CLAPACK project (http://www.netlib.org/clapack/) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1.
So my question now is: why is there no newer port of LAPACK to C? Are there any suggestion how to achieve my goal anyway?
Thanks in advance!
I managed to port LAPACKE, the LAPACK C-wrapper to javascript. Nevertheless I can't work with it, because the wrapper uses internal the FORTRAN routines. How would I embed these in emscripten?
E.g. the function LAPACKE_cgbcon uses LAPACKE_xerbla which is only available in FORTRAN. Why would I benefit from porting a wrapper?
The new version uses Fortran 95. There exist no automatic translation tool from it to C.
There is a new tool called fable available, but it also supports only a small subset of Fortran 90. They claimed to be able to translate part of LAPACK 3.2.1, but there are no news about full and more recent LAPACK.
Do you really need the code in C? Can't you just call it from C, possibly using an existing C wrapper?
For the official C API see http://www.netlib.org/lapack/#_standard_c_language_apis_for_lapack

Resources