Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
omaraflak committed Aug 28, 2023
1 parent 5dfdcf4 commit f1ac7f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct {

typedef struct {
std::vector<Token> tokens;
int current;
size_t current;
std::map<std::shared_ptr<AbstractSyntaxTree>, Frame> frames;
std::stack<std::shared_ptr<AbstractSyntaxTree>> frame_stack;
std::map<std::string, std::shared_ptr<FunctionNode>> functions;
Expand Down Expand Up @@ -159,7 +159,7 @@ bool match_sequence(Parser& parser, const std::vector<std::set<TokenType>>& type
if (parser.current + types.size() >= parser.tokens.size()) {
return false;
}
for (int i = 0; i < types.size(); i++) {
for (size_t i = 0; i < types.size(); i++) {
if (types[i].find(parser.tokens[parser.current + i].type) == types[i].end()) {
return false;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ std::shared_ptr<AbstractSyntaxTree> binary_expression(
Parser& parser,
const std::vector<std::vector<TokenType>>& types,
TokenType expected_type,
const int& index = 0
const size_t& index = 0
) {
if (index == types.size()) {
return unary_expression(parser, expected_type);
Expand Down Expand Up @@ -440,7 +440,7 @@ void check_native_function(

bool same_parameters_type = expected_types.size() == actual_types.size();
if (same_parameters_type) {
for (int i = 0; i < expected_types.size(); i++) {
for (size_t i = 0; i < expected_types.size(); i++) {
if (C_TYPE_TO_AST_TYPE.at(expected_types.at(i)) != actual_types.at(i)->get_type()) {
same_parameters_type = false;
break;
Expand All @@ -454,7 +454,7 @@ void check_native_function(
}

std::cout << "Expected following function signature: " << C_TYPE_NAME.at(fun->get_return_type()) << " " << id << "(";
for (int i = 0; i < expected_types.size(); i++) {
for (size_t i = 0; i < expected_types.size(); i++) {
std::cout << C_TYPE_NAME.at(expected_types.at(i));
if (i + 1 < expected_types.size()) {
std::cout << ", ";
Expand All @@ -463,7 +463,7 @@ void check_native_function(
std::cout << ");";

std::cout << std::endl << "But got this instead: " << AST_TYPE_NAME.at(node->get_return_type()) << " " << id << "(";
for (int i = 0; i < node->get_parameters_count(); i++) {
for (size_t i = 0; i < node->get_parameters_count(); i++) {
std::cout << AST_TYPE_NAME.at(actual_types.at(i)->get_type());
if (i + 1 < node->get_parameters_count()) {
std::cout << ", ";
Expand Down Expand Up @@ -656,7 +656,7 @@ std::shared_ptr<BlockNode> block(Parser& parser) {
std::shared_ptr<BlockNode> block(new BlockNode());
push_scope(parser, block);
const Frame& frame = parser.frames.at(current_frame(parser));
const int nest_level = frame.scope_stack.size();
const size_t nest_level = frame.scope_stack.size();
while (
!eof(parser) && (
frame.scope_stack.size() != nest_level ||
Expand Down
12 changes: 6 additions & 6 deletions lib/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace scanner {
struct Scanner {
std::string code;
int start;
int current;
int line;
size_t start;
size_t current;
size_t line;
};

Token create_token(const TokenType& type, const Scanner& scanner) {
Expand All @@ -26,7 +26,7 @@ bool is_character(const char& c) {
}

bool match_string(const Scanner& scanner, const std::string& str, const bool& keyword = false) {
for (int i = 0; i < str.size(); i++) {
for (size_t i = 0; i < str.size(); i++) {
const char p = scanner.code[scanner.current + i];
if (p == '\0' || p != str[i]) {
return false;
Expand All @@ -39,7 +39,7 @@ bool match_string(const Scanner& scanner, const std::string& str, const bool& ke
}

int match_quote(const Scanner& scanner) {
int p = scanner.current + 1;
size_t p = scanner.current + 1;
while (p < scanner.code.size() && scanner.code[p] != '\n') {
if (scanner.code[p] == '\\') {
p += 2;
Expand Down Expand Up @@ -70,7 +70,7 @@ int match_identifier(const Scanner& scanner) {
}

int next_line(const Scanner& scanner) {
int p = scanner.current;
size_t p = scanner.current;
while (p < scanner.code.size() && scanner.code[p] != '\n') {
p++;
}
Expand Down

0 comments on commit f1ac7f6

Please sign in to comment.