3

I'm lookign for a langage with the following features :

  • SWIG-compatible, or similar. Compatibility with C++ should be easy :

C, C++, AllegroCL, C# - Mono, C# - MS .NET, CFFI, CHICKEN, CLISP, D, Go , Guile, Java, Lua, MzScheme/Racket, Ocaml, Octave, Perl, PHP, Python, R, Ruby, Tcl/Tk

  • Statically typed : No myObject.CompletelyNewFieldWithUnknownSideEffects = GuessWhat() like in Lua. No isinstance() like in php. No newVariableOfUnknownType = foo() like in Python. Preferably strongly typed, too ( "Hello"+"0" rather than "Hello"+0 ) :

C, C++, C#, D, Go, Java, Ocaml, PHP, Ruby ? Other ?

  • Can be compiled at runtime ( and exec("gcc plugin.cpp")! doesn't count ! ) into whatever asm/intermediate langage.

C : libCLang, Ch; C++ : Ch; Any scripting langage; Other ?

  • Can be compiled (either offline or at runtime) into a x86 .dll/.so, OR .cpp

C : gcc, libClang, etc; C++; C#; D; Python; Go; OCaml; Lua : LuaJIT; Ruby : Ludicrous

  • Preferably with debugger :)

TL;DR

I would like a statically typed, embeddable scripting langage which can be compiled for perf.

Ideas ? Comments ? Input of any kind ? Thanks !

EDIT Valid propositions so far :

So there is much more hope than I originally thought :) Thank you all ! I'll keep investigating and will accept an answer when I have more experience on the subject.

Calvin1602
  • 9,413
  • 2
  • 44
  • 55
  • 1
    Racket ships with a statically-typed language - Typed Racket, but I do not know it interoperates with SWIG. – Begemoth May 06 '11 at 16:37
  • I'm curious why you say "exec("gcc plugin.cpp") doesn't count!" Combine it with dlopen, and you've got an entirely functional way of compiling code and running it from within the process that compiled it. It's a bit heavy on filesystem use, admittedly, but it ought to work fine other than that. – Brooks Moses May 08 '11 at 05:24
  • It would work... on MY machine. Reboot on Windows : doesn't work. No Cygwin : doesn't work. Bad gcc version : doesn't work. Bad file permissions : doesn't work. PATH not correct : doesn't work. – Calvin1602 May 08 '11 at 19:11
  • On Windows you will need to ship your program with MinGW just like Git ships with MSYS. There is another problem you will need to build your C++ program with MinGW and not with Visual C++ since ABI of the compilers differ. – Begemoth May 09 '11 at 07:00

4 Answers4

1

Ruby is in each of your lists, and the Rubinius compiler compiles it down to bytecode. Does that meet your needs?

2nd try: Have you looked at Boo: "an object oriented statically typed programming language for the Common Language Infrastructure"

AShelly
  • 34,686
  • 15
  • 91
  • 152
  • Ruby isn't statically typed, so no. – Tom Anderson May 06 '11 at 17:16
  • Boo doesn't seem to be easily embeddable from C++. But you have a good point though : .NET seems good for this, and you can compile C# from C# : http://support.microsoft.com/kb/304655/en-us – Calvin1602 May 06 '11 at 21:02
  • Accepted as solution. Not for Boo but for C#, which can be embedded through SWIG, and compiled on the fly with Mono : http://docs.go-mono.com/Mono.CSharp.Evaluator.Compile%20%28string%29 . – Calvin1602 May 10 '11 at 13:41
1

This is almost certainly not a useful answer, but Java does actually fit all your bullet points.

  • You can talk to native code with JNI, JNA, or SWIG.
  • As statically typed as it gets without needing a PhD
  • Can be compiled at runtime through the compiler API
  • Is compiled to native code at runtime by some excellent compilers (and there are offline compilers too)
  • Has a number of debuggers

The problem is that it's not exactly a scripting language; you need to write quite a lot of boilerplate to get a small task done, and the APIs are usually fairly involved.

Tom Anderson
  • 46,189
  • 17
  • 92
  • 133
1

Have a look at OpenCL, perhaps? It's designed around being a C-like language that is compiled at runtime, but AMD's latest SDKs provide the ability to do offline pre-compilation as well.

It's not an obvious choice, because it's promoted for use on GPUs, but it's designed to be more broadly-applicable than that and can be run just as well on ordinary CPUs.

Brooks Moses
  • 9,267
  • 2
  • 33
  • 57
  • +1 for unexpected, original and clever answer. I'll need more time to form a better opinion though :) – Calvin1602 May 06 '11 at 21:05
  • Correct me if I'm wrong, but I don't think it's possible to call C++ functions from a kernel. This is a no-go for a scripting language. Too bad. – Calvin1602 May 06 '11 at 21:17
  • You're right; I'd missed that part of the requirements. I think you may be able to call inline C++ functions to some extent, but calling non-inline C++ (or C, for that matter) code wouldn't work. – Brooks Moses May 08 '11 at 05:12
0

I'm pretty sure D is compilable and can be run as a script.

HRÓÐÓLFR
  • 5,842
  • 5
  • 32
  • 35