initial push with task5b done

This commit is contained in:
simonkellet
2023-10-19 15:00:09 +01:00
parent 3c134ed3b5
commit a607f09f6b
208 changed files with 13177 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
/target/
/.classpath
/build/
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Triangle.AbstractMachine</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
+4
View File
@@ -0,0 +1,4 @@
apply plugin: 'java-library'
apply plugin: 'eclipse'
sourceCompatibility = 11
+12
View File
@@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>triangle-abstractmachine</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>triangle.tools</groupId>
<artifactId>triangle-tools</artifactId>
<version>2.1</version>
<relativePath>../</relativePath>
</parent>
</project>
@@ -0,0 +1,71 @@
/*
* @(#)Instruction.java
*
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk
*
* Original release:
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractMachine;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
public class Instruction {
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// OpCode = 0..15; {4 bits unsigned}
// Length = 0..255; {8 bits unsigned}
// Operand = -32767..+32767; {16 bits signed}
// Represents TAM instructions.
final OpCode opCode;
final Register register;
final int length;
int operand; // Not final to allow for patching jump address
public Instruction(OpCode opcode, Register register, int length, int operand) {
this.opCode = opcode;
this.register = register;
this.length = length;
this.operand = operand;
}
public void setOperand(int operand) {
this.operand = operand;
}
public void write(DataOutputStream output) throws IOException {
output.writeInt(opCode.ordinal());
output.writeInt(register.ordinal());
output.writeInt(length);
output.writeInt(operand);
}
public static Instruction read(DataInputStream input) throws IOException {
try {
var opCode = OpCode.values()[input.readInt()];
var register = Register.values()[input.readInt()];
var length = input.readInt();
var operand = input.readInt();
return new Instruction(opCode, register, length, operand);
} catch (EOFException s) {
return null;
}
}
}
@@ -0,0 +1,58 @@
/*
* @(#)Machine.java
*
* Revisions and updates (c) 2022-2023 Sandy Brownlee. alexander.brownlee@stir.ac.uk
*
* Original release:
*
* Copyright (C) 1999, 2003 D.A. Watt and D.F. Brown
* Dept. of Computing Science, University of Glasgow, Glasgow G12 8QQ Scotland
* and School of Computer and Math Sciences, The Robert Gordon University,
* St. Andrew Street, Aberdeen AB25 1HG, Scotland.
* All rights reserved.
*
* This software is provided free for educational use only. It may
* not be used for commercial purposes without the prior written permission
* of the authors.
*/
package triangle.abstractMachine;
public final class Machine {
public final static int maxRoutineLevel = 7;
// WORDS AND ADDRESSES
// Java has no type synonyms, so the following representations are
// assumed:
//
// type
// Word = -32767..+32767; {16 bits signed}
// DoubleWord = -2147483648..+2147483647; {32 bits signed}
// CodeAddress = 0..+32767; {15 bits unsigned}
// DataAddress = 0..+32767; {15 bits unsigned}
// INSTRUCTIONS
// CODE STORE
public static Instruction[] code = new Instruction[1024];
// CODE STORE REGISTERS
public final static int CB = 0, PB = 1024, // = upper bound of code array + 1
PT = 1052; // = PB + 28
// REGISTER NUMBERS
// DATA REPRESENTATION
public final static int booleanSize = 1, characterSize = 1, integerSize = 1, addressSize = 1,
closureSize = 2 * addressSize,
linkDataSize = 3 * addressSize,
falseRep = 0, trueRep = 1, maxintRep = 32767;
}
@@ -0,0 +1,5 @@
package triangle.abstractMachine;
public enum OpCode {
LOAD, LOADA, LOADI, LOADL, STORE, STOREI, CALL, CALLI, RETURN, NOP, PUSH, POP, JUMP, JUMPI, JUMPIF, HALT
}
@@ -0,0 +1,6 @@
package triangle.abstractMachine;
public enum Primitive {
ID, NOT, AND, OR, SUCC, PRED, NEG, ADD, SUB, MULT, DIV, MOD, LT, LE, GE, GT, EQ, NE, EOL, EOF, GET, PUT, GETEOL,
PUTEOL, GETINT, PUTINT, NEW, DISPOSE
}
@@ -0,0 +1,5 @@
package triangle.abstractMachine;
public enum Register {
CB, CT, PB, PT, SB, ST, HB, HT, LB, L1, L2, L3, L4, L5, L6, CP
}