Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-20fa
extracredit01
Commits
67155769
Commit
67155769
authored
5 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Improve tests
parent
02fb032a
No related merge requests found
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
Makefile
+2
-2
Makefile
eval.c
+1
-0
eval.c
eval_types.c
+5
-0
eval_types.c
refs.c
+4
-0
refs.c
repl.c
+4
-1
repl.c
tests/dense_graph.py
+1
-1
tests/dense_graph.py
tests/gc_ref_counts.py
+1
-1
tests/gc_ref_counts.py
tests/gc_tombstones.py
+41
-0
tests/gc_tombstones.py
tests/linked_list.py
+1
-1
tests/linked_list.py
tests/long_loops.py
+1
-1
tests/long_loops.py
tests/simple_recursive.py
+1
-1
tests/simple_recursive.py
with
62 additions
and
8 deletions
+62
-8
Makefile
View file @
67155769
CC
=
clang-with-asan
CFLAGS
=
-Wall
-Wextra
-Werror
-MMD
-fno-sanitize
=
integer
CFLAGS
=
-Wall
-Wextra
-Werror
-MMD
ifdef
NREADLINE
CFLAGS
+=
-DNREADLINE
...
...
@@ -16,7 +16,7 @@ TESTS_1 = simple_math simple_print algo_fizzbuzz algo_csum algo_join \
long_chain transpose ordered_fractions
# champernowne bouncy_numbers
TESTS_2
=
$(TESTS_1)
dict_ops long_chain_dict tree dict_resize stress_struct
TESTS_3
=
$(TESTS_2)
self_cycle simple_recursive simple_rep long_loops
\
linked_list gc_ref_counts dense_graph compacting
linked_list gc_ref_counts dense_graph compacting
gc_tombstones
test
:
test3
test1
:
$(TESTS_1:=-result)
...
...
This diff is collapsed.
Click to expand it.
eval.c
View file @
67155769
...
...
@@ -88,6 +88,7 @@ void eval_close() {
free
(
global_vars
[
i
].
name
);
}
free
(
global_vars
);
global_vars
=
NULL
;
}
/*!
...
...
This diff is collapsed.
Click to expand it.
eval_types.c
View file @
67155769
...
...
@@ -120,18 +120,23 @@ static bool integer_eq(value_t *l, value_t *r) {
return
integer_cmp
(
l
,
r
)
==
0
;
}
__attribute__
((
no_sanitize
(
"integer"
)))
static
reference_t
integer_add
(
value_t
*
l
,
value_t
*
r
)
{
return
make_reference_int
(
integer_coerce
(
l
)
+
integer_coerce
(
r
));
}
__attribute__
((
no_sanitize
(
"integer"
)))
static
reference_t
integer_subtract
(
value_t
*
l
,
value_t
*
r
)
{
return
make_reference_int
(
integer_coerce
(
l
)
-
integer_coerce
(
r
));
}
__attribute__
((
no_sanitize
(
"integer"
)))
static
reference_t
integer_multiply
(
value_t
*
l
,
value_t
*
r
)
{
return
make_reference_int
(
integer_coerce
(
l
)
*
integer_coerce
(
r
));
}
__attribute__
((
no_sanitize
(
"integer"
)))
static
reference_t
integer_divide
(
value_t
*
l
,
value_t
*
r
)
{
return
make_reference_int
(
integer_coerce
(
l
)
/
integer_coerce
(
r
));
}
__attribute__
((
no_sanitize
(
"integer"
)))
static
reference_t
integer_modulo
(
value_t
*
l
,
value_t
*
r
)
{
return
make_reference_int
(
integer_coerce
(
l
)
%
integer_coerce
(
r
));
}
...
...
This diff is collapsed.
Click to expand it.
refs.c
View file @
67155769
...
...
@@ -144,6 +144,8 @@ value_t *deref(reference_t ref) {
/* Make sure the reference's value is within the pool!
* Also ensure that the value is not NULL, indicating an unused reference. */
assert
(
pool
<=
(
uint8_t
*
)
value
&&
(
uint8_t
*
)
value
<
pool
+
pool_size
);
/* The value should also be aligned to an 8-byte boundary. */
assert
((
size_t
)
value
%
ALIGNMENT
==
0
);
return
value
;
}
...
...
@@ -227,5 +229,7 @@ void collect_garbage() {
void
refs_close
()
{
free
(
pool
);
free
(
ref_table
);
pool
=
NULL
;
ref_table
=
NULL
;
}
This diff is collapsed.
Click to expand it.
repl.c
View file @
67155769
...
...
@@ -33,7 +33,10 @@ static bool debug = false;
* completion.
*/
bool
eval
(
Node
*
node
)
{
assert
(
node
!=
NULL
);
if
(
node
==
NULL
)
{
/* Parsed a comment; nothing to do. */
return
true
;
}
/* Perform the computation. */
reference_t
result
=
eval_root
(
node
);
...
...
This diff is collapsed.
Click to expand it.
tests/dense_graph.py
View file @
67155769
# -m 1000
0
# -m 1000
9
node_one
=
{
"name"
:
"a"
}
node_two
=
{
"name"
:
"b"
}
...
...
This diff is collapsed.
Click to expand it.
tests/gc_ref_counts.py
View file @
67155769
# -m 1000
0
# -m 1000
8
# Simple test: one garbage value refers to non-garbage
non_garbage
=
123
...
...
This diff is collapsed.
Click to expand it.
tests/gc_tombstones.py
0 → 100644
View file @
67155769
# -m 10015
d
=
{
0
:
0
,
1
:
1
}
# output {0: 0, 1: 1}
print
(
d
)
i
=
2
while
i
<=
40
:
d
[
i
]
=
d
[
i
-
2
]
+
d
[
i
-
1
]
del
d
[
i
-
2
]
i
=
i
+
1
del
i
# output 824 bytes in use; 10 refs in use
mem
()
# output {39: 63245986, 40: 102334155}
print
(
d
)
gc
()
# output 824 bytes in use; 10 refs in use
mem
()
del
d
# output 72 bytes in use; 3 refs in use
mem
()
a
=
{}
a
[
True
]
=
a
b
=
{
1
:
a
}
del
a
# output {1: {True: {True: {...: ...}}}}
print
(
b
)
# output 584 bytes in use; 10 refs in use
mem
()
del
b
[
1
]
# output {}
print
(
b
)
# output 552 bytes in use; 9 refs in use
mem
()
gc
()
# output 312 bytes in use; 6 refs in use
mem
()
del
b
# output 72 bytes in use; 3 refs in use
mem
()
This diff is collapsed.
Click to expand it.
tests/linked_list.py
View file @
67155769
# -m 1000
0
# -m 1000
4
a
=
{
"value"
:
1
,
"prev"
:
None
,
"next"
:
None
}
b
=
{
"value"
:
True
,
"prev"
:
a
,
"next"
:
None
}
...
...
This diff is collapsed.
Click to expand it.
tests/long_loops.py
View file @
67155769
# -m 10000
0
# -m 10000
3
# Create three separate cycles
z
=
{
"next"
:
"i am root"
}
...
...
This diff is collapsed.
Click to expand it.
tests/simple_recursive.py
View file @
67155769
# -m 1000
0
# -m 1000
1
a
=
[
0
]
a
[
0
]
=
a
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help