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
0a462cac
Commit
0a462cac
authored
Jan 25, 2016
by
Laszlo Domoszlai
Browse files
more working examples
parent
562cb8de
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
interpreter/gc.c
View file @
0a462cac
...
...
@@ -55,7 +55,25 @@ void gc()
}
else
{
int
size
=
ptr
->
desc
->
thunk_size
;
int
size
;
if
(
ptr
->
desc
==
(
Desc
*
)
__ARRAY__
)
{
if
(
ptr
->
_array
.
is_boxed
)
{
size
=
sizeof
(
Desc
)
+
sizeof
(
Array
)
+
(
ptr
->
_array
.
bytes_per_elem
*
ptr
->
_array
.
length
);
}
else
{
// TODO: other cases
}
}
else
{
size
=
ptr
->
desc
->
thunk_size
;
}
memcpy
(
allocptr
,
ptr
,
size
);
ptr
->
desc
=
NULL
;
ptr
->
_forward_ptr
=
(
Thunk
*
)
allocptr
;
...
...
@@ -72,7 +90,15 @@ void gc()
while
(
scanptr
<
allocptr
)
{
Thunk
*
ptr
=
(
Thunk
*
)
scanptr
;
scanptr
+=
ptr
->
desc
->
thunk_size
;
if
(
ptr
->
desc
==
(
Desc
*
)
__ARRAY__
)
{
scanptr
+=
sizeof
(
Desc
)
+
sizeof
(
Array
)
+
(
ptr
->
_array
.
bytes_per_elem
*
ptr
->
_array
.
length
);
}
else
{
scanptr
+=
ptr
->
desc
->
thunk_size
;
}
for
(
int
i
=
0
;
i
<
ptr
->
desc
->
arity
;
i
++
)
{
...
...
@@ -98,7 +124,25 @@ void gc()
}
else
{
int
size
=
arg
->
desc
->
thunk_size
;
int
size
;
if
(
arg
->
desc
==
(
Desc
*
)
__ARRAY__
)
{
if
(
arg
->
_array
.
is_boxed
)
{
size
=
sizeof
(
Desc
)
+
sizeof
(
Array
)
+
(
arg
->
_array
.
bytes_per_elem
*
arg
->
_array
.
length
);
}
else
{
// TODO: other cases
}
}
else
{
size
=
arg
->
desc
->
thunk_size
;
}
memcpy
(
allocptr
,
arg
,
size
);
arg
->
desc
=
NULL
;
arg
->
_forward_ptr
=
(
Thunk
*
)
allocptr
;
...
...
tests/parsetest1.exp
0 → 100644
View file @
0a462cac
[Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Cons [400] [Parselib.Nill]]]]]]]]]]]
\ No newline at end of file
tests/p
ostponed/Parselib
.sapl
→
tests/p
arsetest1
.sapl
View file @
0a462cac
main = Parselib.Start
Parselib.Start = Parselib.parsetest
2
0
Parselib.parsetest !n_0 = if (eq n_0 0) Parselib.Nill (Parselib.Cons (Parselib.length1 (Parselib.filter1 Parselib.isSingle (Parselib.parseRules Parselib.prog100))) (Parselib.parsetest (sub n_0 1)))
Parselib.Start = Parselib.parsetest
1
0
Parselib.parsetest !n_0
::I
= if (eq
I
n_0 0) Parselib.Nill (Parselib.Cons (Parselib.length1 (Parselib.filter1 Parselib.isSingle (Parselib.parseRules Parselib.prog100))) (Parselib.parsetest (sub
I
n_0 1)))
Parselib.prog100 = Parselib.concat1 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 (Parselib.Cons Parselib.prog10 Parselib.Nill))))))))))
:: Parselib.List1 = Parselib.Nill | Parselib.Cons a1 a2
Parselib.prog10 = Parselib.concat1 (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog (Parselib.Cons Parselib.prog Parselib.Nill))))))))))
...
...
@@ -29,9 +29,9 @@ StdList.map f_0 !_x_1 = select _x_1 (_predefined._Cons a_1_0 x_1_1 -> _predefine
Parselib.concat1 !_x_0 = select _x_0 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons _x_1_0 xss_1_1 -> select _x_1_0 (Parselib.Nill -> Parselib.concat1 xss_1_1) (Parselib.Cons x_2_0 xs_2_1 -> Parselib.Cons x_2_0 (Parselib.concat1 (Parselib.Cons xs_2_1 xss_1_1))) )
Parselib.parseRules = Parselib.start (Parselib.pMany Parselib.pRule)
Parselib.pRule = Parselib.seqleft (Parselib.sequ (Parselib.seqapply Parselib.rule Parselib.pTerm) (Parselib.option Parselib.pRightHandSide Parselib.Nill)) (Parselib.pSymbol_127 '.')
Parselib.pSymbol_127 a_0 !_x_1 = select _x_1 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons x_1_0 xs_1_1 -> if (Parselib.eqChar_128 x_1_0 a_0) (Parselib.Cons (Parselib.Tup x_1_0 xs_1_1) Parselib.Nill) Parselib.Nill)
Parselib.pSymbol_127 a_0
::C
!_x_1 = select _x_1 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons x_1_0 xs_1_1 -> if (Parselib.eqChar_128 x_1_0 a_0) (Parselib.Cons (Parselib.Tup x_1_0 xs_1_1) Parselib.Nill) Parselib.Nill)
:: Parselib.Tuptype = Parselib.Tup a1 a2
Parselib.eqChar_128 !a_0 !b_1 = eq a_0 b_1
Parselib.eqChar_128
::B
!a_0
::C
!b_1
::C
= eq
C
a_0 b_1
Parselib.pRightHandSide = Parselib.seqright (Parselib.seqright (Parselib.pSymbol_127 ':') (Parselib.pSymbol_127 '-')) (Parselib.pListSep Parselib.pTerm Parselib.pComma)
Parselib.pComma = Parselib.pSymbol_127 ','
Parselib.pTerm = Parselib.choice (Parselib.choice Parselib.pCon Parselib.pVar) Parselib.pFun
...
...
@@ -55,35 +55,35 @@ Parselib.pParens p_0 = Parselib.pPack (Parselib.pSymbol_127 '(') p_0 (Parselib.p
Parselib.pPack p_0 r_1 q_2 = Parselib.seqleft (Parselib.seqright p_0 r_1) q_2
Parselib.seqleft p_0 q_1 = Parselib.sequ (Parselib.seqapply StdFunc.const p_0) q_1
Parselib.pIdentifier = Parselib.sequ (Parselib.seqapply Parselib.list (Parselib.pSatisfy StdChar.isAlpha)) (Parselib.greedy (Parselib.pSatisfy Parselib.isAlphaNum))
Parselib.isAlphaNum !c_0 = if (StdChar.isAlpha c_0) True (StdChar.isDigit c_0)
StdChar.isDigit !c_0 = and (ge c_0 '0') (ge '9' c_0)
Parselib.isAlphaNum
::B
!c_0
::C
= if (StdChar.isAlpha c_0) True (StdChar.isDigit c_0)
StdChar.isDigit !c_0 = and (ge
C
c_0 '0') (ge
C
'9' c_0)
StdChar.isAlpha !c_0 = or (StdChar.isLower c_0) (StdChar.isUpper c_0)
StdChar.isUpper !c_0 = and (ge c_0 'A') (ge 'Z' c_0)
StdChar.isLower !c_0 = and (ge c_0 'a') (ge 'z' c_0)
StdChar.isUpper !c_0 = and (ge
C
c_0 'A') (ge
C
'Z' c_0)
StdChar.isLower !c_0 = and (ge
C
c_0 'a') (ge
C
'z' c_0)
Parselib.pSatisfy p_0 !_x_1 = select _x_1 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons x_1_0 xs_1_1 -> if (p_0 x_1_0) (Parselib.Cons (Parselib.Tup x_1_0 xs_1_1) Parselib.Nill) Parselib.Nill)
Parselib.greedy p_0 = Parselib.determ (Parselib.pMany p_0)
Parselib.determ !p_0 xs_1 = Parselib.dt (p_0 xs_1)
Parselib.dt !_x_0 = select _x_0 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons r_1_0 xs_1_1 -> Parselib.Cons r_1_0 Parselib.Nill)
Parselib.fun n_0 ns_1 = Parselib.Fun n_0 ns_1
:: Parselib.Term = Parselib.Con a1 | Parselib.Var a1 | Parselib.Fun a1 a2
:: Parselib.Term = Parselib.Con a1
::I
| Parselib.Var a1
::I
| Parselib.Fun a1 a2
Parselib.pVar = Parselib.seqapply Parselib.var (Parselib.seqright (Parselib.pSymbol_127 'X') Parselib.pNatural)
Parselib.pNatural = Parselib.seqapply (Parselib.foldlp Parselib.makeNum 0) (Parselib.pMany1 Parselib.pDigAsInt_125)
Parselib.pDigAsInt_125 = Parselib.seqapply Parselib.dig2num_126 Parselib.pDigit
Parselib.pDigit = Parselib.pSatisfy StdChar.isDigit
Parselib.dig2num_126 !c_0 = sub (
toInt_char c_0) (toInt_char
'0')
Parselib.dig2num_126
::I
!c_0
::C
= sub
I
(
C2I c_0) (C2I
'0')
Parselib.pMany1 p_0 = Parselib.sequ (Parselib.seqapply Parselib.list p_0) (Parselib.pMany p_0)
Parselib.makeNum !a_0 !b_1 = add (mult a_0 10) b_1
Parselib.makeNum
::I
!a_0
::I
!b_1
::I
= add
I
(mult
I
a_0 10) b_1
Parselib.foldlp f_0 z_1 !_x_2 = select _x_2 (Parselib.Nill -> z_1) (Parselib.Cons x_1_0 xs_1_1 -> Parselib.foldlp f_0 (f_0 z_1 x_1_0) xs_1_1)
Parselib.var n_0 = Parselib.Var n_0
Parselib.var n_0
::I
= Parselib.Var n_0
Parselib.pCon = Parselib.seqapply Parselib.con Parselib.pNatural
Parselib.con n_0 = Parselib.Con n_0
Parselib.con n_0
::I
= Parselib.Con n_0
Parselib.rule r_0 rs_1 = Parselib.Rule r_0 rs_1
:: Parselib.Rulet = Parselib.Rule a1 a2
Parselib.start !p_0 xs_1 = Parselib.fstp (Parselib.hd1 (p_0 (Parselib.filter1 Parselib.anon_130 xs_1)))
Parselib.anon_130 !x_0 = not (StdChar.isSpace x_0)
Parselib.anon_130
::B
!x_0
::C
= not (StdChar.isSpace x_0)
StdChar.isSpace !c_0 = select c_0 (' ' -> true) ('\t' -> true) ('\n' -> true) ('\r' -> true) ('\f' -> true) ('\r' -> true) (_ -> false)
Parselib.filter1 f_0 !_x_1 = select _x_1 (Parselib.Nill -> Parselib.Nill) (Parselib.Cons x_1_0 xs_1_1 -> if (f_0 x_1_0) (Parselib.Cons x_1_0 (Parselib.filter1 f_0 xs_1_1)) (Parselib.filter1 f_0 xs_1_1))
Parselib.hd1 !_x_0 = select _x_0 (Parselib.Cons x_1_0 xs_1_1 -> x_1_0)
Parselib.fstp !_x_0 = select _x_0 (Parselib.Tup f_1_0 s_1_1 -> f_1_0)
Parselib.isSingle !_x_0 = select _x_0 (Parselib.Rule _x_1_0 cs_1_1 -> select _x_1_0 (Parselib.Fun f_2_0 fs_2_1 -> if (eq (Parselib.length1 fs_2_1) 1) (eq (Parselib.length1 cs_1_1) 0) False) )
Parselib.length1 !_x_0 = select _x_0 (Parselib.Nill -> 0) (Parselib.Cons x_1_0 xs_1_1 -> add 1 (Parselib.length1 xs_1_1))
Parselib.isSingle
::B
!_x_0 = select _x_0 (Parselib.Rule _x_1_0 cs_1_1 -> select _x_1_0 (Parselib.Fun f_2_0 fs_2_1 -> if (eq
I
(Parselib.length1 fs_2_1) 1) (eq
I
(Parselib.length1 cs_1_1) 0) False) )
Parselib.length1
::I
!_x_0 = select _x_0 (Parselib.Nill -> 0) (Parselib.Cons x_1_0 xs_1_1 -> add
I
1 (Parselib.length1 xs_1_1))
tests/parsetest2.exp
0 → 100644
View file @
0a462cac
[3000]
\ No newline at end of file
tests/parsetest2.sapl
0 → 100644
View file @
0a462cac
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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