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
9ea474a6
Commit
9ea474a6
authored
Aug 24, 2015
by
Laszlo Domoszlai
Browse files
add DEBUG option
parent
56188eaa
Changes
4
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
9ea474a6
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdbool.h>
#include
<assert.h>
#include
"debug.h"
#include
"code.h"
#include
"desc.h"
#include
"thunk.h"
...
...
@@ -58,14 +58,11 @@ exec(Code* expr, int frame_ptr, Thunk* target, bool force)
if
(
force
&&
slice
->
type
==
FT_PRIM
)
{
Thunk
args
[
expr
->
nr_args
];
int
old_top
=
stack_top
;
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
&
args
[
i
],
true
);
}
int
old_top
=
stack_top
;
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
pushs
(
&
args
[
i
]);
pushs
(
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
&
args
[
i
],
true
));
}
thunk
=
((
PrimEntry
*
)
slice
)
->
exec
(
target
);
...
...
@@ -73,15 +70,11 @@ exec(Code* expr, int frame_ptr, Thunk* target, bool force)
stack_top
=
old_top
;
}
else
if
(
force
&&
slice
->
type
==
FT_FUN
)
{
Thunk
*
args
[
expr
->
nr_args
];
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
args
[
i
]
=
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
NULL
,
is_strict_fun_arg
((
FunEntry
*
)
slice
,
i
));
}
int
old_top
=
stack_top
;
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
pushs
(
args
[
i
]
);
int
old_top
=
stack_top
;
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
pushs
(
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
,
NULL
,
is_strict_fun_arg
((
FunEntry
*
)
slice
,
i
))
);
}
thunk
=
exec
(((
FunEntry
*
)
slice
)
->
body
,
stack_top
-
1
,
target
,
true
);
...
...
interpreter/debug.h
0 → 100644
View file @
9ea474a6
#ifndef DEBUG_H
#define DEBUG_H
#define DEBUG
#ifndef DEBUG
#define NDEBUG
#endif
#include
<assert.h>
#endif
/* DEBUG_H */
interpreter/main.c
View file @
9ea474a6
...
...
@@ -2,6 +2,7 @@
#include
<stdbool.h>
#include
<string.h>
#include
"debug.h"
#include
"desc.h"
#include
"prim.h"
#include
"parse.h"
...
...
@@ -55,22 +56,24 @@ int main() {
// 44
// char* funstream = "160 F13 example.Start0 0 AF11 example.map2 VF11 example.incAF17 _predefined._Cons2 LI1 AF17 _predefined._Cons2 LI2 AF17 _predefined._Cons2 LI3 VF16 _predefined._Nil36 F11 example.inc1 1 AF3 add2 VA0 LI1 148 F11 example.map2 1 SVA0 2 C16 _predefined._NilVF16 _predefined._NilC17 _predefined._ConsAF17 _predefined._Cons2 AA1 1 VL0 AF11 example.map2 VA1 VL1 50 A2 17 _predefined._Cons2 0 16 _predefined._Nil0 0 ";
// [_predefined._Cons [2] [_predefined._Cons [3] [_predefined._Cons [4] [_predefined._Nil]]]]
//
char* funstream = "44 F13 example.Start0 0 AF11 example.fib1 LI36 119 F11 example.fib1 1 IAF2 lt2 VA0 LI2 LI1 AF3 add2 AF11 example.fib1 AF3 sub2 VA0 LI1 AF11 example.fib1 AF3 sub2 VA0 LI2 ";
char
*
funstream
=
"44 F13 example.Start0 0 AF11 example.fib1 LI36 119 F11 example.fib1 1 IAF2 lt2 VA0 LI2 LI1 AF3 add2 AF11 example.fib1 AF3 sub2 VA0 LI1 AF11 example.fib1 AF3 sub2 VA0 LI2 "
;
// fib
char
*
funstream
=
"29 F9 Braun.int1 1 IVA0 LI1 LI0 27 F9 Braun.and2 2 IVA1 VA0 L099 F9 Braun.all2 1 SVA0 2 C9 Flite.NilL1C10 Flite.ConsAF9 Braun.and2 AA1 1 VL0 AF9 Braun.all2 VA1 VL1 98 F16 Braun._c;39;3_203 4 IAF3 eqB2 VA2 L0L0IAF3 eqB2 VA2 L1AF14 Braun.equal_182 VA1 VA0 VF7 nomatch175 F14 Braun.equal_182 3 SVA1 2 C9 Flite.NilSVA0 2 C9 Flite.NilL1C10 Flite.ConsL0C10 Flite.ConsSVA0 2 C9 Flite.NilL0C10 Flite.ConsAF16 Braun._c;39;3_203 AF3 eqI2 VL0 VL2 VL1 VL3 176 F9 Braun.ilv2 3 SVA1 2 C9 Flite.NilVA0 C10 Flite.ConsSVA0 2 C9 Flite.NilAF10 Flite.Cons2 VL0 VL1 C10 Flite.ConsAF10 Flite.Cons2 VL0 AF10 Flite.Cons2 VL2 AF9 Braun.ilv2 VL1 VL3 153 F12 Braun.toList1 1 SVA0 2 C11 Braun.EmptyVF9 Flite.NilC12 Braun.BranchAF10 Flite.Cons2 VL0 AF9 Braun.ilv2 AF12 Braun.toList1 VL1 AF12 Braun.toList1 VL2 40 A2 11 Braun.Empty0 0 12 Braun.Branch3 0 167 F12 Braun.insert2 1 SVA0 2 C11 Braun.EmptyAF12 Braun.Branch3 VA1 VF11 Braun.EmptyVF11 Braun.EmptyC12 Braun.BranchAF12 Braun.Branch3 VA1 AF12 Braun.insert2 VL0 VL2 VL1 119 F14 Braun.fromList1 1 SVA0 2 C9 Flite.NilVF11 Braun.EmptyC10 Flite.ConsAF12 Braun.insert2 VL0 AF14 Braun.fromList1 VL1 90 F13 Braun.prop_171 1 AF14 Braun.equal_182 VA0 AF12 Braun.toList1 AF14 Braun.fromList1 VA0 118 F15 Braun.replicate2 2 IAF3 eqI2 VA1 LI0 VF9 Flite.NilAF10 Flite.Cons2 VA0 AF15 Braun.replicate2 AF3 sub2 VA1 LI1 VA0 44 F11 Braun.<=_162 3 AF3 not1 AF2 lt2 VA0 VA1 35 A2 9 Flite.Nil0 0 10 Flite.Cons2 0 121 F12 Braun.fromTo2 3 IAF11 Braun.<=_162 VA1 VA0 AF10 Flite.Cons2 VA1 AF12 Braun.fromTo2 AF3 add2 VA1 LI1 VA0 VF9 Flite.Nil125 F11 Braun.Start0 0 AF9 Braun.int1 AF9 Braun.all2 VF13 Braun.prop_17AF15 Braun.replicate2 LI6000 AF12 Braun.fromTo2 LI0 LI255 27 F4 main0 0 VF11 Braun.Start"
;
//
char* funstream = "29 F9 Braun.int1 1 IVA0 LI1 LI0 27 F9 Braun.and2 2 IVA1 VA0 L099 F9 Braun.all2 1 SVA0 2 C9 Flite.NilL1C10 Flite.ConsAF9 Braun.and2 AA1 1 VL0 AF9 Braun.all2 VA1 VL1 98 F16 Braun._c;39;3_203 4 IAF3 eqB2 VA2 L0L0IAF3 eqB2 VA2 L1AF14 Braun.equal_182 VA1 VA0 VF7 nomatch175 F14 Braun.equal_182 3 SVA1 2 C9 Flite.NilSVA0 2 C9 Flite.NilL1C10 Flite.ConsL0C10 Flite.ConsSVA0 2 C9 Flite.NilL0C10 Flite.ConsAF16 Braun._c;39;3_203 AF3 eqI2 VL0 VL2 VL1 VL3 176 F9 Braun.ilv2 3 SVA1 2 C9 Flite.NilVA0 C10 Flite.ConsSVA0 2 C9 Flite.NilAF10 Flite.Cons2 VL0 VL1 C10 Flite.ConsAF10 Flite.Cons2 VL0 AF10 Flite.Cons2 VL2 AF9 Braun.ilv2 VL1 VL3 153 F12 Braun.toList1 1 SVA0 2 C11 Braun.EmptyVF9 Flite.NilC12 Braun.BranchAF10 Flite.Cons2 VL0 AF9 Braun.ilv2 AF12 Braun.toList1 VL1 AF12 Braun.toList1 VL2 40 A2 11 Braun.Empty0 0 12 Braun.Branch3 0 167 F12 Braun.insert2 1 SVA0 2 C11 Braun.EmptyAF12 Braun.Branch3 VA1 VF11 Braun.EmptyVF11 Braun.EmptyC12 Braun.BranchAF12 Braun.Branch3 VA1 AF12 Braun.insert2 VL0 VL2 VL1 119 F14 Braun.fromList1 1 SVA0 2 C9 Flite.NilVF11 Braun.EmptyC10 Flite.ConsAF12 Braun.insert2 VL0 AF14 Braun.fromList1 VL1 90 F13 Braun.prop_171 1 AF14 Braun.equal_182 VA0 AF12 Braun.toList1 AF14 Braun.fromList1 VA0 118 F15 Braun.replicate2 2 IAF3 eqI2 VA1 LI0 VF9 Flite.NilAF10 Flite.Cons2 VA0 AF15 Braun.replicate2 AF3 sub2 VA1 LI1 VA0 44 F11 Braun.<=_162 3 AF3 not1 AF2 lt2 VA0 VA1 35 A2 9 Flite.Nil0 0 10 Flite.Cons2 0 121 F12 Braun.fromTo2 3 IAF11 Braun.<=_162 VA1 VA0 AF10 Flite.Cons2 VA1 AF12 Braun.fromTo2 AF3 add2 VA1 LI1 VA0 VF9 Flite.Nil125 F11 Braun.Start0 0 AF9 Braun.int1 AF9 Braun.all2 VF13 Braun.prop_17AF15 Braun.replicate2 LI6000 AF12 Braun.fromTo2 LI0 LI255 27 F4 main0 0 VF11 Braun.Start";
//braun
#ifdef DEBUG
printf
(
"sizeof(int): %d, sizeof(long): %d, sizeof(void*): %d, sizeof(Thunk): %d
\n\n
"
,
sizeof
(
int
),
sizeof
(
long
),
sizeof
(
void
*
),
sizeof
(
Thunk
));
#endif
int
nrfuns
=
parse
(
&
funstream
,
strlen
(
funstream
));
printf
(
"Number of functions parsed: %d
\n
"
,
nrfuns
);
// TODO: put it into a special "expression" space, instead of "code"
//
char *exprstream = "VF13 example.Start";
char
*
exprstream
=
"VF11 Braun.Start"
;
char
*
exprstream
=
"VF13 example.Start"
;
//
char *exprstream = "VF11 Braun.Start";
Code
*
expr
=
parseTerm
(
&
exprstream
);
...
...
@@ -78,5 +81,7 @@ int main() {
eval
(
res
);
print
(
res
,
true
);
#ifdef DEBUG
print_stat
();
#endif
}
interpreter/thunk.c
View file @
9ea474a6
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdbool.h>
#include
<assert.h>
#include
"debug.h"
#include
"thunk.h"
#include
"desc.h"
#include
"code.h"
...
...
@@ -43,7 +43,7 @@ Thunk* forward_to(Thunk* target, Thunk* thunk) {
if
(
target
!=
NULL
)
{
target
->
desc
=
NULL
;
target
->
_forward_ptr
=
thunk
;
return
t
arget
;
return
t
hunk
;
}
else
{
return
thunk
;
}
...
...
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