~starkingdoms/starkingdoms

02374995e7050f311dc9676f47905f1c4a12f757 — ghostly_zsh 1 year, 4 months ago 3aca67b
a few tests
M kabel/src/lib.rs => kabel/src/lib.rs +3 -0
@@ 94,6 94,9 @@ pub fn compile(program: String) -> String {
        output += &error.to_string();
        output += "\n";
    }
    if analyzer.errors.len() != 0 {
        return output;
    }
    #[cfg(feature = "timer")]
    {
        let analyzer_elapsed = analyzer_instant.elapsed();

M kabel_test/src/main.rs => kabel_test/src/main.rs +10 -4
@@ 1,13 1,15 @@
//use std::{env, fs};

use std::{env, fs};

use kabel::{debug::{debug_ast, debug_bytecode, debug_token_array}, run_codegen, run_lexer, run_parser, run_semantic_analysis};

fn main() {
    /*let args: Vec<String> = env::args().collect();
    let args: Vec<String> = env::args().collect();
    let program =
        fs::read_to_string(args[1].clone()).unwrap();*/
        fs::read_to_string(args[1].clone()).unwrap();

    let program =
    /*let program =
"if(true) {
    print \"if\";
} else if(true) {


@@ 16,7 18,7 @@ fn main() {
    print \"else\";
}
print \"after\";
".to_string();
".to_string();*/

    let mut output = "".to_string();



@@ 51,6 53,10 @@ print \"after\";
        output += &error.to_string();
        output += "\n";
    }
    if analyzer.errors.len() != 0 {
        println!("{}", output);
        return;
    }

    let codegen = run_codegen(program, ast);


M kabel_test/test/lexer/arithmetic.kab => kabel_test/test/lexer/arithmetic.kab +2 -0
@@ 8,3 8,5 @@
6%4

3 * (8 + 4)

3.0

M kabel_test/test/lexer/arithmetic.out => kabel_test/test/lexer/arithmetic.out +1 -0
@@ 26,3 26,4 @@ Num 8
Plus
Num 4
RightParen
Num 3

A kabel_test/test/runtime/arithmetic_run.kab => kabel_test/test/runtime/arithmetic_run.kab +13 -0
@@ 0,0 1,13 @@
print 2+2; // 4
print 2+2*3; // 8
print 2 - 2; // 0
print 2.1+2.3*3; // 9
print 2 / 4; // 0.5
print 5 % 4; // 1
print 2 / -4; // -0.5
print 5 * 4 / 2; // 10
print 4 * 5 / 2; // 10

print 3 & 8 + 4; // 0
print 4 ^ 7; // 3
print 8 | 2; // 10

A kabel_test/test/runtime/arithmetic_run.out => kabel_test/test/runtime/arithmetic_run.out +12 -0
@@ 0,0 1,12 @@
4
8
0
9
0.5
1
-0.5
10
10
0
3
10

A kabel_test/test/runtime/if_statement.kab => kabel_test/test/runtime/if_statement.kab +40 -0
@@ 0,0 1,40 @@
if(5 == 4) {
    print 1;
} else {
    print 3;
}
print 4;

if(1 < 3) {
    print 2;
}

if(5 >= 5) {
    print 8;
} else if(false) {
    print 9;
} else {
    print 6;
}

if(false) {
    print 3;
} else if(true) {
    print 4;
} else {
    print 6;
}

if(2 < 4) {
    print "foo";
} else {
    print "bar";
}

if(false) {
    print 5;
} else if(false) {
    print 0;
} else {
    print 1;
}

A kabel_test/test/runtime/if_statement.out => kabel_test/test/runtime/if_statement.out +7 -0
@@ 0,0 1,7 @@
3
4
2
8
4
foo
1

A kabel_test/test/runtime/logic.kab => kabel_test/test/runtime/logic.kab +39 -0
@@ 0,0 1,39 @@
print 2 == 2; // true
print 3 == 2; // false
print "hi" == "hi"; // true
print "hi" == 2; // false
print "hi" == "true"; // false

print 2 != 2; // false
print 5 != 2; // true
print "hi" != "hi"; // false

print 2 > 3; // false
print 3 > 3; // false
print 5 > 3; // true

print 2 >= 3; // false
print 3 >= 3; // true
print 5 >= 3; // true

print 2 < 3; // true
print 3 < 3; // false
print 5 < 3; // false

print 2 <= 3; // true
print 3 <= 3; // true
print 5 <= 3; // false

print true && true; // true
print false && true; // false
print true && false; // false
print false && false; // false

print true || true; // true
print false || true; // true
print true || false; // true
print false || false; // false

print 5 > 2 || 2 < 3*2; // true
print 2 < 4 && 5 > 2 || 9 < 8; // true
print false && true && false; // false

A kabel_test/test/runtime/logic.out => kabel_test/test/runtime/logic.out +31 -0
@@ 0,0 1,31 @@
true
false
true
false
false
false
true
false
false
false
true
false
true
true
true
false
false
true
true
false
true
false
false
false
true
true
true
false
true
true
false