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
481adea1
Commit
481adea1
authored
Aug 01, 2015
by
Laszlo Domoszlai
Browse files
prepare for parsing the body of a function
parent
c26b13c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
interpreter/code.h
0 → 100644
View file @
481adea1
#ifndef __CODE_H
#define __CODE_H
#include
"desc.h"
#define CT_LIT 1
#define CT_VAR 2
#define CT_APP 3
struct
CodeFlags
{
unsigned
int
type
:
3
;
unsigned
int
local_type
:
3
;
unsigned
int
arity
:
4
;
};
#define LIT_INT 1
#define LIT_REAL 2
#define LIT_CHAR 3
#define LIT_BOOL 4
#define LIT_STRING 5
struct
CleanString
{
int
length
;
char
characters
[];
};
struct
LitEntry
{
struct
CodeFlags
flags
;
union
{
int
_int
;
double
_real
;
char
_char
;
int
_bool
;
struct
CleanString
_string
;
};
};
#define VAR_ARG
#define VAR_LOCAL
#define VAR_FN
struct
VarEntry
{
struct
CodeFlags
flags
;
union
{
int
index
;
// index on the stack
FunFlags
*
f
;
};
};
struct
AppEntry
{
struct
CodeFlags
flags
;
struct
VarEntry
*
var
;
struct
CodeFlags
*
args
[];
};
#endif // __CODE_H
\ No newline at end of file
interpreter/parse.c
View file @
481adea1
...
...
@@ -6,6 +6,9 @@
#include
"parse.h"
#include
"mem.h"
#include
"desc.h"
#include
"code.h"
int
parseInt
(
char
**
ptr
,
int
*
result
)
{
char
*
end
;
...
...
@@ -206,15 +209,40 @@ int parseDef2(char** ptr)
if
(
!
parseInt
(
ptr
,
&
defSize
))
return
-
1
;
char
*
nextDef
=
*
ptr
+
defSize
;
// This is used to temporarily copy (converts clean string to C style) the function name for lookup
char
name
[
MAX_IDENTIFIER_LENGTH
];
// 2. Type char
char
type
=
*
(
*
ptr
)
++
;
switch
(
type
)
{
case
'F'
:
// Normal function
{
int
nameLength
;
if
(
!
parseInt
(
ptr
,
&
nameLength
))
return
0
;
copyNameAndForward
(
name
,
ptr
,
nameLength
);
FunEntry
*
entry
=
(
FunEntry
*
)
find_desc
(
name
);
// should not fail, just added to the map in the 1. phase
// read continuation
*
ptr
=
(
char
*
)
entry
->
body
;
break
;
}
case
'C'
:
// CAF
{
int
nameLength
;
if
(
!
parseInt
(
ptr
,
&
nameLength
))
return
0
;
copyNameAndForward
(
name
,
ptr
,
nameLength
);
CAFEntry
*
entry
=
(
CAFEntry
*
)
find_desc
(
name
);
// should not fail, just added to the map in the 1. phase
// read continuation
*
ptr
=
(
char
*
)
entry
->
body
;
break
;
}
...
...
@@ -232,7 +260,7 @@ int parseDef2(char** ptr)
int
parse
(
char
**
ptr
,
int
length
)
{
char
*
*
origptr
=
ptr
;
char
*
origptr
=
*
ptr
;
char
*
endptr
=
*
ptr
+
length
;
int
numDefs
=
0
;
...
...
@@ -243,7 +271,7 @@ int parse(char** ptr, int length)
if
(
parseDef1
(
ptr
)
<
0
)
return
-
1
;
}
ptr
=
origptr
;
*
ptr
=
origptr
;
while
(
*
ptr
<
endptr
)
{
...
...
interpreter/parse.h
View file @
481adea1
#ifndef __PARSE_H
#define __PARSE_H
#
include
"desc.h"
#
define MAX_IDENTIFIER_LENGTH 256
int
parse
(
char
**
ptr
,
int
length
);
...
...
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