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
b7b37e5e
Commit
b7b37e5e
authored
Aug 18, 2015
by
Laszlo Domoszlai
Browse files
handle the case when an application is based on argument
parent
eb94e8bc
Changes
5
Hide whitespace changes
Inline
Side-by-side
interpreter/code.c
View file @
b7b37e5e
...
...
@@ -34,21 +34,43 @@ struct Thunk* exec(Code* expr, int frame_ptr)
}
break
;
case
CT_APP
:
// TODO: check over application
// TODO: enforce strictness in ADT/Record
VarEntry
*
var
=
((
AppEntry
*
)
expr
)
->
var
;
Thunk
*
thunk
;
switch
(
var
->
base
.
local_type
)
{
case
VAR_FN
:
Thunk
*
thunk
;
thunk
=
createF
(
var
->
f
,
((
AppEntry
*
)
expr
)
->
base
.
arity
);
case
VAR_FN
:
thunk
=
createF
(
var
->
f
,
expr
->
nr_args
);
for
(
int
i
=
0
;
i
<
thunk
->
desc
->
arity
;
i
++
)
{
// TODO: enforce strictness
thunk
->
_args
[
i
]
=
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
);
}
return
thunk
;
case
VAR_ARG
:
Thunk
*
basethunk
;
basethunk
=
eval
(
stack
[
frame_ptr
-
var
->
index
]);
thunk
=
createF
(
basethunk
->
desc
->
type
==
FT_SLICE
?
((
SliceEntry
*
)
basethunk
->
desc
)
->
forward_ptr
:
basethunk
->
desc
,
basethunk
->
desc
->
arity
+
expr
->
nr_args
);
for
(
int
i
=
0
;
i
<
basethunk
->
desc
->
arity
;
i
++
)
{
thunk
->
_args
[
i
]
=
basethunk
->
_args
[
i
];
}
for
(
int
i
=
0
;
i
<
expr
->
nr_args
;
i
++
)
{
thunk
->
_args
[
basethunk
->
desc
->
arity
+
i
]
=
exec
(((
AppEntry
*
)
expr
)
->
args
[
i
],
frame_ptr
);
}
return
thunk
;
default:
printf
(
"Exec: Unhandled VAR type"
);
printf
(
"Exec: Unhandled VAR type
in CT_APP
"
);
exit
(
-
1
);
}
}
}
\ No newline at end of file
interpreter/code.h
View file @
b7b37e5e
...
...
@@ -12,7 +12,7 @@ struct Code
{
unsigned
int
type
:
3
;
unsigned
int
local_type
:
3
;
unsigned
int
arity
:
4
;
// used in AppEntry
unsigned
int
nr_args
:
4
;
// used in AppEntry
};
#define LIT_INT 1
...
...
interpreter/main.c
View file @
b7b37e5e
...
...
@@ -14,8 +14,6 @@ int main()
init_desc
();
init_prim
();
//char* funstream = "40 R10 example._R2 1 9 example.a9 example.b37 F12 example.g_482 3 AF3 add2 VA0 VA1 39 C9 example.fAF12 example.g_482 LI1 LI2 55 F13 example.Start0 0 AF10 example._R2 LI1 VF9 example.f29 F4 main0 0 VF13 example.Start";
// OK char* funstream = "25 F13 example.Start0 0 LI1 29 F4 main0 0 VF13 example.Start";
// 1
// OK char* funstream = "20 F9 example.c1 1 VA0 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
...
...
@@ -40,8 +38,10 @@ int main()
// example.A 5
// OK char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 44 F13 example.Start0 0 AF9 example.A2 LI5 LI6 29 F4 main0 0 VF13 example.Start";
// example.A 5 6
// char* funstream = "40 R10 example._R2 1 9 example.a9 example.b46 F13 example.Start0 0 AF10 example._R2 LI6 LI7 29 F4 main0 0 VF13 example.Start";
//
OK
char* funstream = "40 R10 example._R2 1 9 example.a9 example.b46 F13 example.Start0 0 AF10 example._R2 LI6 LI7 29 F4 main0 0 VF13 example.Start";
// example._R 6 7
// OK char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 1 VA0 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
// 9
int
nrfuns
=
parse
(
&
funstream
,
strlen
(
funstream
));
printf
(
"Number of functions parsed: %d
\n
"
,
nrfuns
);
...
...
interpreter/main.exe
View file @
b7b37e5e
No preview for this file type
interpreter/parse.c
View file @
b7b37e5e
...
...
@@ -324,7 +324,7 @@ AppEntry* parseApp(char **ptr)
struct
AppEntry
*
entry
=
(
AppEntry
*
)
alloc_code
(
sizeof
(
AppEntry
)
+
sizeof
(
void
*
)
*
nrArgs
);
entry
->
base
.
type
=
CT_APP
;
entry
->
base
.
arity
=
nrArgs
;
entry
->
base
.
nr_args
=
nrArgs
;
entry
->
var
=
var
;
for
(
int
i
=
0
;
i
<
nrArgs
;
i
++
)
...
...
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