Skip to content

Commit

Permalink
Merge pull request #133 from berdal84/refactor/result
Browse files Browse the repository at this point in the history
refactor|fixes: use Optional<T>, macros ";"
  • Loading branch information
berdal84 authored Oct 23, 2024
2 parents 64200fb + f42d40c commit cfa20cb
Show file tree
Hide file tree
Showing 23 changed files with 323 additions and 288 deletions.
10 changes: 5 additions & 5 deletions src/ndbl/cli/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void CLI::clear()

void CLI::log_function_call(const variant &result, const FunctionDescriptor *type)
{
LOG_MESSAGE("CLI", "CLI::%s() done (result: %s)\n",type->get_identifier(), result.to<std::string>().c_str())
LOG_MESSAGE("CLI", "CLI::%s() done (result: %s)\n",type->get_identifier(), result.to<std::string>().c_str());
}

std::string CLI::get_line()
Expand All @@ -124,15 +124,15 @@ bool CLI::PublicApi::serialize()
return true;
}

LOG_WARNING("CLI", "unable to serialize! Are you sure you entered an expression earlier?\n")
LOG_WARNING("CLI", "unable to serialize! Are you sure you entered an expression earlier?\n");
return false;
}

bool CLI::PublicApi::compile()
{
if( m_cli->compile() == nullptr)
{
LOG_ERROR("CLI", "unable to compile!\n")
LOG_ERROR("CLI", "unable to compile!\n");
return false;
}
return true;
Expand Down Expand Up @@ -204,13 +204,13 @@ bool CLI::run()

if( !load_program(m_asm_code) )
{
LOG_ERROR("CLI", "Unable to run program!\n")
LOG_ERROR("CLI", "Unable to run program!\n");
return false;
}

if( !run_program() )
{
LOG_ERROR("CLI", "Unable to run program!\n")
LOG_ERROR("CLI", "Unable to run program!\n");
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/ndbl/core/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ void Graph::clear()
return;
}

LOG_VERBOSE( "Graph", "Clearing graph ...\n")
LOG_VERBOSE( "Graph", "Clearing graph ...\n");
m_root = nullptr;
while ( !m_node_registry.empty() )
{
Node* node = m_node_registry[0];
LOG_VERBOSE("Graph", "destroying node \"%s\" (id: %zu)\n", node->name().c_str(), (u64_t)node )
LOG_VERBOSE("Graph", "destroying node \"%s\" (id: %zu)\n", node->name().c_str(), (u64_t)node );
destroy(node);
}

Expand All @@ -53,7 +53,7 @@ void Graph::clear()
}
#endif

LOG_VERBOSE("Graph", "Graph cleared.\n")
LOG_VERBOSE("Graph", "Graph cleared.\n");
}

bool Graph::update()
Expand Down Expand Up @@ -99,7 +99,7 @@ void Graph::add(Node* _node)

set_dirty();

LOG_VERBOSE("Graph", "add node %s (%s)\n", _node->name().c_str(), _node->get_class()->get_name())
LOG_VERBOSE("Graph", "add node %s (%s)\n", _node->name().c_str(), _node->get_class()->get_name());
}

void Graph::remove(Node* _node)
Expand Down Expand Up @@ -247,7 +247,7 @@ void Graph::remove(DirectedEdge edge)
}
else
{
LOG_WARNING("Graph", "Unable to unregister edge\n")
LOG_WARNING("Graph", "Unable to unregister edge\n");
}
set_dirty(); // To express this graph changed
}
Expand Down
22 changes: 11 additions & 11 deletions src/ndbl/core/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ void CPU::clear_registers()
qword CPU::read(Register _id)const
{
ASSERT(_id < Register_COUNT);
LOG_VERBOSE("CPU", "read register %s (value: %s)\n", Register_to_string(_id), m_register[_id].to_string().c_str() )
LOG_VERBOSE("CPU", "read register %s (value: %s)\n", Register_to_string(_id), m_register[_id].to_string().c_str() );
return m_register[_id];
}

qword& CPU::read_write(Register _id)
{
ASSERT(_id < Register_COUNT);
LOG_VERBOSE("CPU", "read_write register %s (value: %s)\n", Register_to_string(_id), m_register[_id].to_string().c_str() )
LOG_VERBOSE("CPU", "read_write register %s (value: %s)\n", Register_to_string(_id), m_register[_id].to_string().c_str() );
return m_register[_id];
}

Expand All @@ -41,7 +41,7 @@ void CPU::write(Register _id, qword _data)
ASSERT(_id < Register_COUNT);
qword& mem_dst = read_write(_id);
mem_dst = _data;
LOG_VERBOSE("CPU", "write register %s (value: %s)\n", Register_to_string(_id), mem_dst.to_string().c_str())
LOG_VERBOSE("CPU", "write register %s (value: %s)\n", Register_to_string(_id), mem_dst.to_string().c_str());
}

void Interpreter::advance_cursor(i64_t _amount)
Expand All @@ -54,7 +54,7 @@ void Interpreter::advance_cursor(i64_t _amount)
void Interpreter::run_program()
{
ASSERT(m_code);
LOG_MESSAGE("Interpreter", "Running program ...\n")
LOG_MESSAGE("Interpreter", "Running program ...\n");
m_is_program_running = true;
m_cpu.clear_registers();
m_visited_nodes.clear();
Expand All @@ -65,7 +65,7 @@ void Interpreter::run_program()
step_over();
}
stop_program();
LOG_MESSAGE("Interpreter", "Program terminated\n")
LOG_MESSAGE("Interpreter", "Program terminated\n");
}

