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
8faff8cc
Commit
8faff8cc
authored
Feb 29, 2016
by
Laszlo Domoszlai
Browse files
more primitive stuff
parent
377629d4
Changes
3
Hide whitespace changes
Inline
Side-by-side
interpreter/builtin.sapl
View file @
8faff8cc
...
@@ -3,6 +3,10 @@ App2 !f a1 a2 = f a1 a2
...
@@ -3,6 +3,10 @@ App2 !f a1 a2 = f a1 a2
App3 !f a1 a2 a3 = f a1 a2 a3
App3 !f a1 a2 a3 = f a1 a2 a3
App4 !f a1 a2 a3 a4 = f a1 a2 a3 a4
App4 !f a1 a2 a3 a4 = f a1 a2 a3 a4
App5 !f a1 a2 a3 a4 a5 = f a1 a2 a3 a4 a5
App5 !f a1 a2 a3 a4 a5 = f a1 a2 a3 a4 a5
App6 !f a1 a2 a3 a4 a5 a6 = f a1 a2 a3 a4 a5 a6
App7 !f a1 a2 a3 a4 a5 a6 a7 = f a1 a2 a3 a4 a5 a6 a7
App8 !f a1 a2 a3 a4 a5 a6 a7 a8 = f a1 a2 a3 a4 a5 a6 a7 a8
App9 !f a1 a2 a3 a4 a5 a6 a7 a8 a9 = f a1 a2 a3 a4 a5 a6 a7 a8 a9
:: _Tuple2 = _Tuple2 a b
:: _Tuple2 = _Tuple2 a b
:: _Tuple3 = _Tuple3 a b c
:: _Tuple3 = _Tuple3 a b c
...
@@ -12,17 +16,23 @@ string_usize !str = _Tuple2 (string_size str) str
...
@@ -12,17 +16,23 @@ string_usize !str = _Tuple2 (string_size str) str
string_uselect !str !pos::I = _Tuple2 (string_select str pos) str
string_uselect !str !pos::I = _Tuple2 (string_select str pos) str
string_replace !str !idx::I !ch::C = _Tuple2 (string_select str idx) (string_update str idx ch)
string_replace !str !idx::I !ch::C = _Tuple2 (string_select str idx) (string_update str idx ch)
array_usize !
st
r = _Tuple2 (array_size
st
r)
st
r
array_usize !
ar
r = _Tuple2 (array_size
ar
r)
ar
r
array_usize_lazy !
st
r = _Tuple2 (array_size_lazy
st
r)
st
r
array_usize_lazy !
ar
r = _Tuple2 (array_size_lazy
ar
r)
ar
r
array_usize_B_B !
st
r = _Tuple2 (array_size_B_B
st
r)
st
r
array_usize_B_B !
ar
r = _Tuple2 (array_size_B_B
ar
r)
ar
r
array_usize_B_I !
st
r = _Tuple2 (array_size_B_I
st
r)
st
r
array_usize_B_I !
ar
r = _Tuple2 (array_size_B_I
ar
r)
ar
r
array_usize_B_R !
st
r = _Tuple2 (array_size_B_R
st
r)
st
r
array_usize_B_R !
ar
r = _Tuple2 (array_size_B_R
ar
r)
ar
r
array_uselect !str !pos::I = _Tuple2 (array_select str pos) str
array_uselect !arr !pos::I = _Tuple2 (array_select arr pos) arr
array_uselect_lazy !str !pos::I = _Tuple2 (array_select_lazy str pos) str
array_uselect_lazy !arr !pos::I = _Tuple2 (array_select_lazy arr pos) arr
array_uselect_B_I !str !pos::I = _Tuple2 (array_select_B_I str pos) str
array_uselect_B_I !arr !pos::I = _Tuple2 (array_select_B_I arr pos) arr
array_uselect_B_R !str !pos::I = _Tuple2 (array_select_B_R str pos) str
array_uselect_B_R !arr !pos::I = _Tuple2 (array_select_B_R arr pos) arr
array_uselect_B_B !str !pos::I = _Tuple2 (array_select_B_B str pos) str
array_uselect_B_B !arr !pos::I = _Tuple2 (array_select_B_B arr pos) arr
array_replace !arr !idx::I !elem = _Tuple2 (array_select arr idx) (array_update arr idx elem)
array_replace_lazy !arr !idx::I elem = _Tuple2 (array_select_lazy arr idx) (array_update_lazy arr idx elem)
array_replace_B_I !arr !idx::I !elem::I = _Tuple2 (array_select_B_I arr idx) (array_update_B_I arr idx elem)
array_replace_B_B !arr !idx::I !elem::B = _Tuple2 (array_select_B_B arr idx) (array_update_B_B arr idx elem)
array_replace_B_R !arr !idx::I !elem::R = _Tuple2 (array_select_B_R arr idx) (array_update_B_R arr idx elem)
second !f !s = s
second !f !s = s
trace !str a = second (_trace str) a
trace !str a = second (_trace str) a
...
...
interpreter/parse.c
View file @
8faff8cc
...
@@ -484,7 +484,7 @@ Code* parseApp(char **ptr, bool dynamic, bool tr) {
...
@@ -484,7 +484,7 @@ Code* parseApp(char **ptr, bool dynamic, bool tr) {
if
(
overSaturated
)
if
(
overSaturated
)
{
{
int
appArity
=
nrArgs
-
desc
->
arity
;
int
appArity
=
nrArgs
-
desc
->
arity
;
assert
(
appArity
<=
5
);
assert
(
appArity
<=
9
);
struct
AppEntry
*
appEntry
struct
AppEntry
*
appEntry
=
(
AppEntry
*
)
alloc_code
(
sizeof
(
AppEntry
)
+
sizeof
(
void
*
)
*
(
appArity
+
1
));
=
(
AppEntry
*
)
alloc_code
(
sizeof
(
AppEntry
)
+
sizeof
(
void
*
)
*
(
appArity
+
1
));
...
...
interpreter/prim.c
View file @
8faff8cc
...
@@ -34,6 +34,42 @@ void __divI(int dst_idx) {
...
@@ -34,6 +34,42 @@ void __divI(int dst_idx) {
target
->
_int
=
readI
(
arg
(
2
))
/
readI
(
arg
(
1
));
target
->
_int
=
readI
(
arg
(
2
))
/
readI
(
arg
(
1
));
}
}
void
__bitxorI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
readI
(
arg
(
2
))
^
readI
(
arg
(
1
));
}
void
__bitandI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
readI
(
arg
(
2
))
&
readI
(
arg
(
1
));
}
void
__bitorI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
readI
(
arg
(
2
))
|
readI
(
arg
(
1
));
}
void
__bitnotI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
~
readI
(
arg
(
1
));
}
void
__shiftleftI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
readI
(
arg
(
2
))
<<
readI
(
arg
(
1
));
}
void
__shiftrightI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
readI
(
arg
(
2
))
>>
readI
(
arg
(
1
));
}
void
__addR
(
int
dst_idx
)
{
void
__addR
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
desc
=
(
Desc
*
)
__REAL__
;
...
@@ -58,6 +94,12 @@ void __divR(int dst_idx) {
...
@@ -58,6 +94,12 @@ void __divR(int dst_idx) {
target
->
_real
=
readR
(
arg
(
2
))
/
readR
(
arg
(
1
));
target
->
_real
=
readR
(
arg
(
2
))
/
readR
(
arg
(
1
));
}
}
void
__negR
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
-
readR
(
arg
(
1
));
}
void
__cos
(
int
dst_idx
)
{
void
__cos
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
desc
=
(
Desc
*
)
__REAL__
;
...
@@ -137,6 +179,12 @@ void __eqI(int dst_idx) {
...
@@ -137,6 +179,12 @@ void __eqI(int dst_idx) {
target
->
_int
=
readI
(
arg
(
2
))
==
readI
(
arg
(
1
));
target
->
_int
=
readI
(
arg
(
2
))
==
readI
(
arg
(
1
));
}
}
void
__eqR
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
target
->
_int
=
readR
(
arg
(
2
))
==
readR
(
arg
(
1
));
}
void
__neqI
(
int
dst_idx
)
{
void
__neqI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
target
->
desc
=
(
Desc
*
)
__BOOL__
;
...
@@ -441,6 +489,66 @@ void __string_create2(int dst_idx)
...
@@ -441,6 +489,66 @@ void __string_create2(int dst_idx)
set_return
(
dst_idx
,
target
);
set_return
(
dst_idx
,
target
);
}
}
void
__array_create2
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
len
=
arg
(
2
);
Thunk
*
def
=
arg
(
1
);
target
=
array_create
(
target
,
sizeof
(
Thunk
*
),
len
->
_int
,
AET_OTHER
);
for
(
int
i
=
0
;
i
<
len
->
_int
;
i
++
)
{
target
->
_array
.
_elems
[
i
]
=
def
;
}
set_return
(
dst_idx
,
target
);
}
void
__array_create2_b_i
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
len
=
arg
(
2
);
Thunk
*
def
=
arg
(
1
);
target
=
array_create
(
target
,
sizeof
(
int
),
len
->
_int
,
AET_INT
);
for
(
int
i
=
0
;
i
<
len
->
_int
;
i
++
)
{
target
->
_array
.
_ints
[
i
]
=
def
->
_int
;
}
set_return
(
dst_idx
,
target
);
}
void
__array_create2_b_b
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
len
=
arg
(
2
);
Thunk
*
def
=
arg
(
1
);
target
=
array_create
(
target
,
sizeof
(
char
),
len
->
_int
,
AET_BOOL
);
for
(
int
i
=
0
;
i
<
len
->
_int
;
i
++
)
{
target
->
_array
.
_bools
[
i
]
=
def
->
_int
;
}
set_return
(
dst_idx
,
target
);
}
void
__array_create2_b_r
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
len
=
arg
(
2
);
Thunk
*
def
=
arg
(
1
);
target
=
array_create
(
target
,
sizeof
(
double
),
len
->
_int
,
AET_REAL
);
for
(
int
i
=
0
;
i
<
len
->
_int
;
i
++
)
{
target
->
_array
.
_reals
[
i
]
=
def
->
_real
;
}
set_return
(
dst_idx
,
target
);
}
void
__string_update
(
int
dst_idx
)
void
__string_update
(
int
dst_idx
)
{
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
target
=
get_dst
(
dst_idx
);
...
@@ -699,6 +807,32 @@ void __C2S(int dst_idx) {
...
@@ -699,6 +807,32 @@ void __C2S(int dst_idx) {
set_return
(
dst_idx
,
target
);
set_return
(
dst_idx
,
target
);
}
}
void
__I2S
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
i
=
arg
(
1
);
char
buff
[
20
];
itoa
(
i
->
_int
,
buff
,
10
);
int
len
=
strlen
(
buff
);
target
=
string_create
(
target
,
len
);
memcpy
(
target
->
_string_ptr
->
chars
,
buff
,
len
);
set_return
(
dst_idx
,
target
);
}
void
__R2S
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
r
=
arg
(
1
);
char
buff
[
1080
];
snprintf
(
buff
,
1080
,
"%f"
,
r
->
_real
);
int
len
=
strlen
(
buff
);
target
=
string_create
(
target
,
len
);
memcpy
(
target
->
_string_ptr
->
chars
,
buff
,
len
);
set_return
(
dst_idx
,
target
);
}
void
__trace
(
int
dst_idx
)
void
__trace
(
int
dst_idx
)
{
{
Thunk
*
str
=
arg
(
1
);
Thunk
*
str
=
arg
(
1
);
...
@@ -765,6 +899,13 @@ void init_prim() {
...
@@ -765,6 +899,13 @@ void init_prim() {
add_prim
(
2
,
0
b011
,
1
,
"eqI"
,
&
__eqI
);
add_prim
(
2
,
0
b011
,
1
,
"eqI"
,
&
__eqI
);
add_prim
(
2
,
0
b011
,
1
,
"neqI"
,
&
__neqI
);
add_prim
(
2
,
0
b011
,
1
,
"neqI"
,
&
__neqI
);
add_prim
(
2
,
0
b011
,
1
,
"bitxor"
,
&
__bitxorI
);
add_prim
(
2
,
0
b011
,
1
,
"bitand"
,
&
__bitandI
);
add_prim
(
2
,
0
b011
,
1
,
"bitor"
,
&
__bitorI
);
add_prim
(
1
,
0
b001
,
1
,
"bitnot"
,
&
__bitnotI
);
add_prim
(
2
,
0
b011
,
1
,
"shiftleft"
,
&
__shiftleftI
);
add_prim
(
2
,
0
b011
,
1
,
"shiftright"
,
&
__shiftrightI
);
add_prim
(
2
,
0
b011
,
1
,
"geC"
,
&
__geC
);
add_prim
(
2
,
0
b011
,
1
,
"geC"
,
&
__geC
);
add_prim
(
2
,
0
b011
,
1
,
"ltC"
,
&
__ltC
);
add_prim
(
2
,
0
b011
,
1
,
"ltC"
,
&
__ltC
);
add_prim
(
2
,
0
b011
,
1
,
"eqC"
,
&
__eqC
);
add_prim
(
2
,
0
b011
,
1
,
"eqC"
,
&
__eqC
);
...
@@ -779,7 +920,9 @@ void init_prim() {
...
@@ -779,7 +920,9 @@ void init_prim() {
add_prim
(
1
,
0
b001
,
1
,
"acos"
,
&
__acos
);
add_prim
(
1
,
0
b001
,
1
,
"acos"
,
&
__acos
);
add_prim
(
1
,
0
b001
,
1
,
"atan"
,
&
__atan
);
add_prim
(
1
,
0
b001
,
1
,
"atan"
,
&
__atan
);
add_prim
(
1
,
0
b001
,
1
,
"absR"
,
&
__absR
);
add_prim
(
1
,
0
b001
,
1
,
"absR"
,
&
__absR
);
add_prim
(
1
,
0
b001
,
1
,
"negR"
,
&
__negR
);
add_prim
(
2
,
0
b011
,
1
,
"ltR"
,
&
__ltR
);
add_prim
(
2
,
0
b011
,
1
,
"ltR"
,
&
__ltR
);
add_prim
(
2
,
0
b011
,
1
,
"eqR"
,
&
__eqR
);
add_prim
(
2
,
0
b011
,
1
,
"eqB"
,
&
__eqB
);
add_prim
(
2
,
0
b011
,
1
,
"eqB"
,
&
__eqB
);
add_prim
(
1
,
0
b001
,
1
,
"not"
,
&
__not
);
add_prim
(
1
,
0
b001
,
1
,
"not"
,
&
__not
);
...
@@ -794,7 +937,6 @@ void init_prim() {
...
@@ -794,7 +937,6 @@ void init_prim() {
add_prim
(
1
,
0
b001
,
1
,
"I2R"
,
&
__I2R
);
add_prim
(
1
,
0
b001
,
1
,
"I2R"
,
&
__I2R
);
add_prim
(
1
,
0
b001
,
1
,
"R2R"
,
&
__R2R
);
add_prim
(
1
,
0
b001
,
1
,
"R2R"
,
&
__R2R
);
add_prim
(
1
,
0
b000
,
0
,
"S2R"
,
&
__S2R
);
add_prim
(
1
,
0
b000
,
0
,
"S2R"
,
&
__S2R
);
add_prim
(
1
,
0
b001
,
0
,
"C2S"
,
&
__C2S
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1"
,
&
__array_create1
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1"
,
&
__array_create1
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1_lazy"
,
&
__array_create1
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1_lazy"
,
&
__array_create1
);
...
@@ -802,8 +944,14 @@ void init_prim() {
...
@@ -802,8 +944,14 @@ void init_prim() {
add_prim
(
1
,
0
b001
,
0
,
"array_create1_B_B"
,
&
__array_create1_b_b
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1_B_B"
,
&
__array_create1_b_b
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1_B_R"
,
&
__array_create1_b_r
);
add_prim
(
1
,
0
b001
,
0
,
"array_create1_B_R"
,
&
__array_create1_b_r
);
add_prim
(
2
,
0
b001
,
0
,
"array_create2"
,
&
__array_create2
);
add_prim
(
2
,
0
b001
,
0
,
"array_create2_lazy"
,
&
__array_create2
);
// TODO: should not be strict
add_prim
(
2
,
0
b011
,
0
,
"array_create2_B_I"
,
&
__array_create2_b_i
);
add_prim
(
2
,
0
b011
,
0
,
"array_create2_B_B"
,
&
__array_create2_b_b
);
add_prim
(
2
,
0
b011
,
0
,
"array_create2_B_R"
,
&
__array_create2_b_r
);
add_prim
(
3
,
0
b010
,
0
,
"array_update"
,
&
__array_update
);
add_prim
(
3
,
0
b010
,
0
,
"array_update"
,
&
__array_update
);
add_prim
(
3
,
0
b010
,
0
,
"array_update_lazy"
,
&
__array_update
);
add_prim
(
3
,
0
b010
,
0
,
"array_update_lazy"
,
&
__array_update
);
// TODO: should not be strict
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_I"
,
&
__array_update_b_i
);
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_I"
,
&
__array_update_b_i
);
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_B"
,
&
__array_update_b_b
);
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_B"
,
&
__array_update_b_b
);
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_R"
,
&
__array_update_b_r
);
add_prim
(
3
,
0
b110
,
0
,
"array_update_B_R"
,
&
__array_update_b_r
);
...
@@ -829,6 +977,9 @@ void init_prim() {
...
@@ -829,6 +977,9 @@ void init_prim() {
add_prim
(
2
,
0
b000
,
0
,
"string_append"
,
&
__string_append
);
add_prim
(
2
,
0
b000
,
0
,
"string_append"
,
&
__string_append
);
add_prim
(
2
,
0
b000
,
1
,
"eqS"
,
&
__eqS
);
add_prim
(
2
,
0
b000
,
1
,
"eqS"
,
&
__eqS
);
add_prim
(
2
,
0
b000
,
1
,
"ltS"
,
&
__ltS
);
add_prim
(
2
,
0
b000
,
1
,
"ltS"
,
&
__ltS
);
add_prim
(
1
,
0
b001
,
0
,
"C2S"
,
&
__C2S
);
add_prim
(
1
,
0
b001
,
0
,
"I2S"
,
&
__I2S
);
add_prim
(
1
,
0
b001
,
0
,
"R2S"
,
&
__R2S
);
add_prim
(
1
,
0
b000
,
0
,
"_trace"
,
&
__trace
);
add_prim
(
1
,
0
b000
,
0
,
"_trace"
,
&
__trace
);
add_prim
(
1
,
0
b000
,
0
,
"abort"
,
&
__abort
);
add_prim
(
1
,
0
b000
,
0
,
"abort"
,
&
__abort
);
...
...
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