Skip to content

Commit

Permalink
Использование всюду MapAccum вместо MapReduce (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Apr 6, 2020
1 parent 4a387dc commit f2c2f94
Show file tree
Hide file tree
Showing 27 changed files with 53 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ first one has priority.
* Extensive enough standard library (in comparison with classic Refal-5
library). Alongside with all the Refal-5 capabilities `Library` provides
the binary input/output, LibraryEx – handy utility functions and higher
order functions: `Map`, `Reduce`, hybrid `MapReduce` which significantly
order functions: `Map`, `Reduce`, hybrid `MapAccum` which significantly
simplify the looping constructs writing.
* Encapsulation: named brackets support – abstract data types. The content
of such brackets is available only in that compilation unit where they
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
библиотекой классического Рефала-5). Библиотека `Library` предоставляет
в дополнение ко всем возможностям Рефала-5 ещё и двоичный ввод/вывод,
библиотека `LibraryEx` — удобные вспомогательные функции и функции высшего
порядка: `Map`, `Reduce`, «гибрид» `MapReduce`, которые существенно
порядка: `Map`, `Reduce`, «гибрид» `MapAccum`, которые существенно
упрощают написание циклических конструкций.
* Инкапсуляция: поддержка именованных скобок — абстрактных типов данных.
Содержимое таких скобок доступно только в той единице трансляции, где они
Expand Down
5 changes: 2 additions & 3 deletions doc/examples/inifile/inifile.sref
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//FROM LibraryEx
$EXTERN Fetch, LoadFile, Pipe, MapReduce, Inc, DelAccumulator, Map, Trim,
Reduce;
$EXTERN Fetch, LoadFile, Pipe, MapAccum, Inc, DelAccumulator, Map, Trim, Reduce;

