Skip to content
GitLab
Menu
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
ae8d3929
Commit
ae8d3929
authored
Dec 28, 2015
by
Laszlo Domoszlai
Browse files
clean up
parent
4642a828
Changes
4
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
ae8d3929
...
...
@@ -166,16 +166,16 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
{
switch
(
expr
->
arg_pattern
)
{
case
1
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
break
;
case
2
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
break
;
default:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
break
;
case
1
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
break
;
case
2
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
break
;
default:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
break
;
}
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
...
...
@@ -186,45 +186,48 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
case
CT_APP_PRIM2
:
{
// careful, "exec" may trigger garbage collection
// read local variables only after the last exec
switch
(
expr
->
arg_pattern
)
{
case
1
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
break
;
case
2
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
case
3
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
case
4
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
break
;
case
5
:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
break
;
case
6
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
break
;
case
7
:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
default:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
case
1
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
break
;
case
2
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
case
3
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
case
4
:
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
break
;
case
5
:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
break
;
case
6
:
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
break
;
case
7
:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
break
;
default:
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
}
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
...
...
interpreter/debug.h
View file @
ae8d3929
...
...
@@ -2,7 +2,7 @@
#define DEBUG_H
//#define DEBUG
#define BENCHMARK
//
#define BENCHMARK
#ifndef DEBUG
#define NDEBUG
...
...
interpreter/thunk.c
View file @
ae8d3929
...
...
@@ -12,7 +12,7 @@
int
readI
(
Thunk
*
thunk
)
{
assert
(
thunk
!=
NULL
);
if
(
thunk
->
desc
!=
(
Desc
*
)
__INT__
&&
thunk
->
desc
!=
(
Desc
*
)
__INT_SHARED__
)
{
if
(
thunk
->
desc
!=
(
Desc
*
)
__INT__
)
{
printf
(
"readI: not an integer: "
);
printDesc
(
thunk
->
desc
);
exit
(
-
1
);
...
...
@@ -24,7 +24,7 @@ int readI(Thunk* thunk) {
int
readB
(
Thunk
*
thunk
)
{
assert
(
thunk
!=
NULL
);
if
(
thunk
->
desc
!=
(
Desc
*
)
__BOOL__
&&
thunk
->
desc
!=
(
Desc
*
)
__BOOL_SHARED__
)
{
if
(
thunk
->
desc
!=
(
Desc
*
)
__BOOL__
)
{
printf
(
"readB: not a boolean: "
);
printDesc
(
thunk
->
desc
);
exit
(
-
1
);
...
...
@@ -32,6 +32,18 @@ int readB(Thunk* thunk) {
return
thunk
->
_bool
;
}
char
readC
(
Thunk
*
thunk
)
{
assert
(
thunk
!=
NULL
);
if
(
thunk
->
desc
!=
(
Desc
*
)
__CHAR__
)
{
printf
(
"readC: not a char: "
);
printDesc
(
thunk
->
desc
);
exit
(
-
1
);
}
return
thunk
->
_char
;
}
#endif
bool
is_hnf
(
Thunk
*
thunk
)
...
...
interpreter/thunk.h
View file @
ae8d3929
...
...
@@ -38,6 +38,7 @@ typedef struct __attribute__((packed)) Thunk {
int
readI
(
Thunk
*
thunk
);
int
readB
(
Thunk
*
thunk
);
char
readC
(
Thunk
*
thunk
);
#else
...
...
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