Play

Check-in [7eff2f2dbd]
Login
Overview
Comment:Turn tuple into record in preperation of registering words which requires loading additional modules.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: 7eff2f2dbd7a8422a3897496d5cfec680fcdcc53fcee5e8c0cf6bde11a50ecea
User & Date: robin.hansen on 2021-02-09 11:27:51
Other Links: branch diff | manifest | tags
Context
2021-02-10
11:03
Can now resolve package references in simple word definitions. check-in: 6416ab78b9 user: robin.hansen tags: modules
2021-02-09
11:27
Turn tuple into record in preperation of registering words which requires loading additional modules... check-in: 7eff2f2dbd user: robin.hansen tags: modules
09:40
Prepare data structures and add test for returning modules to load from qualifier step. check-in: a7c9bebc32 user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Qualifier.elm from [caaf815568] to [98de1e5664].

489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505














506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582

583
584
585
586
587
588

589

590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606


607
608
609
610
611
612
613
initQualifyNode :
    String
    -> RunConfig
    -> Dict String WordDefinition
    -> List Parser.AstNode
    -> ( Dict String WordDefinition, Result Problem (List Node) )
initQualifyNode currentDefName config qualifiedWords impl =
    List.foldr (qualifyNode config currentDefName) ( 1, qualifiedWords, [] ) impl
        |> (\( _, newQualifiedWords, errors ) -> ( newQualifiedWords, Result.combine errors ))


qualifyNode :
    RunConfig
    -> String
    -> Parser.AstNode
    -> ( Int, Dict String WordDefinition, List (Result Problem Node) )
    -> ( Int, Dict String WordDefinition, List (Result Problem Node) )














qualifyNode config currentDefName node ( availableQuoteId, qualifiedWords, qualifiedNodes ) =
    case node of
        Parser.Integer loc value ->
            ( availableQuoteId
            , qualifiedWords
            , Ok (Integer loc value) :: qualifiedNodes
            )

        Parser.Word loc value ->
            let
                qualifiedName =
                    qualifyName config value
            in
            if Dict.member value config.ast.words then
                ( availableQuoteId
                , qualifiedWords
                , Ok (Word loc qualifiedName) :: qualifiedNodes
                )

            else
                case Dict.get value builtinDict of
                    Just builtin ->
                        ( availableQuoteId
                        , qualifiedWords
                        , Ok (Builtin loc builtin) :: qualifiedNodes
                        )

                    Nothing ->
                        ( availableQuoteId
                        , qualifiedWords
                        , Err (UnknownWordRef loc value) :: qualifiedNodes
                        )

        Parser.PackageWord loc path value ->
            qualifyNode config currentDefName (Parser.Word loc value) ( availableQuoteId, qualifiedWords, qualifiedNodes )

        Parser.ExternalWord loc path value ->
            qualifyNode config currentDefName (Parser.Word loc value) ( availableQuoteId, qualifiedWords, qualifiedNodes )

        Parser.ConstructType typeName ->
            ( availableQuoteId
            , qualifiedWords
            , Ok (ConstructType (qualifyName config typeName)) :: qualifiedNodes
            )

        Parser.SetMember typeName memberName ->
            ( availableQuoteId
            , qualifiedWords
            , Ok (SetMember (qualifyName config typeName) memberName) :: qualifiedNodes
            )

        Parser.GetMember typeName memberName ->
            ( availableQuoteId
            , qualifiedWords
            , Ok (GetMember (qualifyName config typeName) memberName) :: qualifiedNodes
            )

        Parser.Quotation sourceLocation quotImpl ->
            let
                quoteName =
                    if String.startsWith "quote:" currentDefName then
                        currentDefName ++ "/" ++ String.fromInt availableQuoteId

                    else
                        "quote:" ++ qualifyName config currentDefName ++ "/" ++ String.fromInt availableQuoteId

                ( newWordsAfterQuot, qualifiedQuotImplResult ) =
                    initQualifyNode quoteName config qualifiedWords quotImpl
            in
            case qualifiedQuotImplResult of
                Ok [ Word _ wordRef ] ->
                    case Dict.get wordRef newWordsAfterQuot of
                        Nothing ->
                            Debug.todo "Cannot happen"

                        Just oldWord ->
                            ( availableQuoteId

                            , Dict.insert wordRef
                                { oldWord | metadata = Metadata.isQuoted oldWord.metadata }
                                newWordsAfterQuot
                            , Ok (WordRef sourceLocation wordRef) :: qualifiedNodes
                            )


                Ok qualifiedQuotImpl ->

                    ( availableQuoteId + 1

                    , Dict.insert quoteName
                        { name = quoteName
                        , metadata =
                            Metadata.default
                                |> Metadata.isQuoted
                        , implementation = SoloImpl qualifiedQuotImpl
                        }
                        newWordsAfterQuot
                    , Ok (WordRef sourceLocation quoteName) :: qualifiedNodes
                    )

                Err err ->
                    ( availableQuoteId
                    , qualifiedWords
                    , Err err :: qualifiedNodes
                    )




typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of
        CustomTypeDef name _ _ _ ->
            name







|
|


|
|
<
<
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


<
<
|
<







<
<
|
<




<
<
|
|
<

<
<
|
|
<

|


|


<
<
|
|
<

<
<
|
|
<

<
<
|
<





|


|


|








|
>
|
|
|
|
<
|
>

>
|
>
|
|
|
|
|
|
|
|
|
<
|
<
<
<
<
|
>
>







489
490
491
492
493
494
495
496
497
498
499
500
501


502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520


521

522
523
524
525
526
527
528


529

530
531
532
533


534
535

536


537
538

539
540
541
542
543
544
545


546
547

548


549
550

551


552

553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

594




595
596
597
598
599
600
601
602
603
604
initQualifyNode :
    String
    -> RunConfig
    -> Dict String WordDefinition
    -> List Parser.AstNode
    -> ( Dict String WordDefinition, Result Problem (List Node) )
initQualifyNode currentDefName config qualifiedWords impl =
    List.foldr (qualifyNode config currentDefName) (initQualifyNodeAccumulator qualifiedWords) impl
        |> (\acc -> ( acc.qualifiedWords, Result.combine acc.qualifiedNodes ))


type alias QualifyNodeAccumulator =
    { availableQuoteId : Int


    , qualifiedWords : Dict String WordDefinition
    , qualifiedNodes : List (Result Problem Node)
    , externalWords : List ( List String, String )
    }


initQualifyNodeAccumulator : Dict String WordDefinition -> QualifyNodeAccumulator
initQualifyNodeAccumulator qualifiedWords =
    { availableQuoteId = 1
    , qualifiedWords = qualifiedWords
    , qualifiedNodes = []
    , externalWords = []
    }


qualifyNode : RunConfig -> String -> Parser.AstNode -> QualifyNodeAccumulator -> QualifyNodeAccumulator
qualifyNode config currentDefName node acc =
    case node of
        Parser.Integer loc value ->


            { acc | qualifiedNodes = Ok (Integer loc value) :: acc.qualifiedNodes }


        Parser.Word loc value ->
            let
                qualifiedName =
                    qualifyName config value
            in
            if Dict.member value config.ast.words then


                { acc | qualifiedNodes = Ok (Word loc qualifiedName) :: acc.qualifiedNodes }


            else
                case Dict.get value builtinDict of
                    Just builtin ->


                        { acc | qualifiedNodes = Ok (Builtin loc builtin) :: acc.qualifiedNodes }


                    Nothing ->


                        { acc | qualifiedNodes = Err (UnknownWordRef loc value) :: acc.qualifiedNodes }


        Parser.PackageWord loc path value ->
            qualifyNode config currentDefName (Parser.Word loc value) acc

        Parser.ExternalWord loc path value ->
            qualifyNode config currentDefName (Parser.Word loc value) acc

        Parser.ConstructType typeName ->


            { acc | qualifiedNodes = Ok (ConstructType (qualifyName config typeName)) :: acc.qualifiedNodes }


        Parser.SetMember typeName memberName ->


            { acc | qualifiedNodes = Ok (SetMember (qualifyName config typeName) memberName) :: acc.qualifiedNodes }


        Parser.GetMember typeName memberName ->


            { acc | qualifiedNodes = Ok (GetMember (qualifyName config typeName) memberName) :: acc.qualifiedNodes }


        Parser.Quotation sourceLocation quotImpl ->
            let
                quoteName =
                    if String.startsWith "quote:" currentDefName then
                        currentDefName ++ "/" ++ String.fromInt acc.availableQuoteId

                    else
                        "quote:" ++ qualifyName config currentDefName ++ "/" ++ String.fromInt acc.availableQuoteId

                ( newWordsAfterQuot, qualifiedQuotImplResult ) =
                    initQualifyNode quoteName config acc.qualifiedWords quotImpl
            in
            case qualifiedQuotImplResult of
                Ok [ Word _ wordRef ] ->
                    case Dict.get wordRef newWordsAfterQuot of
                        Nothing ->
                            Debug.todo "Cannot happen"

                        Just oldWord ->
                            { acc
                                | qualifiedWords =
                                    Dict.insert wordRef
                                        { oldWord | metadata = Metadata.isQuoted oldWord.metadata }
                                        newWordsAfterQuot
                                , qualifiedNodes = Ok (WordRef sourceLocation wordRef) :: acc.qualifiedNodes

                            }

                Ok qualifiedQuotImpl ->
                    { acc
                        | availableQuoteId = acc.availableQuoteId + 1
                        , qualifiedWords =
                            Dict.insert quoteName
                                { name = quoteName
                                , metadata =
                                    Metadata.default
                                        |> Metadata.isQuoted
                                , implementation = SoloImpl qualifiedQuotImpl
                                }
                                newWordsAfterQuot
                        , qualifiedNodes = Ok (WordRef sourceLocation quoteName) :: acc.qualifiedNodes

                    }





                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }


typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of
        CustomTypeDef name _ _ _ ->
            name