Skip to content

Commit

Permalink
Lot's of bugs have been fixed but todo list growed a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
SolindekDev committed Nov 30, 2023
1 parent 2a8dc6b commit 3b7fc53
Show file tree
Hide file tree
Showing 36 changed files with 260 additions and 97 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fun main() {

fun main() {
println("What's your name: ")
let user_name: string = input()
let user_name: string = read_line_stdin()
println("Welcome ")
println(user_name)
}
Expand Down
21 changes: 13 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
- [X] ... Arguments
- [X] Implement printf
- [X] Implement Extern
- [ ] Implement enum
- [ ] Implement every thing from barngo
- [X] Implement enum
- [X] Implement everything from barngo
- [ ] Implement structs
- [ ] Implement pointers
- [ ] Implement match
Expand All @@ -60,11 +60,16 @@
BUGS:
- [X] Make args parser finally work...
- [X] Make numbers act like booleans vice versa
- [ ] __use__
- [ ] Variable use so warning doesnt come up
- [X] __use__
- [X] Variable use so warning doesnt come up
- [ ] Conditions with string
- [ ] Seg fault with using int_to_string from std.ba
- [ ] \\\" bug
- [ ] constant variables and enums can't use runtime values like functions
- [ ] implement --no-main and --no-stdlib
- [ ] add some more info to unused variable warning
- [X] constant variables and enums can't use runtime values like functions
- [X] implement --no-main and --no-stdlib
- [ ] add some more info to unused variable warning
- [X] format arguments are not required
- [X] add || and &&
- [ ] implement __BARN_CURRENT_COMPILED_FILE__
- [ ] for loops...
- [ ] typecheck for enums
- [ ] test-12-extern-functions.ba is buggy
20 changes: 9 additions & 11 deletions examples/10-variable-declaration.ba
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
fun main() {
let num: int = 0
let _num: int = 0

let num1: int = 1 + 1
let num2: int = 1 - 1
let num3: int = 1 * 1
let num4: int = 1 / 1
let _num1: int = 1 + 1
let _num2: int = 1 - 1
let _num3: int = 1 * 1
let _num4: int = 1 / 1

let num5: int = (1 + ((1 * 2)))
let _num5: int = (1 + ((1 * 2)))

let wow_number: float = ((10.0 * 20) + (328 + 1 - 2390 - 21 + 21)) / 2
let _wow_number: float = ((10.0 * 20) + (328 + 1 - 2390 - 21 + 21)) / 2

let str1: string = "String"
let yeah: bool = true

// println(str1)
let _str1: string = "String"
let _yeah: bool = true
}
2 changes: 1 addition & 1 deletion examples/11-negative-numbers.ba
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fun main() {
let negative: int = -2
let __negative: int = -2
}
6 changes: 3 additions & 3 deletions examples/12-mathematical-operations-with-var.ba
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fun main() {
let first_var: int = 1
let next_var: int = first_var
let next_var_with_math: int = (first_var * 2) / next_var
let __first_var: int = 1
let __next_var: int = __first_var
let __next_var_with_math: int = (__first_var * 2) / __next_var
}
4 changes: 2 additions & 2 deletions examples/13-char-variable.ba
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let first_letter_name: char = 'B'
let __first_letter_name: char = 'B'

fun main() {
let second_letter_name: char = 'r'
let __second_letter_name: char = 'r'
}
3 changes: 3 additions & 0 deletions examples/15-assigment-variable.ba
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "std.ba"

fun pow2(float x) -> float {
return (x * x)
}
Expand All @@ -7,5 +9,6 @@ fun main() -> int {
pi = 3.14 // Whoops my bad

let area: float = pi * pow2(pi)
fmt_print("area: %f", area)
return 0 // Success
}
2 changes: 1 addition & 1 deletion examples/16-@import_c.ba
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import_c "stdio.h"

fun main() {
println("Siema")

}
2 changes: 1 addition & 1 deletion examples/23-iota-function-std.ba
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import "std.ba"

fun main() -> int {
let str: string = iota(20, 10)
let str: string = parse_string_to_int(20, 10)
println(str)
return 0
}
2 changes: 1 addition & 1 deletion examples/24-user-input-name-and-age.ba
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fun main() {
println("What's your name: ")
let user_name: string = input()
let user_name: string = read_line_stdin()
println("Welcome ")
println(user_name)
}
8 changes: 4 additions & 4 deletions examples/28-for-loop.ba
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@import "std.ba"

fun main() {
for let i: int = 0; i < 10; i++ {
printnum(i)
println("\n")
}
// for let i: int = 0; i < 10; i++ {
// printnum(i)
// println("\n")
// }
}
24 changes: 12 additions & 12 deletions examples/31-fizz-buzz-in-barn.ba
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@import "std.ba"

fun main() {
for let i: int = 0; i != 1000; i++ {
if (i % 15) == 0 {
println("FizzBuzz\t")
} elif (i % 3) == 0 {
println("Fizz\t")
} elif (i % 5) == 0 {
println("Buzz\t")
} else {
printnum(i)
println("\t")
}
}
// for let i: int = 0; i != 1000; i++ {
// if (i % 15) == 0 {
// println("FizzBuzz\t")
// } elif (i % 3) == 0 {
// println("Fizz\t")
// } elif (i % 5) == 0 {
// println("Buzz\t")
// } else {
// printnum(i)
// println("\t")
// }
// }
}
23 changes: 15 additions & 8 deletions examples/43-structures.ba
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
@import "std.ba"
// This is just a concept for now but i will
// go with this syntax

struct Person {
name: string,
age: i16
}
// ------------------

// @import "std.ba"

// struct Person {
// name: string,
// age: i16
// }

fun main() {
let me: Person = new Person{ "My name", 60 }
fmt_print("name: %s, age: %d", me.name, me.age)
}
// let me: Person = new Person{ "My name", 60 }
// fmt_print("name: %s, age: %d", me.name, me.age)
}

