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
87648b03
Commit
87648b03
authored
Sep 21, 2015
by
Laszlo Domoszlai
Browse files
the big prim split (code clean up needs)
parent
459d73d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
87648b03
...
...
@@ -107,7 +107,16 @@ void set_create_thunk_fun(Code* code)
switch
(
code
->
type
)
{
case
CT_APP_PRIM1
:
case
CT_APP_PRIM_S
:
case
CT_APP_PRIM_T
:
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_THUNK
:
code
->
create_thunk
=
create_thunk_app_static
;
...
...
@@ -124,7 +133,8 @@ void set_create_thunk_fun(Code* code)
case
CT_THUNK
:
code
->
create_thunk
=
create_thunk_thunk
;
break
;
default:
case
CT_SELECT
:
case
CT_IF
:
code
->
create_thunk
=
NULL
;
break
;
}
...
...
@@ -155,6 +165,98 @@ 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_T
:
{
push_a
(
&
((
ThunkEntry
*
)
((
AppEntry
*
)
expr
)
->
args
[
0
])
->
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_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
);
push_a
(
alloc_b
());
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
:
{
push_a
(
alloc_b
());
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
:
{
push_a
(
alloc_b
());
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
));
push_a
(
alloc_b
());
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
:
{
push_a
(
alloc_b
());
...
...
interpreter/code.h
View file @
87648b03
...
...
@@ -5,14 +5,15 @@
enum
CodeType
{
CT_VAR
,
CT_VAR_STRICT
,
CT_APP_PRIM1
,
CT_APP_PRIM2
,
CT_APP_PRIM1
,
CT_APP_PRIM_T
,
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_THUNK
,
CT_APP_FUN
,
CT_APP_DYN
,
CT_SELECT
,
CT_IF
,
CT_THUNK
};
struct
Code
{
CodeType
type
:
4
;
CodeType
type
:
5
;
unsigned
int
nr_args
:
5
;
// used in AppEntry
unsigned
int
nr_cases
:
5
;
// used in SelectEntry
unsigned
int
strict
:
1
;
// used in VarEntry
...
...
interpreter/parse.c
View file @
87648b03
...
...
@@ -363,11 +363,53 @@ Code* parseApp(char **ptr, bool dynamic) {
if
(
desc
->
type
==
FT_PRIM1
)
{
entry
->
base
.
type
=
CT_APP_PRIM1
;
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_T
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
)
{
entry
->
base
.
type
=
CT_APP_PRIM_S
;
}
else
{
entry
->
base
.
type
=
CT_APP_PRIM1
;
}
}
else
if
(
desc
->
type
==
FT_PRIM2
)
{
entry
->
base
.
type
=
CT_APP_PRIM2
;
if
(
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
&&
entry
->
args
[
1
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_ST
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
&&
entry
->
args
[
1
]
->
type
==
CT_VAR_STRICT
)
{
entry
->
base
.
type
=
CT_APP_PRIM_TS
;
}
else
if
(
entry
->
args
[
1
]
->
type
==
CT_VAR_STRICT
&&
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
)
{
entry
->
base
.
type
=
CT_APP_PRIM_SS
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_TA
;
}
else
if
(
entry
->
args
[
1
]
->
type
==
CT_THUNK
)
{
entry
->
base
.
type
=
CT_APP_PRIM_AT
;
}
else
if
(
entry
->
args
[
0
]
->
type
==
CT_VAR_STRICT
)
{
entry
->
base
.
type
=
CT_APP_PRIM_SA
;
}
else
if
(
entry
->
args
[
1
]
->
type
==
CT_VAR_STRICT
)
{
entry
->
base
.
type
=
CT_APP_PRIM_AS
;
}
else
{
entry
->
base
.
type
=
CT_APP_PRIM2
;
}
}
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