Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 9d662d2

Browse files
committed
Made code be in many files.
Added support for multi-word arguments and for `--verbose` option that creates table instead couting logs. Preparing for v0.3.0 release.
1 parent 94ada76 commit 9d662d2

File tree

13 files changed

+593
-454
lines changed

13 files changed

+593
-454
lines changed

.idea/runConfigurations/sasm.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 44 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.19)
22
project(sasm)
33

44
set(CMAKE_CXX_STANDARD 20)
5-
set(CMAKE_CXX_FLAGS "-O")
6-
include_directories("submodules/tabulate/include")
7-
add_executable(sasm main.cpp)
5+
set(CMAKE_CXX_FLAGS "-O3")
6+
include_directories("submodules/tabulate/include" ".")
7+
set(SASM_LIB errors.hpp tools.hpp tokens.hpp options.hpp sasm_interpreter.hpp globals.hpp)
8+
9+
add_library(sasmutils ${SASM_LIB})
10+
set_target_properties(sasmutils PROPERTIES LINKER_LANGUAGE CXX)
11+
add_executable(sasm main.cpp)
12+
target_link_libraries(sasm sasmutils)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Feel free to contact me via Discussions tab on GitHub or via e-mail if you are e
1616
In Discussions tab there always is also a discussion about latest release.
1717

1818
# Known issues
19-
On GNU/Linux, `print*` commands doesn't work.
19+
On GNU/Linux, `print*` commands don't work.

errors.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
#include<functional>
3+
#include<iostream>
4+
5+
extern std::string global_file_name, global_line;
6+
extern std::size_t global_line_num;
7+
enum class STATUS
8+
{
9+
UNRECOGNISEDARG = -390, ARGUMENTSOVERFLOW = 3, ARGUMENTSUNDERFLOW = -3, DIVBYZERO = -1,
10+
SUCCESS = 0, /*ISNOTARRAY = 1,*/ UNDECLAREDID = 2, NOFILE = -2, EMPTYSTACK = 390
11+
};
12+
13+
template<typename ...AdditionalParams>
14+
STATUS Error(const std::function<STATUS(const std::string&, const std::string&, const std::size_t&, AdditionalParams...)>& f, AdditionalParams ...args)
15+
{
16+
return f(global_file_name, global_line, global_line_num, args...);
17+
}
18+
STATUS WrongArity(const std::string& file_name, const std::string& line, const std::size_t& line_num, const std::string& instr, const unsigned short& corr_args, const unsigned short& actual_args)
19+
{
20+
std::cerr << "In file " << file_name << ": line: " << line_num << ": error: '" << instr << "' statement accepts only " << corr_args << " operand" << (corr_args != 1 ? "s" : "") << ", but " << actual_args << " were given!" << std::endl;
21+
std::cerr << line << std::endl;
22+
return (corr_args < actual_args ? STATUS::ARGUMENTSOVERFLOW : STATUS::ARGUMENTSUNDERFLOW);
23+
}
24+
STATUS UndeclaredID(const std::string& file_name, const std::string& line, const std::size_t& line_num, const std::string& instr)
25+
{
26+
std::cerr << "In file " << file_name << ": line: " << line_num << ": error: Undeclared identifier: '" << instr << "'!" << std::endl;
27+
std::cerr << line << std::endl;
28+
return STATUS::UNDECLAREDID;
29+
}
30+
STATUS EmptyStack(const std::string& file_name, const std::string& line, const std::size_t& line_num, const std::string& instr)
31+
{
32+
std::cerr << "In file " << file_name << ": line: " << line_num << ": error: Stack is empty, but '" << instr << "' was used!" << std::endl;
33+
std::cerr << line << std::endl;
34+
return STATUS::EMPTYSTACK;
35+
}
36+
STATUS DivisionByZero(const std::string& file_name, const std::string& line, const std::size_t& line_num)
37+
{
38+
std::cerr << "In file " << file_name << ": line: " << line_num << ": error: Division by 0!" << std::endl;
39+
std::cerr << line << std::endl;
40+
return STATUS::DIVBYZERO;
41+
}

examples/hello_world.sasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load Hello
22
printps
33
; Quotes aren't implemented and <space> terminates arguments (not only ',' terminates), so you have to write space character this way:
4+
; Er... you now can `load Hello World' normally, but without quotes
45
load 32
56
printpc
67
; Feature available in versions 0.1.0-beta+test and 0.1.0-beta+noverbose or higher: blank line

examples/spaces-in-args.sasm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; New feature: spaces in arguments (v0.3.0)
2+
load Hello World!
3+
printps
4+
load 10
5+
printpc

globals.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Created by Antoni Kiedos on 30.06.2021.
3+
//
4+
5+
#ifndef SASM_GLOBALS_HPP
6+
#define SASM_GLOBALS_HPP
7+
#include<stack>
8+
#include<string>
9+
#include<vector>
10+
#include "tokens.hpp"
11+
12+
std::stack<std::string> global_stack{};
13+
std::string global_line{};
14+
std::string global_file_name{};
15+
std::size_t global_line_num = 0;
16+
std::vector<std::string> global_instruction{};
17+
INSTR global_mnemonic{};
18+
std::string global_op1{}, global_op2{}, global_op3{}, global_op4{};
19+
int global_aux_i{};
20+
std::stack<std::string> global_aux_dbg_stack{};
21+
std::string global_aux_dbg_elem{};
22+
bool global_printc_aux_b_operand_is_num{false};
23+
int global_printc_aux_i{};
24+
bool global_printpc_aux_b_operand_is_num{false};
25+
int global_printpc_aux_i{};
26+
27+
#endif //SASM_GLOBALS_HPP

0 commit comments

Comments
 (0)