Skip to content

Commit

Permalink
[#72] Zcode filenames to Zscript
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Aug 1, 2023
1 parent 5fb8484 commit 34dac28
Show file tree
Hide file tree
Showing 49 changed files with 416 additions and 416 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.zscript.javareceiver.core;

import net.zscript.javareceiver.execution.ActionSource;
import net.zscript.javareceiver.execution.ZcodeCommandContext;
import net.zscript.javareceiver.execution.CommandContext;
import net.zscript.javareceiver.semanticParser.ExecutionActionFactory;
import net.zscript.javareceiver.semanticParser.SemanticParser;
import net.zscript.javareceiver.semanticParser.ZcodeSemanticAction;
import net.zscript.javareceiver.semanticParser.SemanticAction;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer;

public abstract class ZcodeChannel implements ActionSource {
Expand All @@ -25,12 +25,12 @@ public SemanticParser getParser() {
}

@Override
public ZcodeOutStream getOutStream(Zcode zcode) {
public ZcodeOutStream getOutStream(Zscript zscript) {
return out;
}

@Override
public ZcodeSemanticAction getAction() {
public SemanticAction getAction() {
return p.getAction();
}

Expand All @@ -41,7 +41,7 @@ public void setChannelIndex(byte i) {
p.setChannelIndex(i);
}

public abstract void channelInfo(final ZcodeCommandContext ctx);
public abstract void channelInfo(final CommandContext ctx);

public abstract void channelSetup(final ZcodeCommandContext ctx);
public abstract void channelSetup(final CommandContext ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.zscript.javareceiver.modules.ZcodeModuleRegistry;
import net.zscript.javareceiver.notifications.ZcodeNotificationSource;

public class Zcode {
public class Zscript {
private final ZcodeModuleRegistry moduleRegistry = new ZcodeModuleRegistry();
private final ZcodeLocks locks = new ZcodeLocks();
private final List<ZcodeChannel> channels = new ArrayList<>();
Expand Down Expand Up @@ -41,7 +41,7 @@ protected void writeBytes(byte[] bytes, int count, boolean hexMode) {

};

public Zcode() {
public Zscript() {
executor = new ZcodeExecutor(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.zscript.javareceiver.core;

public class ZcodeStatus {
public class ZscriptStatus {
/** command success */
public static final byte SUCCESS = 0x0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.zscript.javareceiver.execution;

import net.zscript.javareceiver.core.Zcode;
import net.zscript.javareceiver.core.Zscript;
import net.zscript.javareceiver.core.ZcodeOutStream;

public interface ActionSource {
ZcodeAction getAction();

ZcodeOutStream getOutStream(Zcode zcode);
ZcodeOutStream getOutStream(Zscript zscript);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import java.util.Optional;

import net.zscript.javareceiver.core.ZcodeStatus;
import net.zscript.javareceiver.core.ZscriptStatus;
import net.zscript.javareceiver.semanticParser.ContextView;
import net.zscript.javareceiver.tokenizer.BlockIterator;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.Zchars;
import net.zscript.javareceiver.tokenizer.ZcodeTokenizer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader.ReadToken;

public class ZcodeAddressingContext extends AbstractContext {
public ZcodeAddressingContext(final ContextView contextView) {
public class AddressingContext extends AbstractContext {
public AddressingContext(final ContextView contextView) {
super(contextView);
}

Expand Down Expand Up @@ -60,23 +60,23 @@ public boolean verify() {
if (token.isMarker()) {
return true;
}
status(ZcodeStatus.INVALID_KEY);
status(ZscriptStatus.INVALID_KEY);
return false;
}
if (token.getKey() == Zchars.Z_ADDRESSING || token.getKey() == Zchars.Z_ADDRESSING_CONTINUE) {
continue;
}
if (token.getKey() != ZcodeTokenizer.ADDRESSING_FIELD_KEY) {
status(ZcodeStatus.INVALID_KEY);
status(ZscriptStatus.INVALID_KEY);
return false;
}
if (i == 1) {
status(ZcodeStatus.INTERNAL_ERROR);
status(ZscriptStatus.INTERNAL_ERROR);
return false;
}
hasReachedData = true;
}
status(ZcodeStatus.MISSING_KEY);
status(ZscriptStatus.MISSING_KEY);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
import java.util.Optional;
import java.util.OptionalInt;

import net.zscript.javareceiver.core.Zcode;
import net.zscript.javareceiver.core.Zscript;
import net.zscript.javareceiver.core.ZcodeCommandOutStream;
import net.zscript.javareceiver.core.ZcodeOutStream;
import net.zscript.javareceiver.core.ZcodeStatus;
import net.zscript.javareceiver.core.ZscriptStatus;
import net.zscript.javareceiver.semanticParser.ContextView;
import net.zscript.javareceiver.tokenizer.BlockIterator;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.Zchars;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader.ReadToken;

public class ZcodeCommandContext extends AbstractContext {
private final Zcode zcode;
public class CommandContext extends AbstractContext {
private final Zscript zscript;
private final ZcodeOutStream out;

public ZcodeCommandContext(final Zcode zcode, final ContextView contextView, final ZcodeOutStream out) {
public CommandContext(final Zscript zscript, final ContextView contextView, final ZcodeOutStream out) {
super(contextView);
this.zcode = zcode;
this.zscript = zscript;
this.out = out;
}

Expand Down Expand Up @@ -177,18 +177,18 @@ public boolean verify() {
if (Zchars.isNumericKey(key)) {
if (foundCmds.get(key - 'A')) {
commandComplete();
status(ZcodeStatus.REPEATED_KEY);
status(ZscriptStatus.REPEATED_KEY);
return false;
}
foundCmds.set(key - 'A');
if (rt.getDataSize() > 2) {
commandComplete();
status(ZcodeStatus.FIELD_TOO_LONG);
status(ZscriptStatus.FIELD_TOO_LONG);
return false;
}
} else if (!Zchars.isBigField(key)) {
commandComplete();
status(ZcodeStatus.INVALID_KEY);
status(ZscriptStatus.INVALID_KEY);
return false;
}
}
Expand All @@ -199,8 +199,8 @@ public void activate() {
contextView.activate();
}

public Zcode getZcode() {
return zcode;
public Zscript getZcode() {
return zscript;
}

public int getChannelIndex() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.zscript.javareceiver.execution;

import net.zscript.javareceiver.core.Zcode;
import net.zscript.javareceiver.core.Zscript;
import net.zscript.javareceiver.core.ZcodeOutStream;

public interface ZcodeAction {
boolean isEmptyAction();

void performAction(Zcode z, ZcodeOutStream out);
void performAction(Zscript z, ZcodeOutStream out);

boolean canLock(Zcode z);
boolean canLock(Zscript z);

boolean lock(Zcode z);
boolean lock(Zscript z);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import java.util.ArrayList;
import java.util.List;

import net.zscript.javareceiver.core.Zcode;
import net.zscript.javareceiver.core.Zscript;

public class ZcodeExecutor {
private final Zcode zcode;
private final Zscript zscript;

private final ZcodeScheduler scheduler = new ZcodeScheduler();

public ZcodeExecutor(Zcode zcode) {
this.zcode = zcode;
public ZcodeExecutor(Zscript zscript) {
this.zscript = zscript;
}

public boolean progress(List<? extends ActionSource> sources) {
Expand All @@ -24,18 +24,18 @@ public boolean progress(List<? extends ActionSource> sources) {
for (ActionSource source : sources) {
ZcodeAction action = source.getAction();
if (action.isEmptyAction()) {
action.performAction(zcode, null);
action.performAction(zscript, null);
} else {
hasNonWait = true;
}
possibleActions.add(action);
}

int indexToExec = scheduler.decide(zcode, possibleActions);
int indexToExec = scheduler.decide(zscript, possibleActions);
ZcodeAction action = possibleActions.get(indexToExec);

if (!action.isEmptyAction() && action.lock(zcode)) {
action.performAction(zcode, sources.get(indexToExec).getOutStream(zcode));
if (!action.isEmptyAction() && action.lock(zscript)) {
action.performAction(zscript, sources.get(indexToExec).getOutStream(zscript));
}
return hasNonWait;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import java.util.List;

import net.zscript.javareceiver.core.Zcode;
import net.zscript.javareceiver.core.Zscript;

public class ZcodeScheduler {

int decide(Zcode zcode, List<ZcodeAction> possibilities) {
int decide(Zscript zscript, List<ZcodeAction> possibilities) {
// TODO: a better one
for (int i = 0; i < possibilities.size(); i++) {
ZcodeAction action = possibilities.get(i);
if (!action.isEmptyAction() && action.canLock(zcode)) {
if (!action.isEmptyAction() && action.canLock(zscript)) {
return i;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package net.zscript.javareceiver.modules;

import net.zscript.javareceiver.core.ZcodeOutStream;
import net.zscript.javareceiver.core.ZcodeStatus;
import net.zscript.javareceiver.execution.ZcodeAddressingContext;
import net.zscript.javareceiver.execution.ZcodeCommandContext;
import net.zscript.javareceiver.core.ZscriptStatus;
import net.zscript.javareceiver.execution.AddressingContext;
import net.zscript.javareceiver.execution.CommandContext;
import net.zscript.javareceiver.tokenizer.Zchars;

public interface ZcodeModule {

int getModuleID();

void execute(ZcodeCommandContext ctx, int command);
void execute(CommandContext ctx, int command);

default void moveAlong(ZcodeCommandContext ctx, int command) {
ctx.status(ZcodeStatus.INTERNAL_ERROR);
default void moveAlong(CommandContext ctx, int command) {
ctx.status(ZscriptStatus.INTERNAL_ERROR);
}

default void address(ZcodeAddressingContext ctx) {
ctx.status(ZcodeStatus.INTERNAL_ERROR);
default void address(AddressingContext ctx) {
ctx.status(ZscriptStatus.INTERNAL_ERROR);
}

default void addressMoveAlong(ZcodeAddressingContext ctx) {
ctx.status(ZcodeStatus.INTERNAL_ERROR);
default void addressMoveAlong(AddressingContext ctx) {
ctx.status(ZscriptStatus.INTERNAL_ERROR);
}

default boolean notification(ZcodeOutStream out, int i, boolean isAddressed) {
out.asCommandOutStream().writeField(Zchars.Z_STATUS, ZcodeStatus.INTERNAL_ERROR);
out.asCommandOutStream().writeField(Zchars.Z_STATUS, ZscriptStatus.INTERNAL_ERROR);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.OptionalInt;

import net.zscript.javareceiver.core.ZcodeOutStream;
import net.zscript.javareceiver.core.ZcodeStatus;
import net.zscript.javareceiver.execution.ZcodeAddressingContext;
import net.zscript.javareceiver.execution.ZcodeCommandContext;
import net.zscript.javareceiver.core.ZscriptStatus;
import net.zscript.javareceiver.execution.AddressingContext;
import net.zscript.javareceiver.execution.CommandContext;
import net.zscript.javareceiver.tokenizer.Zchars;

public class ZcodeModuleRegistry {
Expand All @@ -19,62 +19,62 @@ public void addModule(ZcodeModule m) {
modules[m.getModuleID()] = m;
}

public void execute(ZcodeCommandContext ctx) {
public void execute(CommandContext ctx) {
// commands are completable unless explicitly marked otherwise by a command
ctx.commandComplete();
OptionalInt value = ctx.getField(Zchars.Z_CMD);
if (value.isEmpty()) {
ctx.status(ZcodeStatus.COMMAND_NOT_FOUND);
ctx.status(ZscriptStatus.COMMAND_NOT_FOUND);
return;
}
int cmd = value.getAsInt();
if ((cmd >> 4) >= 0x1000) {
ctx.status(ZcodeStatus.FIELD_TOO_LONG);
ctx.status(ZscriptStatus.FIELD_TOO_LONG);
return;
}
if (cmd > MAX_SYSTEM_CMD && !ctx.isActivated()) {
ctx.status(ZcodeStatus.NOT_ACTIVATED);
ctx.status(ZscriptStatus.NOT_ACTIVATED);
return;
}
if (modules[cmd >> 4] == null) {
ctx.status(ZcodeStatus.COMMAND_NOT_FOUND);
ctx.status(ZscriptStatus.COMMAND_NOT_FOUND);
return;
}

modules[cmd >> 4].execute(ctx, cmd & 0xF);
}

public void moveAlong(ZcodeCommandContext ctx) {
public void moveAlong(CommandContext ctx) {
ctx.commandComplete();
int cmd = ctx.getField(Zchars.Z_CMD).getAsInt();
modules[cmd >> 4].moveAlong(ctx, cmd & 0xF);
}

public void execute(ZcodeAddressingContext ctx) {
public void execute(AddressingContext ctx) {
ctx.commandComplete();
if (!ctx.isActivated()) {
ctx.status(ZcodeStatus.NOT_ACTIVATED);
ctx.status(ZscriptStatus.NOT_ACTIVATED);
return;
}
int addr = ctx.getAddressSegments().next().get();

ZcodeModule module = modules[addr];
if (module == null) {
ctx.status(ZcodeStatus.ADDRESS_NOT_FOUND);
ctx.status(ZscriptStatus.ADDRESS_NOT_FOUND);
return;
}
module.address(ctx);
}

public void moveAlong(ZcodeAddressingContext ctx) {
public void moveAlong(AddressingContext ctx) {
ctx.commandComplete();
int addr = ctx.getAddressSegments().next().get();
modules[addr].addressMoveAlong(ctx);
}

public boolean notification(ZcodeOutStream out, int type, boolean isAddressed) {
if (modules[type >> 4] == null) {
out.asCommandOutStream().writeField(Zchars.Z_STATUS, ZcodeStatus.INTERNAL_ERROR);
out.asCommandOutStream().writeField(Zchars.Z_STATUS, ZscriptStatus.INTERNAL_ERROR);
return true;
}
return modules[type >> 4].notification(out, type & 0xF, isAddressed);
Expand Down
Loading

0 comments on commit 34dac28

Please sign in to comment.