Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/nsl/instruction/CPUInstruction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* CPUInstruction.java
*/

package nsl.instruction;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import nsl.*;
import nsl.expression.*;

/**
* @author Jan
*/
public class CPUInstruction extends AssembleExpression {
public static final String name = "CPU";

private static final Set<String> VALID_CPUS = new HashSet<>(Arrays.asList("x86", "amd64"));

private final Expression cpu;

/**
* Class constructor.
*
* @param returns the number of values to return
*/
public CPUInstruction(int returns) {
if (!ScriptParser.inGlobalContext())
throw new NslContextException(EnumSet.of(NslContext.Global), name);
if (returns > 0) throw new NslReturnValueException(name);

ArrayList<Expression> paramsList = Expression.matchList();
if (paramsList.size() != 1) throw new NslArgumentException(name, 1);

this.cpu = paramsList.get(0);
if (!ExpressionType.isString(this.cpu))
throw new NslArgumentException(name, 1, ExpressionType.String);

String cpuValue = this.cpu.getStringValue();
if (!VALID_CPUS.contains(cpuValue)) {
throw new NslException(
String.format(
"%s: Invalid CPU architecture \"%s\". Valid values are: %s",
name, cpuValue, String.join(", ", VALID_CPUS)),
true);
}
}

/** Assembles the source code. */
@Override
public void assemble() throws IOException {
AssembleExpression.assembleIfRequired(this.cpu);
ScriptParser.writeLine(name + " " + this.cpu);
}

/**
* Assembles the source code.
*
* @param var the variable to assign the value to
*/
@Override
public void assemble(Register var) throws IOException {
throw new UnsupportedOperationException("Not supported.");
}
}
1 change: 1 addition & 0 deletions src/nsl/statement/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static AssembleExpression matchInstruction(int returns) {
return new ComponentTextInstruction(returns);
if (ScriptParser.tokenizer.match(CopyFilesInstruction.name))
return new CopyFilesInstruction(returns);
if (ScriptParser.tokenizer.match(CPUInstruction.name)) return new CPUInstruction(returns);
if (ScriptParser.tokenizer.match(CRCCheckInstruction.name))
return new CRCCheckInstruction(returns);
if (ScriptParser.tokenizer.match(CreateDirectoryInstruction.name))
Expand Down