Home > Blockchain >  Can I run code in different languages in "containers" and access each variable?
Can I run code in different languages in "containers" and access each variable?

Time:12-12

I know the question sounds dumb, but I couldn't frame it properly. So, here's what I am expecting.

 #This is some programming language.
java_file = new Java()#creates a temp java named java_file which will be interpreted when this program runs. 
py_file = new Python()#creates a temp py file 
java_file{
/*The usual class declaration*/
x=6
}
x=java_file.get(x)#this variable is of the hypothetical language.
py_file{
print(MAIN.x)#MAIN.x refers to the previous defined value.
}

I am thinking of a programming language that supports all the language by running each in a seperate container, So is there any way to do that? Preferably using Java. This looks like sockets, but I want to take full control of each container, like being able to halt and resume and read internal states.

CodePudding user response:

Here's an idea: you could run local servers in each container to connect to, and in you're Java program which controls them you can create processes wrapped by a Language class which can send control packets to the servers using Sockets. This can also be used to access variables. See the concept below:

public abstract class Language {
    public Object getVariable(String variableName) {
        sendPacketToServer("get_variable "   variableName);
        return readResponse();
    }
}

Note: this leaves your options quite flexible and allows for remote control of programs too. However, if you wish you could send and receive data using process input and output streams.

CodePudding user response:

The short answer:

  • It is possible in theory assuming that you can specify clear semantics for this hybrid language.

  • In practice, I know of no (implemented) hybrid language that operates like this. Not even remotely.


The first (BIG) problem would be specifying a language that allowed you to embed other languages within it AND reference elements defined in the embedded languages. The syntax and semantics needs to take account of the existing syntax and semantics of all of the languages that you are embedding. Complicated, I imagine.

The second (BIG) problem would be implementing it.

  • Do you try use existing implementations for the embedded languages? How does the framework language control the embedded executions? How does it stop the executions at the appropriate points and extract / inject values?

  • Do you build new implementations (e.g. interpreters) that run in the "virtual machine" of the framework language? Would the performance be acceptable?


It is an interesting idea ... but would the end result be worth it? Are there convincing use-cases? Do you have a way to resource a few man-years of effort (from people who know how to design and implement languages) to see if it will work?

  • Related