// ------------------
2 changes: 1 addition & 1 deletion extensions/vscode/barn-lang/syntaxes/barn.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
}]
},
"reserved-words": {
"match": "\\b(println|println|println|printbool|println|putchar|input|string_length|string_compare|string_reverse|iota|string_malloc|printnum)\\b",
"match": "\\b(println|println|fmt_print|printbool|println|putchar|read_line_stdin|string_length|string_compare|string_reverse|string_malloc|printnum)\\b",
"name": "entity.name.function.member.tpl"
},
"comments": {
Expand Down
5 changes: 5 additions & 0 deletions include/barn_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef enum __barn_node_kind_t {
BARN_NODE_VARIABLE_DECREMENTATION,

BARN_NODE_EXPRESSION,
BARN_NODE_IMPORT_C,

BARN_NODE_CONDITION_STATEMENT,
BARN_NODE_END_STATEMENT,
Expand Down Expand Up @@ -126,6 +127,10 @@ typedef struct __barn_node_t {
barn_node_t* function;
} function_call;

struct {
char* header;
} import_c;

struct {
barn_array_t* enum_fields;
} enumerate;
Expand Down
1 change: 1 addition & 0 deletions include/barn_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ void barn_parser_reset_local_variables(barn_parser_t* parser);
void barn_parser_append_node(barn_parser_t* parser, barn_node_t* node);

void barn_parser_show_ast(barn_parser_t* parser);
void barn_parser_import_c(barn_parser_t* parser);

#endif /* __BARN_PARSER__ */
2 changes: 2 additions & 0 deletions include/barn_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ char* barn_create_string_from_char(char c);
void barn_append_char_to_allocated_string(char** str, char c);
void barn_append_string_to_allocated_string(char** str, char* sstr);

bool barn_string_prefix(const char* string, const char* prefix);

#endif /* __BARN_STRING__ */
6 changes: 3 additions & 3 deletions libs/assert.ba
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
* ==========================
*/

// TODO: implement __BARN_CURRENT_COMPILED_FILE__
fun __barn_get_filename() -> string {
return __BARN_CURRENT_COMPILED_FILE__
// return __BARN_CURRENT_COMPILED_FILE__
return "__barn_get_filename is unimplemented"
}

/*
Expand All @@ -37,7 +39,6 @@ fun __barn_get_filename() -> string {
* ==========================
*/

__code__("[[noreturn]]")
fun __assert_failed___(string __filename, string __message) {
__code__("printf(\"Assertion Failed: %s: %s\n\", __filename, __message);")

Expand All @@ -51,7 +52,6 @@ fun __assert_failed___(string __filename, string __message) {
* ==========================
*/

__code__("[[noreturn]]")
fun assert(string __message) {
let filename: string = __barn_get_filename()
__assert_failed___(filename, __message)
Expand Down
5 changes: 5 additions & 0 deletions libs/std.ba
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ fun parse_double(string s) -> f64 {
__use__(s)
}

fun parse_string_to_int(int n, int base) -> string {
__use__(n)
__use__(base)
}

// TODO: fix int_to_string function

// Function for changing number to string
Expand Down
6 changes: 5 additions & 1 deletion main.ba
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@import "std.ba"

let text: string = "okokok"

fun main() -> int {
fmt_print(text, 0)
if 1 && 1 {
fmt_print(text)
}
return 0
}
16 changes: 11 additions & 5 deletions scripts/compile_all_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ def find_files_with_extension(directory, extension):
def is_path_to_folder(path):
return os.path.isdir(path)

def is_path_to_file(path):
return os.path.isfile(path)

def start_compilation_process(folder_path):
files = find_files_with_extension(folder_path, BARN_EXTENSION)

if (is_path_to_file("./barn")):
print(f"barn: compile_all_files.py: expected barn compiler at \"./barn\"")

if len(files) == 0:
print(f"barn: compile_all_files.py: there isn't any barn files (with extension {BARN_EXTENSION}) inside {folder_path}")
else:
success = 0
for file in files:
print(f"Compiling: {file}...")
completed_process = subprocess.run(f"barn {file}", shell=True, text=True, capture_output=True)
process = subprocess.run([f"./barn {file}"], timeout=2, shell=True)

if completed_process.returncode == 0:
print(f"Success: {completed_process.stdout}")
if process.returncode == 0:
success += 1
print(f"File {file} has been compiled successfully\n")
else:
print(f"Error message: \n{completed_process.stdout}")
exit(1)

total_files = len(files)
print(f"Successfully compiled {success}/{total_files}")

Expand Down
Loading

0 comments on commit 3b7fc53

Please sign in to comment.