Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/factorial.con
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function main():
!result rax
call printf(fmt, result)

mov rax, 60
syscall
syscall exit()

section .data
fmt: db "%d", 10, 0
3 changes: 2 additions & 1 deletion examples/strchr.con
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ extern printf
section .text
function strchr(str, chr):
!ptrresult rax
!findchr sil
mov ptrresult, 0
while byte[str] ne 0:
if byte[str] e chr:
if byte[str] e findchr:
mov ptrresult, str
ret
inc str
Expand Down
7 changes: 4 additions & 3 deletions src/construct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <fstream>
#include <sstream>
#include "construct_types.h"
#include "deconstruct.h" // parse_construct()
#include "reconstruct.h" // linearize_tokens()
#include "construct_flags.h" // handle_flags()
#include "deconstruct.h"
#include "reconstruct.h"
#include "construct_flags.h"

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -40,6 +40,7 @@ int main(int argc, char** argv)
apply_ifs(tokens);
apply_whiles(tokens);
apply_funcalls(tokens);
apply_syscalls(tokens);
std::vector<con_macro> empty_macros;
apply_macros(tokens, empty_macros);
linearize_tokens(tokens);
Expand Down
8 changes: 6 additions & 2 deletions src/construct_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ std::string tokentype_to_string(CON_TOKENTYPE type)
return "macro";
case FUNCALL:
return "funcall";
case SYSCALL:
return "syscall";
}
throw std::invalid_argument("Invalid token type: "+std::to_string(static_cast<int>(type)));
}
Expand All @@ -39,10 +41,12 @@ std::string token_to_string(con_token token)
tokstring += ", name: " + token.tok_tag->name;
break;
case WHILE:
tokstring += ", condition: " + token.tok_while->condition.arg1 + " " + comparison_to_string(token.tok_while->condition.op) + " " + token.tok_while->condition.arg2;
tokstring += ", condition: " + token.tok_while->condition.arg1 + " "
+ comparison_to_string(token.tok_while->condition.op) + " " + token.tok_while->condition.arg2;
break;
case IF:
tokstring += ", condition: " + token.tok_if->condition.arg1 + " " + comparison_to_string(token.tok_if->condition.op) + " " + token.tok_if->condition.arg2;
tokstring += ", condition: " + token.tok_if->condition.arg1 + " "
+ comparison_to_string(token.tok_if->condition.op) + " " + token.tok_if->condition.arg2;
break;
case FUNCTION:
tokstring += ", function: " + token.tok_function->name + ", arguments: ";
Expand Down
11 changes: 9 additions & 2 deletions src/construct_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ enum CON_TOKENTYPE {
FUNCTION,
CMD,
MACRO,
FUNCALL
FUNCALL,
SYSCALL
};


Expand All @@ -43,7 +44,8 @@ struct con_token {
struct con_cmd* tok_cmd;
struct con_macro* tok_macro;
struct con_funcall* tok_funcall;
std::vector<con_token*> tokens; // Only non-empty for if, while and function tokens
struct con_syscall* tok_syscall;
std::vector<con_token*> tokens; // relevant to "if", "while", "function" and "syscall" tokens
};

struct _con_condition {
Expand Down Expand Up @@ -89,4 +91,9 @@ struct con_funcall {
std::vector<std::string> arguments;
};

struct con_syscall {
uint16_t number;
std::vector<std::string> arguments;
};

#endif // CONSTRUCT_TYPES_H_
Loading