├── .gitignore
├── Contributing.md
├── Extensions.md
├── LICENSE
├── README.md
├── UnitTest.devp
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jpizza
├── bin
│ └── main
│ │ └── META-INF
│ │ └── MANIFEST.MF
├── build.gradle
└── src
│ └── main
│ └── java
│ ├── META-INF
│ └── MANIFEST.MF
│ └── lemon
│ └── jpizza
│ ├── Constants.java
│ ├── JPType.java
│ ├── Logger.java
│ ├── Operations.java
│ ├── Pair.java
│ ├── Position.java
│ ├── RunMain.java
│ ├── RunTest.java
│ ├── Shell.java
│ ├── Token.java
│ ├── TokenType.java
│ ├── Tokens.java
│ ├── cases
│ ├── Case.java
│ └── ElseCase.java
│ ├── compiler
│ ├── Chunk.java
│ ├── ChunkBuilder.java
│ ├── ChunkCode.java
│ ├── Compiler.java
│ ├── Disassembler.java
│ ├── FlatPosition.java
│ ├── FunctionType.java
│ ├── JStack.java
│ ├── OpCode.java
│ ├── TypeLookup.java
│ ├── headers
│ │ ├── Cache.java
│ │ ├── HeadCode.java
│ │ └── Memo.java
│ ├── libraries
│ │ ├── GUIs.java
│ │ ├── Generators.java
│ │ ├── HTTPx.java
│ │ ├── IOFile.java
│ │ ├── JPCollections.java
│ │ ├── JPSon.java
│ │ ├── JPrinter.java
│ │ ├── JSystem.java
│ │ ├── Time.java
│ │ ├── awt
│ │ │ ├── AbstractWindowToolkit.java
│ │ │ ├── config
│ │ │ │ ├── Canvas.java
│ │ │ │ ├── ColorSpan.java
│ │ │ │ ├── JFont.java
│ │ │ │ ├── Queue.java
│ │ │ │ └── Window.java
│ │ │ └── displays
│ │ │ │ ├── Drawable.java
│ │ │ │ ├── Img.java
│ │ │ │ ├── Line.java
│ │ │ │ ├── Oval.java
│ │ │ │ ├── Polygon.java
│ │ │ │ ├── Rectangle.java
│ │ │ │ └── Text.java
│ │ ├── pretzel
│ │ │ ├── Handle.java
│ │ │ └── Pretzel.java
│ │ └── puddle
│ │ │ ├── ClientPDL.java
│ │ │ ├── PDL.java
│ │ │ └── ServerPDL.java
│ ├── types
│ │ ├── AnyType.java
│ │ ├── GenericType.java
│ │ ├── SpreadType.java
│ │ ├── Type.java
│ │ ├── TypeCodes.java
│ │ ├── Types.java
│ │ ├── VoidType.java
│ │ ├── objects
│ │ │ ├── ClassType.java
│ │ │ ├── EnumChildType.java
│ │ │ ├── EnumType.java
│ │ │ ├── FuncType.java
│ │ │ ├── InstanceType.java
│ │ │ ├── MapType.java
│ │ │ ├── MaybeType.java
│ │ │ ├── MethodType.java
│ │ │ ├── NamespaceType.java
│ │ │ ├── PrimitiveGenericType.java
│ │ │ ├── ReferenceType.java
│ │ │ ├── TupleType.java
│ │ │ └── VecType.java
│ │ └── primitives
│ │ │ ├── BooleanType.java
│ │ │ ├── BytesType.java
│ │ │ ├── DictType.java
│ │ │ ├── FloatType.java
│ │ │ ├── IntType.java
│ │ │ ├── ListType.java
│ │ │ ├── PrimitiveType.java
│ │ │ ├── PrimitiveTypes.java
│ │ │ ├── ResultType.java
│ │ │ └── StringType.java
│ ├── values
│ │ ├── Pattern.java
│ │ ├── Value.java
│ │ ├── ValueArray.java
│ │ ├── Var.java
│ │ ├── classes
│ │ │ ├── BoundMethod.java
│ │ │ ├── ClassAttr.java
│ │ │ ├── Instance.java
│ │ │ ├── JClass.java
│ │ │ └── Namespace.java
│ │ ├── enums
│ │ │ ├── JEnum.java
│ │ │ └── JEnumChild.java
│ │ └── functions
│ │ │ ├── JClosure.java
│ │ │ ├── JFunc.java
│ │ │ ├── JNative.java
│ │ │ ├── NativeResult.java
│ │ │ ├── Result.java
│ │ │ └── Spread.java
│ └── vm
│ │ ├── CallFrame.java
│ │ ├── JPExtension.java
│ │ ├── LibraryManager.java
│ │ ├── VM.java
│ │ └── VMResult.java
│ ├── errors
│ ├── Error.java
│ └── Tip.java
│ ├── generators
│ ├── Lexer.java
│ ├── Optimizer.java
│ └── Parser.java
│ ├── nodes
│ ├── Node.java
│ ├── TreePrinter.java
│ ├── definitions
│ │ ├── AttrAssignNode.java
│ │ ├── AttrDeclareNode.java
│ │ ├── ClassDefNode.java
│ │ ├── DecoratorNode.java
│ │ ├── DestructNode.java
│ │ ├── DynAssignNode.java
│ │ ├── FuncDefNode.java
│ │ ├── LetNode.java
│ │ ├── MethDefNode.java
│ │ └── VarAssignNode.java
│ ├── expressions
│ │ ├── AssertNode.java
│ │ ├── BodyNode.java
│ │ ├── BreakNode.java
│ │ ├── CallNode.java
│ │ ├── CastNode.java
│ │ ├── ClaccessNode.java
│ │ ├── ContinueNode.java
│ │ ├── DerefNode.java
│ │ ├── DropNode.java
│ │ ├── ExtendNode.java
│ │ ├── ForNode.java
│ │ ├── ImportNode.java
│ │ ├── IterNode.java
│ │ ├── PassNode.java
│ │ ├── QueryNode.java
│ │ ├── ReturnNode.java
│ │ ├── ScopeNode.java
│ │ ├── SpreadNode.java
│ │ ├── SwitchNode.java
│ │ ├── ThrowNode.java
│ │ ├── UseNode.java
│ │ └── WhileNode.java
│ ├── operations
│ │ ├── BinOpNode.java
│ │ └── UnaryOpNode.java
│ ├── values
│ │ ├── BooleanNode.java
│ │ ├── BytesNode.java
│ │ ├── DictNode.java
│ │ ├── EnumNode.java
│ │ ├── ListNode.java
│ │ ├── NullNode.java
│ │ ├── NumberNode.java
│ │ ├── PatternNode.java
│ │ ├── RefNode.java
│ │ ├── StringNode.java
│ │ └── ValueNode.java
│ └── variables
│ │ ├── AttrAccessNode.java
│ │ ├── AttrNode.java
│ │ ├── VarAccessNode.java
│ │ └── VarNode.java
│ └── results
│ └── ParseResult.java
├── jpn.png
├── pizzico512.png
├── settings.gradle
└── shadow.bat
/.gitignore:
--------------------------------------------------------------------------------
1 | .replit
2 | replit.nix
3 | *.class
4 | *.jar
5 | sometoken.txt
6 | .DS_STORE
7 | *.devp
8 | *.jbox
9 | *.json
10 | .classpath
11 | .project
12 | .idea
13 | .gradle
14 | **/build/
15 | !src/**/build/
16 | gradle-app.setting
17 | !gradle-wrapper.jar
18 | .gradletasknamecache
19 | etc
20 | package.bat
21 | !UnitTest.devp
--------------------------------------------------------------------------------
/Contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing Guide
2 |
3 | A short and sweet guide on how to get started contributing to JPizza.
4 |
5 | ## Getting the source code
6 |
7 | If you just want to build JPizza for yourself, you can just download the source from github or clone the main repo.
8 |
9 | If you want to contribute any code, Please fork the repo and clone from your fork.
10 |
11 | ## Compiling JPizza
12 |
13 | JPizza uses the gradle build system. So, compiling JPizza is pretty simple! Just navigate your terminal into the folder where you cloned JPizza, then `cd` into the JPizza folder. From there, run the `gradlew shadowJar` command if you are on macos or linux, or `gradlew.bat shadowJar` if you are on windows.
14 |
15 | This will compile JPizza, and the resulting jar will be located at `jpizza/build/libs/jpizza-all.jar`
16 |
17 | If you want to create a cross platform release, you can run `gradlew assembleShadowDist` \[or `gradlew.bat assembleShadowDist` if on windows\]
18 |
19 | This will create archives which include scripts to run JPizza on unix and windows, alongside with the compiled JPizza jar. These archives can be extracted and put anywhere, and once you add the bin folder to your path, you can run JPizza easily.
20 |
21 | ## Thats it!
22 |
23 | That's really all you need to know to compile JPizza! Have fun!
24 |
--------------------------------------------------------------------------------
/Extensions.md:
--------------------------------------------------------------------------------
1 | # JPizza Extension Development
2 |
3 | So, you want to make an extension for JPizza? Well, You've come to the right place.
4 |
5 | ## Getting Started
6 |
7 | The first thing you need to do is [clone the base extension repo.](https://github.com/Lemon-Chad/JPizza-Extension-Template)
8 | This repo contains all of the code and gradle magic to make your own JPizza extension.
9 |
10 | After you have the code, Pick a name for your extension. Should be the easy part.
11 |
12 | ## Beginning Development
13 |
14 | In order to start writing code for your extension, look in the `app/src/main/java/jpext` folder. In there, there should be one file, named `LibraryName.java` (You should rename this to match the name of your library)
15 |
16 | Once you have the file opened, make sure to change every instance of LibraryName to the exact same thing you put as the name of the file. Now, you are almost ready to start making all of your custom functions!
17 |
18 | Next, you need the JPizza jar. Download the latest jar from github, (or compile it yourself), and put it into the `app/jars` folder. Make sure to name it jpizza-all.jar
19 |
20 | This is necessary for all the imports to work, but don't worry, it's not included in the final jar of your extension.
21 |
22 | ## Making Libraries
23 |
24 | So, you want to make a function, but where does that function go?
25 |
26 | Well, in a library of course!
27 |
28 | If you look in the LibraryName.java (Which is what it will be referred to, even though you should have changed the name), you will see a function called `initialize`. This is where all of your initialization code should go. To make the initialization code, simply make a call to the initialize function with the name of your import, the class of your library, (as in, `LibraryName.class`), and finally, a HashMap. In this HashMap, you should `put` all of your functions that will go into that library and a list of parameters for the function.
29 | Example:
30 | `initialize("demo", LibraryName.class, new HashMap<>(){{
31 | put("printDemo", Collections.singletonList("value"));
32 | }});`
33 | This is the initialize call for a library called demo, with one function, 'printDemo', which takes in 1 'value' as its parameter.
34 |
35 | ## Making Functions
36 |
37 | So, you have your libraries, but how do you make functions? Well, once you add it to your library, just create a public Java function below with a return type of RTResult. Make sure to make the name of the function `execute_FunctionName`. This function should take in 1 value, a Context. From this, just do what you gotta do, add a return somewhere, and bam. Easy extension done!
38 |
39 | ## What Next?
40 |
41 | So you have all your code, but how do you use this? Well, just run the gradle task named `jar`. You can do this by running `./gradlew jar` on unix or `./gradlew.bat jar` on windows.
42 |
43 | If everything is good, this should create a jar in the app/build/libs folder called `app.jar`. Simply rename this to the name of your extension, (as used previously), and add it to your `.jpizza/extensions` folder located in your home directory (unless you configured otherwise). Then, simply load up JPizza, and use the command `extend LibraryName` to load the extension, then just import anything you want to use!
44 |
45 | ### Notes
46 | - This is a VERY new and untested system. If you find any bugs with the extension template/compilation process, Please create an issue on the template's github repository. If you find any bugs with the JPizza command, Please create an issue on JPizza's github repository.
47 | - This system will be better eventually once we know what bugs there are. You can use this to do anything you can do with Java within JPizza, so we want it to be as good as possible.
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Jackson Oliver Smith
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # JPizza2
4 |
5 |
6 |
7 | A fast to type and easy to ship language for developers on the go!
8 |
9 | ## Why Use It?
10 |
11 | - Function arrow syntax for fast inline functions.
12 | - Loop arrow syntax to generate complex lists.
13 | - Callback variables that update the value when called.
14 | - The ability to strictly limit numeric variable ranges.
15 | - Query expression that function as an alternative to ternary chains.
16 | - Match expression that functions as a switch statement that returns a value.
17 | - Built-in optimization features like memoization.
18 | - Main functions/classes.
19 | - Built-in benchmarking functions.
20 | - Automatic feedback on how to make your code cleaner.
21 | - Open source.
22 | - Response devs that constantly fix bugs.
23 | - Open source package manager.
24 | - More!
25 |
26 | ## Resources
27 | - [Documentation](https://jpizza.rtfd.io) -> The good ol' docs
28 | - [Contributing Guide](Contributing.md) -> Basic steps to get started contributing.
29 | - [Extension Guide](Extensions.md) -> Guide to developing jpizza extensions.
30 | - [VSCode](https://bit.ly/jp2vscode) -> Add JPizza2 to VSCode
31 | - [JPX](https://bit.ly/jpx) -> Framework adding fun import features and helps you ship your app to other machines without the need for JPizza2
32 | - [Video Tutorials](https://bit.ly/jp2tutorial) -> A full video tutorial series over JPizza2, Fridge, and even JPX!
33 | - [Discord](https://discord.gg/9RGBBk4w4B) -> The official JPizza discord.
34 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GRADLE_OPTS=-Dfile.encoding=utf-8
2 | org.gradle.jvmargs='-Dfile.encoding=UTF-8'
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lemon-Chad/jpizza/1d0380d519decb5d8a7c0b19858dc4772a96862c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jpizza/bin/main/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: lemon.jpizza.Shell
3 |
4 |
--------------------------------------------------------------------------------
/jpizza/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * This generated file contains a sample Java application project to get you started.
5 | * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
6 | * User Manual available at https://docs.gradle.org/7.2/userguide/building_java_projects.html
7 | */
8 |
9 | plugins {
10 | // Apply the application plugin to add support for building a CLI application in Java.
11 | id 'application'
12 | id 'com.github.johnrengelman.shadow' version '7.0.0'
13 | id 'java'
14 | }
15 |
16 | compileJava.options.encoding = 'UTF-8'
17 |
18 | repositories {
19 | // Use Maven Central for resolving dependencies.
20 | mavenCentral()
21 | }
22 |
23 | dependencies {
24 | // Use JUnit test framework.
25 | testImplementation 'junit:junit:4.13.2'
26 |
27 | implementation 'com.github.tomas-langer:chalk:1.0.2'
28 |
29 | implementation 'org.apache.commons:commons-lang3:3.12.0'
30 | implementation 'org.apache.commons:commons-text:1.9'
31 | implementation 'commons-io:commons-io:2.11.0'
32 |
33 |
34 | // Use Jackson for JSON serialization.
35 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.0.1'
36 |
37 | implementation 'org.jetbrains:annotations:16.0.2'
38 |
39 |
40 | // This dependency is used by the application.
41 | implementation 'com.google.guava:guava:30.1.1-jre'
42 | }
43 |
44 | application {
45 | // Define the main class for the application.
46 | mainClass = 'lemon.jpizza.Shell'
47 | }
48 |
49 |
50 | jar {
51 | //noinspection GroovyAssignabilityCheck
52 | manifest {
53 | attributes 'Main-Class': 'lemon.jpizza.Shell'
54 | }
55 |
56 | }
57 |
58 | run{
59 | standardInput = System.in
60 | }
61 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: lemon.jpizza.Shell
3 |
4 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/JPType.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | public enum JPType {
4 | AttrAssign,
5 | AttrAccess,
6 | Attr,
7 | Assert,
8 | Bytes,
9 | BaseFunction,
10 | Break,
11 | BinOp,
12 | Boolean,
13 | ClassInstance,
14 | ClassPlate,
15 | CMethod,
16 | ClassDef,
17 | Call,
18 | Claccess,
19 | Continue,
20 | Deref,
21 | DynAssign,
22 | Dict,
23 | Decorator,
24 | Extend,
25 | Enum,
26 | EnumChild,
27 | Function,
28 | FuncDef,
29 | For,
30 | Generic,
31 | Import,
32 | Iter,
33 | Library,
34 | List,
35 | MethDef,
36 | Null,
37 | Number,
38 | Pattern,
39 | Pass,
40 | Query,
41 | Ref,
42 | Return,
43 | Res,
44 | String,
45 | Switch,
46 | Spread,
47 | Use,
48 | UnaryOp,
49 | VarAssign,
50 | Value,
51 | VarAccess,
52 | Var,
53 | While,
54 | Body,
55 | Scope,
56 | Let,
57 | Throw,
58 | Drop,
59 | Destruct,
60 | Cast,
61 | }
62 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/Logger.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | import com.github.tomaslanger.chalk.Chalk;
4 | import lemon.jpizza.compiler.values.Value;
5 |
6 | import java.util.Collections;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Scanner;
10 |
11 | public class Logger {
12 | boolean log = true;
13 | boolean tips = false;
14 | public final boolean debug = false;
15 | final int omitt = 5;
16 | final int tape = 40;
17 | final Scanner scanner = new Scanner(System.in);
18 |
19 | public void reset() {
20 | log = true;
21 | tips = false;
22 | }
23 |
24 | public String ots(Object text) {
25 | return ots(text, false);
26 | }
27 |
28 | @SuppressWarnings("DuplicatedCode")
29 | public String ots(Object text, boolean stringInner) {
30 | if (text instanceof Value) {
31 | Value val = (Value) text;
32 | if (val.isList) {
33 | StringBuilder sb = new StringBuilder();
34 | List l = val.asList();
35 |
36 | for (int i = 0; i < l.size(); i++)
37 | if (i >= omitt && i < l.size() - omitt) {
38 | if (i == omitt + 1) sb.append("..., ");
39 | }
40 | else sb.append(ots(l.get(i), true)).append(", ");
41 |
42 | return "[ " + sb + "len=" + l.size() + " ]";
43 | }
44 | else if (val.isMap) {
45 | StringBuilder sb = new StringBuilder();
46 | Map d = val.asMap();
47 |
48 | Value[] keys = d.keySet().toArray(new Value[0]);
49 | for (int i = 0; i < keys.length; i++)
50 | if (i >= omitt && i < keys.length - omitt) {
51 | if (i == omitt + 1) sb.append("..., ");
52 | }
53 | else sb.append(ots(keys[i], true)).append(": ")
54 | .append(ots(d.get(keys[i]), true)).append(", ");
55 |
56 | return "{ " + sb + "len=" + keys.length + " }";
57 | }
58 | else if (val.isNull) {
59 | return "null";
60 | }
61 | else if (val.isString && stringInner) {
62 | return "\"" + val.asString() + "\"";
63 | }
64 | return val.asString();
65 | }
66 | return text.toString();
67 | }
68 |
69 | public void out(Object text) {
70 | if (log)
71 | System.out.print(ots(text));
72 | System.out.flush();
73 | }
74 |
75 | public void warn(Object text) {
76 | if (log)
77 | System.out.println(Chalk.on(
78 | getTape("WARNING") + "\n" + ots(text)
79 | ).yellow());
80 | }
81 |
82 | private String getTape(String message) {
83 | return String.join("", Collections.nCopies((tape - message.length()) / 2, " ")) + message + "\n" +
84 | String.join("", Collections.nCopies(tape, Shell.fileEncoding.equals("UTF-8") ? "─" : "_"));
85 | }
86 |
87 | public void fail(Object text) {
88 | if (log) {
89 | System.out.println(Chalk.on(
90 | getTape("FAILURE") + "\n" + ots(text)
91 | ).red());
92 | System.exit(1);
93 | }
94 | }
95 |
96 | public void tip(Object text) {
97 | if (log && tips)
98 | System.out.println(Chalk.on(
99 | getTape("TIP") + "\n" + ots(text)
100 | ).cyan());
101 | }
102 |
103 | public void outln(Object text) {
104 | if (log) System.out.println(ots(text));
105 | }
106 |
107 | public void disableLogging() { log = false; }
108 | public void enableLogging() { log = true; }
109 |
110 | public void enableTips() { tips = true; }
111 | public void disableTips() { tips = false; }
112 |
113 | public void debug(String format) {
114 | if (debug)
115 | System.out.print(Chalk.on(format).magenta());
116 | }
117 |
118 | public void debug(Value val) {
119 | if (debug)
120 | System.out.print(Chalk.on(ots(val)).magenta());
121 | }
122 |
123 | public String in() {
124 | return scanner.nextLine();
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/Operations.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | public enum Operations {
4 | BITCOMPL,
5 | BITAND,
6 | BITOR,
7 | BITXOR,
8 | LEFTSHIFT,
9 | RIGHTSHIFT,
10 | SIGNRIGHTSHIFT,
11 | BRACKET,
12 | NUMBER,
13 | DICTIONARY,
14 | ALIST,
15 | ASTRING,
16 | BOOL,
17 | ANULL,
18 | FUNCTION,
19 | DELETE,
20 | GET,
21 | ADD,
22 | SUB,
23 | MUL,
24 | DIV,
25 | MOD,
26 | FASTPOW,
27 | LTE,
28 | LT,
29 | ALSO,
30 | INCLUDING,
31 | INVERT,
32 | APPEND,
33 | EXTEND,
34 | POP,
35 | REMOVE,
36 | EXECUTE,
37 | EQ,
38 | NE,
39 | TOSTRING,
40 | COPY,
41 | TYPE,
42 | ACCESS,
43 | }
44 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/Pair.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | public class Pair {
4 | public T a;
5 | public X b;
6 | public Pair(T a, X b) {
7 | this.a = a;
8 | this.b = b;
9 | }
10 |
11 | public String toString() {
12 | return String.format("%s, %s", a, b);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/Position.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | public class Position {
4 | public int idx;
5 | public int ln;
6 | public int col;
7 | public int tcol = -1;
8 | public int tidx;
9 | public final String fn;
10 | public final String ftext;
11 |
12 | public Position(int idx, int ln, int col, String fn, String ftext) {
13 | this.idx = idx;
14 | this.ln = ln;
15 | this.col = col;
16 | this.fn = fn;
17 | this.ftext = ftext;
18 | }
19 |
20 | public Position setT(int tcol, int tidx) {
21 | this.tcol = tcol;
22 | this.tidx = tidx;
23 | return this;
24 | }
25 |
26 | public void advance(char current_char) {
27 | idx++;
28 | col++;
29 |
30 | if (current_char != '\t') {
31 | tcol++;
32 | tidx++;
33 | }
34 |
35 | if (current_char == Constants.splitter) {
36 | ln++;
37 | col = 0;
38 | tcol = 0;
39 | }
40 |
41 | }
42 |
43 | public Position advance() {
44 | idx++;
45 | col++;
46 | return this;
47 | }
48 |
49 | public Position copy() {
50 | return new Position(idx, ln, col, fn, ftext).setT(tcol, tidx);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/RunMain.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | public class RunMain {
4 | public static void main(String[] args) {
5 | Shell.main(new String[]{ "-c", "main.devp", "-r", "main.jbox" });
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/RunTest.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | import java.io.IOException;
4 |
5 | public class RunTest {
6 | public static void main(String[] args) {
7 | double start = System.currentTimeMillis();
8 | Shell.main("-c UnitTest.devp -r UnitTest.jbox".split(" "));
9 | double end = System.currentTimeMillis();
10 | Shell.logger.outln("Time: " + (end - start) + "ms");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/Tokens.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class Tokens {
7 | public static final Map TOKEY = new HashMap(){{
8 | put("[", TokenType.LeftBracket);
9 | put("\\", TokenType.Backslash);
10 | put("..", TokenType.DotDot);
11 | put("~~", TokenType.TildeTilde);
12 | put("~>", TokenType.RightTildeArrow);
13 | put("<~", TokenType.LeftTildeArrow);
14 | put("@", TokenType.At);
15 | put("~&", TokenType.TildeAmpersand);
16 | put("~|", TokenType.TildePipe);
17 | put("~^", TokenType.TildeCaret);
18 | put("~", TokenType.Tilde);
19 | put("<-", TokenType.LeftArrow);
20 | put("::", TokenType.ColonColon);
21 | put("%", TokenType.Percent);
22 | put("#", TokenType.Hash);
23 | put("]", TokenType.RightBracket);
24 | put(",", TokenType.Comma);
25 | put("+", TokenType.Plus);
26 | put("++", TokenType.PlusPlus);
27 | put("--", TokenType.MinusMinus);
28 | put(">>", TokenType.AngleAngle);
29 | put(":", TokenType.Colon);
30 | put("$", TokenType.DollarSign);
31 | put("$_", TokenType.DollarUnderscore);
32 | put("?", TokenType.QuestionMark);
33 | put("-", TokenType.Minus);
34 | put("*", TokenType.Star);
35 | put("/", TokenType.Slash);
36 | put("(", TokenType.LeftParen);
37 | put(")", TokenType.RightParen);
38 | put("^", TokenType.Caret);
39 | put("=>", TokenType.FatArrow);
40 | put("&", TokenType.Ampersand);
41 | put("|", TokenType.Pipe);
42 | put("->", TokenType.SkinnyArrow);
43 | put(";", TokenType.Newline);
44 | put("{", TokenType.LeftBrace);
45 | put("}", TokenType.RightBrace);
46 | put("^=", TokenType.CaretEquals);
47 | put("*=", TokenType.StarEquals);
48 | put("/=", TokenType.SlashEquals);
49 | put("+=", TokenType.PlusEquals);
50 | put("-=", TokenType.MinusEquals);
51 | put(".", TokenType.Dot);
52 | }};
53 | }
54 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/cases/Case.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.cases;
2 |
3 | import lemon.jpizza.nodes.Node;
4 |
5 | public class Case {
6 | public final boolean returnValue;
7 | public final Node condition;
8 | public final Node statements;
9 |
10 | public Case(Node condition, Node statements, boolean returnValue) {
11 | this.condition = condition;
12 | this.statements = statements;
13 | this.returnValue = returnValue;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/cases/ElseCase.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.cases;
2 |
3 | import lemon.jpizza.nodes.Node;
4 |
5 | public class ElseCase {
6 | public final boolean returnValue;
7 | public final Node statements;
8 |
9 | public ElseCase(Node statements, boolean returnValue) {
10 | this.statements = statements;
11 | this.returnValue = returnValue;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/Chunk.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | import lemon.jpizza.Constants;
4 | import lemon.jpizza.compiler.types.Type;
5 | import lemon.jpizza.compiler.values.Value;
6 | import lemon.jpizza.compiler.values.ValueArray;
7 |
8 | import java.util.*;
9 |
10 | public class Chunk {
11 | List code;
12 | public int[] codeArray;
13 | public String packageName;
14 | public String target;
15 | ValueArray constants;
16 | public List positions;
17 | final String source;
18 | public Map globals;
19 |
20 | public Chunk(String source) {
21 | this.code = new ArrayList<>();
22 | this.constants = new ValueArray();
23 | this.positions = new ArrayList<>(Collections.singletonList(new FlatPosition(0, 0, 0)));
24 | this.source = source;
25 | this.globals = new HashMap<>();
26 | }
27 |
28 | public void addGlobal(String name, Type type) {
29 | globals.put(name, type);
30 | }
31 |
32 | public void write(int b, int index, int len) {
33 | code.add(b);
34 |
35 | FlatPosition last = positions.get(positions.size() - 1);
36 | if (last.index == index && last.len == len) {
37 | last.span++;
38 | }
39 | else {
40 | positions.add(new FlatPosition(index, len, 1));
41 | }
42 | }
43 |
44 | public FlatPosition getPosition(int offset) {
45 | int i = 0;
46 | for (FlatPosition pos : positions) {
47 | if (i + pos.span >= offset) {
48 | return pos;
49 | }
50 | i += pos.span;
51 | }
52 | return positions.get(positions.size() - 1);
53 | }
54 |
55 | public void compile() {
56 | codeArray = new int[code.size()];
57 | for (int i = 0; i < code.size(); i++) {
58 | codeArray[i] = code.get(i);
59 | }
60 | constants.compile();
61 | }
62 |
63 | public int getLine(int offset) {
64 | return Constants.indexToLine(source, getPosition(offset).index);
65 | }
66 |
67 | public int addConstant(Value value) {
68 | return constants.write(value);
69 | }
70 |
71 | public String source() {
72 | return source;
73 | }
74 |
75 | public ValueArray constants() {
76 | return constants;
77 | }
78 | public void constants(ValueArray constants) {
79 | this.constants = constants;
80 | }
81 |
82 | public int[] dump() {
83 | List list = new ArrayList<>(Collections.singletonList(ChunkCode.Chunk));
84 | Value.addAllString(list, source);
85 | if (packageName != null) {
86 | Value.addAllString(list, packageName);
87 | }
88 | else {
89 | list.add(0);
90 | }
91 | if (target != null) {
92 | Value.addAllString(list, target);
93 | }
94 | else {
95 | list.add(0);
96 | }
97 | list.add(positions.size());
98 | for (FlatPosition pos : positions) {
99 | list.add(pos.index);
100 | list.add(pos.len);
101 | list.add(pos.span);
102 | }
103 | for (int i : constants().dump())
104 | list.add(i);
105 | list.add(globals.size());
106 | for (Map.Entry entry : globals.entrySet()) {
107 | Value.addAllString(list, entry.getKey());
108 | list.addAll(entry.getValue().dumpList());
109 | }
110 | list.add(codeArray.length);
111 | for (int i : codeArray)
112 | list.add(i);
113 | return list.stream().mapToInt(Integer::intValue).toArray();
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/ChunkCode.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | public class ChunkCode {
4 | public static final int Number = 0;
5 | public static final int Boolean = 1;
6 | public static final int String = 2;
7 | public static final int Enum = 3;
8 | public static final int EnumChild = 4;
9 | public static final int Func = 5;
10 | public static final int Type = 6;
11 | public static final int Chunk = 7;
12 | }
13 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/FlatPosition.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | public class FlatPosition {
4 | // The starting index of the token in the source file
5 | public final int index;
6 | // The number of characters after the index
7 | public final int len;
8 | // How many bytes this instruction takes
9 | public int span;
10 |
11 | public FlatPosition(int index, int len, int span) {
12 | this.index = index;
13 | this.len = len;
14 | this.span = span;
15 | }
16 |
17 | public String toString() {
18 | return "(" + index + "," + len + ")";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/FunctionType.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | public enum FunctionType {
4 | Function,
5 | Script,
6 | Method,
7 | Constructor,
8 | Scope,
9 | }
10 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/JStack.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | public class JStack {
4 | public int count;
5 | T[] stack;
6 | int top;
7 | int size;
8 |
9 | static int MAX = 5000;
10 | static double GROW_RATE = 1.5;
11 |
12 | public JStack(int size) {
13 | this.size = size;
14 | stack = (T[]) new Object[size];
15 | top = 0;
16 | }
17 |
18 | public void push(T t) {
19 | stack[top++] = t;
20 | count++;
21 | if (size - top < 32) {
22 | int newSize = (int) (size * GROW_RATE);
23 | T[] newStack = (T[]) new Object[newSize];
24 | System.arraycopy(stack, 0, newStack, 0, size);
25 | stack = newStack;
26 | size = newSize;
27 | }
28 | if (count > MAX) {
29 | throw new RuntimeException("Stack overflow");
30 | }
31 | }
32 |
33 | public T pop() {
34 | count--;
35 | return stack[--top];
36 | }
37 |
38 | public T peek() {
39 | return peek(0);
40 | }
41 |
42 | public T peek(int offset) {
43 | return stack[top - offset - 1];
44 | }
45 |
46 | public T get(int index) {
47 | return stack[index];
48 | }
49 |
50 | public void set(int index, T t) {
51 | stack[index] = t;
52 | }
53 |
54 | public void setTop(int top) {
55 | this.top = top;
56 | count = top;
57 | }
58 |
59 | public void clear() {
60 | top = 0;
61 | count = 0;
62 | for (int i = 0; i < size; i++) {
63 | stack[i] = null;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/OpCode.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler;
2 |
3 | public class OpCode {
4 | public static final int Return = 0x00;
5 | public static final int Constant = 0x01;
6 | public static final int Negate = 0x02;
7 | public static final int Increment = 0x03;
8 | public static final int Decrement = 0x04;
9 | public static final int Add = 0x05;
10 | public static final int Subtract = 0x06;
11 | public static final int Multiply = 0x07;
12 | public static final int Divide = 0x08;
13 | public static final int Modulo = 0x09;
14 | public static final int Power = 0x0A;
15 | public static final int Equal = 0x0B;
16 | public static final int LessThan = 0x0C;
17 | public static final int GreaterThan = 0x0D;
18 | public static final int Not = 0x0E;
19 | public static final int Pop = 0x0F;
20 | public static final int SetGlobal = 0x10;
21 | public static final int DefineGlobal = 0x11;
22 | public static final int GetGlobal = 0x12;
23 | public static final int GetLocal = 0x13;
24 | public static final int SetLocal = 0x14;
25 | public static final int Jump = 0x16;
26 | public static final int JumpIfFalse = 0x17;
27 | public static final int JumpIfTrue = 0x18;
28 | public static final int Loop = 0x19;
29 | public static final int For = 0x1A;
30 | public static final int StartCache = 0x1B;
31 | public static final int CollectLoop = 0x1C;
32 | public static final int FlushLoop = 0x1D;
33 | public static final int DefineLocal = 0x1E;
34 | public static final int Pattern = 0x1F;
35 | public static final int Call = 0x20;
36 | public static final int Closure = 0x21;
37 | public static final int GetUpvalue = 0x22;
38 | public static final int SetUpvalue = 0x23;
39 | public static final int MakeArray = 0x24;
40 | public static final int MakeMap = 0x25;
41 | public static final int Class = 0x26;
42 | public static final int Access = 0x27;
43 | public static final int Method = 0x28;
44 | public static final int MakeVar = 0x29;
45 | public static final int SetAttr = 0x2A;
46 | public static final int GetAttr = 0x2B;
47 | public static final int Index = 0x2C;
48 | public static final int Get = 0x2D;
49 | public static final int Null = 0x2E;
50 | public static final int Assert = 0x2F;
51 | public static final int Throw = 0x30;
52 | public static final int Import = 0x31;
53 | public static final int Enum = 0x32;
54 | public static final int BitAnd = 0x33;
55 | public static final int BitOr = 0x34;
56 | public static final int BitXor = 0x35;
57 | public static final int BitCompl = 0x36;
58 | public static final int LeftShift = 0x37;
59 | public static final int RightShift = 0x38;
60 | public static final int SignRightShift = 0x39;
61 | public static final int Copy = 0x3A;
62 | public static final int Iter = 0x3B;
63 | public static final int Spread = 0x3C;
64 | public static final int Ref = 0x3D;
65 | public static final int Deref = 0x3E;
66 | public static final int SetRef = 0x3F;
67 | public static final int ToBytes = 0x40;
68 | public static final int FromBytes = 0x41;
69 | public static final int Chain = 0x43;
70 | public static final int DropLocal = 0x44;
71 | public static final int DropGlobal = 0x45;
72 | public static final int DropUpvalue = 0x46;
73 | public static final int Header = 0x47;
74 | public static final int Destruct = 0x48;
75 | public static final int PatternVars = 0x49;
76 | public static final int Extend = 0x4B;
77 | }
78 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/headers/Cache.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.headers;
2 |
3 | import lemon.jpizza.compiler.values.Value;
4 |
5 | public class Cache {
6 | String name;
7 | Value[] args;
8 | Value result;
9 | public Cache(String name, Value[] args, Value result) {
10 | this.name = name;
11 | this.args = args;
12 | this.result = result;
13 | }
14 | public boolean equals(Object o) {
15 | if (o instanceof Cache) {
16 | Cache c = (Cache) o;
17 | if (!c.name.equals(name)) return false;
18 | if (c.args.length != args.length) return false;
19 | for (int i = 0; i < args.length; i++) {
20 | if (!c.args[i].equals(args[i])) return false;
21 | }
22 | return true;
23 | }
24 | return false;
25 | }
26 |
27 | public boolean equals(String name, Value[] args) {
28 | if (!this.name.equals(name)) return false;
29 | if (this.args.length != args.length) return false;
30 | for (int i = 0; i < args.length; i++) {
31 | if (!this.args[i].equals(args[i])) return false;
32 | }
33 | return true;
34 | }
35 |
36 | public Value getValue() {
37 | return result;
38 | }
39 |
40 | public void store(Value result) {
41 | this.result = result;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/headers/HeadCode.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.headers;
2 |
3 | public class HeadCode {
4 | public static final int Memoize = 0x0;
5 | public static final int SetMainFunction = 0x1;
6 | public static final int SetMainClass = 0x2;
7 | public static final int Export = 0x3;
8 | public static final int Package = 0x4;
9 | public static final int ExportTo = 0x5;
10 | }
11 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/headers/Memo.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.headers;
2 |
3 | import lemon.jpizza.compiler.values.Value;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Stack;
8 |
9 | public class Memo {
10 | List caches;
11 | Stack stack;
12 |
13 | public Memo() {
14 | this.caches = new ArrayList<>();
15 | this.stack = new Stack<>();
16 | }
17 |
18 | public void stackCache(String name, Value[] args) {
19 | Cache c = new Cache(name, args, null);
20 | caches.add(c);
21 | stack.add(c);
22 | }
23 |
24 | public void storeCache(Value result) {
25 | stack.pop().store(result);
26 | }
27 |
28 | public Value get(String key, Value[] args) {
29 | for (Cache cache : caches) {
30 | if (cache.equals(key, args)) {
31 | return cache.getValue();
32 | }
33 | }
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/libraries/GUIs.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.libraries;
2 |
3 | import lemon.jpizza.compiler.types.Types;
4 | import lemon.jpizza.compiler.vm.JPExtension;
5 | import lemon.jpizza.compiler.vm.VM;
6 |
7 | import javax.imageio.ImageIO;
8 | import javax.swing.*;
9 | import java.awt.*;
10 | import java.io.IOException;
11 | import java.net.URL;
12 |
13 | public class GUIs extends JPExtension {
14 |
15 | static JFrame frame;
16 |
17 | @Override
18 | public String name() { return "guis"; }
19 |
20 | public GUIs(VM vm) {
21 | super(vm);
22 | }
23 |
24 | @Override
25 | public void setup() {
26 |
27 | func("createGUI", (args) -> {
28 |
29 | frame = new JFrame(args[0].asString());
30 | frame.setTitle(args[0].asString());
31 | frame.setFocusTraversalKeysEnabled(false);
32 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33 |
34 | try {
35 | URL url = new URL("https://raw.githubusercontent.com/Lemon-Chad/jpizza/main/pizzico512.png");
36 | Image image = ImageIO.read(url);
37 | frame.setIconImage(image);
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | }
41 |
42 | return Ok;
43 | }, Types.VOID, Types.STRING);
44 |
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/libraries/Generators.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.libraries;
2 |
3 | import lemon.jpizza.compiler.types.Types;
4 | import lemon.jpizza.compiler.vm.JPExtension;
5 | import lemon.jpizza.compiler.vm.VM;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class Generators extends JPExtension {
11 | @Override
12 | public String name() { return "gens"; }
13 |
14 | public Generators(VM vm) {
15 | super(vm);
16 | }
17 |
18 | @Override
19 | public void setup() {
20 | func("range", (args) -> {
21 | double start = args[0].asNumber();
22 | double end = args[1].asNumber();
23 | double step = args[2].asNumber();
24 | List list = new ArrayList<>();
25 | for (double i = start; i < end; i += step)
26 | list.add(i);
27 | return Ok(list);
28 | }, Types.LIST, Types.FLOAT, Types.FLOAT, Types.FLOAT);
29 | func("linear", (args) -> {
30 | double start = args[0].asNumber();
31 | double end = args[1].asNumber();
32 | double step = args[2].asNumber();
33 |
34 | double m = args[3].asNumber();
35 | double b = args[4].asNumber();
36 |
37 | List list = new ArrayList<>();
38 | for (double i = start; i < end; i += step)
39 | list.add(m * i + b);
40 | return Ok(list);
41 | }, Types.LIST, Types.FLOAT, Types.FLOAT, Types.FLOAT, Types.FLOAT, Types.FLOAT);
42 | func("quadratic", (args) -> {
43 | double start = args[0].asNumber();
44 | double end = args[1].asNumber();
45 | double step = args[2].asNumber();
46 |
47 | double a = args[3].asNumber();
48 | double b = args[4].asNumber();
49 | double c = args[5].asNumber();
50 |
51 | List list = new ArrayList<>();
52 | for (double i = start; i < end; i += step)
53 | list.add(a * i * i + b * i + c);
54 | return Ok(list);
55 | }, Types.LIST, Types.FLOAT, Types.FLOAT, Types.FLOAT, Types.FLOAT, Types.FLOAT, Types.FLOAT);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/libraries/Time.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.libraries;
2 |
3 | import lemon.jpizza.compiler.types.GenericType;
4 | import lemon.jpizza.compiler.types.Type;
5 | import lemon.jpizza.compiler.types.Types;
6 | import lemon.jpizza.compiler.types.objects.FuncType;
7 | import lemon.jpizza.compiler.values.Value;
8 | import lemon.jpizza.compiler.values.functions.NativeResult;
9 | import lemon.jpizza.compiler.vm.JPExtension;
10 | import lemon.jpizza.compiler.vm.VM;
11 |
12 | public class Time extends JPExtension {
13 | @Override
14 | public String name() { return "time"; }
15 |
16 | public Time(VM vm) {
17 | super(vm);
18 | }
19 |
20 | @Override
21 | public void setup() {
22 | func("epoch", (args) -> Ok(System.currentTimeMillis()), Types.INT);
23 | func("halt", (args) -> {
24 | try {
25 | Thread.sleep(args[0].asNumber().intValue());
26 | } catch (InterruptedException e) {
27 | return Err("Internal", "Interrupted");
28 | }
29 | return Ok;
30 | }, Types.VOID, Types.INT);
31 | func("stopwatch", (args) -> {
32 | long start = System.currentTimeMillis();
33 | NativeResult ret = VM.Run(args[0].asClosure(), new Value[0]);
34 | if (!ret.ok()) return ret;
35 | long end = System.currentTimeMillis();
36 | return Ok(end - start);
37 | }, Types.INT, new FuncType(Types.VOID, new Type[0], new GenericType[0], false) );
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/jpizza/src/main/java/lemon/jpizza/compiler/libraries/awt/config/Canvas.java:
--------------------------------------------------------------------------------
1 | package lemon.jpizza.compiler.libraries.awt.config;
2 |
3 | import lemon.jpizza.compiler.libraries.awt.displays.Drawable;
4 | import lemon.jpizza.compiler.libraries.awt.displays.Rectangle;
5 |
6 | import javax.swing.*;
7 | import java.awt.*;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 | import java.util.Map;
11 | import java.util.Objects;
12 | import java.util.concurrent.ConcurrentHashMap;
13 |
14 | public class Canvas extends JPanel {
15 | Queue> drawings;
16 | Queue> colors;
17 | Queue