File tree Expand file tree Collapse file tree 3 files changed +17
-18
lines changed Expand file tree Collapse file tree 3 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,18 @@ struct RequestVisitor
12
12
{
13
13
bool operator ()( const Utilities::CommandLineParser::Config& config ) const
14
14
{
15
- const Hasm::AssemblerEngine assembler{ []( const auto & log ) { std::cout << log << std::endl; } };
16
-
17
- return assembler.run ( { config.inputFile , config.exportSymbols } );
15
+ try
16
+ {
17
+ const Hasm::AssemblerEngine assembler{ []( const auto & log ) { std::cout << log << std::endl; } };
18
+
19
+ return assembler.run ( { config.inputFile , config.exportSymbols } );
20
+ }
21
+ catch ( const std::exception& exception )
22
+ {
23
+ std::cerr << exception.what () << std::endl;
24
+
25
+ return false ;
26
+ }
18
27
}
19
28
20
29
bool operator ()( const Utilities::CommandLineParser::RequestToPrintHelp& help ) const
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ class Assembler
34
34
Hack::word computeValue ( const std::string& symbol );
35
35
bool isValidValue ( Hack::word value ) const ;
36
36
void output ( Hack::word word );
37
- void displayInvalidACommandMessage ();
38
37
39
38
std::ostream& m_out;
40
39
Parser m_parser;
Original file line number Diff line number Diff line change @@ -92,26 +92,17 @@ bool Assembler::assembleAddressingInstruction()
92
92
{
93
93
const auto symbol = m_parser.symbol ();
94
94
const auto value = computeValue ( symbol );
95
- const auto isValid = isValidValue ( value );
96
95
97
- if ( isValid )
96
+ if ( isValidValue ( value ) )
98
97
{
99
98
output ( value );
100
- }
101
- else
102
- {
103
- displayInvalidACommandMessage ();
104
- }
105
99
106
- return isValid ;
107
- }
100
+ return true ;
101
+ }
108
102
109
- void Assembler::displayInvalidACommandMessage ()
110
- {
111
- const auto cmd = m_parser.getInstruction ();
112
- const auto lineNumber = m_parser.getCurrentLineNumber ();
103
+ m_logger ( ErrorMessage::invalidLoadValue ( m_parser.getInstruction (), m_parser.getCurrentLineNumber () ) );
113
104
114
- m_logger ( ErrorMessage::invalidLoadValue ( cmd, lineNumber ) ) ;
105
+ return false ;
115
106
}
116
107
117
108
bool Assembler::assembleComputationInstruction ()
You can’t perform that action at this time.
0 commit comments