Dear David,
So far I've been able to generate Poly/ML style codetree for a subset of Spad language used in OpenAxiom. The codetree is written into a text file. As an example, for the following spad function:
foo (a : Integer) : Integer == a := a + 1 a
I currently generate the following intermediate code:
DECL #1{0 uses} = LAMBDA( foo(2) CL=false CR=0 LEV=0 LOCALS=0 ARGS=G ARGLIVES= RES=G CLOS=() BLOCK(BLOCK(DECL #2{0 uses} = RECCONSTR(PARAM(0,1), PARAM(0,2)); BLOCK(DECL #3{0 uses} = GLOBAL (FUN "run_call2(1)", LAMBDAINLINE( runcall2(1) CL=false CR=0 LEV=0 LOCALS=0 ARGS=G ARGLIVES= RES=G CLOS=() LOCAL(1,1) G $(INDIRECT(0, PARAM(0,1)) G, INDIRECT(1, PARAM(0,1)) G)){LAMBDA} ) (*GLOBAL*){early} G $(INDIRECT(0, LOCAL(0, 2)), LIT1 G); DECL #4{0 uses} = LOCAL(0, 3); LOCAL(0, 4) ) ) )){LAMBDA}"
I also wrote a ML library which reads in and parses the codetree string. Does my current approach look sensible to you? What would you suggest if improvements are needed?
I'm thinking that the next step for me is to call Poly/ML middle functions that would take the codetree and evaluate the entire codetree for a Spad function (and then hopefully a Spad domain.) I've read the code and the documentation in the codetree source code files. Is there any way for me to call the codetree functions as a library in my ML code?
Thanks,
Yue
I'm thinking that the next step for me is to call Poly/ML middle functions that would take the codetree and evaluate the entire codetree for a Spad function (and then hopefully a Spad domain.) I've read the code and the documentation in the codetree source code files. Is there any way for me to call the codetree functions as a library in my ML code?
I've added a CodeTree sub-structure to the PolyML structure which makes the codetree available to ML programs. This just passes through the internal construction functions. To build a codetree you just call the constructor functions and then call PolyML.CodeTree.genCode to generate the machine code. You can turn on switches such as PolyML.Compiler.codetree and PolyML.Compiler.assemblyCode to display the code you've built and the machine code that the code generator has produced from it. To use this you will need to rebuild the compiler with make compiler in the polyml directory.
There's a little example in the samplecode directory to get you started.
Regards, David
On 02/28/2011 07:55 AM, David Matthews wrote:
I'm thinking that the next step for me is to call Poly/ML middle functions that would take the codetree and evaluate the entire codetree for a Spad function (and then hopefully a Spad domain.) I've read the code and the documentation in the codetree source code files. Is there any way for me to call the codetree functions as a library in my ML code?
I've added a CodeTree sub-structure to the PolyML structure which makes the codetree available to ML programs. This just passes through the internal construction functions. To build a codetree you just call the constructor functions and then call PolyML.CodeTree.genCode to generate the machine code. You can turn on switches such as PolyML.Compiler.codetree and PolyML.Compiler.assemblyCode to display the code you've built and the machine code that the code generator has produced from it. To use this you will need to rebuild the compiler with make compiler in the polyml directory.
There's a little example in the samplecode directory to get you started.
I've updated my version and tried out the sample code which works quite well. Thank you very much David!
Best,
Yue
On 28/02/2011 17:07, Yue Li wrote:
On 02/28/2011 07:55 AM, David Matthews wrote:
I've added a CodeTree sub-structure to the PolyML structure which makes the codetree available to ML programs. This just passes through the internal construction functions. To build a codetree you just call the constructor functions and then call PolyML.CodeTree.genCode to generate the machine code. You can turn on switches such as PolyML.Compiler.codetree and PolyML.Compiler.assemblyCode to display the code you've built and the machine code that the code generator has produced from it. To use this you will need to rebuild the compiler with make compiler in the polyml directory.
There's a little example in the samplecode directory to get you started.
I've updated my version and tried out the sample code which works quite well. Thank you very much David!
I've added a little bit to this to make it possible to extract the codetree from an ML variable. It was already possible to use an ML variable as a constant but this works better when the ML is an inline function. I've updated the sample code with an example of "Hello World" using TextIO.print and string concatenation.
Regards, David
On 03/01/2011 08:37 AM, David Matthews wrote:
On 28/02/2011 17:07, Yue Li wrote:
On 02/28/2011 07:55 AM, David Matthews wrote:
I've added a CodeTree sub-structure to the PolyML structure which makes the codetree available to ML programs. This just passes through the internal construction functions. To build a codetree you just call the constructor functions and then call PolyML.CodeTree.genCode to generate the machine code. You can turn on switches such as PolyML.Compiler.codetree and PolyML.Compiler.assemblyCode to display the code you've built and the machine code that the code generator has produced from it. To use this you will need to rebuild the compiler with make compiler in the polyml directory.
There's a little example in the samplecode directory to get you started.
I've updated my version and tried out the sample code which works quite well. Thank you very much David!
I've added a little bit to this to make it possible to extract the codetree from an ML variable. It was already possible to use an ML variable as a constant but this works better when the ML is an inline function. I've updated the sample code with an example of "Hello World" using TextIO.print and string concatenation.
I appreciate your great work David! I've tried the new example. The two examples are very helpful. I'm now trying to add the calls to these constructor functions inside my code tree parser.
Thanks,
Yue