├── .circleci └── config.yml ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── recode_request.md ├── pull_request_template.md ├── stale.yml └── workflows │ └── gradle.yml ├── .gitignore ├── CONTRIBUTERS.md ├── CONTRIBUTING.md ├── IDEAS.md ├── LICENSE.md ├── README.md ├── VERSION.props ├── build.gradle ├── config └── ide.gradle ├── docs └── README.md ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── ready.sh ├── run.sh ├── settings.gradle ├── src └── com │ └── mani │ ├── compiler │ ├── ManiCompiler.java │ └── resources │ │ ├── main.mni │ │ └── summation.mni │ └── lang │ ├── Modules │ ├── Module.java │ ├── arrays │ │ ├── arrays.java │ │ ├── arrays_arrayAddItem.java │ │ ├── arrays_arrayPos.java │ │ ├── arrays_newArray.java │ │ └── arrays_reverseArray.java │ ├── atomic │ │ ├── atomic.java │ │ ├── atomic_boolean.java │ │ ├── atomic_boolean_compareSet.java │ │ ├── atomic_boolean_get.java │ │ ├── atomic_boolean_getSet.java │ │ ├── atomic_boolean_set.java │ │ ├── atomic_int.java │ │ ├── atomic_int_compareSet.java │ │ ├── atomic_int_get.java │ │ ├── atomic_int_getAdd.java │ │ └── atomic_int_set.java │ ├── datetime │ │ ├── datetime.java │ │ └── datetime_newDate.java │ ├── db │ │ └── db.java │ ├── downloader │ │ └── downloader.java │ ├── files │ │ ├── files.java │ │ ├── files_getPath.java │ │ ├── files_open.java │ │ ├── files_read.java │ │ └── files_write.java │ ├── flatmap │ │ └── flatmap.java │ ├── frame │ │ └── frame.java │ ├── functional │ │ ├── f_arrayForEach.java │ │ └── functional.java │ ├── http │ │ ├── http.java │ │ ├── http_download.java │ │ └── http_http.java │ ├── java │ │ └── java.java │ ├── json │ │ ├── json.java │ │ ├── json_encode.java │ │ └── json_parse.java │ ├── logger │ │ └── logger.java │ ├── maps │ │ ├── maps.java │ │ ├── maps_arraysToMap.java │ │ ├── maps_mapAddItem.java │ │ ├── maps_mapFind.java │ │ ├── maps_mapGetKeys.java │ │ ├── maps_mapGetValue.java │ │ ├── maps_mapGetValues.java │ │ ├── maps_mapKeyExists.java │ │ ├── maps_mapRemoveItem.java │ │ ├── maps_mapUpdateItem.java │ │ └── maps_newMap.java │ ├── math │ │ ├── math.java │ │ └── math_rand.java │ ├── munit │ │ ├── Tester.java │ │ └── munit.java │ ├── requests │ │ └── requests.java │ ├── sockets │ │ ├── new_socket.java │ │ └── sockets.java │ ├── std │ │ ├── std.java │ │ ├── std_ask.java │ │ ├── std_charAt.java │ │ ├── std_size.java │ │ ├── std_sleep.java │ │ ├── std_sort.java │ │ ├── std_toChar.java │ │ ├── std_toLowerCase.java │ │ ├── std_toString.java │ │ ├── std_toUpperCase.java │ │ └── std_trim.java │ ├── system │ │ └── system.java │ ├── threads │ │ └── threads.java │ ├── types │ │ └── types.java │ └── webSocket │ │ ├── webSocket.java │ │ └── webSocket_create.java │ ├── core │ ├── Expr.java │ ├── Interpreter.java │ ├── Lexer.java │ ├── Parser.java │ ├── Resolver.java │ └── Stmt.java │ ├── domain │ ├── ManiCallable.java │ ├── ManiCallableInternal.java │ ├── ManiClass.java │ ├── ManiFunction.java │ ├── ManiInstance.java │ └── Namespace.java │ ├── enviroment │ ├── Environment.java │ └── Inbuilt.java │ ├── exceptions │ ├── GeneralError.java │ ├── Return.java │ └── RuntimeError.java │ ├── language │ ├── French.java │ ├── German.java │ ├── Japanese.java │ ├── Lang.java │ └── Spanish.java │ ├── local │ ├── Locals.java │ └── Strings.java │ ├── main │ ├── Mani.java │ └── Std.java │ └── token │ ├── Token.java │ └── TokenType.java ├── stdlib ├── StringMaker.mni ├── entity.mni ├── files.mni ├── lists.mni ├── maps.mni ├── math.mni ├── screens.mni └── tester.mni ├── test ├── asOperator.mni ├── atomic.mni ├── basics.mni ├── errorScript.mni ├── files.mni ├── forEach.mni ├── import │ └── file_test_import.txt ├── lists.mni ├── maps.mni ├── math.mni ├── runTests.mni ├── runTestsOffline.mni ├── switchCase.mni └── testErrorOutputs.mni ├── testing └── tests.sh /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Java Gradle CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-java/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | # specify the version you desire here 10 | - image: circleci/openjdk:8-jdk 11 | 12 | # Specify service dependencies here if necessary 13 | # CircleCI maintains a library of pre-built images 14 | # documented at https://circleci.com/docs/2.0/circleci-images/ 15 | # - image: circleci/postgres:9.4 16 | 17 | working_directory: ~/repo 18 | 19 | environment: 20 | # Customize the JVM maximum heap limit 21 | JVM_OPTS: -Xmx3200m 22 | TERM: dumb 23 | 24 | steps: 25 | - checkout 26 | 27 | # Download and cache dependencies 28 | - restore_cache: 29 | keys: 30 | - v1-dependencies-{{ checksum "build.gradle" }} 31 | # fallback to using the latest cache if no exact match is found 32 | - v1-dependencies- 33 | 34 | - run: gradle dependencies 35 | 36 | - save_cache: 37 | paths: 38 | - ~/.gradle 39 | key: v1-dependencies-{{ checksum "build.gradle" }} 40 | 41 | # run tests! 42 | - run: ./tests.sh 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: crazywolf132 4 | patreon: # Replace with a single Patreon username 5 | open_collective: brayden-moon 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | custom: # Replace with a single custom sponsorship URL 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behaviour: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | Code to reproduce: 18 | 19 | 20 | **Expected behaviour** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Error** 24 | If applicable, please provide the full error. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. MACOS, WINDOWS, LINUX] 28 | - Version [e.g. MOJAVE, 10, ARCH] 29 | 30 | **Standard Library:** 31 | Were you using a standard library? 32 | - [] Yes 33 | - [] No 34 | If yes, what libraries? 35 | 36 | 37 | If applicable, did you have internet connection? 38 | - [] Yes 39 | - [] No 40 | 41 | **Additional context** 42 | Add any other context about the problem here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/recode_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Recode Request 3 | about: Used to ask for a recode of a function or a class 4 | 5 | --- 6 | 7 | **Name of the function or class, and location** 8 | Please provide a link from GitHub to the exact location. 9 | 10 | > Please paste link here. 11 | 12 | **Reason for a re-code** 13 | A clear and concise description of why this needs to be re-coded. 14 | 15 | > Reason here 16 | 17 | **Will this affect anything else in the system?** 18 | Please select one of the following: 19 | 20 | > - [ ] Yes 21 | > - [ ] No 22 | 23 | > If so, other file names or functions here. 24 | 25 | **Is the re-code required for any feature requests?** 26 | If so, please specify the feature request it applies to. 27 | 28 | > Feature request here. 29 | 30 | **Additional context** 31 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Added Feature 3 | about: I have added a feature to the language. 4 | --- 5 | 6 | **Is your PR related to a feature request or Bug report?** 7 | If applicable, please list feature request number or bug report ID. 8 | > Answer here. 9 | 10 | **Describe your PR** 11 | A clear and concise description of what your pull request is changing or adding. 12 | > Answer here. 13 | 14 | **Describe intended use** 15 | A clear and concise description of the intended use of the feature. Along with example code. 16 | > Answer here. 17 | 18 | **How did you fix the bug?** 19 | If applicable, how did you fix the bug? Please use code snippets too. 20 | > Answer here 21 | 22 | **Is it in the form of a library** 23 | - [] Yes 24 | - [] No 25 | 26 | If applicable what is the library called? 27 | > Answer here. 28 | 29 | **Does your PR replace an existing system** 30 | If applicable, please describe how this PR changes the use of a related item. 31 | > Answer here. 32 | 33 | **Additional comments** 34 | Add any additional comments or screenshots here. -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | # Label to use when marking as stale 4 | staleLabel: Stale 5 | 6 | # Comment to post when removing the stale label. Set to `false` to disable 7 | unmarkComment: false 8 | 9 | # Limit the number of actions per hour, from 1-30. Default is 30 10 | # limitPerRun: 30 11 | 12 | # Number of days of inactivity before an Issue or Pull Request becomes stale 13 | daysUntilStale: 30 14 | 15 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 16 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 17 | daysUntilClose: 14 18 | 19 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 20 | exemptLabels: 21 | - Good First Issue 22 | - Feature Request 23 | - Blocked 24 | - Bug 25 | 26 | # Set to true to ignore issues in a project (defaults to false) 27 | # exemptProjects: false 28 | 29 | # Set to true to ignore issues in a milestone (defaults to false) 30 | # exemptMilestones: false 31 | 32 | # Set to true to ignore issues with an assignee (defaults to false) 33 | exemptAssignees: true 34 | 35 | issues: 36 | # Comment to post when marking as stale. Set to `false` to disable 37 | markComment: > 38 | This issue has been automatically marked as stale because it has not had activity 39 | in a long time. If this issue is still relevant and should remain open, please reply 40 | with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___."). 41 | Thank you for your contributions. 42 | closeComment: > 43 | This issue has been automatically closed because it has not had 44 | activity in a long time. Please feel free to reopen it or create a new issue. 45 | pulls: 46 | # Comment to post when marking as stale. Set to `false` to disable 47 | markComment: > 48 | This pull request has been automatically marked as stale because it has not had recent 49 | activity, and will be closed if no further activity occurs. If this pull request was 50 | overlooked, forgotten, or should remain open for any other reason, please reply 51 | here to call attention to it and remove the stale status. 52 | Thank you for your contributions. 53 | closeComment: > 54 | This pull request has been automatically closed because it has not had 55 | activity in a long time. Please feel free to reopen it or create a new issue. -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Gradle 17 | run: ./gradlew build 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | ## *.jar 3 | .gradle 4 | 5 | ## Intellij 6 | .idea/ 7 | *.ipr 8 | *.iws 9 | *.iml 10 | out/ 11 | 12 | ## VSCODE 13 | .vscode/ 14 | 15 | # This prop file contains a sdk.dir meant to point to your local Android SDK 16 | local.properties 17 | 18 | ## Eclipse 19 | .classpath 20 | .project 21 | .metadata 22 | **/bin/ 23 | tmp/ 24 | *.tmp 25 | *.bak 26 | *.swp 27 | *~.nib 28 | 29 | .settings/ 30 | .loadpath 31 | .externalToolBuilders/ 32 | *.launch 33 | 34 | ## NetBeans 35 | **/nbproject/private/ 36 | build/ 37 | nbbuild/ 38 | dist/ 39 | nbdist/ 40 | nbactions.xml 41 | nb-configuration.xml 42 | 43 | ## OS Specific 44 | .DS_Store 45 | Icon 46 | ehthumbs.db 47 | Thumbs.db 48 | -------------------------------------------------------------------------------- /CONTRIBUTERS.md: -------------------------------------------------------------------------------- 1 | Need to create a rule for contributing. 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | ### Creating/taking issues 3 | When contributing to this repository, in most cases an issue should be used. If you are creating an issue, please stick to the **[issue creation templates](.github/ISSUE_TEMPLATE)**. 4 | Once you have created your issue or taken an existing issue, please leave a comment on it so other people know that it is being worked on. Similarly, if you decide to drop the issue, it is appreciated if you comment to let people know that it is avaiable again (also include any findings you may have that may help others to solve the issue) 5 | 6 | ### Committing 7 | When creating a commit, you should follow the standards below - [commit messages](#commit-messages). 8 | 9 | ### Raising pull requests 10 | After making the necessary changes, you can raise a pull request. Pull requests should follow the **[pull request templates](.github/PULL_REQUEST_TEMPLATE)** to make it easy to keep track of what is included in it. Pull requests should always succesfully build (unless specifically told otherwise) - this is to ensure the mainline is not broken for others who wish to use Máni or contribute to it. 11 | If a pull request includes tests and these tests do not pass, please ensure an issue is logged to make them pass. 12 | 13 | --- 14 | #### Commit messages 15 | To make it obvious what each commit includes and/or fixes, please stick to the following structure when writing the commit messages (take care to inlcude line spaces where shown) 16 | 17 | 18 | HEADER - #issueNo 19 | 20 | Detailed description of changes 21 | 22 | FOOTER 23 | 24 | - **HEADER** - The HEADER should be a short message describing the change (often the same as the issue name you are fixing) 25 | - e.g. Fix ClassCastException when opening file 26 | - **#issueNo** - The issueNo must be included if this commit is directly working on a logged issue - this is not always the case so is not always required. Not to be confused with pull request number 27 | - **Body of message** - The main body of the commit message should be a breif summary of why the change was needed and a description of what change was made. 28 | - e.g. Opening file was throwing ClassCastException - String cannot be cast to File. Updated file construction to take string as filename parameter. 29 | - **FOOTER** - The FOOTER should be included to link to any other issues that should also be fixed by your changes (e.g issues to make tests pass) or other issues it contributes to. 30 | - e.g. Fixes - "Opening file throws error" (#1) 31 | 32 | 33 | --- 34 | **If you have any questions about any of the procedures for contributing, please don't hesitate to contact us!** 35 | -------------------------------------------------------------------------------- /IDEAS.md: -------------------------------------------------------------------------------- 1 | # WELCOME TO THE IDEAS PAGE 2 | 3 | ## What is this? 4 | This is where we are adding ideas on how we plan to do the functions part of the system. 5 | 6 | ## What has been done so far? 7 | 8 | So far, when you create a list: 9 | ```JS 10 | let x = [1, 2, 3, 4, 5]; 11 | ``` 12 | you can use the `at()` function to get the element at a certain position. 13 | The code that runs this is in the `Inbuilt.java` file, around line 210. 14 | 15 | What happens is, the Interpreter goes through the code. And it finds the `.` 16 | then it checks to see if it is referencing a `ManiFunction` or not. 17 | 18 | The system used to return an error saying `Only instances have properties.`. We decided to change this. 19 | Rather than having lots of Standard libraries with functions that referenced the API's, (In my opinion, double handling). 20 | It now looks to see if there is a `Local` that suits what is beeing sort after. 21 | 22 | It checks the type of the Object being passed, then what the function name is. 23 | 24 | If it does not exist, it will return the same error as before. Otherwise it will run the code todo with that funciton. 25 | 26 | An example of a local is this: 27 | ```JAVA 28 | locals.put("posOf", new ManiCallableInternal() { 29 | @Override 30 | public int arity() { return 1; } //If you dont need any arguments. Dont include this. 31 | 32 | @Override 33 | public Object call(Interpreter interpreter, List arguments) { 34 | // Do your code here. 35 | return null; 36 | } 37 | }); 38 | ``` 39 | ### Whats the problem with this? 40 | Sure, everything may seem all well and good, but the problem is how it works. 41 | When the user defines something or imports an API (which all standard libraries do), all the variables get added to a big hashmap (dictionay, or object). 42 | This can be really bad if you dont want all the functions from the system to be added, as it could flood the map and make it slow. 43 | 44 | ### Whats the goal? 45 | The goal is to be able to create a system that is small and powerful. 46 | We want the end user to be able to use all of these features, but we dont want 47 | to flood the map with all of the functions if it doesnt have to be. 48 | 49 | ### Our current solution. 50 | Our current solution to this is with the API's. 51 | Each api can be imported with the following code: 52 | ```JS 53 | load "arrays"; 54 | ``` 55 | This will load the arrays API. This means it will only import the functions defined in that module. 56 | 57 | The only problem with this system is that it doesnt allow us to do extensions. 58 | The easiest way to explain what i mean by that is with a demonstration. 59 | 60 | With extensions: 61 | ```JS 62 | let x = [1, 2, "some string", 3, 4]; 63 | let y = x.at(2); // This is the example of the extension. (It just has a '.') 64 | say y; // prints: "some string" 65 | ``` 66 | 67 | Without extensions: 68 | ```JS 69 | let x = [1, 2, "some string", 3 4]; 70 | let y = arrayPos(x, 2); // This is what the API currently does. 71 | say y; // prints: "some string" 72 | ``` 73 | 74 | As we can see. The API creates an actual function to use, rather than a property of the original object. 75 | 76 | Its simply just not intuitive enough for any user. 77 | 78 | ## Possible solution to this mess. 79 | One possible solution i have been thinking about is. 80 | What if we edited the API's (modules) so that instead of creating another function like they do. 81 | Instead add the extensions. 82 | 83 | This could solve the problem of the loading them all, it could also solve the problem of the API's being too hard to learn. 84 | 85 | ### Why not just do this? 86 | In my opinion, there is a problem with this. If we do this, what is even the point in having an STDLIB built in mani? -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | Máni 4 |

5 |

Máni

