Skip to main content

Translating c++ to java using python code interpreter in GPT-4:

This took time to formulate.

As the inputs needed to achieve it took a while. Namely it took a while to find the right approach to it.

And then it hit me. If I really wanted to be lazy about translating the entire library, I'd get a system trained on data such as programming languages and compiler knowledge.

Then I had to consider the thought "Well, most of it is c++ jazz to say or do not c++ jazz. How much could one simplify the transpiling process with as few look ups needed".

Now, I personally would have figured out how to do it all by hand and dealt with the wrist pain later.

But, the fact that it came close to matching 99% of my request, it even helpfully put in a snippet for saying "i don't man", helps. because it also helpfully told me which files it might consider looking in for those pieces to be less "UNKNOWN_TYPE" types.

And what came next was even better. Connecting the runtime parts.

The first server will run in cpython3.

The second will run in jython2.7.3.

The cpython server makes its functions & classes available to jython.

jython makes its functions available to brython.js

Brython.js itself gets to access either or in all likelihood.

This makes it easier to have each of the parts that need to be backend stay such and things that need to be front end stay such.

Only now the last trick for everyone else using acorn.io & kubernetes tools: "how do I get rid of a database, volumes, & secrets from my stack?"

This is what would be needed with jython runtime:

import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
multicall = xmlrpclib.MultiCall(proxy)
multicall.add(7,3)
multicall.subtract(7,3)
multicall.multiply(7,3)
multicall.divide(7,3)
result = multicall()
print "7+3=%d, 7-3=%d, 7*3=%d, 7/3=%d" % tuple(result)
                                    

And this is what you'd need in cpython:

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
with SimpleXMLRPCServer(("localhost", 8000),
                        requestHandler=RequestHandler) as server:
    server.register_introspection_functions()

    # Register pow() function; this will use the value of
    # pow.__name__ as the name, which is just 'pow'.
    server.register_function(pow)

    # Register a function under a different name
    def adder_function(x,y):
        return x + y
    server.register_function(adder_function, 'add')

    # Register an instance; all the methods of the instance are
    # published as XML-RPC methods (in this case, just 'mul').
    class MyFuncs:
        def mul(self, x, y):
            return x * y

    server.register_instance(MyFuncs())

    # Run the server's main loop
    server.serve_forever()

Comments

Popular posts from this blog

Brain Emulator Conceptual Framework