Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Stores errors produced during the validation of an instruction.
- #[derive(Clone, Debug, Hash, PartialEq)]
- pub enum InstructionError {
- /// Represent a non-termination instruction of a block.
- NonTermination {
- /// Index of the instruction.
- /* Users can't actually read the instructions of a method once appended, however, this number is in the same order they appended them
- so a user can infer which instruction caused error by counting the instructions they added.*/
- index: usize,
- /// Error of the instruction.
- error: NonTerminalInstructionError,
- /// Provides an IR text representation of the instruction which produced the error.
- /* Useful for easier understanding of the instruction which causes the error?. */
- text: String,
- },
- /// Represent the last instruction of a block.
- Termination {
- /* Termination instruction doesn't have index because they are the last instruction of a block. */
- /// Error of the instruction.
- error: TerminalInstructionError,
- /// Provides an IR text representation of the instruction which produced the error.
- text: String,
- },
- }
- /// Represent an erreore ofe a non-terminal instruction.
- #[derive(Clone, Debug, Hash, PartialEq)]
- pub enum NonTerminalInstructionError {
- /// The instruction accepts two arguments whose type must be the same but different types where provided for each argument.
- Arguments2MustBeOfSameType([InstructionTypedArgument; 2]),
- /// The instruction was provided with an argument of wrong type.
- InvalidArgumentType {
- /// Argument provided.
- argument: InstructionTypedArgument,
- /// Expected type.
- expected: InstructionParameterType,
- }
- // [...] TODO: Add more errors.
- InvalidArgumentForCalledFunction {
- /// Function called.
- function: FuncDec,
- /// Index of parameter.
- index: usize,
- /// Expected type of the parameter.
- expectedType: Type,
- /// Type of argument passed.
- passedType: Type,
- } // The instruction is a function call, but wrong argument was supplied.
- InvalidArgumentsCountForCalledFunctionn {
- /// Function called.
- function: FuncDec,
- /// Number of arguments expected.
- expected: usize,
- /// Number of arguments found.
- found: usize,
- }
- }
- #[derive(Clone, Debug, Hash, PartialEq)]
- /// Represent a typed argument passed to a parameter.
- pub struct InstructionTypedArgument {
- /// Name of the parameter.
- pub name: InstructionParameterName,
- /// Type of the argument passed.
- pub type_: Type,
- }
- #[derive(Clone, Debug, Hash, PartialEq)]
- /// Represent the name of a parameter.
- pub enum InstructionParameterName {
- Op1,
- Op2,
- /// [...] TODO: Some instructions can have different parameter names
- }
- #[derive(Clone, Debug, Hash, PartialEq)]
- /// Represent the expected type of an argument that are allowed to pass to an specific parameter.
- pub enum InstructionParameterType {
- /// Accepts any integer type or scalar of integers.
- ScalarOrArrayOfIntegers,
- /// Accepts any floating point type or scalar of floating points.
- ScalarOrArrayOfFloatingPoints,
- /// Accepts an specific type.
- OfType(Type),
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement