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
4619092e
Commit
4619092e
authored
Aug 17, 2015
by
Laszlo Domoszlai
Browse files
create thunk from simple function pointers (not an application)
parent
5dd354ca
Changes
7
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
4619092e
...
...
@@ -19,6 +19,16 @@ struct Thunk* exec(Code* expr)
exit
(
-
1
);
}
break
;
case
CT_VAR
:
switch
(
expr
->
local_type
)
{
case
VAR_FN
:
return
createF
(((
VarEntry
*
)
expr
)
->
f
,
0
);
break
;
default:
printf
(
"Exec: Unhandled VAR type"
);
exit
(
-
1
);
}
default:
printf
(
"Exec: Unhandled CODE type"
);
exit
(
-
1
);
...
...
interpreter/desc.c
View file @
4619092e
...
...
@@ -50,7 +50,7 @@ void gen_slices(void* dest, void* forward_ptr, int arity)
SliceEntry
*
slice
=
(
SliceEntry
*
)
dest
+
sizeof
(
SliceEntry
)
*
i
;
slice
->
base
.
type
=
FT_SLICE
;
slice
->
base
.
arity
=
i
;
slice
->
forward_ptr
=
forward_ptr
;
slice
->
forward_ptr
=
(
Desc
*
)
forward_ptr
;
}
}
...
...
interpreter/desc.h
View file @
4619092e
...
...
@@ -36,7 +36,7 @@ struct FunEntry
struct
SliceEntry
{
struct
Desc
base
;
void
*
forward_ptr
;
// FunEntry or ADTEntry
Desc
*
forward_ptr
;
// FunEntry or ADTEntry
};
struct
ADTEntry
{
...
...
interpreter/main.c
View file @
4619092e
...
...
@@ -23,8 +23,7 @@ int main()
// TODO: put it into a special "expression" space, instead of "code"
//char *exprstream = "VF13 example.Start";
char
*
exprstream
=
"LI1 "
;
char
*
exprstream
=
"VF13 example.Start"
;
Code
*
expr
=
parseTerm
(
&
exprstream
);
Thunk
*
res
=
exec
(
expr
);
...
...
interpreter/main.exe
View file @
4619092e
No preview for this file type
interpreter/thunk.c
View file @
4619092e
...
...
@@ -13,6 +13,36 @@ struct Thunk* createI(int i)
return
thunk
;
}
struct
Thunk
*
createF
(
Desc
*
f
,
int
nrargs
)
{
// Even if no arguments, still allocate enough space for a forward pointer
Thunk
*
thunk
=
(
Thunk
*
)
alloc_heap
(
sizeof
(
Thunk
)
+
sizeof
(
Thunk
*
)
*
(
nrargs
>
0
?
nrargs
-
1
:
0
));
Desc
*
slice
=
f
;
if
(
f
->
arity
>
0
)
{
slice
=
&
(((
SliceEntry
*
)
f
)[
-
f
->
arity
].
base
);
}
thunk
->
desc
=
slice
;
return
thunk
;
}
int
printDesc
(
Desc
*
f
)
{
switch
(
f
->
type
)
{
case
FT_SLICE
:
return
printDesc
(((
SliceEntry
*
)
f
)
->
forward_ptr
);
case
FT_FUN
:
printf
(
"%s"
,
((
FunEntry
*
)
f
)
->
name
);
return
f
->
arity
;
default:
printf
(
"printDesc: unhandled DESC
\n
"
);
exit
(
-
1
);
}
}
void
print
(
Thunk
*
thunk
)
{
if
((
FunEntry
*
)
thunk
->
desc
==
__INT__
)
...
...
@@ -21,7 +51,12 @@ void print(Thunk* thunk)
}
else
{
printf
(
"print: unhandled DESC
\n
"
);
exit
(
-
1
);
int
arity
=
printDesc
(
thunk
->
desc
);
if
(
arity
>
0
)
{
printf
(
"print: unhandled arity
\n
"
);
exit
(
-
1
);
}
}
}
\ No newline at end of file
}
interpreter/thunk.h
View file @
4619092e
...
...
@@ -19,6 +19,7 @@ struct Thunk
};
struct
Thunk
*
createI
(
int
i
);
struct
Thunk
*
createF
(
Desc
*
f
,
int
nrargs
);
void
print
(
Thunk
*
thunk
);
...
...
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