Skip to content

Commit

Permalink
GH-392 Implement type instance in REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Mar 14, 2020
1 parent dd21282 commit e22c70f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public TypeInstance createInstance(ProcessStack stack, Class<?>[] parameterTypes

@SuppressWarnings("unchecked")
private Constructor<? extends TypeInstance> getConstructor(Class<?>[] parameterTypes) {
parameterTypes = ArrayUtils.merge(TypeFrame.class, parameterTypes, Class[]::new);

try {
return (Constructor<? extends TypeInstance>) type.getAssociatedClass().fetchImplementation().getConstructor(ArrayUtils.merge(TypeFrame.class, parameterTypes, Class[]::new));
return (Constructor<? extends TypeInstance>) type.getAssociatedClass().fetchImplementation().getConstructor(parameterTypes);
} catch (NoSuchMethodException e) {
throw new PandaFrameworkException(type.getAssociatedClass().fetchImplementation() + " does not implement " + Arrays.toString(parameterTypes) + " constructor");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ private void type(Module module, String name, Class<?> primitiveClass) {
}

private Type generate(Module module, Class<?> primitiveClass, String name) {
Type primitiveType = PandaTypeUtils.generateOf(module, "Primitive" + name, primitiveClass);

Type type = PandaTypeUtils.generateOf(module, name, ClassUtils.getNonPrimitiveClass(primitiveClass));
type.addBase(primitiveType);

return type;
PandaTypeUtils.generateOf(module, "Primitive" + name, primitiveClass);
return PandaTypeUtils.generateOf(module, name, ClassUtils.getNonPrimitiveClass(primitiveClass));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.panda_lang.framework.design.runtime.Process;
import org.panda_lang.framework.design.runtime.ProcessStack;
import org.panda_lang.framework.language.architecture.statement.PandaVariableData;
import org.panda_lang.framework.language.architecture.type.PandaConstructor;
import org.panda_lang.framework.language.architecture.type.PandaMethod;
import org.panda_lang.framework.language.architecture.type.PandaType;
import org.panda_lang.framework.language.architecture.type.TypeComponents;
Expand Down Expand Up @@ -65,6 +66,12 @@ public final class ReplCreator {
context.withComponent(TypeComponents.PROTOTYPE, type);
this.typeScope = new TypeScope(PandaSourceLocationUtils.unknownLocation("repl"), type);

type.getConstructors().declare(PandaConstructor.builder()
.type(type)
.callback((frame, instance, arguments) -> typeScope.createInstance(frame, new Class<?>[0], arguments))
.location(type.getLocation())
.build());

this.replScope = new ReplScope(typeScope.getSourceLocation(), Collections.emptyList());
context.withComponent(Components.SCOPE, replScope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.panda_lang.framework.design.architecture.dynamic.Frame;
import org.panda_lang.framework.design.architecture.type.PropertyFrame;
import org.panda_lang.framework.design.architecture.statement.StandardizedFramedScope;
import org.panda_lang.framework.language.architecture.type.TypeInstance;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -30,9 +31,9 @@ final class ReplFrame implements Frame, PropertyFrame {
private final Frame instance;
private final Map<Integer, Object> memory = new HashMap<>();

protected ReplFrame(ReplScope scope, Frame instance) {
protected ReplFrame(ReplScope scope, TypeInstance instance) {
this.scope = scope;
this.instance = instance;
this.instance = instance.__panda__get_frame();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.panda_lang.framework.design.interpreter.source.SourceLocation;
import org.panda_lang.framework.design.runtime.ProcessStack;
import org.panda_lang.framework.language.architecture.statement.AbstractPropertyFramedScope;
import org.panda_lang.framework.language.architecture.type.TypeInstance;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -42,7 +43,7 @@ final class ReplScope extends AbstractPropertyFramedScope {

@Override
public Frame revive(ProcessStack stack, Object instance) {
ReplFrame frame = new ReplFrame(this, (Frame) instance);
ReplFrame frame = new ReplFrame(this, (TypeInstance) instance);

for (Entry<Integer, Object> entry : defaultValues.entrySet()) {
frame.set(entry.getKey(), entry.getValue());
Expand Down
22 changes: 0 additions & 22 deletions panda/src/main/java/org/panda_lang/panda/shell/repl/ShellType.java

This file was deleted.

0 comments on commit e22c70f

Please sign in to comment.