aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-06-07 10:47:47 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit53a331bc8b2fc33bd2b7e25a23b4128f89ee0b52 (patch)
tree2e5c0f4cda85b2afdb6142145fa7ded61d100f02 /tests
parent1b68fdcf5aebf2bc53bbd9234c77aea243c0decd (diff)
Add assignment, while, extern, function signature type, start on bytecode
Diffstat (limited to 'tests')
-rw-r--r--tests/b.amal.z6
-rw-r--r--tests/bytecode.amal12
-rw-r--r--tests/bytecode.amal.z11
-rw-r--r--tests/errors/const_assign.amal4
-rw-r--r--tests/errors/const_assign.amal.z6
-rw-r--r--tests/io.amal.z6
-rw-r--r--tests/main.amal22
-rw-r--r--tests/main.amal.z69
-rw-r--r--tests/main.c45
-rw-r--r--tests/sub/a.amal.z2
10 files changed, 122 insertions, 61 deletions
diff --git a/tests/b.amal.z b/tests/b.amal.z
index bf8e698..b9e0013 100644
--- a/tests/b.amal.z
+++ b/tests/b.amal.z
@@ -1,4 +1,2 @@
-typedef i64 signed long long;
-typedef f64 double;
-void f0() {
-}
+FUNC_START 0
+FUNC_END
diff --git a/tests/bytecode.amal b/tests/bytecode.amal
new file mode 100644
index 0000000..c5b2cb3
--- /dev/null
+++ b/tests/bytecode.amal
@@ -0,0 +1,12 @@
+extern const printf: fn;
+
+const print = fn {
+
+}
+
+const main = fn {
+ var value = 23;
+ value = 34;
+ const str_value = "hello, world";
+ print();
+} \ No newline at end of file
diff --git a/tests/bytecode.amal.z b/tests/bytecode.amal.z
new file mode 100644
index 0000000..2809b47
--- /dev/null
+++ b/tests/bytecode.amal.z
@@ -0,0 +1,11 @@
+FUNC_START 0
+FUNC_END
+FUNC_START 0
+mov r0, i0
+mov r1, r0
+mov r2, i1
+mov r1, r2
+mov r3, s0
+mov r4, r3
+call 0
+FUNC_END
diff --git a/tests/errors/const_assign.amal b/tests/errors/const_assign.amal
new file mode 100644
index 0000000..b0b0ec4
--- /dev/null
+++ b/tests/errors/const_assign.amal
@@ -0,0 +1,4 @@
+const main = fn {
+ const value = 23;
+ value = 34;
+} \ No newline at end of file
diff --git a/tests/errors/const_assign.amal.z b/tests/errors/const_assign.amal.z
new file mode 100644
index 0000000..99b1210
--- /dev/null
+++ b/tests/errors/const_assign.amal.z
@@ -0,0 +1,6 @@
+FUNC_START 0
+mov r0, i0
+mov r1, r0
+mov r2, i1
+mov r1, r2
+FUNC_END
diff --git a/tests/io.amal.z b/tests/io.amal.z
index bf8e698..b9e0013 100644
--- a/tests/io.amal.z
+++ b/tests/io.amal.z
@@ -1,4 +1,2 @@
-typedef i64 signed long long;
-typedef f64 double;
-void f0() {
-}
+FUNC_START 0
+FUNC_END
diff --git a/tests/main.amal b/tests/main.amal
index ae37816..c12ecba 100644
--- a/tests/main.amal
+++ b/tests/main.amal
@@ -20,8 +20,28 @@ const main = fn {
episfjpseifipesf
*/
io.puts("lole");
+ if num1 == 43
+ print(2);
}
const print = fn {
-} \ No newline at end of file
+}
+
+/*
+// Shader main function is guaranteed to be inline if run on CPU
+
+const vertex_passthrough = VertexShader {
+ const main = fn() vec4f {
+ return gl_ModelViewProjectionMatrix * gl_Vertex;
+ }
+}
+
+const fragment_passthrough = FragmentShader {
+ tex: texture2d;
+
+ const main = fn(coord: vec2f) vec2f {
+ return tex.getPixel(coord);
+ }
+}
+*/
diff --git a/tests/main.amal.z b/tests/main.amal.z
index 73d9dae..eac48f6 100644
--- a/tests/main.amal.z
+++ b/tests/main.amal.z
@@ -1,36 +1,33 @@
-typedef i64 signed long long;
-typedef f64 double;
-void f0() {
-void f1() {
-}
-const char* r0 = "hello";
-const char* r1 = r0;
-PUSH r0 ***
-const char* r2 = "world";
-PUSH r2 ***
-i64 r3 = 356;
-PUSH r3 ***
-f64 r4 = 13.370000;
-PUSH r4 ***
-r5 = CALL 0x621000010bc8 ***
-i64 r6 = 23232;
-i64 r7 = r6;
-i64 r8 = 30;
-r9 = r0 * r8;
-r10 = r0 + r9;
-i64 r11 = r10;
-r12 = r0 + r0;
-i64 r13 = 34;
-i64 r14 = 32;
-r15 = r13 + r14;
-i64 r16 = 2;
-r17 = r15 / r16;
-r18 = r0 * r17;
-r19 = r12 * r18;
-i64 r20 = r19;
-const char* r21 = "lole";
-PUSH r21 ***
-r22 = CALL 0x621000006948 ***
-}
-void f2() {
-}
+FUNC_START 0
+FUNC_START 0
+FUNC_END
+mov r0, s0
+mov r1, r0
+push r1
+mov r2, s1
+push r2
+mov r3, i0
+push r3
+mov r4, i1
+push r4
+call 2
+mov r6, i2
+mov r7, i3
+mov r8, r7
+mov r9, i4
+mov r12, r11
+mov r14, i5
+mov r15, i6
+mov r17, i7
+mov r21, r20
+mov r22, s2
+push r22
+call 0
+mov r24, i8
+jz r25, 24
+mov r26, i9
+push r26
+call 2
+FUNC_END
+FUNC_START 0
+FUNC_END
diff --git a/tests/main.c b/tests/main.c
index 04f2343..3080807 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -7,6 +7,9 @@
#include <stdlib.h>
#include <unistd.h>
+static int num_successful_tests = 0;
+static int num_tests_run = 0;
+
#define REQUIRE_EQ_INT(expected, actual) do{\
if((expected) != (actual)) {\
fprintf(stderr, "%s:%d: Assert failed (%s vs %s).\nExpected %d, got %d.\n", __FILE__, __LINE__, #expected, #actual, (expected), (actual));\
@@ -42,7 +45,7 @@ static CHECK_RESULT int test_hash_map() {
return 0;
}
-#define FAIL_TEST(name) do { fprintf(stderr, "Test failed: %s\n", (name)); exit(1); } while(0)
+#define FAIL_TEST(name) do { fprintf(stderr, "Test failed: %s\n", (name)); return; } while(0)
typedef struct {
char *filepath;
@@ -56,8 +59,8 @@ typedef struct {
static void error_callback_assert(const char *err_msg, int err_msg_len, void *userdata) {
ErrorExpectedData *expected_data;
- expected_data = userdata;
int expected_err_msg_len;
+ expected_data = userdata;
expected_err_msg_len = strlen(expected_data->expected_error);
if(expected_data->got_expected_error) {
@@ -74,14 +77,14 @@ static void error_callback_assert(const char *err_msg, int err_msg_len, void *us
expected_data->got_expected_error = bool_true;
}
-
+#if 0
static void error_callback(const char *err_msg, int err_msg_len, void *userdata) {
ErrorUnexpectedData *data;
data = userdata;
fprintf(stderr, "Test failed: %s with error: %.*s\n", data->filepath, err_msg_len, err_msg);
exit(1);
}
-
+#endif
static char* get_full_path(const char *filepath) {
#define PATH_LEN 4096
char *buf;
@@ -120,33 +123,39 @@ static char* join_str(const char *str1, const char *str2, char delimiter) {
static void test_load(const char *filepath) {
amal_compiler compiler;
amal_compiler_options options;
+ char *full_path;
int result;
amal_compiler_options_init(&options);
+ ++num_tests_run;
+ full_path = get_full_path(filepath);
+ /*
options.error_callback = error_callback;
ErrorUnexpectedData data;
data.filepath = get_full_path(filepath);
options.error_callback_userdata = &data;
+ */
result = amal_compiler_init(&compiler, &options);
if(result != AMAL_COMPILER_OK) {
- fprintf(stderr, "Failed to initialize compiler, error code: %d\n", result);
- FAIL_TEST(data.filepath);
+ fprintf(stderr, "Failed to initialize compiler to test %s, error code: %d\n", full_path, result);
+ FAIL_TEST(full_path);
}
result = amal_compiler_load_file(&compiler, filepath);
if(result != AMAL_COMPILER_OK) {
- fprintf(stderr, "Failed to load file %s, result: %d\n", data.filepath, result);
- FAIL_TEST(data.filepath);
+ fprintf(stderr, "Failed to load file %s, result: %d\n", full_path, result);
+ FAIL_TEST(full_path);
}
if(amal_compiler_deinit(&compiler) != 0) {
- fprintf(stderr, "Failed to deinitialize compiler.\n");
- FAIL_TEST(data.filepath);
+ fprintf(stderr, "Failed to deinitialize compiler for test %s\n", full_path);
+ FAIL_TEST(full_path);
}
- fprintf(stderr, "Test succeeded: %s\n", data.filepath);
- free(data.filepath);
+ fprintf(stderr, "Test succeeded as expected: %s\n", full_path);
+ ++num_successful_tests;
+ free(full_path);
}
static void test_load_error(const char *filepath, const char *expected_error) {
@@ -155,6 +164,7 @@ static void test_load_error(const char *filepath, const char *expected_error) {
int result;
amal_compiler_options_init(&options);
+ ++num_tests_run;
options.error_callback = error_callback_assert;
ErrorExpectedData expected_data;
expected_data.filepath = get_full_path(filepath);
@@ -184,7 +194,8 @@ static void test_load_error(const char *filepath, const char *expected_error) {
FAIL_TEST(expected_data.filepath);
}
- fprintf(stderr, "Test succeeded: %s\n", expected_data.filepath);
+ fprintf(stderr, "Test failed as expected: %s\n", expected_data.filepath);
+ ++num_successful_tests;
free(expected_data.filepath);
free(expected_data.expected_error);
}
@@ -205,11 +216,17 @@ int main(int argc, char **argv) {
" pub const num = 45;\n"
" ^\n");
test_load_error("tests/errors/closure_no_lhs.amal",
- "1:1: error: Expected variable declaration, string, variable or function call\n"
+ "1:1: error: Expected string, variable, closure, struct, function call or import\n"
"fn {}\n"
"^\n");
+ test_load_error("tests/errors/const_assign.amal",
+ "3:5: error: Can't assign to a const value\n"
+ " value = 34;\n"
+ " ^\n");
+ fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run);
} else if(argc == 2) {
test_load(argv[1]);
+ fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run);
} else {
fprintf(stderr, "usage: test [test-file-path]\n");
fprintf(stderr, "examples:\n");
diff --git a/tests/sub/a.amal.z b/tests/sub/a.amal.z
index e0c566e..e69de29 100644
--- a/tests/sub/a.amal.z
+++ b/tests/sub/a.amal.z
@@ -1,2 +0,0 @@
-typedef i64 signed long long;
-typedef f64 double;