Skip to content

Commit

Permalink
refactor: update errors message in vm #41
Browse files Browse the repository at this point in the history
  • Loading branch information
zestones committed Feb 11, 2025
1 parent 216ebb6 commit fe715a3
Show file tree
Hide file tree
Showing 50 changed files with 142 additions and 319 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ To delete the VSCode extension, run ``make extension-uninstall``.

## 🚀 Usage

- **Compiler:** Run ``./bin/argoc -a <source-file> -o <output-file>``. Use ./``./bin/argov --help`` for more options.
- **Virtual Machine:** Run ``./bin/argov –a <intermediate-file>``. Use ``./bin/argov –h`` for more options.
- **Compiler:** Run :
```bash
./bin/argoc -a <source-file> -o <output-file>
```
Use ./``./bin/argov --help`` for more options.
- **Virtual Machine:** Run :
```bash
./bin/argov –a <intermediate-file>
```
Use ``./bin/argov –h`` for more options.

## 📜 Language Overview

Expand Down
Binary file modified bin/argoc
Binary file not shown.
Binary file modified bin/argov
Binary file not shown.
20 changes: 0 additions & 20 deletions examples/interpretation/cool.arn

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
111 changes: 0 additions & 111 deletions examples/interpretation/matrix/display-matrix.arn

This file was deleted.

43 changes: 0 additions & 43 deletions examples/interpretation/matrix/matrix.arn

This file was deleted.

12 changes: 0 additions & 12 deletions examples/interpretation/recursive.arn

This file was deleted.

2 changes: 2 additions & 0 deletions examples/interpretation/runtime-errors/division-by-zero.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var x : int;
x := 10 / 0;
4 changes: 4 additions & 0 deletions examples/interpretation/runtime-errors/invalid-index.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type list : array[0:10, 0:10] of int;

var list: list;
list[true, 5] := 1;
4 changes: 4 additions & 0 deletions examples/interpretation/runtime-errors/missing-index.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type list : array[0:10, 0:10] of int;

var list: list;
list[5] := 1;
4 changes: 4 additions & 0 deletions examples/interpretation/runtime-errors/modulo-operation.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var x : float;

x := 10.456;
x := x % 2.0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type matrix : array[0:10, 0:10] of int;
var list : matrix;

list[11, 5] := 1;
10 changes: 10 additions & 0 deletions examples/interpretation/runtime-errors/uninitialized-value.arn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type date : struct {
day : int;
month : int;
year : int;
} fstruct;

var d1 : date;
d1.day := 1;

d1.year := d1.year + 1;
37 changes: 0 additions & 37 deletions examples/interpretation/supracool.arn

This file was deleted.

14 changes: 0 additions & 14 deletions examples/interpretation/test.arn

This file was deleted.

6 changes: 2 additions & 4 deletions src/utils/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void yywarn(const Error error) {
case SEMANTIC_ERROR: fprintf(stderr, "Semantic Warning"); break;
case TYPE_ERROR: fprintf(stderr, "Type Warning"); break;
case LEXICAL_ERROR: fprintf(stderr, "Lexical Warning"); break;
case INVALID_INPUT_ERROR: fprintf(stderr, "Invalid Input Warning"); break;
case RUN_TIME_ERROR: fprintf(stderr, "Run Time Warning"); break;
default: fprintf(stderr, "Unknown Warning"); break;
}
fprintf(stderr, "]");
Expand All @@ -36,9 +36,7 @@ void yerror(const Error error) {
case SEMANTIC_ERROR: fprintf(stderr, "Semantic Error"); break;
case TYPE_ERROR: fprintf(stderr, "Type Error"); break;
case LEXICAL_ERROR: fprintf(stderr, "Lexical Error"); break;
case INVALID_INPUT_ERROR: fprintf(stderr, "Invalid Input Error"); break;
case DIVISION_BY_ZERO: fprintf(stderr, "Division by 0"); break;
case UNINITIALIZED_VARIABLE: fprintf(stderr, "Null Variable"); break;
case RUN_TIME_ERROR: fprintf(stderr, "Run Time Error"); break;
default: fprintf(stderr, "Unknown Error"); break;
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
* @enum ErrorType
* @brief Enumeration of error types.
*/
typedef enum {
typedef enum
{
NO_ERROR,
SYNTAX_ERROR,
SEMANTIC_ERROR,
TYPE_ERROR,
LEXICAL_ERROR,
RUN_TIME_ERROR,
INVALID_INPUT_ERROR,
DIVISION_BY_ZERO,
UNINITIALIZED_VARIABLE
UNINITIALIZED_VARIABLE,
INVALID_OPERATION,
INSUFFICIENT_INDICES,
} ErrorType;

/**
Expand Down
27 changes: 24 additions & 3 deletions src/virtual_machine/core/address/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ int get_array_address(Node *start_array_access, int base_address) {

for (int dim = 0; dim < num_dimensions; dim++) {
if (array_access == NULL) {
printf("Error: Insufficient indices provided for array assignment.\n");
set_error_type(&error, RUN_TIME_ERROR);
set_error_message(
&error,
"Insufficient indices provided for array assignment.\n"
" Ensure that '%d' indices are specified.",
num_dimensions
);
yerror(error);
exit(EXIT_FAILURE);
}

if (array_access->type == A_ARRAY_INDEX) {
// Resolve the expression for the current index in the current dimension
vm_cell index_cell = resolve_expression(array_access->child);
if (index_cell.type != INTEGER) {
printf("Error: Index type should be integer, instead got: %d\n", index_cell.type);
set_error_type(&error, RUN_TIME_ERROR);
set_error_message(
&error,
"Invalid index type, index type should be integer.\n"
" Instead got type '%s'.",
get_cell_type_string(index_cell));
yerror(error);
exit(EXIT_FAILURE);
}

Expand All @@ -45,7 +58,15 @@ int get_array_address(Node *start_array_access, int base_address) {
int upper_bound = get_array_nth_dimension(array_decl_index, 2 * dim + 1);

if (index < lower_bound || index > upper_bound) {
printf("Error: Index %d out of bounds for dimension %d.\n", index, dim);
set_error_type(&error, RUN_TIME_ERROR);
set_error_message(
&error,
"Index %d out of bounds for dimension %d.\n"
" Allowed range: [%d, %d].",
index, dim, lower_bound, upper_bound
);
yerror(error);

exit(EXIT_FAILURE);
}

Expand Down
Loading

0 comments on commit fe715a3

Please sign in to comment.