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
377629d4
Commit
377629d4
authored
Feb 29, 2016
by
Laszlo Domoszlai
Browse files
more primitive functions
parent
567aa67a
Changes
2
Hide whitespace changes
Inline
Side-by-side
interpreter/builtin.sapl
View file @
377629d4
...
...
@@ -12,6 +12,18 @@ string_usize !str = _Tuple2 (string_size str) 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)
array_usize !str = _Tuple2 (array_size str) str
array_usize_lazy !str = _Tuple2 (array_size_lazy str) str
array_usize_B_B !str = _Tuple2 (array_size_B_B str) str
array_usize_B_I !str = _Tuple2 (array_size_B_I str) str
array_usize_B_R !str = _Tuple2 (array_size_B_R str) str
array_uselect !str !pos::I = _Tuple2 (array_select str pos) str
array_uselect_lazy !str !pos::I = _Tuple2 (array_select_lazy str pos) str
array_uselect_B_I !str !pos::I = _Tuple2 (array_select_B_I str pos) str
array_uselect_B_R !str !pos::I = _Tuple2 (array_select_B_R str pos) str
array_uselect_B_B !str !pos::I = _Tuple2 (array_select_B_B str pos) str
second !f !s = s
trace !str a = second (_trace str) a
...
...
interpreter/prim.c
View file @
377629d4
#include
<string.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
#include
"prim.h"
#include
"desc.h"
...
...
@@ -57,6 +58,43 @@ void __divR(int dst_idx) {
target
->
_real
=
readR
(
arg
(
2
))
/
readR
(
arg
(
1
));
}
void
__cos
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
cos
(
readR
(
arg
(
1
)));
}
void
__sin
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
sin
(
readR
(
arg
(
1
)));
}
void
__tan
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
tan
(
readR
(
arg
(
1
)));
}
void
__acos
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
acos
(
readR
(
arg
(
1
)));
}
void
__atan
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
atan
(
readR
(
arg
(
1
)));
}
void
__absR
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
double
val
=
readR
(
arg
(
1
));
target
->
_real
=
val
<
0
?
-
val
:
val
;
}
void
__gtI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
...
...
@@ -87,6 +125,12 @@ void __ltC(int dst_idx) {
target
->
_int
=
readC
(
arg
(
2
))
<
readC
(
arg
(
1
));
}
void
__ltR
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
target
->
_int
=
readR
(
arg
(
2
))
<
readR
(
arg
(
1
));
}
void
__eqI
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
...
...
@@ -239,6 +283,15 @@ void __string_size(int dst_idx)
target
->
_int
=
length
;
}
void
__array_size
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
arr
=
arg
(
1
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
arr
->
_array
.
length
;
}
void
__string_select
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
...
...
@@ -260,6 +313,54 @@ void __string_select(int dst_idx)
target
->
_int
=
(
char
)
chars
[
pos
->
_int
];
}
void
__array_select
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
arr
=
arg
(
2
);
Thunk
*
pos
=
arg
(
1
);
Thunk
*
elem
=
arr
->
_array
.
_elems
[
pos
->
_int
];
if
(
target
!=
NULL
)
{
target
->
desc
=
(
Desc
*
)
__FORWARD_PTR__
;
target
->
_forward_ptr
=
elem
;
}
set_return
(
dst_idx
,
elem
);
}
void
__array_select_b_b
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
arr
=
arg
(
2
);
Thunk
*
pos
=
arg
(
1
);
target
->
desc
=
(
Desc
*
)
__BOOL__
;
target
->
_int
=
(
int
)
arr
->
_array
.
_bools
[
pos
->
_int
];
}
void
__array_select_b_i
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
arr
=
arg
(
2
);
Thunk
*
pos
=
arg
(
1
);
target
->
desc
=
(
Desc
*
)
__INT__
;
target
->
_int
=
arr
->
_array
.
_ints
[
pos
->
_int
];
}
void
__array_select_b_r
(
int
dst_idx
)
{
Thunk
*
target
=
get_dst
(
dst_idx
);
Thunk
*
arr
=
arg
(
2
);
Thunk
*
pos
=
arg
(
1
);
target
->
desc
=
(
Desc
*
)
__REAL__
;
target
->
_real
=
arr
->
_array
.
_reals
[
pos
->
_int
];
}
Thunk
*
array_create
(
Thunk
*
target
,
int
elementsize
,
int
len
,
ArrayElementType
type
)
{
int
newsize
=
sizeof
(
Desc
)
+
sizeof
(
Array
)
+
len
*
elementsize
;
...
...
@@ -671,7 +772,14 @@ void init_prim() {
add_prim
(
2
,
0
b011
,
1
,
"addR"
,
&
__addR
);
add_prim
(
2
,
0
b011
,
1
,
"subR"
,
&
__subR
);
add_prim
(
2
,
0
b011
,
1
,
"multR"
,
&
__multR
);
add_prim
(
2
,
0
b011
,
1
,
"divR"
,
&
__divR
);
add_prim
(
2
,
0
b011
,
1
,
"divR"
,
&
__divR
);
add_prim
(
1
,
0
b001
,
1
,
"cos"
,
&
__cos
);
add_prim
(
1
,
0
b001
,
1
,
"sin"
,
&
__sin
);
add_prim
(
1
,
0
b001
,
1
,
"tan"
,
&
__tan
);
add_prim
(
1
,
0
b001
,
1
,
"acos"
,
&
__acos
);
add_prim
(
1
,
0
b001
,
1
,
"atan"
,
&
__atan
);
add_prim
(
1
,
0
b001
,
1
,
"absR"
,
&
__absR
);
add_prim
(
2
,
0
b011
,
1
,
"ltR"
,
&
__ltR
);
add_prim
(
2
,
0
b011
,
1
,
"eqB"
,
&
__eqB
);
add_prim
(
1
,
0
b001
,
1
,
"not"
,
&
__not
);
...
...
@@ -700,6 +808,18 @@ void init_prim() {
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
(
1
,
0
b000
,
1
,
"array_size"
,
&
__array_size
);
add_prim
(
1
,
0
b000
,
1
,
"array_size_lazy"
,
&
__array_size
);
add_prim
(
1
,
0
b000
,
1
,
"array_size_B_I"
,
&
__array_size
);
add_prim
(
1
,
0
b000
,
1
,
"array_size_B_B"
,
&
__array_size
);
add_prim
(
1
,
0
b000
,
1
,
"array_size_B_R"
,
&
__array_size
);
add_prim
(
2
,
0
b010
,
0
,
"array_select"
,
&
__array_select
);
add_prim
(
2
,
0
b010
,
0
,
"array_select_lazy"
,
&
__array_select
);
add_prim
(
2
,
0
b010
,
1
,
"array_select_B_I"
,
&
__array_select_b_i
);
add_prim
(
2
,
0
b010
,
1
,
"array_select_B_B"
,
&
__array_select_b_b
);
add_prim
(
2
,
0
b010
,
1
,
"array_select_B_R"
,
&
__array_select_b_r
);
add_prim
(
1
,
0
b000
,
1
,
"string_size"
,
&
__string_size
);
add_prim
(
2
,
0
b010
,
1
,
"string_select"
,
&
__string_select
);
add_prim
(
1
,
0
b001
,
0
,
"string_create1"
,
&
__string_create1
);
...
...
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