XMLVM

 
An XML-based Programming Language
XMLVM logo
 
 

Overview

XMLVM is an XML-based programming language. It is build on the virtual machine concept and is closely modelled after the Java virtual machine. In fact, one way to look at XMLVM is that it is an XML representation of the contents of a Java class file, thereby defining an assembly syntax for Java class files. To the right you can see the classic "Hello World" example in Java. Below is the resulting XMLVM that was automatically generated from HelloWorld.class. Note that this XML also contains the implementation of methods between the <code> tags using instructions defined by the Java virtual machine. One of those instructions is <iadd> for adding two integers. Java's virtual machine is a stack based machine, and the <iadd> instruction pops off two integer arguments and pushes the sum back onto the stack. The following XSL-template shows how <iadd> would be translated to JavaScript:

<xsl:template match="iadd">
<xsl:text>
__op2 = __stack[--__sp]; // Pop operand 1
__op1 = __stack[--__sp]; // Pop operand 2
__stack[__sp++] = __op1 + __op2; // Push sum
</xsl:text>
</xsl:template>

XMLVM simply mimics the stack machine in the target language. Variables such as __stack and __sp are used to mimic the stack and are declared for each method of a class. Thus once the XMLVM has been created, it can easily be translated to another high-level programming language via XSLT stylesheets. Click here to see what the "Hello World" looks like in JavaScript. Click here to see the C++ version of "Hello World". We use XMLVM to translate Java applications to JavaScript in order to migrate the code to a web browser. Check out the XML11 homepage for a demo.

public class HelloWorld
{

    static public void main(String[] args)
    {
        System.out.println("Hello World");
    }

}

<xmlvm>
<!-- Generated: Fri Oct 28 09:09:09 PDT 2005 -->
<class name="HelloWorld" isPublic="true" extends="java.lang.Object">
<method name="<init>" isPublic="true" stack="1" locals="1">
<signature>
<return type="void"/>
</signature>
<code>
<var name="this" id="0" type="org.xmlvm.test.HelloWorld"/>
<aload type="java.lang.Object" index="0"/>
<invokespecial class-type="java.lang.Object" method="<init>">
<signature>
<return type="void"/>
</signature>
</invokespecial>
<return/>
</code>
</method>
<method name="main" isPublic="true" isStatic="true" stack="2" locals="1">
<signature>
<return type="void"/>
<parameter type="java.lang.String[]"/>
</signature>
<code>
<var name="args" id="0" type="java.lang.String[]"/>
<getstatic class-type="java.lang.System" type="java.io.PrintStream" field="out"/>
<ldc type="java.lang.String" value="Hello World"/>
<invokevirtual class-type="java.io.PrintStream" method="println">
<signature>
<return type="void"/>
<parameter type="java.lang.String"/>
</signature>
</invokevirtual>
<return/>
</code>
</method>
</class>
</xmlvm>

SourceForge.net Logo