├── .gitattributes ├── .gitignore ├── .gitmodules ├── .idea ├── codeStyleSettings.xml ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── encodings.xml ├── google-java-format.xml ├── libraries │ └── JLang.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── .vscode ├── c_cpp_properties.json ├── launch.json └── settings.json ├── LICENSE ├── Makefile ├── README.md ├── THIRD_PARTY_README ├── bin ├── check-setup.sh ├── compile_ll.sh ├── execute.sh ├── jlangc └── plc ├── build.xml ├── compiler ├── compiler.iml └── src │ └── jlang │ ├── JLangExtensionInfo.java │ ├── JLangOptions.java │ ├── JLangScheduler.java │ ├── LLVMEmitted.java │ ├── Main.java │ ├── Topics.java │ ├── Version.java │ ├── ast │ ├── AbstractSynchronized.java │ ├── AddressOf.java │ ├── AddressOf_c.java │ ├── ESeq.java │ ├── ESeq_c.java │ ├── JLangAbstractExtFactory_c.java │ ├── JLangExt.java │ ├── JLangExtFactory.java │ ├── JLangExtFactory_c.java │ ├── JLangLang.java │ ├── JLangLang_c.java │ ├── JLangNodeFactory.java │ ├── JLangNodeFactory_c.java │ ├── JLangOps.java │ ├── Load.java │ ├── Load_c.java │ ├── SynchronizedEnter.java │ ├── SynchronizedEnter_c.java │ ├── SynchronizedExit.java │ ├── SynchronizedExit_c.java │ └── package.html │ ├── extension │ ├── JLangAddressOfExt.java │ ├── JLangAnnotationElemExt.java │ ├── JLangArrayAccessExt.java │ ├── JLangArrayInitExt.java │ ├── JLangAssertExt.java │ ├── JLangAssignExt.java │ ├── JLangBinaryExt.java │ ├── JLangBooleanLitExt.java │ ├── JLangBranchExt.java │ ├── JLangCallExt.java │ ├── JLangCastExt.java │ ├── JLangCharLitExt.java │ ├── JLangClassDeclExt.java │ ├── JLangClassLitExt.java │ ├── JLangConditionalExt.java │ ├── JLangConstructorCallExt.java │ ├── JLangDesugaredNodeExt.java │ ├── JLangDoExt.java │ ├── JLangEseqExt.java │ ├── JLangExtendedForExt.java │ ├── JLangFieldDeclExt.java │ ├── JLangFieldExt.java │ ├── JLangFloatLitExt.java │ ├── JLangForExt.java │ ├── JLangIfExt.java │ ├── JLangInitializerExt.java │ ├── JLangInstanceofExt.java │ ├── JLangIntLitExt.java │ ├── JLangLabeledExt.java │ ├── JLangLoadExt.java │ ├── JLangLocalDeclExt.java │ ├── JLangLocalExt.java │ ├── JLangNewArrayExt.java │ ├── JLangNewExt.java │ ├── JLangNullLitExt.java │ ├── JLangProcedureCallExt.java │ ├── JLangProcedureDeclExt.java │ ├── JLangReturnExt.java │ ├── JLangSourceFileExt.java │ ├── JLangSpecialExt.java │ ├── JLangStringLitExt.java │ ├── JLangSwitchExt.java │ ├── JLangSynchronizedEnterExt.java │ ├── JLangSynchronizedExitExt.java │ ├── JLangSynchronizedExt.java │ ├── JLangThrowExt.java │ ├── JLangTryExt.java │ ├── JLangTryWithResourcesExt.java │ ├── JLangUnaryExt.java │ ├── JLangWhileExt.java │ └── package.html │ ├── package.html │ ├── structures │ ├── ClassObjects.java │ ├── DispatchVector.java │ ├── DispatchVector_c.java │ ├── ObjectStruct.java │ └── ObjectStruct_c.java │ ├── test │ ├── TestAll.java │ ├── TestFunctional.java │ └── TestUtil.java │ ├── types │ ├── JLangClassFileLazyClassInitializer.java │ ├── JLangLocalInstance.java │ ├── JLangLocalInstance_c.java │ ├── JLangParsedClassType_c.java │ ├── JLangSubstMethodInstance_c.java │ ├── JLangTypeSystem.java │ ├── JLangTypeSystem_c.java │ └── SubstMethodInstance.java │ ├── util │ ├── CollectUtils.java │ ├── Constants.java │ ├── DebugInfo.java │ ├── DesugarBarrier.java │ ├── JLangDesugared.java │ ├── JLangFreshGen.java │ ├── JLangMangler.java │ ├── LLVMUtils.java │ ├── Triple.java │ └── TypedNodeFactory.java │ └── visit │ ├── DeclareExplicitAnonCtors.java │ ├── DesugarEnums.java │ ├── DesugarImplicitConversions.java │ ├── DesugarInnerClasses.java │ ├── DesugarInstanceInitializers.java │ ├── DesugarLocalClasses.java │ ├── DesugarLocally.java │ ├── DesugarSynchronized.java │ ├── DesugarVisitor.java │ ├── LLVMTranslator.java │ ├── NameAnonClasses.java │ ├── StringLitFold.java │ └── package.html ├── defs.Darwin ├── defs.Linux ├── docs ├── .gitignore ├── README.md ├── _config.yml ├── _layouts │ ├── default.html │ └── subscribe.html ├── contact-us.md ├── developer-guide.md ├── getting-started.md ├── index.md ├── release-notes │ └── release-dec-2019.md ├── stylesheets │ ├── github-light.css │ ├── normalize.css │ └── stylesheet.css ├── thread-proposal.md └── user-manual.md ├── examples └── cup │ ├── Makefile │ ├── Makefile.obj │ ├── bin │ ├── JFlex.jar │ ├── cup.sh │ ├── debug-cup.sh │ └── java-cup-11.jar │ ├── build.xml │ ├── changelog.txt │ ├── license.txt │ ├── manual.html │ ├── src │ ├── cup │ │ └── parser.cup │ ├── java │ │ ├── .gitignore │ │ └── java_cup │ │ │ ├── ErrorManager.java │ │ │ ├── Lexer.java │ │ │ ├── Main.java │ │ │ ├── action_part.java │ │ │ ├── action_production.java │ │ │ ├── anttask │ │ │ └── CUPTask.java │ │ │ ├── assoc.java │ │ │ ├── emit.java │ │ │ ├── internal_error.java │ │ │ ├── lalr_item.java │ │ │ ├── lalr_item_set.java │ │ │ ├── lalr_state.java │ │ │ ├── lalr_transition.java │ │ │ ├── lr_item_core.java │ │ │ ├── non_terminal.java │ │ │ ├── nonassoc_action.java │ │ │ ├── parse_action.java │ │ │ ├── parse_action_row.java │ │ │ ├── parse_action_table.java │ │ │ ├── parse_reduce_row.java │ │ │ ├── parse_reduce_table.java │ │ │ ├── parser.java │ │ │ ├── production.java │ │ │ ├── production_part.java │ │ │ ├── reduce_action.java │ │ │ ├── runtime │ │ │ ├── ComplexSymbolFactory.java │ │ │ ├── DefaultSymbolFactory.java │ │ │ ├── Scanner.java │ │ │ ├── ScannerBuffer.java │ │ │ ├── Symbol.java │ │ │ ├── SymbolFactory.java │ │ │ ├── SyntaxTreeDFS.java │ │ │ ├── SyntaxTreeTransform.java │ │ │ ├── SyntaxTreeXPath.java │ │ │ ├── XMLElement.java │ │ │ ├── lr_parser.java │ │ │ └── virtual_parse_stack.java │ │ │ ├── shift_action.java │ │ │ ├── sym.java │ │ │ ├── symbol.java │ │ │ ├── symbol_part.java │ │ │ ├── symbol_set.java │ │ │ ├── terminal.java │ │ │ ├── terminal_set.java │ │ │ └── version.java │ └── jflex │ │ ├── Lexer.java │ │ └── Lexer.jflex │ ├── target │ └── .gitignore │ ├── test │ └── example.cup │ └── testgrammars │ ├── .gitignore │ ├── Constants.java │ ├── Lexer.java │ ├── c │ ├── .gitignore │ ├── c.cup │ ├── c.jflex │ ├── complicated.c │ ├── input.c │ ├── makeTest.sh │ ├── tree-view.css │ ├── tree-view.xsl │ └── tree.xsl │ ├── calc │ ├── .gitignore │ ├── calc.cup │ ├── makeCalc.sh │ └── scanner.java │ ├── input.minijava │ ├── makeAnnotatedTest.sh │ ├── makeNonAnnotatedTest.sh │ ├── makeXMLtest.sh │ ├── minijava.cup │ ├── minijava │ ├── TestVisitor.java │ ├── codegen.sq │ ├── make.sh │ ├── minijava.cup │ ├── minijava.jflex │ ├── simple.minijava │ ├── tree-view.css │ ├── tree-view.xsl │ └── tree.xsl │ ├── minijava2 │ ├── bin │ │ └── JFlex.jar │ ├── build.xml │ ├── cup │ │ └── Parser.cup │ ├── expres.mp │ ├── flex │ │ └── Scanner.jflex │ ├── input.minijava │ ├── src │ │ ├── minijava │ │ │ ├── Cond.java │ │ │ ├── Constants.java │ │ │ ├── Decl.java │ │ │ ├── Expr.java │ │ │ ├── InMemoryParser.java │ │ │ ├── MinijavaVisitor.java │ │ │ ├── Program.java │ │ │ └── Stmt.java │ │ └── miniparser │ │ │ ├── CFGGenerator.java │ │ │ ├── Lexer.java │ │ │ ├── Main.java │ │ │ ├── MiniJVMGenerator.java │ │ │ ├── Parser.java │ │ │ ├── SyntaxTreeGenerator.java │ │ │ └── sym.java │ └── trees.mp │ ├── test-correctannotations.cup │ ├── test-noannotations.cup │ ├── tree-view.css │ ├── tree-view.xsl │ └── tree.xsl ├── jdk-lite ├── .gitignore ├── Makefile ├── dump.txt ├── native │ └── java │ │ ├── io │ │ └── PrintStream.cpp │ │ └── lang │ │ ├── Class.cpp │ │ ├── Object.cpp │ │ └── String.cpp └── src │ └── java │ ├── io │ ├── PrintStream.java │ └── Serializable.java │ ├── lang │ ├── ArrayIndexOutOfBoundsException.java │ ├── ArrayStoreException.java │ ├── AssertionError.java │ ├── AutoCloseable.java │ ├── Class.java │ ├── ClassCastException.java │ ├── ClassNotFoundException.java │ ├── CloneNotSupportedException.java │ ├── Cloneable.java │ ├── Comparable.java │ ├── Enum.java │ ├── Error.java │ ├── Exception.java │ ├── Float.java │ ├── IllegalArgumentException.java │ ├── IllegalStateException.java │ ├── IndexOutOfBoundsException.java │ ├── Integer.java │ ├── Iterable.java │ ├── JLangNotImplementedError.java │ ├── NullPointerException.java │ ├── Number.java │ ├── Object.java │ ├── Runnable.java │ ├── RuntimeException.java │ ├── String.java │ ├── System.java │ ├── Throwable.java │ ├── UnsupportedOperationException.java │ └── annotation │ │ └── Annotation.java │ ├── test │ ├── AbstractTest.java │ ├── SubTest.java │ └── Test.java │ └── util │ ├── AbstractCollection.java │ ├── AbstractSet.java │ ├── Collection.java │ ├── ConcurrentModificationException.java │ ├── Dictionary.java │ ├── Enumeration.java │ ├── Hashtable.java │ ├── Iterator.java │ ├── List.java │ ├── ListIterator.java │ ├── Map.java │ ├── NoSuchElementException.java │ ├── RandomAccess.java │ └── Set.java ├── jdk ├── .gitignore ├── Main.java ├── Makefile ├── Makefile.obj ├── README.md ├── jdk-method-filter.txt ├── make-patch.sh ├── modification_notice.txt ├── patches │ ├── java │ │ ├── io │ │ │ ├── BufferedInputStream.patch │ │ │ ├── FileDescriptor.patch │ │ │ ├── FileInputStream.patch │ │ │ └── UnixFileSystem.patch │ │ ├── lang │ │ │ ├── Thread.patch │ │ │ └── ThreadLocal.patch │ │ ├── nio │ │ │ └── charset │ │ │ │ ├── ArrayDecoder.patch │ │ │ │ ├── ArrayEncoder.patch │ │ │ │ ├── Charset.patch │ │ │ │ ├── HistoricallyNamedCharset.patch │ │ │ │ ├── ISO_8859_1.patch │ │ │ │ ├── StandardCharset.patch │ │ │ │ ├── StandardCharsets.patch │ │ │ │ ├── Surrogate.patch │ │ │ │ ├── US_ASCII.patch │ │ │ │ ├── UTF_8.patch │ │ │ │ └── Unicode.patch │ │ └── util │ │ │ ├── HashMap.patch │ │ │ ├── HashTable.patch │ │ │ └── concurrent │ │ │ └── atomic │ │ │ └── AtomicInteger.patch │ └── sun │ │ ├── misc │ │ ├── Hashing.patch │ │ └── OSEnvironment.patch │ │ ├── nio │ │ └── cs │ │ │ └── FastCharsetProvider.patch │ │ └── reflect │ │ └── UnsafeFieldAccessorImpl.patch ├── src.zip └── stubs.cpp ├── lib ├── hamcrest-core-1.3.jar ├── javacpp.jar ├── junit-4.12.jar ├── llvm-javadoc.jar ├── llvm-linux-x86_64.jar ├── llvm-macosx-x86_64.jar ├── llvm-sources.jar ├── llvm.jar └── ppg.jar ├── runtime ├── .clang-format ├── .gitignore ├── Makefile ├── linux_version.map ├── native │ ├── array.cpp │ ├── array.h │ ├── base_class.cpp │ ├── base_class.h │ ├── class.cpp │ ├── class.h │ ├── constants.cpp │ ├── constants.h │ ├── debug.cpp │ ├── exception.cpp │ ├── exception.h │ ├── factory.cpp │ ├── factory.h │ ├── helper.h │ ├── init.cpp │ ├── init.h │ ├── interface.cpp │ ├── interface.h │ ├── jni.cpp │ ├── jni_help.h │ ├── jvm.cpp │ ├── jvm.h │ ├── main.cpp │ ├── monitor.cpp │ ├── monitor.h │ ├── native.cpp │ ├── native.h │ ├── nativetest.cpp │ ├── nativetest.h │ ├── reflect.cpp │ ├── reflect.h │ ├── rep.h │ ├── signals.h │ ├── stack_trace.cpp │ ├── stack_trace.h │ ├── threads.cpp │ ├── threads.h │ ├── unsafe.cpp │ └── unsafe.h ├── runtime.iml └── src │ └── jlang │ └── runtime │ ├── Array.java │ ├── BaseClass.java │ ├── Constants.java │ ├── Exceptions.java │ ├── Factory.java │ ├── Helper.java │ └── MainWrapper.java └── tests ├── AnonymousSubClass.java ├── isolated ├── .gitignore ├── Add.java ├── Annotations.java ├── AnonymousClass.java ├── Array.java ├── ArrayInit.java ├── ArrayOutOfBounds.java ├── ArrayReflection.java ├── Assert.java ├── Assign.java ├── Binary.java ├── BinaryCondOps.java ├── Blocks.java ├── Cast.java ├── CastNull.java ├── ClassLiteral.java ├── ClassReflection.java ├── ClassTest.java ├── ConcurrentReflection.java ├── Conditional.java ├── Empty.java ├── EnhancedFor.java ├── Enums.java ├── ExceptionReturnTest.java ├── Exceptions.java ├── ExceptionsNested.java ├── FieldReflection.java ├── FinalField.java ├── Generic.java ├── Generic01.java ├── Generic02.java ├── Generic03.java ├── Generic04.java ├── Generic05.java ├── Generic06.java ├── Generic07.java ├── Generic08.java ├── Generic09.java ├── Generic10.java ├── Generic11.java ├── Generic12.java ├── Generic13.java ├── Generic14.java ├── GenericInterface.java ├── GenericMethods.java ├── GenericRemoved.java ├── HashtableTest.java ├── IfStatement.java ├── Inc.java ├── Initializer.java ├── InnerClass.java ├── InstanceOf.java ├── Interface.java ├── InterfaceHierarchy.java ├── InterruptTest.java ├── Labeled.java ├── Lit.java ├── LocalClass.java ├── Loop.java ├── Main.java ├── Makefile ├── MethodReflection.java ├── MultipleInterfaces.java ├── Nesting.java ├── NotifyAllTest.java ├── NotifyTest.java ├── PrimitiveReflection.java ├── Printing.java ├── ReflectionMemoryTest.java ├── RuntimeTypeCheck.java ├── SimpleClass.java ├── Special.java ├── StaticFields.java ├── StringConversion.java ├── StringIntern.java ├── Strings.java ├── Subtype.java ├── Switch.java ├── Synchronized.java ├── TernaryOperator.java ├── ThreadingTest.java ├── TryFinally.java ├── TryWithResources.java ├── Unary.java ├── UnaryOperations.java ├── VarArgs.java ├── checkDiffs.sh └── expected_fails ├── misc ├── EmptyClass.java ├── Eratosthenes.java ├── ExtendConditions.java ├── ExtendImportedClass.java ├── FloatingPoint.java ├── Hello.java ├── Hello.pll ├── Hello2.java ├── InheritedStaticMethod.java ├── IntAdd.c ├── IntAdd.h ├── IntAdd.java ├── IntAdd.o ├── IntAdd.s ├── IntComparisons.java ├── IntLinkedList.java ├── StaticMethods.java ├── SubSubClass.java ├── TestByte.java ├── TestStringLit.java ├── UseSimpleClass.java ├── libhelloworld.jnilib ├── pthScript ├── pthScript.results ├── temp.java ├── test.sh └── tests │ ├── BreakTest.java │ └── Conditions.java └── tests.iml /.gitattributes: -------------------------------------------------------------------------------- 1 | jdk/src.zip filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /compiler/classes 2 | /lib/polyllvm.jar 3 | /lib/polyllvm-rt.jar 4 | /.idea/workspace.xml 5 | /.idea/usage.statistics.xml 6 | /.idea/tasks.xml 7 | /.idea/shelf 8 | /.idea/dictionary 9 | /.idea/dictionaries 10 | /out/ 11 | *.class 12 | *.DS_STORE 13 | .*.sw? 14 | *.out 15 | .settings/ 16 | .cproject 17 | .project 18 | .classpath 19 | *.ll 20 | *.o 21 | *.dSYM 22 | *~ 23 | tests/isolated/check 24 | examples/cup/dist 25 | examples/cup/out 26 | examples/cup/test/*.java 27 | examples/cup/testgrammars/out 28 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/polyglot"] 2 | path = lib/polyglot 3 | url = https://github.com/polyglot-compiler/polyglot 4 | ignore = untracked 5 | [submodule "lib/javacpp-presets"] 6 | path = lib/javacpp-presets 7 | url = https://github.com/gharrma/javacpp-presets 8 | branch = master 9 | -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/google-java-format.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/libraries/JLang.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/runtime/native/", 7 | "/usr/lib/jvm/jdk1.7.0_80/include/", 8 | "/usr/lib/jvm/jdk1.7.0_80/include/linux/" 9 | ], 10 | "defines": [], 11 | "compilerPath": "/usr/bin/gcc", 12 | "cStandard": "c11", 13 | "cppStandard": "c++17", 14 | "intelliSenseMode": "clang-x64" 15 | } 16 | ], 17 | "version": 4 18 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "gdb", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "target": "./program.o", 12 | "cwd": "${workspaceRoot}", 13 | "valuesFormatting": "parseText", 14 | "env": {"JAVA_HOME": "/usr/lib/jvm/jdk1.7.0_80"}, 15 | "autorun": ["handle SIGPWR nostop noprint", "handle SIGXCPU nostop noprint"] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.watcherExclude": { 3 | "**/.git/objects/**": true, 4 | "**/.git/subtree-cache/**": true, 5 | "**/node_modules/*/**": true, 6 | "**/jdk/**": true, 7 | "**/jdk-lite/**": true, 8 | "**/docs/**": true, 9 | "**/classes/**": true, 10 | "**/out/**": true, 11 | } 12 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2017 Cornell University 2 | -------------------------------------------------- 3 | This program is free software; you can redistribute it and/or modify it 4 | under the terms of the GNU General Public License version 2 as published by the Free 5 | Software Foundation. 6 | 7 | This program is distributed in the hope that it will be useful, but WITHOUT 8 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 10 | more details. 11 | 12 | You should have received a copy of the GNU General Public License along 13 | with this program; if not, write to the Free Software Foundation, Inc., 59 14 | Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 | 16 | --------------------------------------------------- 17 | Up to date contact information for the developers of this program 18 | can be found on the repository website: https://polyglot-compiler.github.io/JLang/ -------------------------------------------------------------------------------- /bin/compile_ll.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 3 | echo $DIR 4 | BASE_DIR=$(realpath $(dirname "$DIR")) 5 | JDK7=$(realpath "$JDK7") 6 | JDK7_LIB="$JDK7"/jre/lib 7 | if [ "$(uname)" = "Linux" ] 8 | then 9 | JDK7_LIB="$JDK7_LIB"/amd64 10 | fi 11 | 12 | CLANG=clang++ 13 | LLC=llc 14 | 15 | if ! [ -z "$CLANG_VERSION" ] 16 | then 17 | CLANG=clang++-"$CLANG_VERSION" 18 | LLC=llc-"$CLANG_VERSION" 19 | fi 20 | 21 | if [ "$#" -lt 1 ] 22 | then 23 | printf "Need to supply at least 1 input file\n" 24 | printf "Usage: compile_ll.sh file1.ll [file2.ll ...]\n" 25 | exit 1 26 | fi 27 | 28 | if [ "$#" -eq 1 ] 29 | then 30 | ARGS="$@" 31 | else 32 | ARGS="${@:2}" 33 | fi 34 | 35 | OBJ_NAME=$(echo "$1" | cut -f 1 -d '.')".o" 36 | "$CLANG" -Wno-override-module -lgc -g -L"$BASE_DIR"/runtime/out -ljvm -L"$BASE_DIR"/"$JDK"/out -ljdk -Wl,-rpath,"$JDK7_LIB" -Wl,-rpath,"$BASE_DIR"/"$JDK"/out -Wl,-rpath,"$BASE_DIR"/runtime/out -rdynamic -o "$OBJ_NAME" $ARGS 37 | 38 | printf "Wrote compiled binary to $OBJ_NAME\n" 39 | 40 | 41 | -------------------------------------------------------------------------------- /bin/execute.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 3 | export JAVA_HOME="$JDK7" 4 | CMD=$(realpath "$1") 5 | "$CMD" "${@:2}" 6 | -------------------------------------------------------------------------------- /bin/plc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DIR="$(dirname "$0")" 4 | RUNTIME=$DIR/../runtime 5 | if [ -z "$CLANG" ] 6 | then 7 | CLANG=clang++ 8 | fi 9 | 10 | out=a.out 11 | outdir=. 12 | clangflags= 13 | directories= 14 | files= 15 | while true; do 16 | case "$1" in 17 | "") 18 | break 19 | ;; 20 | -o) 21 | shift 22 | out="$1" 23 | shift 24 | ;; 25 | -d) 26 | shift 27 | outdir="$1" 28 | shift 29 | ;; 30 | -g) 31 | clangflags="$clangflags -g" 32 | shift 33 | ;; 34 | *) 35 | if [ -d "$1" ]; then 36 | directories="$directories $1" 37 | else 38 | files="$files $1" 39 | fi 40 | shift 41 | ;; 42 | esac 43 | done 44 | 45 | for d in $directories; do 46 | srcs=`find $d -name "*.java"` 47 | files="$files $srcs" 48 | done 49 | 50 | 51 | $DIR/jlangc -d "$outdir" $files && \ 52 | $CLANG -Wno-override-module -L/usr/local/lib/ -lgc -O1 -o "$out" $clangflags "$RUNTIME"/runtime.o `find "$outdir" -name *.ll` 53 | -------------------------------------------------------------------------------- /compiler/compiler.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /compiler/src/jlang/Main.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang; 4 | 5 | /** 6 | * Main is the main program of the compiler extension. 7 | * It simply invokes Polyglot's main, passing in the extension's 8 | * JLangExtensionInfo. 9 | */ 10 | public class Main 11 | { 12 | public static void main(String[] args) { 13 | polyglot.main.Main polyglotMain = new polyglot.main.Main(); 14 | 15 | try { 16 | polyglotMain.start(args, new JLangExtensionInfo()); 17 | } 18 | catch (polyglot.main.Main.TerminationException e) { 19 | System.err.println(e.getMessage()); 20 | System.exit(1); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /compiler/src/jlang/Topics.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang; 4 | 5 | import polyglot.main.Report; 6 | 7 | /** 8 | * Extension information for JLang extension. 9 | */ 10 | public class Topics { 11 | public static final String jlang = "jlang"; 12 | 13 | static { 14 | Report.topics.add(jlang); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /compiler/src/jlang/Version.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang; 4 | 5 | /** 6 | * Version information for JLang extension 7 | */ 8 | public class Version extends polyglot.main.Version { 9 | @Override 10 | public String name() { 11 | return "jlang"; 12 | } 13 | 14 | @Override 15 | public int major() { 16 | return 0; 17 | } 18 | 19 | @Override 20 | public int minor() { 21 | return 1; 22 | } 23 | 24 | @Override 25 | public int patch_level() { 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/AddressOf.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Expr; 6 | 7 | /** 8 | * An AddressOf translates its child as an lvalue even in an rvalue context. 9 | * This is useful for temporarily storing the result of an expression before 10 | * later using it in an lvalue context. 11 | */ 12 | public interface AddressOf extends Expr { 13 | 14 | Expr expr(); 15 | } 16 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/ESeq.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Expr; 6 | import polyglot.ast.Stmt; 7 | 8 | import java.util.List; 9 | 10 | public interface ESeq extends Expr { 11 | 12 | List statements(); 13 | 14 | ESeq statements(List statements); 15 | 16 | Expr expr(); 17 | 18 | ESeq expr(Expr expr); 19 | } 20 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/JLangExtFactory.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Ext; 6 | import polyglot.ext.jl7.ast.JL7ExtFactory; 7 | 8 | /** 9 | * Extension factory for the JLang extension. 10 | */ 11 | public interface JLangExtFactory extends JL7ExtFactory { 12 | 13 | Ext extESeq(); 14 | 15 | Ext extAddressOf(); 16 | 17 | Ext extLoad(); 18 | 19 | Ext extSynchronizedEnter(); 20 | 21 | Ext extSynchronizedExit(); 22 | } 23 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/JLangLang.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Node; 6 | import polyglot.ext.jl7.ast.J7Lang; 7 | 8 | import static org.bytedeco.javacpp.LLVM.LLVMBasicBlockRef; 9 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef; 10 | 11 | import jlang.visit.DesugarLocally; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public interface JLangLang extends J7Lang { 15 | 16 | /** 17 | * Simplifies (desugars) this node so that translation to LLVM is easier. 18 | * This method should be called until the AST reaches a fixed point. 19 | */ 20 | Node desugar(Node n, DesugarLocally v); 21 | 22 | Node overrideTranslateLLVM(Node parent, Node n, LLVMTranslator LLVMTranslator); 23 | 24 | LLVMTranslator enterTranslateLLVM(Node n, LLVMTranslator v); 25 | 26 | Node leaveTranslateLLVM(Node n, LLVMTranslator v); 27 | 28 | void translateLLVMConditional(Node n, LLVMTranslator v, 29 | LLVMBasicBlockRef trueBlock, 30 | LLVMBasicBlockRef falseBlock); 31 | 32 | LLVMValueRef translateAsLValue(Node n, LLVMTranslator v); 33 | } 34 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/JLangNodeFactory.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Expr; 6 | import polyglot.ast.Stmt; 7 | import polyglot.ext.jl7.ast.JL7NodeFactory; 8 | import polyglot.util.Position; 9 | 10 | import java.util.List; 11 | 12 | /** NodeFactory for JLang. */ 13 | public interface JLangNodeFactory extends JL7NodeFactory { 14 | 15 | ESeq ESeq(Position pos, List statements, Expr expr); 16 | 17 | AddressOf AddressOf(Position pos, Expr expr); 18 | 19 | Load Load(Position pos, Expr expr); 20 | 21 | SynchronizedEnter SynchronizedEnter(Position pos, Expr expr); 22 | 23 | SynchronizedExit SynchronizedExit(Position pos, Expr expr); 24 | } 25 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/Load.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.ast; 4 | 5 | import polyglot.ast.Expr; 6 | 7 | /** 8 | * A load dereferences its child. 9 | * This is useful in conjunction with {@link AddressOf}. 10 | */ 11 | public interface Load extends Expr { 12 | 13 | Expr expr(); 14 | } 15 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/SynchronizedEnter.java: -------------------------------------------------------------------------------- 1 | package jlang.ast; 2 | 3 | import polyglot.ast.Expr; 4 | import polyglot.ast.Stmt; 5 | 6 | public interface SynchronizedEnter extends Stmt { 7 | Expr expr(); 8 | } 9 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/SynchronizedEnter_c.java: -------------------------------------------------------------------------------- 1 | package jlang.ast; 2 | 3 | import polyglot.ast.*; 4 | import polyglot.util.CodeWriter; 5 | import polyglot.util.Position; 6 | import polyglot.visit.PrettyPrinter; 7 | 8 | public class SynchronizedEnter_c extends AbstractSynchronized implements SynchronizedEnter { 9 | 10 | SynchronizedEnter_c(Position pos, Expr expr, Ext ext) { 11 | super(pos, expr, ext); 12 | } 13 | 14 | protected N expr(N n, Expr expr) { 15 | return super.expr(n, expr); 16 | } 17 | 18 | @Override 19 | public void prettyPrint(CodeWriter w, PrettyPrinter pp) { 20 | w.write("synchronized_enter("); 21 | expr.prettyPrint(w, pp); 22 | w.write(")"); 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "synchronized_enter(" + expr.toString() + ");"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/SynchronizedExit.java: -------------------------------------------------------------------------------- 1 | package jlang.ast; 2 | 3 | import polyglot.ast.Expr; 4 | import polyglot.ast.Stmt; 5 | 6 | public interface SynchronizedExit extends Stmt { 7 | Expr expr(); 8 | } 9 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/SynchronizedExit_c.java: -------------------------------------------------------------------------------- 1 | package jlang.ast; 2 | 3 | import polyglot.ast.Expr; 4 | import polyglot.ast.Ext; 5 | import polyglot.util.CodeWriter; 6 | import polyglot.util.Position; 7 | import polyglot.visit.PrettyPrinter; 8 | 9 | public class SynchronizedExit_c extends AbstractSynchronized implements SynchronizedExit { 10 | 11 | SynchronizedExit_c(Position pos, Expr expr, Ext ext) { 12 | super(pos, expr, ext); 13 | } 14 | 15 | @Override 16 | public void prettyPrint(CodeWriter w, PrettyPrinter pp) { 17 | w.write("synchronized_exit("); 18 | expr.prettyPrint(w, pp); 19 | w.write(")"); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "synchronized_exit(" + expr.toString() + ");"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /compiler/src/jlang/ast/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | AST nodes for the JLang language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangAddressOfExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | 7 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef; 8 | 9 | import jlang.ast.AddressOf; 10 | import jlang.ast.JLangExt; 11 | import jlang.visit.LLVMTranslator; 12 | 13 | public class JLangAddressOfExt extends JLangExt { 14 | 15 | @Override 16 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 17 | AddressOf n = (AddressOf) node(); 18 | LLVMValueRef ptr = lang().translateAsLValue(n.expr(), v); 19 | v.addTranslation(n, ptr); 20 | return super.leaveTranslateLLVM(v); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangAnnotationElemExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import jlang.ast.JLangExt; 6 | import jlang.visit.LLVMTranslator; 7 | import polyglot.ast.Node; 8 | 9 | public class JLangAnnotationElemExt extends JLangExt { 10 | 11 | @Override 12 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 13 | // Do not recurse into annotations, since there may actually be 14 | // expressions inside, and we don't want to translate them. 15 | // E.g., the annotation @Target({FIELD, METHOD}) contains a list 16 | // of enum values, but they should not appear in LLVM IR. 17 | return node(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangAssertExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Assert; 6 | import polyglot.ast.Expr; 7 | import polyglot.ast.Node; 8 | import polyglot.main.Options; 9 | import polyglot.util.InternalCompilerError; 10 | import polyglot.util.Position; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | import jlang.ast.JLangExt; 16 | import jlang.visit.DesugarLocally; 17 | import jlang.visit.LLVMTranslator; 18 | 19 | public class JLangAssertExt extends JLangExt { 20 | 21 | @Override 22 | public Node leaveTranslateLLVM(LLVMTranslator v) { 23 | throw new InternalCompilerError("Assert statements should have been desugared"); 24 | } 25 | 26 | @Override 27 | public Node desugar(DesugarLocally v) { 28 | Assert n = (Assert) node(); 29 | Position pos = n.position(); 30 | 31 | if (!Options.global.assertions) { 32 | // Assertions are disabled. 33 | return v.nf.Empty(pos); 34 | } 35 | 36 | List args = n.errorMessage() != null 37 | ? Collections.singletonList(n.errorMessage()) 38 | : Collections.emptyList(); 39 | 40 | return v.tnf.If(v.tnf.Not(n.cond()), v.tnf.Throw(pos, v.ts.AssertionError(), args)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangBooleanLitExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.BooleanLit; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.*; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangBooleanLitExt extends JLangExt { 15 | private static final long serialVersionUID = SerialVersionUID.generate(); 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | BooleanLit n = (BooleanLit) node(); 20 | LLVMTypeRef type = v.utils.toLL(n.type()); 21 | LLVMValueRef val = LLVMConstInt(type, n.value() ? 1 : 0, /*sign-extend*/ 0); 22 | v.addTranslation(node(), val); 23 | return super.leaveTranslateLLVM(v); 24 | } 25 | 26 | @Override 27 | public void translateLLVMConditional(LLVMTranslator v, 28 | LLVMBasicBlockRef trueBlock, 29 | LLVMBasicBlockRef falseBlock) { 30 | BooleanLit n = (BooleanLit) node(); 31 | LLVMBuildBr(v.builder, n.value() ? trueBlock : falseBlock); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangBranchExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Branch; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.LLVMBuildBr; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangBranchExt extends JLangExt { 15 | private static final long serialVersionUID = SerialVersionUID.generate(); 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | Branch n = (Branch) node(); 20 | 21 | LLVMTranslator.ControlTransferLoc loc = n.kind() == Branch.CONTINUE 22 | ? v.getContinueLoc(n.label()) 23 | : v.getBreakLoc(n.label()); 24 | 25 | // If we are within an exception frame, we may need to detour through finally blocks first. 26 | v.buildFinallyBlockChain(loc.getTryCatchNestingLevel()); 27 | 28 | LLVMBuildBr(v.builder, loc.getBlock()); 29 | 30 | return super.leaveTranslateLLVM(v); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangCharLitExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.CharLit; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.*; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangCharLitExt extends JLangExt { 15 | private static final long serialVersionUID = SerialVersionUID.generate(); 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | CharLit n = (CharLit) node(); 20 | LLVMTypeRef type = v.utils.toLL(n.type()); 21 | LLVMValueRef val = LLVMConstInt(type, n.value(), /*sign-extend*/ 0); 22 | v.addTranslation(n, val); 23 | return super.leaveTranslateLLVM(v); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangConstructorCallExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.ConstructorCall; 6 | import polyglot.ast.Node; 7 | import polyglot.util.InternalCompilerError; 8 | import polyglot.util.SerialVersionUID; 9 | 10 | import static org.bytedeco.javacpp.LLVM.LLVMGetParam; 11 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef; 12 | 13 | import jlang.visit.LLVMTranslator; 14 | 15 | public class JLangConstructorCallExt extends JLangProcedureCallExt { 16 | private static final long serialVersionUID = SerialVersionUID.generate(); 17 | 18 | @Override 19 | public Node leaveTranslateLLVM(LLVMTranslator v) { 20 | if (node().qualifier() != null) 21 | throw new InternalCompilerError("Qualified ctor call should have been desugared"); 22 | 23 | // Most of the translation happens in this super call. 24 | return super.leaveTranslateLLVM(v); 25 | } 26 | 27 | @Override 28 | protected LLVMValueRef buildReceiverArg(LLVMTranslator v) { 29 | return LLVMGetParam(v.currFn(), 0); 30 | } 31 | 32 | @Override 33 | public ConstructorCall node() { 34 | return (ConstructorCall) super.node(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangDesugaredNodeExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import jlang.ast.JLangExt; 6 | import jlang.visit.LLVMTranslator; 7 | import polyglot.ast.Node; 8 | import polyglot.util.InternalCompilerError; 9 | 10 | public class JLangDesugaredNodeExt extends JLangExt { 11 | private static final String errorMsg = 12 | "This node should be desugared before translating to LLVM IR"; 13 | 14 | @Override 15 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 16 | throw new InternalCompilerError(errorMsg + ": " + node().getClass()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangEseqExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | 7 | import static org.bytedeco.javacpp.LLVM.LLVMBasicBlockRef; 8 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef; 9 | 10 | import jlang.ast.ESeq; 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangEseqExt extends JLangExt { 15 | 16 | @Override 17 | public Node leaveTranslateLLVM(LLVMTranslator v) { 18 | ESeq n = (ESeq) node(); 19 | v.addTranslation(n, v.getTranslation(n.expr())); 20 | return super.leaveTranslateLLVM(v); 21 | } 22 | 23 | @Override 24 | public void translateLLVMConditional( 25 | LLVMTranslator v, LLVMBasicBlockRef trueBlock, LLVMBasicBlockRef falseBlock) { 26 | ESeq n = (ESeq) node(); 27 | n.visitList(n.statements(), v); 28 | lang().translateLLVMConditional(n.expr(), v, trueBlock, falseBlock); 29 | } 30 | 31 | @Override 32 | public LLVMValueRef translateAsLValue(LLVMTranslator v) { 33 | ESeq n = (ESeq) node(); 34 | n.visitList(n.statements(), v); 35 | return lang().translateAsLValue(n.expr(), v); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangFloatLitExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.FloatLit; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.LLVMConstReal; 10 | import static org.bytedeco.javacpp.LLVM.LLVMTypeRef; 11 | 12 | import jlang.ast.JLangExt; 13 | import jlang.visit.LLVMTranslator; 14 | 15 | public class JLangFloatLitExt extends JLangExt { 16 | private static final long serialVersionUID = SerialVersionUID.generate(); 17 | 18 | @Override 19 | public Node leaveTranslateLLVM(LLVMTranslator v) { 20 | FloatLit n = (FloatLit) node(); 21 | LLVMTypeRef type = v.utils.toLL(n.type()); 22 | v.addTranslation(n, LLVMConstReal(type, n.value())); 23 | return super.leaveTranslateLLVM(v); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangIfExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.If; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import java.lang.Override; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | import static org.bytedeco.javacpp.LLVM.*; 15 | 16 | public class JLangIfExt extends JLangExt { 17 | private static final long serialVersionUID = SerialVersionUID.generate(); 18 | 19 | @Override 20 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 21 | If n = (If) node(); 22 | LLVMBasicBlockRef ifEnd = v.utils.buildBlock("if.end"); 23 | LLVMBasicBlockRef ifTrue = v.utils.buildBlock("if.true"); 24 | LLVMBasicBlockRef ifFalse = n.alternative() != null 25 | ? v.utils.buildBlock("if.false") 26 | : ifEnd; 27 | 28 | lang().translateLLVMConditional(n.cond(), v, ifTrue, ifFalse); 29 | 30 | LLVMPositionBuilderAtEnd(v.builder, ifTrue); 31 | n.visitChild(n.consequent(), v); 32 | v.utils.branchUnlessTerminated(ifEnd); 33 | 34 | if (n.alternative() != null) { 35 | LLVMPositionBuilderAtEnd(v.builder, ifFalse); 36 | n.visitChild(n.alternative(), v); 37 | v.utils.branchUnlessTerminated(ifEnd); 38 | } 39 | 40 | LLVMPositionBuilderAtEnd(v.builder, ifEnd); 41 | return n; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangInitializerExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import jlang.ast.JLangExt; 6 | import jlang.visit.LLVMTranslator; 7 | import polyglot.ast.Node; 8 | import polyglot.util.SerialVersionUID; 9 | 10 | public class JLangInitializerExt extends JLangExt { 11 | private static final long serialVersionUID = SerialVersionUID.generate(); 12 | 13 | @Override 14 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 15 | // Instance initializers and static initializers are desugared 16 | // into standalone functions that are called when necessary. 17 | return node(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangInstanceofExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Instanceof; 6 | import polyglot.ast.Node; 7 | import polyglot.types.ReferenceType; 8 | import polyglot.util.SerialVersionUID; 9 | 10 | import java.lang.Override; 11 | 12 | import jlang.ast.JLangExt; 13 | import jlang.visit.LLVMTranslator; 14 | 15 | import static org.bytedeco.javacpp.LLVM.*; 16 | 17 | public class JLangInstanceofExt extends JLangExt { 18 | private static final long serialVersionUID = SerialVersionUID.generate(); 19 | 20 | @Override 21 | public Node leaveTranslateLLVM(LLVMTranslator v) { 22 | Instanceof n = (Instanceof) node(); 23 | LLVMValueRef obj = v.getTranslation(n.expr()); 24 | ReferenceType rt = n.compareType().type().toReference(); 25 | LLVMValueRef compTypeIdVar = v.classObjs.toTypeIdentity(rt); 26 | LLVMTypeRef bytePtrTy = v.utils.ptrTypeRef(v.utils.intType(8)); 27 | LLVMTypeRef objTy = v.utils.toLL(v.ts.Object()); 28 | LLVMValueRef objBitcast = LLVMBuildBitCast(v.builder, obj, objTy, "cast.obj"); 29 | LLVMTypeRef funcType = v.utils.functionType(v.utils.intType(1), objTy, bytePtrTy); 30 | LLVMValueRef function = v.utils.getFunction("InstanceOf", funcType); 31 | LLVMValueRef res = v.utils.buildFunCall(function, objBitcast, compTypeIdVar); 32 | v.addTranslation(n, res); 33 | return super.leaveTranslateLLVM(v); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangIntLitExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.IntLit; 6 | import polyglot.ast.Node; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.*; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangIntLitExt extends JLangExt { 15 | private static final long serialVersionUID = SerialVersionUID.generate(); 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | IntLit n = (IntLit) node(); 20 | assert n.type().isLongOrLess(); 21 | LLVMTypeRef type = v.utils.toLL(n.type()); 22 | LLVMValueRef res = LLVMConstInt(type, n.value(), /*sign-extend*/ 0); 23 | v.addTranslation(n, res); 24 | return super.leaveTranslateLLVM(v); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangLoadExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | 7 | import java.lang.Override; 8 | 9 | import jlang.ast.Load; 10 | import jlang.ast.JLangExt; 11 | import jlang.visit.LLVMTranslator; 12 | 13 | import static org.bytedeco.javacpp.LLVM.*; 14 | 15 | public class JLangLoadExt extends JLangExt { 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | Load n = (Load) node(); 20 | LLVMValueRef ptr = v.getTranslation(n.expr()); 21 | LLVMValueRef val = LLVMBuildLoad(v.builder, ptr, "load"); 22 | v.addTranslation(n, val); 23 | return super.leaveTranslateLLVM(v); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangNullLitExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | import polyglot.ast.NullLit; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import static org.bytedeco.javacpp.LLVM.LLVMConstNull; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | public class JLangNullLitExt extends JLangExt { 15 | private static final long serialVersionUID = SerialVersionUID.generate(); 16 | 17 | @Override 18 | public Node leaveTranslateLLVM(LLVMTranslator v) { 19 | NullLit n = (NullLit) node(); 20 | v.addTranslation(n, LLVMConstNull(v.utils.toLL(n.type()))); 21 | return super.leaveTranslateLLVM(v); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangSpecialExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | import polyglot.ast.Special; 7 | import polyglot.util.InternalCompilerError; 8 | import polyglot.util.SerialVersionUID; 9 | 10 | import static org.bytedeco.javacpp.LLVM.*; 11 | 12 | import jlang.ast.JLangExt; 13 | import jlang.visit.LLVMTranslator; 14 | 15 | public class JLangSpecialExt extends JLangExt { 16 | private static final long serialVersionUID = SerialVersionUID.generate(); 17 | 18 | @Override 19 | public Node leaveTranslateLLVM(LLVMTranslator v) { 20 | Special n = (Special) node(); 21 | 22 | if (n.qualifier() != null) 23 | throw new InternalCompilerError( 24 | "Qualified this should have been desugared by the DesugarInnerClasses visitor"); 25 | if (n.kind().equals(Special.SUPER)) 26 | throw new InternalCompilerError( 27 | "super should have been desugared by the DesugarInnerClasses visitor"); 28 | assert n.kind().equals(Special.THIS); 29 | 30 | v.addTranslation(n, LLVMGetParam(v.currFn(), 0)); 31 | return super.leaveTranslateLLVM(v); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangSynchronizedEnterExt.java: -------------------------------------------------------------------------------- 1 | package jlang.extension; 2 | 3 | import jlang.ast.JLangExt; 4 | import jlang.ast.SynchronizedEnter; 5 | import jlang.util.Constants; 6 | import jlang.visit.LLVMTranslator; 7 | import org.bytedeco.javacpp.LLVM.LLVMTypeRef; 8 | import org.bytedeco.javacpp.LLVM.LLVMValueRef; 9 | import polyglot.ast.Node; 10 | 11 | import static jlang.extension.JLangSynchronizedExt.buildMonitorFunc; 12 | 13 | public class JLangSynchronizedEnterExt extends JLangExt { 14 | 15 | @Override 16 | public Node leaveTranslateLLVM(LLVMTranslator v) { 17 | SynchronizedEnter n = (SynchronizedEnter) node(); 18 | 19 | LLVMValueRef obj = v.getTranslation(n.expr()); 20 | 21 | buildMonitorFunc(v, Constants.MONITOR_ENTER, obj); 22 | 23 | return n; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangSynchronizedExitExt.java: -------------------------------------------------------------------------------- 1 | package jlang.extension; 2 | 3 | import jlang.ast.JLangExt; 4 | import jlang.ast.SynchronizedEnter; 5 | import jlang.ast.SynchronizedExit; 6 | import jlang.util.Constants; 7 | import jlang.visit.LLVMTranslator; 8 | import org.bytedeco.javacpp.LLVM.LLVMValueRef; 9 | import polyglot.ast.Node; 10 | 11 | import static jlang.extension.JLangSynchronizedExt.buildMonitorFunc; 12 | 13 | public class JLangSynchronizedExitExt extends JLangExt { 14 | 15 | @Override 16 | public Node leaveTranslateLLVM(LLVMTranslator v) { 17 | SynchronizedExit n = (SynchronizedExit) node(); 18 | 19 | LLVMValueRef obj = v.getTranslation(n.expr()); 20 | 21 | buildMonitorFunc(v, Constants.MONITOR_EXIT, obj); 22 | 23 | return n; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangThrowExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | import polyglot.ast.Throw; 7 | 8 | import java.lang.Override; 9 | 10 | import jlang.ast.JLangExt; 11 | import jlang.util.Constants; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | import static org.bytedeco.javacpp.LLVM.*; 15 | 16 | public class JLangThrowExt extends JLangExt { 17 | 18 | @Override 19 | public Node leaveTranslateLLVM(LLVMTranslator v) { 20 | Throw n = (Throw) node(); 21 | LLVMValueRef createExnFun = v.utils.getFunction(Constants.CREATE_EXCEPTION, 22 | v.utils.functionType(v.utils.i8Ptr(), v.utils.i8Ptr())); 23 | LLVMValueRef throwExnFunc = v.utils.getFunction(Constants.THROW_EXCEPTION, 24 | v.utils.functionType(LLVMVoidTypeInContext(v.context), v.utils.i8Ptr())); 25 | LLVMValueRef cast = LLVMBuildBitCast( 26 | v.builder, v.getTranslation(n.expr()), v.utils.i8Ptr(), "cast"); 27 | LLVMValueRef exn = v.utils.buildFunCall(createExnFun, cast); 28 | v.utils.buildProcCall(throwExnFunc, exn); 29 | LLVMBuildUnreachable(v.builder); 30 | return super.leaveTranslateLLVM(v); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/JLangWhileExt.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.extension; 4 | 5 | import polyglot.ast.Node; 6 | import polyglot.ast.While; 7 | import polyglot.util.SerialVersionUID; 8 | 9 | import java.lang.Override; 10 | 11 | import jlang.ast.JLangExt; 12 | import jlang.visit.LLVMTranslator; 13 | 14 | import static org.bytedeco.javacpp.LLVM.*; 15 | 16 | public class JLangWhileExt extends JLangExt { 17 | private static final long serialVersionUID = SerialVersionUID.generate(); 18 | 19 | @Override 20 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) { 21 | While n = (While) node(); 22 | 23 | LLVMBasicBlockRef cond = v.utils.buildBlock("while.cond"); 24 | LLVMBasicBlockRef body = v.utils.buildBlock("while.body"); 25 | LLVMBasicBlockRef end = v.utils.buildBlock("while.end"); 26 | 27 | v.pushLoop(cond, end); 28 | 29 | // Conditional. 30 | LLVMBuildBr(v.builder, cond); 31 | LLVMPositionBuilderAtEnd(v.builder, cond); 32 | lang().translateLLVMConditional(n.cond(), v, body, end); 33 | 34 | // Body. 35 | LLVMPositionBuilderAtEnd(v.builder, body); 36 | n.visitChild(n.body(), v); 37 | v.utils.branchUnlessTerminated(cond); 38 | 39 | LLVMPositionBuilderAtEnd(v.builder, end); 40 | v.popLoop(); 41 | return n; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /compiler/src/jlang/extension/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | AST extensions and delegates for the JLang language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/jlang/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | JLang language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /compiler/src/jlang/structures/DispatchVector.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.structures; 4 | 5 | import org.bytedeco.javacpp.LLVM.LLVMTypeRef; 6 | import org.bytedeco.javacpp.LLVM.LLVMValueRef; 7 | import polyglot.types.MethodInstance; 8 | import polyglot.types.ReferenceType; 9 | 10 | /** 11 | * Defines the layout of a dispatch vector in terms of LLVM IR. 12 | * Translations wishing to access elements in a dispatch vector at 13 | * runtime should go through this interface. 14 | */ 15 | public interface DispatchVector { 16 | 17 | /** Returns an LLVM type representing the dispatch vector layout. */ 18 | LLVMTypeRef structTypeRef(ReferenceType rt); 19 | 20 | /** Initializes the dispatch vector for a specific concrete class. */ 21 | void initializeDispatchVectorFor(ReferenceType rt); 22 | 23 | /** Returns a pointer to the dispatch vector for a specific concrete class. */ 24 | LLVMValueRef getDispatchVectorFor(ReferenceType rt); 25 | 26 | /** Returns a pointer to the specified method in a dispatch vector. */ 27 | LLVMValueRef buildFuncElementPtr(LLVMValueRef dvPtr, ReferenceType rt, MethodInstance mi); 28 | } 29 | -------------------------------------------------------------------------------- /compiler/src/jlang/test/TestAll.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.test; 4 | 5 | import org.junit.runner.RunWith; 6 | import org.junit.runners.Suite; 7 | import org.junit.runners.Suite.SuiteClasses; 8 | 9 | @RunWith(Suite.class) 10 | @SuiteClasses({ TestFunctional.class }) 11 | 12 | public class TestAll { 13 | } 14 | -------------------------------------------------------------------------------- /compiler/src/jlang/types/JLangClassFileLazyClassInitializer.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.types; 4 | 5 | import polyglot.ext.jl5.types.reflect.JL5ClassFileLazyClassInitializer; 6 | import polyglot.types.ClassType; 7 | import polyglot.types.MethodInstance; 8 | import polyglot.types.reflect.ClassFile; 9 | import polyglot.types.reflect.Method; 10 | 11 | public class JLangClassFileLazyClassInitializer extends JL5ClassFileLazyClassInitializer { 12 | 13 | JLangTypeSystem ts; 14 | 15 | public JLangClassFileLazyClassInitializer(ClassFile file, JLangTypeSystem ts) { 16 | super(file, ts); 17 | this.ts = ts; 18 | } 19 | 20 | @Override 21 | protected MethodInstance methodInstance(Method m, ClassType ct) { 22 | MethodInstance mi = super.methodInstance(m, ct); 23 | JLangParsedClassType_c pct = (JLangParsedClassType_c) ct; 24 | if (pct.isNewMethod(mi)) { 25 | return mi; 26 | } else { 27 | return null; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /compiler/src/jlang/types/JLangLocalInstance.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.types; 4 | 5 | import polyglot.ext.jl5.types.JL5LocalInstance; 6 | 7 | public interface JLangLocalInstance extends JL5LocalInstance { 8 | 9 | /** 10 | * Whether this is a compiler-generated variable that should not be 11 | * visible to the user when debugging. 12 | */ 13 | boolean isTemp(); 14 | 15 | /** Whether this variable is in SSA form. */ 16 | boolean isSSA(); 17 | } 18 | -------------------------------------------------------------------------------- /compiler/src/jlang/types/JLangLocalInstance_c.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.types; 4 | 5 | import polyglot.ext.jl5.types.JL5LocalInstance_c; 6 | import polyglot.types.Flags; 7 | import polyglot.types.Type; 8 | import polyglot.types.TypeSystem; 9 | import polyglot.util.Position; 10 | 11 | public class JLangLocalInstance_c 12 | extends JL5LocalInstance_c 13 | implements JLangLocalInstance { 14 | private final boolean isTemp, isSSA; 15 | 16 | public JLangLocalInstance_c( 17 | TypeSystem ts, Position pos, Flags flags, Type type, String name, 18 | boolean isTemp, boolean isSSA) { 19 | super(ts, pos, flags, type, name); 20 | this.isTemp = isTemp; 21 | this.isSSA = isSSA; 22 | } 23 | 24 | @Override 25 | public boolean isTemp() { 26 | return isTemp; 27 | } 28 | 29 | @Override 30 | public boolean isSSA() { 31 | return isSSA; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /compiler/src/jlang/types/JLangTypeSystem.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.types; 4 | 5 | import polyglot.ext.jl5.types.JL5MethodInstance; 6 | import polyglot.ext.jl5.types.JL5Subst; 7 | import polyglot.ext.jl7.types.JL7TypeSystem; 8 | import polyglot.types.ClassType; 9 | import polyglot.types.Flags; 10 | import polyglot.types.ParsedClassType; 11 | import polyglot.types.Type; 12 | import polyglot.util.Position; 13 | 14 | public interface JLangTypeSystem extends JL7TypeSystem { 15 | 16 | ParsedClassType ArrayObject(); 17 | 18 | ClassType RuntimeHelper(); 19 | 20 | @Override 21 | JLangLocalInstance localInstance(Position pos, Flags flags, Type type, String name); 22 | 23 | /** 24 | * Creates a local instance with the option of making it a temp variable, which 25 | * is hidden from the user when debugging. 26 | */ 27 | JLangLocalInstance localInstance( 28 | Position pos, Flags flags, Type type, String name, boolean isTemp, boolean isSSA); 29 | 30 | SubstMethodInstance substMethodInstance(JL5MethodInstance postSubst, 31 | JL5MethodInstance preSubst, JL5Subst subst); 32 | 33 | 34 | /** Returns whether two types are equal when ignoring generics. */ 35 | boolean typeEqualsErased(Type a, Type b); 36 | 37 | /** Returns whether {@code a} is a subtype of {@code b}, ignoring generics. */ 38 | boolean isSubtypeErased(Type a, Type b); 39 | } 40 | -------------------------------------------------------------------------------- /compiler/src/jlang/types/SubstMethodInstance.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.types; 4 | 5 | import polyglot.ext.jl5.types.JL5MethodInstance; 6 | import polyglot.ext.jl5.types.JL5Subst; 7 | 8 | /** 9 | * Represents a Java method whose type parameters have been substituted, but 10 | * also keeps track of information about this substitution. All methods produced 11 | * by type-checking a method call are instances of this type. 12 | * 13 | *

14 | * In Polyglot, type-checking a method call produces the substituted method 15 | * instance, but does not give back the substitution for the method's type 16 | * parameters. This interface provides a workaround to allow for querying about 17 | * the substitution for a method's type parameters in the scenario of a method 18 | * call. 19 | * 20 | */ 21 | public interface SubstMethodInstance extends JL5MethodInstance { 22 | /** 23 | * Returns the method before substituting its type parameters. The returned 24 | * value cannot be a {@link SubstMethodInstance}. 25 | */ 26 | JL5MethodInstance base(); 27 | 28 | /** 29 | * Returns the substitution for the type parameters of the method. If the 30 | * original method is not parameterized, it returns an empty substitution. 31 | */ 32 | JL5Subst subst(); 33 | } 34 | -------------------------------------------------------------------------------- /compiler/src/jlang/util/CollectUtils.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.util; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.List; 7 | 8 | public final class CollectUtils { 9 | 10 | static public T[] toArray(List l, Class clazz) { 11 | @SuppressWarnings("unchecked") 12 | T[] res = (T[]) Array.newInstance(clazz, l.size()); 13 | int idx = 0; 14 | for (T t : l) 15 | res[idx++] = t; 16 | return res; 17 | } 18 | 19 | static public T[] toArray(T head, List l, Class clazz) { 20 | @SuppressWarnings("unchecked") 21 | T[] res = (T[]) Array.newInstance(clazz, 1 + l.size()); 22 | int idx = 0; 23 | res[idx++] = head; 24 | for (T t : l) 25 | res[idx++] = t; 26 | return res; 27 | } 28 | 29 | static public T[] toArray(T t1, T t2, List l, 30 | Class clazz) { 31 | @SuppressWarnings("unchecked") 32 | T[] res = (T[]) Array.newInstance(clazz, 2 + l.size()); 33 | int idx = 0; 34 | res[idx++] = t1; 35 | res[idx++] = t2; 36 | for (T t : l) 37 | res[idx++] = t; 38 | return res; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /compiler/src/jlang/util/DesugarBarrier.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.util; 4 | 5 | import jlang.JLangScheduler; 6 | import polyglot.frontend.Job; 7 | import polyglot.frontend.goals.Barrier; 8 | import polyglot.frontend.goals.Goal; 9 | 10 | public class DesugarBarrier extends Barrier { 11 | 12 | private final JLangScheduler jlangScheduler; 13 | 14 | public static DesugarBarrier create(JLangScheduler s) { 15 | return new DesugarBarrier(s); 16 | } 17 | 18 | protected DesugarBarrier(JLangScheduler scheduler) { 19 | super(scheduler); 20 | this.jlangScheduler = scheduler; 21 | } 22 | 23 | @Override 24 | public Goal goalForJob(Job job) { 25 | return this.jlangScheduler.LLVMDesugared(job); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /compiler/src/jlang/util/JLangFreshGen.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.util; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public class JLangFreshGen { 9 | 10 | private static JLangFreshGen instance = null; 11 | 12 | Map prefixMap; 13 | 14 | private JLangFreshGen() { 15 | prefixMap = new HashMap<>(); 16 | } 17 | 18 | private static JLangFreshGen instance() { 19 | if (instance == null) { 20 | instance = new JLangFreshGen(); 21 | } 22 | return instance; 23 | } 24 | 25 | private String freshString(String string) { 26 | String ret; 27 | if (prefixMap.containsKey(string)) { 28 | ret = string + prefixMap.get(string); 29 | prefixMap.put(string, prefixMap.get(string) + 1); 30 | } 31 | else { 32 | ret = string + "0"; 33 | prefixMap.put(string, 1); 34 | } 35 | return ret; 36 | } 37 | 38 | public static String fresh() { 39 | return instance().freshString("fresh"); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /compiler/src/jlang/visit/StringLitFold.java: -------------------------------------------------------------------------------- 1 | package jlang.visit; 2 | 3 | import polyglot.ast.Binary; 4 | import polyglot.ast.Expr; 5 | import polyglot.ast.Node; 6 | import polyglot.ast.NodeFactory; 7 | import polyglot.types.TypeSystem; 8 | import polyglot.util.Position; 9 | import polyglot.visit.NodeVisitor; 10 | 11 | /** 12 | * Created by dantech on 11/4/18. 13 | */ 14 | public class StringLitFold extends NodeVisitor { 15 | 16 | protected TypeSystem ts; 17 | protected NodeFactory nf; 18 | 19 | public StringLitFold(TypeSystem ts, NodeFactory nf) { 20 | super(nf.lang()); 21 | this.ts = ts; 22 | this.nf = nf; 23 | } 24 | 25 | @Override 26 | public Node leave(Node old, Node n, NodeVisitor v_) { 27 | if (!(n instanceof Expr)) { 28 | return n; 29 | } 30 | 31 | Expr e = (Expr) n; 32 | 33 | if (!lang().isConstant(e, lang())) { 34 | return e; 35 | } 36 | 37 | if (e instanceof Binary) { 38 | Binary b = (Binary) e; 39 | 40 | if (b.operator() == Binary.ADD 41 | && lang().constantValue(b.left(), lang()) instanceof String 42 | && lang().constantValue(b.right(), lang()) instanceof String) { 43 | String lit = (String) lang().constantValue(b, lang()); 44 | Position pos = e.position(); 45 | return nf.StringLit(pos, lit).type(ts.String()); 46 | } 47 | } 48 | 49 | return e; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /compiler/src/jlang/visit/package.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | Visitors for the JLang language extension. 4 |

5 | 6 | -------------------------------------------------------------------------------- /defs.Darwin: -------------------------------------------------------------------------------- 1 | export SHARED_LIB_EXT := dylib 2 | 3 | # TODO: Ideally would would not need dynamic_lookup here. 4 | export LIBJVM_FLAGS += \ 5 | -current_version 1.0.0 -compatibility_version 1.0.0 \ 6 | -undefined dynamic_lookup 7 | 8 | # use xcode header search path for macOS 10.15+ 9 | export MACOS_FLAGS := 10 | ifeq ($(shell expr $(shell sw_vers -productVersion) \>= 10.15),1) 11 | MACOS_FLAGS += \ 12 | -isysroot $(shell xcrun --show-sdk-path) \ 13 | -I/usr/local/include 14 | endif 15 | 16 | -------------------------------------------------------------------------------- /defs.Linux: -------------------------------------------------------------------------------- 1 | export SHARED_LIB_EXT := so 2 | export JDK7_LIB_PATH := $(JDK7)/jre/lib/amd64 3 | export LIBJVM_FLAGS = $(SHARED_LIB_FLAGS) -Wl,--version-script=linux_version.map -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _site/ 2 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | Making changes to the website 2 | ----------------------------- 3 | 4 | Documentation is translated from Markdown to HTML using [Jekyll](http://jekyllrb.com), which is well integrated with Github. To make changes to the website, simply edit a Markdown file and push to master. To preview local changes, install Jekyll and type `jekyll serve`. 5 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | kramdown: 2 | input: GFM 3 | hard_wrap: false 4 | project: "JLang" 5 | contact: jlang-users-l@cornell.edu 6 | contact-join: jlang-users-l-request@cornell.edu 7 | update-month: March 8 | update-year: 2020 9 | update-date: 3-1-2020 10 | 11 | github: 12 | url: https://github.com/polyglot-compiler/JLang 13 | 14 | -------------------------------------------------------------------------------- /docs/contact-us.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Contact Us" 3 | layout: subscribe 4 | --- 5 | 6 | 7 | Mailing List 8 | ------------ 9 | 10 | There is a mailing list for JLang users and contributors. 11 | This is a great forum for development, design and feature discussions. Use the form below to join the JLang users list! 12 | 13 | To report bugs or monitor in-development improvements, please check the Github issues page. 14 | 15 | 16 | 17 | Contributor Contact 18 | ------------------ 19 | 20 | For any questions which can't be addressed in the above methods, please reach out to Drew Zagieboylo or Andrew C. Myers. 21 | -------------------------------------------------------------------------------- /examples/cup/Makefile.obj: -------------------------------------------------------------------------------- 1 | OUT := out 2 | LL := $(shell find $(OUT)/java_cup/runtime -name "*.ll") 3 | OBJ := $(LL:%.ll=%.o) 4 | 5 | all: $(OBJ) 6 | .PHONY: all 7 | 8 | $(OBJ): %.o: %.ll 9 | @echo "Compiling $<" 10 | @$(CLANG) -Wno-override-module -fPIC -c -o $@ $< 11 | -------------------------------------------------------------------------------- /examples/cup/bin/JFlex.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/bin/JFlex.jar -------------------------------------------------------------------------------- /examples/cup/bin/cup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 3 | export JAVA_HOME="$JDK7" 4 | "$DIR"/Main.o "$@" 5 | -------------------------------------------------------------------------------- /examples/cup/bin/debug-cup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 3 | export JAVA_HOME="$JDK7" 4 | gdb "$DIR"/Main.o "$@" 5 | -------------------------------------------------------------------------------- /examples/cup/bin/java-cup-11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/bin/java-cup-11.jar -------------------------------------------------------------------------------- /examples/cup/changelog.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/changelog.txt -------------------------------------------------------------------------------- /examples/cup/src/java/.gitignore: -------------------------------------------------------------------------------- 1 | #/java_cup/parser.java 2 | #/java_cup/sym.java 3 | #/java_cup/Lexer.java -------------------------------------------------------------------------------- /examples/cup/src/java/java_cup/assoc.java: -------------------------------------------------------------------------------- 1 | package java_cup; 2 | 3 | /* Defines integers that represent the associativity of terminals 4 | * @version last updated: 7/3/96 5 | * @author Frank Flannery 6 | */ 7 | 8 | public class assoc { 9 | 10 | /* various associativities, no_prec being the default value */ 11 | public final static int left = 0; 12 | public final static int right = 1; 13 | public final static int nonassoc = 2; 14 | public final static int no_prec = -1; 15 | 16 | } -------------------------------------------------------------------------------- /examples/cup/src/java/java_cup/internal_error.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup; 3 | 4 | /** Exception subclass for reporting internal errors in JavaCup. */ 5 | public class internal_error extends Exception 6 | { 7 | /** Constructor with a message */ 8 | public internal_error(String msg) 9 | { 10 | super(msg); 11 | } 12 | 13 | /** Method called to do a forced error exit on an internal error 14 | for cases when we can't actually throw the exception. */ 15 | public void crash() 16 | { 17 | ErrorManager.getManager().emit_fatal("JavaCUP Internal Error Detected: "+getMessage()); 18 | printStackTrace(); 19 | System.exit(-1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/cup/src/java/java_cup/runtime/Scanner.java: -------------------------------------------------------------------------------- 1 | package java_cup.runtime; 2 | 3 | /** 4 | * Defines the Scanner interface, which CUP uses in the default 5 | * implementation of lr_parser.scan(). Integration 6 | * of scanners implementing Scanner is facilitated. 7 | * 8 | * @version last updated 23-Jul-1999 9 | * @author David MacMahon 10 | */ 11 | 12 | /* ************************************************* 13 | Interface Scanner 14 | 15 | Declares the next_token() method that should be 16 | implemented by scanners. This method is typically 17 | called by lr_parser.scan(). End-of-file can be 18 | indicated either by returning 19 | new Symbol(lr_parser.EOF_sym()) or 20 | null. 21 | ***************************************************/ 22 | public interface Scanner { 23 | /** Return the next token, or null on end-of-file. */ 24 | public Symbol next_token() throws java.lang.Exception; 25 | } 26 | -------------------------------------------------------------------------------- /examples/cup/src/java/java_cup/runtime/ScannerBuffer.java: -------------------------------------------------------------------------------- 1 | package java_cup.runtime; 2 | 3 | import java.util.Collections; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | public class ScannerBuffer implements Scanner { 8 | private Scanner inner; 9 | private List buffer = new LinkedList(); 10 | /** 11 | * Wraps around a custom scanner and stores all so far produced tokens in a buffer 12 | * @param inner the scanner to buffer 13 | */ 14 | public ScannerBuffer(Scanner inner){ 15 | this.inner=inner; 16 | } 17 | /** 18 | * Read-Only access to the buffered Symbols 19 | * @return an unmodifiable Version of the buffer 20 | */ 21 | public List getBuffered() { 22 | return Collections.unmodifiableList(buffer); 23 | } 24 | @Override 25 | public Symbol next_token() throws Exception { 26 | Symbol buffered = inner.next_token(); 27 | buffer.add(buffered); 28 | return buffered; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /examples/cup/target/.gitignore: -------------------------------------------------------------------------------- 1 | /classes/ 2 | /dist/ -------------------------------------------------------------------------------- /examples/cup/test/example.cup: -------------------------------------------------------------------------------- 1 | import java_cup.runtime.*; 2 | 3 | parser code {: 4 | // Connect this parser to a scanner! 5 | scanner s; 6 | Parser(scanner s){ this.s=s; } 7 | :} 8 | 9 | /* define how to connect to the scanner! */ 10 | init with {: s.init(); :}; 11 | scan with {: return s.next_token(); :}; 12 | 13 | /* Terminals (tokens returned by the scanner). */ 14 | terminal SEMI, PLUS, MINUS, TIMES, UMINUS, LPAREN, RPAREN; 15 | terminal Integer NUMBER; // our scanner provides numbers as integers 16 | 17 | /* Non terminals */ 18 | non terminal expr_list; 19 | non terminal Integer expr; // used to store evaluated subexpressions 20 | 21 | /* Precedences */ 22 | precedence left PLUS, MINUS; 23 | precedence left TIMES; 24 | precedence left UMINUS; 25 | 26 | /* The grammar rules */ 27 | expr_list ::= expr_list expr:e SEMI {: System.out.println(e);:} 28 | | expr:e SEMI {: System.out.println(e);:} 29 | ; 30 | expr ::= expr:e1 PLUS expr:e2 {: RESULT = e1+e2; :} 31 | | expr:e1 MINUS expr:e2 {: RESULT = e1-e2; :} 32 | | expr:e1 TIMES expr:e2 {: RESULT = e1*e2; :} 33 | | MINUS expr:e {: RESULT = -e; :} 34 | %prec UMINUS 35 | | LPAREN expr:e RPAREN {: RESULT = e; :} 36 | | NUMBER:n {: RESULT = n; :} 37 | ; 38 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/.gitignore: -------------------------------------------------------------------------------- 1 | output.html 2 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/Constants.java: -------------------------------------------------------------------------------- 1 | public interface Constants { 2 | 3 | public static final int INTTYPE = 1; 4 | public static final int BOOLTYPE = 2; 5 | 6 | public static final int TRUE = 1; 7 | public static final int FALSE = 0; 8 | 9 | public static final int PLUS = 1; 10 | public static final int MINUS = 2; 11 | public static final int MULT = 3; 12 | public static final int DIV = 4; 13 | public static final int MOD = 5; 14 | 15 | public static final int LEQ = 1; 16 | public static final int LE = 2; 17 | public static final int GT = 3; 18 | public static final int GTQ = 4; 19 | public static final int EQ = 5; 20 | public static final int NEQ = 6; 21 | public static final int AND = 7; 22 | public static final int OR = 8; 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/c/.gitignore: -------------------------------------------------------------------------------- 1 | *.java 2 | *.class 3 | *.xml 4 | output.html 5 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/c/input.c: -------------------------------------------------------------------------------- 1 | int a=0; 2 | 3 | int c; 4 | 5 | void main(int d, int e){ 6 | int f = 3; 7 | int h=f, b=0; 8 | h + 1; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/c/makeTest.sh: -------------------------------------------------------------------------------- 1 | rm *.java 2 | rm *.class 3 | jflex c.jflex 4 | ../../bin/cup.sh -locations -interface -parser Parser -xmlactions c.cup 5 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java 6 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser input.c simple.xml 7 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser complicated.c complicated.xml 8 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/c/tree-view.css: -------------------------------------------------------------------------------- 1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black } 2 | 3 | .connector { font-family: monospace; } 4 | 5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold; 6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 7 | .altname { color: navy; text-decoration: underline } 8 | .uri { color: #444; font-style: italic } 9 | .value { color: #040; background-color: #CCC; font-weight: bold } 10 | .escape { color: #620; font-family: monospace } 11 | 12 | .root { color: yellow; background-color: black } 13 | .element { color: yellow; background-color: navy } 14 | .namespace { color: yellow; background-color: #333 } 15 | .attribute { color: yellow; background-color: #040 } 16 | .text { color: yellow; background-color: #400 } 17 | .pi { color: yellow; background-color: #044 } 18 | .comment { color: yellow; background-color: #303 } 19 | 20 | .root,.element,.attribute,.namespace,.text,.comment,.pi 21 | { font-weight: bold; 22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 23 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/calc/.gitignore: -------------------------------------------------------------------------------- 1 | *.java 2 | *.class 3 | *.xml 4 | output.html 5 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/calc/calc.cup: -------------------------------------------------------------------------------- 1 | /* Simple +/-/* expression language; parser evaluates constant expressions on the fly*/ 2 | import java_cup.runtime.*; 3 | 4 | parser code {: 5 | scanner s; 6 | Parser(scanner s){ 7 | this.s=s; 8 | } 9 | :} 10 | init with {: s.init(); :}; 11 | scan with {: return s.next_token(); :}; 12 | /* Terminals (tokens returned by the scanner). */ 13 | terminal SEMI, PLUS, MINUS, TIMES, UMINUS, LPAREN, RPAREN; 14 | terminal Integer NUMBER; // our scanner provides numbers as integers 15 | 16 | /* Non terminals */ 17 | non terminal expr_list; 18 | non terminal Integer expr; // used to store evaluated subexpressions 19 | 20 | /* Precedences */ 21 | precedence left PLUS, MINUS; 22 | precedence left TIMES; 23 | precedence left UMINUS; 24 | 25 | /* The grammar rules */ 26 | expr_list ::= expr_list expr:e SEMI {: System.out.println(e);:} 27 | | expr:e SEMI {: System.out.println(e);:} 28 | ; 29 | expr ::= expr:e1 PLUS expr:e2 {: RESULT = e1+e2; :} 30 | | expr:e1 MINUS expr:e2 {: RESULT = e1-e2; :} 31 | | expr:e1 TIMES expr:e2 {: RESULT = e1*e2; :} 32 | | MINUS expr:e {: RESULT = -e; :} 33 | %prec UMINUS 34 | | LPAREN expr:e RPAREN {: RESULT = e; :} 35 | | NUMBER:n {: RESULT = n; :} 36 | ; 37 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/calc/makeCalc.sh: -------------------------------------------------------------------------------- 1 | ../../bin/cup.sh -interface -parser Parser calc.cup 2 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java 3 | java -cp ../../dist/java-cup-11b-runtime.jar:. Main 4 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/input.minijava: -------------------------------------------------------------------------------- 1 | int x, y; 2 | y = 10; 3 | x = read(); 4 | while (1-y <= -x) { 5 | y = x * (-y + 5); 6 | } 7 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/makeAnnotatedTest.sh: -------------------------------------------------------------------------------- 1 | mkdir -p out 2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions test-correctannotations.cup 3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ -d out *.java out/*.java 4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_annotated.xml 5 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/makeNonAnnotatedTest.sh: -------------------------------------------------------------------------------- 1 | mkdir -p out 2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions -genericlabels test-noannotations.cup 3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ -d out *.java out/*.java 4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_not_annotated.xml 5 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/makeXMLtest.sh: -------------------------------------------------------------------------------- 1 | mkdir -p out 2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions test2.cup 3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ *.java out/*.java 4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_xml.xml 5 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava/TestVisitor.java: -------------------------------------------------------------------------------- 1 | import java_cup.runtime.SyntaxTreeDFS.AbstractVisitor; 2 | import java_cup.runtime.SyntaxTreeDFS; 3 | import java_cup.runtime.XMLElement; 4 | import java.util.List; 5 | 6 | public class TestVisitor extends AbstractVisitor { 7 | public TestVisitor(){ 8 | registerPreVisit("stmt",this::preVisitStatement); 9 | } 10 | public void preVisitStatement(XMLElement element, List children){ 11 | System.out.println("Found a statement"); 12 | SyntaxTreeDFS.dfs(element,new TerminalFilter()); 13 | } 14 | public void defaultPre(XMLElement elem, List children) {} 15 | public void defaultPost(XMLElement elem, List children) {} 16 | } 17 | 18 | class TerminalFilter extends AbstractVisitor { 19 | public void defaultPre(XMLElement elem, List children) { 20 | if (elem instanceof XMLElement.Terminal) 21 | System.out.println(""+elem); 22 | } 23 | public void defaultPost(XMLElement elem, List children) {} 24 | } 25 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava/make.sh: -------------------------------------------------------------------------------- 1 | rm Parser.java Lexer.java 2 | rm *.class 3 | jflex minijava.jflex 4 | ../../bin/cup.sh -locations -interface -parser Parser -xmlactions minijava.cup 5 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java 6 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser simple.minijava simple.xml / 7 | basex codegen.sq output.xml > simple.minijvm 8 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava/simple.minijava: -------------------------------------------------------------------------------- 1 | int x, y; 2 | y = 10; 3 | x = read(); 4 | write(x); 5 | if (x>=0) 6 | write (y); 7 | else 8 | write (x); 9 | while (1-y <= -x) { 10 | y = x * (-y + 5); 11 | } 12 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava/tree-view.css: -------------------------------------------------------------------------------- 1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black } 2 | 3 | .connector { font-family: monospace; } 4 | 5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold; 6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 7 | .altname { color: navy; text-decoration: underline } 8 | .uri { color: #444; font-style: italic } 9 | .value { color: #040; background-color: #CCC; font-weight: bold } 10 | .escape { color: #620; font-family: monospace } 11 | 12 | .root { color: yellow; background-color: black } 13 | .element { color: yellow; background-color: navy } 14 | .namespace { color: yellow; background-color: #333 } 15 | .attribute { color: yellow; background-color: #040 } 16 | .text { color: yellow; background-color: #400 } 17 | .pi { color: yellow; background-color: #044 } 18 | .comment { color: yellow; background-color: #303 } 19 | 20 | .root,.element,.attribute,.namespace,.text,.comment,.pi 21 | { font-weight: bold; 22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 23 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/bin/JFlex.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/testgrammars/minijava2/bin/JFlex.jar -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/expres.mp: -------------------------------------------------------------------------------- 1 | verbatimtex 2 | etex 3 | 4 | input expressg; 5 | 6 | beginfig(1); 7 | z3=(0,0); 8 | drawovalbox(3,40,17)(btex \tt start etex); 9 | z1c=z3c-(0,40); 10 | drawdiamondbox(1,45,25)(btex \tt x > 5 etex); 11 | z2c=z1c-(0,40); 12 | drawLEVENT(2,55,15)(btex \tt x=read(); etex); 13 | z4c=z2c-(0,40); 14 | drawENT(4,40,15)(btex \tt x=5; etex); 15 | z5=z3c-(0,160); 16 | drawovalbox(5,40,17)(btex \tt stop etex); 17 | 18 | drawnormalCA(3bm,1tm); 19 | drawnormalCA(2bm,4tm); 20 | drawnormalCA(4bm,5tm); 21 | endfig; 22 | end; -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/input.minijava: -------------------------------------------------------------------------------- 1 | int x, y; 2 | y = 10; 3 | x = read(); 4 | read(); 5 | while (1-y <= -x) { 6 | y = x * (-y + 5); 7 | } 8 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/src/minijava/Constants.java: -------------------------------------------------------------------------------- 1 | // Technische Universitaet Muenchen 2 | // Fakultaet fuer Informatik 3 | // Riitta Hoellerer 4 | // 5 | // Praktikum des Uebersetzerbaus 6 | // SS 2001 7 | // 8 | // interface containing constants (for Lexer, IdentificationVisitor and 9 | // EmitCodeVisitor) 10 | // 11 | package minijava; 12 | public interface Constants { 13 | 14 | public static final int INTTYPE = 1; 15 | public static final int BOOLTYPE = 2; 16 | 17 | public static final int TRUE = 1; 18 | public static final int FALSE = 0; 19 | 20 | public static final int PLUS = 1; 21 | public static final int MINUS = 2; 22 | public static final int MULT = 3; 23 | public static final int DIV = 4; 24 | public static final int MOD = 5; 25 | 26 | public static final int LEQ = 1; 27 | public static final int LE = 2; 28 | public static final int GT = 3; 29 | public static final int GTQ = 4; 30 | public static final int EQ = 5; 31 | public static final int NEQ = 6; 32 | public static final int AND = 7; 33 | public static final int OR = 8; 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/src/minijava/Decl.java: -------------------------------------------------------------------------------- 1 | package minijava; 2 | import java.util.List; 3 | public class Decl { 4 | public List varlist; 5 | public Decl(List l){ 6 | varlist = l; 7 | } 8 | public String toString(){ 9 | String ret = "int "+varlist.get(0); 10 | for (int i = 1; i < varlist.size(); i++) ret += ","+varlist.get(i); 11 | return ret+";\n"; 12 | } 13 | public void accept(MinijavaVisitor v){ 14 | v.preVisit(this); 15 | v.postVisit(this); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/src/minijava/InMemoryParser.java: -------------------------------------------------------------------------------- 1 | package minijava; 2 | 3 | import java.io.InputStream; 4 | 5 | import java_cup.runtime.ComplexSymbolFactory; 6 | import minijava.Program; 7 | import miniparser.*; 8 | 9 | public class InMemoryParser { 10 | private InputStream in; 11 | public InMemoryParser(InputStream in) { 12 | this.in=in; 13 | } 14 | public Program parse() throws Exception { 15 | Lexer scanner = null; 16 | ComplexSymbolFactory csf = new ComplexSymbolFactory(); 17 | scanner = new Lexer( new java.io.InputStreamReader(in),csf ); 18 | Parser p = new Parser(scanner, csf); 19 | return (Program)p.parse().value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/minijava2/src/minijava/Program.java: -------------------------------------------------------------------------------- 1 | package minijava; 2 | import java.util.List; 3 | public class Program extends Stmt.Compound { 4 | public List ld; 5 | public Program(List ld, List ls){ 6 | super(ls); 7 | this.ld = ld; 8 | } 9 | public String toString(){ 10 | String ret="" ; 11 | for (Decl d: ld) ret += d; 12 | for (Stmt s: ls) ret += s; 13 | return ret; 14 | } 15 | public void accept(MinijavaVisitor v){ 16 | if (!v.preVisit(this)) return; 17 | for (Decl d: ld) d.accept(v); 18 | for (Stmt s: ls) s.accept(v); 19 | v.postVisit(this); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/cup/testgrammars/tree-view.css: -------------------------------------------------------------------------------- 1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black } 2 | 3 | .connector { font-family: monospace; } 4 | 5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold; 6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 7 | .altname { color: navy; text-decoration: underline } 8 | .uri { color: #444; font-style: italic } 9 | .value { color: #040; background-color: #CCC; font-weight: bold } 10 | .escape { color: #620; font-family: monospace } 11 | 12 | .root { color: yellow; background-color: black } 13 | .element { color: yellow; background-color: navy } 14 | .namespace { color: yellow; background-color: #333 } 15 | .attribute { color: yellow; background-color: #040 } 16 | .text { color: yellow; background-color: #400 } 17 | .pi { color: yellow; background-color: #044 } 18 | .comment { color: yellow; background-color: #303 } 19 | 20 | .root,.element,.attribute,.namespace,.text,.comment,.pi 21 | { font-weight: bold; 22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px } 23 | -------------------------------------------------------------------------------- /jdk-lite/.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | /bin/ 3 | -------------------------------------------------------------------------------- /jdk-lite/dump.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/jdk-lite/dump.txt -------------------------------------------------------------------------------- /jdk-lite/native/java/lang/Class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" { 5 | 6 | jstring JVM_GetClassName(JNIEnv *env, jclass cls); 7 | 8 | // Need mutable C-strings here, for RegisterNatives to accept them. 9 | char getNameName[] = "getName"; 10 | char getNameSig[] = "()Ljava/lang/String;"; 11 | 12 | static JNINativeMethod methods[] = { 13 | {getNameName, getNameSig, (void*) &JVM_GetClassName}, 14 | }; 15 | 16 | void Java_java_lang_Class_registerNatives(JNIEnv *env, jclass clazz) { 17 | env->RegisterNatives(clazz, methods, sizeof(methods)/sizeof(JNINativeMethod)); 18 | } 19 | 20 | } // extern "C" 21 | -------------------------------------------------------------------------------- /jdk-lite/native/java/lang/Object.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" { 5 | 6 | jint Java_java_lang_Object_hashCode__(JNIEnv* env, jobject o) { 7 | auto addr = reinterpret_cast(o); 8 | return static_cast(addr); 9 | } 10 | 11 | jclass Java_java_lang_Object_getClass__(JNIEnv* env, jobject o) { 12 | return env->GetObjectClass(o); 13 | } 14 | 15 | } // extern "C" 16 | -------------------------------------------------------------------------------- /jdk-lite/src/java/io/PrintStream.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.io; 4 | 5 | // Hack to easily get console I/O. 6 | public class PrintStream { 7 | 8 | public void print(Object o) { 9 | print(o == null ? "null" : o.toString()); 10 | } 11 | 12 | public void println(Object o) { 13 | println(o == null ? "null" : o.toString()); 14 | } 15 | 16 | public native void println(); 17 | 18 | public native void print(String s); 19 | public native void println(String s); 20 | 21 | public native void print(boolean n); 22 | public native void println(boolean n); 23 | 24 | public native void print(byte n); 25 | public native void println(byte n); 26 | 27 | public native void print(char c); 28 | public native void println(char c); 29 | 30 | public native void print(short n); 31 | public native void println(short n); 32 | 33 | public native void print(int n); 34 | public native void println(int n); 35 | 36 | public native void print(long n); 37 | public native void println(long n); 38 | 39 | public native void print(float n); 40 | public native void println(float n); 41 | 42 | public native void print(double n); 43 | public native void println(double n); 44 | 45 | public native void flush(); 46 | } 47 | -------------------------------------------------------------------------------- /jdk-lite/src/java/io/Serializable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.io; 4 | 5 | public interface Serializable { 6 | } -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/ArrayIndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException { 7 | 8 | public ArrayIndexOutOfBoundsException() { 9 | super(); 10 | } 11 | 12 | public ArrayIndexOutOfBoundsException(int index) { 13 | super("Array index out of range: " ); 14 | } 15 | 16 | public ArrayIndexOutOfBoundsException(String s) { 17 | super(s); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/ArrayStoreException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class ArrayStoreException extends RuntimeException { 7 | 8 | public ArrayStoreException() { 9 | super(); 10 | } 11 | 12 | public ArrayStoreException(String s) { 13 | super(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/AssertionError.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class AssertionError extends Error { 6 | 7 | public AssertionError() { 8 | } 9 | 10 | private AssertionError(String detailMessage) { 11 | super(detailMessage); 12 | } 13 | 14 | public AssertionError(Object detailMessage) { 15 | this(detailMessage.toString()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/AutoCloseable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public interface AutoCloseable { 6 | void close() throws Exception; 7 | } 8 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Class.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public final class Class { 6 | 7 | private static native void registerNatives(); 8 | static { 9 | registerNatives(); 10 | } 11 | 12 | public static Class forName(String name) { 13 | throw new RuntimeException("unimplemented"); 14 | } 15 | 16 | public native String getName(); 17 | 18 | public String toString() { 19 | String name = getName(); 20 | switch (name) { 21 | case "void": 22 | case "boolean": 23 | case "byte": 24 | case "char": 25 | case "short": 26 | case "int": 27 | case "long": 28 | case "float": 29 | case "double": 30 | return name; 31 | default: 32 | return "class " + name; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/ClassCastException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class ClassCastException extends RuntimeException { 7 | 8 | public ClassCastException() { 9 | super(); 10 | } 11 | 12 | public ClassCastException(String s) { 13 | super(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/ClassNotFoundException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class ClassNotFoundException extends Exception { 6 | 7 | public ClassNotFoundException() { 8 | super(); 9 | } 10 | 11 | public ClassNotFoundException(String s) { 12 | super(s); 13 | } 14 | 15 | public ClassNotFoundException(String s, Throwable t) { 16 | super(s, t); 17 | } 18 | } -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/CloneNotSupportedException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class CloneNotSupportedException extends Exception { 7 | 8 | public CloneNotSupportedException() { 9 | super(); 10 | } 11 | 12 | public CloneNotSupportedException(String s) { 13 | super(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Cloneable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public interface Cloneable { 6 | } 7 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Comparable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public interface Comparable { 6 | public int compareTo(T o); 7 | } 8 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Enum.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | import java.io.Serializable; 6 | import java.io.ObjectInputStream; 7 | 8 | public abstract class Enum> implements Serializable { 9 | private final String name; 10 | 11 | public final String name() { 12 | return name; 13 | } 14 | 15 | private final int ordinal; 16 | 17 | public final int ordinal() { 18 | return ordinal; 19 | } 20 | 21 | protected Enum(String name, int ordinal) { 22 | this.name = name; 23 | this.ordinal = ordinal; 24 | } 25 | 26 | public String toString() { 27 | return name; 28 | } 29 | 30 | public final boolean equals(Object other) { 31 | return this == other; 32 | } 33 | 34 | public final int hashCode() { 35 | return super.hashCode(); 36 | } 37 | 38 | protected final Object clone() { 39 | return this; 40 | } 41 | 42 | public final int compareTo(E o) { 43 | return 0; 44 | } 45 | 46 | public final Class getDeclaringClass() { 47 | return null; 48 | } 49 | 50 | public static > T valueOf(Class enumType, 51 | String name) { 52 | throw new RuntimeException("java.lang.Enum#valueOf unimplemented"); 53 | } 54 | 55 | private void readObject(ObjectInputStream in) {} 56 | 57 | private void readObjectNoData() {} 58 | } 59 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Error.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class Error extends Throwable { 6 | 7 | public Error() { 8 | super(); 9 | } 10 | 11 | public Error(String message) { 12 | super(message); 13 | } 14 | 15 | public Error(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public Error(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Exception.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class Exception extends Throwable { 6 | 7 | public Exception() { 8 | super(); 9 | } 10 | 11 | public Exception(String message) { 12 | super(message); 13 | } 14 | 15 | public Exception(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public Exception(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Float.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public final class Float extends Number { 6 | private final float value; 7 | 8 | public static String toString(float f) { 9 | return String.valueOf(f); 10 | } 11 | 12 | public Float(float value) { 13 | this.value = value; 14 | } 15 | 16 | public String toString() { 17 | return Float.toString(value); 18 | } 19 | 20 | public float floatValue() { 21 | return value; 22 | } 23 | 24 | public static boolean isNaN(float f) { 25 | return f != f; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/IllegalArgumentException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class IllegalArgumentException extends RuntimeException { 7 | 8 | public IllegalArgumentException() { 9 | super(); 10 | } 11 | 12 | public IllegalArgumentException(String s) { 13 | super(s); 14 | } 15 | 16 | public IllegalArgumentException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public IllegalArgumentException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/IllegalStateException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class IllegalStateException extends RuntimeException { 7 | 8 | public IllegalStateException() { 9 | super(); 10 | } 11 | 12 | public IllegalStateException(String s) { 13 | super(s); 14 | } 15 | 16 | public IllegalStateException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public IllegalStateException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/IndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public 6 | class IndexOutOfBoundsException extends RuntimeException { 7 | 8 | public IndexOutOfBoundsException() { 9 | super(); 10 | } 11 | 12 | public IndexOutOfBoundsException(String s) { 13 | super(s); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Integer.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public final class Integer extends Number { 6 | 7 | public static final int MAX_VALUE = 214748364; 8 | 9 | public static String toString(int i) { 10 | return String.valueOf(i); 11 | } 12 | 13 | public static Integer valueOf(int i) { 14 | return new Integer(i); 15 | } 16 | 17 | private final int value; 18 | 19 | public Integer(int value) { 20 | this.value = value; 21 | } 22 | 23 | public int intValue() { 24 | return value; 25 | } 26 | 27 | public float floatValue() { 28 | return (float) value; 29 | } 30 | 31 | public String toString() { 32 | return toString(value); 33 | } 34 | 35 | public int hashCode() { 36 | return value; 37 | } 38 | 39 | public boolean equals(Object obj) { 40 | if (obj instanceof Integer) { 41 | return value == ((Integer) obj).intValue(); 42 | } 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Iterable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | import java.util.Iterator; 6 | 7 | public interface Iterable { 8 | 9 | Iterator iterator(); 10 | } 11 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/JLangNotImplementedError.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class JLangNotImplementedError extends RuntimeException { 6 | 7 | public JLangNotImplementedError() { 8 | super(); 9 | } 10 | 11 | public JLangNotImplementedError(String s) { 12 | super(s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/NullPointerException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class NullPointerException extends RuntimeException { 6 | 7 | public NullPointerException() { super(); } 8 | 9 | public NullPointerException(String s) { super(s); } 10 | } 11 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Number.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class Number {} 6 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Object.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class Object { 6 | 7 | protected Object clone() throws CloneNotSupportedException { 8 | return this; 9 | } 10 | 11 | public boolean equals(Object other) { 12 | return this == other; 13 | } 14 | 15 | protected final void finalize() throws Throwable { 16 | throw new RuntimeException("Object#finalize() not implemented"); 17 | } 18 | 19 | public final native Class getClass(); 20 | 21 | public native int hashCode(); 22 | 23 | public final void notify() { 24 | throw new RuntimeException("Object#notify() not implemented"); 25 | } 26 | 27 | public final void notifyAll() { 28 | throw new RuntimeException("Object#notifyAll() not implemented"); 29 | } 30 | 31 | public String toString() { 32 | throw new RuntimeException("Object#toString() not implemented"); 33 | } 34 | 35 | public final void wait(long timeout) { 36 | throw new RuntimeException("Object#wait(long) not implemented"); 37 | } 38 | 39 | public final void wait(long timeout, int nanos) { 40 | throw new RuntimeException("Object#wait(long,int) not implemented"); 41 | } 42 | 43 | public final void wait() { 44 | throw new RuntimeException("Object#wait() not implemented"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Runnable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public interface Runnable { 6 | 7 | void run(); 8 | } 9 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/RuntimeException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class RuntimeException extends Exception { 6 | 7 | public RuntimeException() { 8 | super(); 9 | } 10 | 11 | public RuntimeException(String message) { 12 | super(message); 13 | } 14 | 15 | public RuntimeException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public RuntimeException(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/System.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | import java.io.PrintStream; 6 | 7 | public class System { 8 | public static PrintStream out = new PrintStream(); 9 | 10 | public static void initializeSystemClass() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/Throwable.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class Throwable { 6 | private String detailMessage; 7 | private Throwable cause; 8 | private Throwable suppressed; 9 | 10 | public Throwable() {} 11 | 12 | public Throwable(String s) { this(s, null); } 13 | 14 | public Throwable(String s, Throwable t) { 15 | this.detailMessage = s; 16 | } 17 | 18 | public Throwable(Throwable t) { 19 | this.detailMessage = t.detailMessage; 20 | this.cause = t; 21 | } 22 | 23 | void addSuppressed(Throwable t) { 24 | this.suppressed = t; 25 | } 26 | 27 | public String getMessage() { return detailMessage; } 28 | public String getLocalizedMessage() {return detailMessage;} 29 | public String toString() { return detailMessage; } 30 | } -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/UnsupportedOperationException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang; 4 | 5 | public class UnsupportedOperationException extends RuntimeException { 6 | 7 | public UnsupportedOperationException() { 8 | } 9 | 10 | public UnsupportedOperationException(String message) { 11 | super(message); 12 | } 13 | 14 | public UnsupportedOperationException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public UnsupportedOperationException(Throwable cause) { 19 | super(cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /jdk-lite/src/java/lang/annotation/Annotation.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.lang.annotation; 4 | 5 | public interface Annotation { 6 | 7 | boolean equals(Object obj); 8 | 9 | int hashCode(); 10 | 11 | String toString(); 12 | 13 | Class annotationType(); 14 | } 15 | -------------------------------------------------------------------------------- /jdk-lite/src/java/test/AbstractTest.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.test; 4 | 5 | public abstract class AbstractTest { 6 | 7 | public abstract String message(); 8 | 9 | public void printMessage() { 10 | System.out.println("My message is: " + message()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /jdk-lite/src/java/test/SubTest.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.test; 4 | 5 | public class SubTest extends Test { 6 | 7 | public void init() { 8 | this.setMessage("Sub Message"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /jdk-lite/src/java/test/Test.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.test; 4 | 5 | public class Test extends AbstractTest { 6 | 7 | private String message; 8 | 9 | public Test() { 10 | init(); 11 | } 12 | 13 | public void init() { 14 | this.message = "Base Message"; 15 | } 16 | 17 | public void setMessage(String msg) { 18 | this.message = msg; 19 | } 20 | 21 | public String message() { 22 | return this.message; 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/Collection.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public interface Collection extends Iterable { 6 | 7 | int size(); 8 | 9 | boolean isEmpty(); 10 | 11 | boolean contains(Object o); 12 | 13 | Iterator iterator(); 14 | 15 | Object[] toArray(); 16 | 17 | T[] toArray(T[] a); 18 | 19 | boolean add(E e); 20 | 21 | boolean remove(Object o); 22 | 23 | boolean containsAll(Collection c); 24 | 25 | boolean addAll(Collection c); 26 | 27 | boolean removeAll(Collection c); 28 | 29 | boolean retainAll(Collection c); 30 | 31 | void clear(); 32 | 33 | boolean equals(Object o); 34 | 35 | int hashCode(); 36 | } 37 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/ConcurrentModificationException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public class ConcurrentModificationException extends RuntimeException { 6 | 7 | public ConcurrentModificationException() { 8 | } 9 | 10 | public ConcurrentModificationException(String message) { 11 | super(message); 12 | } 13 | 14 | public ConcurrentModificationException(Throwable cause) { 15 | super(cause); 16 | } 17 | 18 | public ConcurrentModificationException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/Iterator.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public interface Iterator { 6 | 7 | boolean hasNext(); 8 | 9 | E next(); 10 | 11 | void remove(); 12 | } 13 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/List.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public interface List extends Collection { 6 | 7 | int size(); 8 | 9 | boolean isEmpty(); 10 | 11 | boolean contains(Object o); 12 | 13 | Iterator iterator(); 14 | 15 | Object[] toArray(); 16 | 17 | T[] toArray(T[] a); 18 | 19 | boolean add(E e); 20 | 21 | boolean remove(Object o); 22 | 23 | boolean containsAll(Collection c); 24 | 25 | boolean addAll(Collection c); 26 | 27 | boolean addAll(int index, Collection c); 28 | 29 | boolean removeAll(Collection c); 30 | 31 | boolean retainAll(Collection c); 32 | 33 | void clear(); 34 | 35 | boolean equals(Object o); 36 | 37 | int hashCode(); 38 | 39 | E get(int index); 40 | 41 | E set(int index, E element); 42 | 43 | void add(int index, E element); 44 | 45 | E remove(int index); 46 | 47 | int indexOf(Object o); 48 | 49 | int lastIndexOf(Object o); 50 | 51 | ListIterator listIterator(); 52 | 53 | ListIterator listIterator(int index); 54 | 55 | List subList(int fromIndex, int toIndex); 56 | } 57 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/ListIterator.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public interface ListIterator extends Iterator { 6 | 7 | boolean hasNext(); 8 | 9 | E next(); 10 | 11 | boolean hasPrevious(); 12 | 13 | E previous(); 14 | 15 | int nextIndex(); 16 | 17 | int previousIndex(); 18 | 19 | void remove(); 20 | 21 | void set(E e); 22 | 23 | void add(E e); 24 | } 25 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/NoSuchElementException.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public class NoSuchElementException extends RuntimeException { 6 | 7 | public NoSuchElementException() { 8 | super(); 9 | } 10 | 11 | public NoSuchElementException(String s) { 12 | super(s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /jdk-lite/src/java/util/RandomAccess.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package java.util; 4 | 5 | public interface RandomAccess { 6 | } 7 | -------------------------------------------------------------------------------- /jdk/.gitignore: -------------------------------------------------------------------------------- 1 | src/ 2 | src.orig/ 3 | out/ 4 | -------------------------------------------------------------------------------- /jdk/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args) { 3 | System.out.println("begin"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /jdk/Makefile.obj: -------------------------------------------------------------------------------- 1 | OUT := out 2 | LL := $(shell find $(OUT) -name "*.ll") 3 | OBJ := $(LL:%.ll=%.o) 4 | 5 | all: $(OBJ) 6 | .PHONY: all 7 | 8 | $(OBJ): %.o: %.ll $(OUT)/llstamp 9 | @echo "Compiling $<" 10 | @$(CLANG) -Wno-override-module -fPIC -c -o $@ $< 11 | -------------------------------------------------------------------------------- /jdk/make-patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ $# -eq 0 ]; then 3 | echo "Example usage: $0 java/lang/Object.java" 4 | exit 1 5 | fi 6 | 7 | SRC=src 8 | 9 | set -e 10 | mkdir -p `dirname patches/"$1"` 11 | if [ ! -f "${SRC}.orig/$1" ]; then 12 | touch "${SRC}.orig/$1" 13 | fi 14 | diff -u "${SRC}.orig/$1" "$SRC/$1" > "patches/${1%.java}.patch" 15 | -------------------------------------------------------------------------------- /jdk/modification_notice.txt: -------------------------------------------------------------------------------- 1 | // This file's original contents have been modified 2 | // by a JLang patch on XXDATEXX (the date this source code was compiled) 3 | -------------------------------------------------------------------------------- /jdk/patches/java/io/FileDescriptor.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/io/FileDescriptor.java 2018-08-02 12:23:56.000000000 -0400 2 | +++ src/java/io/FileDescriptor.java 2018-08-02 13:32:41.000000000 -0400 3 | @@ -165,6 +165,7 @@ 4 | private static FileDescriptor standardStream(int fd) { 5 | FileDescriptor desc = new FileDescriptor(); 6 | desc.handle = set(fd); 7 | + desc.fd = fd; 8 | return desc; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /jdk/patches/java/io/FileInputStream.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/io/FileInputStream.java 2013-01-04 14:04:02.000000000 -0500 2 | +++ src/java/io/FileInputStream.java 2018-05-13 17:45:35.000000000 -0400 3 | @@ -56,13 +56,8 @@ 4 | private final Object closeLock = new Object(); 5 | private volatile boolean closed = false; 6 | 7 | - private static final ThreadLocal runningFinalize = 8 | - new ThreadLocal<>(); 9 | - 10 | + // Modified for JLang. 11 | private static boolean isRunningFinalize() { 12 | - Boolean val; 13 | - if ((val = runningFinalize.get()) != null) 14 | - return val.booleanValue(); 15 | return false; 16 | } 17 | 18 | @@ -397,12 +392,8 @@ 19 | * stream is still using it. If the user directly invokes 20 | * close() then the FileDescriptor is also released. 21 | */ 22 | - runningFinalize.set(Boolean.TRUE); 23 | - try { 24 | - close(); 25 | - } finally { 26 | - runningFinalize.set(Boolean.FALSE); 27 | - } 28 | + // Modified for JLang. 29 | + close(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /jdk/patches/java/nio/charset/ArrayDecoder.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/nio/charset/ArrayDecoder.java 2018-07-23 13:58:08.000000000 -0400 2 | +++ src/java/nio/charset/ArrayDecoder.java 2018-07-23 13:52:29.000000000 -0400 3 | @@ -0,0 +1,35 @@ 4 | +/* 5 | + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 7 | + * 8 | + * 9 | + * 10 | + * 11 | + * 12 | + * 13 | + * 14 | + * 15 | + * 16 | + * 17 | + * 18 | + * 19 | + * 20 | + * 21 | + * 22 | + * 23 | + * 24 | + * 25 | + * 26 | + * 27 | + */ 28 | + 29 | +package java.nio.charset; 30 | + 31 | +/* 32 | + * FastPath byte[]->char[] decoder, REPLACE on malformed or 33 | + * unmappable input. 34 | + */ 35 | + 36 | +public interface ArrayDecoder { 37 | + int decode(byte[] src, int off, int len, char[] dst); 38 | +} 39 | -------------------------------------------------------------------------------- /jdk/patches/java/nio/charset/ArrayEncoder.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/nio/charset/ArrayEncoder.java 2018-07-23 13:58:13.000000000 -0400 2 | +++ src/java/nio/charset/ArrayEncoder.java 2018-07-23 13:52:29.000000000 -0400 3 | @@ -0,0 +1,35 @@ 4 | +/* 5 | + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 7 | + * 8 | + * 9 | + * 10 | + * 11 | + * 12 | + * 13 | + * 14 | + * 15 | + * 16 | + * 17 | + * 18 | + * 19 | + * 20 | + * 21 | + * 22 | + * 23 | + * 24 | + * 25 | + * 26 | + * 27 | + */ 28 | + 29 | +package java.nio.charset; 30 | + 31 | +/* 32 | + * FastPath char[]->byte[] encoder, REPLACE on malformed input or 33 | + * unmappable input. 34 | + */ 35 | + 36 | +public interface ArrayEncoder { 37 | + int encode(char[] src, int off, int len, byte[] dst); 38 | +} 39 | -------------------------------------------------------------------------------- /jdk/patches/java/nio/charset/HistoricallyNamedCharset.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/nio/charset/HistoricallyNamedCharset.java 2018-07-23 14:07:26.000000000 -0400 2 | +++ src/java/nio/charset/HistoricallyNamedCharset.java 2018-07-23 14:07:09.000000000 -0400 3 | @@ -0,0 +1,33 @@ 4 | +/* 5 | + * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. 6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 7 | + * 8 | + * 9 | + * 10 | + * 11 | + * 12 | + * 13 | + * 14 | + * 15 | + * 16 | + * 17 | + * 18 | + * 19 | + * 20 | + * 21 | + * 22 | + * 23 | + * 24 | + * 25 | + * 26 | + * 27 | + */ 28 | + 29 | +package java.nio.charset; 30 | + 31 | + 32 | +public interface HistoricallyNamedCharset { 33 | + 34 | + public String historicalName(); 35 | + 36 | +} 37 | -------------------------------------------------------------------------------- /jdk/patches/java/nio/charset/StandardCharset.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/jdk/patches/java/nio/charset/StandardCharset.patch -------------------------------------------------------------------------------- /jdk/patches/java/util/HashMap.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/util/HashMap.java 2018-07-30 17:10:30.000000000 -0400 2 | +++ src/java/util/HashMap.java 2018-07-30 17:29:24.000000000 -0400 3 | @@ -322,6 +322,7 @@ 4 | 5 | // internal utilities 6 | 7 | + void alphaMethod() { }; 8 | /** 9 | * Initialization hook for subclasses. This method is called 10 | * in all constructors and pseudo-constructors (clone, readObject) 11 | -------------------------------------------------------------------------------- /jdk/patches/java/util/concurrent/atomic/AtomicInteger.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/java/util/concurrent/atomic/AtomicInteger.java 2013-01-04 14:04:10.000000000 -0500 2 | +++ src/java/util/concurrent/atomic/AtomicInteger.java 2018-05-16 12:29:53.000000000 -0400 3 | @@ -57,10 +57,8 @@ 4 | private static final long valueOffset; 5 | 6 | static { 7 | - try { 8 | - valueOffset = unsafe.objectFieldOffset 9 | - (AtomicInteger.class.getDeclaredField("value")); 10 | - } catch (Exception ex) { throw new Error(ex); } 11 | + // Modified for JLang until we have reflection. 12 | + valueOffset = 16; 13 | } 14 | 15 | private volatile int value; 16 | -------------------------------------------------------------------------------- /jdk/patches/sun/misc/Hashing.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/sun/misc/Hashing.java 2013-01-04 14:04:42.000000000 -0500 2 | +++ src/sun/misc/Hashing.java 2018-05-12 21:02:09.000000000 -0400 3 | @@ -257,12 +257,13 @@ 4 | // not practically reversible. 5 | int hashing_seed[] = { 6 | System.identityHashCode(Hashing.class), 7 | - System.identityHashCode(instance), 8 | - System.identityHashCode(Thread.currentThread()), 9 | - (int) Thread.currentThread().getId(), 10 | - (int) (System.currentTimeMillis() >>> 2), // resolution is poor 11 | - (int) (System.nanoTime() >>> 5), // resolution is poor 12 | - (int) (Runtime.getRuntime().freeMemory() >>> 4) // alloc min 13 | + System.identityHashCode(instance) 14 | + // Modified for JLang. 15 | + // System.identityHashCode(Thread.currentThread()), 16 | + // (int) Thread.currentThread().getId(), 17 | + // (int) (System.currentTimeMillis() >>> 2), // resolution is poor 18 | + // (int) (System.nanoTime() >>> 5), // resolution is poor 19 | + // (int) (Runtime.getRuntime().freeMemory() >>> 4) // alloc min 20 | }; 21 | 22 | seed = murmur3_32(hashing_seed); 23 | -------------------------------------------------------------------------------- /jdk/patches/sun/misc/OSEnvironment.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/sun/misc/OSEnvironment.java 2018-08-11 16:32:44.000000000 +0200 2 | +++ src/sun/misc/OSEnvironment.java 2018-08-11 18:13:56.000000000 +0200 3 | @@ -36,7 +36,7 @@ 4 | * At this time only the process-wide error mode needs to be set. 5 | */ 6 | public static void initialize() { 7 | - Win32ErrorMode.initialize(); 8 | + //no-op on Linux + Solaris 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /jdk/patches/sun/nio/cs/FastCharsetProvider.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/sun/nio/cs/FastCharsetProvider.java 2018-07-23 14:50:58.000000000 -0400 2 | +++ src/sun/nio/cs/FastCharsetProvider.java 2018-07-23 15:03:04.000000000 -0400 3 | @@ -112,6 +112,14 @@ 4 | cs = new US_ASCII(); 5 | cache.put(csn, cs); 6 | return cs; 7 | + } else if (cln.equals("UTF_8")) { 8 | + cs = new UTF_8(); 9 | + cache.put(csn, cs); 10 | + return cs; 11 | + } else if (cln.equals("ISO_8859_1")) { 12 | + cs = new ISO_8859_1(); 13 | + cache.put(csn, cs); 14 | + return cs; 15 | } 16 | 17 | // Instantiate the charset and cache it 18 | -------------------------------------------------------------------------------- /jdk/patches/sun/reflect/UnsafeFieldAccessorImpl.patch: -------------------------------------------------------------------------------- 1 | --- src.orig/sun/reflect/UnsafeFieldAccessorImpl.java 2019-05-18 20:59:00.000000000 +0800 2 | +++ src/sun/reflect/UnsafeFieldAccessorImpl.java 2019-05-18 21:02:07.000000000 +0800 3 | @@ -40,12 +40,17 @@ 4 | static final Unsafe unsafe = Unsafe.getUnsafe(); 5 | 6 | protected final Field field; 7 | - protected final int fieldOffset; 8 | + protected final long fieldOffset; 9 | protected final boolean isFinal; 10 | 11 | UnsafeFieldAccessorImpl(Field field) { 12 | this.field = field; 13 | - fieldOffset = unsafe.fieldOffset(field); 14 | + if (Modifier.isStatic(field.getModifiers())) { 15 | + this.fieldOffset = unsafe.staticFieldOffset(field); 16 | + } else { 17 | + this.fieldOffset = unsafe.objectFieldOffset(field); 18 | + } 19 | + 20 | isFinal = Modifier.isFinal(field.getModifiers()); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /jdk/src.zip: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2df53789a094eeab37e5c85a64a2fba372418e4206297f795fd852ed68762d8f 3 | size 36689314 4 | -------------------------------------------------------------------------------- /jdk/stubs.cpp: -------------------------------------------------------------------------------- 1 | // This file defines symbols that are otherwise 2 | // missing for various (usually unknown) reasons. 3 | #include 4 | #include 5 | #include "jni.h" 6 | 7 | extern "C" { 8 | 9 | // We always return null, representing the boot class loader. 10 | jobject 11 | Java_java_lang_Class_getClassLoader0(JNIEnv*, jobject) { 12 | return nullptr; 13 | } 14 | 15 | // Pretty sure this only matters on Windows. 16 | jlong 17 | Java_java_io_FileDescriptor_set(JNIEnv *env, jclass fdClass, jint fd) { 18 | return -1; 19 | } 20 | 21 | void Polyglot_java_lang_Enum_compareTo__Ljava_lang_Object_2() { 22 | // For some reason Polyglot adds this method to java.lang.Enum with 23 | // the wrong argument type, in addition to the correct version. 24 | // This should be fixed, because this likely breaks 25 | // method dispatch for enums. For now we abort if called. 26 | fprintf(stderr, "This method should not be called\n"); 27 | abort(); 28 | } 29 | 30 | } // extern "C" 31 | -------------------------------------------------------------------------------- /lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /lib/javacpp.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/javacpp.jar -------------------------------------------------------------------------------- /lib/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/junit-4.12.jar -------------------------------------------------------------------------------- /lib/llvm-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-javadoc.jar -------------------------------------------------------------------------------- /lib/llvm-linux-x86_64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-linux-x86_64.jar -------------------------------------------------------------------------------- /lib/llvm-macosx-x86_64.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-macosx-x86_64.jar -------------------------------------------------------------------------------- /lib/llvm-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-sources.jar -------------------------------------------------------------------------------- /lib/llvm.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm.jar -------------------------------------------------------------------------------- /lib/ppg.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/ppg.jar -------------------------------------------------------------------------------- /runtime/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # We'll use defaults from the LLVM style, but with 4 columns indentation. 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | --- 6 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | runtime.ll 3 | runtime.o 4 | -------------------------------------------------------------------------------- /runtime/linux_version.map: -------------------------------------------------------------------------------- 1 | SUNWprivate_1.1 { 2 | global: 3 | main; 4 | jni*; 5 | JVM*; 6 | Polyglot*; 7 | jio*; 8 | Java_sun_misc_Unsafe*; 9 | RegisterJavaClass; #TODO rename all of the functions called from JLang-compiled code to have same prefix 10 | createArray; 11 | create1DArray; 12 | InternStringLit; 13 | GetJavaNativeFunc; #Then we can just export PREFIX* 14 | createUnwindException; 15 | extractJavaExceptionObject; 16 | InstanceOf; 17 | throwUnwindException; 18 | __getInterfaceMethod; 19 | __createInterfaceTables; 20 | __java_personality_v0; 21 | __GC_malloc; 22 | getGlobalMutexObject; 23 | local: 24 | *; 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /runtime/native/array.cpp: -------------------------------------------------------------------------------- 1 | #include "array.h" 2 | 3 | extern "C" { 4 | extern void Polyglot_jlang_runtime_Array_load_class(); 5 | extern DispatchVector Polyglot_jlang_runtime_Array_cdv; 6 | extern jclass Polyglot_jlang_runtime_Array_class; 7 | } 8 | 9 | static jclass __runtimeArrayClass = nullptr; 10 | static DispatchVector *__runtimeArrayCdv = nullptr; 11 | 12 | static void initRuntimeArray() { 13 | if (__runtimeArrayClass == nullptr && __runtimeArrayCdv == nullptr) { 14 | Polyglot_jlang_runtime_Array_load_class(); 15 | __runtimeArrayClass = Polyglot_jlang_runtime_Array_class; 16 | __runtimeArrayCdv = &Polyglot_jlang_runtime_Array_cdv; 17 | } 18 | } 19 | 20 | jclass getRuntimeArrayClass() { 21 | initRuntimeArray(); 22 | return __runtimeArrayClass; 23 | } 24 | 25 | DispatchVector *getRuntimeArrayCdv() { 26 | initRuntimeArray(); 27 | return __runtimeArrayCdv; 28 | } -------------------------------------------------------------------------------- /runtime/native/array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "rep.h" 4 | 5 | jclass getRuntimeArrayClass(); 6 | DispatchVector *getRuntimeArrayCdv(); -------------------------------------------------------------------------------- /runtime/native/base_class.cpp: -------------------------------------------------------------------------------- 1 | #include "base_class.h" 2 | 3 | extern "C" { 4 | extern void Polyglot_jlang_runtime_BaseClass_load_class(); 5 | extern jclass Polyglot_jlang_runtime_BaseClass_class; 6 | } 7 | 8 | jclass __baseClass = nullptr; 9 | 10 | jclass getBaseClass() { 11 | if (__baseClass == NULL) { 12 | // Force this class load function to be called at initialization 13 | Polyglot_jlang_runtime_BaseClass_load_class(); 14 | __baseClass = Polyglot_jlang_runtime_BaseClass_class; 15 | } 16 | return __baseClass; 17 | } -------------------------------------------------------------------------------- /runtime/native/base_class.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "jni.h" 4 | 5 | /** 6 | * Returns the global base class for primitive types 7 | */ 8 | jclass getBaseClass(); -------------------------------------------------------------------------------- /runtime/native/constants.cpp: -------------------------------------------------------------------------------- 1 | #include "constants.h" 2 | 3 | extern "C" { 4 | extern void Polyglot_jlang_runtime_Constants_load_class(); 5 | extern int Polyglot_jlang_runtime_Constants_classSize; 6 | extern int Polyglot_jlang_runtime_Constants_numOfRuntimeCdvArrayMethods; 7 | } 8 | 9 | static int __classSize = 0; 10 | static int __numOfRuntimeCdvArrayMethods = 0; 11 | 12 | static void initConstants() { 13 | if (__classSize == 0 && __numOfRuntimeCdvArrayMethods == 0) { 14 | Polyglot_jlang_runtime_Constants_load_class(); 15 | __classSize = Polyglot_jlang_runtime_Constants_classSize; 16 | __numOfRuntimeCdvArrayMethods = 17 | Polyglot_jlang_runtime_Constants_numOfRuntimeCdvArrayMethods; 18 | } 19 | } 20 | 21 | int getClassSize() { 22 | initConstants(); 23 | return __classSize; 24 | } 25 | 26 | int getNumOfRuntimeArrayCdvMethods() { 27 | initConstants(); 28 | return __numOfRuntimeCdvArrayMethods; 29 | } -------------------------------------------------------------------------------- /runtime/native/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int getClassSize(); 4 | 5 | int getNumOfRuntimeArrayCdvMethods(); -------------------------------------------------------------------------------- /runtime/native/debug.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Helper functions to be used in gdb/lldb. 4 | 5 | std::string make_string(const char *x) { return x; } -------------------------------------------------------------------------------- /runtime/native/exception.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #pragma once 4 | 5 | #include "jni.h" 6 | #include "rep.h" 7 | #include 8 | 9 | void throwClassNotFoundException(JNIEnv *env, const char *name); 10 | void throwNewThrowable(JNIEnv *env, jclass clazz, const char *msg); 11 | void throwThrowable(JNIEnv *env, jthrowable obj); 12 | void throwInterruptedException(JNIEnv *env); 13 | 14 | extern "C" { 15 | 16 | _Unwind_Exception *createUnwindException(jobject jexception); 17 | void throwUnwindException(_Unwind_Exception *exception); 18 | 19 | } // extern "C" 20 | -------------------------------------------------------------------------------- /runtime/native/factory.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | // Provides methods to construct common Java objects 4 | // needed by native code. These factory methods directly 5 | // dispatch to symbols compiled from Java code in 6 | // jlang.runtime.Factory. 7 | #pragma once 8 | 9 | #include "jni.h" 10 | 11 | // Arrays. 12 | jbooleanArray CreateJavaBooleanArray(jint len); 13 | jbyteArray CreateJavaByteArray(jint len); 14 | jcharArray CreateJavaCharArray(jint len); 15 | jshortArray CreateJavaShortArray(jint len); 16 | jintArray CreateJavaIntArray(jint len); 17 | jlongArray CreateJavaLongArray(jint len); 18 | jfloatArray CreateJavaFloatArray(jint len); 19 | jdoubleArray CreateJavaDoubleArray(jint len); 20 | jobjectArray CreateJavaObjectArray(jint len); 21 | 22 | // Strings. 23 | jstring CreateJavaString(jcharArray chars); 24 | // Objects. 25 | jobject CreateJavaObject(jclass clazz); 26 | jobject CloneJavaObject(jobject obj); 27 | -------------------------------------------------------------------------------- /runtime/native/helper.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | // Provides definitions to java runtime functions compiled by JLang 4 | 5 | #pragma once 6 | 7 | #include "jni.h" 8 | 9 | #define POLYGLOT_ARRAY_STORE \ 10 | Polyglot_jlang_runtime_Helper_arrayStore___3Ljava_lang_Object_2ILjava_lang_Object_2 11 | 12 | extern "C" { 13 | extern jstring 14 | Polyglot_jlang_runtime_Helper_toString__Ljava_lang_Object_2(jobject); 15 | void POLYGLOT_ARRAY_STORE(jobjectArray, jint, jobject); 16 | extern jobject 17 | Polyglot_jlang_runtime_Helper_arrayLoad___3Ljava_lang_Object_2I(jobject, 18 | jint); 19 | extern void 20 | Polyglot_jlang_runtime_Helper_printString__Ljava_lang_String_2(jstring); 21 | } -------------------------------------------------------------------------------- /runtime/native/init.cpp: -------------------------------------------------------------------------------- 1 | #include "init.h" 2 | 3 | #include "class.h" 4 | #include "jvm.h" 5 | #include "factory.h" 6 | #include "threads.h" 7 | 8 | extern "C" { 9 | void Polyglot_java_lang_System_initializeSystemClass__(); 10 | } // extern "C" 11 | 12 | void InitializeMainThread() { 13 | // initialize classes 14 | FindClass("java.lang.String"); 15 | FindClass("java.lang.System"); 16 | FindClass("java.lang.Thread"); 17 | FindClass("java.lang.ThreadGroup"); 18 | FindClass("java.lang.reflect.Method"); 19 | FindClass("java.lang.ref.Finalizer"); 20 | FindClass("java.lang.Class"); 21 | 22 | // setup currentThread for main thread 23 | currentThread = GetMainThread(); 24 | Threads::Instance().threads[currentThread].threadStatus = true; 25 | 26 | // initialize the system class 27 | Polyglot_java_lang_System_initializeSystemClass__(); 28 | } -------------------------------------------------------------------------------- /runtime/native/init.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | void InitializeMainThread(); -------------------------------------------------------------------------------- /runtime/native/interface.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | extern "C" { 8 | 9 | void *__getInterfaceMethod(jobject obj, int intf_id_hash, void *intf_id, 10 | int method_index); 11 | 12 | struct idv_ht_node { 13 | idv_ht_node *next; 14 | void *intf_id; 15 | void *idv; 16 | }; 17 | 18 | } // extern "C" 19 | 20 | // The hash table of interface dispatch vectors. 21 | // representation type is actually a linked list 22 | class idv_ht { 23 | public: 24 | /** 25 | * Constructor. 26 | * @param capacity must be a power of 2 27 | */ 28 | idv_ht(size_t capacity); 29 | 30 | /** 31 | * Fetch an interface dispatch vector with its precomputed hash 32 | * code. 33 | */ 34 | void *get(int hashcode, void *intf_id); 35 | 36 | /** 37 | * Add an interface dispatch vector with its precomputed hash 38 | * code. 39 | */ 40 | void put(int hashcode, void *intf_id, void *idv); 41 | 42 | private: 43 | idv_ht_node **table; 44 | size_t capacity; 45 | size_t getIndexForHash(int h); 46 | }; 47 | -------------------------------------------------------------------------------- /runtime/native/monitor.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019 Cornell University 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define GC_THREADS 11 | #include 12 | #undef GC_THREADS 13 | 14 | class Monitor { 15 | public: 16 | Monitor(const Monitor &monitor) = delete; 17 | Monitor &operator=(const Monitor &monitor) = delete; 18 | 19 | static Monitor &Instance(); 20 | void enter(jobject obj); 21 | void exit(jobject obj); 22 | 23 | void wait(jobject obj, jlong ms); 24 | void notify(jobject obj); 25 | void notifyAll(jobject obj); 26 | 27 | pthread_mutex_t *globalMutex(); 28 | 29 | private: 30 | static thread_local std::deque syncObjs; 31 | pthread_mutex_t mutex; 32 | 33 | Monitor(); 34 | bool hasEntered(jobject obj); 35 | }; 36 | 37 | class ScopedLock { 38 | private: 39 | pthread_mutex_t *mutex; 40 | 41 | public: 42 | ScopedLock(pthread_mutex_t *_mutex); 43 | ~ScopedLock(); 44 | }; -------------------------------------------------------------------------------- /runtime/native/nativetest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #include "nativetest.h" 4 | 5 | extern "C" { 6 | JNIEXPORT jstring JNICALL Java_NativeTest_getNativeStringTest(JNIEnv *env, 7 | jclass ignored) { 8 | jstring jkey = env->NewStringUTF("testNativeCall"); 9 | return jkey; 10 | } 11 | 12 | JNIEXPORT jstring JNICALL 13 | Java_NativeTest_00024NativeTestInner_getNativeInnerStringTest(JNIEnv *env, 14 | jobject ignored) { 15 | jstring jkey = env->NewStringUTF("testInnerNativeCall"); 16 | return jkey; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /runtime/native/nativetest.h: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | /* DO NOT EDIT THIS FILE - it is machine generated */ 4 | #include 5 | /* Header for class NativeTest */ 6 | 7 | #ifndef _Included_NativeTest 8 | #define _Included_NativeTest 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | /* 13 | * Class: NativeTest 14 | * Method: getNativeStringTest 15 | * Signature: ()Ljava/lang/String; 16 | */ 17 | JNIEXPORT jstring JNICALL Java_NativeTest_getNativeStringTest 18 | (JNIEnv *, jclass); 19 | 20 | /* 21 | * Class: NativeTest_NativeTestInner 22 | * Method: getNativeInnerStringTest 23 | * Signature: ()Ljava/lang/String; 24 | */ 25 | JNIEXPORT jstring JNICALL Java_NativeTest_00024NativeTestInner_getNativeInnerStringTest 26 | (JNIEnv *, jobject); 27 | 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif 33 | -------------------------------------------------------------------------------- /runtime/native/reflect.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #include "reflect.h" 4 | 5 | extern "C" { 6 | 7 | void CTOR_CTOR(jclass, jobjectArray, jobjectArray, jint, jint, jstring, 8 | jbyteArray, jbyteArray); 9 | 10 | bool InstanceOf(jobject obj, void *type_id) { 11 | if (obj == nullptr) 12 | return false; 13 | type_info *type_info = Unwrap(obj)->Cdv()->SuperTypes(); 14 | for (int32_t i = 0, end = type_info->size; i < end; ++i) 15 | if (type_info->super_type_ids[i] == type_id) 16 | return true; 17 | return false; 18 | } 19 | } // extern "C" 20 | 21 | jobject CreateConstructor(jclass declaring_clazz, 22 | const JavaClassInfo *clazz_info, 23 | JavaMethodInfo ctor_info) { 24 | // TODO actually implement 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /runtime/native/reflect.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #pragma once 4 | 5 | #include "class.h" 6 | #include "factory.h" 7 | #include "rep.h" 8 | #include 9 | extern "C" { 10 | bool InstanceOf(jobject obj, void *compare_type_id); 11 | } // extern "C" 12 | 13 | jobject CreateConstructor(jclass declaring_clazz, 14 | const JavaClassInfo *clazz_info, 15 | JavaMethodInfo ctor_info); 16 | -------------------------------------------------------------------------------- /runtime/native/stack_trace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #include "stack_trace.h" 4 | #include 5 | #include 6 | 7 | void DumpStackTrace() { 8 | // Dump stack trace. 9 | constexpr int max_frames = 256; 10 | void *callstack[max_frames]; 11 | int frames = backtrace(callstack, max_frames); 12 | backtrace_symbols_fd(callstack, frames, fileno(stderr)); 13 | } 14 | -------------------------------------------------------------------------------- /runtime/native/stack_trace.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018 Cornell University 2 | 3 | #pragma once 4 | 5 | void DumpStackTrace(); 6 | -------------------------------------------------------------------------------- /runtime/native/threads.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019 Cornell University 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define GC_THREADS 9 | #include 10 | #undef GC_THREADS 11 | 12 | extern thread_local jobject currentThread; 13 | 14 | struct NativeThread { 15 | pthread_t tid; 16 | bool threadStatus; 17 | bool interrupted; 18 | }; 19 | 20 | class Threads { 21 | public: 22 | Threads(const Threads &threads) = delete; 23 | Threads &operator=(const Threads &threads) = delete; 24 | static Threads &Instance(); 25 | 26 | void startThread(jobject jthread); 27 | void join(); 28 | std::unordered_map threads; 29 | 30 | private: 31 | Threads() = default; 32 | }; 33 | 34 | jobject GetMainThread(); 35 | -------------------------------------------------------------------------------- /runtime/runtime.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/BaseClass.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.runtime; 4 | 5 | // This is an empty class whose Class Object. 6 | // We'll use as the basis for all primitive.class objects. 7 | // e.g. int.class 8 | class BaseClass { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/Constants.java: -------------------------------------------------------------------------------- 1 | package jlang.runtime; 2 | 3 | public class Constants { 4 | // TODO: auto-generate 5 | public static final int classSize = 168; // = v.obj.sizeOfObj(v.ts.Class()) 6 | public static final int numOfRuntimeCdvArrayMethods = 11; // = v.cdvMethods(v.ts.ArrayObject()).size() 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/Exceptions.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.runtime; 4 | import java.lang.reflect.Constructor; 5 | 6 | class Exceptions { 7 | 8 | static void createClassNotFoundException(String name) throws ClassNotFoundException { throw new ClassNotFoundException(name) ; } 9 | static void throwNewThrowable(Class clazz, String msg) throws Throwable { 10 | Constructor ctor = clazz.getConstructor(String.class); 11 | throw ctor.newInstance(msg); 12 | } 13 | static void throwThrowable(Throwable t) throws Throwable { 14 | throw t; 15 | } 16 | static void throwInterruptedException() throws InterruptedException { throw new InterruptedException(); } 17 | } 18 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/Factory.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.runtime; 4 | 5 | // Helps native code construct common Java objects. 6 | class Factory { 7 | 8 | static boolean[] BooleanArray (int len) { return new boolean[len]; } 9 | static byte [] ByteArray (int len) { return new byte [len]; } 10 | static char [] CharArray (int len) { return new char [len]; } 11 | static short [] ShortArray (int len) { return new short [len]; } 12 | static int [] IntArray (int len) { return new int [len]; } 13 | static long [] LongArray (int len) { return new long [len]; } 14 | static float [] FloatArray (int len) { return new float [len]; } 15 | static double [] DoubleArray (int len) { return new double [len]; } 16 | 17 | static String String(char[] chars) { return new String(chars); } 18 | 19 | static Object[] ObjectArray(int len) { 20 | return new Object[len]; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/Helper.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.runtime; 4 | 5 | // Helper functions that implement Java semantics so that the compiler 6 | // doesn't have to. That is, a JLang translation can sometimes call one of 7 | // these helper methods rather than translating everything directly. 8 | class Helper { 9 | 10 | // If o or o.toString() are null, we must substitute "null". 11 | static String toString(Object o) { 12 | if (o == null) return "null"; 13 | String res = o.toString(); 14 | return res == null ? "null" : res; 15 | } 16 | 17 | static void arrayStore(Object[] arr, int i, Object o) { 18 | arr[i] = o; 19 | } 20 | 21 | static Object arrayLoad(Object[] arr, int i) { 22 | return arr[i]; 23 | } 24 | 25 | static Integer autoBoxInt(int i) { 26 | return new Integer(i); 27 | } 28 | 29 | static void printString(String s) { 30 | System.out.println(s); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /runtime/src/jlang/runtime/MainWrapper.java: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2018 Cornell University 2 | 3 | package jlang.runtime; 4 | 5 | // Wraps the Java entry point in a try-catch block so that we can 6 | // report uncaught exceptions to the client. 7 | class MainWrapper { 8 | 9 | // This native method is generated by JLang when it encounters 10 | // the main method in the client program. 11 | static native void main(String[] args); 12 | 13 | static void runMain(String[] args) { 14 | // TODO: Print stack trace. 15 | main(args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/AnonymousSubClass.java: -------------------------------------------------------------------------------- 1 | import java.test.AbstractTest; 2 | import java.test.Test; 3 | import java.test.SubTest; 4 | 5 | public class AnonymousSubClass { 6 | 7 | public static void main(String[] args) { 8 | AbstractTest at = new Test(); 9 | at.printMessage(); 10 | at = new SubTest(); 11 | at.printMessage(); 12 | SubTest st = new SubTest() { 13 | public void doNothing(){ System.out.print(""); }; 14 | }; 15 | st.printMessage(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/isolated/.gitignore: -------------------------------------------------------------------------------- 1 | *.sol 2 | *.ll 3 | *.output 4 | *.binary 5 | /Tmp.java 6 | *.dSYM 7 | -------------------------------------------------------------------------------- /tests/isolated/Add.java: -------------------------------------------------------------------------------- 1 | public class Add { 2 | static { 3 | System.out.println("Static initializer"); 4 | } 5 | 6 | 7 | public static void main(String[] args) { 8 | Add add = new Add(); // Runs static initializer. 9 | // String s = args[1]; 10 | f(1); 11 | } 12 | 13 | public static int f(int i) { 14 | System.out.println("Hello!"); 15 | char c = 1; 16 | short s = 2; 17 | if (i < 2 && i > -10) { 18 | if (i < 3) { 19 | return 3; 20 | } else { 21 | return 4; 22 | } 23 | } 24 | i += i; 25 | i = (int) (1 + 2l); 26 | long j = i; 27 | return c + s; 28 | } 29 | 30 | public static native int g(); 31 | } 32 | -------------------------------------------------------------------------------- /tests/isolated/Annotations.java: -------------------------------------------------------------------------------- 1 | class Annotations { 2 | 3 | enum T {T1, T2} 4 | 5 | @Target(T.T1) 6 | public @interface Target { 7 | T[] value(); 8 | } 9 | 10 | @Target({T.T1, T.T2}) 11 | public @interface A {} 12 | 13 | @A 14 | void f() {} 15 | 16 | public static void main(String[] arg) { 17 | System.out.println("begin"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/AnonymousClass.java: -------------------------------------------------------------------------------- 1 | public class AnonymousClass { 2 | private final String field = "outer field"; 3 | 4 | private interface I { 5 | void f(); 6 | } 7 | 8 | void member() { 9 | final int local = 42; 10 | I i = new I() { 11 | private final String field = "inner field"; 12 | 13 | @Override 14 | public void f() { 15 | System.out.println(AnonymousClass.this.field); 16 | System.out.println(field); 17 | System.out.println(local); 18 | } 19 | }; 20 | i.f(); 21 | } 22 | 23 | public static void main(String[] args) { 24 | final String local = "local"; 25 | 26 | I i = new I() { 27 | int field = 3; 28 | 29 | @Override 30 | public void f() { 31 | System.out.println(local); 32 | System.out.println(field); 33 | 34 | I j = new I() { 35 | int field = 4; 36 | 37 | @Override 38 | public void f() { 39 | System.out.println(local); 40 | System.out.println(field); 41 | } 42 | }; 43 | j.f(); 44 | } 45 | }; 46 | i.f(); 47 | 48 | i = new I() { public void f() { System.out.println(5); } }; 49 | i.f(); 50 | 51 | new AnonymousClass().member(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/isolated/ArrayOutOfBounds.java: -------------------------------------------------------------------------------- 1 | public class ArrayOutOfBounds { 2 | public static void main(String[] args) { 3 | int[] xs = {0,1,2,3,4}; 4 | try { 5 | for (int i = 0; i <= xs.length + 10; i++) { 6 | System.out.println(xs[i]); 7 | } 8 | } catch (ArrayIndexOutOfBoundsException e) { 9 | System.out.println("catch"); 10 | } 11 | 12 | try { 13 | for (int i = 0; i <= xs.length + 10; i++) { 14 | System.out.println(xs[i] = i+10); 15 | } 16 | } catch (ArrayIndexOutOfBoundsException e){ 17 | System.out.println("catch") ; 18 | } 19 | 20 | int x = 0; 21 | try { 22 | System.out.println(xs[--x]); 23 | } catch (ArrayIndexOutOfBoundsException e) { 24 | System.out.println("catch " + x); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/isolated/Assert.java: -------------------------------------------------------------------------------- 1 | class Assert { 2 | 3 | public static void main(String[] args) { 4 | try { 5 | assert true; 6 | System.out.println("After1"); 7 | } catch (AssertionError e) { 8 | System.out.println("Bad"); 9 | } 10 | try { 11 | assert false; 12 | System.out.println("After2"); 13 | } catch (AssertionError e) { 14 | System.out.println("Good"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/isolated/BinaryCondOps.java: -------------------------------------------------------------------------------- 1 | public class BinaryCondOps { 2 | public static void main(String[] args) { 3 | boolean x = false && printMsgTrue(); 4 | assertBool(!x); 5 | x = false && printMsgFalse(); 6 | assertBool(!x); 7 | 8 | x = true && printMsgTrue(); 9 | assertBool(x); 10 | x = true && printMsgFalse(); 11 | assertBool(!x); 12 | 13 | x = false || printMsgTrue(); 14 | assertBool(x); 15 | x = false || printMsgFalse(); 16 | assertBool(!x); 17 | 18 | x = true || printMsgTrue(); 19 | assertBool(x); 20 | x = true || printMsgFalse(); 21 | assertBool(x); 22 | } 23 | 24 | static void assertBool(boolean x){ 25 | if (x){ 26 | System.out.println("GOOD"); 27 | } else { 28 | System.out.println("FAIL"); 29 | } 30 | } 31 | 32 | 33 | static boolean printMsgTrue(){ 34 | System.out.println("MSG"); 35 | return true; 36 | } 37 | 38 | static boolean printMsgFalse(){ 39 | System.out.println("MSG"); 40 | return false; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/isolated/Blocks.java: -------------------------------------------------------------------------------- 1 | public class Blocks { 2 | public static void main(String[] args) { 3 | { 4 | System.out.print(1); 5 | } 6 | { 7 | System.out.print(2); 8 | } 9 | { 10 | { 11 | System.out.print(3); 12 | } 13 | { 14 | System.out.print(4); 15 | 16 | } 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/isolated/Cast.java: -------------------------------------------------------------------------------- 1 | class Cast { 2 | 3 | static Object f() { 4 | return "Hello, world!"; 5 | } 6 | 7 | static String g() { 8 | return (String) new Object(); 9 | } 10 | 11 | static class Inner { 12 | T field; 13 | Inner(T field) { 14 | this.field = field; 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | System.out.println("begin"); 20 | 21 | String s = (String) f(); 22 | System.out.println(s); 23 | 24 | try { g(); } 25 | catch (ClassCastException e) { 26 | System.out.println("catch g"); 27 | } 28 | 29 | Inner i = new Inner(new Integer(42)); 30 | System.out.println(i.field); 31 | System.out.println((Integer) i.field); 32 | try { 33 | System.out.println((String) (Object) i.field); 34 | } catch (ClassCastException e) { 35 | System.out.println("catch field"); 36 | } 37 | 38 | System.out.println((Integer) 42); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/isolated/CastNull.java: -------------------------------------------------------------------------------- 1 | class CastNull { 2 | 3 | static class InnerOne { 4 | 5 | } 6 | 7 | static interface InnerInterOne { 8 | public Object objectify(); 9 | } 10 | 11 | static class InnerTwo implements InnerInterOne { 12 | public Object objectify() { 13 | return this; 14 | } 15 | 16 | 17 | } 18 | 19 | static class InnerThree implements InnerInterOne { 20 | public Object objectify() { 21 | return null; 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | 27 | InnerTwo t = null; 28 | System.out.println(t == null); 29 | t = new InnerTwo(); 30 | InnerInterOne in = (InnerInterOne)t.objectify(); 31 | System.out.println(in == null); 32 | in = (InnerInterOne) new InnerThree().objectify(); 33 | System.out.println(in == null); 34 | InnerOne ino = (InnerOne) new InnerThree().objectify(); 35 | System.out.println(ino == null); 36 | try { 37 | Object o = new InnerTwo(); 38 | InnerOne o1 = (InnerOne) new InnerTwo().objectify(); 39 | } catch (ClassCastException e) { 40 | System.out.println("caught exception"); 41 | } 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /tests/isolated/ClassLiteral.java: -------------------------------------------------------------------------------- 1 | class ClassLiteral { 2 | 3 | class Inner {} 4 | 5 | interface It {} 6 | 7 | abstract class Abstract {} 8 | 9 | public static void main(String[] args) { 10 | System.out.println(int.class); 11 | System.out.println(ClassLiteral.Inner.class); 12 | System.out.println(Object.class.toString()); 13 | System.out.println(byte[].class); 14 | System.out.println(String[][].class); 15 | System.out.println(); 16 | 17 | System.out.println(new ClassLiteral().getClass()); 18 | System.out.println(new Object().getClass()); 19 | System.out.println("String".getClass()); 20 | // System.out.println(new char[0].getClass()); // TODO 21 | System.out.println(); 22 | 23 | System.out.println(Object.class == new Object().getClass()); 24 | System.out.println(String.class == "String".getClass()); 25 | System.out.println(String.class == new Object().getClass()); 26 | System.out.println(ClassLiteral.Inner.class 27 | == new ClassLiteral().new Inner().getClass()); 28 | // System.out.println(It.class); TODO 29 | System.out.println(Abstract.class); 30 | // System.out.println(short[].class == new short[] {1, 2, 3}.getClass()); TODO 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/isolated/ClassReflection.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Field; 2 | 3 | class ClassReflection { 4 | 5 | public static void main(String[] args) { 6 | ClassReflectionE ce = new ClassReflectionE(); 7 | Class clse = ce.getClass(); 8 | Field[] fe = clse.getDeclaredFields(); 9 | System.out.println(fe.length); 10 | System.out.println(clse.getSuperclass()); 11 | } 12 | 13 | int k; 14 | 15 | public ClassReflection(int i, int j) { 16 | k = i + j; 17 | } 18 | 19 | static class GenericClassReflection { 20 | T[] arr; 21 | 22 | public T get(){ 23 | return arr[0]; 24 | } 25 | } 26 | 27 | static class ClassReflectionE extends ClassReflection { 28 | public int gg; 29 | 30 | public ClassReflectionE() { 31 | super(641,42); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /tests/isolated/ClassTest.java: -------------------------------------------------------------------------------- 1 | public class ClassTest { 2 | 3 | public static void main(String[] args) throws Exception { 4 | // Class clazz = Class.forName("java.lang.Object"); 5 | System.out.println(Object.class.getName()); 6 | } 7 | } -------------------------------------------------------------------------------- /tests/isolated/Conditional.java: -------------------------------------------------------------------------------- 1 | class Conditional { 2 | 3 | static boolean t() { 4 | System.out.println("t"); 5 | return true; 6 | } 7 | 8 | static boolean f() { 9 | System.out.println("f"); 10 | return false; 11 | } 12 | 13 | static int a() { 14 | System.out.println("a"); 15 | return 1; 16 | } 17 | 18 | static int b() { 19 | System.out.println("b"); 20 | return 2; 21 | } 22 | 23 | public static void main(String[] args) { 24 | System.out.println("begin"); 25 | System.out.println(true ? 1 : 2); 26 | System.out.println(false ? 1 : 2); 27 | System.out.println(t() ? a() : b()); 28 | System.out.println(f() ? a() : b()); 29 | } 30 | } -------------------------------------------------------------------------------- /tests/isolated/Empty.java: -------------------------------------------------------------------------------- 1 | public class Empty { 2 | public static void main(String[] args) { 3 | // Do nothing. 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/isolated/ExceptionsNested.java: -------------------------------------------------------------------------------- 1 | class ExceptionsNested { 2 | public static void main(String[] args) { 3 | try { 4 | catchesRuntimeExn(); 5 | System.out.println("Should not print"); 6 | } catch (Exception e) { 7 | System.out.println("Caught exception"); 8 | } 9 | } 10 | 11 | public static void catchesRuntimeExn() throws Exception { 12 | try { 13 | throwsExn(); 14 | } catch (RuntimeException e) { 15 | System.out.println("Caught runtime exception"); 16 | } 17 | } 18 | 19 | public static void throwsExn() throws Exception { 20 | throw new Exception(); 21 | } 22 | } -------------------------------------------------------------------------------- /tests/isolated/Generic.java: -------------------------------------------------------------------------------- 1 | public class Generic{ 2 | public static void main(String[] args) { 3 | System.out.println(new Generic("Hi There!").toString()); 4 | System.out.println(new Generic("Hi There!").toString()); 5 | System.out.println(new Generic(new A()).toString()); 6 | 7 | Generic stringGeneric = new Generic("Hi!"); 8 | System.out.println(stringGeneric.toString()); 9 | stringGeneric.obj = "Changed!"; 10 | System.out.println(stringGeneric.toString()); 11 | 12 | String s = stringGeneric.obj; 13 | System.out.println(s); 14 | 15 | String s1 = stringGeneric.retrieve(); 16 | System.out.println(s1); 17 | 18 | A a = new Generic(new A()).retrieve(); 19 | System.out.println(a.toString()); 20 | 21 | } 22 | 23 | public T obj; 24 | 25 | public Generic(T obj){ 26 | this.obj = obj; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Generic["+ obj +"]"; 32 | } 33 | 34 | public T retrieve(){ 35 | return obj; 36 | } 37 | 38 | private static class A{ 39 | @Override 40 | public String toString() { 41 | return "A"; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/isolated/Generic01.java: -------------------------------------------------------------------------------- 1 | public class Generic01 { 2 | public static void main(String[] args) { 3 | D d = new D(); 4 | C1 c1 = new C1(); 5 | c1.m(d); 6 | C2 c2 = new C2(); 7 | c2.m(d); 8 | } 9 | static class C1 { 10 | int j = 0; 11 | public void m(T x) { System.out.println("C1.m"); } 12 | } 13 | static class C2 extends C1 { 14 | public void m(D x) { System.out.println("C2.m"); } 15 | } 16 | static class D { } 17 | } 18 | -------------------------------------------------------------------------------- /tests/isolated/Generic02.java: -------------------------------------------------------------------------------- 1 | public class Generic02 { 2 | public static void main(String[] args) { 3 | D1 d1 = new D1(); 4 | D2 d2 = new D2(); 5 | C1 c1 = new C1(); 6 | C2 c2 = new C2(); 7 | c1.m(d1); 8 | c1.m(d2); 9 | c2.m(d2); 10 | } 11 | static class C1 { 12 | public void m(T x) { System.out.println("C1.m"); } 13 | } 14 | static class C2 extends C1 { 15 | public void m(T x) { System.out.println("C2.m"); } 16 | } 17 | static class D1 { } 18 | static class D2 extends D1 { } 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/Generic03.java: -------------------------------------------------------------------------------- 1 | public class Generic03 { 2 | public static void main(String[] args) { 3 | C c = new C(new D2()); 4 | m(c).n(); 5 | } 6 | static T m(C c) { 7 | return c.getVal(); 8 | } 9 | static class C { 10 | private T val; 11 | public C(T t) { val = t; } 12 | public T getVal() { return val; } 13 | } 14 | static class D1 { 15 | public void n() { System.out.println("D1.n"); } 16 | } 17 | static class D2 extends D1 { 18 | public void n() { System.out.println("D2.n"); } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/isolated/Generic04.java: -------------------------------------------------------------------------------- 1 | public class Generic04 { 2 | public static void main(String[] args) { 3 | A a1 = new A(new C()); 4 | A a2 = new A(new B()); 5 | a1.n('a'); 6 | } 7 | static class A { 8 | public A(X x) { 9 | } 10 | public void n(long c) { 11 | System.out.println(c); 12 | } 13 | } 14 | static class B { 15 | } 16 | static class C extends B { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/isolated/Generic05.java: -------------------------------------------------------------------------------- 1 | public class Generic05 { 2 | public static void main(String[] args) { 3 | A a = new A(); 4 | a.m(new B(), new C()); 5 | } 6 | static class A { 7 | public void m(T t, S s) { 8 | System.out.println("A.m"); 9 | } 10 | } 11 | static class B {} 12 | static class C {} 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/isolated/Generic06.java: -------------------------------------------------------------------------------- 1 | public class Generic06 { 2 | public static void main(String[] args) { 3 | } 4 | public static class C1 implements I1 { } 5 | public static class C2 extends C1 implements I2 { } 6 | public static class C3 extends C2 { } 7 | public interface I1 {} 8 | public interface I2 extends I1 {} 9 | } 10 | -------------------------------------------------------------------------------- /tests/isolated/Generic07.java: -------------------------------------------------------------------------------- 1 | class Generic07 { 2 | 3 | static class A { 4 | void f(T t) {} 5 | } 6 | 7 | static class B { 8 | private final A a = new A<>(); 9 | 10 | void f(T t) { 11 | a.f(t); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | System.out.println("begin"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/isolated/Generic08.java: -------------------------------------------------------------------------------- 1 | class Generic08 { 2 | 3 | interface I { 4 | void set(E e); 5 | } 6 | 7 | static class A implements I { 8 | public void set(E e) { 9 | System.out.println("setting " + e); 10 | } 11 | } 12 | 13 | public static void main(String[] args) { 14 | System.out.println("begin"); 15 | new A().set(42); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/isolated/Generic09.java: -------------------------------------------------------------------------------- 1 | class Generic09 { 2 | 3 | interface I { 4 | T[] toArray(T[] a); 5 | } 6 | 7 | static class A implements I { 8 | public T[] toArray(T[] a) { 9 | return a; 10 | } 11 | } 12 | 13 | public static void main(String[] args) { 14 | System.out.println("begin"); 15 | I a = new A(); 16 | System.out.println(a.toArray(new String[42]).length); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/isolated/Generic10.java: -------------------------------------------------------------------------------- 1 | class Generic10 { 2 | 3 | static class A implements Cloneable { 4 | @Override 5 | public A clone() { 6 | try { 7 | return (A) super.clone(); 8 | } catch (CloneNotSupportedException e) { 9 | throw new RuntimeException(e); 10 | } 11 | } 12 | 13 | void f() { 14 | clone(); 15 | } 16 | } 17 | 18 | static A[] f() { 19 | return new A[0]; 20 | } 21 | 22 | public static void main(String[] args) { 23 | System.out.println("begin"); 24 | new A().clone(); 25 | f().clone(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/isolated/Generic11.java: -------------------------------------------------------------------------------- 1 | class Generic11 { 2 | 3 | interface I { 4 | void set(T e); 5 | } 6 | 7 | static class A implements I { 8 | public void set(String e) { 9 | System.out.println("setting " + e); 10 | } 11 | } 12 | 13 | static class E implements I { 14 | public void set(Integer n) { 15 | System.out.println("integer " + n); 16 | } 17 | public void set(String s) { 18 | System.out.println("string " + s); 19 | } 20 | } 21 | 22 | static class B { 23 | void f(T t) {} 24 | } 25 | 26 | static class C extends B { 27 | void f(Integer n) { 28 | System.out.println(n); 29 | } 30 | } 31 | 32 | static class D extends B { 33 | void f(Integer n) { 34 | System.out.println("integer " + n); 35 | } 36 | void f(String s) { 37 | System.out.println("string " + s); 38 | } 39 | } 40 | 41 | public static void main(String[] args) { 42 | System.out.println("begin"); 43 | new A().set("hello"); 44 | new C().f(42); 45 | new D().f(43); 46 | new D().f("d"); 47 | ((B) new D()).f("cast to raw"); 48 | new E().set(44); 49 | new E().set("e"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/isolated/Generic12.java: -------------------------------------------------------------------------------- 1 | class Generic12 { 2 | 3 | public static void main(String[] args) { 4 | A a = new A(); // A {String / T} 5 | a.f("A"); 6 | 7 | B b = new B(); 8 | b.f("B"); 9 | ((A) b).f("(A) B"); 10 | } 11 | 12 | static class A { 13 | int i = 0; 14 | public void f(T t) { System.out.println("T " + t); } 15 | } 16 | 17 | static class B extends A { 18 | public void f(String s) { System.out.println("String " + s); } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/isolated/Generic13.java: -------------------------------------------------------------------------------- 1 | public class Generic13 { 2 | 3 | static class A {} 4 | 5 | static class B extends A {} 6 | 7 | // Calling f with an argument of raw type A causes 8 | // T to be inferred as A. Then the upper bound of T 9 | // becomes A> after type variable substitutions. 10 | // Yet A is not a subtype of A>, so the bounds on the 11 | // type variable are not satisfied. 12 | static > void f(A a) { 13 | System.out.println(a.getClass()); 14 | } 15 | 16 | public static void main(String[] args) { 17 | System.out.println("begin"); 18 | A a = new A(); 19 | f(a); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/isolated/Generic14.java: -------------------------------------------------------------------------------- 1 | class Generic14 { 2 | 3 | static class A { 4 | class Inner { 5 | void f() { 6 | System.out.println("f"); 7 | } 8 | } 9 | 10 | void createInner() { 11 | new Inner().f(); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | System.out.println("begin"); 17 | new A().createInner(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/GenericInterface.java: -------------------------------------------------------------------------------- 1 | public class GenericInterface { 2 | 3 | public static void main(String[] args) { 4 | System.out.println(new A().getValue$$()); 5 | } 6 | 7 | @Override 8 | public String toString() { 9 | return "GenericInterface"; 10 | } 11 | 12 | private static class A implements I { 13 | 14 | @Override 15 | public GenericInterface getValue$$() { 16 | return new GenericInterface(); 17 | } 18 | } 19 | 20 | private interface I { 21 | T getValue$$(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/isolated/GenericMethods.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class GenericMethods { 4 | 5 | public static void main(String[] args) { 6 | new GenericMethods().print("hi", "world"); 7 | } 8 | 9 | public T print(T o1, T o2) { 10 | System.out.println("T " + o1 + " -- " + o2); 11 | return o1; 12 | } 13 | 14 | // Polyglot disagrees with javac on which 'print' method to call, 15 | // so we ignore this part of the test for now. 16 | // public String print(String o1, String o2) { 17 | // System.out.println("String " + o1 + " -- " + o2); 18 | // return o2; 19 | // } 20 | 21 | public void print(HashMap o1){ 22 | System.out.println(o1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/isolated/GenericRemoved.java: -------------------------------------------------------------------------------- 1 | public class GenericRemoved { 2 | public static void main(java.lang.String[] args) { 3 | java.lang.System.out.println( 4 | new GenericRemoved((java.lang.Object) "Hi There!").toString()); 5 | java.lang.System.out.println( 6 | new GenericRemoved((java.lang.Object) "Hi There!").toString()); 7 | java.lang.System.out.println( 8 | new GenericRemoved(new GenericRemoved.A()).toString()); 9 | } 10 | 11 | java.lang.Object obj; 12 | 13 | public GenericRemoved(java.lang.Object obj) { 14 | super(); 15 | this.obj = obj; 16 | } 17 | 18 | public java.lang.String toString() { 19 | return "Generic[".concat(((java.lang.Object) obj).toString()).concat("]"); 20 | } 21 | 22 | private static class A { 23 | public java.lang.String toString() { return "A"; } 24 | public A() { super(); } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/isolated/HashtableTest.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Hashtable; 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | public class HashtableTest { 7 | 8 | public static void main(String[] args) { 9 | Hashtable hash = new Hashtable<>(); 10 | hash.put("hello","world"); 11 | System.out.println(hash.get("hello")); 12 | hash.put("hello","no"); 13 | System.out.println(hash.get("hello")); 14 | Hashtable hash2 = new Hashtable<>(); 15 | hash2.put("world", "hello"); 16 | System.out.println(hash2.get("world")); 17 | for (Map.Entry e : hash.entrySet()) { 18 | if (e.getKey().equals("hello")) { 19 | System.out.println(e.getKey() + ":" + e.getValue()); 20 | } 21 | } 22 | chmtest(); 23 | } 24 | 25 | public static void chmtest() { 26 | ConcurrentHashMap hm = new ConcurrentHashMap<>(); 27 | hm.put(3, "yes"); 28 | System.out.println(hm.get(3)); 29 | } 30 | } -------------------------------------------------------------------------------- /tests/isolated/IfStatement.java: -------------------------------------------------------------------------------- 1 | public class IfStatement { 2 | public static void main(String[] args) { 3 | int x = 3; 4 | 5 | if (x >= 3) { 6 | System.out.print(1); 7 | } 8 | 9 | if (x >= 4) { 10 | System.out.print(-1); 11 | } else { 12 | System.out.print(2); 13 | } 14 | 15 | if (x == 3 && x - 32 > 6) { 16 | System.out.print(-1); 17 | } else { 18 | if (x < 7) { 19 | System.out.print(3); 20 | } else { 21 | System.out.print(-1); 22 | } 23 | } 24 | 25 | if (x - 32 > 6 && t()) { 26 | System.out.println(-1); 27 | } else { 28 | System.out.println(4); 29 | } 30 | } 31 | 32 | public static boolean t() { 33 | System.out.println(-1); 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/isolated/Inc.java: -------------------------------------------------------------------------------- 1 | public class Inc { 2 | private static int f() { 3 | System.out.println("Function called"); 4 | return 0; 5 | } 6 | 7 | public static void main(String[] args) { 8 | int a[] = new int[1]; 9 | System.out.println(a[0]); 10 | a[f()] += 1; 11 | System.out.println(a[0]); 12 | a[f()] *= 4; 13 | System.out.println(a[0]); 14 | a[f()] -= 1; 15 | System.out.println(a[0]); 16 | a[f()] /= 2; 17 | System.out.println(a[0]); 18 | a[f()] <<= 1; 19 | System.out.println(a[0]); 20 | System.out.println(a[f()]++); 21 | System.out.println(a[0]); 22 | System.out.println(--a[f()]); 23 | System.out.println(a[0]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/isolated/Initializer.java: -------------------------------------------------------------------------------- 1 | class Initializer { 2 | int i = 42; 3 | 4 | static { System.out.println("Static"); } 5 | { System.out.println(i); } 6 | { System.out.println("After"); } 7 | 8 | Initializer(int i) { 9 | System.out.println("Inner constructor"); 10 | System.out.println(i); 11 | } 12 | 13 | Initializer(String s) {} 14 | 15 | Initializer() { 16 | this(27); 17 | System.out.println("Outer constructor"); 18 | } 19 | 20 | public static void main(String[] args) { 21 | Initializer i = new Initializer(); 22 | i = new Initializer(); 23 | i = new Subclass(); 24 | i = new Subclass(); 25 | } 26 | 27 | static class Subclass extends Initializer { 28 | int j = 24; 29 | 30 | { System.out.print("Subclass "); System.out.println(j); } 31 | { System.out.println("Subclass after"); } 32 | 33 | Subclass(int n) { 34 | super(); 35 | System.out.println("Subclass inner constructor"); 36 | } 37 | 38 | Subclass() { 39 | this(0); 40 | System.out.println("Subclass outer constructor"); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/isolated/InstanceOf.java: -------------------------------------------------------------------------------- 1 | class InstanceOf { 2 | public static void main(String[] args) { 3 | f(new C2()); 4 | f(new C3()); 5 | } 6 | public static void f(Object o) { 7 | System.out.println(o instanceof I1); 8 | System.out.println(o instanceof I2); 9 | System.out.println(o instanceof C1); 10 | System.out.println(o instanceof C2); 11 | System.out.println(o instanceof C3); 12 | System.out.println(o instanceof InstanceOf); 13 | } 14 | public static class C1 implements I1 { } 15 | public static class C2 extends C1 implements I2 { } 16 | public static class C3 extends C2 { } 17 | public interface I1 {} 18 | public interface I2 extends I1 {} 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/Interface.java: -------------------------------------------------------------------------------- 1 | public class Interface { 2 | public static void main(String[] args){ 3 | I obj; 4 | obj = new I1(); 5 | System.out.println(obj.method()); 6 | obj = new I2(); 7 | System.out.println(obj.method()); 8 | obj = new I3(); 9 | System.out.println(obj.method()); 10 | J jbo = (J) obj; 11 | System.out.println(jbo.method2()); 12 | } 13 | 14 | 15 | } 16 | 17 | interface I { 18 | int method(); 19 | } 20 | 21 | interface J { 22 | int method2(); 23 | } 24 | 25 | class I1 implements I{ 26 | public int a(){return -1;} 27 | public int method(){ 28 | return 1; 29 | } 30 | } 31 | 32 | class I2 implements I{ 33 | public int b(){return -2;} 34 | public int method(){ 35 | return 2; 36 | } 37 | } 38 | 39 | class I3 implements I,J { 40 | public int method() { 41 | return 3; 42 | } 43 | public int method2() { 44 | return 0; 45 | } 46 | } -------------------------------------------------------------------------------- /tests/isolated/InterfaceHierarchy.java: -------------------------------------------------------------------------------- 1 | public class InterfaceHierarchy { 2 | public static void main(String[] args){ 3 | IHC obj = new IHC(); 4 | System.out.println(obj.method1()); 5 | System.out.println(obj.method2()); 6 | 7 | IH1 ih1 = obj; 8 | System.out.println(ih1.method1()); 9 | 10 | IH2 ih2 = obj; 11 | System.out.println(ih2.method1()); 12 | System.out.println(ih2.method2()); 13 | } 14 | 15 | 16 | } 17 | 18 | interface IH1 { 19 | int method1(); 20 | } 21 | 22 | interface IH2 extends IH1 { 23 | int method2(); 24 | } 25 | 26 | 27 | class IHC implements IH2{ 28 | 29 | public int method1() { 30 | return 1; 31 | } 32 | 33 | public int method2() { 34 | return 2; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/isolated/InterruptTest.java: -------------------------------------------------------------------------------- 1 | public class InterruptTest { 2 | public static void main(String args[]) { 3 | Thread current = Thread.currentThread(); 4 | System.out.println(current.isInterrupted()); 5 | current.interrupt(); 6 | System.out.println(current.isInterrupted()); 7 | System.out.println(current.isInterrupted()); 8 | System.out.println(Thread.interrupted()); 9 | System.out.println(current.isInterrupted()); 10 | current.interrupt(); 11 | synchronized (current) { 12 | try { 13 | current.wait(1); 14 | System.out.println("no"); 15 | } catch (InterruptedException e) { 16 | System.out.println(e.getClass()); 17 | } 18 | } 19 | synchronized (current) { 20 | try { 21 | current.wait(1); 22 | System.out.println("yes"); 23 | } catch (InterruptedException e) { 24 | System.out.println(e.getClass()); 25 | } 26 | } 27 | current.interrupt(); 28 | synchronized (current) { 29 | try { 30 | current.join(); 31 | System.out.println("yes"); 32 | } catch (InterruptedException e) { 33 | System.out.println(e.getClass()); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/isolated/Lit.java: -------------------------------------------------------------------------------- 1 | public class Lit { 2 | public static void main(String[] args) { 3 | Lit n = null; 4 | System.out.println(n); 5 | 6 | boolean bool = false; 7 | char c = 0x41; 8 | byte b = 0b101; 9 | short s = 3; 10 | int i = -22; 11 | long l = 987654321000L; 12 | float f = 1.012334f; 13 | double d = -14.032456; 14 | String str = "Hello, world!"; 15 | System.out.println(bool); 16 | System.out.println(c); 17 | System.out.println(b); 18 | System.out.println(s); 19 | System.out.println(i); 20 | System.out.println(l); 21 | System.out.println(f); 22 | System.out.println(d); 23 | System.out.println(str); 24 | 25 | System.out.println(true); 26 | System.out.println(0x11); 27 | System.out.println(0b011); 28 | System.out.println(-22); 29 | System.out.println(987654321000L); 30 | System.out.println(1.012334f); 31 | System.out.println(-14.032456); 32 | System.out.println("Hello, world!"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/isolated/Loop.java: -------------------------------------------------------------------------------- 1 | public class Loop { 2 | public static void main(String[] args) { 3 | int n = 10; 4 | for (int i = 0; i < n; ++i) { 5 | if (i % 2 == 1) 6 | continue; 7 | if (i > 0) 8 | System.out.print(" "); 9 | System.out.print(i); 10 | } 11 | System.out.println(); 12 | 13 | int i = 0; 14 | while (i < n) { 15 | if (i > 0) 16 | System.out.print(" "); 17 | System.out.print(i); 18 | ++i; 19 | if (i > n/2) { 20 | break; 21 | } 22 | } 23 | System.out.println(); 24 | 25 | i = n - 1; 26 | do { 27 | System.out.println("do-while"); 28 | ++i; 29 | } while (i <= n); 30 | 31 | i = 0; 32 | do { 33 | if (i > 5) 34 | break; 35 | if (i > 0) 36 | System.out.print(" "); 37 | System.out.print(i); 38 | ++i; 39 | } while (i < n); 40 | System.out.println(); 41 | 42 | i = 0; 43 | for (;;) { 44 | ++i; 45 | break; 46 | } 47 | for (; i == 0; ); 48 | System.out.println(i); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/isolated/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | for (int i = 0; i < args.length; ++i) { 4 | System.out.println(args[i]); 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/isolated/MultipleInterfaces.java: -------------------------------------------------------------------------------- 1 | public class MultipleInterfaces { 2 | public static void main(String[] args){ 3 | MIC obj = new MIC(); 4 | System.out.println(obj.method1()); 5 | System.out.println(obj.method2()); 6 | System.out.println(obj.method3()); 7 | 8 | MI1 mi1 = obj; 9 | System.out.println(mi1.method1()); 10 | 11 | MI2 mi2 = obj; 12 | System.out.println(mi2.method2()); 13 | 14 | MI3 mi3 = obj; 15 | System.out.println(mi3.method3()); 16 | 17 | } 18 | 19 | 20 | } 21 | 22 | interface MI1 { 23 | int method1(); 24 | } 25 | 26 | interface MI2 { 27 | int method2(); 28 | } 29 | 30 | interface MI3 { 31 | int method3(); 32 | } 33 | 34 | class MIC implements MI1, MI2, MI3{ 35 | 36 | public int method1() { 37 | return 1; 38 | } 39 | 40 | public int method2() { 41 | return 2; 42 | } 43 | 44 | public int method3() { 45 | return 3; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/isolated/Nesting.java: -------------------------------------------------------------------------------- 1 | public class Nesting { 2 | public static void main(String[] args) { 3 | System.out.println(new StaticNested().toString()); 4 | 5 | Nesting outer = new Nesting(); 6 | Inner inner = outer.new Inner(); 7 | System.out.println(inner); 8 | 9 | Inner.InnerInner innerInner = inner.new InnerInner(); 10 | System.out.println(innerInner); 11 | 12 | } 13 | 14 | public int outer = 100; 15 | 16 | private static class StaticNested { 17 | @Override 18 | public String toString() { 19 | return "StaticNested"; 20 | } 21 | } 22 | 23 | public class Inner { 24 | 25 | public class InnerInner{ 26 | 27 | @Override 28 | public String toString() { 29 | return "InnerInner" + outer; 30 | } 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "Inner" + outer; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/isolated/PrimitiveReflection.java: -------------------------------------------------------------------------------- 1 | public class PrimitiveReflection { 2 | 3 | public static void main(String[] args) { 4 | System.out.println(int.class); 5 | System.out.println(int.class.getSuperclass()); 6 | System.out.println(long.class); 7 | System.out.println(short.class); 8 | System.out.println(char.class); 9 | System.out.println(byte.class); 10 | System.out.println(float.class); 11 | System.out.println(double.class); 12 | System.out.println(boolean.class); 13 | System.out.println(void.class); 14 | } 15 | } -------------------------------------------------------------------------------- /tests/isolated/Printing.java: -------------------------------------------------------------------------------- 1 | public class Printing { 2 | public static void main(String[] args) { 3 | System.out.println(1); 4 | System.out.println(2); 5 | System.out.println(3); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/isolated/ReflectionMemoryTest.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.Field; 2 | import java.lang.reflect.Method; 3 | 4 | public class ReflectionMemoryTest { 5 | static boolean b; 6 | 7 | public static void main(String[] args) { 8 | ReflectionMemoryTest s = new ReflectionMemoryTest(); 9 | Class cls = s.getClass(); 10 | Field[] fields = cls.getDeclaredFields(); 11 | Method[] methods = cls.getDeclaredMethods(); 12 | System.out.println(fields.length); 13 | for (int i = 0; i < 100000; i++) { 14 | System.out.println(fields[0].getType()); 15 | System.out.println(methods[0].getReturnType()); 16 | System.out.println(i); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/RuntimeTypeCheck.java: -------------------------------------------------------------------------------- 1 | public class RuntimeTypeCheck { 2 | 3 | static class A{} 4 | static class B{} 5 | 6 | private static B createB() { 7 | System.out.println("Creating B"); 8 | return new B(); 9 | } 10 | 11 | public static void main(String[] args) { 12 | try { 13 | A a = (A) (Object) createB(); 14 | } catch (ClassCastException e){ 15 | System.out.println("Correct"); 16 | } 17 | System.out.println("Done"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/isolated/SimpleClass.java: -------------------------------------------------------------------------------- 1 | public class SimpleClass { 2 | int field; 3 | private char field2; 4 | 5 | public SimpleClass(int i) { 6 | this.field = i; 7 | this.field2 = (char) i; 8 | } 9 | 10 | public static void main(String[] args) { 11 | SimpleClass s = new SimpleClass(0); 12 | s.field = 12; 13 | s.field2 = 'A'; 14 | System.out.println(s.method() + s.privateMethod()); 15 | 16 | SimpleClassE se = new SimpleClassE(21); 17 | System.out.println(se.finalMethod() + se.method()); 18 | 19 | } 20 | 21 | public int method() { 22 | privateMethod(); 23 | return field + field2; 24 | } 25 | 26 | private int privateMethod() { 27 | field2 = 'A'; 28 | return 23; 29 | } 30 | 31 | final int finalMethod() { 32 | field2 = 'B'; 33 | return 74; 34 | } 35 | 36 | public static class SimpleClassE extends SimpleClass { 37 | 38 | public SimpleClassE(int i) { 39 | super(i); 40 | } 41 | 42 | public int method() { 43 | return super.method() + 1; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/isolated/Special.java: -------------------------------------------------------------------------------- 1 | class Special { 2 | protected final String field = "Super field"; 3 | 4 | public static void main(String[] args) { 5 | Special s = new Special(); 6 | s.f(); 7 | Sub sub = new Sub(); 8 | sub.f(); 9 | } 10 | 11 | void f() { 12 | this.g(); 13 | } 14 | 15 | void g() { 16 | System.out.println("Hello!"); 17 | System.out.println(field); 18 | } 19 | } 20 | 21 | class Sub extends Special { 22 | protected final String field = "Sub field"; 23 | 24 | void g() { 25 | System.out.println("Bonjour!"); 26 | System.out.println(field); 27 | super.g(); 28 | System.out.println(super.field); 29 | System.out.println("Bonjour!"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/isolated/StaticFields.java: -------------------------------------------------------------------------------- 1 | public class StaticFields { 2 | private static int i = 1; 3 | private static int j = 2; 4 | private static int k; 5 | 6 | public static void main(String[] args) { 7 | System.out.println(i); 8 | System.out.println(j); 9 | k = i + j; 10 | System.out.println(k); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/isolated/StringConversion.java: -------------------------------------------------------------------------------- 1 | public class StringConversion { 2 | public static void main(String[] args) { 3 | System.out.println("Creating...\n" + new StringConversion() +"\nDone!"); 4 | System.out.println("null: " + null); 5 | System.out.println("nullObj: " + nullObj()); 6 | System.out.println("nullStr: " + nullStr()); 7 | System.out.println("nullToString: " + new NullToString()); 8 | System.out.println("byte: " + (byte) 0); 9 | System.out.println("short: " + (short) 0); 10 | System.out.println("char: " + 'a'); 11 | System.out.println("int: " + 0); 12 | System.out.println("long: " + 0L); 13 | // System.out.println("float: " + 0.0f); Not implemented yet 14 | // System.out.println("double: " + 0.0); Not implemented yet 15 | System.out.println("bool: " + true); 16 | System.out.println("bool: " + false); 17 | } 18 | 19 | public static Object nullObj() { 20 | return null; 21 | } 22 | 23 | public static String nullStr() { 24 | return null; 25 | } 26 | 27 | public String toString() { 28 | return "StringConversion"; 29 | } 30 | 31 | public static class NullToString { 32 | public String toString() { 33 | return null; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/isolated/StringIntern.java: -------------------------------------------------------------------------------- 1 | class StringIntern { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("hello" == "hello"); 5 | // this should succeed once we add string constant folding 6 | System.out.println("hello" == "hel"+"l" + "o"); 7 | System.out.println("hello" == ("hel"+"lo").intern()); 8 | System.out.println(("he"+"llo").intern() == ("hel"+"lo").intern()); 9 | String he = "he"; 10 | System.out.println(he+"llo" == ("hel"+"lo").intern()); 11 | } 12 | } -------------------------------------------------------------------------------- /tests/isolated/Strings.java: -------------------------------------------------------------------------------- 1 | public class Strings { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello, world! 1"); 5 | String s = "Hello, world! 2"; 6 | System.out.println(s); 7 | char[] vals = { 'h', 'e', 'l', 'l' , 'o' }; 8 | String chars = new String(vals); 9 | System.out.println(chars); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/isolated/Subtype.java: -------------------------------------------------------------------------------- 1 | public class Subtype { 2 | 3 | public static void main(String[] args) { 4 | A a = new A().getValue$$(); 5 | B b = new B().getValue$$(); 6 | 7 | System.out.println(a + " -- " + b); 8 | } 9 | 10 | private static class A { 11 | 12 | public A getValue$$() { 13 | return new A(); 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "A"; 19 | } 20 | } 21 | 22 | private static class B extends A{ 23 | @Override 24 | public B getValue$$() { 25 | return new B(); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "B"; 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/isolated/Synchronized.java: -------------------------------------------------------------------------------- 1 | public class Synchronized { 2 | public static void main(String[] args) { 3 | Synchronized obj = new Synchronized(); 4 | synchronized (obj) { 5 | System.out.println("Hello"); 6 | } 7 | try { 8 | testtry(); 9 | } catch (Exception e) { 10 | System.out.println("caught e: " + e.getMessage()); 11 | } 12 | 13 | try { 14 | synchronized (obj) { 15 | throw new Exception("inner throw"); 16 | } 17 | } catch (Exception e) { 18 | System.out.println("caught e: " + e.getMessage()); 19 | } 20 | 21 | synchronized (obj) { 22 | System.out.println("Acquired lock after exceptions"); 23 | obj.doStuff(); 24 | } 25 | } 26 | 27 | public static synchronized void testtry() throws Exception { 28 | System.out.println("entertest"); 29 | throw new Exception("message1"); 30 | } 31 | 32 | public synchronized void doStuff() { 33 | System.out.println("acquired owned lock succeeded"); 34 | } 35 | 36 | public static void synchronized_enter(Object o) { 37 | //checking that the desugar name for monitor enter isn't used as 38 | //special constant anywhere. This method should never be called 39 | System.out.println("yesss"); 40 | return; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /tests/isolated/TernaryOperator.java: -------------------------------------------------------------------------------- 1 | public class TernaryOperator { 2 | public static void main(String[] args) { 3 | System.out.print(true ? 1 : 0); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/isolated/ThreadingTest.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.concurrent.ConcurrentLinkedQueue; 3 | 4 | public class ThreadingTest extends Thread { 5 | 6 | private int id; 7 | private final static List output = new ArrayList<>(); 8 | 9 | public ThreadingTest(int id) { 10 | this.id = id; 11 | } 12 | 13 | public void run() { 14 | try { 15 | for (int i = 0; i < 10; i++) { 16 | // Displaying the thread that is running 17 | synchronized (output) { 18 | output.add("Thread " + id + " is running"); 19 | } 20 | } 21 | } catch (Exception e) { 22 | // Throwing an exception 23 | e.printStackTrace(); 24 | } 25 | } 26 | 27 | public static void main(String[] args) throws Exception { 28 | System.out.println("hi"); 29 | System.out.println(Math.random() < 1); 30 | 31 | int n = 8; // Number of threads 32 | ThreadingTest[] pool = new ThreadingTest[8]; 33 | for (int i = 0; i < 8; i++) { 34 | ThreadingTest object = new ThreadingTest(i); 35 | pool[i] = object; 36 | object.start(); 37 | } 38 | for (ThreadingTest t : pool) { 39 | t.join(); 40 | } 41 | 42 | Collections.sort(output); 43 | for (String s : output) { 44 | System.out.println(s); 45 | } 46 | System.out.println(output.size()); 47 | } 48 | } -------------------------------------------------------------------------------- /tests/isolated/Unary.java: -------------------------------------------------------------------------------- 1 | class Unary { 2 | public static void main(String[] args) { 3 | System.out.println("begin"); 4 | 5 | int i = 0; 6 | System.out.println(i++); 7 | System.out.println(++i); 8 | System.out.println(-i); 9 | System.out.println(--i); 10 | System.out.println(i--); 11 | System.out.println(+i); 12 | 13 | float f = 0; 14 | System.out.println(f++ == 0.0); 15 | System.out.println(f == 1.0); 16 | System.out.println(++f == 2.0); 17 | System.out.println(-f == -2.0); 18 | System.out.println(--f == 1.0); 19 | System.out.println(f-- == 1.0); 20 | System.out.println(+(-(++f)) == -1.0); 21 | 22 | Integer w = 5; 23 | System.out.println(w++); 24 | System.out.println(w); 25 | System.out.println(++w); 26 | System.out.println(-w); 27 | System.out.println(--w); 28 | System.out.println(w--); 29 | System.out.println(+w); 30 | 31 | System.out.println(!true); 32 | System.out.println(~24); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/isolated/UnaryOperations.java: -------------------------------------------------------------------------------- 1 | public class UnaryOperations { 2 | public static void main(String[] args){ 3 | int x = -10; 4 | System.out.println(x); 5 | x = -x; 6 | System.out.println(x); 7 | 8 | System.out.println((-100)+ 10); 9 | 10 | System.out.println(+10); 11 | System.out.println(+(-10)); 12 | 13 | System.out.println(~0); 14 | System.out.println(~10); 15 | System.out.println(~100); 16 | 17 | 18 | int y = 0; 19 | System.out.println((y++) + (++y)); 20 | System.out.println(y); 21 | System.out.println((y--) + (--y)); 22 | System.out.println(y); 23 | 24 | System.out.println(!true); 25 | System.out.println(!false); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/isolated/VarArgs.java: -------------------------------------------------------------------------------- 1 | class VarArgs { 2 | 3 | VarArgs(int... ns) { 4 | System.out.println("constructor"); 5 | System.out.println(ns.length); 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("begin"); 10 | f(); 11 | f("hello"); 12 | f("hello", "world"); 13 | f(3, "repeat", "thrice"); 14 | g((short) 1, (byte) 2, 3); 15 | new VarArgs(1, 2, 3); 16 | } 17 | 18 | static void f(String s) { 19 | System.out.println("f " + s); 20 | } 21 | 22 | static void f(String... ss) { 23 | System.out.print("f"); 24 | for (int i = 0; i < ss.length; ++i) { 25 | System.out.print(" " + ss[i]); 26 | } 27 | System.out.println(); 28 | } 29 | 30 | static void f(int repeat, T... ss) { 31 | while (repeat --> 0) { 32 | f(ss); 33 | } 34 | } 35 | 36 | static void g(int... ns) { 37 | System.out.print("g"); 38 | for (int i = 0; i < ns.length; ++i) { 39 | System.out.print(" " + ns[i]); 40 | } 41 | System.out.println(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/isolated/expected_fails: -------------------------------------------------------------------------------- 1 | ArrayReflection 2 | ReflectionMemoryTest 3 | -------------------------------------------------------------------------------- /tests/misc/EmptyClass.java: -------------------------------------------------------------------------------- 1 | public class EmptyClass { 2 | } 3 | -------------------------------------------------------------------------------- /tests/misc/ExtendConditions.java: -------------------------------------------------------------------------------- 1 | import tests.Conditions; 2 | 3 | public class ExtendConditions extends Conditions { 4 | 5 | 6 | public void h() { 7 | super.h(); 8 | } 9 | 10 | public void i() { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/misc/ExtendImportedClass.java: -------------------------------------------------------------------------------- 1 | import polyglot.ast.IntLit_c; 2 | import polyglot.util.Position; 3 | 4 | public class ExtendImportedClass extends IntLit_c { 5 | 6 | public ExtendImportedClass(Position pos, Kind kind, long value) { 7 | super(pos, kind, value); 8 | something(); 9 | } 10 | 11 | private long something() { 12 | return 12312312312L; 13 | } 14 | 15 | 16 | public long value() { 17 | return super.value(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/misc/FloatingPoint.java: -------------------------------------------------------------------------------- 1 | 2 | public class FloatingPoint { 3 | 4 | // public static void main(String[] args) { 5 | // main(); 6 | // } 7 | 8 | // private class ABC extends FloatingPoint { 9 | // 10 | // } 11 | 12 | public static void main() { 13 | float x = 32.0F; 14 | double y = x; 15 | y = y + y; 16 | } 17 | 18 | public double f(float f) { 19 | return f; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /tests/misc/Hello.java: -------------------------------------------------------------------------------- 1 | public class Hello { 2 | public static void main(String[] args) { 3 | int x = 1 + 2 + 3 + 4 + 5; 4 | System.out.println(x); 5 | System.out.println(1 + 2 + 3 + 4 + 5); 6 | System.out.println("Hello world!"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/misc/Hello.pll: -------------------------------------------------------------------------------- 1 | public class Hello { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/misc/Hello2.java: -------------------------------------------------------------------------------- 1 | public class Hello2 { 2 | public static void main(String[] args) { 3 | int x; 4 | if(true){ 5 | x = 1+2+3+4+5; 6 | } else { 7 | x = 2+3+4+5+6; 8 | } 9 | 10 | String s = new String("Hi"); 11 | 12 | System.out.println(x); 13 | System.out.println(1+2+3+4+5); 14 | System.out.println("Hello world!"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/misc/InheritedStaticMethod.java: -------------------------------------------------------------------------------- 1 | public class InheritedStaticMethod extends InheritedStaticMethod_A { 2 | public static void main(String[] args) { 3 | // InheritedStaticMethod.foo(); 4 | } 5 | } 6 | 7 | class InheritedStaticMethod_A { 8 | public static void foo() { 9 | System.out.println("Static A.foo"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/misc/IntAdd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "IntAdd.h" 4 | 5 | JNIEXPORT void JNICALL Java_IntAdd_print(JNIEnv * e, jclass c, jint i){ 6 | printf("%d", i); 7 | } 8 | //JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) { 9 | // printf("Hello World!\n"); 10 | // return; 11 | //} 12 | -------------------------------------------------------------------------------- /tests/misc/IntAdd.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class IntAdd */ 4 | 5 | #ifndef _Included_IntAdd 6 | #define _Included_IntAdd 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: IntAdd 12 | * Method: print 13 | * Signature: (I)V 14 | */ 15 | JNIEXPORT void JNICALL Java_IntAdd_print 16 | (JNIEnv *, jclass, jint); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /tests/misc/IntAdd.java: -------------------------------------------------------------------------------- 1 | public class IntAdd { 2 | public static void main() { 3 | int x = 1+2; 4 | print(x+f(4,x)); 5 | if(x == 3){ 6 | print(1); 7 | } else if(false){ 8 | print(0); 9 | } else { 10 | print(123); 11 | } 12 | // double y = 1.0; 13 | } 14 | 15 | public static int f(int w, int y) { 16 | int x = w+y; 17 | return x; 18 | } 19 | 20 | public static native void print(int i); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /tests/misc/IntAdd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/tests/misc/IntAdd.o -------------------------------------------------------------------------------- /tests/misc/IntAdd.s: -------------------------------------------------------------------------------- 1 | .cstring 2 | LC0: 3 | .ascii "%d\0" 4 | .text 5 | .globl _Java_IntAdd_print 6 | _Java_IntAdd_print: 7 | LFB1: 8 | pushq %rbp 9 | LCFI0: 10 | movq %rsp, %rbp 11 | LCFI1: 12 | subq $32, %rsp 13 | movq %rdi, -8(%rbp) 14 | movq %rsi, -16(%rbp) 15 | movl %edx, -20(%rbp) 16 | movl -20(%rbp), %eax 17 | movl %eax, %esi 18 | leaq LC0(%rip), %rdi 19 | movl $0, %eax 20 | call _printf 21 | leave 22 | LCFI2: 23 | ret 24 | LFE1: 25 | .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support 26 | EH_frame1: 27 | .set L$set$0,LECIE1-LSCIE1 28 | .long L$set$0 29 | LSCIE1: 30 | .long 0 31 | .byte 0x1 32 | .ascii "zR\0" 33 | .byte 0x1 34 | .byte 0x78 35 | .byte 0x10 36 | .byte 0x1 37 | .byte 0x10 38 | .byte 0xc 39 | .byte 0x7 40 | .byte 0x8 41 | .byte 0x90 42 | .byte 0x1 43 | .align 3 44 | LECIE1: 45 | LSFDE1: 46 | .set L$set$1,LEFDE1-LASFDE1 47 | .long L$set$1 48 | LASFDE1: 49 | .long LASFDE1-EH_frame1 50 | .quad LFB1-. 51 | .set L$set$2,LFE1-LFB1 52 | .quad L$set$2 53 | .byte 0 54 | .byte 0x4 55 | .set L$set$3,LCFI0-LFB1 56 | .long L$set$3 57 | .byte 0xe 58 | .byte 0x10 59 | .byte 0x86 60 | .byte 0x2 61 | .byte 0x4 62 | .set L$set$4,LCFI1-LCFI0 63 | .long L$set$4 64 | .byte 0xd 65 | .byte 0x6 66 | .byte 0x4 67 | .set L$set$5,LCFI2-LCFI1 68 | .long L$set$5 69 | .byte 0xc 70 | .byte 0x7 71 | .byte 0x8 72 | .align 3 73 | LEFDE1: 74 | .subsections_via_symbols 75 | -------------------------------------------------------------------------------- /tests/misc/IntComparisons.java: -------------------------------------------------------------------------------- 1 | public class IntComparisons { 2 | public static void main() { 3 | noelse(); 4 | } 5 | 6 | public static void noelse(){ 7 | if (1 < 2) { 8 | print(1); 9 | } 10 | if (1 < 1) { 11 | print(0); 12 | } 13 | if (1 < 0) { 14 | print(0); 15 | } 16 | if (4 > 3) { 17 | print(2); 18 | } 19 | if (3 > 3) { 20 | print(0); 21 | } 22 | if (3 > 4) { 23 | print(0); 24 | } 25 | if (2 == 2) { 26 | print(3); 27 | } 28 | if (2 == 1) { 29 | print(0); 30 | } 31 | if (1 <= 2) { 32 | print(4); 33 | } 34 | if (1 <= 1) { 35 | print(5); 36 | } 37 | if (1 <= 0) { 38 | print(0); 39 | } 40 | if (3 >= 4) { 41 | print(0); 42 | } 43 | if (3 >= 3) { 44 | print(6); 45 | } 46 | if (2 >= 3) { 47 | print(0); 48 | } 49 | if (2 != 1) { 50 | print(7); 51 | } 52 | if (2 != 2) { 53 | print(0); 54 | } 55 | } 56 | 57 | public static native void print(int i); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /tests/misc/IntLinkedList.java: -------------------------------------------------------------------------------- 1 | 2 | public class IntLinkedList { 3 | 4 | private int data; 5 | private IntLinkedList next; 6 | 7 | public IntLinkedList next() { 8 | return next; 9 | } 10 | 11 | public int data() { 12 | return data; 13 | } 14 | 15 | public void append(int i) { 16 | IntLinkedList temp = this; 17 | while (temp.next != null) { 18 | temp = temp.next; 19 | } 20 | addSuccessor(i); 21 | } 22 | 23 | private void addSuccessor(int i) { 24 | next = new IntLinkedList(); 25 | next.data = i; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/misc/StaticMethods.java: -------------------------------------------------------------------------------- 1 | public class StaticMethods { 2 | public static void main(String[] args) { 3 | A.foo(); 4 | // B.foo(); 5 | C.foo(); 6 | 7 | A objA = new C(); 8 | // objA.foo(); 9 | 10 | B objB = new C(); 11 | // objB.foo(); 12 | 13 | C objC = new C(); 14 | // objC.foo(); 15 | } 16 | } 17 | 18 | class A { 19 | public static void foo() { 20 | System.out.println("Static A.foo"); 21 | } 22 | } 23 | 24 | class B extends A { 25 | 26 | } 27 | 28 | class C extends B { 29 | public static void foo() { 30 | System.out.println("Static C.foo"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/misc/SubSubClass.java: -------------------------------------------------------------------------------- 1 | 2 | public class SubSubClass extends UseSimpleClass { 3 | 4 | // public static void main(String[] args) { 5 | // main(); 6 | // } 7 | 8 | public static void main() { 9 | UseSimpleClass s = new SubSubClass(); 10 | s.field = 'A';//12; 11 | print(s.method() + s.method2()); 12 | SimpleClass x = s; 13 | print(x.method()); 14 | 15 | print(s.hashCode()); 16 | print(s.hashCode()); 17 | } 18 | 19 | 20 | public int method2() { 21 | return super.method2() - 10; 22 | } 23 | 24 | // public int method(){ 25 | // return super.method() - 10; 26 | // } 27 | 28 | 29 | public int hashCode(){ 30 | return super.hashCode() + 4; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/misc/TestByte.java: -------------------------------------------------------------------------------- 1 | public class TestByte { 2 | public static void main(String[] args) { 3 | byte x = (char) 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/misc/TestStringLit.java: -------------------------------------------------------------------------------- 1 | public class TestStringLit { 2 | public static void main(String[] args) { 3 | String s = "HIIIII"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/misc/UseSimpleClass.java: -------------------------------------------------------------------------------- 1 | public class UseSimpleClass extends SimpleClass { 2 | 3 | // public static void main(String[] args) { 4 | // main(); 5 | // } 6 | 7 | // public static void main() { 8 | // SimpleClass s = new UseSimpleClass(); 9 | // s.field = 'A';//12; 10 | // print(s.method()); 11 | // } 12 | 13 | 14 | public int method() { 15 | return super.method() + 1; 16 | } 17 | 18 | public int method2() { 19 | return method() + 1; 20 | } 21 | // 22 | // int method3() { 23 | // return 3; 24 | // } 25 | // 26 | // protected int method4() { 27 | // return 4; 28 | // } 29 | // 30 | // private int method5() { 31 | // return 5; 32 | // } 33 | } 34 | -------------------------------------------------------------------------------- /tests/misc/libhelloworld.jnilib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/tests/misc/libhelloworld.jnilib -------------------------------------------------------------------------------- /tests/misc/pthScript: -------------------------------------------------------------------------------- 1 | # pth test script 2 | # 3 | # This file is a test script for pth (Polyglot Test Harness). It 4 | # conforms to the following grammar. 5 | # 6 | # ScriptFile ::= CompilerTest+ 7 | # CompilerTest ::= ExtClassName ["CmdLineArgs"] { FileTest [; FileTest]* } 8 | # FileTest ::= CompilationUnits [Description] [FailureSet] 9 | # CompilationUnits ::= Filenames [, Filenames]* 10 | # Filenames ::= Filename [Filename]* 11 | # Description ::= LitString 12 | # FailureSet ::= Failure [, Failure]* 13 | # Failure ::= ( ErrorKind ) 14 | # | ( ErrorKind, "RegExp" ) 15 | # | ( "RegExp" ) 16 | # | ( ) 17 | # ErrorKind : one of, or a unique prefix of one of the following 18 | # strings: "Warning", "Internal Error", "I/O Error", 19 | # "Lexical Error", "Syntax Error", "Semantic Error" 20 | # or "Post-compiler Error". 21 | # Filename : the name of a file. Is interpreted from the 22 | # directory where pth is run. 23 | # LitString : a literal string, enclosed in quotes. 24 | # RegExp : a regular expression, as in java.util.regex; 25 | # is always enclosed in quotes. 26 | # CmdLineArgs : additional command line args for the Polyglot 27 | # compiler; is always enclosed in quotes. 28 | 29 | jlang.ExtensionInfo "-d out -c" { 30 | # Hello.java; 31 | IntAdd.java; 32 | } 33 | -------------------------------------------------------------------------------- /tests/misc/pthScript.results: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/tests/misc/pthScript.results -------------------------------------------------------------------------------- /tests/misc/temp.java: -------------------------------------------------------------------------------- 1 | public class temp { 2 | public static void main(String[] args) { 3 | String x; 4 | x = "" + 4 + 3; 5 | System.out.println(x); 6 | x = "" + f(); 7 | System.out.println(x); 8 | x = "woah" + null; 9 | System.out.println(x); 10 | x = "woah" + new Object(); 11 | System.out.println(x); 12 | } 13 | 14 | private static int f(){ 15 | return 1; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/misc/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | pth=`dirname $0`/../../bin/pth 4 | echo $pth 5 | 6 | if [ ! -f "$pth" ]; then 7 | # TODO: make sure polyglot/bin (which is where pth lives) is in your path 8 | pth=pth 9 | fi 10 | 11 | $pth -classpath ../compiler/classes pthScript 12 | -------------------------------------------------------------------------------- /tests/misc/tests/BreakTest.java: -------------------------------------------------------------------------------- 1 | package tests; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class BreakTest { 6 | public static void main(String[] args) { 7 | main(); 8 | } 9 | 10 | public static void main() { 11 | LinkedList m = new LinkedList<>(); 12 | m.push("k1"); 13 | m.push("k2"); 14 | m.push("k3"); 15 | m.push("k4"); 16 | 17 | int x = 1; 18 | Loop: while (true) { 19 | x++; 20 | break Loop; 21 | } 22 | 23 | Ret: return; 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/tests.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | --------------------------------------------------------------------------------