-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3e2709c
Showing
23 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="compiler-src"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="lib" path="lib/AeminiumGPU.jar"/> | ||
<classpathentry kind="lib" path="lib/javacl-1.0-beta-6-shaded.jar"/> | ||
<classpathentry kind="lib" path="lib/javacl-demos-1.0-beta-6-shaded.jar"/> | ||
<classpathentry kind="lib" path="compiler-lib/spoon-core-1.4-jar-with-dependencies.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin | ||
spooned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>SpoonCompilerTest</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#Fri Mar 11 14:37:20 EST 2011 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project name="AeminiumGPU" basedir="." default="main"> | ||
|
||
<property name="src.dir" value="src"/> | ||
<property name="build.dir" value="bin"/> | ||
<property name="lib.dir" value="lib"/> | ||
<property name ="main-class" value="code.SimpleMap" /> | ||
|
||
|
||
<property name="spooned.dir" value="spooned"/> | ||
<property name="compiler.src.dir" value="compiler-src"/> | ||
<property name="compiler.build.dir" value="compiler"/> | ||
<property name="compiler.lib.dir" value="compiler-lib"/> | ||
|
||
<path id="classpath"> | ||
<path refid="compiler.classpath" /> | ||
<fileset dir="${lib.dir}" includes="**/*.jar"/> | ||
</path> | ||
|
||
<path id="compiler.classpath"> | ||
<pathelement location="${compiler.build.dir}" /> | ||
<fileset dir="${compiler.lib.dir}" includes="**/*.jar"/> | ||
<fileset dir="${lib.dir}" includes="**/*.jar"/> | ||
</path> | ||
|
||
<target name="compile-compiler"> | ||
<mkdir dir="${compiler.build.dir}"/> | ||
<javac srcdir="${compiler.src.dir}" destdir="${compiler.build.dir}" classpathref="compiler.classpath" /> | ||
</target> | ||
|
||
<target name="precompile" depends="compile-compiler"> | ||
<!-- define spoon task --> | ||
<taskdef name="spoon" classname="spoon.SpoonTask" classpathref="compiler.classpath"/> | ||
|
||
<spoon classpathref="compiler.classpath" verbose= "true"> | ||
<sourceSet dir="${src.dir}" /> | ||
<templateset dir="${compiler.src.dir}" includes="template/" /> | ||
<processor type="processing.MapLambdaProcessor" /> | ||
</spoon> | ||
</target> | ||
|
||
<target name="compile" depends="precompile"> | ||
<mkdir dir="${build.dir}"/> | ||
<javac srcdir="${spooned.dir}" destdir="${build.dir}" classpathref="classpath" /> | ||
</target> | ||
|
||
<target name="main" depends="compile"></target> | ||
|
||
<target name="run" depends="compile"> | ||
<java fork="true" classname="${main-class}"> | ||
<classpath> | ||
<path location="${build.dir}" /> | ||
<path refid="classpath"/> | ||
</classpath> | ||
</java> | ||
</target> | ||
|
||
|
||
</project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package processing; | ||
|
||
public class Environment { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package processing; | ||
|
||
import spoon.processing.AbstractProcessor; | ||
import spoon.reflect.code.CtBlock; | ||
import spoon.reflect.code.CtCodeElement; | ||
import spoon.reflect.code.CtReturn; | ||
import spoon.reflect.code.CtStatement; | ||
import spoon.reflect.code.CtVariableAccess; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.template.Substitution; | ||
import spoon.template.Template; | ||
import template.MapLambdaTemplate; | ||
|
||
public class MapLambdaProcessor<T> extends AbstractProcessor<CtMethod<T>>{ | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public void process(CtMethod<T> target) { | ||
if (target.getSimpleName().equals("call")) { | ||
CtClass parent = target.getParent(CtClass.class); | ||
int c = parent.getMethods().size(); | ||
/* | ||
Set<CtMethod> methods = parent.getMethods(); | ||
parent.setMethods(methods); | ||
*/ | ||
|
||
createGetSourceMethod(target); | ||
int c2 = parent.getMethods().size(); | ||
System.out.println("Alcides says:" + target.getSimpleName() + " c:" + c + "->" + c2); | ||
|
||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private StringBuilder visitExpr(CtCodeElement expr, StringBuilder b) { | ||
StringBuilder n = new StringBuilder(); | ||
if (expr instanceof CtBlock) { | ||
// Iterate over statements | ||
for (CtStatement st : ((CtBlock<T>) expr).getStatements()) { | ||
n.append(visitExpr(st, b)); | ||
n.append("\n"); | ||
} | ||
|
||
} else if (expr instanceof CtReturn) { | ||
CtReturn<T> ret = (CtReturn<T>) expr; | ||
n.append("return "); | ||
n.append(visitExpr(ret.getReturnedExpression(), b)); | ||
n.append(";"); | ||
|
||
} else if (expr instanceof CtVariableAccess) { | ||
CtVariableAccess<?> va = (CtVariableAccess<?>) expr; | ||
if (va.getVariable().getSimpleName().equals("input")) { | ||
n.append("input"); | ||
} else { | ||
// TODO: Check if valid | ||
System.out.println("Type of var " + va.getVariable().getSimpleName() + " is " + va.getVariable().getType()); | ||
|
||
b.append(va.getVariable().getSimpleName()); | ||
} | ||
|
||
} else { | ||
System.out.println("Unknown type:" + expr.getClass()); | ||
} | ||
|
||
return n; | ||
} | ||
|
||
private CtMethod<T> createGetSourceMethod(CtMethod<T> target) { | ||
// Template | ||
|
||
StringBuilder clCode = new StringBuilder(); | ||
CtBlock<T> body = target.getBody(); | ||
clCode = visitExpr(body, clCode); | ||
|
||
System.out.println(":::: Final Code ::::"); | ||
System.out.println(clCode); | ||
System.out.println(":: End Final Code ::"); | ||
Template t = new MapLambdaTemplate(clCode.toString()); | ||
Substitution.insertAllMethods(target.getParent(CtClass.class), t); | ||
return null; | ||
/* | ||
CtMethod<T> n = new CtMethodImpl<T>(); | ||
// Signature | ||
n.setSimpleName("getSource2"); | ||
n.setParameters(new ArrayList()); | ||
// Return Type | ||
CtTypeReference void_ = new CtTypeReferenceImpl<T>(); | ||
void_.setSimpleName("java.lang.String"); | ||
n.setType(void_); | ||
// Body | ||
return n;*/ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package template; | ||
|
||
import spoon.template.Local; | ||
import spoon.template.Parameter; | ||
import spoon.template.Template; | ||
|
||
public class MapLambdaTemplate implements Template { | ||
|
||
|
||
@Parameter | ||
String _code_; | ||
|
||
public String getSource() { | ||
return _code_; | ||
} | ||
|
||
@Local | ||
public MapLambdaTemplate(String code) { | ||
_code_ = code; | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package code; | ||
|
||
import aeminium.gpu.lists.IntList; | ||
import aeminium.gpu.lists.PList; | ||
import aeminium.gpu.operations.Lambda; | ||
|
||
public class SimpleMap { | ||
public static void main(String[] args) { | ||
IntList in = new IntList(); | ||
in.add(1); | ||
in.add(2); | ||
in.add(5); | ||
PList<Integer> out = in.map(new Lambda<Integer, Integer>() { | ||
|
||
@Override | ||
public Integer call(Integer input) { | ||
return input; | ||
} | ||
|
||
}); | ||
|
||
for (int i = 0; i < out.size(); i++) { | ||
System.out.println(i + ": " + out.get(i)); | ||
} | ||
|
||
} | ||
} |