├── src
├── test
│ ├── resources
│ │ ├── compile
│ │ │ └── list.cafe
│ │ ├── parse-test
│ │ │ ├── error_test
│ │ │ │ ├── for_loop_error.cafe
│ │ │ │ └── slice_subscript_error.cafe
│ │ │ ├── slice_subscript.cafe
│ │ │ └── if_else.cafe
│ │ ├── compile-and-execute
│ │ │ ├── for_loop.cafe
│ │ │ ├── ann_func.cafe
│ │ │ ├── function_call.cafe
│ │ │ ├── default_import_object_test.cafe
│ │ │ ├── bind_args.cafe
│ │ │ ├── closure.cafe
│ │ │ ├── missing_pop_if_else.cafe
│ │ │ └── list.cafe
│ │ └── ann-func-test
│ │ │ ├── anonymous_func_export.cafe
│ │ │ ├── anonymous_func_import.cafe
│ │ │ └── as-closure
│ │ │ ├── ann_func_import.cafe
│ │ │ └── ann_func_export.cafe
│ └── java
│ │ ├── compiler
│ │ ├── CompileTest.java
│ │ ├── CompileAndExecuteTest.java
│ │ ├── gen
│ │ │ └── AnnFuncNameGeneratorTest.java
│ │ ├── CompileAndCheckTest.java
│ │ └── parser
│ │ │ └── MainParserTest.java
│ │ └── testing
│ │ └── Utils.java
└── main
│ └── java
│ ├── compiler
│ ├── ast
│ │ ├── package-info.java
│ │ ├── TreeVisitor.java
│ │ └── Tree.java
│ ├── main
│ │ ├── package-info.java
│ │ ├── cli
│ │ │ ├── CompileCommand.java
│ │ │ └── Command.java
│ │ └── SourceFileManager.java
│ ├── util
│ │ ├── package-info.java
│ │ ├── Context.java
│ │ ├── Position.java
│ │ └── Log.java
│ ├── parser
│ │ ├── package-info.java
│ │ ├── Lexer.java
│ │ ├── Parser.java
│ │ ├── ParserType.java
│ │ ├── Scanner.java
│ │ ├── ScannerFactory.java
│ │ ├── ParserFactory.java
│ │ └── CharReader.java
│ ├── ir
│ │ ├── TargetFuncWrapper.java
│ │ ├── AssignedStatement.java
│ │ ├── NullStatement.java
│ │ ├── ExpressionStatement.java
│ │ ├── CafeStatement.java
│ │ ├── ThisStatement.java
│ │ ├── CafeClosure.java
│ │ ├── PropertyAccess.java
│ │ ├── FunctionWrapper.java
│ │ ├── CafeExport.java
│ │ ├── CafeElement.java
│ │ ├── ListCollection.java
│ │ ├── SubscriptExpression.java
│ │ ├── AnonymousFunction.java
│ │ ├── ReferenceLookup.java
│ │ ├── BreakContinueStatement.java
│ │ ├── ObjectCreationStatement.java
│ │ ├── CafeImport.java
│ │ ├── ConstantStatement.java
│ │ ├── ReturnStatement.java
│ │ ├── UnaryExpression.java
│ │ ├── OperatorType.java
│ │ ├── DeclarativeAssignmentStatement.java
│ │ ├── SliceExpression.java
│ │ ├── ObjectAccessStatement.java
│ │ ├── ReferenceTable.java
│ │ ├── AssignmentStatement.java
│ │ ├── BinaryExpression.java
│ │ ├── SymbolReference.java
│ │ ├── MethodInvocation.java
│ │ ├── FunctionInvocation.java
│ │ ├── CafeIrVisitor.java
│ │ ├── ForLoopStatement.java
│ │ └── Block.java
│ ├── Main.java
│ ├── analyzer
│ │ ├── Symbol.java
│ │ └── SymbolTable.java
│ └── gen
│ │ └── JVMBytecodeUtils.java
│ ├── library
│ ├── base
│ │ ├── CFunc.java
│ │ ├── CList.java
│ │ ├── CObjectProto.java
│ │ ├── CObject.java
│ │ ├── CListProto.java
│ │ └── CFuncProto.java
│ ├── Slicable.java
│ ├── Subscriptable.java
│ ├── io
│ │ └── BasicIO.java
│ ├── DFunc.java
│ └── DList.java
│ └── runtime
│ ├── imports
│ ├── ImportPathVisitor.java
│ ├── ModulePath.java
│ ├── JavaModulePath.java
│ └── CafeModulePath.java
│ ├── Runtime.java
│ ├── ReferenceSymbol.java
│ ├── ExportMap.java
│ ├── indy
│ ├── FunctionReferenceID.java
│ └── FunctionInvocationID.java
│ ├── ReferenceTable.java
│ ├── CafeURLClassLoader.java
│ └── JavaImports.java
├── lib
└── asm-7.3.1.jar
├── gradle
├── innosetup
│ ├── logo.ico
│ ├── iscc
│ ├── innoinstall.sh
│ └── cafe_exe_compiler.iss
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── examples
├── Closure.cafe
├── List.cafe
├── Object.cafe
└── merge_sort.cafe
├── .gitattributes
├── .gitignore
├── COPYRIGHT-examples
├── settings.gradle
├── THIRD-PARTY
├── README.md
├── gradlew.bat
└── .github
└── workflows
└── build-and-release.yml
/src/test/resources/compile/list.cafe:
--------------------------------------------------------------------------------
1 | var x = {};
2 | var l = [1,[2,3],"string", x];
--------------------------------------------------------------------------------
/lib/asm-7.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cafe-jvm-lang/cafe/HEAD/lib/asm-7.3.1.jar
--------------------------------------------------------------------------------
/src/test/resources/parse-test/error_test/for_loop_error.cafe:
--------------------------------------------------------------------------------
1 | for(var i=0 i<10;){
2 |
3 | }
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/for_loop.cafe:
--------------------------------------------------------------------------------
1 | for(var i=0;i<10;i=i+1){
2 | var j;
3 | }
--------------------------------------------------------------------------------
/gradle/innosetup/logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cafe-jvm-lang/cafe/HEAD/gradle/innosetup/logo.ico
--------------------------------------------------------------------------------
/src/test/resources/ann-func-test/anonymous_func_export.cafe:
--------------------------------------------------------------------------------
1 | export var a = func(){
2 | return "Hello";
3 | };
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/ann_func.cafe:
--------------------------------------------------------------------------------
1 | var a = func(){
2 | return "Hello";
3 | };
4 |
5 | a();
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/function_call.cafe:
--------------------------------------------------------------------------------
1 | func A(){
2 | cmd.println("Hello");
3 | }
4 |
5 | A();
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cafe-jvm-lang/cafe/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/src/test/resources/parse-test/error_test/slice_subscript_error.cafe:
--------------------------------------------------------------------------------
1 | var l = [1,[2,3],"string", x];
2 | var r1 = l[0:];
3 | l[0:1] = r;
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/default_import_object_test.cafe:
--------------------------------------------------------------------------------
1 | cmd.println(Object.__proto__);
2 | cmd.println(Function.__proto__);
--------------------------------------------------------------------------------
/examples/Closure.cafe:
--------------------------------------------------------------------------------
1 | func A(){
2 | func B(){
3 | cmd.println("In B");
4 | }
5 | return B;
6 | }
7 |
8 | var a = A();
9 | a();
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/bind_args.cafe:
--------------------------------------------------------------------------------
1 | func a(b,c){
2 | cmd.println(b);
3 | }
4 |
5 | var z = {h:"inside z"};
6 | var q = a.bind(z,1);
7 | q(3);
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/closure.cafe:
--------------------------------------------------------------------------------
1 | func A(){
2 | func B(){
3 | cmd.println("In B");
4 | }
5 | return B;
6 | }
7 |
8 | var a = A();
9 | a();
--------------------------------------------------------------------------------
/src/test/resources/ann-func-test/anonymous_func_import.cafe:
--------------------------------------------------------------------------------
1 | import a from "./src/test/resources/ann-func-test/anonymous_func_export";
2 |
3 | export func test(){
4 | return a();
5 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | #
2 | # https://help.github.com/articles/dealing-with-line-endings/
3 | #
4 | # These are explicitly windows files and should use crlf
5 | *.bat text eol=crlf
6 |
7 |
--------------------------------------------------------------------------------
/gradle/innosetup/iscc:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -x
3 | unset DISPLAY
4 | scriptname=$1
5 | [ -f "$scriptname" ] && scriptname=$(winepath -w "$scriptname")
6 | wine "C:\inno\ISCC.exe" "$scriptname" "/q"
7 |
--------------------------------------------------------------------------------
/src/test/resources/ann-func-test/as-closure/ann_func_import.cafe:
--------------------------------------------------------------------------------
1 | import z as a from "./src/test/resources/ann-func-test/as-closure/ann_func_export";
2 |
3 | export func test(){
4 | return a();
5 | }
--------------------------------------------------------------------------------
/src/test/resources/parse-test/slice_subscript.cafe:
--------------------------------------------------------------------------------
1 | var x = {a:10};
2 | var l = [1,[2,3],"string", x];
3 | cmd.println(x[z]);
4 | # var r = l[a:b()];
5 | var r1 = l[0:4];
6 | var r = l[2:b()];
7 | l[0:1] = r;
--------------------------------------------------------------------------------
/src/test/resources/ann-func-test/as-closure/ann_func_export.cafe:
--------------------------------------------------------------------------------
1 | var a = func(){
2 | return func(){
3 | return "inside closure";
4 | };
5 | };
6 |
7 | export var z = a();
8 |
--------------------------------------------------------------------------------
/gradle/innosetup/innoinstall.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -x
3 |
4 | rm -rf /tmp/inno
5 | mkdir /tmp/inno
6 | cd /tmp/inno
7 |
8 | wget -O is.exe http://files.jrsoftware.org/is/5/isetup-5.5.5.exe
9 | innoextract is.exe
10 | mkdir -p ~/".wine/drive_c/inno"
11 | cp -R app/* ~/".wine/drive_c/inno"
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
3 | # Ignore Gradle project-specific cache directory
4 | .gradle
5 |
6 | # Ignore Gradle build output directory
7 | build
8 |
9 | # Eclipse Core
10 | .project
11 |
12 | # JDT-specific (Eclipse Java Development Tools)
13 | .classpath
14 |
15 | cp.cafe
16 | /.idea/
17 | /.vscode/
18 | /.settings/
19 |
--------------------------------------------------------------------------------
/examples/List.cafe:
--------------------------------------------------------------------------------
1 | var x = {a:10};
2 | var z = "string";
3 | var l = [1,[2,3],z];
4 | l[1][0] = "new";
5 | cmd.println(l);
6 |
7 | x["l"] = l;
8 | x.l[1][0] = "new 2";
9 | x.l[0:1] = 3;
10 | cmd.println(x);
11 |
12 | cmd.println(l[1:3]);
13 | l[2:3] = ["slice1","slice2"];
14 | cmd.println(l);
15 |
16 | l[0:3] = "a";
17 | cmd.println(l);
18 |
19 | l.add("last element");
20 | l.remove(z);
21 | l.removeAt(0);
22 | cmd.println(l);
23 |
24 |
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/missing_pop_if_else.cafe:
--------------------------------------------------------------------------------
1 | var acc = {
2 | amount: 0,
3 | updateBal: func(b){
4 | },
5 | withdraw: func(b){
6 | if(this.amount < b){
7 | cmd.println("Insufficient Balance");
8 | cmd.println("Please check");
9 | } else {
10 | cmd.print("Hello");
11 | this.updateBal(-b);
12 | }
13 | }
14 | };
15 |
16 | acc.withdraw(2000);
--------------------------------------------------------------------------------
/src/test/resources/compile-and-execute/list.cafe:
--------------------------------------------------------------------------------
1 | var x = {a:10};
2 | var z = "string";
3 | var l = [1,[2,3],z];
4 | l[1][0] = "new";
5 | cmd.println(l);
6 |
7 | x["l"] = l;
8 | x.l[1][0] = "new 2";
9 | x.l[0:1] = 3;
10 | cmd.println(x);
11 |
12 | cmd.println(l[1:3]);
13 | l[2:3] = ["slice1","slice2"];
14 | cmd.println(l);
15 |
16 | l[0:3] = "a";
17 | cmd.println(l);
18 |
19 | l.add("last element");
20 | l.remove(z);
21 | l.removeAt(0);
22 | cmd.println(l);
23 | cmd.println("Size: "+l.size());
24 |
25 |
--------------------------------------------------------------------------------
/examples/Object.cafe:
--------------------------------------------------------------------------------
1 | var acc = {
2 | init: func(){
3 | this.amount = 0;
4 | },
5 | updateBal: func(amt){
6 | this.amount = this.amount+amt;
7 | },
8 | checkBalance: func(){
9 | cmd.println(this.amount);
10 | },
11 | deposit: func(b){
12 | this.updateBal(b);
13 | },
14 | withdraw: func(b){
15 | if(this.amount < b){
16 | cmd.println("Insufficient Balance");
17 | } else {
18 | updateBal(-b);
19 | }
20 | }
21 | };
22 |
23 | acc.init();
24 | acc.checkBalance();
25 | acc.deposit(1000);
26 | acc.withdraw(2000);
27 | acc.checkBalance();
--------------------------------------------------------------------------------
/COPYRIGHT-examples:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021. The Cafe Authors
3 |
4 | This file is part of Cafe.
5 |
6 | Cafe is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, version 3 of the License.
9 |
10 | Cafe is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with Cafe. If not, see .
17 | */
--------------------------------------------------------------------------------
/src/test/resources/parse-test/if_else.cafe:
--------------------------------------------------------------------------------
1 | var acc = {
2 | init: func(){
3 | this.amount = 0;
4 | },
5 | updateBal: func(amt){
6 | this.amount = this.amount+amt;
7 | },
8 | checkBalance: func(){
9 | cmd.println(this.amount);
10 | },
11 | deposit: func(b){
12 | this.updateBal(b);
13 | },
14 | withdraw: func(b){
15 | if(this.amount < b){
16 | cmd.println("Insufficient Balance");
17 | cmd.println("Please check");
18 | } else {
19 | cmd.print("Hello");
20 | updateBal(-b);
21 | }
22 | }
23 | };
24 |
25 | cmd.println(acc.amount);
26 | acc.init();
27 | acc.checkBalance();
28 | acc.deposit(1000);
29 | acc.withdraw(2000);
30 | acc.checkBalance();
--------------------------------------------------------------------------------
/src/main/java/compiler/ast/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ast;
--------------------------------------------------------------------------------
/src/main/java/compiler/main/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.main;
--------------------------------------------------------------------------------
/src/main/java/compiler/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.util;
--------------------------------------------------------------------------------
/src/main/java/compiler/parser/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.parser;
--------------------------------------------------------------------------------
/examples/merge_sort.cafe:
--------------------------------------------------------------------------------
1 | const merge = func(a,b){
2 | const c = [];
3 |
4 | for(;a.size()> 0 and b.size() > 0;){
5 | var obj;
6 |
7 | if(a.get(0) > b.get(0)){
8 | obj = b.get(0);
9 | b.removeAt(0);
10 | }else{
11 | obj = a.get(0);
12 | a.removeAt(0);
13 | }
14 | c.add(obj);
15 | }
16 |
17 | for(;a.size()>0;){
18 | c.add(a.get(0));
19 | a.removeAt(0);
20 | }
21 |
22 | for(;b.size()>0;){
23 | c.add(b.get(0));
24 | b.removeAt(0);
25 | }
26 |
27 | return c;
28 | },
29 | merge_sort = func(a){
30 | if (a.size() < 2){
31 | return a;
32 | }
33 |
34 | const middle = floor(a.size()/2);
35 | const a_l = a[0:middle];
36 | const a_r = a[middle:a.size()];
37 | const sorted_l = merge_sort(a_l);
38 | const sorted_r = merge_sort(a_r);
39 | return merge(sorted_l, sorted_r);
40 | };
41 |
42 | func floor(a){
43 | const dec = a % 1;
44 | if(dec < 0.5){ a = a-dec; }
45 | else{ a = a + (1-dec); }
46 |
47 | return a;
48 | }
49 |
50 | cmd.println(merge_sort([5,4,3,2,1]));
--------------------------------------------------------------------------------
/src/main/java/library/base/CFunc.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.base;
31 |
32 | public class CFunc {
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/library/base/CList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.base;
31 |
32 | public class CList {
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ast/TreeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ast;
31 |
32 | public interface TreeVisitor {
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/library/base/CObjectProto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.base;
31 |
32 | public class CObjectProto {
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/TargetFuncWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public interface TargetFuncWrapper {
33 | CafeFunction getTarget();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/AssignedStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public abstract class AssignedStatement extends ExpressionStatement {
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/library/Slicable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library;
31 |
32 | public interface Slicable {
33 | DList slice(int s, int e);
34 |
35 | void setSlice(int s, int e, Object value);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/library/Subscriptable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library;
31 |
32 | public interface Subscriptable {
33 | Object getSubscript(Object key);
34 |
35 | void setSubscript(Object key, Object value);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/runtime/imports/ImportPathVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package runtime.imports;
31 |
32 | public interface ImportPathVisitor {
33 | void visit(CafeModulePath path);
34 |
35 | void visit(JavaModulePath path);
36 | }
37 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | #
4 | # Developed by:
5 | # Dhyey Shah
6 | # https://github.com/dhyey-shah
7 | #
8 | # Contributors:
9 | # Saurabh Pethani
10 | # https://github.com/SaurabhPethani
11 | #
12 | # Romil Nisar
13 | #
14 | #
15 | # This file is part of Cafe.
16 | #
17 | # Cafe is free software: you can redistribute it and/or modify
18 | # it under the terms of the GNU General Public License as published by
19 | # the Free Software Foundation, version 3 of the License.
20 | #
21 | # Cafe is distributed in the hope that it will be useful,
22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | # GNU General Public License for more details.
25 | #
26 | # You should have received a copy of the GNU General Public License
27 | # along with Cafe. If not, see .
28 | #
29 | distributionBase=GRADLE_USER_HOME
30 | distributionPath=wrapper/dists
31 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
32 | zipStoreBase=GRADLE_USER_HOME
33 | zipStorePath=wrapper/dists
34 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ast/Tree.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ast;
31 |
32 | /**
33 | * The base contract for all tree nodes in AST.
34 | *
35 | * @author Dhyey
36 | */
37 | public interface Tree {
38 | void accept(TreeVisitor v);
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/library/base/CObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.base;
31 |
32 | import library.DObject;
33 |
34 | public class CObject {
35 | public static DObject create(DObject e, DObject o) {
36 | return new DObject(o);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/compiler/parser/Lexer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.parser;
31 |
32 | import compiler.parser.Tokens.Token;
33 |
34 | public interface Lexer {
35 |
36 | void nextToken();
37 |
38 | Token token();
39 |
40 | Token prevToken();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/compiler/parser/Parser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.parser;
31 |
32 | import compiler.ast.Node;
33 |
34 | public abstract class Parser {
35 | abstract Parser instance(ParserFactory factory, Lexer lexer);
36 |
37 | public abstract Node parse();
38 | }
--------------------------------------------------------------------------------
/src/main/java/runtime/Runtime.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package runtime;
31 |
32 |
33 | public final class Runtime {
34 |
35 | private Runtime() {
36 | }
37 |
38 | public static void runtime(Class> module) throws Throwable {
39 | new ImportEvaluator().evaluate(module);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/NullStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public class NullStatement extends ExpressionStatement {
33 | @Override
34 | protected NullStatement self() {
35 | return this;
36 | }
37 |
38 | @Override
39 | public void accept(CafeIrVisitor visitor) {
40 | visitor.visitNull(this);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | /*
31 | * This file was generated by the Gradle 'init' task.
32 | *
33 | * The settings file is used to specify which projects to include in your build.
34 | *
35 | * Detailed information about configuring a multi-project build in Gradle can be found
36 | * in the user manual at https://docs.gradle.org/6.4/userguide/multi_project_builds.html
37 | */
38 |
39 | rootProject.name = 'cafe'
40 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/ExpressionStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public abstract class ExpressionStatement> extends CafeStatement {
33 | public static ExpressionStatement> of(Object expr) {
34 | if (expr == null)
35 | return null;
36 | if (expr instanceof ExpressionStatement)
37 | return (ExpressionStatement>) expr;
38 |
39 | throw cantConvert("ExpressionStatement", expr);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/compiler/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler;
31 |
32 | public class Main {
33 |
34 | /**
35 | * Entry point into the compiler
36 | *
37 | * @param args expects a file-name.txt file
38 | */
39 | public static void main(String[] args) {
40 | System.exit(compile(args));
41 | }
42 |
43 | public static int compile(String[] args) {
44 | compiler.main.Main compiler = new compiler.main.Main();
45 | return compiler.compile(args).exitCode;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/CafeStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public abstract class CafeStatement> extends CafeElement {
33 |
34 | public static CafeStatement> of(Object statement) {
35 | // TODO: return null ?, not sure
36 | if (statement == null) return null;
37 | if (statement instanceof CafeStatement) {
38 | return (CafeStatement) statement;
39 | }
40 | throw cantConvert("CafeStatement", statement);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/library/io/BasicIO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.io;
31 |
32 | import library.DObject;
33 |
34 | public class BasicIO {
35 | public static void print(DObject b, Object o) {
36 | System.out.print(o);
37 | }
38 |
39 | public static void println(DObject b, Object o) {
40 | System.out.println(o);
41 | }
42 |
43 | public static String input(DObject b) {
44 | return System.console()
45 | .readLine();
46 | }
47 |
48 | public static String input(DObject b, String s) {
49 | println(b, s);
50 | return input(b);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/runtime/ReferenceSymbol.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package runtime;
31 |
32 | public final class ReferenceSymbol {
33 | private String name;
34 | private String alias;
35 | private String path;
36 |
37 | public ReferenceSymbol(String name, String alias, String path) {
38 | this.name = name;
39 | this.alias = alias;
40 | this.path = path;
41 | }
42 |
43 | public String getPath() {
44 | return path;
45 | }
46 |
47 | public String getName() {
48 | return name;
49 | }
50 |
51 | public String getAlias() {
52 | return alias;
53 | }
54 |
55 | public boolean hasAlias() {
56 | return alias != null && !alias.isEmpty();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/compiler/ir/ThisStatement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.ir;
31 |
32 | public class ThisStatement extends ExpressionStatement {
33 |
34 | private final boolean isGlobal;
35 |
36 | private ThisStatement(boolean isGlobal) {
37 | this.isGlobal = isGlobal;
38 | }
39 |
40 | public static ThisStatement create(boolean isGlobal) {
41 | return new ThisStatement(isGlobal);
42 | }
43 |
44 | public boolean isGlobal() {
45 | return isGlobal;
46 | }
47 |
48 | @Override
49 | protected ThisStatement self() {
50 | return this;
51 | }
52 |
53 | @Override
54 | public void accept(CafeIrVisitor visitor) {
55 | visitor.visitThis(this);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/compiler/analyzer/Symbol.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.analyzer;
31 |
32 | import java.util.Objects;
33 |
34 | public final class Symbol {
35 | String name;
36 | boolean isConst;
37 |
38 | public Symbol(String name) {
39 | this(name, false);
40 | }
41 |
42 | public Symbol(String name, boolean isConst) {
43 | this.name = name;
44 | this.isConst = isConst;
45 | }
46 |
47 | @Override
48 | public boolean equals(Object o) {
49 | if (this == o) return true;
50 | if (o == null || getClass() != o.getClass()) return false;
51 | Symbol symbol = (Symbol) o;
52 | return name.equals(symbol.name);
53 | }
54 |
55 | @Override
56 | public int hashCode() {
57 | return Objects.hash(name);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/library/base/CListProto.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package library.base;
31 |
32 | import library.DList;
33 | import library.DObject;
34 |
35 | public class CListProto {
36 | public static void add(DObject object, Object value) {
37 | ((DList) object).add(value);
38 | }
39 |
40 | public static Object get(DObject object, Object index) {
41 | return ((DList) object).get((Integer) index);
42 | }
43 |
44 | public static void remove(DObject object, Object value) {
45 | ((DList) object).remove(value);
46 | }
47 |
48 | public static void removeAt(DObject object, Object value) {
49 | ((DList) object).removeAt((Integer) value);
50 | }
51 |
52 | public static int size(DObject object) {
53 | return ((DList) object).size();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/compiler/parser/ParserType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.parser;
31 |
32 | /**
33 | * A registry of the concrete implementation of parsers.
34 | *
35 | * @author Dhyey
36 | */
37 | public enum ParserType {
38 | MAINPARSER("MainParser");
39 |
40 | String parserClassName;
41 |
42 | ParserType(String className) {
43 | this.parserClassName = className;
44 | }
45 |
46 | String getParserClassName() {
47 | return parserClassName;
48 | }
49 |
50 | static void init() {
51 | for (ParserType type : ParserType.values()) {
52 | try {
53 | Class.forName("compiler.parser." + type.getParserClassName());
54 | } catch (ClassNotFoundException e) {
55 | e.printStackTrace();
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/compiler/util/Context.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler.util;
31 |
32 | import java.util.HashMap;
33 | import java.util.Map;
34 |
35 | /**
36 | * Context ensures that single context is used for each compiler phase invocation.
37 | *
Every phase registers itself with this context
38 | *
39 | * @author Dhyey
40 | */
41 | public class Context {
42 | public static class Key {
43 | }
44 |
45 | protected final Map, Object> map = new HashMap<>();
46 |
47 | public void put(Key key, T fac) {
48 | Object old = map.put(key, fac);
49 | if (old != null) {
50 | throw new AssertionError("duplicate value");
51 | }
52 | }
53 |
54 | @SuppressWarnings("unchecked")
55 | public T get(Key key) {
56 | Object o = map.get(key);
57 | return (T) o;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/compiler/CompileTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021. Dhyey Shah, Saurabh Pethani, Romil Nisar
3 | *
4 | * Developed by:
5 | * Dhyey Shah
6 | * https://github.com/dhyey-shah
7 | *
8 | * Contributors:
9 | * Saurabh Pethani
10 | * https://github.com/SaurabhPethani
11 | *
12 | * Romil Nisar
13 | *
14 | *
15 | * This file is part of Cafe.
16 | *
17 | * Cafe is free software: you can redistribute it and/or modify
18 | * it under the terms of the GNU General Public License as published by
19 | * the Free Software Foundation, version 3 of the License.
20 | *
21 | * Cafe is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with Cafe. If not, see .
28 | */
29 |
30 | package compiler;
31 |
32 | import compiler.main.CafeCompiler;
33 | import compiler.main.CompilerResult;
34 | import org.testng.annotations.DataProvider;
35 | import org.testng.annotations.Test;
36 | import testing.Utils;
37 |
38 | import java.io.File;
39 | import java.util.Iterator;
40 |
41 | import static org.testng.Assert.assertTrue;
42 |
43 | public class CompileTest {
44 | public static final String SRC = "src/test/resources/compile/";
45 |
46 | @DataProvider(name = "cafe-files")
47 | public static Iterator