Can call the compiler from command line with argument
This commit is contained in:
@@ -96,6 +96,7 @@ gen_expr(Ast_Expr *ast){
|
|||||||
CASE(INDEX, Index){
|
CASE(INDEX, Index){
|
||||||
gen("(");
|
gen("(");
|
||||||
gen_expr(node->expr);
|
gen_expr(node->expr);
|
||||||
|
|
||||||
gen("[");
|
gen("[");
|
||||||
gen_expr(node->index);
|
gen_expr(node->index);
|
||||||
gen("]");
|
gen("]");
|
||||||
@@ -426,7 +427,6 @@ compile_string(String filecontent, String filename = "default_name"_s){
|
|||||||
pctx->resolving_package = result;
|
pctx->resolving_package = result;
|
||||||
F64 parse_end = os_time();
|
F64 parse_end = os_time();
|
||||||
|
|
||||||
|
|
||||||
gen(R"==(
|
gen(R"==(
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -448,6 +448,11 @@ typedef float F32;
|
|||||||
typedef double F64;
|
typedef double F64;
|
||||||
typedef S32 Bool;
|
typedef S32 Bool;
|
||||||
|
|
||||||
|
typedef struct Slice{
|
||||||
|
S64 len;
|
||||||
|
void *data;
|
||||||
|
}Slice;
|
||||||
|
|
||||||
typedef struct String{
|
typedef struct String{
|
||||||
U8 *str;
|
U8 *str;
|
||||||
S64 len;
|
S64 len;
|
||||||
|
|||||||
26
main.cpp
26
main.cpp
@@ -77,10 +77,9 @@ Expr:
|
|||||||
|
|
||||||
|
|
||||||
@todo
|
@todo
|
||||||
[ ] - Passing down program to compile through command line
|
|
||||||
[ ] - Arrays with size passed
|
[ ] - Arrays with size passed
|
||||||
[ ] - Switch
|
[ ] - Switch
|
||||||
[ ] - Fix printf somehow.
|
[ ] - Values inited to 0 by default
|
||||||
|
|
||||||
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
||||||
[ ] - Array of inferred size
|
[ ] - Array of inferred size
|
||||||
@@ -115,6 +114,7 @@ Expr:
|
|||||||
[x] - We are parsing wrong here: (t.str=(&string_to_lex.str)[i]);
|
[x] - We are parsing wrong here: (t.str=(&string_to_lex.str)[i]);
|
||||||
[x] - Test new operators, add constant eval for them
|
[x] - Test new operators, add constant eval for them
|
||||||
[x] - lvalue, rvalue concept so we cant assign value to some arbitrary weird expression
|
[x] - lvalue, rvalue concept so we cant assign value to some arbitrary weird expression
|
||||||
|
[x] - Passing down program to compile through command line
|
||||||
[x] - More basic types
|
[x] - More basic types
|
||||||
[x] - Implementing required operations int128
|
[x] - Implementing required operations int128
|
||||||
[x] - Fix casting
|
[x] - Fix casting
|
||||||
@@ -161,7 +161,7 @@ Expr:
|
|||||||
#include "typecheck.cpp"
|
#include "typecheck.cpp"
|
||||||
#include "ccodegen.cpp"
|
#include "ccodegen.cpp"
|
||||||
|
|
||||||
int main(){
|
int main(int argument_count, char **arguments){
|
||||||
// test_big_int();
|
// test_big_int();
|
||||||
|
|
||||||
test_os_memory();
|
test_os_memory();
|
||||||
@@ -191,15 +191,19 @@ int main(){
|
|||||||
printf("%s", result.str);
|
printf("%s", result.str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(argument_count > 1){
|
||||||
|
Scratch scratch;
|
||||||
|
String name = string_fmt(scratch, "%s.kl", arguments[1]);
|
||||||
|
String c_filename = string_fmt(scratch, "%s.c", arguments[1]);
|
||||||
|
String call = string_fmt(scratch, "clang.exe %s.c -g -o %s.exe && %s.exe", arguments[1], arguments[1], arguments[1]);
|
||||||
|
|
||||||
#if 1
|
result = compile_file(name);
|
||||||
result = compile_file("program.kl"_s);
|
FILE *f = fopen((const char *)c_filename.str, "w");
|
||||||
FILE *f = fopen("program.c", "w");
|
assert(f);
|
||||||
assert(f);
|
fprintf(f, "%.*s", (int)result.len, result.str);
|
||||||
fprintf(f, "%.*s", (int)result.len, result.str);
|
fclose(f);
|
||||||
fclose(f);
|
system((const char *)call.str);
|
||||||
system("clang.exe program.c -g -o program.exe");
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
__debugbreak();
|
__debugbreak();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ parsing_error(Token *token, const char *str, ...){
|
|||||||
STRING_FMT(scratch, str, string);
|
STRING_FMT(scratch, str, string);
|
||||||
|
|
||||||
// @Note(Krzosa): Print nice error message
|
// @Note(Krzosa): Print nice error message
|
||||||
printf("\nError: %s", string.str);
|
printf("\nError :: %s", string.str);
|
||||||
if(token){
|
if(token){
|
||||||
if(token->kind == TK_Error){
|
if(token->kind == TK_Error){
|
||||||
printf("Token Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
printf("Token Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||||
}
|
}
|
||||||
printf(" %s:%d\n", token->file.str, (S32)token->line + 1);
|
printf(" :: %s:%d\n", token->file.str, (S32)token->line + 1);
|
||||||
|
|
||||||
// @Note(Krzosa): Print error line
|
// @Note(Krzosa): Print error line
|
||||||
{
|
{
|
||||||
@@ -409,7 +409,11 @@ parse_expr(S64 min_bp){
|
|||||||
case TK_Decrement : left = ast_expr_unary(token, TK_Decrement, parse_expr(prefix_bp.right)); break;
|
case TK_Decrement : left = ast_expr_unary(token, TK_Decrement, parse_expr(prefix_bp.right)); break;
|
||||||
|
|
||||||
case TK_OpenBracket: {
|
case TK_OpenBracket: {
|
||||||
Ast_Array *result = ast_array(token, parse_expr(0));
|
Ast_Expr *expr = 0;
|
||||||
|
if(!token_is(TK_CloseBracket))
|
||||||
|
expr = parse_expr(0);
|
||||||
|
|
||||||
|
Ast_Array *result = ast_array(token, expr);
|
||||||
token_expect(TK_CloseBracket);
|
token_expect(TK_CloseBracket);
|
||||||
result->base = parse_expr(prefix_bp.right);
|
result->base = parse_expr(prefix_bp.right);
|
||||||
left = result;
|
left = result;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ binary_test :: (thing: S32 = 442)
|
|||||||
bit_xor :: 8 ^ 7
|
bit_xor :: 8 ^ 7
|
||||||
character :: 'ó
|
character :: 'ó
|
||||||
|
|
||||||
|
// '
|
||||||
|
|
||||||
boolean_equals :: true == false
|
boolean_equals :: true == false
|
||||||
boolean_var: Bool = boolean_equals
|
boolean_var: Bool = boolean_equals
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ typedef float F32;
|
|||||||
typedef double F64;
|
typedef double F64;
|
||||||
typedef S32 Bool;
|
typedef S32 Bool;
|
||||||
|
|
||||||
|
typedef struct Slice{
|
||||||
|
S64 len;
|
||||||
|
void *data;
|
||||||
|
}Slice;
|
||||||
|
|
||||||
typedef struct String{
|
typedef struct String{
|
||||||
U8 *str;
|
U8 *str;
|
||||||
S64 len;
|
S64 len;
|
||||||
|
|||||||
@@ -570,8 +570,12 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
|||||||
CASE(INDEX, Index){
|
CASE(INDEX, Index){
|
||||||
Operand left = resolve_expr(node->expr);
|
Operand left = resolve_expr(node->expr);
|
||||||
Operand index = resolve_expr(node->index);
|
Operand index = resolve_expr(node->index);
|
||||||
if(left.type->kind != TYPE_ARRAY && left.type->kind != TYPE_POINTER) parsing_error(node->pos, "Indexing variable that is not an [Array] or [Pointer], it's of type %s instead", docname(left.type));
|
if(!is_int(index.type)){
|
||||||
if(!is_int(index.type)) type_error(node->pos, untyped_int, index.type,"Trying to index the array with invalid type, expected int");
|
type_error(node->pos, untyped_int, index.type,"Trying to index the array with invalid type, expected int");
|
||||||
|
}
|
||||||
|
if(!is_array(left.type) && !is_pointer(left.type)){
|
||||||
|
parsing_error(node->pos, "Indexing variable that is not an [Array] or [Pointer], it's of type %s instead", docname(left.type));
|
||||||
|
}
|
||||||
return operand_lvalue(left.type->arr.base);
|
return operand_lvalue(left.type->arr.base);
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user