aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/compile-layout.c12
-rw-r--r--src/mds-kbdc/make-tree.c1
-rw-r--r--src/mds-kbdc/variables.c3
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/macro-value_without_sideeffect5
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/nilreturning_function4
-rw-r--r--test-files/mds-kbdc/compile-layout/invalid/value_without_sideeffect2
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/do_not_shadow_variable_with_for5
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/function-if-value-end-value10
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/function-value-if-value8
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/function-value-if-value-end-value11
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/function-value-value6
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/identity_function5
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/let-function-end-nonshadowing_for7
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/let-function-shadowing_for7
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/macro_15
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/map_with_function_call5
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/override_variable3
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_for7
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_function_call7
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_let9
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_macro_call6
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/value_with_indirect_sideeffect6
-rw-r--r--test-files/mds-kbdc/compile-layout/valid/value_with_sideeffect3
23 files changed, 129 insertions, 8 deletions
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index bd906d5..ae29046 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -174,7 +174,7 @@ static int let(size_t variable, const char32_t* restrict string, const mds_kbdc_
statement && (statement->processed != PROCESS_LEVEL))
{
statement->processed = PROCESS_LEVEL;
- NEW_ERROR(statement, WARNING, "does not shadow existing definition");/* TODO test */
+ NEW_ERROR(statement, WARNING, "does not shadow existing definition");
error->start = lineoff;
error->end = lineoff + (size_t)snprintf(NULL, 0, "\\%zu", variable);
}
@@ -315,7 +315,7 @@ static int call_function(mds_kbdc_tree_t* restrict tree, const char* restrict na
/* Push call stack and set parameters. */
variables_stack_push();
for (i = 0; i < arg_count; i++)
- fail_if (let(i, arguments[i], NULL, NULL, 0, 0));
+ fail_if (let(i + 1, arguments[i], NULL, NULL, 0, 0));
/* Switch include-stack to the function's. */
fail_if (our_include_stack = mds_kbdc_include_stack_save(), our_include_stack == NULL);
@@ -333,7 +333,7 @@ static int call_function(mds_kbdc_tree_t* restrict tree, const char* restrict na
/* Check that the function returned a value. */
if (*return_value == NULL)
- FUN_ERROR(tree, ERROR, "function ‘%s/%zu’ did not return a value", name, arg_count);/* TODO test */
+ FUN_ERROR(tree, ERROR, "function ‘%s/%zu’ did not return a value", name, arg_count);
goto done;
}
@@ -2410,7 +2410,7 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
array that is not shadowed by an inner function- or macro-call. */
if (r && !have_side_effect)
{
- NEW_ERROR(tree, ERROR, "value-statement outside function without side-effects");/* TODO test */
+ NEW_ERROR(tree, ERROR, "value-statement outside function without side-effects");
tree->processed = PROCESS_LEVEL;
}
if (have_side_effect)
@@ -2422,7 +2422,7 @@ static int compile_map(mds_kbdc_tree_map_t* restrict tree)
/* For simplicity we set `last_value_statement` on includes,
* so we are sure `last_value_statement` has the same include-stack. */
- NEW_ERROR(previous_last_value_statement, WARNING, "value-statement has no effects");/* TODO test */
+ NEW_ERROR(previous_last_value_statement, WARNING, "value-statement has no effects");
NEW_ERROR(tree, NOTE, "overridden here");
}
@@ -2469,7 +2469,7 @@ static int compile_macro_call(mds_kbdc_tree_macro_call_t* restrict tree)
fail_if (arg = mds_kbdc_tree_dup(tree->arguments), arg == NULL);
fail_if (bad = evaluate_element(arg), bad < 0);
if (bad)
- return 0;
+ return mds_kbdc_tree_free(arg), 0;
/* Get the macro's subtree and include-stack, if it has
not been defined `get_macro` will add an error message
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c
index 7534a40..960fe22 100644
--- a/src/mds-kbdc/make-tree.c
+++ b/src/mds-kbdc/make-tree.c
@@ -788,6 +788,7 @@ static int test_for_keyword(const char* restrict keyword)
SKIP_SPACES(end);
prev_end_char = *end, *end = '\0';
NEW_ERROR(1, ERROR, "expecting keyword ‘%s’", keyword);
+ error->end = error->start + 1;
return 0;
fail:
diff --git a/src/mds-kbdc/variables.c b/src/mds-kbdc/variables.c
index 7431767..155edd7 100644
--- a/src/mds-kbdc/variables.c
+++ b/src/mds-kbdc/variables.c
@@ -168,8 +168,7 @@ int variables_let(size_t variable, mds_kbdc_tree_t* restrict value)
{
/* Shadow or define. */
previous = variables[variable];
- variables[variable] = malloc(sizeof(variable_t));
- if (variables[variable] == NULL)
+ if (xmalloc(variables[variable], 1, variable_t))
fail_if (variables[variable] = previous, 1);
variables[variable]->value = value;
variables[variable]->previous = previous;
diff --git a/test-files/mds-kbdc/compile-layout/invalid/macro-value_without_sideeffect b/test-files/mds-kbdc/compile-layout/invalid/macro-value_without_sideeffect
new file mode 100644
index 0000000..a85e1b2
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/macro-value_without_sideeffect
@@ -0,0 +1,5 @@
+macro m/0
+ "a"
+end macro
+m()
+
diff --git a/test-files/mds-kbdc/compile-layout/invalid/nilreturning_function b/test-files/mds-kbdc/compile-layout/invalid/nilreturning_function
new file mode 100644
index 0000000..f3518a4
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/nilreturning_function
@@ -0,0 +1,4 @@
+function f/0
+end function
+"\f()" : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/invalid/value_without_sideeffect b/test-files/mds-kbdc/compile-layout/invalid/value_without_sideeffect
new file mode 100644
index 0000000..8da2ae3
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/invalid/value_without_sideeffect
@@ -0,0 +1,2 @@
+"a"
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/do_not_shadow_variable_with_for b/test-files/mds-kbdc/compile-layout/valid/do_not_shadow_variable_with_for
new file mode 100644
index 0000000..677735c
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/do_not_shadow_variable_with_for
@@ -0,0 +1,5 @@
+let \1 : 0
+for 1 to 1 as \1
+end for
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/function-if-value-end-value b/test-files/mds-kbdc/compile-layout/valid/function-if-value-end-value
new file mode 100644
index 0000000..0b90798
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/function-if-value-end-value
@@ -0,0 +1,10 @@
+# It is acceptable not to find unneccessary statements
+
+function f/0
+ if 1
+ "a"
+ end if
+ "a"
+end function
+<letter \f()> : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/function-value-if-value b/test-files/mds-kbdc/compile-layout/valid/function-value-if-value
new file mode 100644
index 0000000..a9f2394
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/function-value-if-value
@@ -0,0 +1,8 @@
+function f/0
+ "a"
+ if 1
+ "a"
+ end if
+end function
+<letter \f()> : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/function-value-if-value-end-value b/test-files/mds-kbdc/compile-layout/valid/function-value-if-value-end-value
new file mode 100644
index 0000000..3d8644a
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/function-value-if-value-end-value
@@ -0,0 +1,11 @@
+# It is acceptable not to find unneccessary statements
+
+function f/0
+ "a"
+ if 1
+ "a"
+ end if
+ "a"
+end function
+<letter \f()> : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/function-value-value b/test-files/mds-kbdc/compile-layout/valid/function-value-value
new file mode 100644
index 0000000..71a282e
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/function-value-value
@@ -0,0 +1,6 @@
+function f/0
+ "a"
+ "a"
+end function
+<letter \f()> : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/identity_function b/test-files/mds-kbdc/compile-layout/valid/identity_function
new file mode 100644
index 0000000..0cd4371
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/identity_function
@@ -0,0 +1,5 @@
+function id/1
+ \1
+end function
+<letter \id("a")> : "\id("a")"
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/let-function-end-nonshadowing_for b/test-files/mds-kbdc/compile-layout/valid/let-function-end-nonshadowing_for
new file mode 100644
index 0000000..8bae30b
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/let-function-end-nonshadowing_for
@@ -0,0 +1,7 @@
+let \1 : 0
+function f/0
+end function
+for "a" to "a" as \1
+end for
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/let-function-shadowing_for b/test-files/mds-kbdc/compile-layout/valid/let-function-shadowing_for
new file mode 100644
index 0000000..1086217
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/let-function-shadowing_for
@@ -0,0 +1,7 @@
+let \1 : ""
+function f/0
+ for 0 to 0 as \1
+ end for
+end function
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/macro_1 b/test-files/mds-kbdc/compile-layout/valid/macro_1
new file mode 100644
index 0000000..3d7323d
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/macro_1
@@ -0,0 +1,5 @@
+macro m/1
+ <letter \1> : \1
+end macro
+m("a")
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/map_with_function_call b/test-files/mds-kbdc/compile-layout/valid/map_with_function_call
new file mode 100644
index 0000000..f85ef2b
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/map_with_function_call
@@ -0,0 +1,5 @@
+function f/0
+ "a"
+end function
+<letter \f()> : "\f()"
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/override_variable b/test-files/mds-kbdc/compile-layout/valid/override_variable
new file mode 100644
index 0000000..30d0bdb
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/override_variable
@@ -0,0 +1,3 @@
+let \4 : { 0 }
+let \4 : { 0 0 }
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_for b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_for
new file mode 100644
index 0000000..37ea0c3
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_for
@@ -0,0 +1,7 @@
+let \1 : "a"
+function f/0
+ for 0 to 0 as \1
+ end for
+end function
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_function_call b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_function_call
new file mode 100644
index 0000000..b858438
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_function_call
@@ -0,0 +1,7 @@
+let \1 : "a"
+function f/1
+ ""
+end function
+"" : "\f(0)"
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_let b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_let
new file mode 100644
index 0000000..a19cc88
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_let
@@ -0,0 +1,9 @@
+let \1 : "a"
+function f/0
+ let \1 : "b"
+end function
+if \equals(\1 "b")
+ let \1 : 0
+end if
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_macro_call b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_macro_call
new file mode 100644
index 0000000..6352d0d
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/shadow_variable_with_macro_call
@@ -0,0 +1,6 @@
+let \1 : "a"
+macro m/1
+end macro
+m(0)
+\1 : ""
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/value_with_indirect_sideeffect b/test-files/mds-kbdc/compile-layout/valid/value_with_indirect_sideeffect
new file mode 100644
index 0000000..24c9f5b
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/value_with_indirect_sideeffect
@@ -0,0 +1,6 @@
+let \4 : { 0 }
+function xset/3
+ "\set(\1 \2 \3)"
+end function
+"\xset(4 0 0)"
+
diff --git a/test-files/mds-kbdc/compile-layout/valid/value_with_sideeffect b/test-files/mds-kbdc/compile-layout/valid/value_with_sideeffect
new file mode 100644
index 0000000..2c0f982
--- /dev/null
+++ b/test-files/mds-kbdc/compile-layout/valid/value_with_sideeffect
@@ -0,0 +1,3 @@
+let \1 : { 0 }
+"\set(1 0 0)"
+