aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-10 00:22:26 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-10 00:22:26 +0100
commit135e40c12e99f97b667bdd561192ea44dd4ebd9e (patch)
tree68c1921593a748daceebe390d2ed98a90b5dc205
parentmds-kbdc: m bug fixes + more test cases (diff)
downloadmds-135e40c12e99f97b667bdd561192ea44dd4ebd9e.tar.gz
mds-135e40c12e99f97b667bdd561192ea44dd4ebd9e.tar.bz2
mds-135e40c12e99f97b667bdd561192ea44dd4ebd9e.tar.xz
mds-kbdc: compile-layout: m + more test cases
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/mds-kbdc/builtin-functions.c4
-rw-r--r--src/mds-kbdc/compile-layout.c19
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/invalid_call_to_builtin_function3
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/invalid_calls_to_set_3_and_get_224
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/builtin_functions62
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/call_to_builtin_function_with_empty_arguments2
6 files changed, 103 insertions, 11 deletions
diff --git a/src/mds-kbdc/builtin-functions.c b/src/mds-kbdc/builtin-functions.c
index 4ccc31f..fbff16f 100644
--- a/src/mds-kbdc/builtin-functions.c
+++ b/src/mds-kbdc/builtin-functions.c
@@ -145,7 +145,7 @@ static char32_t* builtin_function_rsh_2(const char32_t** restrict args)
{
define_2;
for (i = 0; i < n; i++)
- rc[i] = a[i % an] << b[i % bn];
+ rc[i] = a[i % an] >> b[i % bn];
return(rc);
}
@@ -160,7 +160,7 @@ static char32_t* builtin_function_lsh_2(const char32_t** restrict args)
{
define_2;
for (i = 0; i < n; i++)
- rc[i] = a[i % an] >> b[i % bn];
+ rc[i] = a[i % an] << b[i % bn];
return(rc);
}
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index ae29046..e6b6ced 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -18,7 +18,7 @@
#include "compile-layout.h"
/* TODO add call stack */
/* TODO fix so that for-loops do not generate the same errors/warnings in all iterations [loopy_error]. */
-/* TODO test all builtin functions */
+/* TODO test set/3 and get/2 */
/* TODO test function- and macro-overloading */
/* TODO test same-named macros and functions */
@@ -224,27 +224,28 @@ static int check_set_3_get_2_call(mds_kbdc_tree_t* restrict tree, int is_set, co
mds_kbdc_tree_t* variable;
mds_kbdc_tree_t* element;
- size_t index;
+ size_t index, arg_count;
if ((variable_arg[0] <= 0) || (variable_arg[1] != -1))
- FUN_ERROR(tree, ERROR, "first argument in call to function ‘%s’ must be a variable index", F);/* TODO test */
+ FUN_ERROR(tree, ERROR, "first argument in call to function ‘%s’ must be a variable index", F);
if ((index_arg[0] < 0) || (index_arg[1] != -1))
- FUN_ERROR(tree, ERROR, "second argument in call to function ‘%s’ must be an element index", F);/* TODO test */
+ FUN_ERROR(tree, ERROR, "second argument in call to function ‘%s’ must be an element index", F);
variable = variables_get((size_t)*variable_arg);
if (variable == NULL)
- FUN_ERROR(tree, ERROR, "‘\\%zu’ is not declared", (size_t)*variable_arg);/* TODO test */
+ FUN_ERROR(tree, ERROR, "‘\\%zu’ is not declared", (size_t)*variable_arg);
if (variable->type != C(ARRAY))
- FUN_ERROR(tree, ERROR, "‘\\%zu’ is not an array", (size_t)*variable_arg);/* TODO test */
+ FUN_ERROR(tree, ERROR, "‘\\%zu’ is not an array", (size_t)*variable_arg);
- index = (size_t)*index_arg;
+ arg_count = index = (size_t)*index_arg;
element = variable->array.elements;
while (element && index--)
element = element->next;
if (element == NULL)
- FUN_ERROR(tree, ERROR, "‘\\%zu’ does not hold %zu elements", (size_t)*variable_arg, (size_t)*index_arg);/* TODO test */
+ FUN_ERROR(tree, ERROR, "‘\\%zu’ does not hold %zu %s",
+ (size_t)*variable_arg, arg_count + 1, arg_count ? "elements" : "element");
return 0;
fail:
@@ -361,7 +362,7 @@ static int call_function(mds_kbdc_tree_t* restrict tree, const char* restrict na
FUN_ERROR(tree, ERROR,
"built-in function ‘%s/%zu’ requires that either none of"
" the arguments are empty strings or that all of them are",
- name, arg_count);/* TODO test */
+ name, arg_count);
}
/* Call the function. */
diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_call_to_builtin_function b/test-files/mds-kbdc/compile-layout/invalid/invalid_call_to_builtin_function
new file mode 100644
index 0000000..a3079e8
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_call_to_builtin_function
@@ -0,0 +1,3 @@
+"" : "\add("" 1)"
+"" : "\sub(1 "")"
+
diff --git a/test-files/mds-kbdc/compile-layout/invalid/invalid_calls_to_set_3_and_get_2 b/test-files/mds-kbdc/compile-layout/invalid/invalid_calls_to_set_3_and_get_2
new file mode 100644
index 0000000..c5cedc6
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/invalid_calls_to_set_3_and_get_2
@@ -0,0 +1,24 @@
+let \2 : ""
+let \3 : {}
+let \4 : { "0" }
+"" : "\set(0 0 0)"
+"" : "\get(0 0)"
+"" : "\set(1 0 0)"
+"" : "\get(1 0)"
+"" : "\set(2 0 0)"
+"" : "\get(2 0)"
+"" : "\set(3 0 0)"
+"" : "\get(3 0)"
+"" : "\set(4 1 0)"
+"" : "\get(4 1)"
+"" : "\set("" 0 0)"
+"" : "\get("" 0)"
+"" : "\set("a" 0 0)"
+"" : "\get("a" 0)"
+"" : "\set("aa" 0 0)"
+"" : "\get("aa" 0)"
+"" : "\set(1 "" 0)"
+"" : "\get(1 "")"
+"" : "\set(1 "aa" 0)"
+"" : "\get(1 "aa")"
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/builtin_functions b/test-files/mds-kbdc/compile-layout/valid/builtin_functions
new file mode 100644
index 0000000..c818472
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/builtin_functions
@@ -0,0 +1,62 @@
+if \not(\equals(\add(1 2) 3))
+ "" : 0
+end if
+if \not(\equals(\sub(5 3) 2))
+ "" : 0
+end if
+if \not(\equals(\mul(2 3) 6))
+ "" : 0
+end if
+if \not(\equals(\div(8 2) 4))
+ "" : 0
+end if
+if \not(\equals(\mod(14 4) 2))
+ "" : 0
+end if
+if \not(\equals(\rsh(1024 2) 256))
+ "" : 0
+end if
+if \not(\equals(\lsh(1 10) 1024))
+ "" : 0
+end if
+if \not(\equals(\or(7 9) 15))
+ "" : 0
+end if
+if \not(\equals(\and(15 5) 5))
+ "" : 0
+end if
+if \not(\equals(\xor(15 21) 26))
+ "" : 0
+end if
+if \not(1)
+ "" : 0
+end if
+if \not(0)
+else
+ "" : 0
+end if
+if \not(\equals(0 0))
+ "" : 0
+end if
+if \equals(0 1)
+ "" : 0
+end if
+if \not(\greater(2 1))
+ "" : 0
+end if
+if \greater(2 2)
+ "" : 0
+end if
+if \greater(2 3)
+ "" : 0
+end if
+if \not(\less(1 2))
+ "" : 0
+end if
+if \less(2 2)
+ "" : 0
+end if
+if \less(3 2)
+ "" : 0
+end if
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/call_to_builtin_function_with_empty_arguments b/test-files/mds-kbdc/compile-layout/valid/call_to_builtin_function_with_empty_arguments
new file mode 100644
index 0000000..783ec25
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/call_to_builtin_function_with_empty_arguments
@@ -0,0 +1,2 @@
+"\add("" "")" : "\not("")"
+