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
93c55a3e
Commit
93c55a3e
authored
Jul 30, 2015
by
Laszlo Domoszlai
Browse files
Function/ADT/Record descriptors are created from precompiled SAPL code now
parent
f30e8871
Changes
10
Hide whitespace changes
Inline
Side-by-side
interpreter/compile.bat
View file @
93c55a3e
g
++
-Wno-write-strings -Wno-pointer-arith
main
.c
fun
.c
mem
.c
parse
.c
-o
main
g
++
-Wno-write-strings -Wno-pointer-arith
main
.c
desc
.c
mem
.c
parse
.c
-o
main
interpreter/
fun
.c
→
interpreter/
desc
.c
View file @
93c55a3e
#include
"
fun
.h"
#include
"
desc
.h"
#include
<stdio.h>
#include
<stdlib.h>
...
...
@@ -20,13 +20,13 @@ KHASH_MAP_INIT_STR(khStrPtr, FunFlags*) // setup khash to handle string key with
// create a hashtable
khash_t
(
khStrPtr
)
*
funHash
=
kh_init
(
khStrPtr
);
void
add_
fun
(
char
*
fn
,
FunFlags
*
desc
)
void
add_
desc
(
char
*
fn
,
FunFlags
*
desc
)
{
khiter_t
k
;
// used by the macros
kh_set
(
khStrPtr
,
funHash
,
fn
,
desc
);
}
FunFlags
*
find_
fun
(
char
*
fn
)
FunFlags
*
find_
desc
(
char
*
fn
)
{
khiter_t
k
;
// used by the macros
return
kh_get_val
(
khStrPtr
,
funHash
,
fn
);
...
...
interpreter/
fun
.h
→
interpreter/
desc
.h
View file @
93c55a3e
#ifndef __
FUN
_H
#define __
FUN
_H
#ifndef __
DESC
_H
#define __
DESC
_H
#define FT_RECORD 1
#define FT_ADT 2
...
...
@@ -32,7 +32,7 @@ struct ADTEntry
{
struct
FunFlags
flags
;
int
strictness
;
char
*
name
;
char
name
[]
;
};
struct
CAFEntry
...
...
@@ -54,9 +54,10 @@ struct RecordEntry
struct
FunFlags
flags
;
int
strictness
;
char
**
fields
;
char
name
[];
};
void
add_
fun
(
char
*
fn
,
FunFlags
*
desc
);
FunFlags
*
find_
fun
(
char
*
fn
);
void
add_
desc
(
char
*
fn
,
FunFlags
*
desc
);
FunFlags
*
find_
desc
(
char
*
fn
);
#endif // __FUN_H
\ No newline at end of file
#endif // __DESC_H
\ No newline at end of file
interpreter/main.c
View file @
93c55a3e
...
...
@@ -2,7 +2,7 @@
#include
<stdio.h>
#include
"mem.h"
#include
"
fun
.h"
#include
"
desc
.h"
#include
"parse.h"
int
main
()
...
...
@@ -10,14 +10,10 @@ int main()
init_mem
();
int
res
;
char
*
stream
=
"
37 F12
example.
g_453 6 AF3 add2 VA0 VA1
"
;
char
*
stream
=
"
40 R10
example.
_R2 1 9 example.a9 example.b
"
;
FunEntry
*
entry
;
parseLine
(
&
stream
,
(
FunFlags
**
)
&
entry
);
printf
(
"%s"
,
entry
->
name
);
parseLine1
(
&
stream
);
// add_fun("jimbo", (FunFlags*) "artist");
// char *tval = (char*) find_fun("jimbo");
// printf ("shortcut tval for jimbo = %s\n", tval);
...
...
interpreter/mem.c
View file @
93c55a3e
...
...
@@ -2,32 +2,15 @@
#include
"mem.h"
void
*
code_mem_free_ptr
;
void
*
code_mem_end
;
void
*
fun_table_free_ptr
;
void
*
fun_table_end
;
int
desc_alloc
;
void
init_mem
()
{
code_mem_free_ptr
=
malloc
(
CODEMEMSIZE
);
code_mem_end
=
code_mem_free_ptr
+
CODEMEMSIZE
;
fun_table_free_ptr
=
malloc
(
FUNTABLESIZE
);
fun_table_end
=
fun_table_free_ptr
+
FUNTABLESIZE
;
desc_alloc
=
0
;
}
void
*
alloc_
fun_table
(
int
size
)
void
*
alloc_
desc
(
int
size
)
{
void
*
current
=
fun_table_free_ptr
;
fun_table_free_ptr
+=
size
;
if
(
fun_table_free_ptr
<
fun_table_end
)
{
return
current
;
}
else
{
return
0
;
}
desc_alloc
+=
size
;
return
malloc
(
size
);
}
\ No newline at end of file
interpreter/mem.h
View file @
93c55a3e
#ifndef __MEM_H
#define __MEM_H
#define CODEMEMSIZE 10000
#define FUNTABLESIZE 10000
void
init_mem
();
// TODO: inline
void
*
alloc_
fun_table
(
int
size
);
void
*
alloc_
desc
(
int
size
);
#endif // __MEM_H
interpreter/parse.c
View file @
93c55a3e
...
...
@@ -4,7 +4,6 @@
#include
<string.h>
#include
"parse.h"
#include
"fun.h"
#include
"mem.h"
int
parseInt
(
char
**
ptr
,
int
*
result
)
...
...
@@ -23,7 +22,7 @@ int parseInt(char** ptr, int* result)
}
}
int
parseLine
(
char
**
ptr
,
FunFlags
**
fun
)
int
parseLine
1
(
char
**
ptr
)
{
int
lineSize
;
...
...
@@ -37,17 +36,20 @@ int parseLine(char** ptr, FunFlags** fun)
switch
(
type
)
{
case
'F'
:
// Normal function
{
// example.g_45 !a_0 !b_1 c_2 = add a_0 b_1
// 37 F12 example.g_453 6 AF3 add2 VA0 VA1
int
nameLength
;
if
(
!
parseInt
(
ptr
,
&
nameLength
))
return
0
;
FunEntry
*
entry
=
(
FunEntry
*
)
alloc_
fun_table
(
sizeof
(
FunEntry
)
+
nameLength
+
1
);
FunEntry
*
entry
=
(
FunEntry
*
)
alloc_
desc
(
sizeof
(
FunEntry
)
+
nameLength
+
1
);
entry
->
flags
.
type
=
FT_FUN
;
memcpy
(
entry
->
name
,
*
ptr
,
nameLength
);
entry
->
name
[
nameLength
]
=
'\0'
;
*
ptr
+=
nameLength
;
int
arity
;
...
...
@@ -58,9 +60,80 @@ int parseLine(char** ptr, FunFlags** fun)
// set the continuation for stage 2
entry
->
body
=
*
ptr
;
*
fun
=
(
FunFlags
*
)
entry
;
add_desc
(
entry
->
name
,
(
FunFlags
*
)
entry
);
break
;
}
case
'A'
:
// ADT
{
// :: example.A = example.A !a1 a2 | example.B
// 33 A2 9 example.A2 2 9 example.B0 0
int
conNum
;
if
(
!
parseInt
(
ptr
,
&
conNum
))
return
0
;
for
(
int
i
=
0
;
i
<
conNum
;
i
++
)
{
int
nameLength
;
if
(
!
parseInt
(
ptr
,
&
nameLength
))
return
0
;
ADTEntry
*
entry
=
(
ADTEntry
*
)
alloc_desc
(
sizeof
(
ADTEntry
)
+
nameLength
+
1
);
entry
->
flags
.
type
=
FT_ADT
;
memcpy
(
entry
->
name
,
*
ptr
,
nameLength
);
entry
->
name
[
nameLength
]
=
'\0'
;
*
ptr
+=
nameLength
;
int
arity
;
if
(
!
parseInt
(
ptr
,
&
arity
))
return
0
;
entry
->
flags
.
arity
=
arity
;
if
(
!
parseInt
(
ptr
,
&
entry
->
strictness
))
return
0
;
add_desc
(
entry
->
name
,
(
FunFlags
*
)
entry
);
}
break
;
}
case
'R'
:
// Record
{
// :: example._R = {example.a, !example.b}
// 40 R10 example._R2 1 9 example.a9 example.b
int
nameLength
;
if
(
!
parseInt
(
ptr
,
&
nameLength
))
return
0
;
RecordEntry
*
entry
=
(
RecordEntry
*
)
alloc_desc
(
sizeof
(
RecordEntry
)
+
nameLength
+
1
);
entry
->
flags
.
type
=
FT_RECORD
;
memcpy
(
entry
->
name
,
*
ptr
,
nameLength
);
entry
->
name
[
nameLength
]
=
'\0'
;
*
ptr
+=
nameLength
;
int
arity
;
if
(
!
parseInt
(
ptr
,
&
arity
))
return
0
;
entry
->
flags
.
arity
=
arity
;
if
(
!
parseInt
(
ptr
,
&
entry
->
strictness
))
return
0
;
entry
->
fields
=
(
char
**
)
alloc_desc
(
sizeof
(
char
*
)
*
arity
);
for
(
int
i
=
0
;
i
<
arity
;
i
++
)
{
int
fieldNameLength
;
if
(
!
parseInt
(
ptr
,
&
fieldNameLength
))
return
0
;
entry
->
fields
[
i
]
=
(
char
*
)
malloc
(
fieldNameLength
);
memcpy
(
entry
->
fields
[
i
],
*
ptr
,
fieldNameLength
);
entry
->
fields
[
i
][
fieldNameLength
]
=
'\0'
;
*
ptr
+=
fieldNameLength
;
}
add_desc
(
entry
->
name
,
(
FunFlags
*
)
entry
);
break
;
}
default:
return
0
;
}
...
...
interpreter/parse.h
View file @
93c55a3e
#ifndef __PARSE_H
#define __PARSE_H
#include
"
fun
.h"
#include
"
desc
.h"
//int parseInt(char** str, int* result);
int
parseLine
(
char
**
ptr
,
FunFlags
**
fun
);
int
parseLine
1
(
char
**
ptr
);
#endif // __PARSE_H
\ No newline at end of file
precompiler/p
arse
rcompiler.icl
→
precompiler/pr
e
compiler.icl
View file @
93c55a3e
module
p
arse
rcompiler
module
pr
e
compiler
import
Sapl
.
SaplParser
import
Sapl
.
SaplTokenizer
...
...
@@ -30,11 +30,19 @@ sFunc ctx (FTFunc name body params) a
#
ctx
=
{
ctx
&
vars
=
addVars
ctx
.
vars
0
params
}
=
a
<++
"F"
<++
sText
(
unpackVar
name
)
<++
sNum
(
length
params
)
<++
sNum
(
calcStrictness
params
)
<++
sTerm
ctx
body
sList
f
es
a
=
a
<++
sNum
(
length
es
)
<++
sList0
es
where
sList0
[
e
]
a
=
a
<++
f
e
sList0
[
e
:
es
]
a
=
sList0
es
(
a
<++
f
e
<++
""
)
sList0
[]
a
=
a
sFunc
ctx
(
FTRecord
name
fields
)
a
=
a
<++
"R"
<++
sText
(
unpackVar
name
)
<++
sNum
(
length
fields
)
<++
sNum
(
calcStrictness
fields
)
<++
sList0
sText
(
map
unpackVar
fields
)
sFunc
ctx
(
FTADT
typeName
cs
)
a
=
a
<++
"A"
<++
sList
sCon
cs
where
sCon
(
SaplConstructor
name
_
params
)
a
=
a
<++
sText
(
unpackVar
name
)
<++
sNum
(
length
params
)
<++
sNum
(
calcStrictness
params
)
sList
f
es
a
=
a
<++
sNum
(
length
es
)
<++
sList0
f
es
sList0
f
[
e
]
a
=
a
<++
f
e
sList0
f
[
e
:
es
]
a
=
sList0
f
es
(
a
<++
f
e
<++
""
)
sList0
f
[]
a
=
a
sNum
num
a
=
a
<++
num
<++
" "
sText
text
a
=
a
<++
sNum
(
textSize
text
)
<++
text
...
...
precompiler/p
arse
rcompiler.prj
→
precompiler/pr
e
compiler.prj
View file @
93c55a3e
...
...
@@ -2,7 +2,7 @@ Version: 1.4
Global
ProjectRoot: .
Target: iTasks
Exec: {Project}\p
arse
rcompiler.exe
Exec: {Project}\pr
e
compiler.exe
CodeGen
CheckStacks: False
CheckIndexes: True
...
...
@@ -46,7 +46,7 @@ Global
Precompile:
Postlink:
MainModule
Name: p
arse
rcompiler
Name: pr
e
compiler
Dir: {Project}
Compiler
NeverMemoryProfile: False
...
...
@@ -60,62 +60,6 @@ MainModule
ReuseUniqueNodes: True
Fusion: False
OtherModules
Module
Name: Sapl.FastString
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplParser
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplStruct
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplTokenizer
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: StdArray
Dir: {Application}\Libraries\StdEnv
...
...
@@ -851,6 +795,62 @@ OtherModules
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.FastString
Dir: {Application}\iTasks-SDK\Dependencies\SAPL
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplParser
Dir: {Application}\iTasks-SDK\Dependencies\SAPL
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplStruct
Dir: {Application}\iTasks-SDK\Dependencies\SAPL
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Sapl.SaplTokenizer
Dir: {Application}\iTasks-SDK\Dependencies\SAPL
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: _SystemDynamic
Dir: {Application}\iTasks-SDK\Patches\Dynamics
...
...
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