Browse files

Adding creation of BlockReturnType subclass.

  • Loading branch information...
1 parent f3282f4 commit 1b33d07271e5cdea7f591701b261a73c564386b9 @jamesladd jamesladd committed Mar 24, 2012
View
3 src/main/java/st/redline/PrimObject.java
@@ -74,7 +74,7 @@ public PrimObject block(String name) {
}
public static SmalltalkClassLoader smalltalkClassLoader() {
- return (SmalltalkClassLoader) Thread.currentThread().getContextClassLoader();
+ return SmalltalkClassLoader.instance();
}
static PrimObject createBlockInstance(PrimObject block) {
@@ -335,6 +335,7 @@ PrimObject resolveObject(String name) {
PrimObject loadObject(String name) {
try {
+ System.out.println("Loading: " + name);
return (PrimObject) Class.forName(name, true, classLoader()).newInstance();
} catch (Exception e) {
throw RedlineException.withCause(e);
View
6 src/main/java/st/redline/bootstrap/ImportMethod.java
@@ -29,7 +29,7 @@ public static String makeFullyQualifiedPath(String packageName, String className
return smalltalkClassLoader.findSources(String.valueOf(importPaths));
}
- private SmalltalkClassLoader smalltalkClassLoader() {
- return SmalltalkClassLoader.instance();
- }
+// private SmalltalkClassLoader smalltalkClassLoader() {
+// return SmalltalkClassLoader.instance();
+// }
}
View
31 src/main/java/st/redline/compiler/BlockReturnTypeCreator.java
@@ -1,5 +1,7 @@
package st.redline.compiler;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import st.redline.ClassPathUtilities;
import st.redline.PrimObject;
@@ -14,13 +16,11 @@
private final String fullyQualifiedClassName;
- public BlockReturnTypeCreator(String className, String packageName) {
- fullyQualifiedClassName = ClassPathUtilities.classNameToFullyQualifiedClassName(packageName, className);
+ public BlockReturnTypeCreator(String fullyQualifedClassName) {
+ this.fullyQualifiedClassName = fullyQualifedClassName.replace(".", "/");
}
void create() {
- System.out.println("***********************");
- System.out.println("BlockReturnTypeCreator creating: " + fullyQualifiedClassName);
if (registry.containsKey(fullyQualifiedClassName))
return;
registry.put(fullyQualifiedClassName, fullyQualifiedClassName);
@@ -29,13 +29,28 @@ void create() {
private void loadClass(byte[] aClass) {
try {
- PrimObject.smalltalkClassLoader().defineClass(aClass).newInstance();
+ PrimObject.smalltalkClassLoader().defineClass(aClass);
} catch (Exception e) {
throw new RedlineException(e);
}
}
- private byte[] createClass() {
- return null;
- }
+ private byte[] createClass() {
+ ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ writer.visit(V1_5, ACC_PUBLIC + ACC_SUPER, fullyQualifiedClassName, null, "st/redline/BlockReturn", null);
+ createAnswerArgumentConstructor(writer);
+ writer.visitEnd();
+ return writer.toByteArray();
+ }
+
+ private void createAnswerArgumentConstructor(ClassWriter writer) {
+ MethodVisitor mv = writer.visitMethod(ACC_PUBLIC, "<init>", "(Lst/redline/PrimObject;)V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, "st/redline/BlockReturn", "<init>", "(Lst/redline/PrimObject;)V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(2, 2);
+ mv.visitEnd();
+ }
}
View
5 src/main/java/st/redline/compiler/ProgramAnalyser.java
@@ -1,6 +1,7 @@
/* Redline Smalltalk, Copyright (c) James C. Ladd. All rights reserved. See LICENSE in the root of this distribution */
package st.redline.compiler;
+import st.redline.ClassPathUtilities;
import st.redline.RedlineException;
import st.redline.SmalltalkClassLoader;
@@ -112,7 +113,7 @@ public void visitBegin(SimpleExpression simpleExpression) {
}
void createBlockReturnType(String blockReturnType) {
- new BlockReturnTypeCreator(blockReturnType, packageName).create();
+ new BlockReturnTypeCreator(blockReturnType).create();
}
public void visitEnd(SimpleExpression simpleExpression) {
@@ -206,7 +207,7 @@ public SmalltalkClassLoader smalltalkClassLoader() {
}
String blockReturnType() {
- return analyser.className() + "$MAnswer";
+ return ClassPathUtilities.classNameToFullyQualifiedClassName(packageName, analyser.className() + "$MAnswer");
}
String createBlockName() {

0 comments on commit 1b33d07

Please sign in to comment.