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
4642a828
Commit
4642a828
authored
Dec 28, 2015
by
Laszlo Domoszlai
Browse files
clean up
parent
ccc3ca9c
Changes
3
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
4642a828
...
...
@@ -118,15 +118,7 @@ void set_create_thunk_fun(Code* code)
switch
(
code
->
type
)
{
case
CT_APP_PRIM1
:
case
CT_APP_PRIM_S
:
case
CT_APP_PRIM2
:
case
CT_APP_PRIM_ST
:
case
CT_APP_PRIM_TS
:
case
CT_APP_PRIM_SS
:
case
CT_APP_PRIM_AT
:
case
CT_APP_PRIM_TA
:
case
CT_APP_PRIM_AS
:
case
CT_APP_PRIM_SA
:
case
CT_APP_FUN
:
case
CT_APP_FUN1
:
case
CT_APP_FUN2
:
...
...
@@ -172,8 +164,19 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
switch
(
expr
->
type
)
{
case
CT_APP_PRIM1
:
{
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
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
;
}
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
...
...
@@ -181,95 +184,48 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_S
:
{
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_ST
:
{
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_TS
:
{
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_SS
:
{
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_TA
:
{
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
thunk
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_AT
:
{
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
thunk
);
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_AS
:
{
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
1
])
->
index
));
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM_SA
:
{
push_a
(
local
(
frame_ptr
,
((
VarEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
index
));
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
destroy_stack_frame
(
root_frame_ptr
);
destroy_stack_frame_b
(
root_frame_ptr_b
);
return
;
}
case
CT_APP_PRIM2
:
{
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
0
],
frame_ptr
,
stack_top_a
);
placeholder
();
exec
(((
AppEntry
*
)
expr
)
->
args
[
1
],
frame_ptr
,
stack_top_a
);
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
);
}
((
PrimEntry
*
)
((
AppEntry
*
)
expr
)
->
f
)
->
exec
(
root_frame_ptr
);
...
...
interpreter/code.h
View file @
4642a828
...
...
@@ -5,8 +5,8 @@
enum
CodeType
{
CT_VAR
,
CT_VAR_STRICT
,
CT_VAR_UNBOXED
,
CT_APP_PRIM1
,
CT_APP_PRIM_S
,
CT_APP_PRIM2
,
CT_APP_PRIM_ST
,
CT_APP_PRIM_TS
,
CT_APP_PRIM_SS
,
CT_APP_PRIM_TA
,
CT_APP_PRIM_AT
,
CT_APP_PRIM_AS
,
CT_APP_PRIM_SA
,
CT_APP_PRIM1
,
CT_APP_PRIM2
,
CT_APP_THUNK
,
CT_APP_DYN
,
CT_APP_FUN
,
CT_APP_FUN1
,
CT_APP_FUN2
,
CT_SELECT_ADT
,
CT_SELECT_LIT
,
CT_IF
,
...
...
@@ -18,6 +18,7 @@ struct Code {
unsigned
int
nr_args
:
5
;
// used in AppEntry
unsigned
int
nr_cases
:
5
;
// used in SelectEntry
unsigned
int
strict
:
1
;
// used in VarEntry
unsigned
int
arg_pattern
:
3
;
struct
Thunk
*
(
*
create_thunk
)(
Code
*
,
int
);
};
...
...
interpreter/parse.c
View file @
4642a828
...
...
@@ -381,13 +381,19 @@ Code* parseApp(char **ptr, bool dynamic) {
{
int
arg0strict
=
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
||
entry
->
args
[
0
]
->
type
==
CT_VAR_UNBOXED
;
entry
->
base
.
type
=
CT_APP_PRIM1
;
if
(
arg0strict
)
{
entry
->
base
.
type
=
CT_APP_PRIM_S
;
entry
->
base
.
arg_pattern
=
1
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
arg_pattern
=
2
;
}
else
{
entry
->
base
.
type
=
CT_APP_PRIM1
;
entry
->
base
.
arg_pattern
=
0
;
}
}
else
if
(
desc
->
type
==
FT_PRIM2
)
...
...
@@ -395,37 +401,39 @@ Code* parseApp(char **ptr, bool dynamic) {
int
arg0strict
=
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
||
entry
->
args
[
0
]
->
type
==
CT_VAR_UNBOXED
;
int
arg1strict
=
entry
->
args
[
1
]
->
type
==
CT_VAR_STRICT
||
entry
->
args
[
1
]
->
type
==
CT_VAR_UNBOXED
;
entry
->
base
.
type
=
CT_APP_PRIM2
;
if
(
arg0strict
&&
entry
->
args
[
1
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_ST
;
entry
->
base
.
arg_pattern
=
1
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
&&
arg1strict
)
{
entry
->
base
.
type
=
CT_APP_PRIM_TS
;
entry
->
base
.
arg_pattern
=
2
;
}
else
if
(
arg0strict
&&
arg1strict
)
{
entry
->
base
.
type
=
CT_APP_PRIM_SS
;
entry
->
base
.
arg_pattern
=
3
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_TA
;
entry
->
base
.
arg_pattern
=
4
;
}
else
if
(
entry
->
args
[
1
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_AT
;
entry
->
base
.
arg_pattern
=
5
;
}
else
if
(
arg0strict
)
{
entry
->
base
.
type
=
CT_APP_PRIM_SA
;
entry
->
base
.
arg_pattern
=
6
;
}
else
if
(
arg1strict
)
{
entry
->
base
.
type
=
CT_APP_PRIM_AS
;
entry
->
base
.
arg_pattern
=
7
;
}
else
{
entry
->
base
.
type
=
CT_APP_PRIM2
;
entry
->
base
.
arg_pattern
=
0
;
}
}
else
if
(
desc
->
type
==
FT_FUN
)
...
...
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