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
d94c62b2
Commit
d94c62b2
authored
Aug 27, 2015
by
Laszlo Domoszlai
Browse files
fix the problem of the previous commit by reducing the stack usage
parent
03992c48
Changes
3
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
d94c62b2
...
...
@@ -13,29 +13,40 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
while
(
1
)
{
assert
(
stack_top_a
<
STACK_SIZE_A
);
switch
(
expr
->
type
)
{
case
CT_LIT
:
prepare
_return
(
root_frame_ptr
,
updateT
(
target
,
&
((
LitEntry
*
)
expr
)
->
thunk
)
);
set
_return
(
root_frame_ptr
,
updateT
(
target
,
&
((
LitEntry
*
)
expr
)
->
thunk
));
destroy_stack_frame
(
root_frame_ptr
);
return
;
case
CT_VAR
:
if
(
expr
->
local_type
==
VAR_LOCAL
)
{
Thunk
*
thunk
=
forward_to
(
target
,
local
(
frame_ptr
,
((
VarEntry
*
)
expr
)
->
index
));
// Destroy stack frame before eval, it is not needed any more
// Greatly reduces stack usage
destroy_stack_frame
(
root_frame_ptr
);
// TODO: inline eval
if
(
force
)
thunk
=
eval
(
thunk
);
prepare_return
(
root_frame_ptr
,
thunk
);
set_return
(
root_frame_ptr
,
thunk
);
return
;
}
else
{
// Safe to destroy, the next call has no arguments
destroy_stack_frame
(
root_frame_ptr
);
Desc
*
slice
=
get_slice
(((
VarEntry
*
)
expr
)
->
f
,
0
);
if
(
force
&&
slice
->
type
==
FT_FUN
)
if
(
force
&&
slice
->
type
==
FT_FUN
)
{
expr
=
((
FunEntry
*
)
slice
)
->
body
;
continue
;
}
else
{
prepare_return
(
root_frame_ptr
,
updateF
(
target
,
get_slice
(((
VarEntry
*
)
expr
)
->
f
,
0
)));
set_return
(
root_frame_ptr
,
updateF
(
target
,
slice
));
return
;
}
}
...
...
@@ -48,6 +59,8 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
if
(
var
->
base
.
local_type
==
VAR_LOCAL
)
{
// TODO: force
Thunk
*
basethunk
=
eval
(
local
(
frame_ptr
,
var
->
index
));
Desc
*
slice
=
...
...
@@ -68,7 +81,8 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
thunk
->
_args
[
basethunk
->
desc
->
arity
+
i
]
=
pop_a
();
}
prepare_return
(
root_frame_ptr
,
thunk
);
set_return
(
root_frame_ptr
,
thunk
);
destroy_stack_frame
(
root_frame_ptr
);
return
;
}
else
...
...
@@ -83,9 +97,9 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
stack_top_a
,
&
args
[
i
],
true
);
}
prepare
_return
(
root_frame_ptr
,
set
_return
(
root_frame_ptr
,
((
PrimEntry
*
)
slice
)
->
exec
(
target
));
destroy_stack_frame
(
root_frame_ptr
);
return
;
}
else
if
(
force
&&
slice
->
type
==
FT_FUN
)
{
...
...
@@ -96,7 +110,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
push_a
(
NULL
);
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
stack_top_a
,
NULL
,
is_strict_fun_arg
((
FunEntry
*
)
slice
,
i
));
}
expr
=
((
FunEntry
*
)
slice
)
->
body
;
frame_ptr
=
new_frame_ptr
;
continue
;
...
...
@@ -112,7 +126,8 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
thunk
->
_args
[
i
]
=
pop_a
();
}
prepare_return
(
root_frame_ptr
,
thunk
);
set_return
(
root_frame_ptr
,
thunk
);
destroy_stack_frame
(
root_frame_ptr
);
return
;
}
}
...
...
interpreter/main.c
View file @
d94c62b2
...
...
@@ -29,7 +29,7 @@ int main ( int argc, char *argv[] )
init_desc
();
init_prim
();
char
*
input
=
"..
\\
tests
\\
Braun
.bsapl"
;
char
*
input
=
"..
\\
tests
\\
nfib
.bsapl"
;
if
(
argc
==
2
)
{
...
...
interpreter/mem.h
View file @
d94c62b2
...
...
@@ -14,7 +14,8 @@ extern Thunk* stack_a[STACK_SIZE_A];
#define push_a(r) stack_a[stack_top_a++]=(r)
#define local(base, idx) stack_a[base+idx-1]
#define prepare_return(base, r) stack_a[base-1]=(r); stack_top_a = base
#define set_return(base, r) stack_a[base-1]=(r)
#define destroy_stack_frame(base) stack_top_a = base
void
init_mem
();
void
print_stat
();
...
...
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