void Interpreter::stop_program()
Expand All @@ -75,11 +75,11 @@ void Interpreter::stop_program()
m_is_program_running = false;
m_is_debugging = false;
m_next_node = {};
LOG_MESSAGE("Interpreter", "Program stopped\n")
LOG_MESSAGE("Interpreter", "Program stopped\n");
}
else
{
LOG_ERROR("Interpreter", "stop_program() failed, program is not running\n")
LOG_ERROR("Interpreter", "stop_program() failed, program is not running\n");
}
}

Expand All @@ -92,9 +92,9 @@ const Code* Interpreter::release_program()
}

m_cpu.clear_registers(); // will also clear reset instruction pointer (stored in a register Register_eip)
LOG_VERBOSE("Interpreter", "registers cleared\n")
LOG_VERBOSE("Interpreter", "registers cleared\n");

LOG_VERBOSE("Interpreter", "program released\n")
LOG_VERBOSE("Interpreter", "program released\n");
const Code* copy = m_code;
m_code = nullptr;
return copy;
Expand Down Expand Up @@ -325,7 +325,7 @@ bool Interpreter::debug_step_over()
default:
break;
}
LOG_MESSAGE("Interpreter", "Step over (current line %#1llx)\n", next_instr->line)
LOG_MESSAGE("Interpreter", "Step over (current line %#1llx)\n", next_instr->line);
}

return continue_execution;
Expand All @@ -340,7 +340,7 @@ void Interpreter::debug_program()
m_visited_nodes.clear();
m_next_node = m_code->get_meta_data().graph->get_root();

LOG_MESSAGE("Interpreter", "Debugging program ...\n")
LOG_MESSAGE("Interpreter", "Debugging program ...\n");
}

bool Interpreter::is_there_a_next_instr() const
Expand Down
2 changes: 1 addition & 1 deletion src/ndbl/core/NodableHeadless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool NodableHeadless::run_program() const
}
catch ( std::runtime_error& error)
{
LOG_ERROR("NodableHeadless", "Unable to run the program! %s\n", error.what())
LOG_ERROR("NodableHeadless", "Unable to run the program! %s\n", error.what());
return false;
}

Expand Down
9 changes: 0 additions & 9 deletions src/ndbl/core/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace ndbl
// forward declarations
class Graph;

/**
* Distinguish between all possible update_world_matrix result
*/
enum class UpdateResult
{
SUCCES_WITHOUT_CHANGES,
SUCCESS_WITH_CHANGES,
};

typedef int NodeFlags;
enum NodeFlag_
{
Expand Down
2 changes: 1 addition & 1 deletion src/ndbl/core/NodeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ VariableNode* NodeFactory::create_variable(const TypeDescriptor* _type, const st
}
else
{
LOG_WARNING("HeadlessNodeFactory", "Variable %s has_flags been created without defining its scope.\n", _name.c_str())
LOG_WARNING("HeadlessNodeFactory", "Variable %s has_flags been created without defining its scope.\n", _name.c_str());
}

m_post_process(node);
Expand Down
6 changes: 3 additions & 3 deletions src/ndbl/core/Scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ void Scope::add_variable(VariableNode* _variable)
{
if (find_variable(_variable->get_identifier()) != nullptr )
{
LOG_ERROR("Scope", "Unable to add variable '%s', already exists in the same scope.\n", _variable->get_identifier().c_str())
LOG_ERROR("Scope", "Unable to add variable '%s', already exists in the same scope.\n", _variable->get_identifier().c_str());
}
else if ( _variable->get_scope() )
{
LOG_ERROR("Scope", "Unable to add variable '%s', already declared in another scope. Remove it first.\n", _variable->get_identifier().c_str())
LOG_ERROR("Scope", "Unable to add variable '%s', already declared in another scope. Remove it first.\n", _variable->get_identifier().c_str());
}
else
{
LOG_VERBOSE("Scope", "Add variable '%s' to the scope\n", _variable->get_identifier().c_str() )
LOG_VERBOSE("Scope", "Add variable '%s' to the scope\n", _variable->get_identifier().c_str() );
m_variables.push_back(_variable);
_variable->reset_scope(this);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ndbl/core/TokenRibbon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,26 @@ Token TokenRibbon::eat_if(Token_t expectedType)

Token TokenRibbon::eat()
{
LOG_VERBOSE("Parser", "Eat token (idx %i) %s \n", m_cursor, peek().buffer_to_string().c_str() )
LOG_VERBOSE("Parser", "Eat token (idx %i) %s \n", m_cursor, peek().buffer_to_string().c_str() );
return m_tokens.at(m_cursor++);
}

void TokenRibbon::transaction_start()
{
m_transaction.push(m_cursor);
LOG_VERBOSE("Parser", "Start Transaction (idx %i)\n", m_cursor)
LOG_VERBOSE("Parser", "Start Transaction (idx %i)\n", m_cursor);
}

void TokenRibbon::transaction_rollback()
{
m_cursor = m_transaction.top();
LOG_VERBOSE("Parser", "Rollback transaction (idx %i)\n", m_cursor)
LOG_VERBOSE("Parser", "Rollback transaction (idx %i)\n", m_cursor);
m_transaction.pop();
}

void TokenRibbon::transaction_commit()
{
LOG_VERBOSE("Parser", "Commit transaction (idx %i)\n", m_cursor)
LOG_VERBOSE("Parser", "Commit transaction (idx %i)\n", m_cursor);
m_transaction.pop();
}

Expand Down
Loading

0 comments on commit cfa20cb

Please sign in to comment.