In which programming language (not using the garbage collector) can you generate a method code, save it and use it at the next program start?

What methods are there at all?

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer to the participants Grundy , aleksandr barakin , cheops , iluxa1810 , Nicolas Chabanovsky ♦ Nov 7 '16 at 4:36 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    .NET with JIT compilation fit? In general, the C compiler is written in C, so it is possible to generate a plug-in and connect it even though the next time you run it. - VladD
  • And what is the difference between a bytecode of a virtual machine (say, LLVM) and a bytecode of a physical processor? Besides, what about the bytecode of the physical processor more fuss and worse portability? - drdaeman Nov.
  • 3
    And, in general, on any (Turing-full), because compiler can be written in any language. The task “to generate a bytecode from a certain language and execute it” is reduced to this. The compiler does not need to write in interpreted languages ​​where eval can be used, but they all have virtual machines. But, for some reason, I suspect that the author does not want to write a compiler. Therefore, I ask - why do you need it, what goal (code generation is clearly not an end in itself) do you want to receive? Perhaps here it is not necessary ... - drdaeman Nov.
  • Well, you can remember forth. There is no need to wait for the next launch. - alexlz
  • There are VMs in Forte, but no OOP 8-) - Dmitry Ponyatov

4 answers 4

It is possible in many, different only the level of service provided to you by the compiler / standard library. If you can generate a data file, then you can generate an executable module.

For example, in .NET you can compile the source of the .NET class into an assembly , since the compiler is part of the .NET framework. After successful compilation, you can immediately connect the assembly through Assembly.Load.

Java has a similar opportunity.

With other languages ​​that do not contain a compiler in the runtime library, you will have to independently generate the executable module in the format of your OS. This task is feasible, because compilers are usually written in the target language. Another question is whether you want to take on this rather time-consuming task.

PS: .NET is not executed by the virtual machine, it has a JIT compiler.

  • one
    LLVM is also JIT, but even from the name you can see the words “virtual machine.” As for me, the edge has long since been erased and there is no sense to avoid virtual machines, as a rule. - drdaeman Nov.
  • @drdaeman: you are right, but for some reason, the vehicle wants precisely that there is no virtual machine. Apparently, he needs to have something more complicated than eval . Although eval is not a feature of "interpreted" languages. - VladD
  • There is no VM in LLVM, it is a pure compilator framework. But in its API (at least what I read) there is no such thing as a "class" and, accordingly, a "method", perhaps in newer versions added. - Dmitry Ponyatov

The question is some muddy. In the statement of the author, almost any programming language falls under this definition. Any PL in one way or another uses bytecode (object code) that can be used the next time it is run. Even SQL has the concept of a precompiled query, I will generally keep silent about all sorts of different interpreters - of which there are countless numbers - there, too, there is a concept of some kind of bytecode, which can be saved and run as needed. Az sinner is also the author of one scripting tongue (still used in the depths of one very big office) - so I know what I'm talking about.

  • 4 hours ago I changed the question, did you probably still answer the old one an hour ago, which mentions the virtual machine? - a4eptp

The author is so cunning.

In which programming language ( not using a virtual machine ) can you generate a method code, save it and use it at the next program start?

If we can generate the code and save it, then it needs to be done so that you can easily download it back. Load binary code? It is not comfortable.

If you want such flexibility, then in any case you will have to use some kind of bytecode. Or download directly as the source code.

By topic: Common Lisp comes to mind.

  • Interested in "upload directly as source code", does this technology have a name? what yap is it available in? - a4eptp
  • In Common Lisp this is for sure. Probably also with Factor and with Prolog, but not sure. Term? Introspection is close - but not that. - Vladimir Gordeev
  • @Vladimir: why is loading binary code uncomfortable? LoadLibrary + GetProcAddress (Windows native), Assembly.Load + Assembly.GetTypes (.NET) - what could be simpler? - VladD
  • @Vladimir Gordeev: In order not to remain in the Microsoft ecosystem, there is also dlopen + dlsym and a few verbose tricks for Java . - VladD
  • Well, yes, the usual loading of the external lib - Vladimir Gordeev

More detailed information is needed about the specific application, the environment in which it is planned to be launched, and the requirements of the TOR, otherwise the only answer is to use the make command to start the application, rebuilding it from C ++ source codes (the only mainstream language is OOP and without garbage collection).

In fact, it’s quite a solution - zaphaet all of your proprieritarny commercially significant code in a binary library without source code, and drag the modified part in the source code, and compile it into an executable file when you start the application.

Otherwise, you can dummy to create another supercompiler for the metaprogramming language 8-)

  • which out of the box is able to work with AST-trees (and not with strings containing a program - as the presentation of the program, it is the trees that first come to mind)
  • contains directly in the specification of the language (a set of formal rules) and not its implementation (distribution for a specific platform) means of storage / input / output of the AST tree in text form (text file, string variable, entry in the text field of the database)
  • conversion functionality of AST-trees (pattern matching, unification, rewriting of elements with backtracking)
  • includes tools for describing the grammars of all actively used programming languages ​​to use ready-made working code
  • supports all dynamic data structures (for example lists, trees, stacks, hashed map / dict from Python) + standard library of algorithms on these structures
  • knows all compiler tops from Dragon Book (from parsing to code generator) and one hundred and fifty optimization algorithms from GCC
  • Dynamic optimizing compiler into machine code (based on LLVM) built into the runtime library
  • manual memory management or controlled garbage collection
  • OOP model (classes, objects, interfaces, inheritance, all tops in the best SmallTalk traditions)
  • and all this is optimized for hard realtime on a cloud of multiprocessor multi-threaded SMP nodes of beowulf HA / HPC clusters on reconfigurable processors with dynamic FPGA / SRAM hardware architecture (and figli trivia 8-)
  • in vain you are minus, this is (1) a full detailed answer to the question and (2) computer science trends for the next 20 years, especially if real-life quantum computers appear - all the applications should be adapted for new hardware architectures, and the creation of tools and languages ​​for program transformation in this case, the thing is inevitable - Dmitry Ponyatov