6 | 7 | Version 1.3.0 8 | 9 | > An awesome, super simple language! 10 | 11 | * Simple and lightweight 12 | * No external dependencies 13 | * Straight recursive descent parser 14 | * Multi-language support 15 | 16 | [![](https://forthebadge.com/images/badges/built-by-codebabes.svg)](#) 17 | [![](https://forthebadge.com/images/badges/made-with-crayons.svg)](#) 18 | [![](https://forthebadge.com/images/badges/contains-technical-debt.svg)](#) 19 | [![](https://forthebadge.com/images/badges/check-it-out.svg)](#) 20 | 21 | 22 | ## What is it? 23 | Máni is an interpreted language that is simple to learn, and easy to use. 24 | 25 | The idea behind it is, take some of the good parts of other languages like nodejs, c++, python etc. 26 | Implement them into this, and try and build an "Alpha" language... if that is even a such thing. 27 | 28 | ## What Máni code looks like. 29 | ~~~ JS 30 | # "arrays"; 31 | 32 | class Vector { 33 | Vector(a, b, c) { 34 | this.x = a; 35 | this.y = b; 36 | this.z = c; 37 | } 38 | 39 | get() { 40 | return [this.x, this.y, this.z]; 41 | } 42 | 43 | add(v) { 44 | if (v is "list") { 45 | return Vector(this.x+v.at(0), this.y+v.at(1), this.z+v.at(2)); 46 | } else if (v is "number") { 47 | return Vector(this.x + v, this.y + v, this.z + v); 48 | } else if (v is "vector") { 49 | return Vector(this.x + v.x, this.y + v.y, this.z + v.z); 50 | } 51 | return nil; 52 | } 53 | 54 | show() { 55 | return "[" + this.x + "," + this.y +"," + this.z + "]"; 56 | } 57 | 58 | 59 | } 60 | 61 | let v1 = Vector(1, 2, 3); 62 | let v2 = Vector(4, 5, 6); 63 | let v3 = v1 + v2; 64 | 65 | say v1 + " + " + v2 + " = " + v3; 66 | ~~~ 67 | Checkout some more examples of Mani code and submit your own [here](https://github.com/Mani-Language/Mani-examples). 68 | 69 | ### Syntax highlighting 70 | | [**ATOM**](https://github.com/crazywolf132/Mani-Atom) | [**VSCODE**](https://github.com/crazywolf132/Mani-vscode) | 71 | |:----------------:|:----------------:| 72 | | [](https://atom.io) | [](https://code.visualstudio.com) | 73 | 74 | ## Team 75 | | [**Brayden Moon**](https://github.com/crazywolf132) | [**Joe Rickard**](https://github.com/Kalekdan) | [**Odin**](https://github.com/ManiOdin) | 76 | |:----------------:|:----------------:|:----------------:| 77 | | [](https://github.com/crazywolf132) | [](https://github.com/Kalekdan) | [](https://github.com/ManiOdin) | 78 | | Founder | Contributor | Faithful Builder | 79 | | [ Github](https://github.com/crazywolf132) | [ Github](https://github.com/Kalekdan) | [ Github](https://github.com/ManiOdin) | 80 | -------------------------------------------------------------------------------- /VERSION.props: -------------------------------------------------------------------------------- 1 | latest=1.3.0 2 | pacakge="" -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | println """ 2 | ******************************************* 3 | You are building Mani! 4 | Output files will be in /build/libs 5 | ******************************************* 6 | """ 7 | group 'Mani' 8 | version '1.0-SNAPSHOT' 9 | 10 | apply from: 'config/ide.gradle' 11 | 12 | apply plugin: 'java' 13 | apply plugin: 'application' 14 | apply plugin: 'idea' 15 | 16 | mainClassName = 'Mani' 17 | 18 | sourceSets.main.java.srcDirs = ['src'] 19 | 20 | sourceCompatibility = 1.8 21 | 22 | ext.buildNumber = System.getenv("BUILD_NUMBER") ?: "dev" 23 | version 'Stable' 24 | 25 | task start(type: JavaExec) { 26 | classpath sourceSets.main.runtimeClasspath 27 | main = "com.mani.lang.main.Mani" 28 | } 29 | 30 | task startCompiled(type: JavaExec) { 31 | classpath sourceSets.main.runtimeClasspath 32 | main = "com.mani.compiler.ManiCompiler" 33 | } 34 | 35 | jar { 36 | manifest { 37 | attributes 'Main-Class': 'com.mani.lang.main.Mani' 38 | } 39 | } 40 | 41 | task buildCompiler(type: Jar) { 42 | manifest { 43 | attributes 'Main-Class': 'com.mani.compiler.ManiCompiler' 44 | } 45 | from { 46 | configurations.compile.collect { 47 | it.isDirectory() ? it : zipTree(it) 48 | } 49 | } 50 | with jar 51 | sourceSets { 52 | main { 53 | resources { 54 | srcDirs "src/com/mani/compiler/resources" 55 | } 56 | } 57 | } 58 | } 59 | 60 | task fatJar(type: Jar) { 61 | version 'FatJar' 62 | manifest { 63 | attributes 'Main-Class': 'com.mani.lang.main.Mani' 64 | } 65 | from { 66 | configurations.compile.collect { 67 | it.isDirectory() ? it : zipTree(it) 68 | } 69 | } 70 | with jar 71 | sourceSets { 72 | main { 73 | into 'stdlib', { 74 | from 'stdlib' 75 | } 76 | } 77 | } 78 | } 79 | 80 | repositories { 81 | mavenCentral() 82 | } 83 | 84 | dependencies { 85 | compile fileTree(dir: 'libs', include: ['*.jar']) 86 | implementation 'com.google.code.gson:gson:2.8.5' 87 | implementation 'com.squareup.okhttp3:okhttp:3.14.0' 88 | compile 'org.mongodb:mongo-java-driver:2.12.3' 89 | compile 'io.socket:socket.io-client:1.0.0' 90 | compile 'com.neovisionaries:nv-websocket-client:2.8' 91 | } 92 | 93 | // For IntelliJ 94 | idea { 95 | module.excludeDirs += file('examples'); 96 | 97 | module.downloadSources = true 98 | 99 | project { 100 | // Set JDK 101 | jdkName = '1.8' 102 | wildcards -= '!?*.groovy' 103 | 104 | ipr { 105 | withXml { xmlProvider -> 106 | def iprNode = xmlProvider.asNode() 107 | ideaActivateCopyright(iprNode) 108 | ideaActivateGradle(iprNode) 109 | ideaActivateCopyright(iprNode) 110 | } 111 | 112 | whenMerged { project -> 113 | project.jdk.languageLevel = 'JDK_1_8' 114 | } 115 | } 116 | } 117 | 118 | workspace.iws.withXml { xmlProvider -> 119 | def iwsNode = xmlProvider.asNode() 120 | ideaMakeAutomatically(iwsNode) 121 | ideaRunConfig(iwsNode) 122 | } 123 | } 124 | 125 | cleanIdea.doLast { 126 | new File('Mani.iws').delete() 127 | new File('Mani.ipr').delete() 128 | new File('Mani.iml').delete() 129 | } 130 | 131 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Máni 2 | The docs is available at the [docs branch](https://github.com/mani-language/Mani/tree/docs). 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 20 14:10:23 AEDT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /ready.sh: -------------------------------------------------------------------------------- 1 | gradle clean 2 | cp -R ./stdlib/* ./docs/stdlib 3 | git add . 4 | clear 5 | echo "READY!" 6 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | gradle clean 2 | clear 3 | gradle build 4 | cp -r ./test/* ./build/libs 5 | cd ./build/libs 6 | clear 7 | java -jar Mani-Stable.jar 8 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user guide at https://docs.gradle.org/4.7/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'Mani' 11 | -------------------------------------------------------------------------------- /src/com/mani/compiler/ManiCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.compiler; 12 | 13 | import com.mani.lang.main.Mani; 14 | 15 | import java.io.BufferedReader; 16 | import java.io.IOException; 17 | import java.io.FileNotFoundException; 18 | import java.io.InputStream; 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.InputStreamReader; 22 | 23 | public class ManiCompiler { 24 | 25 | public static void main(String[] args) { 26 | // This is where we go through the internal resources folder. 27 | // Inside that there will be a settings file (Generated by Mani itself) 28 | // It will determine what file is to be executed first (Mani file) 29 | 30 | Mani.compiledMode = true; 31 | Mani.hasInternet = true; // To make it completely un-needed to have mani installed. 32 | 33 | String inputString = ""; 34 | try { 35 | ClassLoader classLoader = ManiCompiler.class.getClassLoader(); 36 | InputStream stream = classLoader.getResourceAsStream("main.mni"); 37 | /// InputStream stream = new FileInputStream(input); 38 | BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); 39 | // Loading the arguments first. 40 | inputString += "let args = ["; 41 | for (int i = 0; i < args.length; i++) { 42 | if (i != 0) { 43 | inputString += ","; 44 | } 45 | inputString += "\"" + args[i] + "\""; 46 | } 47 | inputString += "];\n"; 48 | 49 | String line = reader.readLine(); 50 | while (line != null) { 51 | inputString += line + "\n"; 52 | line = reader.readLine(); 53 | } 54 | } catch (FileNotFoundException e) { 55 | e.printStackTrace(); 56 | } 57 | catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | Mani.run(inputString, "main.mni"); 61 | } 62 | } -------------------------------------------------------------------------------- /src/com/mani/compiler/resources/main.mni: -------------------------------------------------------------------------------- 1 | # "maps"; 2 | # "lists"; 3 | load "summation.mni"; 4 | 5 | say addTogether(5, 2); 6 | 7 | let num1 = 1000000; 8 | let num2 = 1000000; 9 | 10 | let sum = num1 + num2; 11 | 12 | say sum; 13 | 14 | let myMap = Map(); 15 | myMap.add("keyName1","valueName1"); 16 | myMap.add("keyName2","valueName2"); 17 | say myMap.map; -------------------------------------------------------------------------------- /src/com/mani/compiler/resources/summation.mni: -------------------------------------------------------------------------------- 1 | fn addTogether(a, b) { 2 | return a + b; 3 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/Module.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | 15 | public interface Module { 16 | void init(Interpreter interpreter); 17 | 18 | boolean hasExtensions(); 19 | 20 | Object extensions(); 21 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/arrays/arrays_arrayAddItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.arrays; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public final class arrays_arrayAddItem implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (arguments.size() != 2) { 29 | return "Please provide an array, and what you wish to add as arguments."; 30 | } 31 | ArrayList arr = (ArrayList) arguments.get(0); 32 | arr.add(arguments.get(1)); 33 | return arr; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/arrays/arrays_arrayPos.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.arrays; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public final class arrays_arrayPos implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof ArrayList)) { 29 | return "Please provide an array and an object you're searching for!"; 30 | } 31 | double counter = 0; 32 | List arr = (List) arguments.get(0); 33 | for(Object obj : arr) { 34 | if (obj.equals(arguments.get(1))){ 35 | return counter; 36 | } 37 | counter += 1; 38 | } 39 | return null; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/arrays/arrays_newArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.arrays; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public final class arrays_newArray implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | return new ArrayList<>(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/arrays/arrays_reverseArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.arrays; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | public final class arrays_reverseArray implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | ArrayList arr = (ArrayList) arguments.get(0); 29 | ArrayList reversed = new ArrayList<>(); 30 | int arrSize = arr.size(); 31 | 32 | for (int i = 0; i < arrSize; i++) { 33 | reversed.add(arr.get(arrSize - i - 1)); 34 | } 35 | 36 | return reversed; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.Modules.Module; 15 | 16 | public final class atomic implements Module { 17 | 18 | @Override 19 | public void init(Interpreter interpreter) { 20 | // Everything for the atomic booleans 21 | interpreter.addSTD("AtomicBool", new atomic_boolean()); 22 | interpreter.addSTD("ABSet", new atomic_boolean_set()); 23 | interpreter.addSTD("ABCompareSet", new atomic_boolean_compareSet()); 24 | interpreter.addSTD("ABGetSet", new atomic_boolean_getSet()); 25 | interpreter.addSTD("ABGet", new atomic_boolean_get()); 26 | 27 | // Everything for the atomic integers 28 | interpreter.addSTD("AtomicInt", new atomic_int()); 29 | interpreter.addSTD("AISet", new atomic_int_set()); 30 | interpreter.addSTD("AICompareSet", new atomic_int_compareSet()); 31 | interpreter.addSTD("AIGet", new atomic_int_get()); 32 | interpreter.addSTD("AIGetAdd", new atomic_int_getAdd()); 33 | } 34 | 35 | @Override 36 | public boolean hasExtensions() { 37 | return false; 38 | } 39 | 40 | @Override 41 | public Object extensions() { 42 | return null; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_boolean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicBoolean; 18 | 19 | public final class atomic_boolean implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | return new AtomicBoolean(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_boolean_compareSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicBoolean; 18 | 19 | public final class atomic_boolean_compareSet implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 3; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments 30 | * 1 - The atomic boolean 31 | * 2 - The condition. 32 | * 3 - The value to set it to, if true. 33 | */ 34 | 35 | AtomicBoolean val = (AtomicBoolean) arguments.get(0); 36 | boolean stmt = (boolean) arguments.get(1); 37 | if (stmt) { 38 | val.set((boolean) arguments.get(2)); 39 | } 40 | return null; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_boolean_get.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicBoolean; 18 | 19 | public final class atomic_boolean_get implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The actual atomic Boolean. 31 | */ 32 | AtomicBoolean val = (AtomicBoolean) arguments.get(0); 33 | return val.get(); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_boolean_getSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicBoolean; 18 | 19 | public final class atomic_boolean_getSet implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The actual Atomic Boolean 31 | * 2 - What to set it too. 32 | */ 33 | 34 | boolean prev; 35 | AtomicBoolean current = (AtomicBoolean) arguments.get(0); 36 | prev = current.get(); 37 | current.set((boolean) arguments.get(1)); 38 | 39 | return prev; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_boolean_set.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicBoolean; 18 | 19 | public final class atomic_boolean_set implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The atomic boolean we are working with. 31 | * 2 - The Value we are setting it with. 32 | */ 33 | 34 | AtomicBoolean val = (AtomicBoolean) arguments.get(0); 35 | val.set((boolean)arguments.get(1)); 36 | 37 | return val; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_int.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public final class atomic_int implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | return new AtomicInteger(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_int_compareSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public final class atomic_int_compareSet implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 3; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The atomic Integer 31 | * 2 - Statement 32 | * 3 - What to set it to 33 | */ 34 | boolean usingBool = arguments.get(1) instanceof Boolean; 35 | boolean stmt; 36 | int Expected; 37 | 38 | AtomicInteger val = (AtomicInteger) arguments.get(0); 39 | Integer toSet = new Double( (Double) arguments.get(2)).intValue(); 40 | 41 | if (usingBool) { 42 | stmt = (boolean) arguments.get(1); 43 | if (stmt) { 44 | val.set(toSet); 45 | } 46 | } else { 47 | Expected = (Integer) arguments.get(1); 48 | val.compareAndSet(Expected, toSet); 49 | } 50 | 51 | return val; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_int_get.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public final class atomic_int_get implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The atomic int. 31 | */ 32 | AtomicInteger val = (AtomicInteger) arguments.get(0); 33 | return val.get(); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_int_getAdd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public final class atomic_int_getAdd implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 3; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The atomic int 31 | * 2 - Amount to add 32 | * 3 - Return prev 33 | */ 34 | 35 | AtomicInteger val = (AtomicInteger) arguments.get(0); 36 | Integer toAdd = new Double((Double) arguments.get(1)).intValue(); 37 | boolean returnPrev = (boolean) arguments.get(2); 38 | 39 | val.addAndGet(toAdd); 40 | 41 | // A cheat way we can do to return the previous... 42 | // is to minus the added from the current. 43 | if (returnPrev) { 44 | return val.get() - toAdd; 45 | } 46 | 47 | return val.get(); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/atomic/atomic_int_set.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.atomic; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.concurrent.atomic.AtomicInteger; 18 | 19 | public final class atomic_int_set implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | /** 29 | * Arguments: 30 | * 1 - The atomic int 31 | * 2 - What to set it to. 32 | */ 33 | 34 | AtomicInteger val = (AtomicInteger) arguments.get(0); 35 | val.set(new Double((Double) arguments.get(1)).intValue()); 36 | return null; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/datetime/datetime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.datetime; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.Modules.Module; 16 | 17 | import java.text.DateFormat; 18 | import java.util.Calendar; 19 | import java.util.List; 20 | 21 | public final class datetime implements Module { 22 | 23 | 24 | private void initConstants(Interpreter interpreter) { 25 | interpreter.define("STYLE_FULL", new Double(DateFormat.FULL)); 26 | interpreter.define("STYLE_LONG", new Double(DateFormat.LONG)); 27 | interpreter.define("STYLE_MEDIUM", new Double(DateFormat.MEDIUM)); 28 | interpreter.define("STYLE_SHORT", new Double(DateFormat.SHORT)); 29 | } 30 | 31 | @Override 32 | public void init(Interpreter interpreter) { 33 | initConstants(interpreter); 34 | interpreter.addSTD("DTnewDate", new datetime_newDate()); 35 | //interpreter.addSTD("DTnewFormat", new datetime_newFormat()); 36 | //interpreter.addSTD("DTFormatDate", new datetime_format()); 37 | //interpreter.addSTD("DTparseDate", new datetime_parseDate()); 38 | interpreter.addSTD("DTtoTimestamp", new ManiCallable(){ 39 | 40 | @Override 41 | public int arity() { 42 | return 1; 43 | } 44 | 45 | @Override 46 | public Object call(Interpreter interpreter, List arguments) { 47 | /** 48 | * Arguments: 49 | * 1 - The date object. 50 | */ 51 | return new Double(((Calendar) arguments.get(0)).getTimeInMillis()); 52 | } 53 | 54 | }); 55 | } 56 | 57 | @Override 58 | public boolean hasExtensions() { 59 | return false; 60 | } 61 | 62 | @Override 63 | public Object extensions() { 64 | return null; 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/datetime/datetime_newDate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.datetime; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.text.DateFormat; 17 | import java.text.SimpleDateFormat; 18 | import java.util.Calendar; 19 | import java.util.List; 20 | 21 | public final class datetime_newDate implements ManiCallable { 22 | 23 | @Override 24 | public int arity() { 25 | return -1; 26 | } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | final Calendar calendar = Calendar.getInstance(); 31 | calendar.clear(); 32 | switch(arguments.size()) { 33 | case 0: 34 | // date() 35 | calendar.setTimeInMillis(System.currentTimeMillis()); 36 | break; 37 | case 1: 38 | // date(timestamp) 39 | // date("date") 40 | date(calendar, arguments.get(0)); 41 | break; 42 | case 2: 43 | // date("pattern", "date") 44 | date(calendar, arguments.get(0), arguments.get(1)); 45 | break; 46 | case 3: 47 | case 4: 48 | // date(year, month, day) 49 | calendar.set( 50 | (new Double((Double) arguments.get(0)).intValue()), 51 | (new Double((Double) arguments.get(1)).intValue()), 52 | (new Double((Double) arguments.get(2)).intValue()) 53 | ); 54 | case 5: 55 | // date(year, month, day, hour, minute) 56 | calendar.set( 57 | (new Double((Double) arguments.get(0)).intValue()), 58 | (new Double((Double) arguments.get(1)).intValue()), 59 | (new Double((Double) arguments.get(2)).intValue()), 60 | (new Double((Double) arguments.get(3)).intValue()), 61 | (new Double((Double) arguments.get(4)).intValue()) 62 | 63 | ); 64 | case 6: 65 | default: 66 | // date(year, month, day, hour, minute, second) 67 | calendar.set( 68 | (new Double((Double) arguments.get(0)).intValue()), 69 | (new Double((Double) arguments.get(1)).intValue()), 70 | (new Double((Double) arguments.get(2)).intValue()), 71 | (new Double((Double) arguments.get(3)).intValue()), 72 | (new Double((Double) arguments.get(4)).intValue()), 73 | (new Double((Double) arguments.get(5)).intValue()) 74 | ); 75 | break; 76 | 77 | } 78 | return calendar; 79 | } 80 | 81 | private static void date(Calendar calendar, Object arg1) { 82 | if (arg1 instanceof Double) { 83 | calendar.setTimeInMillis(new Double((Double) arg1).longValue()); 84 | return; 85 | } 86 | try { 87 | calendar.setTime(DateFormat.getDateTimeInstance().parse(arg1.toString())); 88 | } catch (Exception ignore) { 89 | } 90 | } 91 | 92 | private static void date(Calendar calendar, Object arg1, Object arg2) { 93 | if (arg1 instanceof Double) { 94 | date(calendar, arg1); 95 | return; 96 | } 97 | try { 98 | calendar.setTime(new SimpleDateFormat(arg1.toString()).parse(arg2.toString())); 99 | } catch (Exception ignore) { 100 | } 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/db/db.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.db; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.Modules.Module; 16 | import com.mongodb.*; 17 | 18 | import java.net.UnknownHostException; 19 | import java.util.List; 20 | 21 | public class db implements Module { 22 | 23 | MongoClient cli; 24 | DB database = null; 25 | DBCollection collection = null; 26 | 27 | { 28 | try { 29 | cli = new MongoClient(); 30 | } catch (UnknownHostException e) { 31 | // We will say nothing, as we cannot assume the 32 | // user will use the default localhost for their mongo instance. 33 | } 34 | } 35 | 36 | @Override 37 | public void init(Interpreter interpreter) { 38 | interpreter.addSTD("db_connect", new ManiCallable() { 39 | @Override 40 | public int arity() { return 1; } 41 | 42 | @Override 43 | public Object call(Interpreter interpreter, List arguments) { 44 | try { 45 | cli = new MongoClient(new MongoClientURI((String) arguments.get(0))); 46 | return "Connected!"; 47 | } catch (UnknownHostException e) { 48 | return e.toString(); 49 | } 50 | } 51 | }); 52 | interpreter.addSTD("db_database", new ManiCallable() { 53 | @Override 54 | public int arity() { return 1; } 55 | 56 | @Override 57 | public Object call(Interpreter interpreter, List arguments) { 58 | cli.getDB((String) arguments.get(0)); 59 | return "Connected to " + arguments.get(0).toString(); 60 | } 61 | }); 62 | interpreter.addSTD("db_collection", new ManiCallable() { 63 | @Override 64 | public int arity() { return 1; } 65 | 66 | @Override 67 | public Object call(Interpreter interpreter, List arguments) { 68 | collection = database.getCollection((String) arguments.get(0)); 69 | return "Collection is: " + arguments.get(0).toString(); 70 | } 71 | }); 72 | interpreter.addSTD("db_insert", new ManiCallable() { 73 | @Override 74 | public int arity() { return 1; } 75 | 76 | @Override 77 | public Object call(Interpreter interpreter, List arguments) { 78 | if (arguments.get(0) instanceof DBObject) { 79 | collection.insert((DBObject) arguments.get(0)); 80 | return "Added"; 81 | } 82 | return "Sorry, you can only commit DB objects."; 83 | } 84 | }); 85 | } 86 | 87 | @Override 88 | public boolean hasExtensions() { 89 | return false; 90 | } 91 | 92 | @Override 93 | public Object extensions() { 94 | return null; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/downloader/downloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.downloader; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.domain.ManiFunction; 16 | import com.mani.lang.Modules.Module; 17 | import com.mani.lang.main.Mani; 18 | 19 | import javax.net.ssl.HttpsURLConnection; 20 | import java.io.*; 21 | import java.net.HttpURLConnection; 22 | import java.net.MalformedURLException; 23 | import java.net.ProtocolException; 24 | import java.net.URL; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | public class downloader implements Module { 29 | @Override 30 | public void init(Interpreter interpreter) { 31 | interpreter.addSTD("download", new ManiCallable() { 32 | @Override 33 | public int arity() { 34 | return -1; 35 | } 36 | 37 | @Override 38 | public Object call(Interpreter interpreter, List arguments) { 39 | if (!(arguments.size() >= 2)) { 40 | Mani.printAndStoreError("Must be atleast 2 arguments in downloader."); 41 | return null; 42 | } 43 | final String downloadURL = (String) arguments.get(0); 44 | final String path = (String) arguments.get(1); 45 | final ManiFunction callback; 46 | final double contentLength; 47 | if (arguments.size() == 3) { 48 | callback = (ManiFunction) arguments.get(2); 49 | contentLength = getContentLength(downloadURL); 50 | } else { 51 | callback = null; 52 | contentLength = -1; 53 | } 54 | final int bufferSize = (arguments.size() == 4) ? Math.max(1024, Integer.valueOf((Integer) arguments.get(3))) : 16384; 55 | final boolean calculateProgressEnabled = contentLength > 0 && callback != null; 56 | 57 | if (calculateProgressEnabled) { 58 | List db = new ArrayList<>(); 59 | db.add((double) 0); 60 | db.add((double) 0); 61 | db.add(contentLength); 62 | callback.call(interpreter, db); 63 | } 64 | 65 | try (InputStream is = new URL(downloadURL).openStream(); 66 | OutputStream os = new FileOutputStream(new File(path))) { 67 | int downloaded = 0; 68 | final byte[] buffer = new byte[bufferSize]; 69 | int read; 70 | 71 | while ((read = is.read(buffer, 0, bufferSize)) != -1) { 72 | os.write(buffer, 0, read); 73 | downloaded += read; 74 | if (calculateProgressEnabled) { 75 | final int percent = (int) (downloaded / ((double) contentLength) * 100.0); 76 | List db = new ArrayList<>(); 77 | db.add((double) percent); 78 | db.add((double) downloaded); 79 | db.add(contentLength); 80 | callback.call(interpreter, db); 81 | } 82 | } 83 | } catch (IOException ioe) { 84 | ioe.printStackTrace(); 85 | return (double) 0; 86 | } finally { 87 | if (callback != null) { 88 | List db = new ArrayList<>(); 89 | db.add(100d); 90 | db.add(contentLength); 91 | db.add(contentLength); 92 | callback.call(interpreter, db); 93 | } 94 | } 95 | 96 | return null; 97 | } 98 | }); 99 | interpreter.addSTD("urlExists", new ManiCallable() { 100 | @Override 101 | public int arity() { 102 | return 1; 103 | } 104 | 105 | @Override 106 | public Object call(Interpreter interpreter, List arguments) { 107 | try { 108 | URL u = new URL((String) arguments.get(0)); 109 | HttpURLConnection huc = (HttpURLConnection) u.openConnection(); 110 | HttpURLConnection.setFollowRedirects(false); 111 | huc.setRequestMethod("HEAD"); 112 | huc.connect(); 113 | return (huc.getResponseCode() == HttpURLConnection.HTTP_OK); 114 | } catch (IOException e) { 115 | e.printStackTrace(); 116 | } 117 | return null; 118 | } 119 | }); 120 | } 121 | 122 | private static int getContentLength(String url) { 123 | HttpURLConnection connection = null; 124 | try { 125 | connection = (HttpsURLConnection) new URL(url).openConnection(); 126 | connection.setRequestMethod("HEAD"); 127 | connection.connect(); 128 | return connection.getContentLength(); 129 | } catch (IOException ioe) { 130 | return -1; 131 | } finally { 132 | if (connection != null) { 133 | connection.disconnect(); 134 | } 135 | } 136 | } 137 | 138 | @Override 139 | public boolean hasExtensions() { 140 | return false; 141 | } 142 | 143 | @Override 144 | public Object extensions() { 145 | return null; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/files/files.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.files; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.domain.ManiCallableInternal; 16 | import com.mani.lang.Modules.Module; 17 | 18 | import java.io.File; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | 22 | public class files implements Module { 23 | 24 | @Override 25 | public void init(Interpreter interpreter) { 26 | interpreter.addSTD("fopen", new files_open()); 27 | interpreter.addSTD("fwrite", new files_write()); 28 | interpreter.addSTD("fread", new files_read()); 29 | interpreter.addSTD("fgetPath", new files_getPath()); 30 | } 31 | 32 | @Override 33 | public boolean hasExtensions() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public Object extensions() { 39 | HashMap> db = new HashMap<>(); 40 | HashMap locals = new HashMap<>(); 41 | 42 | locals.put("exists", new ManiCallableInternal() { 43 | @Override 44 | public Object call(Interpreter interpreter, List arguments) { 45 | return ((File) workWith).exists(); 46 | } 47 | }); 48 | 49 | locals.put("canWrite", new ManiCallableInternal() { 50 | @Override 51 | public Object call(Interpreter interpreter, List arguments) { 52 | return ((File) workWith).canWrite(); 53 | } 54 | }); 55 | 56 | locals.put("canRead", new ManiCallableInternal() { 57 | @Override 58 | public Object call(Interpreter interpreter, List arguments) { 59 | return ((File) workWith).canRead(); 60 | } 61 | }); 62 | 63 | locals.put("canExecute", new ManiCallableInternal() { 64 | @Override 65 | public Object call(Interpreter interpreter, List arguments) { 66 | return ((File) workWith).canExecute(); 67 | } 68 | }); 69 | 70 | db.put("file", locals); 71 | return db; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/files/files_getPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.files; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.io.File; 17 | import java.util.List; 18 | 19 | public class files_getPath implements ManiCallable { 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | return ((File) arguments.get(0)).getAbsolutePath(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/files/files_open.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.files; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.io.File; 17 | import java.util.List; 18 | 19 | public class files_open implements ManiCallable { 20 | 21 | /** 22 | * 1 - File name. 23 | */ 24 | @Override 25 | public int arity() { 26 | return 1; 27 | } 28 | 29 | @Override 30 | public Object call(Interpreter interpreter, List arguments) { 31 | final File fopen = new File(arguments.get(0).toString()); 32 | 33 | return fopen; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/files/files_read.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.files; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.io.File; 17 | import java.io.FileNotFoundException; 18 | import java.util.List; 19 | import java.util.Scanner; 20 | 21 | public class files_read implements ManiCallable { 22 | @Override 23 | public int arity() { 24 | return 1; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | try { 30 | String data = ""; 31 | File f = null; 32 | if (arguments.get(0) instanceof String) { 33 | f = new File((String)arguments.get(0)); 34 | } else if (arguments.get(0) instanceof File) { 35 | f = (File) arguments.get(0); 36 | } 37 | 38 | Scanner fscan = new Scanner(f); 39 | 40 | if (f.exists()) { 41 | while (fscan.hasNextLine()) { 42 | data += fscan.nextLine() + "\n"; 43 | } 44 | } 45 | 46 | return data; 47 | 48 | } catch (FileNotFoundException e) { 49 | return "File not found"; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/files/files_write.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.files; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.io.File; 17 | import java.io.FileOutputStream; 18 | import java.io.IOException; 19 | import java.io.PrintWriter; 20 | import java.util.List; 21 | 22 | public class files_write implements ManiCallable { 23 | 24 | /** 25 | * 1 - File object. 26 | * 2 - What we are writing. 27 | * 3 - true for append, false for write blank file 28 | */ 29 | @Override 30 | public int arity() { 31 | return 3; 32 | } 33 | 34 | @Override 35 | public Object call(Interpreter interpreter, List arguments) { 36 | File file = (File) arguments.get(0); 37 | 38 | try { 39 | PrintWriter pw = new PrintWriter(new FileOutputStream(file, (Boolean) arguments.get(2))); 40 | pw.write((String) arguments.get(1)); 41 | pw.flush(); 42 | pw.close(); 43 | } catch (IOException e) { 44 | return "Failed to load file."; 45 | } 46 | 47 | return file; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/flatmap/flatmap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.flatmap; 12 | 13 | import com.mani.lang.Modules.Module; 14 | import com.mani.lang.core.Interpreter; 15 | import com.mani.lang.domain.ManiCallable; 16 | import com.mani.lang.domain.ManiCallableInternal; 17 | import com.mani.lang.exceptions.GeneralError; 18 | 19 | import java.util.HashMap; 20 | import java.util.List; 21 | 22 | public class flatmap implements Module { 23 | @Override 24 | public void init(Interpreter interpreter) { 25 | interpreter.addSTD("flatMap", new ManiCallable() { 26 | @Override 27 | public int arity() { 28 | return 2; 29 | } 30 | 31 | @Override 32 | public Object call(Interpreter interpreter, List arguments) { 33 | if (!(arguments.get(0) instanceof Double && arguments.get(1) instanceof Double)) { 34 | throw new GeneralError("Arguments must be width and height in numbers!"); 35 | } 36 | int width = ((Double) arguments.get(0)).intValue(); 37 | int height = ((Double) arguments.get(1)).intValue(); 38 | return new FlatMap(width, height); 39 | } 40 | }); 41 | } 42 | 43 | @Override 44 | public boolean hasExtensions() { 45 | return true; 46 | } 47 | 48 | @Override 49 | public Object extensions() { 50 | HashMap> db = new HashMap<>(); 51 | HashMap locals = new HashMap<>(); 52 | 53 | locals.put("at", new ManiCallableInternal() { 54 | @Override 55 | public int arity() { 56 | return 2; 57 | } 58 | 59 | @Override 60 | public Object call(Interpreter interpreter, List arguments) { 61 | if (!(arguments.get(0) instanceof Double && arguments.get(1) instanceof Double)) { 62 | throw new GeneralError("Arguments must be x and y, in numbers!"); 63 | } 64 | int x = ((Double) arguments.get(0)).intValue(); 65 | int y = ((Double) arguments.get(1)).intValue(); 66 | return ((FlatMap) this.workWith).get(x, y); 67 | } 68 | }); 69 | 70 | locals.put("put", new ManiCallableInternal() { 71 | @Override 72 | public int arity() { 73 | return 3; 74 | } 75 | 76 | @Override 77 | public Object call(Interpreter interpreter, List arguments) { 78 | if (!(arguments.get(0) instanceof Double && arguments.get(1) instanceof Double)) { 79 | throw new GeneralError("Position arguments must be a number"); 80 | } 81 | 82 | int x = ((Double) arguments.get(0)).intValue(); 83 | int y = ((Double) arguments.get(1)).intValue(); 84 | Object obj = arguments.get(2); 85 | 86 | ((FlatMap) this.workWith).put(x, y, obj); 87 | return null; 88 | } 89 | }); 90 | 91 | db.put("flatmap", locals); 92 | return db; 93 | } 94 | 95 | public class FlatMap { 96 | int width; 97 | int height; 98 | Object[][] map; 99 | 100 | FlatMap(int width, int height) { 101 | this.width = width; 102 | this.height = height; 103 | this.map = new Object[this.width][this.height]; 104 | } 105 | 106 | public Object get(int x, int y) { 107 | return this.map[x][y]; 108 | } 109 | 110 | public void put(int x, int y, Object obj) { 111 | this.map[x][y] = obj; 112 | } 113 | } 114 | } 115 | 116 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/functional/f_arrayForEach.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.functional; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.domain.ManiFunction; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public final class f_arrayForEach implements ManiCallable { 21 | 22 | @Override 23 | public int arity() { 24 | return 2; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | if (arguments.size() != 2 || (arguments.size() == 2 && !(arguments.get(0) instanceof List && arguments.get(1) instanceof ManiFunction))) { 30 | return "Arguments must be array and function."; 31 | } 32 | ArrayList list = (ArrayList) arguments.get(0); 33 | ManiFunction run = (ManiFunction) arguments.get(1); 34 | for (Object obj : list) { 35 | List db = new ArrayList<>(); 36 | db.add(obj); 37 | run.call(interpreter, db); 38 | } 39 | return null; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/functional/functional.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.functional; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.Modules.Module; 15 | 16 | public final class functional implements Module { 17 | 18 | @Override 19 | public void init(Interpreter interpreter) { 20 | interpreter.addSTD("arrayForEach", new f_arrayForEach()); 21 | } 22 | 23 | @Override 24 | public boolean hasExtensions() { 25 | return false; 26 | } 27 | 28 | @Override 29 | public Object extensions() { 30 | return null; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/http/http.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.http; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class http implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 0; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/http/http_download.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.http; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | //import okhttp3.*; 19 | 20 | public final class http_download implements ManiCallable { 21 | 22 | @Override 23 | public int arity() { 24 | return 1; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | /*try { 30 | final Response response = client.newCall( 31 | new Request.Builder().url(arguments.get(0).toString()).build()) 32 | .execute() 33 | return response.body().bytes(); 34 | } catch (IOException ex) { 35 | return ex; 36 | }*/ 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/http/http_http.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.http; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | /*import java.util.Map; 18 | import okhttp3.FormBody; 19 | import okhttp3.MediaType; 20 | import okhttp3.OkHttpClient; 21 | import okhttp3.Request; 22 | import okhttp3.RequestBody; 23 | import okhttp3.Response; 24 | import okhttp3.internal.http.HttpMethod;*/ 25 | 26 | public final class http_http implements ManiCallable { 27 | 28 | @Override 29 | public int arity() { 30 | return 1; 31 | } 32 | 33 | @Override 34 | public Object call(Interpreter interpreter, List arguments) { 35 | /*try { 36 | final Response response = client.newCall( 37 | new Request.Builder().url(arguments.get(0).toString()).build()) 38 | .execute() 39 | return response.body().bytes(); 40 | } catch (IOException ex) { 41 | return ex; 42 | }*/ 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/java/java.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.java; 12 | 13 | import com.mani.lang.Modules.Module; 14 | import com.mani.lang.core.Interpreter; 15 | import com.mani.lang.domain.ManiCallable; 16 | 17 | import java.util.List; 18 | 19 | public class java implements Module { 20 | @Override 21 | public void init(Interpreter interpreter) { 22 | // interpreter.addSTD("newClass",); 23 | } 24 | 25 | 26 | 27 | private static class JavaClass { 28 | 29 | public final Class clazz; 30 | 31 | public JavaClass(Class clazz) { 32 | this.clazz = clazz; 33 | init(clazz); 34 | } 35 | 36 | private void init(Class clazz) { 37 | 38 | } 39 | } 40 | 41 | @Override 42 | public boolean hasExtensions() { 43 | return false; 44 | } 45 | 46 | @Override 47 | public Object extensions() { 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/json/json.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.json; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.Modules.Module; 15 | 16 | public final class json implements Module { 17 | 18 | @Override 19 | public void init(Interpreter interpreter) { 20 | interpreter.addSTD("json_parse", new json_parse()); 21 | interpreter.addSTD("json_encode", new json_encode()); 22 | } 23 | 24 | @Override 25 | public boolean hasExtensions() { 26 | return false; 27 | } 28 | 29 | @Override 30 | public Object extensions() { 31 | return null; 32 | } 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/json/json_encode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.json; 12 | 13 | import com.google.gson.Gson; 14 | import com.google.gson.JsonElement; 15 | import com.mani.lang.core.Interpreter; 16 | import com.mani.lang.domain.ManiCallable; 17 | 18 | import java.util.List; 19 | 20 | public class json_encode implements ManiCallable { 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | Gson gson = new Gson(); 29 | String str = gson.fromJson((JsonElement) arguments.get(0), String.class); 30 | return ""; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/json/json_parse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.json; 12 | 13 | import com.google.gson.Gson; 14 | import com.google.gson.GsonBuilder; 15 | import com.google.gson.reflect.TypeToken; 16 | import com.mani.lang.core.Interpreter; 17 | import com.mani.lang.domain.ManiCallable; 18 | 19 | import java.lang.reflect.Type; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | public final class json_parse implements ManiCallable { 24 | 25 | @Override 26 | public int arity() { 27 | return 1; 28 | } 29 | 30 | @Override 31 | public Object call(Interpreter interpreter, List arguments) { 32 | Gson gson = new GsonBuilder().create(); 33 | Type type = new TypeToken>(){}.getType(); 34 | Map theMap = gson.fromJson((String) arguments.get(0), type); 35 | return theMap; 36 | } 37 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallableInternal; 15 | import com.mani.lang.Modules.Module; 16 | 17 | import java.util.HashMap; 18 | import java.util.List; 19 | 20 | public final class maps implements Module { 21 | 22 | @Override 23 | public void init(Interpreter interpreter) { 24 | interpreter.addSTD("newMap", new maps_newMap()); 25 | interpreter.addSTD("mapGetValue", new maps_mapGetValue()); 26 | interpreter.addSTD("mapAddItem", new maps_mapAddItem()); 27 | interpreter.addSTD("mapRemoveItem", new maps_mapRemoveItem()); 28 | interpreter.addSTD("mapUpdateItem", new maps_mapUpdateItem()); 29 | interpreter.addSTD("mapGetKeys", new maps_mapGetKeys()); 30 | interpreter.addSTD("arraysToMap", new maps_arraysToMap()); 31 | interpreter.addSTD("mapKeyExists", new maps_mapKeyExists()); 32 | interpreter.addSTD("mapGetValues", new maps_mapGetValues()); 33 | interpreter.addSTD("mapFind", new maps_mapFind()); 34 | } 35 | 36 | @Override 37 | public boolean hasExtensions() { 38 | return true; 39 | } 40 | 41 | @Override 42 | public Object extensions() { 43 | HashMap> db = new HashMap<>(); 44 | HashMap locals = new HashMap<>(); 45 | 46 | locals.put("count", new ManiCallableInternal() { 47 | 48 | @Override 49 | public Object call(Interpreter interpreter, List arguments) { 50 | return (double) ((HashMap) this.workWith).size(); 51 | } 52 | }); 53 | 54 | locals.put("has", new ManiCallableInternal() { 55 | @Override 56 | public int arity() { return 1; } 57 | 58 | @Override 59 | public Object call(Interpreter interpreter, List arguments) { 60 | return ((HashMap) this.workWith).keySet().contains(arguments.get(0)); 61 | } 62 | }); 63 | 64 | locals.put("add", new ManiCallableInternal() { 65 | @Override 66 | public int arity() { return 2; } 67 | 68 | @Override 69 | public Object call(Interpreter interpreter, List arguments) { 70 | return ((HashMap) this.workWith).put(arguments.get(0), arguments.get(1)); 71 | } 72 | }); 73 | 74 | locals.put("del", new ManiCallableInternal() { 75 | @Override 76 | public int arity() { return 1; } 77 | 78 | @Override 79 | public Object call(Interpreter interpreter, List arguments) { 80 | return ((HashMap) this.workWith).remove(arguments.get(0)); 81 | } 82 | }); 83 | 84 | locals.put("at", new ManiCallableInternal() { 85 | @Override 86 | public int arity() { return 1; } 87 | 88 | @Override 89 | public Object call(Interpreter interpreter, List arguments) { 90 | return ((HashMap) this.workWith).get(arguments.get(0)); 91 | } 92 | }); 93 | 94 | db.put("map", locals); 95 | return db; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_arraysToMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.main.Mani; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | 21 | public final class maps_arraysToMap implements ManiCallable { 22 | 23 | @Override 24 | public int arity() { 25 | return 2; 26 | } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | if (!(arguments.get(0) instanceof ArrayList || arguments.get(1) instanceof ArrayList)) { 31 | return "Please provide 2 arrays as arguments."; 32 | } 33 | HashMap joined = new HashMap<>(); 34 | ArrayList first = (ArrayList) arguments.get(0); 35 | ArrayList second = (ArrayList) arguments.get(1); 36 | if (first.size() != second.size()) { 37 | Mani.printAndStoreError("Please make sure both arrays are the same size."); 38 | return "Please make sure both arrays are the same size."; 39 | } 40 | for (int i = 0; i < first.size(); i++) { 41 | joined.put(first.get(i), second.get(i)); 42 | } 43 | return joined; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapAddItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_mapAddItem implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 3; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof HashMap)) { 29 | return "Please make sure your first argument is a map."; 30 | } 31 | HashMap map = (HashMap) arguments.get(0); 32 | map.put(arguments.get(1), arguments.get(2)); 33 | return map; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapFind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | 20 | public final class maps_mapFind implements ManiCallable { 21 | 22 | @Override 23 | public int arity() { 24 | return 3; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | if (!(arguments.get(0) instanceof HashMap)) { 30 | return "Please make sure you have a map as your argument."; 31 | } else if (!(arguments.get(1) instanceof String)) { 32 | return "Please make sure you have a string as your key argument."; 33 | } 34 | 35 | HashMap> given = (HashMap>) arguments.get(0); 36 | Object keyParam = arguments.get(1); 37 | 38 | ArrayList keys = new ArrayList<>(); 39 | 40 | for (Object key : given.keySet()) { 41 | keys.add(key); 42 | } 43 | 44 | HashMap indexedValue; 45 | for (Object key : keys) { 46 | if (!(given.get(key) instanceof HashMap)) continue; 47 | indexedValue = given.get(key); 48 | if (indexedValue != null && indexedValue.get(keyParam) != null){ 49 | if (indexedValue.get(keyParam).equals(arguments.get(2))) return indexedValue; 50 | } 51 | } 52 | 53 | return null; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapGetKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | 20 | public final class maps_mapGetKeys implements ManiCallable { 21 | 22 | @Override 23 | public int arity() { 24 | return 1; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | if (!(arguments.get(0) instanceof HashMap)) { 30 | return "Please make sure you have a map as your argument."; 31 | } 32 | ArrayList keys = new ArrayList<>(); 33 | HashMap given = (HashMap) arguments.get(0); 34 | for (Object key : given.keySet()) { 35 | keys.add(key); 36 | } 37 | return keys; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapGetValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_mapGetValue implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof HashMap)) { 29 | return "Please provide a map as your first argument."; 30 | } 31 | HashMap map = (HashMap) arguments.get(0); 32 | if (map.containsKey(arguments.get(1))) { 33 | return map.get(arguments.get(1)); 34 | } 35 | return null; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapGetValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | 20 | public final class maps_mapGetValues implements ManiCallable { 21 | 22 | @Override 23 | public int arity() { 24 | return 1; 25 | } 26 | 27 | @Override 28 | public Object call(Interpreter interpreter, List arguments) { 29 | if (!(arguments.get(0) instanceof HashMap)) { 30 | return "Please make sure you have a map as your argument."; 31 | } 32 | ArrayList values = new ArrayList<>(); 33 | HashMap given = (HashMap) arguments.get(0); 34 | for (Object key : given.keySet()) { 35 | values.add(given.get(key)); 36 | } 37 | return values; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapKeyExists.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_mapKeyExists implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof HashMap)) { 29 | return "Please provide a map as the first argument."; 30 | } 31 | HashMap given = (HashMap) arguments.get(0); 32 | for (Object obj : given.keySet()) { 33 | if (obj.equals(arguments.get(1))) { 34 | return true; 35 | } 36 | } 37 | return false; 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapRemoveItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_mapRemoveItem implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 2; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof HashMap)) { 29 | return "Please use a map as your first argument."; 30 | } 31 | HashMap given = (HashMap) arguments.get(0); 32 | 33 | given.remove(arguments.get(1)); 34 | return given; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_mapUpdateItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_mapUpdateItem implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 3; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (!(arguments.get(0) instanceof HashMap)) { 29 | return "Please make sure your first argument is a map."; 30 | } 31 | HashMap map = (HashMap) arguments.get(0); 32 | if (map.containsKey(arguments.get(1))) { 33 | map.put(arguments.get(1), arguments.get(2)); 34 | return map; 35 | } 36 | return arguments.get(1).toString() + ", does not exist in the map."; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/maps/maps_newMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.maps; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public final class maps_newMap implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 0; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | return new HashMap<>(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/math/math.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.math; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.Modules.Module; 16 | 17 | import java.util.List; 18 | import java.util.function.DoubleBinaryOperator; 19 | import java.util.function.DoubleFunction; 20 | import java.util.function.DoubleUnaryOperator; 21 | 22 | public class math implements Module { 23 | 24 | private static final DoubleFunction doubleToNumber = Double::valueOf; 25 | 26 | @Override 27 | public void init(Interpreter interpreter) { 28 | // Defining common Math variables. 29 | interpreter.define("PI", Math.PI); 30 | interpreter.define("E", Math.E); 31 | 32 | // Defining the functions. 33 | interpreter.addSTD("rand", new math_rand()); 34 | interpreter.addSTD("acos", functionConvert(Math::acos)); 35 | interpreter.addSTD("asin", functionConvert(Math::asin)); 36 | interpreter.addSTD("atan", functionConvert(Math::atan)); 37 | interpreter.addSTD("atan2", biFunctionConvert(Math::atan2)); 38 | interpreter.addSTD("cbrt", functionConvert(Math::cbrt)); 39 | interpreter.addSTD("ceil", functionConvert(Math::ceil)); 40 | interpreter.addSTD("cos", functionConvert(Math::cos)); 41 | interpreter.addSTD("sin", functionConvert(Math::sin)); 42 | interpreter.addSTD("tan", functionConvert(Math::tan)); 43 | interpreter.addSTD("cosh", functionConvert(Math::cosh)); 44 | interpreter.addSTD("exp", functionConvert(Math::exp)); 45 | interpreter.addSTD("expm1", functionConvert(Math::expm1)); 46 | interpreter.addSTD("floor", functionConvert(Math::floor)); 47 | interpreter.addSTD("round", new ManiCallable() { 48 | @Override 49 | public int arity() { return 1; } 50 | 51 | @Override 52 | public Object call(Interpreter interpreter, List arguments) { 53 | return Math.round((Double) arguments.get(0)); 54 | } 55 | }); 56 | } 57 | 58 | private static ManiCallable functionConvert(DoubleUnaryOperator op) { 59 | return new ManiCallable() { 60 | @Override 61 | public int arity() { return 1; } 62 | 63 | @Override 64 | public Object call(Interpreter interpreter, List arguments) { 65 | return doubleToNumber.apply(op.applyAsDouble((double) arguments.get(0))); 66 | } 67 | }; 68 | } 69 | 70 | private static ManiCallable biFunctionConvert(DoubleBinaryOperator op) { 71 | return new ManiCallable() { 72 | @Override 73 | public int arity() { return 2; } 74 | 75 | @Override 76 | public Object call(Interpreter interpreter, List arguments) { 77 | return doubleToNumber.apply(op.applyAsDouble((double) arguments.get(0), (double) arguments.get(1))); 78 | } 79 | }; 80 | } 81 | 82 | @Override 83 | public boolean hasExtensions() { 84 | return false; 85 | } 86 | 87 | @Override 88 | public Object extensions() { 89 | return null; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/math/math_rand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.math; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.main.Std; 16 | 17 | import java.util.List; 18 | import java.util.Random; 19 | 20 | public class math_rand implements ManiCallable { 21 | @Override 22 | public int arity() { 23 | return -1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (arguments.size() > 2) { 29 | return "Too many arguments"; 30 | } 31 | 32 | Random rand = new Random(); 33 | 34 | if (arguments.size() == 1 && arguments.get(0) instanceof Double) { 35 | return Std.makeDouble(rand.nextInt( Std.DoubleToInt((Double) arguments.get(0)) )); 36 | } else if (arguments.size() == 1 && arguments.get(0) instanceof String) { 37 | Long to = Long.valueOf((String) ((String) arguments.get(0)).substring(1, ((String) arguments.get(0)).length() - 1)); 38 | Long from = 0L; 39 | final long randomLong = rand.nextLong() >>> 1; 40 | return (randomLong % (to - from) + from); 41 | } else if (arguments.size() == 2) { 42 | int max = new Double((Double) arguments.get(1)).intValue(); 43 | int min = new Double((Double) arguments.get(0)).intValue(); 44 | return Std.makeDouble(rand.nextInt(max - min + 1) + min); 45 | } 46 | 47 | return rand.nextDouble(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/munit/Tester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.munit; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class Tester { 17 | Tester() { } 18 | 19 | public String setHeader(String header) { 20 | this.header = header; 21 | return header; 22 | } 23 | 24 | public String setMessage(String message) { 25 | this.message = message; 26 | return message; 27 | } 28 | 29 | public boolean assertEquals(Object expected, Object actual) { 30 | this.testList.add(new Test(this.message, equals(expected, actual))); 31 | return equals(expected, actual); 32 | } 33 | 34 | public boolean assertEquals(Object expected, Object actual, String message) { 35 | this.message = message; 36 | return this.assertEquals(expected, actual); 37 | } 38 | 39 | public boolean assertTrue(Object expected) { 40 | boolean passed = expected.equals(true); 41 | this.testList.add(new Test(this.message, passed)); 42 | return passed; 43 | } 44 | 45 | public boolean assertTrue(Object expected, String message) { 46 | this.message = message; 47 | return this.assertTrue(expected); 48 | } 49 | 50 | public boolean assertFalse(Object expected) { 51 | boolean passed = expected.equals(false); 52 | this.testList.add(new Test(this.message, passed)); 53 | return passed; 54 | } 55 | 56 | public boolean assertFalse(Object expected, String message) { 57 | this.message = message; 58 | return this.assertFalse(expected); 59 | } 60 | 61 | private boolean equals(Object obj1, Object obj2) { 62 | if (obj1 == null) { 63 | return (obj2 == null); 64 | } 65 | return obj1.equals(obj2); 66 | } 67 | 68 | public boolean getResults() { 69 | for (Test test : testList) { 70 | this.count++; 71 | if (test.isPassed()) { 72 | this.passed++; 73 | } else { 74 | this.failed++; 75 | } 76 | } 77 | return display(); 78 | } 79 | 80 | private boolean display() { 81 | System.out.println((this.passed == this.count && this.failed == 0 ? " \u001B[102m\u001B[90m PASSED " : " \u001B[101m FAILED ") + "\u001B[0m\u001B[97m\u001B[1m " + this.header + "\u001B[49m\u001B[0m"); 82 | for (Test test : testList) { 83 | System.out.println(test); 84 | } 85 | if (this.passed != this.count && this.failed >= 0) { 86 | System.exit(1); 87 | } 88 | return (this.passed == this.count && this.failed == 0); 89 | } 90 | 91 | private int count = 0; 92 | private int passed = 0; 93 | private int failed = 0; 94 | private String message = ""; 95 | private String header = ""; 96 | private List testList = new ArrayList<>(); 97 | 98 | private static class Test { 99 | Test(String message, boolean passed) { 100 | this.message = message; 101 | this.passed = passed; 102 | } 103 | 104 | public boolean isPassed() { return passed; } 105 | public String getMessage() { return message; } 106 | 107 | public void setPassed(boolean passed) { this.passed = passed; } 108 | public void setMessage(String message) { this.message = message; } 109 | 110 | @Override 111 | public String toString() { 112 | return "\t" + (this.passed ? "\u001B[92m✔" : "\u001B[91m✘") + "\u001B[90m \"" + this.message + "\"\u001B[0m"; 113 | } 114 | 115 | private boolean passed; 116 | private String message; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/munit/munit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.munit; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallableInternal; 15 | import com.mani.lang.Modules.Module; 16 | import com.mani.lang.domain.ManiCallable; 17 | import com.mani.lang.local.Locals; 18 | 19 | import java.util.HashMap; 20 | import java.util.List; 21 | 22 | public class munit implements Module { 23 | 24 | @Override 25 | public void init(Interpreter interpreter) { 26 | interpreter.addSTD("newTester", new ManiCallable() { 27 | @Override 28 | public int arity() { return 0; } 29 | 30 | @Override 31 | public Object call(Interpreter interpreter, List arguments) { 32 | return new Tester(); 33 | } 34 | }); 35 | } 36 | 37 | @Override 38 | public boolean hasExtensions() { 39 | return true; 40 | } 41 | 42 | @Override 43 | public Object extensions() { 44 | HashMap> db = new HashMap<>(); 45 | HashMap locals = new HashMap<>(); 46 | 47 | locals.put("header", new ManiCallableInternal() { 48 | @Override 49 | public int arity() { return 1; } 50 | @Override 51 | public Object call(Interpreter interpreter, List arguments) { 52 | ((Tester) this.workWith).setHeader((String) arguments.get(0)); 53 | return null; 54 | } 55 | }); 56 | 57 | locals.put("assertEquals", new ManiCallableInternal() { 58 | @Override 59 | public int arity() { return 3; } 60 | @Override 61 | public Object call(Interpreter interpreter, List arguments) { 62 | ((Tester) this.workWith).assertEquals(arguments.get(0), arguments.get(1), (String) arguments.get(2)); 63 | return null; 64 | } 65 | }); 66 | 67 | locals.put("assertType", new ManiCallableInternal() { 68 | @Override 69 | public int arity() { return 3; } 70 | @Override 71 | public Object call(Interpreter interpreter, List arguments) { 72 | ((Tester) this.workWith).assertEquals(Locals.getType(arguments.get(0)), Locals.getType(arguments.get(1)), (String) arguments.get(2)); 73 | return null; 74 | } 75 | }); 76 | 77 | locals.put("assertTrue", new ManiCallableInternal() { 78 | @Override 79 | public int arity() { return 2; } 80 | @Override 81 | public Object call(Interpreter interpreter, List arguments) { 82 | ((Tester) this.workWith).assertTrue(arguments.get(0), (String) arguments.get(1)); 83 | return null; 84 | } 85 | }); 86 | 87 | locals.put("assertFalse", new ManiCallableInternal() { 88 | @Override 89 | public int arity() { return 2; } 90 | @Override 91 | public Object call(Interpreter interpreter, List arguments) { 92 | ((Tester) this.workWith).assertFalse(arguments.get(0), (String) arguments.get(1)); 93 | return null; 94 | } 95 | }); 96 | 97 | locals.put("results", new ManiCallableInternal() { 98 | @Override 99 | public Object call(Interpreter interpreter, List arguments) { 100 | ((Tester) this.workWith).getResults(); 101 | return null; 102 | } 103 | }); 104 | 105 | db.put("tester", locals); 106 | return db; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/sockets/new_socket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.sockets; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.main.Mani; 16 | import com.mani.lang.main.Std; 17 | import com.mani.lang.local.Locals; 18 | import io.socket.client.IO; 19 | 20 | import java.net.URISyntaxException; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | 24 | public class new_socket implements ManiCallable { 25 | @Override 26 | public int arity() { 27 | return -1; 28 | } 29 | 30 | @Override 31 | public Object call(Interpreter interpreter, List arguments) { 32 | try { 33 | final String url = arguments.get(0).toString(); 34 | if (arguments.size() == 1) { 35 | return IO.socket(url); 36 | } 37 | 38 | if (!(Locals.getType(arguments.get(1)).equals("map"))) { 39 | Mani.printAndStoreError("Map expected in second argument"); 40 | return null; 41 | } 42 | IO.Options options = parseOptions((HashMap) arguments.get(1)); 43 | return IO.socket(url, options); 44 | } catch (URISyntaxException ue) { 45 | return -1; 46 | } 47 | } 48 | 49 | private static IO.Options parseOptions(HashMap db) { 50 | final IO.Options result = new IO.Options(); 51 | 52 | if (db.containsKey("rememberUpgrade")) { result.rememberUpgrade = Std.DoubleToInt((Double) db.get("rememberUpgrade")) != 0; } 53 | if (db.containsKey("secure")) { result.secure = Std.DoubleToInt((Double) db.get("secure")) != 0; } 54 | if (db.containsKey("timestampRequests")) { result.timestampRequests = Std.DoubleToInt((Double) db.get("timestampRequests")) != 0; } 55 | if (db.containsKey("upgrade")) { result.upgrade = Std.DoubleToInt((Double) db.get("upgrade")) != 0; } 56 | 57 | if (db.containsKey("policyPort")) { result.policyPort = Std.DoubleToInt((Double) db.get("policyPort")); } 58 | if (db.containsKey("port")) { result.port = Std.DoubleToInt((Double) db.get("port")); } 59 | 60 | if (db.containsKey("host")) { result.host = String.valueOf(db.get("host")); } 61 | if (db.containsKey("hostname")) { result.hostname = String.valueOf(db.get("hostname")); } 62 | if (db.containsKey("path")) { result.path = String.valueOf(db.get("path")); } 63 | if (db.containsKey("query")) { result.query = String.valueOf(db.get("query")); } 64 | if (db.containsKey("timestampParam")) { result.timestampParam = String.valueOf(db.get("timestampParam")); } 65 | 66 | 67 | if (db.containsKey("transports")) { 68 | final List arr = (List) db.get("transports"); 69 | final String[] values = new String[((List) db.get("transports")).size()]; 70 | int index = 0; 71 | for (Object value : arr) { 72 | values[index++] = value.toString(); 73 | } 74 | result.transports = values; 75 | } 76 | 77 | return result; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/sockets/sockets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.sockets; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallableInternal; 15 | import com.mani.lang.domain.ManiFunction; 16 | import com.mani.lang.Modules.Module; 17 | import io.socket.client.Socket; 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | 23 | public class sockets implements Module { 24 | 25 | boolean logger = true; 26 | 27 | @Override 28 | public void init(Interpreter interpreter) { 29 | interpreter.define("EVENT_CONNECT", Socket.EVENT_CONNECT); 30 | interpreter.define("EVENT_CONNECTING", Socket.EVENT_CONNECTING); 31 | interpreter.define("EVENT_CONNECT_ERROR", Socket.EVENT_CONNECT_ERROR); 32 | interpreter.define("EVENT_CONNECT_TIMEOUT", Socket.EVENT_CONNECT_TIMEOUT); 33 | interpreter.define("EVENT_DISCONNECT", Socket.EVENT_DISCONNECT); 34 | interpreter.define("EVENT_ERROR", Socket.EVENT_ERROR); 35 | interpreter.define("EVENT_MESSAGE", Socket.EVENT_MESSAGE); 36 | interpreter.define("EVENT_PING", Socket.EVENT_PING); 37 | interpreter.define("EVENT_PONG", Socket.EVENT_PONG); 38 | interpreter.define("EVENT_RECONNECT", Socket.EVENT_RECONNECT); 39 | interpreter.define("EVENT_RECONNECTING", Socket.EVENT_RECONNECTING); 40 | interpreter.define("EVENT_RECONNECT_ATTEMPT", Socket.EVENT_RECONNECT_ATTEMPT); 41 | interpreter.define("EVENT_RECONNECT_ERROR", Socket.EVENT_RECONNECT_ERROR); 42 | interpreter.define("EVENT_RECONNECT_FAILED", Socket.EVENT_RECONNECT_FAILED); 43 | 44 | interpreter.addSTD("newSocket", new new_socket()); 45 | } 46 | 47 | @Override 48 | public boolean hasExtensions() { 49 | return true; 50 | } 51 | 52 | @Override 53 | public Object extensions() { 54 | HashMap> db = new HashMap<>(); 55 | HashMap locals = new HashMap<>(); 56 | 57 | locals.put("open", new ManiCallableInternal() { 58 | @Override 59 | public Object call(Interpreter interpreter, List arguments) { 60 | ((Socket) this.workWith).open(); 61 | if (logger) 62 | System.out.println("Connection opened"); 63 | return null; 64 | } 65 | }); 66 | 67 | locals.put("logging", new ManiCallableInternal() { 68 | @Override 69 | public int arity() { return 1; } 70 | 71 | @Override 72 | public Object call(Interpreter interpreter, List arguments) { 73 | if (arguments.get(0) instanceof Boolean) { 74 | logger = (boolean) arguments.get(0); 75 | } 76 | return null; 77 | } 78 | }); 79 | 80 | locals.put("id", new ManiCallableInternal() { 81 | @Override 82 | public Object call(Interpreter interpreter, List arguments) { 83 | return ((Socket) this.workWith).id(); 84 | } 85 | }); 86 | 87 | locals.put("on", new ManiCallableInternal() { 88 | @Override 89 | public int arity() { return 2; } 90 | @Override 91 | public Object call(Interpreter interpreter, List arguments) { 92 | final String event = arguments.get(0).toString(); 93 | final ManiFunction listener = (ManiFunction) arguments.get(1); 94 | 95 | ((Socket) this.workWith).on(event, sArgs -> { 96 | executeSocketListener(interpreter, listener, sArgs); 97 | }); 98 | return null; 99 | } 100 | }); 101 | 102 | locals.put("emit", new ManiCallableInternal() { 103 | @Override 104 | public int arity() { return 2; } 105 | @Override 106 | public Object call(Interpreter interpreter, List arguments) { 107 | final String event = arguments.get(0).toString(); 108 | final Object msg = arguments.get(1); 109 | ((Socket) this.workWith).emit(event, msg); 110 | return null; 111 | } 112 | }); 113 | 114 | locals.put("send", new ManiCallableInternal() { 115 | @Override 116 | public int arity() { return 1; } 117 | @Override 118 | public Object call(Interpreter interpreter, List arguments) { 119 | final Object msg = arguments.get(0); 120 | ((Socket) this.workWith).send(msg); 121 | return null; 122 | } 123 | }); 124 | 125 | locals.put("close", new ManiCallableInternal() { 126 | @Override 127 | public Object call(Interpreter interpreter, List arguments) { 128 | ((Socket) this.workWith).close(); 129 | return null; 130 | } 131 | }); 132 | 133 | db.put("socket", locals); 134 | return db; 135 | } 136 | 137 | private void executeSocketListener(Interpreter interpreter, ManiFunction listener, Object[] sArgs) { 138 | List args = new ArrayList<>(); 139 | if (sArgs == null) { 140 | listener.call(interpreter, args); 141 | } else { 142 | int size = sArgs.length; 143 | for (int i = 0; i < size; i++) { 144 | args.add(sArgs[i]); 145 | } 146 | listener.call(interpreter, args); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.domain.ManiFunction; 16 | import com.mani.lang.Modules.Module; 17 | import com.mani.lang.main.Mani; 18 | import com.mani.lang.main.Std; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Arrays; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | public final class std implements Module{ 26 | 27 | @Override 28 | public void init(Interpreter interpreter) { 29 | 30 | interpreter.define("ANSI_RESET", "\u001B[0m"); 31 | interpreter.define("ANSI_BLACK", "\u001B[30m"); 32 | interpreter.define("ANSI_RED", "\u001B[31m"); 33 | interpreter.define("ANSI_GREEN", "\u001B[32m"); 34 | interpreter.define("ANSI_YELLOW", "\u001B[33m"); 35 | interpreter.define("ANSI_BLUE", "\u001B[34m"); 36 | interpreter.define("ANSI_PURPLE", "\u001B[35m"); 37 | interpreter.define("ANSI_CYAN", "\u001B[36m"); 38 | interpreter.define("ANSI_WHITE", "\u001B[37m"); 39 | interpreter.define("NL", "\n"); 40 | interpreter.define("TAB", "\t"); 41 | 42 | interpreter.addSTD("toString", new std_toString()); 43 | interpreter.addSTD("toLowerCase", new std_toLowerCase()); 44 | interpreter.addSTD("toUpperCase", new std_toUpperCase()); 45 | interpreter.addSTD("charAt", new std_charAt()); 46 | interpreter.addSTD("sleep", new std_sleep()); 47 | interpreter.addSTD("sort", new std_sort()); 48 | interpreter.addSTD("trim", new std_trim()); 49 | interpreter.addSTD("toChar", new std_toChar()); 50 | interpreter.addSTD("size", new std_size()); 51 | interpreter.addSTD("time", new ManiCallable() { 52 | 53 | @Override 54 | public int arity() { 55 | return 0; 56 | } 57 | 58 | @Override 59 | public Object call(Interpreter interpreter, List arguments) { 60 | return Std.makeDouble((int) System.currentTimeMillis()); 61 | } 62 | }); 63 | interpreter.addSTD("find", new ManiCallable() { 64 | 65 | @Override 66 | public int arity() { 67 | return 1; 68 | } 69 | 70 | @Override 71 | public Object call(Interpreter interpreter, List arguments) { 72 | ManiFunction returned = interpreter.getFunction(arguments.get(0).toString()); 73 | returned.call(interpreter, arguments); 74 | return returned; 75 | } 76 | }); 77 | interpreter.addSTD("split", new ManiCallable() { 78 | @Override 79 | public int arity() { 80 | return 2; 81 | } 82 | 83 | @Override 84 | public Object call(Interpreter interpreter, List arguments) { 85 | String workWith = (String) arguments.get(0); 86 | String splitBy = (String) arguments.get(1); 87 | List list = new ArrayList(Arrays.asList(workWith.split(splitBy))); 88 | return list; 89 | } 90 | }); 91 | 92 | interpreter.addSTD("exit", new ManiCallable(){ 93 | 94 | @Override 95 | public int arity() { 96 | return 1; 97 | } 98 | 99 | @Override 100 | public Object call(Interpreter interpreter, List arguments) { 101 | System.exit(Std.DoubleToInt((double) arguments.get(0))); 102 | return null; 103 | } 104 | }); 105 | 106 | interpreter.addSTD("enviro", new ManiCallable() { 107 | 108 | @Override 109 | public int arity() { return 1; } 110 | 111 | @Override 112 | public Object call(Interpreter interpreter, List arguments) { 113 | Map db = System.getenv(); 114 | if (db.containsKey(arguments.get(0))) { 115 | return db.get(arguments.get(0)); 116 | } 117 | return null; 118 | } 119 | }); 120 | 121 | interpreter.addSTD("wipeMemory", new ManiCallable() { 122 | @Override 123 | public int arity() { 124 | return 0; 125 | } 126 | 127 | @Override 128 | public Object call(Interpreter interpreter, List arguments) { 129 | interpreter.wipeMemory(); 130 | Std.loaded.clear(); 131 | Mani.hadRuntimeError = false; 132 | return null; 133 | } 134 | }); 135 | } 136 | 137 | @Override 138 | public boolean hasExtensions() { 139 | return false; 140 | } 141 | 142 | @Override 143 | public Object extensions() { 144 | return null; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_ask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | import java.util.Scanner; 18 | 19 | public class std_ask implements ManiCallable { 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | String question = (String) arguments.get(0); 28 | Scanner input = new Scanner(System.in); 29 | System.out.print(question); 30 | Object result = input.next(); 31 | 32 | input.close(); 33 | input = null; 34 | 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_charAt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class std_charAt implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 2; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | if (arguments.size() == 2) { 28 | if (arguments.get(0) instanceof Double && arguments.get(1) instanceof String) { 29 | final String str = (String) arguments.get(1); 30 | final int in = new Double((Double) arguments.get(0)).intValue(); 31 | 32 | return str.charAt(in); 33 | 34 | } 35 | } 36 | return "Requires arguements: position, string"; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_size.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.main.Std; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | 21 | public final class std_size implements ManiCallable { 22 | 23 | @Override 24 | public int arity() { 25 | return 1; 26 | } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | switch(arguments.get(0).getClass().getSimpleName().toLowerCase()) { 31 | case "string": 32 | return Std.makeDouble(arguments.get(0).toString().length()); 33 | case "arraylist": 34 | case "list": 35 | ArrayList arrayGiven = (ArrayList) arguments.get(0); 36 | return Std.makeDouble(arrayGiven.size()); 37 | case "hashmap": 38 | HashMap given = (HashMap) arguments.get(0); 39 | return Std.makeDouble(given.size()); 40 | } 41 | return null; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_sleep.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.main.Std; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | 21 | public final class std_sleep implements ManiCallable { 22 | 23 | @Override 24 | public int arity() { 25 | return 1; 26 | } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | if (arguments.size() != 1 || (arguments.size() == 1 && !(arguments.get(0) instanceof Long))) { 31 | return "Requires long arguement to use."; 32 | } 33 | long num = ((Long) arguments.get(0)).longValue(); 34 | try{ 35 | Thread.sleep(num); 36 | } catch (InterruptedException e) { 37 | throw new RuntimeException("Exception: " + e.toString()); 38 | } 39 | return null; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_sort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.Collections; 17 | import java.util.List; 18 | 19 | public final class std_sort implements ManiCallable { 20 | 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | if (arguments.size() != 1) { 29 | return "Please provide 1 arguement with an array"; 30 | } 31 | if (arguments.get(0) instanceof String) { 32 | List db = (List) arguments.get(0); 33 | Collections.sort(db); 34 | return db; 35 | } else if (arguments.get(0) instanceof Double) { 36 | List db = (List) arguments.get(0); 37 | Collections.sort(db); 38 | } 39 | return "This function can only be used for String or Number arrays!"; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_toChar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * For converting an Ascii value to a character. 20 | */ 21 | public final class std_toChar implements ManiCallable { 22 | 23 | @Override 24 | public int arity() { 25 | return 1; 26 | } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | int num = new Double((double) arguments.get(0)).intValue(); 31 | return (char) num; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_toLowerCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class std_toLowerCase implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | if (arguments.size() != 1 || (arguments.size() == 1 && !(arguments.get(0) instanceof String))) { 28 | return "Requires string arguement to use."; 29 | } 30 | return arguments.get(0).toString().toLowerCase(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_toString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class std_toString implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | if (arguments.size() != 1) { 28 | return "Please provide atleast 1 argument to convert to string"; 29 | } 30 | return arguments.get(0).toString(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_toUpperCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class std_toUpperCase implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | if (arguments.size() != 1 || (arguments.size() == 1 && !(arguments.get(0) instanceof String))) { 28 | return "Requires string arguement to use."; 29 | } 30 | return arguments.get(0).toString().toUpperCase(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/std/std_trim.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.std; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | 16 | import java.util.List; 17 | 18 | public final class std_trim implements ManiCallable { 19 | 20 | @Override 21 | public int arity() { 22 | return 1; 23 | } 24 | 25 | @Override 26 | public Object call(Interpreter interpreter, List arguments) { 27 | if (arguments.size() != 1 || ( arguments.size() == 1 && !(arguments.get(0) instanceof String))) { 28 | return "Please provide 1 arguement, a string"; 29 | } 30 | return arguments.get(0).toString().trim(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/system/system.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.system; 12 | 13 | import com.mani.lang.Modules.Module; 14 | import com.mani.lang.core.Interpreter; 15 | import com.mani.lang.domain.ManiCallable; 16 | import com.mani.lang.main.Mani; 17 | import com.mani.lang.main.Std; 18 | 19 | import java.util.List; 20 | 21 | public class system implements Module { 22 | @Override 23 | public void init(Interpreter interpreter) { 24 | interpreter.addSTD("System.online", new ManiCallable() { 25 | @Override 26 | public int arity() { return 1; } 27 | 28 | @Override 29 | public Object call(Interpreter interpreter, List arguments) { 30 | if (!(arguments.get(0) instanceof Boolean)) { 31 | Mani.printAndStoreError("Argument must be true or false!"); 32 | return null; 33 | } 34 | Mani.hasInternet = (Boolean) arguments.get(0); 35 | return null; 36 | } 37 | }); 38 | 39 | interpreter.addSTD("System.compiled", new ManiCallable() { 40 | @Override 41 | public int arity() { return 1; } 42 | 43 | @Override 44 | public Object call(Interpreter interpreter, List arguments) { 45 | if (!(arguments.get(0) instanceof Boolean)) { 46 | Mani.printAndStoreError("Argument must be true or false!"); 47 | return null; 48 | } 49 | Mani.compiledMode = (Boolean) arguments.get(0); 50 | return null; 51 | } 52 | }); 53 | 54 | // interpreter.addSTD("stdlib_path", new ManiCallable() { 55 | // @Override 56 | // public int arity() { 57 | // return 1; 58 | // } 59 | // 60 | // @Override 61 | // public Object call(Interpreter interpreter, List arguments) { 62 | // if (!(arguments.get(0) instanceof String)) { 63 | // Mani.printAndStoreError("Argument must be a string!"); 64 | // return null; 65 | // } 66 | // Mani.stdlib_path = (String) arguments.get(0); 67 | // return true; 68 | // } 69 | // }); 70 | 71 | interpreter.addSTD("System.hadError", new ManiCallable() { 72 | @Override 73 | public int arity() { 74 | return 0; 75 | } 76 | 77 | @Override 78 | public Object call(Interpreter interpreter, List arguments) { 79 | return Mani.hadRuntimeError; 80 | } 81 | }); 82 | 83 | interpreter.addSTD("System.latestError", new ManiCallable() { 84 | @Override 85 | public int arity() { 86 | return 0; 87 | } 88 | 89 | @Override 90 | public Object call(Interpreter interpreter, List arguments) { 91 | return Mani.latestErrorMsg; 92 | } 93 | }); 94 | 95 | interpreter.addSTD("System.nanoTime", new ManiCallable() { 96 | @Override 97 | public int arity() { 98 | return 0; 99 | } 100 | 101 | @Override 102 | public Object call(Interpreter interpreter, List arguments) { 103 | return Std.makeDouble((int) System.currentTimeMillis()); 104 | } 105 | }); 106 | 107 | interpreter.addSTD("System.exit", new ManiCallable() { 108 | @Override 109 | public int arity() { 110 | return 1; 111 | } 112 | 113 | @Override 114 | public Object call(Interpreter interpreter, List arguments) { 115 | System.exit(Std.DoubleToInt((Double) arguments.get(0))); 116 | return null; 117 | } 118 | }); 119 | } 120 | 121 | @Override 122 | public boolean hasExtensions() { 123 | return false; 124 | } 125 | 126 | @Override 127 | public Object extensions() { 128 | return null; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/threads/threads.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.threads; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.mani.lang.domain.ManiCallableInternal; 16 | import com.mani.lang.domain.ManiFunction; 17 | import com.mani.lang.Modules.Module; 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | 23 | public class threads implements Module { 24 | @Override 25 | public void init(Interpreter interpreter) { 26 | interpreter.addSTD("thread", new ManiCallable() { 27 | @Override 28 | public int arity() { return 1; } 29 | 30 | @Override 31 | public Object call(Interpreter interpreter, List arguments) { 32 | ManiFunction callback = (ManiFunction) arguments.get(0); 33 | Thread thread = new Thread(() -> callback.call(interpreter, new ArrayList())); 34 | thread.start(); 35 | return thread; 36 | } 37 | }); 38 | 39 | interpreter.addSTD("sleep", new ManiCallable() { 40 | @Override 41 | public int arity() { 42 | return 1; 43 | } 44 | 45 | @Override 46 | public Object call(Interpreter interpreter, List arguments) { 47 | try { 48 | Thread.sleep(((Double) arguments.get(0)).longValue()); 49 | } catch (InterruptedException e) { 50 | Thread.currentThread().interrupt(); 51 | } 52 | return null; 53 | } 54 | }); 55 | } 56 | 57 | @Override 58 | public boolean hasExtensions() { 59 | return true; 60 | } 61 | 62 | @Override 63 | public Object extensions() { 64 | HashMap> db = new HashMap<>(); 65 | HashMap locals = new HashMap<>(); 66 | 67 | locals.put("sleep", new ManiCallableInternal(){ 68 | @Override 69 | public int arity() { return 1; } 70 | 71 | @Override 72 | public Object call(Interpreter interpreter, List arguments){ 73 | Thread thread = ((Thread) this.workWith); 74 | try { 75 | thread.sleep((Long) arguments.get(0)); 76 | } catch (InterruptedException e) { 77 | Thread.currentThread().interrupt(); 78 | } 79 | return null; 80 | } 81 | }); 82 | 83 | db.put("thread", locals); 84 | return db; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/mani/lang/Modules/webSocket/webSocket_create.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.Modules.webSocket; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallable; 15 | import com.neovisionaries.ws.client.WebSocketFactory; 16 | 17 | import java.io.IOException; 18 | import java.util.List; 19 | 20 | public class webSocket_create implements ManiCallable { 21 | @Override 22 | public int arity() { 23 | return 1; 24 | } 25 | 26 | @Override 27 | public Object call(Interpreter interpreter, List arguments) { 28 | WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(5000); 29 | try { 30 | return factory.createSocket((String) arguments.get(0)); 31 | } catch (IOException e) { 32 | return null; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mani/lang/domain/ManiCallable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | package com.mani.lang.domain; 11 | 12 | import com.mani.lang.core.Interpreter; 13 | 14 | import java.util.List; 15 | 16 | public interface ManiCallable { 17 | // arity is the amount of arguments the command needs. 18 | int arity(); 19 | Object call(Interpreter interpreter, List arguments); 20 | } -------------------------------------------------------------------------------- /src/com/mani/lang/domain/ManiCallableInternal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.domain; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | 15 | import java.util.List; 16 | 17 | /*public interface ManiCallableInternal { 18 | // arity is the amount of arguments the command needs. 19 | Object workWith = null; 20 | void setItem(Object item); 21 | int arity(); 22 | Object call(Interpreter interpreter, List arguments); 23 | }*/ 24 | 25 | public class ManiCallableInternal implements ManiCallable { 26 | 27 | public Object workWith = null; 28 | 29 | public void setItem(Object item) { 30 | this.workWith = item; 31 | } 32 | 33 | @Override 34 | public int arity() { 35 | return 0; 36 | } 37 | 38 | @Override 39 | public Object call(Interpreter interpreter, List arguments) { 40 | return null; 41 | } 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/domain/ManiClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.domain; 12 | 13 | import com.mani.lang.exceptions.RuntimeError; 14 | import com.mani.lang.token.Token; 15 | import com.mani.lang.core.Interpreter; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | public class ManiClass implements ManiCallable { 21 | public final String name; 22 | private final Map methods; 23 | final ManiClass superclass; 24 | 25 | public ManiClass(String name, ManiClass superclass, Map methods) { 26 | this.name = name; 27 | this.superclass = superclass; 28 | this.methods = methods; 29 | } 30 | 31 | public ManiFunction findMethod(ManiInstance instance, String name) { 32 | if(methods.containsKey(name)) return methods.get(name).bind(instance); 33 | 34 | if (superclass != null) { 35 | ManiFunction result = superclass.findMethod(instance, name); 36 | if (result != null && !result.isPrivate()) { 37 | return result; 38 | } else if (result != null && result.isPrivate()) { 39 | throw new RuntimeError(new Token(null, name, result, 0), "Sorry, this is a private function!"); 40 | } 41 | } 42 | 43 | return null; 44 | } 45 | 46 | public String getName() { 47 | return this.name; 48 | } 49 | 50 | @Override 51 | public int arity() { 52 | ManiFunction initializer = methods.get(name); 53 | if(initializer == null) return 0; 54 | return initializer.arity(); 55 | } 56 | 57 | @Override 58 | public Object call(Interpreter interpreter, List arguments) { 59 | ManiInstance instance = new ManiInstance(this); 60 | ManiFunction initializer = methods.get(name); 61 | if(initializer != null) initializer.bind(instance).call(interpreter, arguments); 62 | return instance; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return name; 68 | } 69 | } -------------------------------------------------------------------------------- /src/com/mani/lang/domain/ManiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.domain; 12 | 13 | import com.mani.lang.enviroment.Environment; 14 | import com.mani.lang.exceptions.Return; 15 | import com.mani.lang.core.Interpreter; 16 | import com.mani.lang.core.Stmt; 17 | 18 | import java.util.List; 19 | 20 | public class ManiFunction implements ManiCallable { 21 | private final Stmt.Function declaration; 22 | private final Environment closure; 23 | private final Boolean isInitializer; 24 | private final Boolean isPrivate; 25 | private final Boolean isDepreciated; 26 | 27 | public ManiFunction(Stmt.Function declaration, Environment closure, Boolean isInitializer, Boolean isPrivate, Boolean isDepreciated) { 28 | this.declaration = declaration; 29 | this.closure = closure; 30 | this.isInitializer = isInitializer; 31 | this.isPrivate = isPrivate; 32 | this.isDepreciated = isDepreciated; 33 | } 34 | 35 | ManiFunction bind(ManiInstance instance) { 36 | Environment environment = new Environment(closure); 37 | environment.define("this", instance); 38 | return new ManiFunction(declaration, environment, isInitializer, isPrivate, isDepreciated); 39 | } 40 | 41 | public Boolean isPrivate() { return this.isPrivate; } 42 | 43 | public Boolean isDepreciated() { return this.isDepreciated; } 44 | 45 | public String getName() { return this.declaration.name.lexeme; } 46 | 47 | @Override 48 | public Object call(Interpreter interpreter, List arguments) { 49 | 50 | Environment environment = new Environment(closure); 51 | for(int i = 0 ; i < declaration.parameters.size() ; i++) { 52 | environment.define(declaration.parameters.get(i).lexeme, arguments.get(i)); 53 | } 54 | 55 | 56 | try { 57 | interpreter.executeBlock(declaration.body, environment); 58 | } catch(Return returnValue) { 59 | if(isInitializer) return environment.getAt(0, "this"); 60 | return returnValue.value; 61 | } 62 | 63 | if(isInitializer) return environment.getAt(0, "this"); 64 | return null; 65 | } 66 | 67 | @Override 68 | public int arity() { 69 | return declaration.parameters.size(); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | final int prime = 31; 75 | int result = 1; 76 | result = prime * result + ((declaration == null) ? 0 : declaration.hashCode()); 77 | result = prime * result + ((closure == null) ? 0 : closure.hashCode()); 78 | result = prime * result + ((isInitializer == null) ? 0 : isInitializer.hashCode()); 79 | result = prime * result + ((isPrivate == null) ? 0 : isPrivate.hashCode()); 80 | return result; 81 | } 82 | 83 | @Override 84 | public boolean equals(Object obj) { 85 | if (this == obj) { 86 | return true; 87 | } 88 | if (obj == null) { 89 | return false; 90 | } 91 | if (getClass() != obj.getClass()) { 92 | return false; 93 | } 94 | ManiFunction other = (ManiFunction) obj; 95 | if (declaration.name == null) { 96 | if (other.declaration.name != null) { 97 | return false; 98 | } 99 | } else if (!declaration.name.equals(other.declaration.name)) { 100 | return false; 101 | } 102 | if (isPrivate == null) { 103 | if (other.isPrivate != null) { 104 | return false; 105 | } 106 | } else if (!isPrivate.equals(other.isPrivate)) { 107 | return false; 108 | } 109 | if (closure == null) { 110 | if (other.closure != null) { 111 | return false; 112 | } 113 | } else if (!closure.equals(other.closure)) { 114 | return false; 115 | } 116 | if (isInitializer == null) { 117 | if (other.isInitializer != null) { 118 | return false; 119 | } 120 | } else if (!isInitializer.equals(other.isInitializer)) { 121 | return false; 122 | } 123 | return this.arity() == other.arity(); 124 | } 125 | 126 | @Override 127 | public String toString() { 128 | return "" ; 129 | } 130 | } -------------------------------------------------------------------------------- /src/com/mani/lang/domain/ManiInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.domain; 12 | 13 | import com.mani.lang.exceptions.RuntimeError; 14 | import com.mani.lang.token.Token; 15 | import com.mani.lang.core.Interpreter; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | public class ManiInstance { 21 | 22 | private ManiClass klass; 23 | final private Map fields = new HashMap<>(); 24 | 25 | ManiInstance(ManiClass klass) { 26 | this.klass = klass; 27 | } 28 | 29 | public Object get(Token name) { 30 | if(fields.containsKey(name.lexeme)) { 31 | return fields.get(name.lexeme); 32 | } 33 | 34 | ManiFunction method = klass.findMethod(this, name.lexeme); 35 | if(method != null) return method; 36 | throw new RuntimeError(name, "Undefined Property '" + name.lexeme +"'."); 37 | } 38 | 39 | public String runShowFn(Interpreter inter) { 40 | return (String) this.klass.findMethod(this, "show").call(inter, null); 41 | } 42 | 43 | public boolean hasShowFn() { 44 | return this.klass.findMethod(this, "show") != null; 45 | } 46 | 47 | public boolean hasFunction(String functionName) { 48 | return this.klass.findMethod(this, functionName) != null; 49 | } 50 | 51 | public void set(Token name, Object value) { 52 | fields.put(name.lexeme, value); 53 | } 54 | 55 | public String getClassName() { 56 | return klass.getName(); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return klass.name + " instance"; 62 | } 63 | } -------------------------------------------------------------------------------- /src/com/mani/lang/domain/Namespace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.domain; 12 | 13 | public class Namespace { 14 | 15 | private String space; 16 | private String name; 17 | 18 | public Namespace(String space, String name) { 19 | this.space = space; 20 | this.name = name; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | final int prime = 31; 26 | int result = 1; 27 | result = prime * result + ((space == null) ? 0 : space.hashCode()); 28 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 29 | return result; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object obj) { 34 | if (this == obj) { 35 | return true; 36 | } 37 | if (obj == null) { 38 | return false; 39 | } 40 | if (getClass() != obj.getClass()) { 41 | return false; 42 | } 43 | Namespace other = (Namespace) obj; 44 | if (space == null) { 45 | if (other.space != null) { 46 | return false; 47 | } 48 | } else if (!space.equals(other.space)) { 49 | return false; 50 | } 51 | if (name == null) { 52 | if (other.name != null) { 53 | return false; 54 | } 55 | } else if (!name.equals(other.name)) { 56 | return false; 57 | } 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/mani/lang/enviroment/Inbuilt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.enviroment; 12 | 13 | import com.mani.lang.main.Mani; 14 | import com.mani.lang.main.Std; 15 | import com.mani.lang.core.Interpreter; 16 | import com.mani.lang.domain.ManiCallable; 17 | 18 | import java.io.IOException; 19 | import java.net.URL; 20 | import java.util.*; 21 | 22 | public class Inbuilt { 23 | 24 | /** 25 | * This file creates a list called "inBuilts" that contains functions / API's that can be used by the stdlib 26 | * This is loaded before anything else. 27 | */ 28 | 29 | 30 | public static Map inBuilts = new HashMap<>(); 31 | } 32 | -------------------------------------------------------------------------------- /src/com/mani/lang/exceptions/GeneralError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.exceptions; 12 | 13 | public class GeneralError extends RuntimeException { 14 | public GeneralError(String message) { 15 | super(message); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/mani/lang/exceptions/Return.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.exceptions; 12 | 13 | public class Return extends RuntimeException { 14 | public final Object value; 15 | 16 | public Return(Object value) { 17 | this.value = value; 18 | } 19 | 20 | public Return() { 21 | value = null; 22 | } 23 | } -------------------------------------------------------------------------------- /src/com/mani/lang/exceptions/RuntimeError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.exceptions; 12 | 13 | import com.mani.lang.token.Token; 14 | 15 | public class RuntimeError extends RuntimeException { 16 | public final Token token; 17 | public RuntimeError(Token token, String message) { 18 | super(message); 19 | this.token = token; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/mani/lang/language/French.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.language; 12 | 13 | import java.util.Map; 14 | 15 | public class French implements Lang { 16 | 17 | @Override 18 | public Object init(Map keywords) { 19 | keywords.put("say", "afficher"); 20 | keywords.put("break", "interrompre"); 21 | keywords.put("return", "retour"); 22 | keywords.put("class", "classe"); 23 | keywords.put("and", "et"); 24 | keywords.put("or", "ou"); 25 | keywords.put("false", "faux"); 26 | keywords.put("true", "vrais"); 27 | keywords.put("this", "ce"); 28 | keywords.put("loop", "boucle"); 29 | keywords.put("while", "tandis"); 30 | keywords.put("STRICT", "STRICT"); 31 | keywords.put("internal", "interne"); 32 | keywords.put("for", "pour"); 33 | keywords.put("else", "sinon"); 34 | keywords.put("if", "si"); 35 | keywords.put("nil", "n�ant"); 36 | keywords.put("let", "laisser"); 37 | keywords.put("load", "charger"); 38 | 39 | 40 | return keywords; 41 | } 42 | } -------------------------------------------------------------------------------- /src/com/mani/lang/language/German.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.language; 12 | 13 | import java.util.Map; 14 | 15 | public class German implements Lang { 16 | 17 | @Override 18 | public Object init(Map keywords) { 19 | keywords.put("say", "sagen"); 20 | keywords.put("break", "brechen"); 21 | keywords.put("return", "rückkehr"); 22 | keywords.put("class", "klasse"); 23 | keywords.put("and", "und"); 24 | keywords.put("or", "oder"); 25 | keywords.put("false", "falsch"); 26 | keywords.put("true", "wahr"); 27 | keywords.put("this", "diese"); 28 | keywords.put("loop", "schleife"); 29 | keywords.put("while", "während"); 30 | keywords.put("STRICT", "STRENG"); 31 | keywords.put("internal", "privatgelände"); 32 | keywords.put("for", "zum"); 33 | keywords.put("else", "sonst"); 34 | keywords.put("if", "ob"); 35 | keywords.put("nil", "null"); 36 | keywords.put("let", "lassen"); 37 | keywords.put("load", "belastung"); 38 | 39 | 40 | return keywords; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/mani/lang/language/Japanese.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.language; 12 | 13 | import java.util.Map; 14 | 15 | public class Japanese implements Lang { 16 | 17 | @Override 18 | public Object init(Map keywords) { 19 | keywords.put("say", "いう"); 20 | keywords.put("break", "ブレーク"); 21 | keywords.put("return", "戻る"); 22 | keywords.put("class", "クラス"); 23 | keywords.put("and", "そして"); 24 | keywords.put("or", "または"); 25 | keywords.put("false", "偽"); 26 | keywords.put("true", "本当の"); 27 | keywords.put("this", "この"); 28 | keywords.put("loop", "ループ"); 29 | keywords.put("while", "しながら"); 30 | keywords.put("STRICT", "厳格"); 31 | keywords.put("internal", "内部"); 32 | keywords.put("for", "にとって"); 33 | keywords.put("else", "さもないと"); 34 | keywords.put("if", "もし"); 35 | keywords.put("nil", "ヌル"); 36 | keywords.put("let", "セット"); 37 | keywords.put("load", "負荷"); 38 | 39 | 40 | return keywords; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/mani/lang/language/Lang.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.language; 12 | 13 | import java.util.Map; 14 | 15 | public interface Lang { 16 | // We are giving them a blank hashmap, to add the keys too. 17 | Object init(Map keywords); 18 | } 19 | -------------------------------------------------------------------------------- /src/com/mani/lang/language/Spanish.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.language; 12 | 13 | import java.util.Map; 14 | 15 | 16 | public class Spanish implements Lang { 17 | 18 | @Override 19 | public Object init(Map keywords) { 20 | keywords.put("say", "contar"); 21 | keywords.put("break", "descanso"); 22 | keywords.put("return", "regreso"); 23 | keywords.put("class", "clase"); 24 | keywords.put("and", "y"); 25 | keywords.put("or", "o"); 26 | keywords.put("false", "falso"); 27 | keywords.put("true", "cierto"); 28 | keywords.put("this", "esto"); 29 | keywords.put("loop", "lazo"); 30 | keywords.put("while", "mientras"); 31 | keywords.put("STRICT", "ESTRICTO"); 32 | keywords.put("internal", "privado"); 33 | keywords.put("for", "para"); 34 | keywords.put("if", "si"); 35 | keywords.put("nil", "null"); 36 | keywords.put("let", "dejar"); 37 | keywords.put("load", "carga"); 38 | 39 | 40 | return keywords; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/mani/lang/local/Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.local; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.domain.ManiCallableInternal; 15 | 16 | import java.util.HashMap; 17 | import java.util.List; 18 | 19 | public class Strings { 20 | 21 | public static HashMap locals = new HashMap<>(); 22 | 23 | static { 24 | //TODO: Needs to be moved to std module 25 | locals.put("startsWith", new ManiCallableInternal() { 26 | @Override 27 | public int arity() { return 1; } 28 | 29 | @Override 30 | public Object call(Interpreter interpreter, List arguments) { 31 | return ((String) arguments.get(0)).startsWith((String) arguments.get(0)); 32 | } 33 | }); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/mani/lang/main/Std.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.main; 12 | 13 | import com.mani.lang.core.Interpreter; 14 | import com.mani.lang.core.Lexer; 15 | import com.mani.lang.core.Parser; 16 | import com.mani.lang.core.Resolver; 17 | import com.mani.lang.core.Stmt; 18 | import com.mani.lang.token.Token; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.io.InputStreamReader; 24 | import java.net.URISyntaxException; 25 | import java.util.ArrayList; 26 | import java.util.Enumeration; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.jar.JarEntry; 31 | import java.util.jar.JarFile; 32 | 33 | public class Std { 34 | 35 | public static boolean hasRun = false; // This if for checking to see if we have search for STDLIBS 36 | public static Map std = new HashMap<>(); // This is the STDLIB paths 37 | public static List loaded = new ArrayList<>(); // This is the files used by STDLib 38 | public static List loadedFiles = new ArrayList<>(); // This is the files used in "load("blah");" 39 | 40 | 41 | public static void Load() { 42 | JarFile jarFile = null; 43 | try { 44 | jarFile = new JarFile(Mani.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); 45 | } catch (IOException e) { 46 | e.printStackTrace(); 47 | } catch (URISyntaxException e) { 48 | e.printStackTrace(); 49 | } 50 | Enumeration e = jarFile.entries(); // Gets the content of the jarfile 51 | while (e.hasMoreElements()) { 52 | JarEntry entry = e.nextElement(); 53 | String name = entry.getName(); 54 | if (!name.contains("stdlib") || !name.contains(".mni")) { // If file is .mni script and is stdlib then add it to list of stlib files 55 | continue; 56 | } 57 | std.put(name.substring(name.lastIndexOf('/') + 1, name.lastIndexOf('.')), name); 58 | } 59 | 60 | hasRun = true; 61 | } 62 | 63 | public static String find(String name) { 64 | if (name.contains(".")) name = name.substring(0, name.lastIndexOf(".")); 65 | if (!loaded.contains(name)){ 66 | loaded.add(name); 67 | if (std.containsKey(name)) { 68 | return std.get(name); 69 | } else { 70 | return "-1"; 71 | } 72 | } 73 | return "-2"; 74 | } 75 | 76 | public static int DoubleToInt(double item) { 77 | return new Double(item).intValue(); 78 | } 79 | 80 | public static Double makeDouble(int item) { 81 | return new Double(item); 82 | } 83 | 84 | public static String loadFromUrl(Interpreter interpreter, String f) { 85 | Lexer lexer = new Lexer(f.toString(), f); 86 | List tokens = lexer.scanTokens(); 87 | Parser parser = new Parser(tokens); 88 | List statements = parser.parse(); 89 | Resolver resolver = new Resolver(interpreter); 90 | resolver.resolve(statements); 91 | interpreter.interpret(statements); 92 | return "Should have worked!"; 93 | } 94 | 95 | public static String loadFile(Interpreter interpreter, String f) { 96 | try { 97 | ClassLoader classLoader = Mani.class.getClassLoader(); // Loads stdlib from directory within .jar file 98 | InputStream stream = classLoader.getResourceAsStream(f); 99 | BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); 100 | StringBuilder inputString = new StringBuilder(); 101 | String line = reader.readLine(); 102 | while (line != null) { 103 | inputString.append(line).append("\n"); 104 | line = reader.readLine(); 105 | } 106 | Lexer lexer = new Lexer(inputString.toString(), f); 107 | List tokens = lexer.scanTokens(); 108 | Parser parser = new Parser(tokens); 109 | List statements = parser.parse(); 110 | Resolver resolver = new Resolver(interpreter); 111 | resolver.resolve(statements); 112 | interpreter.interpret(statements); 113 | return "Should have worked!"; 114 | } catch (IOException e) { 115 | return "Oh shit!"; 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/com/mani/lang/token/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.token; 12 | 13 | public class Token { 14 | public final TokenType type; 15 | public final String lexeme; 16 | public final Object literal; 17 | public final int line; 18 | 19 | public String file = "~unknown file~"; 20 | 21 | public Token(TokenType type, String lexeme, Object literal, int line) { 22 | this.type = type; 23 | this.lexeme = lexeme; 24 | this.literal = literal; 25 | this.line = line; 26 | } 27 | public String toString() { 28 | return type + " " + lexeme + " " + literal; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/mani/lang/token/TokenType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 This source file is part of the Máni open source project 3 | * 4 | * Copyright (c) 2018 - 2019. 5 | * 6 | * Licensed under Mozilla Public License 2.0 7 | * 8 | * See https://github.com/mani-language/Mani/blob/master/LICENSE.md for license information. 9 | */ 10 | 11 | package com.mani.lang.token; 12 | public enum TokenType { 13 | 14 | //Single-character Tokens 15 | LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE, LEFT_SQUARE, RIGHT_SQUARE, COMMA, DOT, MINUS, PLUS, SEMICOLON, SLASH, 16 | STAR, PERCENT, IMPORT, COLON, 17 | 18 | //one or two character Tokens 19 | 20 | BANG, BANG_EQUAL, GREATER, GREATER_EQUAL, LESS, LESS_EQUAL, EQUAL, EQUAL_EQUAL, VAR_ARROW, 21 | 22 | // combined assignment ops 23 | PERCENT_ASSIGN, PLUS_ASSIGN, MINUS_ASSIGN, SLASH_ASSIGN, STAR_ASSIGN, PLUS_PLUS, MINUS_MINUS, ASSIGN_ARROW, STAR_STAR, 24 | 25 | //Literals 26 | IDENTIFIER, NUMBER, STRING, 27 | 28 | //KEYWORDS 29 | 30 | AND, CLASS, ELSE, FALSE, FN, FOR, IF, NIL, OR, PRINT, RETURN, SUPER, THIS, TRUE, LET, WHILE, LOOP, BREAK, INTERNAL, 31 | DEPRECIATED, LOAD, STRICT, IS, AS, MATCH, CASE, CHANGELANG, NAMESET, SWITCH, DEFAULT, 32 | 33 | //End 34 | EOF 35 | 36 | } 37 | -------------------------------------------------------------------------------- /stdlib/StringMaker.mni: -------------------------------------------------------------------------------- 1 | # "lists"; 2 | 3 | class StringMaker{ 4 | StringMaker() { 5 | this.strings = List(); 6 | } 7 | 8 | append(item) { 9 | if (item is "list") { 10 | for (string : item) { 11 | this.strings.add(string); 12 | } 13 | } else { 14 | this.strings.add(item); 15 | } 16 | } 17 | 18 | join(operator) { 19 | return this.strings.join(operator); 20 | } 21 | 22 | show() { 23 | this.strings.join(" "); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /stdlib/entity.mni: -------------------------------------------------------------------------------- 1 | class Entity { 2 | Entity(obj) { 3 | this.obj = obj; 4 | } 5 | 6 | get(item) { 7 | return this.obj.at(item); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /stdlib/files.mni: -------------------------------------------------------------------------------- 1 | load "files"; 2 | # "lists"; 3 | 4 | class File { 5 | File(filename) { 6 | this.filename = filename; 7 | this.file = nil; 8 | this.contents = nil; 9 | this.opened = false; 10 | } 11 | 12 | open() { 13 | // Opens the file for reading and writing 14 | this.file = fopen(this.filename); 15 | } 16 | 17 | read() { 18 | // Returns the contents of the file as a String 19 | this.contents = fread(this.filename); 20 | return this.contents; 21 | } 22 | 23 | toList() { 24 | // Returns the contents of the file as a list with 25 | // each line in the file as a separate list item 26 | let fileToList = List(); 27 | fileToList.direct(split(this.read(), "\n")); 28 | return fileToList.list; 29 | } 30 | 31 | write(lines) { 32 | // Overrites all existing data in the file and writes "lines" to it 33 | if (!(lines is "list" or lines is "string")) { 34 | say "Must be a string or list, please convert and try again!"; 35 | return; 36 | } 37 | fwrite(this.file, lines, false); 38 | } 39 | 40 | append(lines) { 41 | // Appends "lines" to the end of the file 42 | if (!(lines is "list" or lines is "string")) { 43 | say "Must be a string or list, please convert and try again!"; 44 | return; 45 | } 46 | fwrite(this.file, lines, true); 47 | } 48 | 49 | path() { 50 | return fgetPath(this.file); 51 | } 52 | 53 | exists() { 54 | return this.file.exists(); 55 | } 56 | 57 | canWrite() { 58 | return this.file.canWrite(); 59 | } 60 | 61 | canRead() { 62 | return this.file.canRead(); 63 | } 64 | 65 | canExecute() { 66 | return this.file.canExecute(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /stdlib/lists.mni: -------------------------------------------------------------------------------- 1 | load "arrays"; 2 | load "functional"; 3 | load "std"; 4 | 5 | class List { 6 | List() { 7 | this.list = []; 8 | } 9 | 10 | raw() { 11 | return this.list; 12 | } 13 | 14 | direct(object) { 15 | // This is used when you directly create a list through the API, and need to convert 16 | // it to a useable list (with the features a list item has...) 17 | this.list = object; 18 | } 19 | 20 | count() { 21 | return this.list.count(); 22 | } 23 | 24 | add(object) { 25 | // This is used when adding an object to the list... 26 | this.list.add(object); 27 | } 28 | 29 | addLots(arr) { 30 | arrayForEach(arr, this.add); 31 | } 32 | 33 | replace(position, value) { 34 | // Replaces the given item with the new value... 35 | this.list = array_replace(this.list, position, value); 36 | } 37 | 38 | del(position) { 39 | // This is used to remove a selected item from the list... 40 | this.list.del(position); 41 | } 42 | 43 | get(position) { 44 | // This is used to grab an object from the list... 45 | return this.list.at(position); 46 | } 47 | 48 | posOf(item) { 49 | return this.list.posOf(item); 50 | } 51 | 52 | snip(toPos) { 53 | this.list = this.list.snip(toPos); 54 | } 55 | 56 | reset() { 57 | // This is used for those times when you cant be bothered deleting each item of the list... 58 | this.list = []; 59 | } 60 | 61 | join(operator) { 62 | let res = ""; 63 | for (item : this.list) { 64 | res += item + "operator"; 65 | } 66 | return res; 67 | } 68 | 69 | trimEach() { 70 | // This is used to remove whitespace from a string... 71 | let length = size(this.list); 72 | for(let i = 0; i < length; i++) { 73 | let str = this.get(i); 74 | str = trim(str); 75 | this.replace(i , str); 76 | } 77 | } 78 | 79 | reverse() { 80 | return arrayReverse(this.list); 81 | } 82 | 83 | forEach(f) { 84 | // This function is used to iterate through the array, and execute a function everytime. 85 | arrayForEach(this.list, f): 86 | } 87 | 88 | show() { 89 | // For when you want to show your list... 90 | return this.list; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /stdlib/maps.mni: -------------------------------------------------------------------------------- 1 | load "maps"; 2 | load "std"; 3 | 4 | class Map { 5 | Map() { 6 | this.map = {}; 7 | } 8 | 9 | add(key, val) { 10 | mapAddItem(this.map, key, val); 11 | return this; 12 | } 13 | 14 | get(key) { 15 | return mapGetValue(this.map, key); 16 | } 17 | 18 | del(key) { 19 | return mapRemoveItem(this.map, key); 20 | } 21 | 22 | find(key, val) { 23 | return mapFind(this.map, key, val); 24 | } 25 | 26 | update(key, val) { 27 | return mapUpdateItem(this.map, key, val); 28 | } 29 | 30 | getValues() { 31 | return mapGetValues(this.map); 32 | } 33 | 34 | getKeys() { 35 | return mapGetKeys(this.map); 36 | } 37 | 38 | copy(newMap) { 39 | this.map = newMap.map; 40 | } 41 | 42 | size() { 43 | return size(this.map); 44 | } 45 | 46 | exists(key) { 47 | return mapKeyExists(this.map, key); 48 | } 49 | 50 | combine(list1, list2) { 51 | this.map = arraysToMap(list1.raw(), list2.raw()); 52 | } 53 | 54 | raw() { 55 | return this.map; 56 | } 57 | 58 | reset() { 59 | this.map = {}; 60 | } 61 | 62 | show() { 63 | /*let r = "{ "; 64 | for (key, val : this.map) { 65 | r += key; 66 | r += ": " 67 | r += val; 68 | r += ", " 69 | } 70 | r += "}"; 71 | return r;*/ 72 | return nil; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /stdlib/math.mni: -------------------------------------------------------------------------------- 1 | class _Math { 2 | _Math() { 3 | 4 | } 5 | 6 | pow(num, pow) { 7 | let holder = num; 8 | for (let i = 1; i <= pow; i++) { 9 | holder *= 10 | } 11 | return num; 12 | } 13 | } 14 | 15 | let Math = _Math(); -------------------------------------------------------------------------------- /stdlib/screens.mni: -------------------------------------------------------------------------------- 1 | load "frame"; 2 | load "std"; 3 | # "maps"; 4 | 5 | class Screen { 6 | Screen(title) { 7 | this.title = title; 8 | this.frame = window(title); 9 | this.showing = false; 10 | this.components = Map(); 11 | this.setup(); 12 | } 13 | 14 | internal setup() { 15 | let btnMap = Map(); 16 | this.components.add("btn", btnMap); 17 | } 18 | 19 | toggle() { 20 | if (!this.showing) { 21 | this.showing = true; 22 | } else { 23 | this.showing = false; 24 | } 25 | windowVis(this.showing); 26 | } 27 | 28 | addBasicBtn(title) { 29 | let pos <- size(this.components.get("btn")); 30 | let btn = this.addBtn(title, 0, 0, 100, 100); 31 | return btn; 32 | } 33 | 34 | addBtn(title, x, y, width, height) { 35 | let btn = Button(title, x, y, width, height); 36 | this.components.get("btn").add(title, btn); 37 | return btn.raw(); 38 | } 39 | 40 | showMap() { 41 | return this.components; 42 | } 43 | } 44 | 45 | class Button { 46 | Button(title, x, y, w, h) { 47 | this.title = title; 48 | this.x = x; 49 | this.y = y; 50 | this.w = w; 51 | this.h = h; 52 | this.button = windowButton(title, x, y, w, h); 53 | this.showing = false; 54 | } 55 | 56 | show() { 57 | this.showing = buttonVis(this.button, this.showing); 58 | } 59 | 60 | raw() { 61 | return this.button; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /stdlib/tester.mni: -------------------------------------------------------------------------------- 1 | load "std"; 2 | 3 | class Tester { 4 | Tester() { 5 | this.passed = 0; 6 | this.run = 0; 7 | this.quitOnFail = true; 8 | this.override = false; 9 | this.setup(); 10 | } 11 | 12 | internal setup() { 13 | if (enviro("PRODUCTION") != nil and enviro("PRODUCTION") == "true") { 14 | this.override = true; 15 | } 16 | } 17 | 18 | msg(message) { 19 | say "TASK: " + message; 20 | } 21 | 22 | match(item, shouldBe) { 23 | this.run++; 24 | this.printResult(item == shouldBe); 25 | } 26 | 27 | matchType(item, shouldbe) { 28 | this.run++; 29 | this.printResult(item is shouldbe); 30 | } 31 | 32 | printResult(passFail) { 33 | if (passFail) { 34 | this.passed++; 35 | say ANSI_GREEN + " PASSED" + ANSI_RESET; 36 | } else { 37 | say ANSI_RED + " FAILED" + ANSI_RESET; 38 | if (this.quitOnFail or this.override) { 39 | this.results(); 40 | exit(1); 41 | } 42 | } 43 | } 44 | 45 | results() { 46 | if (this.passed == this.run) { 47 | say ANSI_GREEN + "ALL " + this.run + " PASSED" + ANSI_RESET; 48 | } else { 49 | say ANSI_RED + (this.run - this.passed) + " failed..." + ANSI_RESET; 50 | } 51 | 52 | if (((this.run - this.passed) / this.run) * 100 >= 75) { 53 | say ANSI_RED + "Test failed with fail rate of: " + (((this.run - this.passed) / this.run) * 100) + "%" + ANSI_RESET; 54 | say "============================="; 55 | say NL + NL; 56 | exit(1); 57 | } 58 | 59 | say "============================="; 60 | say NL + NL; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/asOperator.mni: -------------------------------------------------------------------------------- 1 | load "munit"; 2 | load "types"; 3 | load "json"; 4 | load "std"; 5 | 6 | let t = newTester(); 7 | t.header("Testing conversions"); 8 | 9 | let str = "Im a string"; 10 | let mp = {"im" : "a map", "i" : "sure am"}; 11 | let lst = ["im", "a list", "thats for sure"]; 12 | let number = 12.0; 13 | 14 | t.assertType(str, "string", "Testing base string"); 15 | t.assertType(mp, {"some":"map"}, "Testing base map"); 16 | t.assertType(lst, ["base", "map"], "Testing base list"); 17 | t.assertType(number, 1.0, "Testing base number"); 18 | 19 | 20 | let nowString = number as "string"; 21 | t.assertType(nowString, "a string", "Converting number to string"); 22 | 23 | nowString = str as "string"; 24 | t.assertType(nowString, "a string", "Converting string to string"); 25 | 26 | nowString = mp as "string"; 27 | t.assertType(nowString, "a string", "Converting map to string"); 28 | 29 | nowString = lst as "string"; 30 | t.assertType(nowString, "a string", "Converting list to string"); 31 | 32 | let nowList = str as "list"; 33 | t.assertType(nowList, [1, 2, 3], "Converting string to list"); 34 | 35 | nowList = number as "list"; 36 | t.assertType(nowList, [1, 2, 3], "Converting number to list"); 37 | 38 | nowList = mp as "list"; 39 | t.assertType(nowList, [1, 2, 3], "Converting map to list"); 40 | 41 | nowList = lst as "list"; 42 | t.assertType(nowList, [1, 2, 3], "Converting list to list"); 43 | 44 | let nowMap = mp as "map"; 45 | t.assertType(nowMap, {"a" : "map"}, "Converting map to map"); 46 | 47 | 48 | t.results(); 49 | -------------------------------------------------------------------------------- /test/atomic.mni: -------------------------------------------------------------------------------- 1 | load "munit"; 2 | load "atomic"; 3 | 4 | let t = newTester(); 5 | t.header("Atomic"); 6 | 7 | let x = AtomicBool(); 8 | t.assertEquals(x, AtomicBool(), "new atomic boolean"); 9 | 10 | ABSet(x, true); 11 | t.assertTrue(x, "setting atomic boolean"); 12 | 13 | let y = "dino"; 14 | ABCompareSet(x, y == "dino", false); 15 | t.assertFalse(x, "compare set atomic boolean"); 16 | 17 | y = ABGetSet(x, true); 18 | t.assertFalse(y, "get set atomic boolean"); 19 | 20 | y = ABGet(x); 21 | t.assertTrue(x, "get atomic boolean"); 22 | 23 | t.results(); -------------------------------------------------------------------------------- /test/basics.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Testing all the basics of the language 3 | */ 4 | load "munit"; 5 | 6 | let t <- newTester(); 7 | t.header("Basics"); 8 | 9 | let x = 0; 10 | 11 | x <- 1; 12 | t.assertEquals(x, 1, "<- assign operator"); 13 | 14 | x << 0; 15 | t.assertEquals(x, 0, "<< assign operator"); 16 | 17 | x = x + 1; 18 | t.assertEquals(x, 1, "+ operator"); 19 | 20 | x++; 21 | t.assertEquals(x, 2, "++ after opeator"); 22 | 23 | ++x; 24 | t.assertEquals(x, 4, "++ before operator"); 25 | 26 | x = x - 1; 27 | t.assertEquals(x, 3, "- operator"); 28 | 29 | x--; 30 | t.assertEquals(x, 2, "-- after operator"); 31 | 32 | --x; 33 | t.assertEquals(x, 0, "-- before operator"); 34 | 35 | x += 43; 36 | t.assertEquals(x, 43, "+= operator"); 37 | 38 | x -= 3; 39 | t.assertEquals(x, 40, "-= operator"); 40 | 41 | x = x % 3; 42 | t.assertEquals(x, 1, "% operator"); 43 | 44 | x++; 45 | x = x ** 2; 46 | t.assertEquals(x, 4, "** power operator"); 47 | 48 | x = x * 2; 49 | t.assertEquals(x, 8, "* operator"); 50 | 51 | x = x / 4; 52 | t.assertEquals(x, 2, "/ operator"); 53 | 54 | let y = nil; 55 | x -> y; 56 | t.assertEquals(y, 2, "-> copy operator"); 57 | 58 | /* 59 | x = "String"; 60 | x -> y; 61 | x = "String1"; 62 | t.assertEquals(y, x, "-> copy operator changing");*/ 63 | 64 | { 65 | x = 10; 66 | let z = "test"; 67 | } 68 | t.assertEquals(x, 10, "block statement"); 69 | 70 | t.results(); -------------------------------------------------------------------------------- /test/errorScript.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Script designed to throw an error 3 | */ 4 | 5 | //Import lists library 6 | # "files"; 7 | 8 | 9 | // This line should throw an error 10 | let f = File(); 11 | -------------------------------------------------------------------------------- /test/files.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Test program to demonstrate all 3 | functionality using files 4 | */ 5 | load "munit"; 6 | //Import lists library 7 | # "files"; 8 | 9 | let t <- newTester(); 10 | t.header("Files"); 11 | 12 | let f = File("./import/file_test_import.txt"); 13 | f.open(); 14 | t.assertEquals(f.filename, "./import/file_test_import.txt", "Open a file"); 15 | 16 | t.assertEquals(f.exists(), true, "Check file exists"); 17 | 18 | t.assertEquals(f.canWrite(), true, "Check can write"); 19 | 20 | t.assertEquals(f.canRead(), true, "Check can read"); 21 | 22 | t.assertEquals(f.canExecute(), false, "Check can execute"); 23 | 24 | t.assertEquals(f.read(),"test contents of a file" + NL + "imported by test/files.mni" + NL, "Read opened file"); 25 | 26 | f.append(NL + "append this to end of file"); 27 | t.assertEquals(f.read(),"test contents of a file" + NL + "imported by test/files.mni" + NL + "append this to end of file" + NL, "Append string to file"); 28 | 29 | t.assertEquals(f.toList(), ["test contents of a file", "imported by test/files.mni", "append this to end of file"], "File contents to list"); 30 | 31 | f.write("write to the file as blank"); 32 | t.assertEquals(f.read(),"write to the file as blank" + NL, "Write string to blank file"); 33 | 34 | t.results(); 35 | -------------------------------------------------------------------------------- /test/forEach.mni: -------------------------------------------------------------------------------- 1 | load "munit"; 2 | 3 | let t <- newTester(); 4 | t.header("ForEach loops"); 5 | 6 | /* t.msg("Testing regular for-each"); 7 | let l = [1, 2, 3, 4]; 8 | let res = 0; 9 | for (test : l) { 10 | res += test; 11 | } 12 | t.match(res, 10); 13 | 14 | t.msg("Testing for-each in a for-each"); 15 | l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; 16 | let result = 0; 17 | for (test : l) { 18 | for (inner : test) { 19 | result += inner; 20 | } 21 | } 22 | t.match(result, 45); 23 | 24 | t.msg("Testing map-for-each"); 25 | let t = {"key": "val", "name" : "mani", "date" : "today"}; 26 | let resu = []; 27 | for (key, val : t) { 28 | res.add(key); 29 | res.add(val); 30 | } 31 | t.match(resu, ["key", "val", "name", "mani", "date", "today"]); */ 32 | -------------------------------------------------------------------------------- /test/import/file_test_import.txt: -------------------------------------------------------------------------------- 1 | test contents of a file 2 | imported by test/files.mni -------------------------------------------------------------------------------- /test/lists.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Test program to demonstrate all 3 | functionality using lists 4 | */ 5 | load "munit"; 6 | //Import lists library 7 | # "lists"; 8 | 9 | let t <- newTester(); 10 | t.header("Lists"); 11 | 12 | //Create a new list 13 | let myList = List(); 14 | t.assertEquals(myList.list, [], "Create new list"); 15 | 16 | 17 | //Add a string to the list 18 | myList.add("stringOne"); 19 | t.assertEquals(myList.list, ["stringOne"], "Add item to list"); 20 | 21 | myList.addLots(["stringTwo", "stringThree"]); 22 | t.assertEquals(myList.list, ["stringOne", "stringTwo", "stringThree"], "Testing add lots function"); 23 | 24 | let reversedArray = myList.reverse(); 25 | t.assertEquals(reversedArray, ["stringThree", "stringTwo", "stringOne"], "Reversing an array"); 26 | 27 | //Add a different type to the list and show 28 | myList.add(2); 29 | t.assertEquals(myList.list, ["stringOne", "stringTwo", "stringThree", 2], "Adding a number"); 30 | 31 | //Replace an item in the list 32 | myList.replace(1, "replacementString"); 33 | t.assertEquals(myList.list, ["stringOne", "replacementString", "stringThree", 2], "Replace item in list"); 34 | 35 | 36 | //Delete an item 37 | myList.del(1); 38 | t.assertEquals(myList.list, ["stringOne", "stringThree", 2], "Delete item"); 39 | 40 | myList.reset(); 41 | t.assertEquals(myList.list, [], "Reseting list"); 42 | 43 | myList.add(" spaceThenString"); 44 | myList.add("stringThenSpace "); 45 | myList.trimEach(); 46 | t.assertEquals(myList.list, ["spaceThenString", "stringThenSpace"], "String trimming"); 47 | 48 | let directList = [1,2,3,4]; 49 | let norm = List(); 50 | 51 | norm.direct(directList); 52 | t.assertEquals(norm.list, directList, "Direct listing"); 53 | 54 | // This is the function we want to run each time. 55 | let r <- List(); 56 | r.addLots([1, 2, 3, 4]); 57 | fn someFunction(item) { 58 | result.add(item); 59 | } 60 | 61 | let result <- []; 62 | r.forEach(someFunction); // This will run the "someFunction" parsing the data from the position in the list. 63 | t.assertEquals(r.list, result, "Testing forEach function"); 64 | 65 | t.results(); 66 | -------------------------------------------------------------------------------- /test/maps.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Test program to demonstrate all 3 | functionality using maps 4 | */ 5 | load "munit"; 6 | # "maps"; 7 | # "lists"; 8 | 9 | let t <- newTester(); 10 | 11 | t.header("Maps"); 12 | 13 | let myMap = Map(); 14 | t.assertEquals(myMap.map, {}, "Creating map"); 15 | 16 | myMap.add("keyName1","valueName1"); 17 | myMap.add("keyName2","valueName2"); 18 | t.assertEquals(myMap.map, {"keyName1" : "valueName1", "keyName2" : "valueName2"}, "Adding keys"); 19 | 20 | let item = myMap.get("keyName2"); 21 | t.assertEquals(item, "valueName2", "Get key"); 22 | 23 | let listOfKeys = List(); 24 | listOfKeys.direct(myMap.getKeys()); 25 | t.assertEquals(listOfKeys.list, ["keyName1", "keyName2"], "List of keys"); 26 | 27 | t.assertEquals(myMap.size(), 2, "Size of map"); 28 | 29 | let mapExists = myMap.exists("keyName1"); 30 | t.assertEquals(mapExists, true, "Check for existing key"); 31 | 32 | mapExists = myMap.exists("nonExistentKey"); 33 | t.assertEquals(mapExists, false, "Check for non-existing key"); 34 | 35 | 36 | // Combine two lists into a map 37 | // Both Lists must be the same length. 38 | let keys = List(); // The keys of the map. 39 | let vals = List(); // The values of the map. 40 | 41 | // Filling the 2 lists with values... 42 | keys.addLots([1, 3, 5, 7, 9]); 43 | vals.addLots([2, 4, 6, 8, 10]); 44 | 45 | // Using keys List, as the keys. 46 | // Using the vals List, as the values. 47 | let mapToTest = Map(); 48 | mapToTest.combine(keys, vals); // changes the contents of the map to these keys and values. 49 | t.assertEquals(mapToTest.map, {1 : 2, 3 : 4, 5 : 6, 7 : 8, 9 : 10}, "Checking combine function of 2 lists"); 50 | 51 | mapToTest.del(1); 52 | t.assertEquals(mapToTest.map, {3 : 4, 5 : 6, 7 : 8, 9 : 10}, "Deleting item"); 53 | 54 | let values = mapToTest.getValues(); 55 | t.assertEquals(values, [10, 6, 4, 8], "Get values"); 56 | 57 | mapToTest.update(3,"update"); 58 | t.assertEquals(mapToTest.map, {9.0 : 10.0, 5.0 : 6.0, 3.0 : "update", 7.0 : 8.0}, "Updating an item"); 59 | 60 | myMap.copy(mapToTest); 61 | t.assertEquals(myMap.map, {9.0 : 10.0, 5.0 : 6.0, 3.0 : "update", 7.0 : 8.0}, "Copying a map"); 62 | 63 | t.assertEquals(mapToTest.map, {9.0 : 10.0, 5.0 : 6.0, 3.0 : "update", 7.0 : 8.0}, "Show a map"); 64 | 65 | mapToTest.reset(); 66 | t.assertEquals(mapToTest.map, {}, "Reset a map"); 67 | /* 68 | let anotherMap = Map(); 69 | let dMap1 = Map(); 70 | let dMap2 = Map(); 71 | 72 | dMap1.add("test", "name"); 73 | dMap2.add("test", "name1"); 74 | anotherMap.add("first", dMap1); 75 | anotherMap.add("second", dMap2); 76 | t.assertEquals(anotherMap.find("test", "name"), dMap1, "Map search"); 77 | 78 | */ 79 | t.results(); 80 | -------------------------------------------------------------------------------- /test/math.mni: -------------------------------------------------------------------------------- 1 | load "munit"; 2 | load "math"; 3 | 4 | let t = newTester(); 5 | let x = 1.23; 6 | 7 | t.header("Math"); 8 | 9 | t.assertEquals(floor(x), 1, "Test floor"); 10 | 11 | t.assertEquals(ceil(x), 2, "Test ceil"); 12 | 13 | t.assertEquals(asin(1), 1.5707963267948966, "Test asin"); 14 | 15 | t.assertEquals(acos(1), 0.0, "Test acos"); 16 | 17 | t.assertEquals(atan(1), 0.7853981633974483, "Test atan"); 18 | 19 | t.assertEquals(atan2(x, x), 0.7853981633974483, "Test atan2"); 20 | 21 | t.assertEquals(cbrt(x), 1.0714412696907731, "Test cbrt"); 22 | 23 | t.assertEquals(cos(x), 0.3342377271245026, "Test cos"); 24 | 25 | t.assertEquals(sin(x), 0.9424888019316975, "Test sin"); 26 | 27 | t.assertEquals(tan(x), 2.819815734268152, "Test tan"); 28 | 29 | t.assertEquals(cosh(x), 1.8567610569852664, "Test cosh"); 30 | 31 | t.assertEquals(exp(x), 3.4212295362896734, "Test exp"); 32 | 33 | t.assertEquals(expm1(x), 2.4212295362896734, "Test expm1"); 34 | 35 | t.results(); 36 | -------------------------------------------------------------------------------- /test/runTests.mni: -------------------------------------------------------------------------------- 1 | load "std"; 2 | load "system"; 3 | 4 | load "basics.mni"; 5 | if (System.hadError()) { System.exit(1); } 6 | 7 | wipeMemory(); 8 | load "std"; 9 | load "system"; 10 | load "files.mni"; 11 | if (System.hadError()) { System.exit(1); } 12 | 13 | wipeMemory(); 14 | load "std"; 15 | load "system"; 16 | load "asOperator.mni"; 17 | if (System.hadError()) { System.exit(1); } 18 | 19 | wipeMemory(); 20 | load "std"; 21 | load "system"; 22 | load "forEach.mni"; 23 | if (System.hadError()) { System.exit(1); } 24 | 25 | wipeMemory(); 26 | load "std"; 27 | load "system"; 28 | // Script intended to throw error 29 | load "errorScript.mni"; 30 | // Tests that error was output correctly 31 | load "testErrorOutputs.mni"; 32 | 33 | wipeMemory(); 34 | load "std"; 35 | load "system"; 36 | load "lists.mni"; 37 | if (System.hadError()) { System.exit(1); } 38 | 39 | wipeMemory(); 40 | load "std"; 41 | load "system"; 42 | load "maps.mni"; 43 | if (System.hadError()) { System.exit(1); } 44 | 45 | //wipeMemory(); 46 | //load "std"; 47 | //load "system"; 48 | //load "atomic.mni"; 49 | //if (hadError()) { exit(1); } 50 | 51 | wipeMemory(); 52 | load "std"; 53 | load "system"; 54 | load "math.mni"; 55 | if (System.hadError()) { System.exit(1); } 56 | -------------------------------------------------------------------------------- /test/runTestsOffline.mni: -------------------------------------------------------------------------------- 1 | load "std"; 2 | load "system"; 3 | 4 | online(false); 5 | load "basics.mni"; 6 | if (hadError()) { exit(1); } 7 | 8 | wipeMemory(); 9 | load "std"; 10 | load "system"; 11 | online(false); 12 | load "files.mni"; 13 | if (hadError()) { exit(1); } 14 | 15 | wipeMemory(); 16 | load "std"; 17 | load "system"; 18 | online(false); 19 | load "asOperator.mni"; 20 | if (hadError()) { exit(1); } 21 | 22 | wipeMemory(); 23 | load "std"; 24 | load "system"; 25 | online(false); 26 | load "forEach.mni"; 27 | if (hadError()) { exit(1); } 28 | 29 | wipeMemory(); 30 | load "std"; 31 | load "system"; 32 | online(false); 33 | // Script intended to throw error 34 | load "errorScript.mni"; 35 | // Tests that error was output correctly 36 | load "testErrorOutputs.mni"; 37 | 38 | wipeMemory(); 39 | load "std"; 40 | load "system"; 41 | online(false); 42 | load "lists.mni"; 43 | if (hadError()) { exit(1); } 44 | 45 | wipeMemory(); 46 | load "std"; 47 | load "system"; 48 | online(false); 49 | load "maps.mni"; 50 | if (hadError()) { exit(1); } 51 | 52 | //wipeMemory(); 53 | //load "std"; 54 | //load "system"; 55 | //load "atomic.mni"; 56 | //if (hadError()) { exit(1); } 57 | 58 | wipeMemory(); 59 | load "std"; 60 | load "system"; 61 | online(false); 62 | load "math.mni"; 63 | if (hadError()) { exit(1); } 64 | -------------------------------------------------------------------------------- /test/switchCase.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Test program to demonstrate switch-case 3 | */ 4 | load "munit"; 5 | //Import lists library 6 | # "lists"; 7 | 8 | let t <- newTester(); 9 | t.header("Switch-case"); 10 | 11 | //Create a new list 12 | let myList = List(); 13 | 14 | // Simple single statement per-case. 15 | let a = 1; 16 | switch (a) { 17 | case 1 : 18 | myList.add(1); 19 | case 2 : 20 | myList.add(2); 21 | case 3 : 22 | myList.add(3); 23 | default : 24 | myList.add(0); 25 | } 26 | t.assertEquals(myList.list, [1,2,3,0], "Add item to list"); 27 | 28 | // When no case is matched; the default gets executed always. 29 | let a = 10; 30 | switch (a) { 31 | case 1 : 32 | myList.add(1); 33 | case 2 : 34 | myList.add(2); 35 | case 3 : 36 | myList.add(3); 37 | default : 38 | myList.add(0); 39 | } 40 | t.assertEquals(myList.list, [1,2,3,0,0], "Add item to list"); 41 | 42 | // Multiple statements per-case. 43 | let a = 3; 44 | switch (a) { 45 | case 1 : 46 | myList.add(1); 47 | myList.add(10); 48 | case 2 : 49 | myList.add(2); 50 | myList.add(20); 51 | case 3 : 52 | myList.add(3); 53 | myList.add(30); 54 | default : 55 | myList.add(0); 56 | myList.add(100); 57 | } 58 | t.assertEquals(myList.list, [1,2,3,0,0,3,30,0,100], "Add item to list"); 59 | 60 | //Create a new list for strings 61 | let myStringList = List(); 62 | 63 | // Simple single statement per-case. 64 | let var = "b"; 65 | switch (var) { 66 | case "a" : 67 | myStringList.add("a"); 68 | case "b" : 69 | myStringList.add("b"); 70 | case "c" : 71 | myStringList.add("c"); 72 | default : 73 | myStringList.add("default"); 74 | } 75 | t.assertEquals(myStringList.list, [b, c, default], "Add item to list"); 76 | 77 | // When switch variable is of number type, but cases are for string type, it 78 | // does not complain about type-mismatch and easily compiles. The default 79 | // block gets executed. Same behaviour is observered for the vice-versa case. 80 | let var = 1; 81 | switch (var) { 82 | case "a" : 83 | myStringList.add("a"); 84 | case "b" : 85 | myStringList.add("b"); 86 | case "c" : 87 | myStringList.add("c"); 88 | default : 89 | myStringList.add("default"); 90 | } 91 | t.assertEquals(myStringList.list, [b, c, default, default], "Add item to list"); 92 | 93 | //Create a new list 94 | let myList2 = List(); 95 | 96 | // Simple switch-case with break. 97 | let a = 1; 98 | switch (a) { 99 | case 1 : 100 | myList2.add(1); 101 | break; 102 | case 2 : 103 | myList2.add(2); 104 | break; 105 | case 3 : 106 | myList2.add(3); 107 | break; 108 | default : 109 | myList2.add(0); 110 | } 111 | t.assertEquals(myList2.list, [1], "Add item to list"); 112 | 113 | let a = 1; 114 | switch (a) { 115 | case 1 : 116 | myList2.add(1); 117 | case 2 : 118 | myList2.add(2); 119 | break; 120 | case 3 : 121 | myList2.add(3); 122 | break; 123 | default : 124 | myList2.add(0); 125 | } 126 | t.assertEquals(myList2.list, [1,1,2], "Add item to list"); 127 | -------------------------------------------------------------------------------- /test/testErrorOutputs.mni: -------------------------------------------------------------------------------- 1 | /* 2 | Tests that the error output is as expected 3 | */ 4 | 5 | 6 | load "munit"; 7 | 8 | let t <- newTester(); 9 | t.header("Assert error outputs"); 10 | 11 | t.assertEquals(latestError(), "Expected 1 argument(s) but got 0." + NL + "[line 10] at errorScript.mni", "Error thrown as epected"); 12 | 13 | t.results(); -------------------------------------------------------------------------------- /testing: -------------------------------------------------------------------------------- 1 | THIS IS FOR REMOTE ORIGIN TESTING 2 | -------------------------------------------------------------------------------- /tests.sh: -------------------------------------------------------------------------------- 1 | gradle clean 2 | clear 3 | gradle build 4 | clear 5 | cp -r ./test/* ./build/libs 6 | cd ./build/libs 7 | java -jar Mani-Stable.jar runTests.mni 8 | 9 | cd ../../ 10 | gradle clean 11 | clear 12 | gradle fatJar 13 | clear 14 | cp -r ./test/* ./build/libs 15 | cd ./build/libs 16 | java -jar Mani-FatJar.jar runTestsOffline.mni 17 | --------------------------------------------------------------------------------