Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-and-itasks
sapl-interpreter
Commits
9359272d
Commit
9359272d
authored
Aug 25, 2015
by
Laszlo Domoszlai
Browse files
add nfib example + correct measurement of execution time in DEBUG mode
parent
a115c3ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
interpreter/main.c
View file @
9359272d
...
...
@@ -2,6 +2,7 @@
#include
<stdlib.h>
#include
<stdbool.h>
#include
<string.h>
#include
<sys/time.h>
#include
"getline.h"
...
...
@@ -18,7 +19,7 @@ int main ( int argc, char *argv[] )
init_desc
();
init_prim
();
char
*
input
=
"..
\\
tests
\\
Braun
.bsapl"
;
char
*
input
=
"..
\\
tests
\\
nfib
.bsapl"
;
if
(
argc
==
2
)
{
...
...
@@ -62,11 +63,26 @@ int main ( int argc, char *argv[] )
Code
*
expr
=
parseTerm
(
&
exprstream
);
#ifdef DEBUG
struct
timeval
t1
,
t2
;
gettimeofday
(
&
t1
,
NULL
);
#endif
Thunk
*
res
=
exec
(
expr
,
stack_top_a
,
NULL
,
true
);
eval
(
res
);
#ifdef DEBUG
gettimeofday
(
&
t2
,
NULL
);
#endif
print
(
res
,
true
);
#ifdef DEBUG
// compute and print the elapsed time in millisec
double
elapsedTime
=
(
t2
.
tv_sec
-
t1
.
tv_sec
)
*
1000
.
0
;
// sec to ms
elapsedTime
+=
(
t2
.
tv_usec
-
t1
.
tv_usec
)
/
1000
.
0
;
// us to ms
printf
(
"
\n\n
execution time: %G ms
\n
"
,
elapsedTime
);
print_stat
();
#endif
}
interpreter/mem.c
View file @
9359272d
...
...
@@ -16,7 +16,7 @@ Thunk* stack_a[STACK_SIZE_A];
char
*
heap_start
;
void
print_stat
()
{
printf
(
"
\
n\
n
allocation:
\n
"
);
printf
(
"
\n
allocation:
\n
"
);
printf
(
"desc: %d
\n
"
,
desc_alloc
);
printf
(
"code: %d
\n
"
,
code_alloc
);
printf
(
"heap: %d (%d thunks)
\n
"
,
heap_alloc
,
nr_heap_alloc
);
...
...
tests/nfib.exp
0 → 100644
View file @
9359272d
[2692537]
\ No newline at end of file
tests/nfib.sapl
0 → 100644
View file @
9359272d
main = example.Start
example.Start = example.nfib 30
example.nfib !n_0 = if (lt n_0 2) 1 (add 1 (add (example.nfib (sub n_0 1)) (example.nfib (sub n_0 2))))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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