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
f76c202c
Commit
f76c202c
authored
Aug 18, 2015
by
Laszlo Domoszlai
Browse files
first "real" application works:
f a b = a + b g f b = f b Start = g (f 8) 9
parent
b7b37e5e
Changes
6
Hide whitespace changes
Inline
Side-by-side
interpreter/desc.h
View file @
f76c202c
...
...
@@ -71,7 +71,7 @@ struct PrimEntry
{
struct
Desc
base
;
int
strictness
;
void
(
*
exec
)();
struct
Thunk
*
(
*
exec
)();
char
name
[];
};
...
...
interpreter/main.c
View file @
f76c202c
...
...
@@ -14,34 +14,38 @@ int main()
init_desc
();
init_prim
();
//
OK
char* funstream = "25 F13 example.Start0 0 LI1 29 F4 main0 0 VF13 example.Start";
// 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";
// char* funstream = "20 F9 example.c1 1 VA0 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// 1
//
OK
char* funstream = "20 F9 example.c2 1 VA0 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c2 1 VA0 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// 1
//
OK
char* funstream = "20 F9 example.c2 2 VA1 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c2 2 VA1 44 F13 example.Start0 0 AF9 example.c2 LI2 LI1 29 F4 main0 0 VF13 example.Start";
// 2
//
OK
char* funstream = "20 F9 example.c2 2 VA1 40 F13 example.Start0 0 AF9 example.c1 LI2 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c2 2 VA1 40 F13 example.Start0 0 AF9 example.c1 LI2 29 F4 main0 0 VF13 example.Start";
// example.c 2
//
OK
char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// example.c 1
//
OK
char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c3 7 VA1 40 F13 example.Start0 0 AF9 example.c1 LI1 29 F4 main0 0 VF13 example.Start";
// example.c 1
//
OK
char* funstream = "20 F9 example.c3 7 VA1 44 F13 example.Start0 0 AF9 example.c2 LI1 LI2 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c3 7 VA1 44 F13 example.Start0 0 AF9 example.c2 LI1 LI2 29 F4 main0 0 VF13 example.Start";
// example.c 1 2
//
OK
char* funstream = "20 F9 example.c3 7 VA1 49 F13 example.Start0 0 AF9 example.c3 LI1 LI33 LI2 29 F4 main0 0 VF13 example.Start";
// char* funstream = "20 F9 example.c3 7 VA1 49 F13 example.Start0 0 AF9 example.c3 LI1 LI33 LI2 29 F4 main0 0 VF13 example.Start";
// 33
//
OK
char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 34 F13 example.Start0 0 VF9 example.B29 F4 main0 0 VF13 example.Start";
// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 34 F13 example.Start0 0 VF9 example.B29 F4 main0 0 VF13 example.Start";
// example.B
// char* funstream = "33 A2 9 example.A2 2 9 example.B0 0 40 F13 example.Start0 0 AF9 example.A1 LI5 29 F4 main0 0 VF13 example.Start";
// 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";
// 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
//
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";
// 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";
// 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
// char* funstream = "26 F9 example.g2 2 AA1 1 VA0 20 F9 example.f2 2 VA1 59 F13 example.Start0 0 AF9 example.g2 AF9 example.f1 LI8 LI9 29 F4 main0 0 VF13 example.Start";
// 8
char
*
funstream
=
"26 F9 example.g2 2 AA1 1 VA0 37 F12 example.f_502 3 AF3 add2 VA1 VA0 63 F13 example.Start0 0 AF9 example.g2 AF12 example.f_501 LI8 LI9 29 F4 main0 0 VF13 example.Start"
;
// 17
int
nrfuns
=
parse
(
&
funstream
,
strlen
(
funstream
));
printf
(
"Number of functions parsed: %d
\n
"
,
nrfuns
);
...
...
interpreter/main.exe
View file @
f76c202c
No preview for this file type
interpreter/prim.c
View file @
f76c202c
...
...
@@ -3,14 +3,15 @@
#include
"prim.h"
#include
"desc.h"
#include
"thunk.h"
#include
"mem.h"
void
__add
()
Thunk
*
__add
()
{
return
createI
(
readI
(
eval
(
stack
[
stack_top
-
2
]))
+
readI
(
eval
(
stack
[
stack_top
-
1
])));
}
PrimEntry
*
add_prim
(
int
arity
,
int
strictness
,
char
*
name
,
void
(
*
exec
)())
PrimEntry
*
add_prim
(
int
arity
,
int
strictness
,
char
*
name
,
Thunk
*
(
*
exec
)())
{
int
nameLength
=
strlen
(
name
);
...
...
interpreter/thunk.c
View file @
f76c202c
...
...
@@ -14,6 +14,17 @@ struct Thunk* createI(int i)
return
thunk
;
}
int
readI
(
Thunk
*
thunk
)
{
if
(
thunk
->
desc
!=
(
Desc
*
)
__INT__
)
{
printf
(
"readI: not an integer
\n
"
);
exit
(
-
1
);
}
return
thunk
->
_int
;
}
struct
Thunk
*
createF
(
Desc
*
f
,
int
nrargs
)
{
// Even if no arguments, still allocate enough space for a forward pointer
...
...
@@ -32,7 +43,7 @@ Thunk* eval(Thunk* thunk)
case
FT_ADT
:
case
FT_RECORD
:
return
thunk
;
case
FT_FUN
:
case
FT_FUN
:
int
old_top
;
old_top
=
stack_top
;
...
...
@@ -44,6 +55,18 @@ Thunk* eval(Thunk* thunk)
stack_top
=
old_top
;
break
;
case
FT_PRIM
:
old_top
=
stack_top
;
for
(
int
i
=
0
;
i
<
thunk
->
desc
->
arity
;
i
++
)
{
pushs
(
thunk
->
_args
[
i
]);
}
thunk
=
((
PrimEntry
*
)
thunk
->
desc
)
->
exec
();
stack_top
=
old_top
;
break
;
default:
printf
(
"eval: unhandled DESC
\n
"
);
exit
(
-
1
);
...
...
interpreter/thunk.h
View file @
f76c202c
...
...
@@ -20,6 +20,8 @@ typedef struct Thunk
}
Thunk
;
struct
Thunk
*
createI
(
int
i
);
int
readI
(
Thunk
*
thunk
);
struct
Thunk
*
createF
(
Desc
*
f
,
int
nrargs
);
Thunk
*
eval
(
Thunk
*
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