Mjolnir.jl icon indicating copy to clipboard operation
Mjolnir.jl copied to clipboard

Minimum example of transpiling

Open kskyten opened this issue 4 years ago • 0 comments

I'm interested in using Mjolnir to transpile Julia to GLSL shaders. Since JSExpr implements a javascript AST I though it would be a good stepping stone to create a minimal example of transpiling to javascript first. How would I transpile the following julia code

function adder(x, y)
    x + y
end

function multiplier(x, y)
    x * y
end

function nested(x, y)
    multiplier(x, adder(x, y))
end

into the equivalent javascript?

function adder(x, y){
    return x+y;
}

function multiplier(x, y){
    return x * y;
}

function nested(x, y){
    return multiplier(x, adder(x, y));
}

Thus far I've come up with this:

using Mjolnir
using JSExpr
using IRTools.Inner: IR, BasicBlock, Statement

import JSExpr: crawl

function JSEpr.crawl(trace::IR)
    crawl.(blocks)
end
function JSEpr.crawl(block::BasicBlock)
    statements = crawl.(block.stmts)
end
function JSEpr.crawl(statement::Statement)
    crawl(statement.expr)
end

kskyten avatar Dec 16 '20 17:12 kskyten