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
ccc3ca9c
Commit
ccc3ca9c
authored
Dec 28, 2015
by
Laszlo Domoszlai
Browse files
clean up
parent
6a42ac1c
Changes
7
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
ccc3ca9c
...
@@ -445,7 +445,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
...
@@ -445,7 +445,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
assert
(
is_hnf
(
arg
));
assert
(
is_hnf
(
arg
));
if
(
get_dst
(
root_frame_ptr
)
!=
NULL
&&
arg
->
desc
->
unboxable
)
if
(
get_dst
(
root_frame_ptr
)
!=
NULL
&&
arg
->
desc
->
thunk_size
<=
sizeof
(
Thunk
)
)
{
{
memcpy
(
get_dst
(
root_frame_ptr
),
arg
,
sizeof
(
Thunk
));
memcpy
(
get_dst
(
root_frame_ptr
),
arg
,
sizeof
(
Thunk
));
}
}
...
...
interpreter/debug.h
View file @
ccc3ca9c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#define DEBUG_H
#define DEBUG_H
//#define DEBUG
//#define DEBUG
//
#define BENCHMARK
#define BENCHMARK
#ifndef DEBUG
#ifndef DEBUG
#define NDEBUG
#define NDEBUG
...
...
interpreter/desc.c
View file @
ccc3ca9c
...
@@ -40,14 +40,14 @@ Desc* get_slice(Desc* f, int nrargs) {
...
@@ -40,14 +40,14 @@ Desc* get_slice(Desc* f, int nrargs) {
return
&
(((
SliceEntry
*
)
f
)[
-
(
f
->
arity
-
nrargs
)].
base
);
return
&
(((
SliceEntry
*
)
f
)[
-
(
f
->
arity
-
nrargs
)].
base
);
}
}
FunEntry
*
alloc_prim
(
char
*
name
,
int
unboxable
)
{
FunEntry
*
alloc_prim
(
char
*
name
)
{
int
len
=
strlen
(
name
);
int
len
=
strlen
(
name
);
FunEntry
*
entry
=
(
FunEntry
*
)
alloc_desc
(
sizeof
(
FunEntry
)
+
len
+
1
);
FunEntry
*
entry
=
(
FunEntry
*
)
alloc_desc
(
sizeof
(
FunEntry
)
+
len
+
1
);
entry
->
base
.
type
=
FT_BOXED_LIT
;
entry
->
base
.
type
=
FT_BOXED_LIT
;
entry
->
base
.
arity
=
0
;
entry
->
base
.
arity
=
0
;
entry
->
base
.
thunk_size
=
sizeof
(
Thunk
);
entry
->
base
.
thunk_size
=
sizeof
(
Thunk
);
entry
->
base
.
unboxable
=
unboxable
;
entry
->
base
.
hnf
=
1
;
entry
->
base
.
hnf
=
1
;
entry
->
base
.
unboxable
=
true
;
memcpy
(
entry
->
name
,
name
,
len
+
1
);
memcpy
(
entry
->
name
,
name
,
len
+
1
);
set_eval_fun
((
Desc
*
)
entry
);
set_eval_fun
((
Desc
*
)
entry
);
...
@@ -60,8 +60,8 @@ void gen_slices(SliceEntry* dest, Desc* forward_ptr, int arity) {
...
@@ -60,8 +60,8 @@ void gen_slices(SliceEntry* dest, Desc* forward_ptr, int arity) {
slice
->
base
.
type
=
FT_SLICE
;
slice
->
base
.
type
=
FT_SLICE
;
slice
->
base
.
arity
=
i
;
slice
->
base
.
arity
=
i
;
slice
->
base
.
thunk_size
=
thunk_size_f
(
i
);
slice
->
base
.
thunk_size
=
thunk_size_f
(
i
);
slice
->
base
.
unboxable
=
false
;
slice
->
base
.
hnf
=
true
;
slice
->
base
.
hnf
=
true
;
slice
->
base
.
unboxable
=
false
;
slice
->
forward_ptr
=
forward_ptr
;
slice
->
forward_ptr
=
forward_ptr
;
set_eval_fun
((
Desc
*
)
slice
);
set_eval_fun
((
Desc
*
)
slice
);
...
@@ -94,31 +94,23 @@ int printDesc(Desc* f) {
...
@@ -94,31 +94,23 @@ int printDesc(Desc* f) {
}
}
void
init_desc
()
{
void
init_desc
()
{
__FORWARD_PTR__
=
alloc_prim
(
"FWD"
,
0
);
__FORWARD_PTR__
=
alloc_prim
(
"FWD"
);
__FORWARD_PTR__
->
base
.
hnf
=
false
;
__FORWARD_PTR__
->
base
.
hnf
=
false
;
set_eval_fun
((
Desc
*
)
__FORWARD_PTR__
);
set_eval_fun
((
Desc
*
)
__FORWARD_PTR__
);
__INT__
=
alloc_prim
(
"INT"
,
1
);
__INT__
=
alloc_prim
(
"INT"
);
__INT_SHARED__
=
alloc_prim
(
"INT"
,
0
);
__BOOL__
=
alloc_prim
(
"BOOL"
);
__BOOL__
=
alloc_prim
(
"BOOL"
,
1
);
__CHAR__
=
alloc_prim
(
"CHAR"
);
__BOOL_SHARED__
=
alloc_prim
(
"BOOL"
,
0
);
__REAL__
=
alloc_prim
(
"REAL"
);
__CHAR__
=
alloc_prim
(
"CHAR"
,
1
);
__CHAR_SHARED__
=
alloc_prim
(
"CHAR"
,
0
);
__REAL__
=
alloc_prim
(
"REAL"
,
1
);
__REAL_SHARED__
=
alloc_prim
(
"REAL"
,
0
);
__STRING__
=
alloc_prim
(
"STRING"
,
0
);
__STRING__
=
alloc_prim
(
"STRING"
);
__ARRAY__
=
alloc_prim
(
"ARRAY"
,
0
);
__ARRAY__
=
alloc_prim
(
"ARRAY"
);
}
}
struct
FunEntry
*
__INT__
;
struct
FunEntry
*
__INT__
;
struct
FunEntry
*
__INT_SHARED__
;
struct
FunEntry
*
__BOOL__
;
struct
FunEntry
*
__BOOL__
;
struct
FunEntry
*
__BOOL_SHARED__
;
struct
FunEntry
*
__CHAR__
;
struct
FunEntry
*
__CHAR__
;
struct
FunEntry
*
__CHAR_SHARED__
;
struct
FunEntry
*
__REAL__
;
struct
FunEntry
*
__REAL__
;
struct
FunEntry
*
__REAL_SHARED__
;
struct
FunEntry
*
__STRING__
;
struct
FunEntry
*
__STRING__
;
struct
FunEntry
*
__ARRAY__
;
struct
FunEntry
*
__ARRAY__
;
...
...
interpreter/desc.h
View file @
ccc3ca9c
...
@@ -72,13 +72,9 @@ Desc* get_slice(Desc* f, int nrargs);
...
@@ -72,13 +72,9 @@ Desc* get_slice(Desc* f, int nrargs);
int
printDesc
(
Desc
*
f
);
int
printDesc
(
Desc
*
f
);
extern
struct
FunEntry
*
__INT__
;
extern
struct
FunEntry
*
__INT__
;
extern
struct
FunEntry
*
__INT_SHARED__
;
extern
struct
FunEntry
*
__BOOL__
;
extern
struct
FunEntry
*
__BOOL__
;
extern
struct
FunEntry
*
__BOOL_SHARED__
;
extern
struct
FunEntry
*
__CHAR__
;
extern
struct
FunEntry
*
__CHAR__
;
extern
struct
FunEntry
*
__CHAR_SHARED__
;
extern
struct
FunEntry
*
__REAL__
;
extern
struct
FunEntry
*
__REAL__
;
extern
struct
FunEntry
*
__REAL_SHARED__
;
extern
struct
FunEntry
*
__STRING__
;
extern
struct
FunEntry
*
__STRING__
;
extern
struct
FunEntry
*
__ARRAY__
;
extern
struct
FunEntry
*
__ARRAY__
;
...
...
interpreter/desc_base.h
View file @
ccc3ca9c
...
@@ -11,7 +11,7 @@ struct Desc {
...
@@ -11,7 +11,7 @@ struct Desc {
FunType
type
:
4
;
FunType
type
:
4
;
unsigned
int
arity
:
8
;
// LIMITATION: maximum 32 arguments
unsigned
int
arity
:
8
;
// LIMITATION: maximum 32 arguments
unsigned
int
thunk_size
:
10
;
// It gives false result for strings and arrays
unsigned
int
thunk_size
:
10
;
// It gives false result for strings and arrays
unsigned
int
unboxable
:
1
;
unsigned
int
unboxable
:
1
;
// TODO: not uses, remove?
unsigned
int
hnf
:
1
;
unsigned
int
hnf
:
1
;
};
};
...
...
interpreter/parse.c
View file @
ccc3ca9c
...
@@ -251,21 +251,21 @@ ThunkEntry* parseLit(char **ptr) {
...
@@ -251,21 +251,21 @@ ThunkEntry* parseLit(char **ptr) {
switch
(
type
)
{
switch
(
type
)
{
case
'I'
:
// Int
case
'I'
:
// Int
{
{
entry
->
thunk
.
desc
=
(
Desc
*
)
__INT_
SHARED_
_
;
entry
->
thunk
.
desc
=
(
Desc
*
)
__INT__
;
if
(
!
parseInt
(
ptr
,
&
entry
->
thunk
.
_int
))
return
0
;
if
(
!
parseInt
(
ptr
,
&
entry
->
thunk
.
_int
))
return
0
;
break
;
break
;
}
}
case
'C'
:
// Char
case
'C'
:
// Char
{
{
entry
->
thunk
.
desc
=
(
Desc
*
)
__CHAR_
SHARED_
_
;
entry
->
thunk
.
desc
=
(
Desc
*
)
__CHAR__
;
entry
->
thunk
.
_char
=
*
(
*
ptr
)
++
;
entry
->
thunk
.
_char
=
*
(
*
ptr
)
++
;
break
;
break
;
}
}
case
'R'
:
// Real
case
'R'
:
// Real
{
{
entry
->
thunk
.
desc
=
(
Desc
*
)
__REAL_
SHARED_
_
;
entry
->
thunk
.
desc
=
(
Desc
*
)
__REAL__
;
if
(
!
parseReal
(
ptr
,
&
entry
->
thunk
.
_real
))
return
0
;
if
(
!
parseReal
(
ptr
,
&
entry
->
thunk
.
_real
))
return
0
;
break
;
break
;
}
}
...
@@ -273,7 +273,7 @@ ThunkEntry* parseLit(char **ptr) {
...
@@ -273,7 +273,7 @@ ThunkEntry* parseLit(char **ptr) {
case
'0'
:
// Bool
case
'0'
:
// Bool
case
'1'
:
case
'1'
:
{
{
entry
->
thunk
.
desc
=
(
Desc
*
)
__BOOL_
SHARED_
_
;
entry
->
thunk
.
desc
=
(
Desc
*
)
__BOOL__
;
entry
->
thunk
.
_bool
=
type
==
'1'
;
entry
->
thunk
.
_bool
=
type
==
'1'
;
break
;
break
;
}
}
...
...
interpreter/thunk.c
View file @
ccc3ca9c
...
@@ -49,15 +49,15 @@ void print(bool force) {
...
@@ -49,15 +49,15 @@ void print(bool force) {
printf
(
"["
);
printf
(
"["
);
if
(
thunk
->
desc
->
type
==
FT_BOXED_LIT
)
{
if
(
thunk
->
desc
->
type
==
FT_BOXED_LIT
)
{
if
((
FunEntry
*
)
thunk
->
desc
==
__INT__
||
(
FunEntry
*
)
thunk
->
desc
==
__INT_SHARED__
)
{
if
((
FunEntry
*
)
thunk
->
desc
==
__INT__
)
{
printf
(
"%d"
,
thunk
->
_int
);
printf
(
"%d"
,
thunk
->
_int
);
}
else
if
((
FunEntry
*
)
thunk
->
desc
==
__BOOL__
||
(
FunEntry
*
)
thunk
->
desc
==
__BOOL_SHARED__
)
{
}
else
if
((
FunEntry
*
)
thunk
->
desc
==
__BOOL__
)
{
if
(
thunk
->
_bool
)
{
if
(
thunk
->
_bool
)
{
printf
(
"True"
);
printf
(
"True"
);
}
else
{
}
else
{
printf
(
"False"
);
printf
(
"False"
);
}
}
}
else
if
((
FunEntry
*
)
thunk
->
desc
==
__CHAR__
||
(
FunEntry
*
)
thunk
->
desc
==
__CHAR_SHARED__
)
{
}
else
if
((
FunEntry
*
)
thunk
->
desc
==
__CHAR__
)
{
printf
(
"%c"
,
thunk
->
_char
);
printf
(
"%c"
,
thunk
->
_char
);
}
else
{
}
else
{
printf
(
"print: unhandled BOXED LIT
\n
"
);
printf
(
"print: unhandled BOXED LIT
\n
"
);
...
...
Write
Preview
Supports
Markdown
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