From 050e329f2a2e2367c2e4f1965190b0f6a5addf29 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 4 Sep 2021 22:26:09 +0200 Subject: The blackjack example works again. --- data/examples/blackjack/cards.fate | 14 +- data/examples/blackjack/global.fate | 10 + data/examples/blackjack/play.fate | 32 +- data/unit-testing/access.fate | 2 +- data/unit-testing/access_constant_index.fate | 4 +- data/unit-testing/add_element.fate | 90 ++-- data/unit-testing/add_element_at.fate | 34 +- data/unit-testing/add_elements_of.fate | 32 +- data/unit-testing/cons_car_cdr.fate | 4 +- data/unit-testing/count.fate | 68 +-- data/unit-testing/field_access.fate | 4 +- data/unit-testing/filter.fate | 30 +- data/unit-testing/fold.fate | 10 +- data/unit-testing/ifelse.fate | 4 +- data/unit-testing/map.fate | 16 +- data/unit-testing/merge.fate | 571 ++++----------------- data/unit-testing/ptr_and_at.fate | 4 +- src/core/src/tonkadur/Main.java | 7 +- src/core/src/tonkadur/TonkadurPlugin.java | 11 - src/core/src/tonkadur/fate/v1/lang/Variable.java | 6 + src/core/src/tonkadur/fate/v1/lang/World.java | 3 + .../fate/v1/lang/computation/AmbiguousWord.java | 5 + .../fate/v1/lang/computation/generic/Access.java | 16 +- .../computation/generic/AddElementComputation.java | 52 +- .../computation/generic/BooleanComputation.java | 59 +++ .../lang/computation/generic/ConsComputation.java | 4 +- .../generic/IndexedSafeMergeComputation.java | 9 - .../v1/lang/computation/generic/Operation.java | 3 + .../v1/lang/instruction/GenericInstruction.java | 2 - .../tonkadur/fate/v1/lang/meta/Computation.java | 6 + .../fate/v1/lang/meta/VariableFromWord.java | 36 +- .../tonkadur/fate/v1/lang/type/CollectionType.java | 34 +- .../src/tonkadur/fate/v1/lang/type/ConsType.java | 45 +- .../tonkadur/fate/v1/lang/type/DictionaryType.java | 78 ++- .../src/tonkadur/fate/v1/lang/type/ExtraType.java | 25 +- .../src/tonkadur/fate/v1/lang/type/FutureType.java | 15 +- .../src/tonkadur/fate/v1/lang/type/LambdaType.java | 17 +- .../tonkadur/fate/v1/lang/type/PointerType.java | 43 +- .../tonkadur/fate/v1/lang/type/SequenceType.java | 6 +- .../src/tonkadur/fate/v1/lang/type/StructType.java | 6 +- src/core/src/tonkadur/fate/v1/lang/type/Type.java | 6 +- src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 | 4 +- src/core/src/tonkadur/fate/v1/parser/FateParser.g4 | 85 ++- .../src/tonkadur/fate/v1/parser/ParserData.java | 2 +- src/core/src/tonkadur/parser/Context.java | 7 +- src/core/src/tonkadur/parser/Location.java | 11 +- 46 files changed, 792 insertions(+), 740 deletions(-) create mode 100644 src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java diff --git a/data/examples/blackjack/cards.fate b/data/examples/blackjack/cards.fate index 6868650..7245436 100644 --- a/data/examples/blackjack/cards.fate +++ b/data/examples/blackjack/cards.fate @@ -10,13 +10,13 @@ (set! card_generator (lambda ( (string family) ) - (map + (list:map (lambda ( (int number) (string family) ) - (set_fields (default card) + (struct:set_fields (default card) (number (var number)) (name (text @@ -33,7 +33,7 @@ (score (clamp 1 number 10)) ) ) - (range 1 13 1) + (list:range 1 13 1) (var family) ) ) @@ -41,10 +41,10 @@ (global (list card) deck_template) -(add_all! (eval card_generator Hearts) deck_template) -(add_all! (eval card_generator Spades) deck_template) -(add_all! (eval card_generator Diamonds) deck_template) -(add_all! (eval card_generator Clubs) deck_template) +(list:add_all! (eval card_generator Hearts) deck_template) +(list:add_all! (eval card_generator Spades) deck_template) +(list:add_all! (eval card_generator Diamonds) deck_template) +(list:add_all! (eval card_generator Clubs) deck_template) (define_sequence compute_score (((ptr (list card)) deck) ((ptr int) result)) (local int aces_count) diff --git a/data/examples/blackjack/global.fate b/data/examples/blackjack/global.fate index d08706b..acf054e 100644 --- a/data/examples/blackjack/global.fate +++ b/data/examples/blackjack/global.fate @@ -15,8 +15,12 @@ ) ) +(global int marker_0) + (declare_text_effect action_description) +(global int marker_1) + (define_sequence money_acquisition ((int amount)) (set! player.money (+ player.money amount)) (if (> amount 0) @@ -26,6 +30,8 @@ ) ) +(global int marker_2) + (define_sequence money_loss ((int amount)) (set! player.money (- player.money amount)) (if (> amount 0) @@ -35,4 +41,8 @@ ) ) +(global int marker_3) + (declare_input_event escape) + +(global int marker_4) diff --git a/data/examples/blackjack/play.fate b/data/examples/blackjack/play.fate index c914b8f..fd4d65c 100644 --- a/data/examples/blackjack/play.fate +++ b/data/examples/blackjack/play.fate @@ -38,26 +38,26 @@ (newline) - (set! current_deck (shuffle deck_template)) + (set! current_deck (list:shuffle deck_template)) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) player.hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) player.hand) (text_effect action_description You have been dealt the (var new_card.name). (newline) ) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) dealer_hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) dealer_hand) (text_effect action_description The dealer has drawn the (var new_card.name). (newline) ) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) player.hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) player.hand) (text_effect action_description You have been dealt the (var new_card.name). @@ -66,8 +66,8 @@ (newline) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) dealer_hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) dealer_hand) (text_effect action_description The dealer has drawn a card, face down. @@ -76,8 +76,8 @@ (visit! initial_draw) - (clear! dealer_hand) - (clear! player.hand) + (list:clear! dealer_hand) + (list:clear! player.hand) (newline) Interesting. Would you like to go again? @@ -177,8 +177,8 @@ (local card new_card) (local int player_score) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) player.hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) player.hand) (visit! compute_score (ptr player.hand) (ptr player_score)) @@ -207,7 +207,7 @@ A bust! What a shame... (newline) (visit! money_loss (var bet)) - (done) + (done!) ) (if (var has_doubled) @@ -253,8 +253,8 @@ (while (< dealer_score 17) (local card new_card) - (pop_left! current_deck (ptr new_card)) - (add! (var new_card) dealer_hand) + (list:pop_left! current_deck new_card) + (list:add! (var new_card) dealer_hand) (text_effect action_description The dealer has drawn the (var new_card.name). diff --git a/data/unit-testing/access.fate b/data/unit-testing/access.fate index e665b69..6079d7d 100644 --- a/data/unit-testing/access.fate +++ b/data/unit-testing/access.fate @@ -3,7 +3,7 @@ (global (list int) li) (global (ptr (list int)) li_ptr) -(set! li (range 0 10 1)) +(set! li (list:range 0 10 1)) (set! li_ptr (ptr li)) (global int i) diff --git a/data/unit-testing/access_constant_index.fate b/data/unit-testing/access_constant_index.fate index be3c3fa..74bf705 100644 --- a/data/unit-testing/access_constant_index.fate +++ b/data/unit-testing/access_constant_index.fate @@ -7,7 +7,7 @@ (global (list int) li) (global (ptr (list int)) li_ptr) -(set! li (range 0 10 1)) +(set! li (list:range 0 10 1)) (set! li_ptr (ptr li)) (assert! (= (var li.0) 0) [FAILED] (var test_name) li.0) @@ -38,7 +38,7 @@ (global int i) (for (set! i 0) (=< i 10) (set! i (+ i 1)) - (add! (range 0 i 1) lili) + (add! (list:range 0 i 1) lili) ) (assert! (= (var lili.10.0) 0) [FAILED] (var test_name) lili.10.0 was (var lili.10.0).) diff --git a/data/unit-testing/add_element.fate b/data/unit-testing/add_element.fate index 299256f..e33d2a4 100644 --- a/data/unit-testing/add_element.fate +++ b/data/unit-testing/add_element.fate @@ -7,19 +7,19 @@ (global (list int) li0) (global (list int) li1) -(set! li0 (add_element -1 li0)) -(set! li0 (add_element 0 li0)) -(set! li0 (add_element 1 li0)) -(set! li0 (add_element 2 li0)) -(set! li0 (add_element 3 4 5 li0)) -(set! li0 (add_element 6 li0)) - -(add_element! -1 li1) -(add_element! 0 li1) -(add_element! 1 li1) -(add_element! 2 3 4 li1) -(add_element! 5 li1) -(add_element! 6 li1) +(set! li0 (list:add_element -1 li0)) +(set! li0 (list:add_element 0 li0)) +(set! li0 (list:add_element 1 li0)) +(set! li0 (list:add_element 2 li0)) +(set! li0 (list:add_element 3 4 5 li0)) +(set! li0 (list:add_element 6 li0)) + +(list:add_element! -1 li1) +(list:add_element! 0 li1) +(list:add_element! 1 li1) +(list:add_element! 2 3 4 li1) +(list:add_element! 5 li1) +(list:add_element! 6 li1) (assert! (= (var li0) (var li1)) [FAILED] (var test_name) equality.) @@ -35,14 +35,14 @@ (global (list int) ali0) (global (list int) ali1) -(set! ali0 (add_element 6 (range -1 5 1))) +(set! ali0 (list:add_element 6 (list:range -1 5 1))) (set! ali1 - (add_element 6 - (add_element 5 - (add_element 4 - (add_element 1 2 3 - (add_element 0 - (add_element -1 ali1) + (list:add_element 6 + (list:add_element 5 + (list:add_element 4 + (list:add_element 1 2 3 + (list:add_element 0 + (list:add_element -1 ali1) ) ) ) @@ -58,35 +58,35 @@ (set! si_ptr (ptr si1)) -(set! si0 (add_element 6 si0)) -(set! si0 (add_element 0 si0)) -(set! si0 (add_element 1 4 -1 si0)) -(set! si0 (add_element 5 si0)) -(set! si0 (add_element 3 si0)) -(set! si0 (add_element 2 si0)) +(set! si0 (set:add_element 6 si0)) +(set! si0 (set:add_element 0 si0)) +(set! si0 (set:add_element 1 4 -1 si0)) +(set! si0 (set:add_element 5 si0)) +(set! si0 (set:add_element 3 si0)) +(set! si0 (set:add_element 2 si0)) -(add_element! 4 si1) -(add_element! 0 (at (ptr si1))) -(add_element! 3 -1 2 si1) -(add_element! 6 si1) -(add_element! 1 (at si_ptr)) -(add_element! 5 si1) +(set:add_element! 4 si1) +(set:add_element! 0 (at (ptr si1))) +(set:add_element! 3 -1 2 si1) +(set:add_element! 6 si1) +(set:add_element! 1 (at si_ptr)) +(set:add_element! 5 si1) (assert! (= (var li0) (var li1) (var ali0) (var ali1) (var si0) (var si1)) [FAILED] (var test_name) equality 3.) -(set! si0 (add_element 0 si0)) -(set! si0 (add_element 4 si0)) -(set! si0 (add_element 6 5 3 si0)) -(set! si0 (add_element -1 si0)) -(set! si0 (add_element 2 si0)) -(set! si0 (add_element 1 si0)) - -(add_element! 4 si1) -(add_element! 1 0 6 si1) -(add_element! -1 si1) -(add_element! 3 si1) -(add_element! 2 si1) -(add_element! 5 si1) +(set! si0 (set:add_element 0 si0)) +(set! si0 (set:add_element 4 si0)) +(set! si0 (set:add_element 6 5 3 si0)) +(set! si0 (set:add_element -1 si0)) +(set! si0 (set:add_element 2 si0)) +(set! si0 (set:add_element 1 si0)) + +(set:add_element! 4 si1) +(set:add_element! 1 0 6 si1) +(set:add_element! -1 si1) +(set:add_element! 3 si1) +(set:add_element! 2 si1) +(set:add_element! 5 si1) (assert! (= (var li0) (var li1) (var ali0) (var ali1) (var si0) (var si1)) [FAILED] (var test_name) equality 4.) diff --git a/data/unit-testing/add_element_at.fate b/data/unit-testing/add_element_at.fate index a3f73fe..89708eb 100644 --- a/data/unit-testing/add_element_at.fate +++ b/data/unit-testing/add_element_at.fate @@ -7,23 +7,23 @@ (global (list int) li0) (global (list int) li1) -(set! li0 (add_element_at 0 0 li0)) -(set! li0 (add_element_at 1 1 li0)) -(set! li0 (add_element_at 2 2 li0)) -(set! li0 (add_element_at 0 -1 li0)) -(set! li0 (add_element_at 0 -3 li0)) -(set! li0 (add_element_at 1 -2 li0)) -(set! li0 (add_element_at 44 3 li0)) -(set! li0 (add_element_at -44 -4 li0)) - -(add_element_at! 0 0 li1) -(add_element_at! 1 1 li1) -(add_element_at! 2 2 li1) -(add_element_at! 0 -1 li1) -(add_element_at! 0 -3 li1) -(add_element_at! 1 -2 li1) -(add_element_at! 44 3 li1) -(add_element_at! -44 -4 li1) +(set! li0 (list:add_element_at 0 0 li0)) +(set! li0 (list:add_element_at 1 1 li0)) +(set! li0 (list:add_element_at 2 2 li0)) +(set! li0 (list:add_element_at 0 -1 li0)) +(set! li0 (list:add_element_at 0 -3 li0)) +(set! li0 (list:add_element_at 1 -2 li0)) +(set! li0 (list:add_element_at 44 3 li0)) +(set! li0 (list:add_element_at -44 -4 li0)) + +(list:add_element_at! 0 0 li1) +(list:add_element_at! 1 1 li1) +(list:add_element_at! 2 2 li1) +(list:add_element_at! 0 -1 li1) +(list:add_element_at! 0 -3 li1) +(list:add_element_at! 1 -2 li1) +(list:add_element_at! 44 3 li1) +(list:add_element_at! -44 -4 li1) (assert! (= (var li0) (var li1)) [FAILED] (var test_name) equality.) diff --git a/data/unit-testing/add_elements_of.fate b/data/unit-testing/add_elements_of.fate index fb47a38..190929a 100644 --- a/data/unit-testing/add_elements_of.fate +++ b/data/unit-testing/add_elements_of.fate @@ -8,18 +8,18 @@ (global (list int) li1) (set! li0 - (add_all (range 8 10 1) - (add_all (range 4 7 1) - (add_all (range 0 3 1) + (list:add_all (list:range 8 10 1) + (list:add_all (list:range 4 7 1) + (list:add_all (list:range 0 3 1) (default (list int)) ) ) ) ) -(add_all! (range 0 3 1) li1) -(add_all! (range 4 7 1) (at (ptr li1))) -(add_all! (range 8 10 1) li1) +(list:add_all! (list:range 0 3 1) li1) +(list:add_all! (list:range 4 7 1) (at (ptr li1))) +(list:add_all! (list:range 8 10 1) li1) (assert! (= (var li0) (var li1)) [FAILED] (var test_name) equality.) @@ -32,17 +32,17 @@ (assert! (= (var li0.6) (var li1.6) 6) [FAILED] (var test_name) at 6: (var li0.6), (var li1.6).) (assert! (= (var li0.7) (var li1.7) 7) [FAILED] (var test_name) at 7: (var li0.7), (var li1.7).) -(add_all! (range 11 20 1) li0) -(add_all! (range 11 20 1) li1) +(list:add_all! (list:range 11 20 1) li0) +(list:add_all! (list:range 11 20 1) li1) (global (set int) si0) (global (set int) si1) (set! si0 - (add_all (range 0 10 2) - (add_all (range 11 20 2) - (add_all (range 1 10 2) - (add_all (range 12 20 2) + (set:add_all (list:range 0 10 2) + (set:add_all (list:range 11 20 2) + (set:add_all (list:range 1 10 2) + (set:add_all (list:range 12 20 2) (default (set int)) ) ) @@ -50,10 +50,10 @@ ) ) -(add_all! (range 0 10 2) si1) -(add_all! (range 11 20 2) (at (ptr si1))) -(add_all! (range 1 10 2) si1) -(add_all! (range 12 20 2) si1) +(set:add_all! (list:range 0 10 2) si1) +(set:add_all! (list:range 11 20 2) (at (ptr si1))) +(set:add_all! (list:range 1 10 2) si1) +(set:add_all! (list:range 12 20 2) si1) (assert! (= (var li0) (var li1) (var si0) (var si1)) [FAILED] (var test_name) equality 2.) diff --git a/data/unit-testing/cons_car_cdr.fate b/data/unit-testing/cons_car_cdr.fate index a555cc0..885e4e4 100644 --- a/data/unit-testing/cons_car_cdr.fate +++ b/data/unit-testing/cons_car_cdr.fate @@ -28,7 +28,7 @@ (cdr (cdr (cdr (cdr (cons 1 (cons 2 (cons 3 (cons 4 5)))))))). ) -(assert! (= (car (cons test 0)) test) +(assert! (= (car (cons test 0)) (string test)) [FAILED] (var test_name) test string: (car (cons test 0)) ) @@ -39,7 +39,7 @@ (set! cfs (cons 3.14 pi)) (assert! (= (car cfs) 3.14) [FAILED] (var test_name) test 3.14: (car cfs).) -(assert! (= (cdr cfs) pi) [FAILED] (var test_name) test pi: (cdr cfs).) +(assert! (= (cdr cfs) (string pi)) [FAILED] (var test_name) test pi: (cdr cfs).) (set! cfs2 (cons (car cfs) (cdr cfs))) diff --git a/data/unit-testing/count.fate b/data/unit-testing/count.fate index 2c54998..05a8c59 100644 --- a/data/unit-testing/count.fate +++ b/data/unit-testing/count.fate @@ -4,57 +4,57 @@ (set! test_name ( COUNT )) -(assert! (= (count 10 (range 0 60 1)) 1) - [FAILED] (var test_name) Failed to find 10 in range 0 60 1. +(assert! (= (list:count 10 (list:range 0 60 1)) 1) + [FAILED] (var test_name) Failed to find 10 in list:range 0 60 1. ) (global (list int) li) -(add_all! (range 0 10 1) li) -(add_all! (range 0 10 1) li) -(add_all! (range 0 10 1) li) -(add_all! (range 0 10 1) li) +(list:add_all! (list:range 0 10 1) li) +(list:add_all! (list:range 0 10 1) li) +(list:add_all! (list:range 0 10 1) li) +(list:add_all! (list:range 0 10 1) li) -(assert! (= (count 10 li) 4) +(assert! (= (list:count 10 li) 4) [FAILED] (var test_name) Failed to find 10 four times in li. ) (global (set int) si) -(add_all! (range 0 10 1) si) -(add_all! (range 0 10 1) si) -(add_all! (range 0 10 1) si) -(add_all! (range 0 10 1) si) +(list:add_all! (list:range 0 10 1) si) +(list:add_all! (list:range 0 10 1) si) +(list:add_all! (list:range 0 10 1) si) +(list:add_all! (list:range 0 10 1) si) -(assert! (= (count 10 si) 1) +(assert! (= (set:count 10 si) 1) [FAILED] (var test_name) Failed to find 10 exactly once in si. ) (global (list string) ls) -(add! test0 ls) -(add! test1 ls) -(add! test2 ls) -(add! test3 ls) +(list:add! test0 ls) +(list:add! test1 ls) +(list:add! test2 ls) +(list:add! test3 ls) -(assert! (= (count test0 ls) 1) +(assert! (= (list:count test0 ls) 1) [FAILED] (var test_name) Failed to find test0 exactly once in ls. ) -(add! test0 ls) -(add! test1 ls) -(add! test2 ls) -(add! test3 ls) -(add! test0 ls) -(add! test1 ls) -(add! test2 ls) -(add! test3 ls) -(add! test0 ls) -(add! test1 ls) -(add! test2 ls) -(add! test3 ls) - -(assert! (= (count test0 ls) 4) +(list:add! test0 ls) +(list:add! test1 ls) +(list:add! test2 ls) +(list:add! test3 ls) +(list:add! test0 ls) +(list:add! test1 ls) +(list:add! test2 ls) +(list:add! test3 ls) +(list:add! test0 ls) +(list:add! test1 ls) +(list:add! test2 ls) +(list:add! test3 ls) + +(assert! (= (list:count test0 ls) 4) [FAILED] (var test_name) Failed to find test0 four times in ls. ) @@ -62,14 +62,14 @@ (local int i) (for (set! i 0) (=< i 10) (set! i (+ i 1)) - (add! (= (mod i 2) 0) lb) + (list:add! (= (mod i 2) 0) lb) ) -(assert! (= (count (true) lb) 6) +(assert! (= (list:count (true) lb) 6) [FAILED] (var test_name) Failed to find six even numbers. ) -(assert! (= (count (false) lb) 5) +(assert! (= (list:count (false) lb) 5) [FAILED] (var test_name) Failed to find four odd numbers. ) diff --git a/data/unit-testing/field_access.fate b/data/unit-testing/field_access.fate index eaedc3a..d9d582a 100644 --- a/data/unit-testing/field_access.fate +++ b/data/unit-testing/field_access.fate @@ -34,7 +34,7 @@ (i 42) (j 69) (k 420) - (li (range 0 10 1)) + (li (list:range 0 10 1)) ) (set_fields! ts0_1 @@ -44,7 +44,7 @@ (k 42) (j 69) (i 420) - (li (range 11 20 1)) + (li (list:range 11 20 1)) ) (set_fields! ts1_0 diff --git a/data/unit-testing/filter.fate b/data/unit-testing/filter.fate index 7fc1ea8..ce202e7 100644 --- a/data/unit-testing/filter.fate +++ b/data/unit-testing/filter.fate @@ -8,10 +8,10 @@ (global (list int) 0to10odd) (global (list int) 0to10even) -(set! 0to10 (range 0 10 1)) +(set! 0to10 (list:range 0 10 1)) (set! 0to10odd - (filter + (list:filter (lambda ((int i) (int two) (int one)) (= (mod i two) (var one))) 0to10 2 @@ -21,9 +21,11 @@ (local (lambda bool (int)) filter_fun) +(global (list int) 0to10evena) (set! filter_fun (lambda ((int i)) (= (mod i 2) 0))) +(global (list int) 0to10eveno) (set! 0to10even - (filter filter_fun 0to10) + (list:filter filter_fun 0to10) ) (assert! @@ -87,14 +89,14 @@ (set! 0to10odd2 (var 0to10)) (set! 0to10even2 (var 0to10)) -(filter! +(list:filter! (lambda ((int i) (int two) (int one)) (= (mod i two) (var one))) 0to10odd2 2 1 ) -(filter! filter_fun 0to10even2) +(list:filter! filter_fun 0to10even2) (assert! (= 0 (var 0to10even2.0)) @@ -152,7 +154,7 @@ ) (set! 0to10odd - (indexed_filter + (list:indexed_filter (lambda ((int ix) (int i) (int two) (int one)) (= (mod i two) (var one))) 0to10 2 @@ -163,7 +165,7 @@ (local (lambda bool (int int)) indexed_filter_fun) (set! indexed_filter_fun (lambda ((int ix) (int i)) (= (mod i 2) 0))) -(set! 0to10even (indexed_filter indexed_filter_fun 0to10)) +(set! 0to10even (list:indexed_filter indexed_filter_fun 0to10)) (assert! (= 0 (var 0to10even.0)) @@ -223,14 +225,14 @@ (set! 0to10odd2 (var 0to10)) (set! 0to10even2 (var 0to10)) -(indexed_filter! +(list:indexed_filter! (lambda ((int ix) (int i) (int two) (int one)) (= (mod i two) (var one))) 0to10odd2 2 1 ) -(indexed_filter! indexed_filter_fun 0to10even2) +(list:indexed_filter! indexed_filter_fun 0to10even2) (assert! (= 0 (var 0to10even2.0)) @@ -290,11 +292,11 @@ (global (list int) oli0) (global (list int) oli1) -(set! oli0 (range -10 10 1)) +(set! oli0 (list:range -10 10 1)) (set! oli1 (var oli0)) (set! oli0 - (indexed_filter + (list:indexed_filter (lambda ((int ix) (int i)) (exactly_one (> i 0) @@ -305,15 +307,15 @@ ) ) -(indexed_filter! +(list:indexed_filter! (lambda ((int ix) (int i) ((list int) o)) (exactly_one (> i 0) - (is_member (var ix) o) + (list:is_member (var ix) o) ) ) oli1 - (range 1 21 2) + (list:range 1 21 2) ) (assert! diff --git a/data/unit-testing/fold.fate b/data/unit-testing/fold.fate index 662ec3c..fdb941f 100644 --- a/data/unit-testing/fold.fate +++ b/data/unit-testing/fold.fate @@ -6,7 +6,7 @@ (global (list int) 0to10) -(set! 0to10 (range 0 10 1)) +(set! 0to10 (list:range 0 10 1)) (assert! (= 55 @@ -47,7 +47,7 @@ (add (- e 10) res) ) (default (list int)) - (range 10 20 1) + (list:range 10 20 1) ) ) @@ -57,7 +57,7 @@ (add (- e mod) res) ) (default (list int)) - (range 10 20 1) + (list:range 10 20 1) 10 ) ) @@ -137,7 +137,7 @@ (add (- e 10) res) ) (default (list int)) - (range 20 30 1) + (list:range 20 30 1) ) ) @@ -147,7 +147,7 @@ (add (- e mod) res) ) (default (list int)) - (range 20 30 1) + (list:range 20 30 1) 10 ) ) diff --git a/data/unit-testing/ifelse.fate b/data/unit-testing/ifelse.fate index 65a228f..3b67540 100644 --- a/data/unit-testing/ifelse.fate +++ b/data/unit-testing/ifelse.fate @@ -10,7 +10,6 @@ (assert! (false) [FAILED] (var test_name) Executing dead code 0.) ) - (set! test (false)) (ifelse (false) @@ -18,6 +17,7 @@ (set! test (true)) ) + (assert! test [FAILED] (var test_name) ignored valid branch 0.) (if (false) @@ -27,12 +27,14 @@ (assert! test [FAILED] (var test_name) Executing dead code 3.) +(global string st_name) (set! test (ifelse (false) (false) (true) ) ) +(global string tt_name) (assert! test [FAILED] (var test_name) Executing dead code 4.) diff --git a/data/unit-testing/map.fate b/data/unit-testing/map.fate index 3d6c16c..4659e96 100644 --- a/data/unit-testing/map.fate +++ b/data/unit-testing/map.fate @@ -12,11 +12,11 @@ (set! li0 (map (lambda ((int i)) (* i 2)) - (range 0 10 1) + (list:range 0 10 1) ) ) -(set! li1 (range 0 10 1)) +(set! li1 (list:range 0 10 1)) (map! (lambda ((int i)) (* i 2)) @@ -26,12 +26,12 @@ (set! li2 (map (lambda ((int i) (int mod)) (* i mod)) - (range 0 10 1) + (list:range 0 10 1) 2 ) ) -(set! li3 (range 0 10 1)) +(set! li3 (list:range 0 10 1)) (map! (lambda ((int i) (int mod)) (* i mod)) @@ -99,11 +99,11 @@ (set! li0 (indexed_map (lambda ((int ix) (int i)) (+ (* i ix) 1000)) - (range 10 20 1) + (list:range 10 20 1) ) ) -(set! li1 (range 10 20 1)) +(set! li1 (list:range 10 20 1)) (indexed_map! (lambda ((int ix) (int i)) (+ (* i ix) 1000)) @@ -113,12 +113,12 @@ (set! li2 (indexed_map (lambda ((int ix) (int i) (int mod)) (+ (* i ix) mod)) - (range 10 20 1) + (list:range 10 20 1) 1000 ) ) -(set! li3 (range 10 20 1)) +(set! li3 (list:range 10 20 1)) (indexed_map! (lambda ((int ix) (int i) (int mod)) (+ (* i ix) mod)) diff --git a/data/unit-testing/merge.fate b/data/unit-testing/merge.fate index 4989b47..2d71db8 100644 --- a/data/unit-testing/merge.fate +++ b/data/unit-testing/merge.fate @@ -20,7 +20,7 @@ (global (list int) li1ob) (set! li0 - (merge_to_list + (list:merge (lambda ( (int a) @@ -28,13 +28,13 @@ ) (- b a) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) ) ) (set! li0oa - (merge_to_list + (list:merge (lambda ( (int a) @@ -42,13 +42,13 @@ ) (- b a) ) - (range 0 60 2) - (range 10 70 1) + (list:range 0 60 2) + (list:range 10 70 1) ) ) (set! li0ob - (merge_to_list + (list:merge (lambda ( (int a) @@ -56,53 +56,13 @@ ) (- b a) ) - (range 0 80 2) - (range 10 40 1) + (list:range 0 80 2) + (list:range 10 40 1) ) ) -(set! li1 (range 10 40 1)) -(set! li1oa (range 10 60 1)) -(set! li1ob (range 10 40 1)) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - (range 0 60 2) - li1 -) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - (range 0 60 2) - li1oa -) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - (range 0 160 2) - li1ob -) - (assert! - (= (var li1) (var li0) (var li0oa) (var li0ob) (var li1oa) (var li1ob)) + (= (var li0) (var li0oa) (var li0ob)) [FAILED] (var test_name) Equality test 0. ) @@ -110,21 +70,15 @@ (assert! (= (- (+ 10 i) (* 2 i)) - (access i li0) - (access i li0oa) - (access i li0ob) - (access i li1) - (access i li1oa) - (access i li1ob) + (list:access i li0) + (list:access i li0oa) + (list:access i li0ob) ) [FAILED] (var test_name) Basic test 0, index (var i), values: Expected: (- (+ 10 i) (* 2 i)); - li0: (access i li0); - li0oa: (access i li0oa); - li0ob: (access i li0ob); - li1: (access i li1); - li1oa: (access i li1oa); - li1ob: (access i li1ob) + li0: (list:access i li0); + li0oa: (list:access i li0oa); + li0ob: (list:access i li0ob); ) ) @@ -134,12 +88,9 @@ (global (set int) si0) (global (set int) si0oa) (global (set int) si0ob) -(global (set int) si1) -(global (set int) si1oa) -(global (set int) si1ob) (set! si0 - (merge_to_set + (set:merge (lambda ( (int a) @@ -147,13 +98,13 @@ ) (- b a) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) ) ) (set! si0oa - (merge_to_set + (set:merge (lambda ( (int a) @@ -161,13 +112,13 @@ ) (- b a) ) - (range 0 60 2) - (range 10 70 1) + (list:range 0 60 2) + (list:range 10 70 1) ) ) (set! si0ob - (merge_to_set + (set:merge (lambda ( (int a) @@ -175,53 +126,13 @@ ) (- b a) ) - (range 0 80 2) - (range 10 40 1) - ) -) - -(add_all! (range 10 40 1) si1) -(add_all! (range 10 60 1) si1oa) -(add_all! (range 10 40 1) si1ob) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - (range 0 60 2) - si1 -) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - (range 0 60 2) - si1oa -) - -(merge! - (lambda - ( - (int a) - (int b) - ) - (- b a) + (list:range 0 80 2) + (list:range 10 40 1) ) - (range 0 80 2) - si1ob ) (assert! - (= (var si0) (var si0oa) (var si0ob) (var si1) (var si1oa) (var si1ob)) + (= (var si0) (var si0oa) (var si0ob)) [FAILED] (var test_name) Equality test 1. ) @@ -238,21 +149,15 @@ (assert! (= (- (+ 10 j) (* 2 j)) - (access i si0) - (access i si0oa) - (access i si0ob) - (access i si1) - (access i si1oa) - (access i si1ob) + (set:access i si0) + (set:access i si0oa) + (set:access i si0ob) ) [FAILED] (var test_name) Basic test 1, index (var i), values: Expected: (- (+ 10 j) (* 2 j)); - si0: (access i si0); - si0oa: (access i si0oa); - si0ob: (access i si0ob); - si1: (access i si1); - si1oa: (access i si1oa); - si1ob: (access i si1ob); + si0: (set:access i si0); + si0oa: (set:access i si0oa); + si0ob: (set:access i si0ob); ) ) @@ -262,12 +167,9 @@ (global (set int) si2) (global (set int) si2oa) (global (set int) si2ob) -(global (set int) si3) -(global (set int) si3oa) -(global (set int) si3ob) (set! si2 - (merge_to_set + (set:merge (lambda ( (int a) @@ -276,14 +178,14 @@ ) (* (- b a) mod) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) -1 ) ) (set! si2oa - (merge_to_set + (set:merge (lambda ( (int a) @@ -292,14 +194,14 @@ ) (* (- b a) mod) ) - (range 0 60 2) - (range 10 80 1) + (list:range 0 60 2) + (list:range 10 80 1) -1 ) ) (set! si2ob - (merge_to_set + (set:merge (lambda ( (int a) @@ -308,60 +210,14 @@ ) (* (- b a) mod) ) - (range 0 80 2) - (range 10 40 1) + (list:range 0 80 2) + (list:range 10 40 1) -1 ) ) -(add_all! (range 10 40 1) si3) -(add_all! (range 10 80 1) si3oa) -(add_all! (range 10 40 1) si3ob) - -(merge! - (lambda - ( - (int a) - (int b) - (int mod) - ) - (* (- b a) mod) - ) - (range 0 60 2) - si3 - -1 -) - -(merge! - (lambda - ( - (int a) - (int b) - (int mod) - ) - (* (- b a) mod) - ) - (range 0 60 2) - si3oa - -1 -) - -(merge! - (lambda - ( - (int a) - (int b) - (int mod) - ) - (* (- b a) mod) - ) - (range 0 90 2) - si3ob - -1 -) - (assert! - (= (var si2) (var si2oa) (var si2ob) (var si3) (var si3oa) (var si3ob)) + (= (var si2) (var si2oa) (var si2ob)) [FAILED] (var test_name) Equality test 2. ) @@ -372,21 +228,15 @@ (assert! (= (* (- (+ 10 i) (* 2 i)) -1) - (access i si2) - (access i si2oa) - (access i si2ob) - (access i si3) - (access i si3oa) - (access i si3ob) + (set:access i si2) + (set:access i si2oa) + (set:access i si2ob) ) [FAILED] (var test_name) Basic test 2, index (var i), values: Expected: (* (- (+ 10 i) (* 2 i)) -1); - si2: (access i si2); - si2oa: (access i si2oa); - si2ob: (access i si2ob); - si3: (access i si3); - si3oa: (access i si3oa); - si3ob: (access i si3ob) + si2: (set:access i si2); + si2oa: (set:access i si2oa); + si2ob: (set:access i si2ob); ) ) @@ -396,12 +246,9 @@ (global (list int) ili0) (global (list int) ili0oa) (global (list int) ili0ob) -(global (list int) ili1) -(global (list int) ili1oa) -(global (list int) ili1ob) (set! ili0 - (indexed_merge_to_list + (list:indexed_merge (lambda ( (int i) @@ -410,13 +257,13 @@ ) (* (- b a) i) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) ) ) (set! ili0oa - (indexed_merge_to_list + (list:indexed_merge (lambda ( (int i) @@ -425,13 +272,13 @@ ) (* (- b a) i) ) - (range 0 60 2) - (range 10 70 1) + (list:range 0 60 2) + (list:range 10 70 1) ) ) (set! ili0ob - (indexed_merge_to_list + (list:indexed_merge (lambda ( (int i) @@ -440,56 +287,13 @@ ) (* (- b a) i) ) - (range 0 80 2) - (range 10 40 1) - ) -) - -(set! ili1 (range 10 40 1)) -(set! ili1oa (range 10 60 1)) -(set! ili1ob (range 10 40 1)) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) i) - ) - (range 0 60 2) - ili1 -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) i) - ) - (range 0 60 2) - ili1oa -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) i) + (list:range 0 80 2) + (list:range 10 40 1) ) - (range 0 160 2) - ili1ob ) (assert! - (= (var ili1) (var ili0) (var ili0oa) (var ili0ob) (var ili1oa) (var ili1ob)) + (= (var ili0) (var ili0oa) (var ili0ob)) [FAILED] (var test_name) Equality test indexed 0. ) @@ -497,21 +301,15 @@ (assert! (= (* (- (+ 10 i) (* 2 i)) i) - (access i ili0) - (access i ili0oa) - (access i ili0ob) - (access i ili1) - (access i ili1oa) - (access i ili1ob) + (list:access i ili0) + (list:access i ili0oa) + (list:access i ili0ob) ) [FAILED] (var test_name) Indexed test 0, index (var i), values: Expected: (* (- (+ 10 i) (* 2 i)) i); - ili0: (access i ili0); - ili0oa: (access i ili0oa); - ili0ob: (access i ili0ob); - ili1: (access i ili1); - ili1oa: (access i ili1oa); - ili1ob: (access i ili1ob) + ili0: (list:access i ili0); + ili0oa: (list:access i ili0oa); + ili0ob: (list:access i ili0ob); ) ) @@ -523,18 +321,15 @@ For reference, the values found in the sets are: (local int o) (set! o (* (- (+ 10 i) (* 2 i)) (+ i 1))) (var o) (newline) - (add! (var o) oracle_set) + (set:add! (var o) oracle_set) ) (global (set int) isi0) (global (set int) isi0oa) (global (set int) isi0ob) -(global (set int) isi1) -(global (set int) isi1oa) -(global (set int) isi1ob) (set! isi0 - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -543,13 +338,13 @@ For reference, the values found in the sets are: ) (* (- b a) (+ i 1)) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) ) ) (set! isi0oa - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -558,13 +353,13 @@ For reference, the values found in the sets are: ) (* (- b a) (+ i 1)) ) - (range 0 60 2) - (range 10 70 1) + (list:range 0 60 2) + (list:range 10 70 1) ) ) (set! isi0ob - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -573,82 +368,33 @@ For reference, the values found in the sets are: ) (* (- b a) (+ i 1)) ) - (range 0 80 2) - (range 10 40 1) + (list:range 0 80 2) + (list:range 10 40 1) ) ) -(add_all! (range 10 40 1) isi1) -(add_all! (range 10 60 1) isi1oa) -(add_all! (range 10 40 1) isi1ob) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) (+ i 1)) - ) - (range 0 60 2) - isi1 -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) (+ i 1)) - ) - (range 0 60 2) - isi1oa -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - ) - (* (- b a) (+ i 1)) - ) - (range 0 80 2) - isi1ob -) - (assert! - (= (var isi0) (var isi0oa) (var isi0ob) (var isi1) (var isi1oa) (var isi1ob)) + (= (var isi0) (var isi0oa) (var isi0ob)) [FAILED] (var test_name) Equality test indexed 1. ) -(for (set! i (- (size oracle_set) 1)) (>= i 0) (set! i (- i 1)) +(for (set! i (- (set:size oracle_set) 1)) (>= i 0) (set! i (- i 1)) (assert! (= - (access i oracle_set) - (access i isi0) - (access i isi0oa) - (access i isi0ob) - (access i isi1) - (access i isi1oa) - (access i isi1ob) + (set:access i oracle_set) + (set:access i isi0) + (set:access i isi0oa) + (set:access i isi0ob) ) [FAILED] (var test_name) Indexed test 1, index (var i), values: - Expected: (access i oracle_set); - isi0: (access i isi0); - isi0oa: (access i isi0oa); - isi0ob: (access i isi0ob); - isi1: (access i isi1); - isi1oa: (access i isi1oa); - isi1ob: (access i isi1ob); + Expected: (set:access i oracle_set); + isi0: (set:access i isi0); + isi0oa: (set:access i isi0oa); + isi0ob: (set:access i isi0ob); ) ) -(clear! oracle_set) +(set:clear! oracle_set) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; INDEXED TEST 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -659,7 +405,7 @@ For reference, the values found in the sets are: (local int o) (set! o (* (- (+ 10 i) (* 2 i)) -1 (+ i 1))) (var o) (newline) - (add! (var o) oracle_set) + (set:add! (var o) oracle_set) ) (global (set int) isi2) @@ -670,7 +416,7 @@ For reference, the values found in the sets are: (global (set int) isi3ob) (set! isi2 - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -680,14 +426,14 @@ For reference, the values found in the sets are: ) (* (* (- b a) mod) (+ i 1)) ) - (range 0 60 2) - (range 10 40 1) + (list:range 0 60 2) + (list:range 10 40 1) -1 ) ) (set! isi2oa - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -697,14 +443,14 @@ For reference, the values found in the sets are: ) (* (* (- b a) mod) (+ i 1)) ) - (range 0 60 2) - (range 10 80 1) + (list:range 0 60 2) + (list:range 10 80 1) -1 ) ) (set! isi2ob - (indexed_merge_to_set + (set:indexed_merge (lambda ( (int i) @@ -714,140 +460,33 @@ For reference, the values found in the sets are: ) (* (- b a) mod (+ i 1)) ) - (range 0 80 2) - (range 10 40 1) + (list:range 0 80 2) + (list:range 10 40 1) -1 ) ) -(add_all! (range 10 40 1) isi3) -(add_all! (range 10 80 1) isi3oa) -(add_all! (range 10 40 1) isi3ob) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - (int mod) - ) - (* (- b a) mod (+ i 1)) - ) - (range 0 60 2) - isi3 - -1 -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - (int mod) - ) - (* (- b a) mod (+ i 1)) - ) - (range 0 60 2) - isi3oa - -1 -) - -(indexed_merge! - (lambda - ( - (int i) - (int a) - (int b) - (int mod) - ) - (* (- b a) mod (+ i 1)) - ) - (range 0 90 2) - isi3ob - -1 -) - (assert! - (= (var isi2) (var isi2oa) (var isi2ob) (var isi3) (var isi3oa) (var isi3ob)) + (= (var isi2) (var isi2oa) (var isi2ob)) [FAILED] (var test_name) Equality test indexed 2. ) -(for (set! i (- (size oracle_set) 1)) (>= i 0) (set! i (- i 1)) +(for (set! i (- (set:size oracle_set) 1)) (>= i 0) (set! i (- i 1)) (assert! (= - (access i oracle_set) - (access i isi2) - (access i isi2oa) - (access i isi2ob) - (access i isi3) - (access i isi3oa) - (access i isi3ob) + (set:access i oracle_set) + (set:access i isi2) + (set:access i isi2oa) + (set:access i isi2ob) ) [FAILED] (var test_name) Indexed test 2, index (var i), values: - Expected: (access i oracle_set); - isi2: (access i isi2); - isi2oa: (access i isi2oa); - isi2ob: (access i isi2ob); - isi3: (access i isi3); - isi3oa: (access i isi3oa); - isi3ob: (access i isi3ob) + Expected: (set:access i oracle_set); + isi2: (set:access i isi2); + isi2oa: (set:access i isi2oa); + isi2ob: (set:access i isi2ob); ) ) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; SAFE TEST 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(global (list int) sli0) -(global (list int) sli1) -(global (list int) sli2) -(global (list int) sli3) - -(set! sli0 - (safe_merge_to_list - (lambda - ( - (int a) - (int b) - ) - (- a b) - ) - 999 - (range 0 10 1) - 1 - (default (list int)) - ) -) - -(set! sli1 - (safe_merge_to_list - (lambda - ( - (int a) - (int b) - ) - (- b a) - ) - 1 - (default (list int)) - 999 - (range 0 10 1) - ) -) - -(for (set! i 0) (=< i 10) (set! i (+ i 1)) - (assert! - (= (access i sli0) (access i sli1) (- i 1)) - [FAILED] (var test_name) Equality test safe 0. - ) -) - -(assert! - (= (var sli0) (var sli1)) - [FAILED] (var test_name) Equality test safe 0. -) - [COMPLETED] (var test_name) (end!) diff --git a/data/unit-testing/ptr_and_at.fate b/data/unit-testing/ptr_and_at.fate index 4ccaa26..9b12862 100644 --- a/data/unit-testing/ptr_and_at.fate +++ b/data/unit-testing/ptr_and_at.fate @@ -71,12 +71,12 @@ (global test_struct0 ts0) -(set_fields! ts0 +(struct:set_fields! ts0 (int0 3) (int1 40) (int_ptr0 (ptr ts0.int0)) (int_ptr1 (ptr ts0.int1)) - (int_list (range 0 10 1)) + (int_list (list:range 0 10 1)) (int_ptr_list_ptr (ptr ts0.int_ptr_list)) ) diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java index ace2e5e..4385fa5 100644 --- a/src/core/src/tonkadur/Main.java +++ b/src/core/src/tonkadur/Main.java @@ -5,6 +5,7 @@ import java.util.List; import java.io.IOException; import tonkadur.parser.Origin; +import tonkadur.parser.Context; import tonkadur.fate.v1.parser.ParserData; @@ -61,7 +62,11 @@ public class Main parser_data.add_file_content ( Origin.BASE_LANGUAGE, - RuntimeParameters.get_input_file() + Files.resolve_filename + ( + Context.BASE_LANGUAGE, + RuntimeParameters.get_input_file() + ) ); System.out.println("Parsing completed."); diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java index 3b3be93..969ac1b 100644 --- a/src/core/src/tonkadur/TonkadurPlugin.java +++ b/src/core/src/tonkadur/TonkadurPlugin.java @@ -30,8 +30,6 @@ public abstract class TonkadurPlugin public static void register_as_loadable_superclass (final Class c) { - System.out.println("[D] Will load subclasses of " + c.getName() + "..."); - LOADABLE_SUPERCLASSES.add(c); } @@ -110,15 +108,6 @@ public abstract class TonkadurPlugin { if (superclass.isAssignableFrom(c) && !c.equals(superclass)) { - System.out.println - ( - "[D] Registering class " - + candidate - + " as a " - + superclass.getName() - + "..." - ); - superclass.getDeclaredMethod ( "register", diff --git a/src/core/src/tonkadur/fate/v1/lang/Variable.java b/src/core/src/tonkadur/fate/v1/lang/Variable.java index bb72565..2d4dbcb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Variable.java +++ b/src/core/src/tonkadur/fate/v1/lang/Variable.java @@ -12,6 +12,7 @@ import tonkadur.parser.Origin; import tonkadur.fate.v1.lang.meta.DeclaredEntity; import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.FutureType; public class Variable extends DeclaredEntity { @@ -73,6 +74,11 @@ public class Variable extends DeclaredEntity /**** Accessors ************************************************************/ public Type get_type () { + if (type instanceof FutureType) + { + return ((FutureType) type).get_current_type(); + } + return type; } diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java index a5f1bbe..bc85e83 100644 --- a/src/core/src/tonkadur/fate/v1/lang/World.java +++ b/src/core/src/tonkadur/fate/v1/lang/World.java @@ -27,6 +27,7 @@ import tonkadur.fate.v1.lang.meta.Instruction; import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.ConsType; +import tonkadur.fate.v1.lang.type.PointerType; import tonkadur.fate.v1.lang.type.DictionaryType; import tonkadur.fate.v1.lang.type.LambdaType; import tonkadur.fate.v1.lang.type.SequenceType; @@ -328,6 +329,8 @@ public class World type_collection.add(DictionaryType.ARCHETYPE); + type_collection.add(PointerType.ARCHETYPE); + type_collection.add(LambdaType.ARCHETYPE); type_collection.add(SequenceType.ARCHETYPE); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java index d78dcc9..624d61b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java @@ -65,6 +65,11 @@ public class AmbiguousWord extends Computation { if (result == null) { + if (type instanceof FutureType) + { + return ((FutureType) type).get_current_type(); + } + return type; } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java index 67335f3..ae63ef6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Access.java @@ -38,6 +38,7 @@ public class Access extends GenericComputation aliases.add("set:at_index"); aliases.add("set:atindex"); aliases.add("set:atIndex"); + aliases.add("collection:access"); return aliases; } @@ -97,7 +98,11 @@ public class Access extends GenericComputation ); } - if (alias.startsWith("set:")) + if (alias.startsWith("collection:")) + { + RecurrentChecks.assert_is_a_collection(parent); + } + else if (alias.startsWith("set:")) { RecurrentChecks.assert_is_a_set(parent); } @@ -106,7 +111,14 @@ public class Access extends GenericComputation RecurrentChecks.assert_is_a_list(parent); } - return new Access(origin, parent, current_type, index); + return + new Access + ( + origin, + parent, + ((CollectionType) current_type).get_content_type(), + index + ); } /***************************************************************************/ diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java index 996d9b3..8eb4328 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/AddElementComputation.java @@ -44,16 +44,60 @@ public class AddElementComputation extends GenericComputation final Computation element; final Computation collection; - if (call_parameters.size() != 2) + if (call_parameters.size() < 2) { // TODO: Error. - System.err.println("Wrong number of params at " + origin.toString()); + System.err.println + ( + "Wrong number of params (" + + (call_parameters.size()) + + " given, 2 expected) at" + + origin.toString() + ); return null; } - element = call_parameters.get(0); - collection = call_parameters.get(1); + + if (call_parameters.size() > 2) + { + final int param_size; + Computation temp_collection; + List temp_params; + + param_size = call_parameters.size(); + + temp_collection = call_parameters.get(param_size - 1); + + temp_params = new ArrayList(); + temp_params.add(temp_collection); + temp_params.add(temp_collection); + + for + ( + final Computation addition: + call_parameters.subList(0, (param_size - 2)) + ) + { + temp_params.set(0, addition); + + temp_collection = + build + ( + origin, + alias, + temp_params + ); + } + + element = call_parameters.get(param_size - 2); + collection = temp_collection; + } + else + { + element = call_parameters.get(0); + collection = call_parameters.get(1); + } if (alias.startsWith("set:")) { diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java new file mode 100644 index 0000000..ff607ef --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/BooleanComputation.java @@ -0,0 +1,59 @@ +package tonkadur.fate.v1.lang.computation.generic; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.ComputationVisitor; +import tonkadur.fate.v1.lang.meta.Computation; + +import tonkadur.fate.v1.lang.type.Type; + +import tonkadur.fate.v1.lang.computation.GenericComputation; + +import tonkadur.fate.v1.lang.computation.Constant; + +public class BooleanComputation extends GenericComputation +{ + public static Collection get_aliases () + { + final Collection aliases; + + aliases = new ArrayList(); + + aliases.add("true"); + aliases.add("false"); + + return aliases; + } + + public static Computation build + ( + final Origin origin, + final String alias, + final List call_parameters + ) + throws Throwable + { + if (call_parameters.size() != 0) + { + // TODO: Error. + System.err.println("Wrong number of params at " + origin.toString()); + + return null; + } + + return Constant.build_boolean(origin, alias.equals("true")); + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + private BooleanComputation (final Origin origin) + { + super(origin, Type.BOOL); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java index 6f569a8..2b45b55 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/ConsComputation.java @@ -48,8 +48,8 @@ public class ConsComputation extends GenericComputation car = call_parameters.get(0); cdr = call_parameters.get(1); - car.expect_non_string(); - cdr.expect_non_string(); + car.expect_string(); + cdr.expect_string(); return new ConsComputation(origin, car, cdr); } diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java index dc860f6..658b650 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/IndexedSafeMergeComputation.java @@ -26,15 +26,6 @@ public class IndexedSafeMergeComputation extends GenericComputation aliases = new ArrayList(); - aliases.add("list:indexed_merge"); - aliases.add("list:indexedmerge"); - aliases.add("list:indexedMerge"); - aliases.add("list:imerge"); - aliases.add("set:indexed_merge"); - aliases.add("set:indexedmerge"); - aliases.add("set:indexedMerge"); - aliases.add("set:imerge"); - aliases.add("list:indexed_safe_merge"); aliases.add("list:indexedsafemerge"); aliases.add("list:indexedSafeMerge"); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java index 46effb9..fed2ea2 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/generic/Operation.java @@ -105,7 +105,10 @@ public class Operation extends GenericComputation operator = Operator.ONE_IN; ALIASED_OPERATOR.put("exactlyOneIn", operator); ALIASED_OPERATOR.put("exactlyonein", operator); + ALIASED_OPERATOR.put("exactlyOne", operator); + ALIASED_OPERATOR.put("exactlyone", operator); ALIASED_OPERATOR.put("exactly_one_in", operator); + ALIASED_OPERATOR.put("exactly_one", operator); ALIASED_OPERATOR.put("OneIn", operator); ALIASED_OPERATOR.put("onein", operator); ALIASED_OPERATOR.put("one_in", operator); diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java index 29a0bd0..065c7db 100644 --- a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java @@ -101,8 +101,6 @@ public abstract class GenericInstruction extends Instruction ); } - System.out.println("Resolving GenericInstruction " + name + "..."); - return (Instruction) computation_class.getDeclaredMethod ( diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java index 17b3ec3..62d88ed 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/Computation.java @@ -4,6 +4,7 @@ import tonkadur.parser.Origin; import tonkadur.parser.ParsingError; import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.FutureType; public abstract class Computation extends Node { @@ -35,6 +36,11 @@ public abstract class Computation extends Node public Type get_type () { + if (type instanceof FutureType) + { + return ((FutureType) type).get_current_type(); + } + return type; } diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java index 365e70a..8fa713d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java @@ -17,6 +17,9 @@ import tonkadur.fate.v1.lang.computation.Constant; import tonkadur.fate.v1.lang.computation.FieldAccess; import tonkadur.fate.v1.lang.computation.VariableReference; +import tonkadur.fate.v1.lang.computation.generic.AtReference; +import tonkadur.fate.v1.lang.computation.generic.Access; + import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.PointerType; import tonkadur.fate.v1.lang.type.StructType; @@ -33,7 +36,7 @@ public class VariableFromWord final Origin origin, final String word ) - throws ParsingError + throws Throwable { final String[] subrefs; Computation result; @@ -67,29 +70,44 @@ public class VariableFromWord while (t instanceof PointerType) { t = ((PointerType) t).get_referenced_type(); + + result = + AtReference.build + ( + origin.with_hint(subref), + "at", + Collections.singletonList(result) + ); } -/* + if (t instanceof CollectionType) { result = - AccessAsReference.build + Access.build ( - origin, - result, - Constant.build(origin, subref) + origin.with_hint(subref), + "collection:access", + Arrays.asList + ( + new Computation[] + { + Constant.build(origin.with_hint(subref), subref), + result + } + ) ); } else if (t instanceof StructType) { result = - FieldReference.build + FieldAccess.build ( - origin, + origin.with_hint(subref), result, Collections.singletonList(subref) ); } - else */ + else { /* TODO: error */ System.err.println("Unimplemented error in VariableFromWord."); diff --git a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java index eb8b664..c3ffb35 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java @@ -1,5 +1,6 @@ package tonkadur.fate.v1.lang.type; +import java.util.List; import java.util.Collections; import tonkadur.error.ErrorManager; @@ -84,7 +85,16 @@ public class CollectionType extends Type /**** Accessors ************************************************************/ public Type get_content_type () { - return parameters.get(0); + final Type result; + + result = parameters.get(0); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } public boolean is_set () @@ -102,7 +112,11 @@ public class CollectionType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof CollectionType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof CollectionType) { final CollectionType ct; @@ -198,4 +212,20 @@ public class CollectionType extends Type this.is_set = is_set; } + + @Override + public Type generate_variant + ( + final Origin origin, + final List parameters + ) + throws Throwable + { + if (this.parameters.size() != parameters.size()) + { + // TODO: error; + } + + return new CollectionType(origin, parameters.get(0), is_set, name); + } } diff --git a/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java b/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java index 7fe5a34..6430494 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/ConsType.java @@ -1,6 +1,7 @@ package tonkadur.fate.v1.lang.type; import java.util.Arrays; +import java.util.List; import tonkadur.parser.Origin; @@ -39,22 +40,60 @@ public class ConsType extends Type super(origin, null, name, Arrays.asList(new Type[]{car, cdr})); } + @Override + public Type generate_variant + ( + final Origin origin, + final List parameters + ) + throws Throwable + { + if (this.parameters.size() != parameters.size()) + { + // TODO: error; + } + + return new ConsType(origin, parameters.get(0), parameters.get(1), name); + } + /**** Accessors ************************************************************/ public Type get_car_type () { - return parameters.get(0); + final Type result; + + result = parameters.get(0); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } public Type get_cdr_type () { - return parameters.get(1); + final Type result; + + result = parameters.get(1); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } /**** Compatibility ********************************************************/ @Override public boolean can_be_used_as (final Type t) { - if (t instanceof ConsType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof ConsType) { final ConsType dt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java index 18f0a0e..b4d227f 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java @@ -1,5 +1,8 @@ package tonkadur.fate.v1.lang.type; +import java.util.List; +import java.util.Arrays; + import tonkadur.error.ErrorManager; import tonkadur.parser.ParsingError; @@ -9,6 +12,8 @@ import tonkadur.fate.v1.error.InvalidTypeException; import tonkadur.fate.v1.lang.meta.DeclaredEntity; +// TODO: implement. +// TODO: Use parameters list instead of separate type members. public class DictionaryType extends Type { public static final DictionaryType ARCHETYPE; @@ -25,12 +30,6 @@ public class DictionaryType extends Type ); } - /***************************************************************************/ - /**** MEMBERS **************************************************************/ - /***************************************************************************/ - protected final Type key_type; - protected final Type value_type; - /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ @@ -60,12 +59,30 @@ public class DictionaryType extends Type /**** Accessors ************************************************************/ public Type get_key_type () { - return key_type; + final Type result; + + result = parameters.get(0); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } public Type get_value_type () { - return value_type; + final Type result; + + result = parameters.get(1); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } @Override @@ -78,7 +95,11 @@ public class DictionaryType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof DictionaryType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof DictionaryType) { final DictionaryType ct; @@ -86,8 +107,8 @@ public class DictionaryType extends Type return ( - key_type.can_be_used_as(ct.key_type) - && value_type.can_be_used_as(ct.value_type) + get_key_type().can_be_used_as(ct.get_key_type()) + && get_value_type().can_be_used_as(ct.get_value_type()) ); } @@ -116,8 +137,8 @@ public class DictionaryType extends Type new DictionaryType ( get_origin(), - ((Type) key_type.generate_comparable_to(ct.key_type)), - ((Type) value_type.generate_comparable_to(ct.value_type)), + ((Type) get_key_type().generate_comparable_to(ct.get_key_type())), + ((Type) get_value_type().generate_comparable_to(ct.get_value_type())), name ); } @@ -127,7 +148,7 @@ public class DictionaryType extends Type @Override public Type generate_alias (final Origin origin, final String name) { - return new DictionaryType(origin, key_type, value_type, name); + return new DictionaryType(origin, get_key_type(), get_value_type(), name); } @Override @@ -136,9 +157,9 @@ public class DictionaryType extends Type final StringBuilder sb = new StringBuilder(); sb.append("(Dict "); - sb.append(key_type.toString()); + sb.append(get_key_type().toString()); sb.append(" "); - sb.append(value_type.toString()); + sb.append(get_value_type().toString()); sb.append(")::"); sb.append(name); @@ -158,9 +179,28 @@ public class DictionaryType extends Type final String name ) { - super(origin, null, name); + super(origin, null, name, Arrays.asList(new Type[]{key_type, value_type})); + } - this.key_type = key_type; - this.value_type = value_type; + public Type generate_variant + ( + final Origin origin, + final List parameters + ) + throws Throwable + { + if (this.parameters.size() != parameters.size()) + { + // TODO: error; + } + + return + new DictionaryType + ( + origin, + parameters.get(0), + parameters.get(1), + name + ); } } diff --git a/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java index aed727f..919abd6 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java @@ -19,7 +19,7 @@ public class ExtraType extends Type public ExtraType ( final Origin origin, - final ExtraType parent, + final Type parent, final String name, final List parameters ) @@ -27,13 +27,34 @@ public class ExtraType extends Type super(origin, parent, name, parameters); } + @Override + public Type generate_variant + ( + final Origin origin, + final List parameters + ) + throws Throwable + { + if (this.parameters.size() != parameters.size()) + { + // TODO: error; + } + + return new ExtraType(origin, this, name, parameters); + } + + /**** Accessors ************************************************************/ /**** Compatibility ********************************************************/ @Override public boolean can_be_used_as (final Type t) { - if (t instanceof ExtraType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof ExtraType) { final ExtraType e; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java b/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java index 5e0650b..f85053d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/FutureType.java @@ -82,7 +82,6 @@ public class FutureType extends Type FUTURE_TYPES.add(this); } - /**** Accessors ************************************************************/ public Type get_base_type () { @@ -98,6 +97,20 @@ public class FutureType extends Type return resolved_type.get_act_as_type(); } + public Type get_current_type () + { + if (resolved_type == null) + { + return this; + } + else if (resolved_type instanceof FutureType) + { + return ((FutureType) resolved_type).get_current_type(); + } + + return resolved_type; + } + public boolean is_base_type () { assert_is_resolved(); diff --git a/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java index 1a6a111..df82195 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/LambdaType.java @@ -50,7 +50,16 @@ public class LambdaType extends Type /**** Accessors ************************************************************/ public Type get_return_type () { - return return_type; + final Type result; + + result = return_type; + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } public List get_signature () @@ -62,7 +71,11 @@ public class LambdaType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof LambdaType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof LambdaType) { final Iterator i0, i1; final LambdaType lt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java b/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java index db1a18a..daf5bc8 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/PointerType.java @@ -1,6 +1,7 @@ package tonkadur.fate.v1.lang.type; import java.util.Collections; +import java.util.List; import tonkadur.parser.Origin; @@ -37,20 +38,39 @@ public class PointerType extends Type final String name ) { - super(origin, null, name, Collections.singletonList(referenced_type)); + super + ( + origin, + ((referenced_type == Type.ANY) ? null : ARCHETYPE), + name, + Collections.singletonList(referenced_type) + ); } /**** Accessors ************************************************************/ public Type get_referenced_type () { - return parameters.get(0); + final Type result; + + result = parameters.get(0); + + if (result instanceof FutureType) + { + return ((FutureType) result).get_resolved_type(); + } + + return result; } /**** Compatibility ********************************************************/ @Override public boolean can_be_used_as (final Type t) { - if (t instanceof PointerType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof PointerType) { final PointerType dt; @@ -80,6 +100,7 @@ public class PointerType extends Type } dt = (PointerType) de; + resulting_referenced_type = (Type) get_referenced_type().generate_comparable_to ( @@ -102,6 +123,22 @@ public class PointerType extends Type return new PointerType(origin, get_referenced_type(), name); } + @Override + public Type generate_variant + ( + final Origin origin, + final List parameters + ) + throws Throwable + { + if (this.parameters.size() != 1) + { + // TODO: error; + } + + return new PointerType(origin, parameters.get(0), "auto gen"); + } + @Override public String toString () { diff --git a/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java b/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java index 0970a98..9adfa61 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/SequenceType.java @@ -97,7 +97,11 @@ public class SequenceType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof SequenceType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof SequenceType) { final Iterator i0, i1; final SequenceType lt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/StructType.java b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java index 1d9ab89..c46396b 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/StructType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java @@ -67,7 +67,11 @@ public class StructType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof StructType) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (t instanceof StructType) { final StructType dt; diff --git a/src/core/src/tonkadur/fate/v1/lang/type/Type.java b/src/core/src/tonkadur/fate/v1/lang/type/Type.java index c1e074b..1bed5da 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/Type.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/Type.java @@ -155,7 +155,11 @@ public class Type extends DeclaredEntity /**** Compatibility ********************************************************/ public boolean can_be_used_as (final Type t) { - if (!get_act_as_type().equals(t.get_act_as_type())) + if (t instanceof FutureType) + { + return can_be_used_as(((FutureType) t).get_resolved_type()); + } + else if (!get_act_as_type().equals(t.get_act_as_type())) { return false; } diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 4c6a5d4..ca632dd 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -58,7 +58,7 @@ VISIT_KW: ( ('call'|'visit') US ((('seq'|'Seq')'uence'?)|('proc'|'Proc')'edure'?)? ) - IMP; + IMP SEP+; CONTINUE_AS_KW: L_PAREN @@ -78,7 +78,7 @@ CONTINUE_AS_KW: ) (US ((('seq'|'Seq')'uence'?)|('proc'|'Proc')'edure'?))? ) - IMP; + IMP SEP+; VARIABLE_KW: L_PAREN ('variable'|'var') SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 80e1213..aded279 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -640,6 +640,8 @@ returns [Instruction result] elem_type = Type.ANY; + ($coll.result).expect_non_string(); + collection_type = ($coll.result).get_type(); /* FIXME: This doesn't let you use it with a Dict. */ @@ -961,11 +963,14 @@ returns [Instruction result] } else { + final String keyword; + + keyword = ($VISIT_KW.text).trim(); $result = GenericInstruction.build ( origin, - ($VISIT_KW.text).substring(0, (($VISIT_KW.text).length() - 1)), + keyword.substring(1, (keyword.length() - 1)), ($maybe_computation_list.result) ); } @@ -1009,15 +1014,14 @@ returns [Instruction result] } else { + final String keyword; + + keyword = ($CONTINUE_AS_KW.text).trim(); $result = GenericInstruction.build ( origin, - ($CONTINUE_AS_KW.text).substring - ( - 0, - (($CONTINUE_AS_KW.text).length() - 1) - ), + keyword.substring(1, (keyword.length() - 1)), ($maybe_computation_list.result) ); } @@ -1427,6 +1431,8 @@ returns [Instruction result] elem_type = Type.ANY; + ($computation.result).expect_non_string(); + collection_type = ($computation.result).get_type(); if (collection_type instanceof CollectionType) @@ -1647,11 +1653,9 @@ returns [Type result] } } - | LAMBDA_KW type WS* L_PAREN maybe_type_list R_PAREN WS* R_PAREN + | LAMBDA_KW type WS* L_PAREN no_space_maybe_type_list R_PAREN WS* R_PAREN { - final Type t; - - t = + $result = new LambdaType ( PARSER.get_origin_at @@ -1661,15 +1665,13 @@ returns [Type result] ), ($type.result), "autogenerated lambda type", - ($maybe_type_list.result) + ($no_space_maybe_type_list.result) ); } - | SEQUENCE_KW maybe_type_list R_PAREN + | SEQUENCE_KW no_space_maybe_type_list R_PAREN { - final Type t; - - t = + $result = new SequenceType ( PARSER.get_origin_at @@ -1678,7 +1680,7 @@ returns [Type result] ($SEQUENCE_KW.getCharPositionInLine()) ), "autogenerated sequence type", - ($maybe_type_list.result) + ($no_space_maybe_type_list.result) ); } @@ -1742,6 +1744,29 @@ returns [List result] } ; +no_space_maybe_type_list +returns [List result] +@init +{ + $result = new ArrayList(); +} +: + (WS* + type + { + $result.add(($type.result)); + } + )* + (WS+ + type + { + $result.add(($type.result)); + } + )* + { + } +; + let_variable_list returns [List> result] @init @@ -2309,6 +2334,11 @@ returns [Computation result] ); } + | TEXT_KW paragraph WS* R_PAREN + { + $result = ($paragraph.result); + } + | ENABLE_TEXT_EFFECT_KW word WS+ paragraph WS* R_PAREN { final TextEffect effect; @@ -2368,7 +2398,7 @@ returns [Computation result] ); } - | IF_KW maybe_computation_list WS* R_PAREN + | IF_KW computation_list WS* R_PAREN { $result = GenericComputation.build @@ -2378,12 +2408,12 @@ returns [Computation result] ($IF_KW.getLine()), ($IF_KW.getCharPositionInLine()) ), - ($IF_KW.text).substring(1), - ($maybe_computation_list.result) + ($IF_KW.text).substring(1).trim(), + ($computation_list.result) ); } - | IF_ELSE_KW maybe_computation_list WS* R_PAREN + | IF_ELSE_KW computation_list WS* R_PAREN { $result = GenericComputation.build @@ -2393,8 +2423,8 @@ returns [Computation result] ($IF_ELSE_KW.getLine()), ($IF_ELSE_KW.getCharPositionInLine()) ), - ($IF_ELSE_KW.text).substring(1), - ($maybe_computation_list.result) + ($IF_ELSE_KW.text).substring(1).trim(), + ($computation_list.result) ); } ; @@ -2575,6 +2605,17 @@ word returns [String result, Origin origin]: ); } + | IMP_MARKER + { + $result = "!"; + $origin = + PARSER.get_origin_at + ( + ($IMP_MARKER.getLine()), + ($IMP_MARKER.getCharPositionInLine()) + ); + } + | IDENTIFIER_KW { $result = $IDENTIFIER_KW.text; diff --git a/src/core/src/tonkadur/fate/v1/parser/ParserData.java b/src/core/src/tonkadur/fate/v1/parser/ParserData.java index ce73193..7f1530d 100644 --- a/src/core/src/tonkadur/fate/v1/parser/ParserData.java +++ b/src/core/src/tonkadur/fate/v1/parser/ParserData.java @@ -202,7 +202,7 @@ public class ParserData } } - public void add_file_content (final Origin origin, final String filename) + public void add_file_content (final Origin origin, String filename) throws IOException, ParsingError { final CommonTokenStream tokens; diff --git a/src/core/src/tonkadur/parser/Context.java b/src/core/src/tonkadur/parser/Context.java index f99ad2b..6f0a64c 100644 --- a/src/core/src/tonkadur/parser/Context.java +++ b/src/core/src/tonkadur/parser/Context.java @@ -13,7 +13,12 @@ public class Context static { - BASE_LANGUAGE = new Context(null, ""); + BASE_LANGUAGE = + new Context + ( + Paths.get(System.getProperty("user.dir")), + "" + ); } /***************************************************************************/ diff --git a/src/core/src/tonkadur/parser/Location.java b/src/core/src/tonkadur/parser/Location.java index af89e7b..1b4ae0a 100644 --- a/src/core/src/tonkadur/parser/Location.java +++ b/src/core/src/tonkadur/parser/Location.java @@ -1,6 +1,7 @@ package tonkadur.parser; import java.nio.file.Path; +import java.nio.file.Paths; public class Location { @@ -11,7 +12,15 @@ public class Location static { - BASE_LANGUAGE = new Location(true, null, "", -1, -1); + BASE_LANGUAGE = + new Location + ( + true, + Paths.get(System.getProperty("user.dir")), + "", + -1, + -1 + ); } /***************************************************************************/ -- cgit v1.2.3-70-g09d2