GetLink instruction
This commit is contained in:
@@ -29,6 +29,7 @@ public class LExecutor{
|
|||||||
|
|
||||||
public LongSeq graphicsBuffer = new LongSeq();
|
public LongSeq graphicsBuffer = new LongSeq();
|
||||||
public StringBuilder textBuffer = new StringBuilder();
|
public StringBuilder textBuffer = new StringBuilder();
|
||||||
|
public Building[] links = {};
|
||||||
|
|
||||||
public boolean initialized(){
|
public boolean initialized(){
|
||||||
return instructions != null && vars != null && instructions.length > 0;
|
return instructions != null && vars != null && instructions.length > 0;
|
||||||
@@ -161,6 +162,27 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GetLinkI implements LInstruction{
|
||||||
|
public int output, index;
|
||||||
|
|
||||||
|
public GetLinkI(int output, int index){
|
||||||
|
this.index = index;
|
||||||
|
this.output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetLinkI(){
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
int address = exec.numi(index);
|
||||||
|
|
||||||
|
if(address >= 0 && address < exec.links.length){
|
||||||
|
exec.setobj(output, exec.links[address]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class ReadI implements LInstruction{
|
public static class ReadI implements LInstruction{
|
||||||
public int target, position, output;
|
public int target, position, output;
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,30 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RegisterStatement("read")
|
||||||
|
public static class GetLinkStatement extends LStatement{
|
||||||
|
public String output = "result", address = "0";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Table table){
|
||||||
|
field(table, output, str -> output = str);
|
||||||
|
|
||||||
|
table.add(" = link# ");
|
||||||
|
|
||||||
|
field(table, address, str -> address = str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LCategory category(){
|
||||||
|
return LCategory.io;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LInstruction build(LAssembler builder){
|
||||||
|
return new GetLinkI(builder.var(output), builder.var(address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RegisterStatement("write")
|
@RegisterStatement("write")
|
||||||
public static class WriteStatement extends LStatement{
|
public static class WriteStatement extends LStatement{
|
||||||
public String input = "result", target = "cell1", address = "0";
|
public String input = "result", target = "cell1", address = "0";
|
||||||
@@ -120,7 +144,6 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RegisterStatement("draw")
|
@RegisterStatement("draw")
|
||||||
public static class DrawStatement extends LStatement{
|
public static class DrawStatement extends LStatement{
|
||||||
public GraphicsType type = GraphicsType.clear;
|
public GraphicsType type = GraphicsType.clear;
|
||||||
|
|||||||
@@ -262,11 +262,22 @@ public class LogicBlock extends Block{
|
|||||||
|
|
||||||
//store connections
|
//store connections
|
||||||
for(LogicLink link : links){
|
for(LogicLink link : links){
|
||||||
if(link.active && validLink(world.build(link.x, link.y))){
|
if(link.active && (link.valid = validLink(world.build(link.x, link.y)))){
|
||||||
asm.putConst(link.name, world.build(link.x, link.y));
|
asm.putConst(link.name, world.build(link.x, link.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//store link objects
|
||||||
|
executor.links = new Building[links.count(l -> l.valid && l.active)];
|
||||||
|
int index = 0;
|
||||||
|
for(LogicLink link : links){
|
||||||
|
if(link.active && link.valid){
|
||||||
|
executor.links[index ++] = world.build(link.x, link.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
asm.putConst("@links", executor.links.length);
|
||||||
|
|
||||||
//store any older variables
|
//store any older variables
|
||||||
for(Var var : executor.vars){
|
for(Var var : executor.vars){
|
||||||
if(!var.constant){
|
if(!var.constant){
|
||||||
|
|||||||
Reference in New Issue
Block a user