refactor packages, add package-info
This commit is contained in:
parent
846df01b11
commit
ec8617354e
|
@ -7,10 +7,11 @@ import org.antlr.v4.runtime.tree.ParseTreeProperty;
|
||||||
|
|
||||||
import pp.iloc.model.Reg;
|
import pp.iloc.model.Reg;
|
||||||
import pp.s1184725.boppi.type.*;
|
import pp.s1184725.boppi.type.*;
|
||||||
|
import pp.s1184725.boppi.symboltable.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds properties of all AST nodes during compilation.
|
* This class holds properties of all AST nodes during compilation.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class Annotations {
|
public class Annotations {
|
||||||
|
|
|
@ -10,11 +10,12 @@ import pp.s1184725.boppi.antlr.*;
|
||||||
import pp.s1184725.boppi.antlr.BoppiParser.*;
|
import pp.s1184725.boppi.antlr.BoppiParser.*;
|
||||||
import pp.s1184725.boppi.exception.*;
|
import pp.s1184725.boppi.exception.*;
|
||||||
import pp.s1184725.boppi.type.*;
|
import pp.s1184725.boppi.type.*;
|
||||||
|
import pp.s1184725.boppi.symboltable.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class performs type checking and variable assignment on a bare parse
|
* This class performs type checking and variable assignment on a bare parse
|
||||||
* tree.
|
* tree.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
|
@ -25,7 +26,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
/**
|
/**
|
||||||
* Checks and annotates a program. Problems are reported to the given
|
* Checks and annotates a program. Problems are reported to the given
|
||||||
* logger.
|
* logger.
|
||||||
*
|
*
|
||||||
* @param ast
|
* @param ast
|
||||||
* the program's AST
|
* the program's AST
|
||||||
* @param logger
|
* @param logger
|
||||||
|
@ -47,7 +48,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether two types are compatible and log an error if they do not.
|
* Checks whether two types are compatible and log an error if they do not.
|
||||||
*
|
*
|
||||||
* @param type1
|
* @param type1
|
||||||
* the left hand or actual type
|
* the left hand or actual type
|
||||||
* @param type2
|
* @param type2
|
||||||
|
@ -62,7 +63,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an error message for a given parse tree node.
|
* Returns an error message for a given parse tree node.
|
||||||
*
|
*
|
||||||
* @param ctx
|
* @param ctx
|
||||||
* the parse tree node at which the error occurred
|
* the parse tree node at which the error occurred
|
||||||
* @param message
|
* @param message
|
||||||
|
@ -81,7 +82,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
* within a set root (may be {@code null}). Effectively traverses between
|
* within a set root (may be {@code null}). Effectively traverses between
|
||||||
* {@code current} and {@code root} in the parent hierarchy looking for a
|
* {@code current} and {@code root} in the parent hierarchy looking for a
|
||||||
* {@code rule} class.
|
* {@code rule} class.
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the rule class
|
* the rule class
|
||||||
* @param ctx
|
* @param ctx
|
||||||
|
@ -105,7 +106,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
/**
|
/**
|
||||||
* Visits the parse tree, then records the returned type in the type
|
* Visits the parse tree, then records the returned type in the type
|
||||||
* annotations and returns it too.
|
* annotations and returns it too.
|
||||||
*
|
*
|
||||||
* @param tree
|
* @param tree
|
||||||
* the tree to visit
|
* the tree to visit
|
||||||
* @return the evaluated type of the tree
|
* @return the evaluated type of the tree
|
||||||
|
@ -394,7 +395,7 @@ public class BoppiChecker extends BoppiBaseVisitor<Type> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type visitTypeFunction(TypeFunctionContext ctx) {
|
public Type visitTypeFunction(TypeFunctionContext ctx) {
|
||||||
return new FunctionType(visit(ctx.type(1)), visit(ctx.type(0)));
|
return new FunctionType(visit(ctx.type(0)), visit(ctx.type(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,11 +13,11 @@ import pp.iloc.model.*;
|
||||||
import pp.s1184725.boppi.antlr.*;
|
import pp.s1184725.boppi.antlr.*;
|
||||||
import pp.s1184725.boppi.antlr.BoppiParser.*;
|
import pp.s1184725.boppi.antlr.BoppiParser.*;
|
||||||
import pp.s1184725.boppi.type.*;
|
import pp.s1184725.boppi.type.*;
|
||||||
import pp.s1184725.boppi.util.RegisterPool;
|
import pp.s1184725.boppi.symboltable.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The generator stage of the Boppi toolchain.
|
* The generator stage of the Boppi toolchain.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
@ -83,7 +83,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
/**
|
/**
|
||||||
* Creates a new generator with the given variable annotations and attaches
|
* Creates a new generator with the given variable annotations and attaches
|
||||||
* the given logger.
|
* the given logger.
|
||||||
*
|
*
|
||||||
* @param ast
|
* @param ast
|
||||||
* the program's AST
|
* the program's AST
|
||||||
* @param annotations
|
* @param annotations
|
||||||
|
@ -142,7 +142,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the chain of ARs.
|
* Increments the chain of ARs.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param ar
|
* @param ar
|
||||||
|
@ -168,7 +168,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the chain of ARs.
|
* Decrements the chain of ARs.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param ar
|
* @param ar
|
||||||
|
@ -195,7 +195,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
/**
|
/**
|
||||||
* Allocates a chunk of memory and returns a pointer to the memory in the
|
* Allocates a chunk of memory and returns a pointer to the memory in the
|
||||||
* given register.
|
* given register.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param size
|
* @param size
|
||||||
|
@ -213,7 +213,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
/**
|
/**
|
||||||
* Allocates a chunk of memory and returns a pointer to the memory in the
|
* Allocates a chunk of memory and returns a pointer to the memory in the
|
||||||
* given register.
|
* given register.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param size
|
* @param size
|
||||||
|
@ -229,7 +229,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees a chunk of memory pointed at by {@code ptr}.
|
* Frees a chunk of memory pointed at by {@code ptr}.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param ptr
|
* @param ptr
|
||||||
|
@ -244,7 +244,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the reference count of a memory chunk.
|
* Increments the reference count of a memory chunk.
|
||||||
*
|
*
|
||||||
* @param temp
|
* @param temp
|
||||||
* temporary register to use
|
* temporary register to use
|
||||||
* @param ptr
|
* @param ptr
|
||||||
|
@ -259,7 +259,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an error message for a given parse tree node.
|
* Returns an error message for a given parse tree node.
|
||||||
*
|
*
|
||||||
* @param ctx
|
* @param ctx
|
||||||
* the parse tree node at which the error occurred
|
* the parse tree node at which the error occurred
|
||||||
* @param message
|
* @param message
|
||||||
|
@ -276,7 +276,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
/**
|
/**
|
||||||
* Constructs a new unique label with the given prefix to make it
|
* Constructs a new unique label with the given prefix to make it
|
||||||
* recognisable in ILOC.
|
* recognisable in ILOC.
|
||||||
*
|
*
|
||||||
* @param prefix
|
* @param prefix
|
||||||
* a short prefix for the label
|
* a short prefix for the label
|
||||||
* @return the label
|
* @return the label
|
||||||
|
@ -289,7 +289,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
* Increments the reference count to a type if it is a reference type. For
|
* Increments the reference count to a type if it is a reference type. For
|
||||||
* function types this includes all access links. Assumes registers are
|
* function types this includes all access links. Assumes registers are
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type of this reference
|
* the type of this reference
|
||||||
* @param addr
|
* @param addr
|
||||||
|
@ -316,7 +316,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
* Decrements the reference count to a type if it is a reference type. For
|
* Decrements the reference count to a type if it is a reference type. For
|
||||||
* function types this includes all access links. Assumes registers are
|
* function types this includes all access links. Assumes registers are
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type of this reference
|
* the type of this reference
|
||||||
* @param addr
|
* @param addr
|
||||||
|
@ -350,7 +350,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
/**
|
/**
|
||||||
* Decrements all reference-type variables of a function. Must be called at
|
* Decrements all reference-type variables of a function. Must be called at
|
||||||
* the end of a function declaration. Assumes registers are reserved.
|
* the end of a function declaration. Assumes registers are reserved.
|
||||||
*
|
*
|
||||||
* @param scope
|
* @param scope
|
||||||
* the function scope with all relevant variables
|
* the function scope with all relevant variables
|
||||||
*/
|
*/
|
||||||
|
@ -641,7 +641,7 @@ public class BoppiGenerator extends BoppiBaseVisitor<Reg> {
|
||||||
* Loads the value on the address pointed to by the variable context.
|
* Loads the value on the address pointed to by the variable context.
|
||||||
* Because the array length is not stored by itself, it will be calculated
|
* Because the array length is not stored by itself, it will be calculated
|
||||||
* here from the size property.
|
* here from the size property.
|
||||||
*
|
*
|
||||||
* @see BoppiBaseVisitor#visitGetVariable(GetVariableContext)
|
* @see BoppiBaseVisitor#visitGetVariable(GetVariableContext)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package pp.s1184725.boppi.util;
|
package pp.s1184725.boppi;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
|
@ -19,13 +19,13 @@ public class RegisterPool {
|
||||||
* Register that must have a value of 0.
|
* Register that must have a value of 0.
|
||||||
*/
|
*/
|
||||||
public static final Reg ZERO = new Reg("r_nul");
|
public static final Reg ZERO = new Reg("r_nul");
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private List<Reg> regFree, regInUse;
|
private List<Reg> regFree, regInUse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new register pool
|
* Creates a new register pool
|
||||||
*
|
*
|
||||||
* @param logger
|
* @param logger
|
||||||
* the logger to use
|
* the logger to use
|
||||||
*/
|
*/
|
||||||
|
@ -48,7 +48,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks two registers while running some code.
|
* Blocks two registers while running some code.
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the return type of the code
|
* the return type of the code
|
||||||
* @param r1
|
* @param r1
|
||||||
|
@ -65,7 +65,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks a register while running some code.
|
* Blocks a register while running some code.
|
||||||
*
|
*
|
||||||
* @param r1
|
* @param r1
|
||||||
* the register to reserve
|
* the register to reserve
|
||||||
* @param code
|
* @param code
|
||||||
|
@ -79,7 +79,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks a register while running some code.
|
* Blocks a register while running some code.
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the return type of the code
|
* the return type of the code
|
||||||
* @param r1
|
* @param r1
|
||||||
|
@ -108,7 +108,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of registers currently in use.
|
* Returns the list of registers currently in use.
|
||||||
*
|
*
|
||||||
* @return the list of registers in use
|
* @return the list of registers in use
|
||||||
*/
|
*/
|
||||||
public List<Reg> getInUse() {
|
public List<Reg> getInUse() {
|
||||||
|
@ -136,7 +136,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs some code with two registers allocated.
|
* Runs some code with two registers allocated.
|
||||||
*
|
*
|
||||||
* @param code
|
* @param code
|
||||||
* the code to run
|
* the code to run
|
||||||
* @return the second register used in the code
|
* @return the second register used in the code
|
||||||
|
@ -147,7 +147,7 @@ public class RegisterPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs some code with a single register allocated.
|
* Runs some code with a single register allocated.
|
||||||
*
|
*
|
||||||
* @param code
|
* @param code
|
||||||
* the code to run
|
* the code to run
|
||||||
* @return the register used in the code
|
* @return the register used in the code
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* This package contains the Boppi language grammar and, after ANTLR
|
||||||
|
* generation, the lexer, parser and visitor classes.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.antlr;
|
|
@ -1,6 +1,6 @@
|
||||||
package pp.s1184725.boppi.exception;
|
package pp.s1184725.boppi.exception;
|
||||||
|
|
||||||
import pp.s1184725.boppi.CachingSymbolTable;
|
import pp.s1184725.boppi.symboltable.CachingSymbolTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exceptions that may be thrown by the {@link CachingSymbolTable}.
|
* Exceptions that may be thrown by the {@link CachingSymbolTable}.
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* This package contains custom exceptions for
|
||||||
|
* {@link pp.s1184725.boppi.CachingSymbolTable}.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.exception;
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* This package contains the main Boppi classes: a checker, generator,
|
||||||
|
* toolchain and supporting classes.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi;
|
|
@ -1,8 +1,9 @@
|
||||||
package pp.s1184725.boppi;
|
package pp.s1184725.boppi.symboltable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import pp.s1184725.boppi.Messages;
|
||||||
import pp.s1184725.boppi.exception.*;
|
import pp.s1184725.boppi.exception.*;
|
||||||
import pp.s1184725.boppi.type.*;
|
import pp.s1184725.boppi.type.*;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ import pp.s1184725.boppi.type.*;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the typing class
|
* the typing class
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class CachingSymbolTable<T extends Type> {
|
public class CachingSymbolTable<T extends Type> {
|
||||||
|
@ -36,9 +37,9 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
* Closes a lexical scope for a function declaration, removing all
|
* Closes a lexical scope for a function declaration, removing all
|
||||||
* declarations within this scope, restoring the local offset and decreasing
|
* declarations within this scope, restoring the local offset and decreasing
|
||||||
* the lookup depth.
|
* the lookup depth.
|
||||||
*
|
*
|
||||||
* @return function scope details
|
* @return function scope details
|
||||||
*
|
*
|
||||||
* @throws NoProgramException
|
* @throws NoProgramException
|
||||||
* if no scope is open
|
* if no scope is open
|
||||||
*/
|
*/
|
||||||
|
@ -51,7 +52,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
* Closes a lexical scope, removing all declarations within this scope. Runs
|
* Closes a lexical scope, removing all declarations within this scope. Runs
|
||||||
* in {@code O(k log k log n)} time, with {@code k} the number of
|
* in {@code O(k log k log n)} time, with {@code k} the number of
|
||||||
* identifiers going out of scope, when the stream is parallelized.
|
* identifiers going out of scope, when the stream is parallelized.
|
||||||
*
|
*
|
||||||
* @throws NoProgramException
|
* @throws NoProgramException
|
||||||
* if no scope is open
|
* if no scope is open
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +70,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of an identifier, if any.
|
* Returns the type of an identifier, if any.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* the name of the identifier
|
* the name of the identifier
|
||||||
* @return the type of the identifier
|
* @return the type of the identifier
|
||||||
|
@ -87,7 +88,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current function scope, if any.
|
* Returns the current function scope, if any.
|
||||||
*
|
*
|
||||||
* @return the current function scope
|
* @return the current function scope
|
||||||
* @throws NoProgramException
|
* @throws NoProgramException
|
||||||
* if no scope is open
|
* if no scope is open
|
||||||
|
@ -101,7 +102,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given identifier is declared.
|
* Returns whether the given identifier is declared.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* the name of the identifier
|
* the name of the identifier
|
||||||
* @return true if the identifier has a declared type
|
* @return true if the identifier has a declared type
|
||||||
|
@ -136,7 +137,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
* and returns the newly made variable instance that belongs to this
|
* and returns the newly made variable instance that belongs to this
|
||||||
* identifier. Throws an exception if the identifier is declared in this
|
* identifier. Throws an exception if the identifier is declared in this
|
||||||
* scope already.
|
* scope already.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* the name of the identifier
|
* the name of the identifier
|
||||||
* @param type
|
* @param type
|
||||||
|
@ -166,7 +167,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
* helper method to make sure calls to {@link #openFunctionScope()} and
|
* helper method to make sure calls to {@link #openFunctionScope()} and
|
||||||
* {@link #closeFunctionScope()} are balanced and returns the function scope
|
* {@link #closeFunctionScope()} are balanced and returns the function scope
|
||||||
* details. {@code code} must take no arguments and must not return a value.
|
* details. {@code code} must take no arguments and must not return a value.
|
||||||
*
|
*
|
||||||
* @param code
|
* @param code
|
||||||
* the code to execute within the scope
|
* the code to execute within the scope
|
||||||
* @return the function scope details
|
* @return the function scope details
|
||||||
|
@ -187,7 +188,7 @@ public class CachingSymbolTable<T extends Type> {
|
||||||
* helper method to make sure calls to {@link #openScope()} and
|
* helper method to make sure calls to {@link #openScope()} and
|
||||||
* {@link #closeScope()} are balanced. {@code code} must take no arguments
|
* {@link #closeScope()} are balanced. {@code code} must take no arguments
|
||||||
* and must return a value.
|
* and must return a value.
|
||||||
*
|
*
|
||||||
* @param <U>
|
* @param <U>
|
||||||
* the type of the code's return value
|
* the type of the code's return value
|
||||||
* @param code
|
* @param code
|
|
@ -1,4 +1,4 @@
|
||||||
package pp.s1184725.boppi;
|
package pp.s1184725.boppi.symboltable;
|
||||||
|
|
||||||
import pp.s1184725.boppi.exception.*;
|
import pp.s1184725.boppi.exception.*;
|
||||||
import pp.s1184725.boppi.type.*;
|
import pp.s1184725.boppi.type.*;
|
||||||
|
@ -9,7 +9,7 @@ import pp.s1184725.boppi.type.*;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the typing class
|
* the typing class
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class DebugCachingSymbolTable<T extends Type> extends CachingSymbolTable<T> {
|
public class DebugCachingSymbolTable<T extends Type> extends CachingSymbolTable<T> {
|
|
@ -1,4 +1,4 @@
|
||||||
package pp.s1184725.boppi;
|
package pp.s1184725.boppi.symboltable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -7,9 +7,9 @@ import pp.s1184725.boppi.type.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of local data for functions.
|
* Keeps track of local data for functions.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the type system to use
|
* the type system to use
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,7 @@ public class FunctionScope<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function scope with the given depth.
|
* Creates a function scope with the given depth.
|
||||||
*
|
*
|
||||||
* @param depth
|
* @param depth
|
||||||
* the lexical depth of this function
|
* the lexical depth of this function
|
||||||
*/
|
*/
|
||||||
|
@ -30,7 +30,7 @@ public class FunctionScope<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new variable in this function scope and returns it.
|
* Creates a new variable in this function scope and returns it.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type of variable to create
|
* the type of variable to create
|
||||||
* @return the variable created
|
* @return the variable created
|
||||||
|
@ -44,7 +44,7 @@ public class FunctionScope<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current lexical scope/function depth.
|
* Returns the current lexical scope/function depth.
|
||||||
*
|
*
|
||||||
* @return the function depth
|
* @return the function depth
|
||||||
*/
|
*/
|
||||||
public int getFunctionDepth() {
|
public int getFunctionDepth() {
|
||||||
|
@ -56,7 +56,7 @@ public class FunctionScope<T extends Type> {
|
||||||
* in the current function scope. Note that this is the size calculated up
|
* in the current function scope. Note that this is the size calculated up
|
||||||
* and including the last variable declaration, so make sure to call it
|
* and including the last variable declaration, so make sure to call it
|
||||||
* right before leaving a function scope.
|
* right before leaving a function scope.
|
||||||
*
|
*
|
||||||
* @return the number of bytes required to store all variables local to a
|
* @return the number of bytes required to store all variables local to a
|
||||||
* function
|
* function
|
||||||
*/
|
*/
|
||||||
|
@ -66,7 +66,7 @@ public class FunctionScope<T extends Type> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the variables local to this function scope.
|
* Returns the variables local to this function scope.
|
||||||
*
|
*
|
||||||
* @return a list of variables
|
* @return a list of variables
|
||||||
*/
|
*/
|
||||||
public List<Variable<T>> getVars() {
|
public List<Variable<T>> getVars() {
|
|
@ -1,4 +1,4 @@
|
||||||
package pp.s1184725.boppi;
|
package pp.s1184725.boppi.symboltable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tracks a variable's properties. It is agnostic of the type system
|
* This class tracks a variable's properties. It is agnostic of the type system
|
||||||
|
@ -6,7 +6,7 @@ package pp.s1184725.boppi;
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* the typing class
|
* the typing class
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class Variable<T> {
|
public class Variable<T> {
|
||||||
|
@ -18,7 +18,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a variable with the given type instance and memory offset.
|
* Creates a variable with the given type instance and memory offset.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type of the variable
|
* the type of the variable
|
||||||
* @param depth
|
* @param depth
|
||||||
|
@ -43,7 +43,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the lexical depth of this variable instance.
|
* Gets the lexical depth of this variable instance.
|
||||||
*
|
*
|
||||||
* @return the depth
|
* @return the depth
|
||||||
*/
|
*/
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
|
@ -52,7 +52,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the local data offset of this variable instance.
|
* Gets the local data offset of this variable instance.
|
||||||
*
|
*
|
||||||
* @return the offset
|
* @return the offset
|
||||||
*/
|
*/
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
|
@ -61,7 +61,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of this variable instance.
|
* Gets the type of this variable instance.
|
||||||
*
|
*
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public T getType() {
|
public T getType() {
|
||||||
|
@ -70,7 +70,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this variable has been assigned.
|
* Returns whether this variable has been assigned.
|
||||||
*
|
*
|
||||||
* @return whether this variable has been assigned
|
* @return whether this variable has been assigned
|
||||||
*/
|
*/
|
||||||
public boolean isAssigned() {
|
public boolean isAssigned() {
|
||||||
|
@ -79,7 +79,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this variable is a constant.
|
* Returns whether this variable is a constant.
|
||||||
*
|
*
|
||||||
* @return whether this variable is a constant
|
* @return whether this variable is a constant
|
||||||
*/
|
*/
|
||||||
public boolean isConstant() {
|
public boolean isConstant() {
|
||||||
|
@ -88,7 +88,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this variable has been assigned conditionally.
|
* Returns whether this variable has been assigned conditionally.
|
||||||
*
|
*
|
||||||
* @return whether this variable has been assigned conditionally
|
* @return whether this variable has been assigned conditionally
|
||||||
*/
|
*/
|
||||||
public boolean isPossiblyAssigned() {
|
public boolean isPossiblyAssigned() {
|
||||||
|
@ -104,7 +104,7 @@ public class Variable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the const-ness of this variable.
|
* Sets the const-ness of this variable.
|
||||||
*
|
*
|
||||||
* @param constant
|
* @param constant
|
||||||
* whether this variable is a constant
|
* whether this variable is a constant
|
||||||
*/
|
*/
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* This package contains a symbol table implementation.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.symboltable;
|
|
@ -6,7 +6,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for fixed-size arrays.
|
* Test cases for fixed-size arrays.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class ArrayTest {
|
public class ArrayTest {
|
||||||
|
@ -127,17 +127,17 @@ public class ArrayTest {
|
||||||
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
assertThat(BoppiTests.out, is(arrayContaining("1337", "13", "2", "15")));
|
assertThat(BoppiTests.out, is(arrayContaining("1337", "13", "2", "15")));
|
||||||
|
|
||||||
BoppiTests.compileAndRunString("var int[][] m; m := [[1,3]]; m[0]; var int[] a; a := [8,9]; print(m[0][1])");
|
BoppiTests.compileAndRunString("var int[][] m; m := [[1,3]]; m[0]; var int[] a; a := [8,9]; print(m[0][1])");
|
||||||
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
assertThat(BoppiTests.out, is(arrayContaining("3")));
|
assertThat(BoppiTests.out, is(arrayContaining("3")));
|
||||||
|
|
||||||
BoppiTests.compileAndRunString("print([1,2]==[1,2],[1,2]<>[1,2],[1]==[1,2],[0]<>[2])");
|
BoppiTests.compileAndRunString("print([1,2]==[1,2],[1,2]<>[1,2],[1]==[1,2],[0]<>[2])");
|
||||||
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
assertThat(BoppiTests.out, is(arrayContaining("true", "false", "false", "true")));
|
assertThat(BoppiTests.out, is(arrayContaining("true", "false", "false", "true")));
|
||||||
|
|
||||||
BoppiTests.compileAndRunFile("programs/arrayFunctions.boppi", "Hello");
|
BoppiTests.compileAndRunFile("programs/arrayFunctions.boppi", "Hello");
|
||||||
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
assertThat(BoppiTests.vm.getInterrupt(), is(0));
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
|
|
|
@ -8,11 +8,11 @@ import java.util.logging.Level;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import pp.s1184725.boppi.util.RegisterPool;
|
import pp.s1184725.boppi.RegisterPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for the basic expression language.
|
* Test cases for the basic expression language.
|
||||||
*
|
*
|
||||||
* @author Frank Wibbelink
|
* @author Frank Wibbelink
|
||||||
*/
|
*/
|
||||||
public class ExpressionTest {
|
public class ExpressionTest {
|
||||||
|
@ -63,6 +63,7 @@ public class ExpressionTest {
|
||||||
public void wrongExpressionChecking() {
|
public void wrongExpressionChecking() {
|
||||||
BoppiTests.checkString("+true");
|
BoppiTests.checkString("+true");
|
||||||
assertThat(BoppiTests.log, hasSize(1));
|
assertThat(BoppiTests.log, hasSize(1));
|
||||||
|
BoppiTests.printOutput();
|
||||||
|
|
||||||
BoppiTests.checkString("5 || true");
|
BoppiTests.checkString("5 || true");
|
||||||
assertThat(BoppiTests.log, hasSize(1));
|
assertThat(BoppiTests.log, hasSize(1));
|
||||||
|
@ -85,6 +86,7 @@ public class ExpressionTest {
|
||||||
BoppiTests.compileAndRunString("print(5*3)");
|
BoppiTests.compileAndRunString("print(5*3)");
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
assertThat(BoppiTests.out, is(arrayContaining("15")));
|
assertThat(BoppiTests.out, is(arrayContaining("15")));
|
||||||
|
BoppiTests.printOutput();
|
||||||
|
|
||||||
BoppiTests.compileAndRunString("print('T', 'e', 's', 't', '!')");
|
BoppiTests.compileAndRunString("print('T', 'e', 's', 't', '!')");
|
||||||
assertThat(BoppiTests.log, is(empty()));
|
assertThat(BoppiTests.log, is(empty()));
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* This package contains JUnit tests for Boppi features and memlib.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.test;
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* This package contains the types in Boppi. Type unification and checking is
|
||||||
|
* currently performed in {@link pp.s1184725.boppi.BoppiChecker}.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.type;
|
|
@ -0,0 +1,5 @@
|
||||||
|
/**
|
||||||
|
* This package provides a command-line interface for compiling Boppi code
|
||||||
|
* and a rudimentary REPL.
|
||||||
|
*/
|
||||||
|
package pp.s1184725.boppi.util;
|
Loading…
Reference in New Issue