
Hi Maciek, I all as I announced in my previous e-mail here are some ideas on how to use metavm for genjs2. I think the best way to use metavm for your purposes is to write a bunch of MicroInstruction classes designed for emitting source code. For example I guess that some rpython low level instruction need to be mapped to infix operator (such as int_add & co.) while others need to be mapped to some support function (such as int_abs). You could write something like this: class InfixOperator(MicroInstruction): def __init__(self, operator): self.operator = operator def render(self, generator, op): generator.emit('(%s %s %s)' %\ (op.args[0], self.operator, op.args[1]) class CallHelper(MicroInstruction): def __init__(self, helper): self.helper = helper def render(self, generator, op): arglist = ... # compute arglist from op.args generator.emit('%s(%s)' % (self.helper, arglist) Then, in your opcodes.py: opcodes = { 'int_add': InfixOperator('+'), 'int_abs': CallHelper('abs') } The difficult thing here is to design the Generator interface in a way that is suitable for emitting both asm code and source code. Maybe we try to separate the two worlds, in this way: genoo/metavm.py --------------- class Generator: def function_signature(self, graph): pass # put here all methods shared by both AsmGenerator and SourceGenerator class StackBasedGenerator(Generator): def emit(self, instr, *args): pass def call(self, func_name): pass def load(self, v): pass def store(self, v): pass ... class SourceCodeGenerator(Generator): def emit(self, expression): pass # and so on genoo/function.py ----------------- class Function(Node, Generator): # some shared code ... class StackBasedFunction(Node, StackBasedGenerator): ... class SourceCodeFunction(Node, SourceCodeGenerator): ... gencli/function.py ------------------ class CliFunction(StackBasedFucntion): ... genjs2/function.py ------------------ class JsFunction(SourceCodeFunction): ... Once we have this design, each MicroInstruction subclass can decide whether to target the generic Generator interface or one of its subinterfaces. ciao Anto
participants (1)
-
Antonio Cuni