├── .gitignore
├── .project
├── .travis.yml
├── LICENSE.md
├── README.md
├── pom.xml
├── recaf-desugar
├── .classpath
├── .project
├── META-INF
│ ├── MANIFEST.MF
│ └── RASCAL.MF
├── build.properties
├── input-paper
│ ├── TestDebug.recaf
│ ├── TestQL.recaf
│ └── TestUsingWithError.recaf
├── input
│ ├── BaseTestExprFieldSuper.recaf
│ ├── BaseTestExprInvokeSuper.recaf
│ ├── PStream.recaf
│ ├── TestAsyncComplex.recaf
│ ├── TestAsyncComplex2.recaf
│ ├── TestAsyncNoAwait.recaf
│ ├── TestAsyncWithAwait.recaf
│ ├── TestBacktracking.recaf
│ ├── TestComeFrom.recaf
│ ├── TestCoroutine.recaf
│ ├── TestDef.recaf
│ ├── TestExprAnd.recaf
│ ├── TestExprFieldSuper.recaf
│ ├── TestExprInheritanceMethodLookup.recaf
│ ├── TestExprInvokeSuper.recaf
│ ├── TestExprNoConstructor.recaf
│ ├── TestExprPlus.recaf
│ ├── TestExprPrivateConstructor.recaf
│ ├── TestExprSimpleMethodLookup.recaf
│ ├── TestFibIter.recaf
│ ├── TestFibIter2.recaf
│ ├── TestFibMemo.recaf
│ ├── TestFibRecAsync.recaf
│ ├── TestFor_noBreak.recaf
│ ├── TestFor_ordinary.recaf
│ ├── TestFor_withBreak.recaf
│ ├── TestGUI.recaf
│ ├── TestGUI2.recaf
│ ├── TestIter.recaf
│ ├── TestIter_YieldEachRec.recaf
│ ├── TestLocals.recaf
│ ├── TestMaybe.recaf
│ ├── TestOrElse.recaf
│ ├── TestPEG.recaf
│ ├── TestPropagate.recaf
│ ├── TestPullStreams.recaf
│ ├── TestSWUL.recaf
│ ├── TestSecurity.recaf
│ ├── TestSimple.recaf
│ ├── TestSolve.recaf
│ ├── TestSolve_alldifferent.recaf
│ ├── TestStream_Complex.recaf
│ ├── TestStream_with_await.recaf
│ ├── TestStream_with_awaitFor.recaf
│ ├── TestStream_with_yield.recaf
│ ├── TestStream_with_yieldFrom.recaf
│ ├── TestSwitch_break_default_beginning.recaf
│ ├── TestSwitch_break_first.recaf
│ ├── TestSwitch_break_second.recaf
│ ├── TestSwitch_break_second_withdefault.recaf
│ ├── TestSwitch_nested_default_beginning.recaf
│ ├── TestSwitch_no_break.recaf
│ ├── TestUsing.recaf
│ ├── TestWeb.recaf
│ ├── TestWhile_no_break.recaf
│ └── TestWhile_withBreak.recaf
├── pom.xml
└── src
│ ├── Plugin.rsc
│ └── lang
│ ├── java
│ └── Java8.rsc
│ └── recaf
│ ├── DesugarMain.rsc
│ ├── Recaf.rsc
│ ├── TypeCheck.rsc
│ └── desugar
│ ├── Expr.rsc
│ ├── RecafFull.rsc
│ ├── RecafStmts.rsc
│ ├── Recaffeinate.rsc
│ ├── Stmt.rsc
│ └── Util.rsc
├── recaf-runtime
├── .classpath
├── .project
├── build.properties
├── libs
│ └── rascal-shell-stable.jar
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── recaf
│ │ ├── core
│ │ ├── ISupply.java
│ │ ├── Ref.java
│ │ ├── alg
│ │ │ ├── JavaExprAlg.java
│ │ │ ├── JavaMethodAlg.java
│ │ │ ├── JavaStmtAlg.java
│ │ │ └── JavaStmtOnlyAlg.java
│ │ ├── cps
│ │ │ ├── CD.java
│ │ │ ├── EvalJavaStmt.java
│ │ │ ├── K.java
│ │ │ ├── K0.java
│ │ │ ├── SD.java
│ │ │ └── StmtJavaCPS.java
│ │ ├── direct
│ │ │ ├── EvalJavaStmt.java
│ │ │ ├── ICase.java
│ │ │ ├── IEval.java
│ │ │ ├── IExec.java
│ │ │ └── StmtJavaDirect.java
│ │ ├── expr
│ │ │ ├── EvalJavaExpr.java
│ │ │ ├── EvalJavaHelper.java
│ │ │ ├── IRef.java
│ │ │ └── ReflectRef.java
│ │ └── full
│ │ │ ├── FullJavaCPS.java
│ │ │ ├── FullJavaDirect.java
│ │ │ └── JavaStmtAlgAdapter.java
│ │ ├── demo
│ │ ├── constraint
│ │ │ └── Solve.java
│ │ ├── cps
│ │ │ ├── Async.java
│ │ │ ├── AsyncFull.java
│ │ │ ├── Backtrack.java
│ │ │ ├── ComeFrom.java
│ │ │ ├── Coroutine.java
│ │ │ ├── Iter.java
│ │ │ ├── IterFull.java
│ │ │ ├── Maybe.java
│ │ │ ├── ParFor.java
│ │ │ ├── Propagate.java
│ │ │ └── StreamExt.java
│ │ ├── direct
│ │ │ ├── App.java
│ │ │ ├── GUI.java
│ │ │ ├── LINQ.java
│ │ │ ├── Logging.java
│ │ │ ├── Maybe.java
│ │ │ ├── Memo.java
│ │ │ ├── MemoizableCall.java
│ │ │ ├── OrElse.java
│ │ │ ├── Policy.java
│ │ │ ├── Security.java
│ │ │ ├── Student.java
│ │ │ ├── StudentPolicy.java
│ │ │ └── Using.java
│ │ ├── generic
│ │ │ ├── Times.java
│ │ │ ├── Unless.java
│ │ │ └── Until.java
│ │ ├── pegs
│ │ │ ├── Fail.java
│ │ │ ├── MemoPEG.java
│ │ │ ├── PEG.java
│ │ │ ├── PEGwithLayout.java
│ │ │ ├── Parser.java
│ │ │ └── Result.java
│ │ ├── swul
│ │ │ └── SWUL.java
│ │ └── web
│ │ │ └── Web.java
│ │ └── paper
│ │ ├── access
│ │ ├── Policy.java
│ │ ├── Security.java
│ │ └── StudentPolicy.java
│ │ ├── demo
│ │ ├── Backtrack.java
│ │ ├── BacktrackFull.java
│ │ ├── Debug.java
│ │ ├── GUI.java
│ │ ├── GUIImpl.java
│ │ ├── Goto.java
│ │ ├── HTTPRequest.java
│ │ ├── HTTPResponse.java
│ │ ├── Maybe.java
│ │ ├── Memo.java
│ │ ├── OrElse.java
│ │ ├── Times.java
│ │ ├── ToAST.java
│ │ ├── ToJS.java
│ │ ├── Tracing.java
│ │ ├── Unless.java
│ │ └── ast
│ │ │ ├── Decl.java
│ │ │ ├── Empty.java
│ │ │ ├── Exp.java
│ │ │ ├── Expr.java
│ │ │ ├── Field.java
│ │ │ ├── For.java
│ │ │ ├── If.java
│ │ │ ├── Invoke.java
│ │ │ ├── Lambda.java
│ │ │ ├── Lit.java
│ │ │ ├── New.java
│ │ │ ├── Return.java
│ │ │ ├── Seq.java
│ │ │ ├── Stm.java
│ │ │ ├── This.java
│ │ │ └── Var.java
│ │ ├── expr
│ │ ├── IEval.java
│ │ ├── MuExpJava.java
│ │ ├── MuExpJavaBase.java
│ │ ├── MuExpJavaZip.java
│ │ ├── Pair.java
│ │ ├── Print.java
│ │ ├── PrintAndEval.java
│ │ └── PrintAndEvalManual.java
│ │ ├── full
│ │ ├── FullMuJava.java
│ │ ├── FullMuJavaCPS.java
│ │ ├── FullMuJavaCPSManual.java
│ │ ├── FullMuJavaDirect.java
│ │ ├── FullMuJavaDirectManual.java
│ │ ├── MuStmIEvalJavaAdapter.java
│ │ ├── MuStmJava.java
│ │ ├── MuStmJavaAdapter.java
│ │ ├── MuStmJavaManualAdapter.java
│ │ └── MuStmPrintEvalAdapter.java
│ │ ├── methods
│ │ ├── MuJavaMethod.java
│ │ ├── TPCPS.java
│ │ ├── TPDirect.java
│ │ └── ToOptional.java
│ │ └── stm
│ │ ├── IExec.java
│ │ ├── MuJava.java
│ │ ├── MuJavaBase.java
│ │ ├── MuJavaCPS.java
│ │ ├── Return.java
│ │ └── SD.java
│ ├── test-generated
│ └── generated
│ │ ├── BaseTestExprFieldSuper.java
│ │ ├── BaseTestExprInvokeSuper.java
│ │ ├── PStream.java
│ │ ├── TestAsyncComplex.java
│ │ ├── TestAsyncComplex2.java
│ │ ├── TestAsyncNoAwait.java
│ │ ├── TestAsyncWithAwait.java
│ │ ├── TestBacktracking.java
│ │ ├── TestComeFrom.java
│ │ ├── TestCoroutine.java
│ │ ├── TestDebug.java
│ │ ├── TestDef.java
│ │ ├── TestExprAnd.java
│ │ ├── TestExprFieldSuper.java
│ │ ├── TestExprInheritanceMethodLookup.java
│ │ ├── TestExprInvokeSuper.java
│ │ ├── TestExprNoConstructor.java
│ │ ├── TestExprPlus.java
│ │ ├── TestExprPrivateConstructor.java
│ │ ├── TestExprSimpleMethodLookup.java
│ │ ├── TestFibIter.java
│ │ ├── TestFibIter2.java
│ │ ├── TestFibMemo.java
│ │ ├── TestFibRecAsync.java
│ │ ├── TestFor_noBreak.java
│ │ ├── TestFor_ordinary.java
│ │ ├── TestFor_withBreak.java
│ │ ├── TestGUI.java
│ │ ├── TestGUI2.java
│ │ ├── TestIter.java
│ │ ├── TestIter_YieldEachRec.java
│ │ ├── TestLocals.java
│ │ ├── TestMaybe.java
│ │ ├── TestOrElse.java
│ │ ├── TestPEG.java
│ │ ├── TestPropagate.java
│ │ ├── TestPullStreams.java
│ │ ├── TestQL.java
│ │ ├── TestSWUL.java
│ │ ├── TestSecurity.java
│ │ ├── TestSimple.java
│ │ ├── TestSolve.java
│ │ ├── TestSolve_alldifferent.java
│ │ ├── TestStream_Complex.java
│ │ ├── TestStream_with_await.java
│ │ ├── TestStream_with_awaitFor.java
│ │ ├── TestStream_with_yield.java
│ │ ├── TestStream_with_yieldFrom.java
│ │ ├── TestSwitch_break_default_beginning.java
│ │ ├── TestSwitch_break_first.java
│ │ ├── TestSwitch_break_second.java
│ │ ├── TestSwitch_break_second_withdefault.java
│ │ ├── TestSwitch_nested_default_beginning.java
│ │ ├── TestSwitch_no_break.java
│ │ ├── TestUsing.java
│ │ ├── TestUsingWithError.java
│ │ ├── TestWeb.java
│ │ ├── TestWhile_no_break.java
│ │ └── TestWhile_withBreak.java
│ └── test
│ ├── java
│ └── recaf
│ │ └── tests
│ │ ├── BaseTest.java
│ │ ├── CompiletimeException.java
│ │ ├── Log4jTestWatcher.java
│ │ ├── RascalModuleRunner.java
│ │ ├── extensions
│ │ ├── TestAsyncExtension.java
│ │ ├── TestBacktrackingExtension.java
│ │ ├── TestIterExtension.java
│ │ ├── TestMaybeExtension.java
│ │ ├── TestSolveExtension.java
│ │ ├── TestStreamExtension.java
│ │ └── TestUsingExtension.java
│ │ └── virtualization
│ │ ├── TestVirtualization.java
│ │ └── TestVirtualizationExpressions.java
│ └── resources
│ ├── log4j2.xml
│ └── test
├── resources
├── SWUL.png
└── recaf.png
├── testgen
└── testnogen
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/eclipse
3 |
4 | ### Eclipse ###
5 | *.pydevproject
6 | .metadata
7 | bin/
8 | tmp/
9 | *.tmp
10 | *.bak
11 | *.swp
12 | *~.nib
13 | local.properties
14 | .settings/
15 | .loadpath
16 |
17 | # Eclipse Core
18 | # .project
19 |
20 | # External tool builders
21 | .externalToolBuilders/
22 |
23 | # Locally stored "Eclipse launch configurations"
24 | *.launch
25 |
26 | # CDT-specific
27 | .cproject
28 |
29 | # JDT-specific (Eclipse Java Development Tools)
30 | # .classpath
31 |
32 | # Java annotation processor (APT)
33 | .factorypath
34 |
35 | # PDT-specific
36 | .buildpath
37 |
38 | # sbteclipse plugin
39 | .target
40 |
41 | # TeXlipse plugin
42 | .texlipse
43 |
44 | # STS (Spring Tool Suite)
45 | .springBeans
46 |
47 | ### Emacs ###
48 | # -*- mode: gitignore; -*-
49 | *~
50 | \#*\#
51 | /.emacs.desktop
52 | /.emacs.desktop.lock
53 | *.elc
54 | auto-save-list
55 | tramp
56 | .\#*
57 |
58 | # Org-mode
59 | .org-id-locations
60 | *_archive
61 |
62 | # flymake-mode
63 | *_flymake.*
64 |
65 | # eshell files
66 | /eshell/history
67 | /eshell/lastdir
68 |
69 | # elpa packages
70 | /elpa/
71 |
72 | # reftex files
73 | *.rel
74 |
75 | # AUCTeX auto folder
76 | /auto/
77 |
78 | # cask packages
79 | .cask/
80 |
81 | ### Java ###
82 | *.class
83 |
84 | # Mobile Tools for Java (J2ME)
85 | .mtj.tmp/
86 |
87 | # Package Files #
88 | *.jar
89 | *.war
90 | *.ear
91 |
92 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
93 | hs_err_pid*
94 |
95 | .DS_Store
96 | *.DS_Store
97 | */.DS_Store
98 |
99 | target/
100 |
101 | */*.log
102 |
103 | */BenchmarkList
104 | */CompilerHints
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | recaf
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.m2e.core.maven2Builder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.m2e.core.maven2Nature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | script: mvn -DGEN=false clean dependency:copy-dependencies test
7 |
8 | notifications:
9 | email: false
10 | webhooks:
11 | urls:
12 | - https://webhooks.gitter.im/e/2112ed37cf625ee2e486
13 | on_success: always # options: [always|never|change] default: always
14 | on_failure: always # options: [always|never|change] default: always
15 | on_start: false # default: false
16 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 CWI - Software Analysis and Transformation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.cwi-swat
8 | recaf
9 | 1.0-SNAPSHOT
10 | pom
11 |
12 |
13 | recaf-runtime
14 | recaf-desugar
15 |
16 |
--------------------------------------------------------------------------------
/recaf-desugar/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/recaf-desugar/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | recaf-desugar
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | rascal_eclipse.rascal_builder
15 |
16 |
17 |
18 |
19 | rascal_eclipse.term_builder
20 |
21 |
22 |
23 |
24 | org.eclipse.pde.ManifestBuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.pde.SchemaBuilder
30 |
31 |
32 |
33 |
34 | org.eclipse.m2e.core.maven2Builder
35 |
36 |
37 |
38 |
39 |
40 | org.eclipse.m2e.core.maven2Nature
41 | rascal_eclipse.rascal_nature
42 | org.eclipse.jdt.core.javanature
43 | org.eclipse.pde.PluginNature
44 | rascal_eclipse.term_nature
45 |
46 |
47 |
--------------------------------------------------------------------------------
/recaf-desugar/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Bundle-ManifestVersion: 2
3 | Bundle-Name: recaf
4 | Bundle-SymbolicName: recaf
5 | Bundle-Version: 1.0.0
6 | Require-Bundle: rascal
7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 |
--------------------------------------------------------------------------------
/recaf-desugar/META-INF/RASCAL.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 0.0.1
2 | Main-Function: main
3 | Main-Module: Plugin
4 | Source: src
5 |
6 |
--------------------------------------------------------------------------------
/recaf-desugar/build.properties:
--------------------------------------------------------------------------------
1 | bin.includes = META-INF/
2 |
--------------------------------------------------------------------------------
/recaf-desugar/input-paper/TestDebug.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import recaf.paper.demo.Debug;
4 |
5 | public class TestDebug {
6 | private static recaf Debug alg = new Debug() {};
7 |
8 | public int x = 3;
9 |
10 | public int dup(int x){
11 | return 2*x;
12 | }
13 |
14 | private recaff Integer simple(){
15 | debug! this.dup(this.x);
16 | return this.dup(this.x);
17 | }
18 |
19 |
20 | public static void main(String args[]) {
21 | TestDebug s = new TestDebug();
22 | int n = s.simple();
23 | System.out.println(n);
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/recaf-desugar/input-paper/TestQL.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 | /*
3 | import recaf.demo.ql.QL;
4 |
5 | public class TestQL {
6 |
7 | private recaf QL alg;
8 |
9 | public TestQL(QL alg) {
10 | this.alg = alg;
11 | }
12 |
13 | public recaf void taxOffice() {
14 | // todo: fix boxing of formal params in binders.
15 | question "Did you sell a house in 2010?", Boolean hasSoldHouse;
16 | question "Did you buy a house in 2010?", Boolean hasBoughtHouse;
17 | question "Did you enter a loan?", Boolean hasMaintLoan;
18 | if (hasSoldHouse) {
19 | question "What was the selling price?", Integer sellingPrice;
20 | question "Private debts for the sold house:", Integer privateDebt;
21 | question "Value residue:", Integer valueResidue = sellingPrice - privateDebt;
22 | }
23 | }
24 |
25 | }*/
--------------------------------------------------------------------------------
/recaf-desugar/input-paper/TestUsingWithError.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import recaf.core.direct.IExec;
4 | import recaf.demo.direct.Using;
5 | import java.io.BufferedReader;
6 | import java.io.FileNotFoundException;
7 | import java.io.FileReader;
8 | import java.io.IOException;
9 |
10 | public class TestUsingWithError {
11 |
12 | private static recaf Using alg = new Using() {};
13 |
14 | static recaf String usingExample(String path) {
15 | using (BufferedReader br : new BufferedReader(new FileReader(path))){
16 | return br.readLine();
17 | }
18 | }
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | public static void main(String args[]) {
37 | System.out.println(new TestUsing().usingExample("src/test-generated/README.md"));
38 | }
39 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/BaseTestExprFieldSuper.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | public class BaseTestExprFieldSuper{
4 |
5 | protected int x = 3;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/recaf-desugar/input/BaseTestExprInvokeSuper.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | public class BaseTestExprInvokeSuper{
4 |
5 | @Override
6 | public String toString(){
7 | return "BaseTestExprInvokeSuper";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/recaf-desugar/input/TestAsyncComplex.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 | import java.util.concurrent.CompletableFuture;
3 | import java.util.concurrent.ExecutionException;
4 | import recaf.demo.cps.Async;
5 |
6 | public class TestAsyncComplex {
7 |
8 | private static recaf Async alg = new Async() {};
9 |
10 | public static void pause(long sleeptime) {
11 | try {
12 | Thread.sleep(sleeptime);
13 | } catch (InterruptedException ex) { }
14 | }
15 |
16 | public static Void print(String msg) {
17 | System.out.println(msg);
18 | return null;
19 | }
20 |
21 | recaf CompletableFuture op() {
22 | if (1 < 2) {
23 | pause(2500);
24 | print("delayed op");
25 | return 42;
26 | }
27 | return 41;
28 | }
29 |
30 | recaf CompletableFuture op2() {
31 | if (1 < 2) {
32 | await Integer x = op();
33 | await Integer y = op();
34 | return x + y;
35 | }
36 | pause(5000);
37 | return 41;
38 | }
39 |
40 | public static void main(String[] args) throws InterruptedException, ExecutionException{
41 | CompletableFuture answer;
42 |
43 | answer = new TestAsyncComplex().op2();
44 |
45 | print("main");
46 |
47 | System.out.println(answer.get());
48 | }
49 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestAsyncComplex2.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 | import java.util.concurrent.CompletableFuture;
3 | import java.util.concurrent.ExecutionException;
4 | import recaf.demo.cps.AsyncFull;
5 |
6 | class MyPrinter{
7 | public MyPrinter(){}
8 |
9 | public Void print(String msg) {
10 | System.out.println(msg);
11 | return null;
12 | }
13 | }
14 |
15 | public class TestAsyncComplex2 {
16 |
17 | private static recaf AsyncFull alg = new AsyncFull() {};
18 |
19 | public Void pause(Integer sleeptime) {
20 | try {
21 | new Thread().sleep(sleeptime);
22 | return null;
23 | } catch (InterruptedException ex) {
24 | return null;
25 | }
26 | }
27 |
28 |
29 | recaff CompletableFuture op() {
30 | if (1 < 2) {
31 | pause(2500);
32 | new MyPrinter().print("delayed op");
33 | return 42;
34 | }
35 | return 41;
36 | }
37 |
38 | recaff CompletableFuture op2() {
39 | if (1 < 2) {
40 | await Integer x = op();
41 | await Integer y = op();
42 | return x + y;
43 | }
44 | pause(5000);
45 | return 41;
46 | }
47 |
48 | public static void main(String[] args) throws InterruptedException, ExecutionException{
49 | CompletableFuture answer;
50 |
51 | answer = new TestAsyncComplex2().op2();
52 |
53 | new MyPrinter().print("main");
54 |
55 | System.out.println(answer.get());
56 | }
57 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestAsyncNoAwait.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 | import java.util.concurrent.CompletableFuture;
3 | import java.util.concurrent.ExecutionException;
4 | import recaf.demo.cps.Async;
5 |
6 | public class TestAsyncNoAwait {
7 | private static recaf Async alg = new Async() {};
8 |
9 | recaf CompletableFuture op() {
10 | if (1 > 5) {
11 | return 42;
12 | }
13 | return 41;
14 | }
15 |
16 | public static void main(String[] args) throws InterruptedException, ExecutionException{
17 | Integer answer = new TestAsyncNoAwait().op().get();
18 |
19 | System.out.println(answer);
20 | }
21 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestAsyncWithAwait.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 | import java.util.concurrent.CompletableFuture;
3 | import java.util.concurrent.ExecutionException;
4 | import recaf.demo.cps.Async;
5 |
6 | public class TestAsyncWithAwait {
7 | private static recaf Async alg = new Async() {};
8 |
9 | recaf CompletableFuture op() {
10 | if (1 < 2) {
11 | await Integer x = secondOp();
12 | return x;
13 | }
14 | return 41;
15 | }
16 |
17 | recaf CompletableFuture secondOp() {
18 | if (1 < 2) {
19 | return 42;
20 | }
21 | return 41;
22 | }
23 |
24 | public static void main(String[] args) throws InterruptedException, ExecutionException{
25 | Integer answer = new TestAsyncWithAwait().op().get();
26 |
27 | System.out.println(answer);
28 | }
29 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestBacktracking.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import java.util.List;
4 | import recaf.demo.cps.Backtrack;
5 | import static java.util.Arrays.asList;
6 | import java.util.stream.IntStream;
7 | import java.util.Iterator;
8 |
9 | public class TestBacktracking {
10 |
11 | static class Pair {
12 | int x, y;
13 | Pair(int x, int y) {
14 | this.x = x;
15 | this.y = y;
16 | }
17 | public String toString() {
18 | return "(" + x + ", " + y + ")";
19 | }
20 | }
21 |
22 | static List solve(recaf Backtrack alg) {
23 | choose Integer x = asList(1, 2, 3);
24 | System.err.println("Choice 1: " + x);
25 | choose Integer y = asList(4, 5, 6);
26 | System.err.println("Choice 2: " + y);
27 | if (x * y == 8) {
28 | return new Pair(x, y);
29 | }
30 | }
31 |
32 | static Iterable range(int n) {
33 | return new Iterable() {
34 | public Iterator iterator() {
35 | return IntStream.range(0, n).iterator();
36 | }
37 | };
38 | }
39 |
40 | public static void main(String args[]) {
41 | System.out.println(solve(new Backtrack()));
42 | }
43 |
44 |
45 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestComeFrom.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import recaf.demo.cps.ComeFrom;
4 | import java.util.Scanner;
5 |
6 | public class TestComeFrom {
7 |
8 | // from wikipedia
9 | static Void repl(recaf ComeFrom cf) {
10 | comeFrom! "l40";
11 | System.out.println("What is your name?");
12 | Scanner scanner = new Scanner(System.in);
13 | String name = scanner.next();
14 | System.out.println("Hello, " + name);
15 | l40: ;
16 | }
17 |
18 | public static void main(String[] args) {
19 | repl(new ComeFrom());
20 | }
21 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestCoroutine.recaf:
--------------------------------------------------------------------------------
1 |
2 | package generated;
3 |
4 | import recaf.demo.cps.Coroutine;
5 | import java.util.Random;
6 |
7 |
8 | public class TestCoroutine {
9 |
10 | static void producer(Coroutine.Co other) throws InterruptedException {
11 | while (true) {
12 | Thread.sleep(1000);
13 | int data = (new Random()).nextInt();
14 | System.out.println("Sending " + data);
15 | System.out.println("Producer received: " + other.resume(data));
16 | }
17 | }
18 |
19 | static Coroutine.Co consumer(recaf Coroutine alg) {
20 | int i = 0;
21 | while (true) {
22 | Integer x = yield! i++;
23 | System.out.println("consumer received: " + x);
24 | yield! 2 * i++;
25 | }
26 | }
27 |
28 | public static void main(String args[]) throws InterruptedException {
29 | Coroutine.Co coro = consumer(new Coroutine());
30 | coro.run();
31 | producer(coro);
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestDef.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import recaf.core.full.FullJavaDirect;
4 |
5 |
6 | public class TestDef {
7 | private static recaf FullJavaDirect alg = new FullJavaDirect() {};
8 |
9 | static recaf void doSomething() {
10 | int sum = 0;
11 | for (int i = 0; i < 10; i++) {
12 | if (i % 2 == 0) {
13 | sum += i;
14 | }
15 | }
16 | System.out.println("sum = " + sum);
17 | }
18 |
19 | public static void main(String args[]) {
20 | doSomething();
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/recaf-desugar/input/TestExprAnd.recaf:
--------------------------------------------------------------------------------
1 | package generated;
2 |
3 | import recaf.core.full.FullJavaDirect;
4 |
5 | public class TestExprAnd {
6 |
7 | private int i = 0;
8 |
9 | private static recaf FullJavaDirect