Skip to content

Commit

Permalink
GH-392 Remove cells
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Mar 14, 2020
1 parent f953c3c commit 619d6bf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 62 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@

package org.panda_lang.framework.language.architecture.statement;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.framework.design.architecture.statement.Block;
import org.panda_lang.framework.design.architecture.statement.Scope;
import org.panda_lang.framework.design.interpreter.source.SourceLocation;
import org.panda_lang.framework.design.runtime.ProcessStack;

public abstract class AbstractBlock extends AbstractScope implements Block {

protected AbstractBlock(Scope parent, SourceLocation location) {
super(parent, location);
}

@Override
public @Nullable Object execute(ProcessStack stack, Object instance) throws Exception {
return stack.callScope(instance, this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.panda_lang.framework.language.architecture.statement;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.framework.design.architecture.statement.Cell;
import org.panda_lang.framework.design.architecture.dynamic.Executable;
import org.panda_lang.framework.design.architecture.statement.FramedScope;
import org.panda_lang.framework.design.architecture.statement.Scope;
import org.panda_lang.framework.design.architecture.statement.Statement;
Expand All @@ -29,13 +29,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public abstract class AbstractScope extends AbstractStatement implements Scope {

protected final FramedScope scope;
protected final Scope parent;
protected final List<Variable> variables = new ArrayList<>();
protected final List<Cell> cells = new ArrayList<>();
protected final List<Statement> statements = new ArrayList<>();

protected AbstractScope(FramedScope scope, @Nullable Scope parent, SourceLocation location) {
super(location);
Expand All @@ -48,8 +49,28 @@ protected AbstractScope(Scope parent, SourceLocation location) {
}

@Override
public Cell addStatement(Statement executable) {
return Lists.add(cells, new PandaCell(executable));
public Statement addStatement(Statement executable) {
return Lists.add(statements, executable);
}

@Override
public boolean hasEffective(Class<? extends Statement> statementClass) {
List<? extends Executable> executables = getExecutables();
Executable executable = Lists.get(executables, executables.size() - 1);

if (executable == null) {
return false;
}

if (statementClass.isAssignableFrom(executable.getClass())) {
return true;
}

if (executable instanceof Scope) {
return ((Scope) executable).hasEffective(statementClass);
}

return false;
}

@Override
Expand Down Expand Up @@ -85,9 +106,16 @@ public List<? extends Variable> getVariables() {
return variables;
}

private List<? extends Executable> getExecutables() {
return statements.stream()
.filter(statement -> statement instanceof Executable)
.map(statement -> (Executable) statement)
.collect(Collectors.toList());
}

@Override
public List<? extends Cell> getCells() {
return cells;
public List<? extends Statement> getStatements() {
return statements;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.panda_lang.framework.design.architecture.dynamic.Controller;
import org.panda_lang.framework.design.architecture.dynamic.Executable;
import org.panda_lang.framework.design.architecture.dynamic.Frame;
import org.panda_lang.framework.design.architecture.statement.Cell;
import org.panda_lang.framework.design.architecture.statement.Scope;
import org.panda_lang.framework.design.architecture.statement.Statement;
import org.panda_lang.framework.design.runtime.Process;
Expand Down Expand Up @@ -67,6 +66,14 @@ public PandaProcessStack(Process process, int stackCapacity) {
}

private @Nullable Result<?> callInternal(Object instance, Statement statement) throws Exception {
if (statement instanceof Scope) {
if (statement instanceof ControlledScope) {
return ((ControlledScope) statement).controlledCall(this, instance);
}

return callScope(instance, (Scope) statement);
}

if (statement instanceof Executable) {
if (statement instanceof Controller) {
Controller controller = (Controller) statement;
Expand All @@ -77,21 +84,13 @@ public PandaProcessStack(Process process, int stackCapacity) {
return null;
}

if (statement instanceof Scope) {
if (statement instanceof ControlledScope) {
return ((ControlledScope) statement).controlledCall(this, instance);
}

return callScope(instance, (Scope) statement);
}

return null;
}

@Override
public @Nullable Result<?> callScope(Object instance, Scope scope) throws Exception {
for (Cell cell : scope.getCells()) {
Result<?> result = callStatement(instance, cell.getStatement());
for (Statement statement : scope.getStatements()) {
Result<?> result = callStatement(instance, statement);

if (result != null) {
return result;
Expand Down

0 comments on commit 619d6bf

Please sign in to comment.