title: inline domain specific language to generate Java code
body: <p>I work on a program that performs matrix and vector operation in Java. The multiple function call and object creation that occurs in my current implementation makes it sluggish and difficult to understand.</p>
  
  <p>For instance I want to update the position of a mechanical point, by speed integration:</p>
  
  <pre><code>void update(Vector3 position, Vector3 speed, float dt){
     Vector3 displacement = new Vector3(speed);
     displacement.assignMul(dt);
     position.assignAdd(displacement);
  }
  </code></pre>
  
  <p>Here the API is not natural, and in addition I need to allocate an build a new Vector3 reference. Obviously i measured a great performance improvement on real uses case when inlining the computation this way:</p>
  
  <pre><code>void update(Vector3 position, Vector3 speed, float dt){
     position.x += speed.x * dt;
     position.y += speed.y * dt;
     position.z += speed.z * dt;
  }
  </code></pre>
  
  <p>Is there any tool that could generate this code from a domain specific language on demand? A Cog like syntax would be nice. (Cog is a code generation tool from Ned Batchelder)</p>
  
  <pre><code>void update(Vector3 position, Vector3 speed, float dt){
     // [[[DSL position += speed * dt ]]] 
     position.x += speed.x * dt;//Generated Code
     position.y += speed.y * dt;//Generated Code
     position.z += speed.z * dt;//Generated Code
     // [[[END]]]
  }
  </code></pre>