Skip to content

Commit

Permalink
Merge pull request #301 from bmstu-iu9/cstyler-intrinsic
Browse files Browse the repository at this point in the history
Интринсики (close #181, close #260)
  • Loading branch information
Mazdaywik authored Jun 29, 2020
2 parents 27ce595 + 6f3739c commit f893b74
Show file tree
Hide file tree
Showing 15 changed files with 1,161 additions and 39 deletions.
163 changes: 163 additions & 0 deletions autotests/intrinsic1.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
* TREE

$INTRINSIC __Meta_Mu;
$INTRINSIC Add, Div, Divmod, Mod, Mul, Sub, Compare;

$META Mu;

$INLINE Residue;

__Step-Drop { = }

$ENTRY Go {
/* empty */
= <Mu &Rev 'abracadabra'> : 'arbadacarba'
= <Mu Rev 'abracadabra'> : 'arbadacarba'
= <Mu ('Rev') 'abracadabra'> : 'arbadacarba'
= <Mu '?' Rev 'abracadabra'> : 'arbadacarba'
= 'abra' : e.X
= <Mu { e.A = e.X e.A e.X } 'cad'> : 'abracadabra'
= <Mu &Add 1 2> : 3
= <Mu '+' 1 2> : 3
= <Mu "+" 1 2> : 3
= <Add 1 2> : 3
= <Add '-' 1 2> : 1
= <Add 1 '-' 2> : '-' 1
= <Add '-' 1 '-' 2> : '-' 3
= <Add (2 3) 1> : 2 4
= <Add (1) 2 3> : 2 4
= <ConstValue 1> : e.z
= <Add 0 <Mul 2 e.z>> : 4
= <Sub 8 5> : 3
= <Sub '-' 8 5> : '-' 13
= <Sub 8 '-' 5> : 13
= <Sub '-' 8 '-' 5> : '-' 3
= <Sub <Mul 2 e.z> 0> : 4
= <Mul 3 3> : 9
= <Mul '-' 3 3> : '-' 9
= <Mul 3 '-' 3> : '-' 9
= <Mul '-' 3 '-' 3> : 9
= <Mul 1 <Mul 2 e.z>> : 4
= <Mul <Mul 2 e.z> 1> : 4
= <Mul (1 1) 1 1> : 1 2 1
= <Div 12 4> : 3
= <Div '-' 12 4> : '-' 3
= <Div 12 '-' 4> : '-' 3
= <Div '-' 12 '-' 4> : 3
= <Div <Mul 2 e.z> 1> : 4
= <Div (1 2) 1 1> : 1
= <Divmod 12 5> : (2) 2
= <Divmod '-' 12 5> : ('-' 2) '-' 2
= <Divmod 12 '-' 5> : ('-' 2) 2
= <Divmod '-' 12 '-' 5> : (2) '-' 2
= <Divmod <Mul 2 e.z> 1> : (4) 0
= <Divmod (1 2) 1 1> : (1) 1
= <Mod 12 5> : 2
= <Mod '-' 12 5> : '-' 2
= <Mod 12 '-' 5> : 2
= <Mod '-' 12 '-' 5> : '-' 2
= <Mod (1 2) 1 1> : 1
= <Compare 10 20> : '-'
= <Compare '-' 10 20> : '-'
= <Compare 10 '-' 20> : '+'
= <Compare '-' 10 '-' 20> : '+'
= <Compare 20 10> : '+'
= <Compare 10 10> : '0'
= <Compare (1 2) 2 3> : '-'
= <Compare ('-' 1 2) 2 3> : '-'
= /* empty */
}

ConstValue {
1 = 2
}

Rev {
t.First e.Middle t.Last = t.Last <Rev e.Middle> t.First;
t.One = t.One;
/* empty */ = /* empty */;
}

__Meta_Mu {
Rev e.Arg s.Metatable = <Rev e.Arg>;
('Rev') e.Arg s.Metatable = <Rev e.Arg>;
'+' e.Arg s.Metatable = <Add e.Arg>;
"+" e.Arg s.Metatable = <Add e.Arg>;
'?' e.Arg s.Metatable = <Residue e.Arg>;
s.Ptr e.Arg s.Metatable = <s.Ptr e.Arg>;
}

Residue {
e.Arg = <Mu e.Arg>
}

Add {
1 2 = 3;
0 4 = 4;
(2 3) 1 = 2 4;
(1) 2 3 = 2 4;
'-' 1 2 = 1;
1 '-' 2 = '-' 1;
'-' 1 '-' 2 = '-' 3
}

Sub {
8 5 = 3;
'-' 8 5 = '-' 13;
8 '-' 5 = 13;
'-' 8 '-' 5 = '-' 3;
4 0 = 4
}

Numb {
'2' = 2;
}

Mul {
2 2 = 4;
'-' 3 3 = '-' 9;
3 '-' 3 = '-' 9;
'-' 3 '-' 3 = 9;
3 3 = 9;
1 4 = 4;
4 1 = 4;
(1 1) 1 1 = 1 2 1;
}

Div {
4 1 = 4;
12 4 = 3;
'-' 12 4 = '-' 3;
12 '-' 4 = '-' 3;
'-' 12 '-' 4 = 3;
(1 2) 1 1 = 1;
}

Divmod {
4 1 = (4) 0;
12 5 = (2) 2;
'-' 12 5 = ('-' 2) '-' 2;
12 '-' 5 = ('-' 2) 2;
'-' 12 '-' 5 = (2) '-' 2;
(1 2) 1 1 = (1) 1;
}

Mod {
4 1 = 0;
12 5 = 2;
'-' 12 5 = '-' 2;
12 '-' 5 = 2;
'-' 12 '-' 5 = '-' 2;
(1 2) 1 1 = 1;
}

Compare {
10 20 = '-';
'-' 10 20 = '-';
10 '-' 20 = '+';
'-' 10 '-' 20 = '+';
20 10 = '+';
10 10 = '0';
(1 2) 2 3 = '-';
('-' 1 2) 2 3 = '-';
}
55 changes: 55 additions & 0 deletions autotests/intrinsic2.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
* TREE

$INTRINSIC Chr, Ord, Upper, Lower;

ConstValue {
1 = 'b';
2 = 'B';
3 = 'a';
4 = 10
}

$ENTRY Go {
/* empty */
= <ConstValue 4> : e.z
= <Chr 10 115 97> : '\nsa'
= <Chr e.z 115 97> : '\nsa'
= <Chr <Numb '10'> 115 97> : '\nsa'
= <ConstValue 3> : e.f
= <Ord '\nsa'> : 10 115 97
= <Ord '\ns' e.f> : 10 115 97
= <ConstValue 1> : e.x
= <Upper 'abcd'> : 'ABCD'
= <Upper 'a' e.x 'cd'> : 'ABCD'
= <Upper 'abcd'> : 'ABCD'
= <ConstValue 2> : e.y
= <Lower 'ABCD'> : 'abcd'
= <Lower 'A' e.y 'CD'> : 'abcd'
= <Lower 'ABCD'> : 'abcd'
= /* empty */
}

Chr {
10 115 97 = '\nsa';
10 = '\n'
}

Ord {
'\nsa' = 10 115 97;
'\n' = 10;
'a' = 97
}

Upper {
'abcd' = 'ABCD';
'b' = 'B'
}

Lower {
'ABCD' = 'abcd';
'B' = 'b'
}

Numb {
'10' = 10;
}
111 changes: 111 additions & 0 deletions autotests/intrinsic3.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
* TREE

$INTRINSIC Numb, Symb;
$INTRINSIC Explode, Implode, Implode_Ext, Explode_Ext;
$INTRINSIC Type;
$INTRINSIC First, Last, Lenw;

$ENTRY Go {
/* empty */
= <Numb '101'> : 101
= <Numb '-101'> : '-' 101
= <Symb 101> : '101'
= <Symb '-' 101> : '-101'

= <Implode 'abcd'> : abcd
= <Implode 'Abcd10abc#$@#$'> : Abcd10abc '#$@#$'
= <Implode_Ext 'Abcd10abc#$@#$'> : "Abcd10abc#$@#$"
= <Implode '!@#$%^&*()'> : 0 '!@#$%^&*()'
= <Explode abcd> : 'abcd'
= <Implode_Ext 'abcd'> : abcd
= <Explode_Ext abcd> : 'abcd'

= <Type 'a' b 1> : 'Lla' b 1
= <Type 1 b 1> : 'N0' 1 b 1
= <Type a b 1> : 'Wi' a b 1
= <Type "cada bra"> : 'Wq' "cada bra"
= <Type () ()> : 'B0' () ()
= <Type [Test ]> : 'Ba' [Test ]
= <Type &Test> : 'Fg' &Test
= <Type {s.1 e.x = e.x}> : 'Fc' e._
= <Type> : '*0'

= <Lenw 'abc'> : 3 'abc'
= <ConstValue 1> : s.x
= <Lenw 'a' s.x 'c'> : 3 'abc'
= <ConstValue 1> : e.y
= <Lenw 'a' e.y 'c'> : 3 'abc'

= <First 2 a (1 2) b c> : (a (1 2)) b c
= <ConstValue 2> : s.x2
= <First 2 s.x2 (1 2) b c> : (a (1 2)) b c
= <ConstValue 2> : e.y2
= <First 2 e.y2 (1 2) b c> : (a (1 2)) b c

= <Last 1 a (1 2) b c> : (a (1 2) b) c
= <ConstValue 2> : s.x2
= <Last 1 s.x2 (1 2) b c> : (a (1 2) b) c
= <ConstValue 2> : e.y2
= <Last 1 e.y2 (1 2) b c> : (a (1 2) b) c
= /* empty */
}

ConstValue {
1 = 'b';
2 = a
}

Numb {
'101' = 101;
'-101' = '-' 101
}

Symb {
101 = '101';
'-' 101 = '-101'
}

Implode {
'abcd' = abcd;
'Abcd10abc#$@#$' = Abcd10abc '#$@#$';
'!@#$%^&*()' = 0 '!@#$%^&*()'
}

Explode {
abcd = 'abcd'
}

Implode_Ext {
'abcd' = abcd;
'Abcd10abc#$@#$' = "Abcd10abc#$@#$"
}

Explode_Ext {
abcd = 'abcd'
}

$ENUM Test;

Type {
'a' b 1 = 'Lla' b 1;
1 b 1 = 'N0' 1 b 1;
a b 1 = 'Wi' a b 1;
() () = 'B0' () ();
[Test ] = 'Ba' [Test ];
&Test = 'Fg' &Test;
= '*0';
"cada bra" = 'Wq' "cada bra";
s.Closure e.Rest = 'Fc' e.Rest
}

Lenw {
'abc' = 3 'abc';
}

First {
2 a (1 2) b c = (a (1 2)) b c;
}

Last {
1 a (1 2) b c = (a (1 2) b) c;
}
3 changes: 3 additions & 0 deletions src/compiler/Checker.ref
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ SeparateDefines {
(e.Declarations) (Drive t.SrcPos s.ScopeClass e.Name) =
(e.Declarations (Drive t.SrcPos e.Name));

(e.Declarations) (Intrinsic t.SrcPos s.ScopeClass e.Name) =
(e.Declarations (Intrinsic t.SrcPos e.Name));

/* определения идентификаторов игнорируем */
(e.Declarations) (Ident t.SrcPos e.Name) =
(e.Declarations);
Expand Down
Loading

0 comments on commit f893b74

Please sign in to comment.