/*
<LoadIniFile e.FileName>
Expand All @@ -22,7 +21,7 @@ $ENTRY LoadIniFile {
<LoadFile e.FileName>
<Pipe
// Нумеруем строки файла
(MapReduce
(MapAccum
{
s.LineNumber (e.Line)
= <Inc s.LineNumber> (s.LineNumber e.Line);
Expand Down
2 changes: 1 addition & 1 deletion doc/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ DoFact {
начинаются с префикса `Sw`. Хотя вместо таких функций рекомендуется
использовать идиому `Fetch`.
* Вместо остаточно-рекурсивных циклов (см. выше) рекомендуется использовать
библиотечные функции `Map`, `MapReduce` или `Reduce`, если это не снижает
библиотечные функции `Map`, `MapAccum` или `Reduce`, если это не снижает
читабельность кода.

## Рекомендации по оформлению кода на C++
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/Checker.ref
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ CheckSpecs-SeparateErrors-Rec {

SeparateDefines {
e.AST
= <MapReduce
= <MapAccum
{
(e.Declarations)
(Function t.SrcPos s.ScopeClass (e.Name) e.Body) =
Expand Down Expand Up @@ -766,7 +766,7 @@ CheckPattern {
>;

(e.ScopeVars) e.Items =
<MapReduce
<MapAccum
{
(e.KnownVars-B (s.Mode e.Index) e.KnownVars-E)
(TkVariable t.SrcPos s.Mode e.Index) =
Expand Down
16 changes: 8 additions & 8 deletions src/compiler/Desugaring.ref
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ EnumerateVars-Assignments {

EnumerateVars-Expr {
s.Depth (e.OriginScopeVars) e.Expr =
<MapReduce
<MapAccum
{
(e.ScopeVars-B (s.Mode e.Index s.Depth^) e.ScopeVars-E)
(TkVariable s.Mode e.Index) =
Expand Down Expand Up @@ -353,7 +353,7 @@ NameNestedBody {
(e.MainName) Sentences e.Sentences
= Sentences
<DelAccumulator
<MapReduce
<MapAccum
{
s.SentenceNumber ((e.Pattern) e.Assigns (e.Result) (e.Blocks^))
= e.MainName '$' s.SentenceNumber: e.MainName^
Expand All @@ -375,7 +375,7 @@ NameNestedBody {

NameNestedBlocks {
(e.MainName) e.Blocks
= <MapReduce
= <MapAccum
{
s.BlockNumber (e.Body)
= e.MainName ':' s.BlockNumber : e.MainName^
Expand All @@ -391,7 +391,7 @@ NameNestedBlocks {
NameNestedAssigns {
(e.MainName) e.Assigns
= <DelAccumulator
<MapReduce
<MapAccum
{
s.AssignId (s.ChainType (e.Result) (e.Blocks) (e.Pattern))
= <ChainTypeMarker s.ChainType> : s.Marker
Expand Down Expand Up @@ -422,7 +422,7 @@ NameNestedResult {

NameNestedResultRec {
s.StartNumber (e.MainName) e.Result
= <MapReduce
= <MapAccum
(&NameNestedResultRec-Term e.MainName)
s.StartNumber e.Result
>;
Expand Down Expand Up @@ -595,7 +595,7 @@ ExtractNested {

ExtractNestedRec {
s.MarkupContext (e.ScopeVars) Sentences e.Sentences
= <MapReduce
= <MapAccum
(&ExtractNested-Sentence s.MarkupContext e.ScopeVars)
((/* вложенные функции */) (/* заимствованные переменные */))
e.Sentences
Expand Down Expand Up @@ -665,7 +665,7 @@ ExtractNested-Conditions {

ExtractNested-Pattern {
(e.ScopeVars) (e.BorrowedVars) e.Pattern =
<MapReduce
<MapAccum
(&UpdateBorrowedVars e.ScopeVars)
(e.BorrowedVars)
<Uniq
Expand Down Expand Up @@ -711,7 +711,7 @@ UpdateBorrowedVars {
ExtractNested-Result {
s.MarkupContext
(e.OriginBorrowedVars) (e.ScopeVars) (e.LocalVars) e.OriginResult
= <MapReduce
= <MapAccum
(&ExtractNested-Result-Term s.MarkupContext (e.ScopeVars) (e.LocalVars))
((/* nested funcs */) (e.OriginBorrowedVars)) e.OriginResult
>
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Engine.ref
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ ResolveIncludes-CheckEqualAST {

GlueErrorListsAndASTs {
(e.SrcName) e.Units
= <MapReduce
= <MapAccum
{
t.CommonErrorList (t.ErrorList (e.UnitName) e.AST)
= <EL-Concat t.CommonErrorList t.ErrorList>
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/GST.ref
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ENTRY GST {
Enum {
e.Items =
<DelAccumulator
<MapReduce
<MapAccum
{ s.Num t.Item = <Inc s.Num> (Num s.Num t.Item); }
0 e.Items
>
Expand Down Expand Up @@ -219,7 +219,7 @@ FilterOverlapped {

FindHeavyTile {
t.NextTile e.Tiles =
<MapReduce
<MapAccum
{
(s.MaxWeight s.IndexP s.IndexR e.MaxItems)
(s.Weight s.CurIndexP s.CurIndexR e.Items)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Generator-Native.ref
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $EXTERN EscapeChar, EscapeString;
$ENTRY GenProgram-Native {
(e.SourceFileName) (e.TargetFileName) (e.NativeRASL)

= <MapReduce
= <MapAccum
&GenCommand-Native
(/* отступ */)
e.NativeRASL
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Generator-RASL.ref
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ CreateCommandInfo {

CalcLabelsOffsets {
e.RASL
= <MapReduce
= <MapAccum
{
(s.Offset e.Labels) (LABEL s.Label)
= (s.Offset e.Labels (s.Label s.Offset));
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/GlobalGen.ref
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ DoLocalGen {
/* Возвращает первый элемент с максимальным ключом */
GlobalGenFromLocalGen {
t.Sentence e.OtherSentences
= <MapReduce
= <MapAccum
{
(s.NumAcc e.SentenceAcc) (s.NumNext e.SentenceNext)
= <Max s.NumAcc s.NumNext>
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/HighLevelRASL-Common.ref
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ BuildString {
*/
$ENTRY MakeSavers {
s.OriginContextOffset e.SubstitutesAndJunks
= <MapReduce
= <MapAccum
{
(s.ContextOffset e.CmdSaves) (Junk e.Junk)
= (s.ContextOffset e.CmdSaves) (Junk e.Junk);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/HighLevelRASL-ConjointFunc.ref
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ComposeVars {
/* Добавляет уникальные индексы */
EnumerateVarsRec {
s.NextNumber e.Expr
= <MapReduce
= <MapAccum
{
s.Next (TkVariable s.Type)
= <Inc s.Next> (TkVariable s.Type 'new' s.Next);
Expand All @@ -201,7 +201,7 @@ EnumerateVarsRec {

EnumerateVars-Subst {
s.StartNumber s.Depth e.Substitute
= <MapReduce
= <MapAccum
{
s.NextNumber (e.Value ':' (e.Var))
= <EnumerateVarsRec s.NextNumber e.Value> : s.NextNumber^ e.Value^
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/HighLevelRASL-DisjointFunc.ref
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ENTRY HighLevelRASL-Function-Disjoint {
>
: e.Sentences^ ((CmdIssueMemory s.LastMemory) e.LastSentence)

= <MapReduce
= <MapAccum
{
s.MaxMemory ((CmdIssueMemory s.Memory) e.Sentence) =
<Max s.MaxMemory s.Memory>
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/HighLevelRASL-GenResult-Opt.ref
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ CreateElemParam {

GenPushLink {
e.MarkedResult
= <MapReduce
= <MapAccum
{
(e.Stack) (TkOpenCall s.Offset) = (e.Stack s.Offset);
(e.Stack) (TkOpenADT s.Offset) = (e.Stack s.Offset);
Expand Down Expand Up @@ -359,7 +359,7 @@ AddOffsets {
для копии (+1 для s-переменных, +2 для t и e),
для остальных элементов --- смещение s.ContextOffset.
*/
<MapReduce
<MapAccum
{
s.Offset (Tile e.Tile) =
s.Offset
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/LowLevelRASL-RASL.ref
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ $INCLUDE "LibraryEx";
$ENTRY LowLevelRASL-RASL {
s.DebugInfo s.Hash1 s.Hash2 (t.FuncTable t.IdentTable) e.Items

= <MapReduce
= <MapAccum
&ClassifyItems
(/* Области видимости функций */)
e.Items
>
: (e.FuncScopeClass) e.Definitions

= <MapReduce (&PrepareFunctionsRASL s.DebugInfo) 0 e.Definitions>
= <MapAccum (&PrepareFunctionsRASL s.DebugInfo) 0 e.Definitions>
: s.MaxLabel e.Definitions^

= (
Expand Down Expand Up @@ -130,7 +130,7 @@ RemoveDebugInfoRec {

ConvertInterpretCommands {
s.NextLabel e.Commands
= <MapReduce &ConvertOneInterpretCommand s.NextLabel e.Commands>;
= <MapAccum &ConvertOneInterpretCommand s.NextLabel e.Commands>;
}

ConvertOneInterpretCommand-Simple {
Expand Down Expand Up @@ -180,7 +180,7 @@ ConvertOneInterpretCommand {

AddBacktrackStackAllocationCommand {
e.Commands
= <MapReduce
= <MapAccum
{
s.Depth (CmdEStart e.VarInfo) =
<Inc s.Depth> (CmdEStart e.VarInfo);
Expand Down Expand Up @@ -235,7 +235,7 @@ PrepareCommonRASL {

GlueFunctionRASLs {
e.Definitions
= <MapReduce
= <MapAccum
{
(e.All-RASL-Commands)
(CmdInterpretFuncDescr
Expand All @@ -254,7 +254,7 @@ GlueFunctionRASLs {

SetFunctionsScopeClass {
(e.FuncScopeClass) e.Functions
= <MapReduce
= <MapAccum
{
(e.Decls-B (s.ScopeClass e.FuncName) e.Decls-E)
(s.FuncId e.FuncName)
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/LowLevelRASL.ref
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $EXTERN DisplayName;
$ENTRY LowLevelRASL {
s.GenMode s.DebugInfo (e.SrcName) e.ProgramElements

= <MapReduce
= <MapAccum
&CalcDigest
/* Числа выбраны случайно: hexdump /dev/urandom */
(4001567069 291363191)
Expand All @@ -37,7 +37,7 @@ $ENTRY LowLevelRASL {

= <SelectConstantsOutliner e.Items> : s.OutlineConstants e.Items^

= <MapReduce
= <MapAccum
s.OutlineConstants
((0 /* functions */) (0 /* idents */))
e.Items
Expand Down Expand Up @@ -212,7 +212,7 @@ OutlineConstants-RASLOnly {

OutlineConstants-Commands {
t.Tables e.Commands
= <MapReduce &OutlineConstants-OneCommand t.Tables e.Commands>;
= <MapAccum &OutlineConstants-OneCommand t.Tables e.Commands>;
}

OutlineConstants-OneCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/OptTree.ref
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ OptResult {

OptResultRec {
(e.OptimizableFunctions) s.Temp e.Result
= <MapReduce (&OptResultTerm e.OptimizableFunctions) s.Temp e.Result>;
= <MapAccum (&OptResultTerm e.OptimizableFunctions) s.Temp e.Result>;
}

OptResultTerm {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/ParseCmdLine.ref
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ $ENTRY ParseCommandLine {
(e.Errors) e.Options
= (<Config-Create> e.Errors) e.Options;
}
(&MapReduce
(&MapAccum
{
(t.Config e.Errors) (CppCompiler-Exe s.Num e.CppCompiler)
= <Update
Expand Down Expand Up @@ -249,7 +249,7 @@ $ENTRY ParseCommandLine {
= (t.Config e.Errors) t.Option;
}
)
(&MapReduce
(&MapAccum
{
(t.Config e.Errors) (SearchFolder s.Num e.Folder)
= (<Config-SetSearchFolder t.Config e.Folder> e.Errors);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/SR-Lexer.sref
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ NormalizeTokens {
e.Tokens
<Pipe
(Map NormalizeToken)
(MapReduce AddLineNumber 1)
(MapAccum AddLineNumber 1)
DelAccumulator
CollectNativeLines
>
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/main.ref
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ RenameLocations {
RenameLocations-Aux {
t.Config s.InitNumber e.Locations
= <Config-GetOverwriteExistRasls t.Config> : s.Overwrite
= <MapReduce
= <MapAccum
{
s.Num (s.Pos Source (s.Dialect e.Source) e.Output '.rasl')
, s.Overwrite : False
Expand Down
4 changes: 2 additions & 2 deletions src/lexgen/DFA-Compiler.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*$FROM LibraryEx
$EXTERN Fetch, Pipe, MapReduce, Map, Reduce;
$EXTERN Fetch, Pipe, MapAccum, Map, Reduce;

*$FROM Error
$EXTERN ErrorAt, WarningAt;
Expand Down Expand Up @@ -297,7 +297,7 @@ NormalizeRule {
<Fetch
e.Alternatives
<Pipe
(&MapReduce
(&MapAccum
&NormalizeAlternative
(EOF-NotCatched)
)
Expand Down
Loading

0 comments on commit f2c2f94

Please sign in to comment.