@@ -19,7 +19,7 @@ bool Lamscript::had_error_ = false;
19
19
bool Lamscript::had_runtime_error_ = false ;
20
20
21
21
// / @brief Run the given source.
22
- void Lamscript::Run (const std::string& source) {
22
+ ProgramResult Lamscript::Run (const std::string& source) {
23
23
parsing::Scanner scanner = parsing::Scanner (source);
24
24
std::vector<parsing::Token> tokens = scanner.ScanTokens ();
25
25
@@ -28,24 +28,30 @@ void Lamscript::Run(const std::string& source) {
28
28
29
29
if (had_error_) {
30
30
had_error_ = false ;
31
- return ;
31
+ return ProgramResult{ProgramStatus::FailedAtParser, 65 } ;
32
32
}
33
33
34
34
parsing::Resolver resolver = parsing::Resolver (interpreter_);
35
35
resolver.Resolve (statements);
36
36
37
37
if (had_error_) {
38
38
had_error_ = false ;
39
- return ;
39
+ return ProgramResult{ProgramStatus::FailedAtResolver, 65 } ;
40
40
}
41
41
42
42
interpreter_->Interpret (statements);
43
+
44
+ if (had_runtime_error_) {
45
+ return ProgramResult{ProgramStatus::FailedAtInterpeter, 70 };
46
+ }
47
+
48
+ return ProgramResult{ProgramStatus::Success, 0 };
43
49
}
44
50
45
51
// / @brief Run a given file.
46
52
// /
47
53
// / This functions throws if it cannot successfully open the file.
48
- void Lamscript::RunFile (const std::string& file_path) {
54
+ ProgramResult Lamscript::RunFile (const std::string& file_path) {
49
55
std::ifstream source_file (file_path, std::ios::in | std::ios::binary);
50
56
std::string source_code;
51
57
@@ -55,22 +61,14 @@ void Lamscript::RunFile(const std::string& file_path) {
55
61
source_file.seekg (0 , std::ios::beg);
56
62
source_file.read (&source_code[0 ], source_code.size ());
57
63
} else {
58
- throw " The Input file could not be read" ;
59
- }
60
-
61
- Run (source_code);
62
-
63
- if (had_error_) {
64
- exit (65 );
64
+ return ProgramResult{ProgramStatus::FailedAtReadingFile, 1 };
65
65
}
66
66
67
- if (had_runtime_error_) {
68
- exit (70 );
69
- }
67
+ return Run (source_code);
70
68
}
71
69
72
70
// / @brief Runs the prompt for the interpreter.
73
- void Lamscript::RunPrompt () {
71
+ ProgramResult Lamscript::RunPrompt () {
74
72
bool running = true ;
75
73
std::string source_line;
76
74
@@ -83,6 +81,7 @@ void Lamscript::RunPrompt() {
83
81
}
84
82
source_line.clear ();
85
83
}
84
+ return ProgramResult{ProgramStatus::Success, 0 };
86
85
}
87
86
88
87
// / @brief Report an error
0 commit comments