Skip to content

Commit

Permalink
GH-625 Returns TypeInstance instead of TypeFrame by default construct…
Browse files Browse the repository at this point in the history
…or (Fix #625)
  • Loading branch information
dzikoysk committed Mar 1, 2021
1 parent 32c6d16 commit f2663fd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package org.panda_lang.framework.architecture.type;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.framework.architecture.statement.AbstractFramedScope;
import org.panda_lang.framework.architecture.type.member.constructor.TypeConstructor;
import org.panda_lang.framework.interpreter.source.Location;
import org.panda_lang.framework.runtime.ProcessStack;

Expand All @@ -31,7 +29,7 @@ public TypeScope(Location location, Reference reference) {
this.reference = reference;
}

public TypeFrame revive(ProcessStack stack, @Nullable Object instance, TypeConstructor constructor, Object[] arguments) throws Exception {
public TypeFrame revive(ProcessStack stack) {
return new TypeFrame(stack.getProcess(), this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static final class ConstructorWorker extends AbstractExpressionSubparser
public Object invoke(ParametrizedMember property, ProcessStack stack, @Nullable Object instance, Object[] args) {
return type.getTypeScope().map(scope -> {
try {
return scope.revive(stack, instance, typeConstructor.get(), args);
return scope.revive(stack);
} catch (Exception exception) {
throw new PandaRuntimeException("Cannot create scope instance", exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ public Option<Completable<TypeMethod>> parse(Context<? extends TypeContext> cont
.name(name.get())
.location(context)
.isAbstract(body.isEmpty())
.isOverriding(overrides)
.isStatic(isStatic)
.visibility(visibility.orElseGet(Visibility.OPEN))
.returnType(returnType)
.isStatic(isStatic)
.body(methodScope)
.build();
type.getMethods().declare(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.panda_lang.framework.architecture.type.TypeScope;
import org.panda_lang.framework.architecture.type.Visibility;
import org.panda_lang.framework.architecture.type.generator.ClassGenerator;
import org.panda_lang.framework.architecture.type.member.constructor.ConstructorScope;
import org.panda_lang.framework.architecture.type.member.constructor.PandaConstructor;
import org.panda_lang.framework.architecture.type.member.field.TypeField;
import org.panda_lang.framework.architecture.type.member.method.TypeMethod;
import org.panda_lang.framework.architecture.type.signature.Signature;
import org.panda_lang.framework.architecture.type.signature.TypedSignature;
import org.panda_lang.framework.interpreter.parser.Component;
import org.panda_lang.framework.interpreter.parser.Context;
import org.panda_lang.framework.interpreter.parser.ContextParser;
import org.panda_lang.framework.interpreter.parser.PandaParserFailure;
Expand All @@ -51,12 +53,12 @@
import org.panda_lang.framework.resource.syntax.separator.Separators;
import org.panda_lang.panda.language.syntax.PandaSourceReader;
import org.panda_lang.utilities.commons.ArrayUtils;
import org.panda_lang.framework.interpreter.parser.Component;
import org.panda_lang.utilities.commons.function.Completable;
import org.panda_lang.utilities.commons.function.Option;
import org.panda_lang.utilities.commons.function.PandaStream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -191,9 +193,12 @@ public Option<Completable<Type>> parse(Context<?> context) {
);
});

ConstructorScope defaultConstructorScope = new ConstructorScope(type.getLocation(), Collections.emptyList());

type.getConstructors().declare(PandaConstructor.builder()
.type(type)
.invoker((constructor, frame, instance, args) -> scope.revive(frame, instance, constructor, args))
.invoker(defaultConstructorScope)
.baseCall(defaultConstructorScope::getBaseCall)
.location(type.getLocation())
.returnType(type.getSignature())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

public class PackageDocument implements Serializable {

public String name = "<undefined>";
public String name = "unnamed";

public String version = "<undefined>";
public String version = "unnamed";

public String author = "<undefined>";
public String author = "unnamed";

public String sources = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public static Package scriptToPackage(File script) throws Exception {
}

PackageDocument packageDocument = new PackageDocument();
packageDocument.name = script.getName();

Package pkg = new Package(packageDocument.name, packageDocument.author, packageDocument.version, script);
PandaModule defaultModule = new PandaModule(pkg, Package.DEFAULT_MODULE);
ModuleSource moduleSource = new ModuleSource(defaultModule, Collections.singleton(URLSource.fromFile(defaultModule, script)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public final class ReplCreator {

type.getConstructors().declare(PandaConstructor.builder()
.type(type)
.invoker((typeConstructor, frame, instance, arguments) -> typeScope.revive(frame, instance, typeConstructor, arguments))
.invoker((typeConstructor, stack, instance, arguments) -> typeScope.revive(stack))
.location(type.getLocation())
.returnType(type.getSignature())
.build());
Expand Down Expand Up @@ -127,12 +127,8 @@ public final class ReplCreator {
*/
public Repl create() throws Exception {
this.processSupplier = () -> new PandaProcess(context.getApplication(), replScope);

Type type = typeScope.getReference().fetchType();

this.instanceSupplier = stack -> {
return typeScope.revive(stack, typeScope, type.getConstructors().getConstructor(Collections.emptyList()).getOrNull(), new Object[0]);
};
// Type type = typeScope.getReference().fetchType();
this.instanceSupplier = typeScope::revive;

return new Repl(this);
}
Expand Down

0 comments on commit f2663fd

Please sign in to comment.