├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── codecov.yml ├── lombok.config ├── pom.xml ├── runescript-commons ├── pom.xml └── src │ ├── main │ └── java │ │ └── me │ │ └── waliedyassen │ │ └── runescript │ │ ├── RuneScriptError.java │ │ ├── commons │ │ ├── Pair.java │ │ ├── document │ │ │ ├── Element.java │ │ │ ├── LineColumn.java │ │ │ ├── LineMap.java │ │ │ └── Span.kt │ │ └── stream │ │ │ ├── BufferedCharStream.java │ │ │ └── CharStream.java │ │ ├── compiler │ │ ├── CompiledFile.java │ │ ├── CompiledUnit.java │ │ ├── CompilerBase.java │ │ ├── CompilerError.java │ │ ├── Input.java │ │ ├── Output.java │ │ ├── SourceFile.java │ │ ├── error │ │ │ └── ErrorReporter.java │ │ ├── idmapping │ │ │ └── IDManager.java │ │ ├── lexer │ │ │ ├── LexerBase.java │ │ │ ├── LexicalError.java │ │ │ ├── TokenizerBase.java │ │ │ ├── table │ │ │ │ └── LexicalTable.java │ │ │ └── token │ │ │ │ ├── Token.java │ │ │ │ └── TokenFactory.java │ │ ├── message │ │ │ ├── CompilerMessage.java │ │ │ └── CompilerMessenger.java │ │ ├── parser │ │ │ ├── ParserBase.java │ │ │ └── SyntaxError.java │ │ ├── symbol │ │ │ ├── Symbol.kt │ │ │ ├── SymbolList.kt │ │ │ ├── SymbolLoader.kt │ │ │ ├── SymbolTable.java │ │ │ └── impl │ │ │ │ ├── ArrayInfo.java │ │ │ │ ├── GraphicInfo.java │ │ │ │ └── RuntimeConstantInfo.java │ │ └── syntax │ │ │ └── SyntaxBase.java │ │ ├── type │ │ ├── Type.kt │ │ ├── TypeUtil.java │ │ ├── primitive │ │ │ └── PrimitiveType.kt │ │ ├── stack │ │ │ └── StackType.java │ │ └── tuple │ │ │ └── TupleType.java │ │ └── util │ │ ├── ChecksumUtil.java │ │ ├── CollectorsEx.java │ │ ├── ReflectionUtil.java │ │ └── StreamUtil.java │ └── test │ └── java │ └── me │ └── waliedyassen │ └── runescript │ ├── commons │ ├── document │ │ ├── LineColumnTest.java │ │ ├── LineMapTest.java │ │ └── SpanTest.java │ └── stream │ │ └── BufferedCharStreamTest.java │ └── type │ └── TupleTypeTest.java ├── runescript-compiler ├── pom.xml └── src │ ├── main │ └── java │ │ └── me │ │ └── waliedyassen │ │ └── runescript │ │ └── compiler │ │ ├── CompiledScript.java │ │ ├── CompiledScriptUnit.java │ │ ├── ScriptCompiler.java │ │ ├── codegen │ │ ├── CodeGenerator.java │ │ ├── Instruction.java │ │ ├── InstructionMap.java │ │ ├── LabelGenerator.java │ │ ├── block │ │ │ ├── Block.java │ │ │ ├── BlockList.java │ │ │ ├── BlockMap.java │ │ │ └── Label.java │ │ ├── local │ │ │ ├── Local.java │ │ │ └── LocalMap.java │ │ ├── opcode │ │ │ ├── BasicOpcode.java │ │ │ ├── CoreOpcode.java │ │ │ └── Opcode.java │ │ ├── optimizer │ │ │ ├── BlockOptimization.java │ │ │ ├── Optimization.java │ │ │ ├── Optimizer.java │ │ │ └── impl │ │ │ │ ├── ConstantFoldingOptimization.java │ │ │ │ ├── DeadBlockOptimization.java │ │ │ │ ├── DeadBranchOptimization.java │ │ │ │ └── NaturalFlowOptimization.java │ │ ├── script │ │ │ └── BinaryScript.java │ │ ├── sw │ │ │ ├── SwitchCase.java │ │ │ ├── SwitchMap.java │ │ │ └── SwitchTable.java │ │ └── writer │ │ │ ├── CodeWriter.java │ │ │ └── bytecode │ │ │ ├── BytecodeCodeWriter.java │ │ │ ├── BytecodeInstruction.java │ │ │ └── BytecodeScript.java │ │ ├── env │ │ └── CompilerEnvironment.java │ │ ├── lexer │ │ ├── Lexer.java │ │ ├── token │ │ │ └── Kind.java │ │ └── tokenizer │ │ │ ├── Mode.java │ │ │ ├── State.java │ │ │ └── Tokenizer.java │ │ ├── message │ │ └── impl │ │ │ └── SyntaxDoneMessage.java │ │ ├── semantics │ │ ├── SemanticChecker.java │ │ ├── SemanticError.java │ │ ├── scope │ │ │ └── Scope.java │ │ └── typecheck │ │ │ ├── PreTypeChecking.java │ │ │ ├── TypeCheckAction.java │ │ │ └── TypeChecking.java │ │ ├── symbol │ │ ├── ScriptSymbolTable.java │ │ └── impl │ │ │ ├── CommandInfo.java │ │ │ └── script │ │ │ ├── Annotation.java │ │ │ └── ScriptInfo.java │ │ ├── syntax │ │ ├── AnnotationSyntax.java │ │ ├── ParameterSyntax.java │ │ ├── ScriptNameSyntax.java │ │ ├── ScriptSyntax.java │ │ ├── Syntax.java │ │ ├── SyntaxParser.java │ │ ├── SyntaxToken.java │ │ ├── TypeSyntax.java │ │ ├── expr │ │ │ ├── ArrayElementSyntax.java │ │ │ ├── ArrayVariableSyntax.java │ │ │ ├── CalcSyntax.java │ │ │ ├── CallSyntax.java │ │ │ ├── CommandSyntax.java │ │ │ ├── ConcatenationSyntax.java │ │ │ ├── ConstantSyntax.kt │ │ │ ├── DynamicSyntax.java │ │ │ ├── ExpressionSyntax.java │ │ │ ├── HookSyntax.java │ │ │ ├── IdentifierSyntax.java │ │ │ ├── ParExpressionSyntax.java │ │ │ ├── ScopedVariableSyntax.java │ │ │ ├── VariableExpressionSyntax.java │ │ │ ├── VariableSyntax.java │ │ │ ├── literal │ │ │ │ ├── LiteralBooleanSyntax.java │ │ │ │ ├── LiteralCoordgridSyntax.java │ │ │ │ ├── LiteralExpressionSyntax.java │ │ │ │ ├── LiteralIntegerSyntax.java │ │ │ │ ├── LiteralLongSyntax.java │ │ │ │ ├── LiteralNullSyntax.java │ │ │ │ ├── LiteralNumberSyntax.java │ │ │ │ ├── LiteralStringSyntax.java │ │ │ │ └── LiteralTypeSyntax.java │ │ │ └── op │ │ │ │ └── BinaryOperationSyntax.java │ │ ├── stmt │ │ │ ├── ArrayDeclarationSyntax.java │ │ │ ├── BlockStatementSyntax.java │ │ │ ├── ErrorStatementSyntax.java │ │ │ ├── ExpressionStatementSyntax.java │ │ │ ├── ReturnStatementSyntax.java │ │ │ ├── StatementSyntax.java │ │ │ ├── SwitchCaseSyntax.java │ │ │ ├── SwitchStatementSyntax.java │ │ │ ├── VariableDeclarationSyntax.java │ │ │ ├── VariableInitializerSyntax.java │ │ │ ├── conditional │ │ │ │ └── IfStatementSyntax.java │ │ │ └── loop │ │ │ │ ├── BreakStatementSyntax.java │ │ │ │ ├── ContinueStatementSyntax.java │ │ │ │ ├── DoWhileStatementSyntax.java │ │ │ │ └── WhileStatementSyntax.java │ │ └── visitor │ │ │ ├── SyntaxTreeVisitor.java │ │ │ └── SyntaxVisitor.java │ │ ├── type │ │ └── ArrayReference.java │ │ └── util │ │ ├── Operator.java │ │ ├── VariableScope.java │ │ └── trigger │ │ ├── BasicTriggerType.java │ │ └── TriggerType.java │ └── test │ ├── java │ └── me │ │ └── waliedyassen │ │ └── runescript │ │ └── compiler │ │ ├── TestHelper.java │ │ ├── codegen │ │ ├── CodeGeneratorTest.java │ │ ├── InstructionMapTest.java │ │ ├── LabelGeneratorTest.java │ │ ├── block │ │ │ ├── BlockMapTest.java │ │ │ ├── BlockTest.java │ │ │ └── LabelTest.java │ │ ├── local │ │ │ └── LocalMapTest.java │ │ ├── opcode │ │ │ └── CoreOpcodeTest.java │ │ └── optimizer │ │ │ └── impl │ │ │ └── ConstantFoldingOptimizationTest.java │ │ ├── env │ │ └── CompilerEnvironmentTest.java │ │ ├── error │ │ └── ThrowingErrorReporter.java │ │ ├── lexer │ │ └── tokenizer │ │ │ └── TokenizerTest.java │ │ ├── parser │ │ └── ScriptParserTest.java │ │ ├── semantics │ │ ├── scope │ │ │ └── ScopeTest.java │ │ └── typecheck │ │ │ └── TypeCheckingTest.java │ │ ├── syntax │ │ └── visitor │ │ │ └── AstTreeVisitorTest.java │ │ └── util │ │ ├── OperatorTest.java │ │ └── VariableScopeTest.java │ └── resources │ ├── me │ └── waliedyassen │ │ └── runescript │ │ └── compiler │ │ ├── codegen │ │ ├── local_01.rs2 │ │ ├── operator_bitwise_and.rs2 │ │ └── operator_bitwise_or.rs2 │ │ └── semantics │ │ └── typecheck │ │ ├── array_01.rs2 │ │ ├── array_02.rs2 │ │ ├── calc_01.rs2 │ │ ├── calc_02.rs2 │ │ ├── call_01.rs2 │ │ ├── operator_bitwise_and.rs2 │ │ └── operator_bitwise_or.rs2 │ ├── parse-script.rs2 │ └── visitor-tree-script.rs2 ├── runescript-editor ├── pom.xml └── src │ └── main │ ├── java │ ├── me │ │ └── waliedyassen │ │ │ └── runescript │ │ │ └── editor │ │ │ ├── Api.java │ │ │ ├── EditorIcons.java │ │ │ ├── RecentPathManager.java │ │ │ ├── RuneScriptEditor.java │ │ │ ├── file │ │ │ ├── FileType.java │ │ │ ├── FileTypeManager.java │ │ │ └── impl │ │ │ │ ├── PlainFileType.java │ │ │ │ ├── ProjectFileType.java │ │ │ │ └── ScriptFileType.java │ │ │ ├── job │ │ │ └── WorkExecutor.java │ │ │ ├── pack │ │ │ ├── Pack.java │ │ │ ├── PackFile.java │ │ │ ├── impl │ │ │ │ ├── FlatPack.java │ │ │ │ └── SQLitePack.java │ │ │ ├── manager │ │ │ │ └── PackManager.java │ │ │ └── provider │ │ │ │ ├── PackProvider.java │ │ │ │ └── impl │ │ │ │ ├── FlatPackProvider.java │ │ │ │ └── SQLitePackProvider.java │ │ │ ├── project │ │ │ ├── PackType.java │ │ │ ├── Project.java │ │ │ ├── ProjectConfig.java │ │ │ ├── ProjectException.java │ │ │ ├── ProjectManager.java │ │ │ ├── build │ │ │ │ └── BuildPath.java │ │ │ ├── cache │ │ │ │ ├── Cache.java │ │ │ │ ├── CachedError.java │ │ │ │ └── unit │ │ │ │ │ └── CacheUnit.java │ │ │ ├── compile │ │ │ │ ├── CompileResult.java │ │ │ │ ├── ProjectCompiler.java │ │ │ │ ├── ProjectCompilerProvider.java │ │ │ │ └── impl │ │ │ │ │ └── ProjectScriptCompiler.java │ │ │ └── dependency │ │ │ │ ├── CircularDependencyException.java │ │ │ │ ├── DependencyNode.java │ │ │ │ └── DependencyTree.java │ │ │ ├── property │ │ │ ├── Property.java │ │ │ ├── PropertyChangeListener.java │ │ │ └── impl │ │ │ │ ├── BooleanProperty.java │ │ │ │ ├── ReferenceProperty.java │ │ │ │ └── StringProperty.java │ │ │ ├── resource │ │ │ └── ResourceManager.java │ │ │ ├── settings │ │ │ ├── Settings.java │ │ │ ├── SettingsManager.java │ │ │ ├── impl │ │ │ │ └── LookAndFeelSettings.java │ │ │ └── state │ │ │ │ └── SettingsState.java │ │ │ ├── shortcut │ │ │ ├── Shortcut.java │ │ │ ├── ShortcutGroup.java │ │ │ ├── ShortcutManager.java │ │ │ ├── UiAction.java │ │ │ └── common │ │ │ │ ├── CommonGroups.java │ │ │ │ └── CommonShortcuts.java │ │ │ ├── ui │ │ │ ├── EditorUI.java │ │ │ ├── dialog │ │ │ │ ├── DialogManager.java │ │ │ │ └── DialogResult.java │ │ │ ├── editor │ │ │ │ ├── Editor.java │ │ │ │ ├── area │ │ │ │ │ └── EditorView.java │ │ │ │ ├── code │ │ │ │ │ ├── CodeEditor.java │ │ │ │ │ ├── FileEditor.java │ │ │ │ │ ├── completion │ │ │ │ │ │ ├── CodeCompletionProvider.java │ │ │ │ │ │ ├── cache │ │ │ │ │ │ │ └── AutoCompleteCache.java │ │ │ │ │ │ ├── impl │ │ │ │ │ │ │ ├── CodeCompletion.java │ │ │ │ │ │ │ ├── CommandCompletion.java │ │ │ │ │ │ │ └── KeywordCompletion.java │ │ │ │ │ │ └── parameter │ │ │ │ │ │ │ └── CodeParameterCompletionProvider.java │ │ │ │ │ ├── folder │ │ │ │ │ │ └── CodeFolder.java │ │ │ │ │ ├── parser │ │ │ │ │ │ ├── ParserManager.java │ │ │ │ │ │ ├── impl │ │ │ │ │ │ │ └── CodeParser.java │ │ │ │ │ │ └── notice │ │ │ │ │ │ │ └── ErrorNotice.java │ │ │ │ │ ├── theme │ │ │ │ │ │ └── CodeTheme.java │ │ │ │ │ └── tokenMaker │ │ │ │ │ │ ├── CodeTokenMaker.java │ │ │ │ │ │ ├── CodeTokens.java │ │ │ │ │ │ └── factory │ │ │ │ │ │ └── TokenMakerFactoryImpl.java │ │ │ │ ├── project │ │ │ │ │ └── ProjectEditor.java │ │ │ │ └── tab │ │ │ │ │ └── EditorTab.java │ │ │ ├── errors │ │ │ │ └── ErrorsView.java │ │ │ ├── explorer │ │ │ │ ├── ExplorerView.java │ │ │ │ └── tree │ │ │ │ │ ├── ExplorerModel.java │ │ │ │ │ ├── ExplorerNode.java │ │ │ │ │ ├── ExplorerTree.java │ │ │ │ │ ├── lazy │ │ │ │ │ ├── LazyLoading.java │ │ │ │ │ └── LoadingNode.java │ │ │ │ │ ├── node │ │ │ │ │ ├── DirectoryNode.java │ │ │ │ │ ├── FileNode.java │ │ │ │ │ └── ProjectNode.java │ │ │ │ │ └── render │ │ │ │ │ └── ExplorerRenderer.java │ │ │ ├── menu │ │ │ │ └── action │ │ │ │ │ ├── Action.java │ │ │ │ │ ├── ActionManager.java │ │ │ │ │ ├── ActionSource.java │ │ │ │ │ ├── impl │ │ │ │ │ ├── Executable.java │ │ │ │ │ ├── Menu.java │ │ │ │ │ └── Separator.java │ │ │ │ │ └── list │ │ │ │ │ └── ActionList.java │ │ │ ├── settings │ │ │ │ └── SettingsDialog.java │ │ │ ├── status │ │ │ │ └── StatusBar.java │ │ │ ├── tabbedpane │ │ │ │ ├── TabComponent.java │ │ │ │ └── TabbedPane.java │ │ │ └── util │ │ │ │ └── DelegatingMouseListener.java │ │ │ ├── util │ │ │ ├── FontManager.java │ │ │ ├── JsonUtil.java │ │ │ ├── LafUtil.java │ │ │ └── ex │ │ │ │ ├── PathEx.java │ │ │ │ └── SwingUtilitiesEx.java │ │ │ └── vfs │ │ │ ├── VFS.java │ │ │ ├── VFSFile.java │ │ │ ├── VFSFileListener.java │ │ │ └── VFSWatcher.java │ └── org │ │ └── fife │ │ └── ui │ │ └── rsyntaxtextarea │ │ └── ErrorStrip.java │ └── resources │ ├── com │ └── formdev │ │ └── flatlaf │ │ └── FlatDarculaLaf.properties │ ├── icons │ ├── favicon.png │ ├── idea │ │ ├── LICENSE.txt │ │ ├── close.svg │ │ ├── close_dark.svg │ │ ├── close_hovered.svg │ │ ├── settings.svg │ │ └── settings_dark.svg │ └── tree │ │ ├── config.png │ │ ├── file.png │ │ ├── folder.png │ │ └── script.png │ └── me │ └── waliedyassen │ └── runescript │ └── editor │ ├── project │ ├── osrs_default_commands.toml │ ├── osrs_default_instructions.toml │ └── osrs_default_triggers.toml │ └── util │ ├── JetBrainsMono-Bold-Italic.ttf │ ├── JetBrainsMono-Bold.ttf │ ├── JetBrainsMono-ExtraBold-Italic.ttf │ ├── JetBrainsMono-ExtraBold.ttf │ ├── JetBrainsMono-Italic.ttf │ ├── JetBrainsMono-Medium-Italic.ttf │ ├── JetBrainsMono-Medium.ttf │ └── JetBrainsMono-Regular.ttf ├── runescript-runtime ├── pom.xml └── src │ └── main │ └── java │ └── me │ └── waliedyassen │ └── runescript │ └── runtime │ ├── ScriptFrame.java │ ├── ScriptRuntime.java │ ├── ScriptRuntimePool.java │ ├── ScriptRuntimeSetup.java │ ├── cache │ └── ScriptCache.java │ ├── executor │ ├── ExecutionException.java │ ├── ScriptExecutor.java │ ├── ScriptFramePool.java │ ├── impl │ │ ├── ArrayOps.java │ │ ├── ConsoleOps.java │ │ ├── CoreOps.java │ │ ├── MathOps.java │ │ └── StringOps.java │ └── instruction │ │ ├── InstructionExecutor.java │ │ └── InstructionExecutorMap.java │ └── script │ └── Script.java └── version-rules.xml /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: java 3 | dist: trusty 4 | jdk: oraclejdk8 5 | install: true 6 | script: 7 | - mvn clean verify jacoco:report 8 | after_success: 9 | - bash <(curl -s https://codecov.io/bash) 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RuneScript 2 | [![Build Status](https://travis-ci.org/waliedyassen/RuneScript.svg?branch=master)](https://travis-ci.org/waliedyassen/RuneScript) 3 | [![codecov](https://codecov.io/gh/waliedyassen/RuneScript/branch/master/graph/badge.svg)](https://codecov.io/gh/waliedyassen/RuneScript) 4 | [![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/waliedyassen/RuneScript.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/waliedyassen/RuneScript/context:java) 5 | 6 | RuneScript itself is an in-house language that is currently being used for RuneScape content development. 7 | 8 | This project aims to create a compiler for that language based on pictures given by mods, along with an IDE that can be used 9 | to modify scripts or configs written in RuneScript and compile them to bytecode. 10 | 11 | ## Specification 12 | You can read about the specification in [here](https://oldschool.runescape.wiki/w/RuneScript) or in [here](https://github.com/RuneStar/cs2) 13 | 14 | ## Contributors 15 | * [waliedyassen](https://github.com/waliedyassen) 16 | 17 | ## License 18 | This project is licensed under the Mozilla Public License - check [LICENSE](LICENSE) for further details. 19 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | require_ci_to_pass: yes 4 | 5 | coverage: 6 | precision: 2 7 | round: down 8 | range: "70...100" 9 | 10 | status: 11 | project: yes 12 | patch: yes 13 | changes: no 14 | 15 | parsers: 16 | gcov: 17 | branch_detection: 18 | conditional: yes 19 | loop: yes 20 | method: no 21 | macro: no 22 | 23 | comment: 24 | layout: "header, diff" 25 | behavior: default 26 | require_changes: no -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.addLombokGeneratedAnnotation = true -------------------------------------------------------------------------------- /runescript-commons/pom.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 4.0.0 10 | 11 | me.waliedyassen.runescript 12 | runescript-parent 13 | 0.6-SNAPSHOT 14 | 15 | runescript-commons 16 | RuneScript Commons 17 | 0.6-SNAPSHOT 18 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/RuneScriptError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript; 9 | 10 | /** 11 | * Represents the base class for all of the RuneScript language errors. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public abstract class RuneScriptError extends RuntimeException { 16 | 17 | /** 18 | * The serialisation version of the {@link RuneScriptError} type. 19 | */ 20 | private static final long serialVersionUID = -1; 21 | 22 | /** 23 | * Constructs a new {@link RuneScriptError} type object instance. 24 | * 25 | * @param message 26 | * the error message text content. 27 | */ 28 | public RuneScriptError(String message) { 29 | super(message); 30 | } 31 | 32 | /** 33 | * Constructs a new {@link RuneScriptError} type object instance. 34 | * 35 | * @param message 36 | * the error message text content. 37 | * @param cause 38 | * the root cause of this error. 39 | */ 40 | RuneScriptError(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/commons/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.commons; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | 13 | /** 14 | * A utility type that holds two objects (the {@code key} and the {@code value}). 15 | * 16 | * @param the type of the key. 17 | * @param the type of the value. 18 | * @author Walied K. Yassen 19 | */ 20 | @RequiredArgsConstructor 21 | public final class Pair { 22 | 23 | /** 24 | * The value of the key. 25 | */ 26 | @Getter 27 | private final K key; 28 | 29 | /** 30 | * The value of the value. 31 | */ 32 | @Getter 33 | private final V value; 34 | 35 | /** 36 | * Creates a new {@link Pair} object instance with the specified {@code key} and {@code value}. 37 | * 38 | * @param key the first value of the pair (key). 39 | * @param value the second value of the pair (value). 40 | * @param the type of the key. 41 | * @param the type of the value. 42 | * @return the created {@link Pair} object instance. 43 | */ 44 | public static Pair of(K key, V value) { 45 | return new Pair<>(key, value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/commons/document/Element.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.commons.document; 9 | 10 | /** 11 | * Represents a document element. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public interface Element { 16 | 17 | /** 18 | * Gets the element in-document position range. 19 | * 20 | * @return the {@link Span} object. 21 | */ 22 | Span getSpan(); 23 | } 24 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/commons/document/Span.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.commons.document 9 | 10 | /** 11 | * Represents a position range within a document. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | data class Span(var begin: Int, var end: Int) { 16 | 17 | constructor(vararg spans: Span) : this(spans.minOf { it.begin }, spans.maxOf { it.end }) 18 | constructor(spans: List) : this(spans.minOf { it.begin }, spans.maxOf { it.end }) 19 | 20 | /** 21 | * Performs [.add] for each of the given `ranges`. 22 | * 23 | * @param spans the ranges to perform for. 24 | */ 25 | fun add(vararg spans: Span) { 26 | for (range in spans) { 27 | add(range) 28 | } 29 | } 30 | 31 | /** 32 | * Updates this position [Span] to include the specified [range][Span]. 33 | * 34 | * @param span the range which we wil update this [Span] object to include. 35 | */ 36 | fun add(span: Span) { 37 | begin = begin.coerceAtMost(span.begin) 38 | end = end.coerceAtLeast(span.end) 39 | } 40 | 41 | /** 42 | * Checks whether the specified [position][LineColumn] is within this position [Span] or 43 | * not. 44 | * 45 | * @param position the position to check whether is it within this position range or not. 46 | * @return `true` if the specified position is within this range otherwise `false`. 47 | */ 48 | operator fun contains(position: Int): Boolean { 49 | return position in begin..end 50 | } 51 | 52 | fun clone() = Span(begin, end) 53 | } -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/CompiledUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import me.waliedyassen.runescript.compiler.syntax.SyntaxBase; 11 | 12 | /** 13 | * The base class for all of the compilation units. 14 | * 15 | * @param the Syntax Tree node type of the compiled unit. 16 | */ 17 | public abstract class CompiledUnit { 18 | 19 | /** 20 | * Returns the Syntax Tree node object. 21 | * 22 | * @return the Syntax Tree node object. 23 | */ 24 | public abstract S getSyntax(); 25 | } 26 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/CompilerBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | import me.waliedyassen.runescript.compiler.idmapping.IDManager; 12 | import me.waliedyassen.runescript.compiler.syntax.SyntaxBase; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * The base class for all the compiler implementations we use for RuneScript. 18 | * 19 | * @param the type of the Syntax Tree object this compiler will produce. 20 | * @param the type of the compilation unit this compiler will produce. 21 | * @author Walied K. Yassen 22 | */ 23 | @RequiredArgsConstructor 24 | public abstract class CompilerBase> { 25 | 26 | /** 27 | * The ID manager for the compiled units. 28 | */ 29 | protected final IDManager idManager; 30 | 31 | /** 32 | * Attempts to compile all of the source code specified in the {@link Input} object 33 | * and produce a {@link Output output} object which contains the compiled form of the object 34 | * and the associated errors produced during that compilation process. 35 | * 36 | * @param input the input object which contains the all of the source code that we want to compile. 37 | * @return the {@link Output} object instance. 38 | * @throws IOException if somehow a problem occurred while writing or reading from the temporary streams. 39 | */ 40 | public abstract Output compile(Input input) throws IOException; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/CompilerError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.RuneScriptError; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | 14 | /** 15 | * Represents an error that has occurred during any of the compiler phases. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public abstract class CompilerError extends RuneScriptError { 20 | 21 | /** 22 | * The serialisation key of the {@link CompilerError} type. 23 | */ 24 | private static final long serialVersionUID = 5818510240712800528L; 25 | 26 | /** 27 | * The error source code range. 28 | */ 29 | @Getter 30 | private final Span span; 31 | 32 | /** 33 | * Constructs a new {@link CompilerError} type object instance. 34 | * 35 | * @param span the error range in the source code. 36 | * @param message a message describing why the error has occurred. 37 | */ 38 | public CompilerError(Span span, String message) { 39 | super(message); 40 | this.span = span; 41 | } 42 | } -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/Input.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * The input object of a compiler 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class Input { 22 | 23 | /** 24 | * The source files that we want to compile. 25 | */ 26 | @Getter 27 | private final List sourceFiles = new ArrayList<>(); 28 | 29 | /** 30 | * Whether or not we want to run the code generation. 31 | */ 32 | @Getter 33 | @Setter 34 | private boolean runCodeGeneration; 35 | 36 | /** 37 | * Whether or not we should run the ID generation before the code generation. 38 | */ 39 | @Getter 40 | @Setter 41 | private boolean runIdGeneration; 42 | 43 | /** 44 | * Adds the specified {@link SourceFile} to the list of files we want to compile. 45 | * 46 | * @param sourceFile the source file that we want to compile. 47 | */ 48 | public void addSourceFile(SourceFile sourceFile) { 49 | sourceFiles.add(sourceFile); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/error/ErrorReporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.error; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.compiler.CompilerError; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Holds a list of all the errors that are reported by one of the compilation process. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public class ErrorReporter { 22 | 23 | /** 24 | * A list of all the errors that has been reported. 25 | */ 26 | @Getter 27 | private final List errors = new ArrayList<>(); 28 | 29 | /** 30 | * Adds a new error to the errors list of the reporter. 31 | * 32 | * @param error the error to add to the errors list. 33 | */ 34 | public void addError(CompilerError error) { 35 | errors.add(error); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/idmapping/IDManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.idmapping; 9 | 10 | import me.waliedyassen.runescript.type.Type; 11 | 12 | /** 13 | * An interface which is responsible for providing ids for configs or scripts that are being code generated. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public interface IDManager { 18 | 19 | /** 20 | * Attempts to find the script ID with the specified {@code name} and contained by the file with the specified {@code extension}. 21 | * If no script is found, we will create a new ID and assign it to that script. 22 | * 23 | * @param name 24 | * the name of the script. 25 | * @param extension 26 | * the extension of the file which contains the script. 27 | * 28 | * @return the id of the script. 29 | */ 30 | int findOrCreateScriptId(String name, String extension); 31 | 32 | /** 33 | * Attempts to find the id for the script with the specified {@code name}. 34 | * 35 | * @param name 36 | * the name of the script that we want to find the id for. 37 | * @param extension 38 | * 39 | * @return the id of the script that we found. 40 | * 41 | * @throws IllegalArgumentException 42 | * if we failed to find an id for the specified {@code name}. 43 | */ 44 | int findScript(String name, String extension) throws IllegalArgumentException; 45 | } 46 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/lexer/LexicalError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.lexer; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.CompilerError; 12 | 13 | /** 14 | * Represents any error that has occurred during a lexical phase parsing. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LexicalError extends CompilerError { 19 | 20 | /** 21 | * The serialisation key of the {@link LexicalError} type. 22 | */ 23 | private static final long serialVersionUID = -7355707302290328841L; 24 | 25 | /** 26 | * Constructs a new {@link LexicalError} type object instance. 27 | * 28 | * @param span the error source code range. 29 | * @param message a message describing why the error has occurred. 30 | */ 31 | public LexicalError(Span span, String message) { 32 | super(span, message + " at offset:" + span.getBegin()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/lexer/token/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.lexer.token; 9 | 10 | import lombok.Data; 11 | import me.waliedyassen.runescript.commons.document.Element; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | 14 | /** 15 | * Represents a single token in any of our parsers. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @Data 20 | public class Token implements Element { 21 | 22 | /** 23 | * The token kind. 24 | */ 25 | private final K kind; 26 | 27 | /** 28 | * The token source code range. 29 | */ 30 | private final Span span; 31 | 32 | /** 33 | * The token lexeme value. 34 | */ 35 | private final String lexeme; 36 | } 37 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/lexer/token/TokenFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.lexer.token; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | 12 | /** 13 | * A factory class for creating new {@link Token} objects. 14 | * 15 | * @param the "kind" type the token will hold. 16 | * @param the token objects type. 17 | */ 18 | public interface TokenFactory> { 19 | 20 | /** 21 | * Creates a new {@link T token} object with the specified data. 22 | * 23 | * @param span the range of the token in the source document. 24 | * @param kind the kind of the token that we are creating. 25 | * @param lexeme the source code representation of the token. 26 | * @return the created {@link T} object. 27 | */ 28 | T createToken(Span span, K kind, String lexeme); 29 | 30 | /** 31 | * Creates a new erroneous {@link T token} object with the specified data. 32 | * 33 | * @param span the range of the token in the source document. 34 | * @param kind the kind of the token that we are creating. 35 | * @param lexeme the source code representation of the token. 36 | * @return the created {@link T} object. 37 | */ 38 | T createErrorToken(Span span, K kind, String lexeme); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/message/CompilerMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.message; 9 | 10 | /** 11 | * The base class for all of the compiler messages. 12 | * 13 | * @author WaliedK. Yassen 14 | */ 15 | public abstract class CompilerMessage { 16 | // NOOP 17 | } 18 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/message/CompilerMessenger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.message; 9 | 10 | /** 11 | * An interface which acts like a bridge between the compiler and the client that is using the compiler, it provides 12 | * data back to the client such as the script that was just parsed. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public interface CompilerMessenger { 17 | 18 | /** 19 | * Handles the specified {@link CompilerMessage message}. 20 | * 21 | * @param message the message that we want to handle. 22 | */ 23 | void handleCompilerMessage(CompilerMessage message); 24 | } 25 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/parser/SyntaxError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.parser; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.CompilerError; 12 | 13 | /** 14 | * Represents a syntax error. The syntax error occurs when the input text sequence does not match the grammar rule or is 15 | * in the wrong context 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class SyntaxError extends CompilerError { 20 | 21 | /** 22 | * The serialisation key of the {@link SyntaxError} type. 23 | */ 24 | private static final long serialVersionUID = 7930378044181873967L; 25 | 26 | /** 27 | * Constructs a new {@link SyntaxError} type object instance. 28 | * 29 | * @param span 30 | * the source code range which the error occurred within. 31 | * @param message 32 | * the error message explaining why the error has occurred. 33 | */ 34 | public SyntaxError(Span span, String message) { 35 | super(span, message); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/symbol/SymbolList.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.symbol 9 | 10 | class SymbolList { 11 | 12 | private val nameLookup = mutableMapOf() 13 | 14 | fun add(symbol: T) { 15 | check(!nameLookup.containsKey(symbol.name)) { "SymbolList contains another symbol with the same name: ${symbol.name}" } 16 | nameLookup[symbol.name] = symbol 17 | } 18 | 19 | fun remove(name: String) { 20 | nameLookup -= name 21 | } 22 | 23 | fun lookupByName(name: String) = nameLookup[name] 24 | } -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/symbol/impl/ArrayInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.symbol.impl; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.compiler.symbol.Symbol; 13 | import me.waliedyassen.runescript.type.primitive.PrimitiveType; 14 | 15 | /** 16 | * Represents a local array symbol information. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | @RequiredArgsConstructor 21 | @Getter 22 | public final class ArrayInfo extends Symbol { 23 | 24 | /** 25 | * The index of the array. 26 | */ 27 | private final int id; 28 | 29 | /** 30 | * The name of the array. 31 | */ 32 | private final String name; 33 | 34 | /** 35 | * The type of the array. 36 | */ 37 | private final PrimitiveType type; 38 | } 39 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/symbol/impl/GraphicInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.symbol.impl; 9 | 10 | import lombok.EqualsAndHashCode; 11 | import lombok.Getter; 12 | import lombok.RequiredArgsConstructor; 13 | import me.waliedyassen.runescript.compiler.symbol.Symbol; 14 | 15 | /** 16 | * A graphic symbol information in the symbol table. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | @RequiredArgsConstructor 21 | @EqualsAndHashCode(callSuper = true) 22 | @Getter 23 | public final class GraphicInfo extends Symbol { 24 | 25 | /** 26 | * The name of the graphic. 27 | */ 28 | private final String name; 29 | 30 | /** 31 | * The id of the graphic. 32 | */ 33 | private final int id; 34 | } 35 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/compiler/symbol/impl/RuntimeConstantInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.symbol.impl; 9 | 10 | import lombok.EqualsAndHashCode; 11 | import lombok.Getter; 12 | import lombok.RequiredArgsConstructor; 13 | import me.waliedyassen.runescript.compiler.symbol.Symbol; 14 | import me.waliedyassen.runescript.type.primitive.PrimitiveType; 15 | 16 | /** 17 | * The symbol information for a runtime constant value, which is a constant that is replaced at runtime with another value. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @RequiredArgsConstructor 22 | @EqualsAndHashCode(callSuper = true) 23 | @Getter 24 | public final class RuntimeConstantInfo extends Symbol { 25 | 26 | /** 27 | * The name of the constant. 28 | */ 29 | private final String name; 30 | 31 | private final int id; 32 | 33 | /** 34 | * The type of the constant. 35 | */ 36 | private final PrimitiveType type; 37 | 38 | /** 39 | * The value of the constant. 40 | */ 41 | private final Object value; 42 | } 43 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/type/Type.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.type 9 | 10 | import me.waliedyassen.runescript.type.stack.StackType 11 | 12 | /** 13 | * Represents the main interface for our type system. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | interface Type { 18 | 19 | /** 20 | * Returns the signature char code of the type. 21 | * 22 | * @return the signature char code of the type. 23 | */ 24 | val code: Char 25 | 26 | /** 27 | * Returns the representation of the type. 28 | * 29 | * @return the type textual representation. 30 | */ 31 | val representation: String? 32 | 33 | /** 34 | * Returns the stack type of the type. 35 | * 36 | * @return the stack type. 37 | */ 38 | val stackType: StackType? 39 | 40 | /** 41 | * Returns the default value of the type. 42 | * 43 | * @return the default value of this type. 44 | */ 45 | val defaultValue: Any? 46 | } -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/type/stack/StackType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.type.stack; 9 | 10 | /** 11 | * Represents the stack value push/pop type, there are three main types within our frame stack system, which are: an an 12 | * {@code int}, a {@code string} or a {@code long} value. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public enum StackType { 17 | 18 | /** 19 | * The integer stack type. 20 | */ 21 | INT, 22 | 23 | /** 24 | * The string stack type. 25 | */ 26 | STRING, 27 | 28 | /** 29 | * The long stack type. 30 | */ 31 | LONG 32 | } 33 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/util/CollectorsEx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.util; 9 | 10 | import java.util.function.BiConsumer; 11 | import java.util.function.Function; 12 | import java.util.stream.Collector; 13 | import java.util.stream.Stream; 14 | 15 | public final class CollectorsEx { 16 | 17 | // From JDK9 18 | public static 19 | Collector flatMapping(Function> mapper, 20 | Collector downstream) { 21 | BiConsumer downstreamAccumulator = downstream.accumulator(); 22 | return Collector.of(downstream.supplier(), 23 | (r, t) -> { 24 | try (Stream result = mapper.apply(t)) { 25 | if (result != null) 26 | result.sequential().forEach(u -> downstreamAccumulator.accept(r, u)); 27 | } 28 | }, 29 | downstream.combiner(), downstream.finisher(), 30 | downstream.characteristics().toArray(new Collector.Characteristics[0])); 31 | } 32 | 33 | private CollectorsEx(){ 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/util/ReflectionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.util; 9 | 10 | /** 11 | * Contains various utilities for reflection api. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public final class ReflectionUtil { 16 | 17 | /** 18 | * Returns the boxed variant of the specified class type. 19 | * 20 | * @param type 21 | * the class type that we want the boxed variant for. 22 | * 23 | * @return the boxed variant class type or the same class type if there is no boxed variant. 24 | */ 25 | public static Class box(Class type) { 26 | if (type.isPrimitive()) { 27 | if (type == byte.class) { 28 | type = Byte.class; 29 | } else if (type == short.class) { 30 | type = Short.class; 31 | } else if (type == int.class) { 32 | type = Integer.class; 33 | } else if (type == long.class) { 34 | type = Long.class; 35 | } else if (type == boolean.class) { 36 | type = Boolean.class; 37 | } else if (type == char.class) { 38 | type = Character.class; 39 | } else { 40 | throw new IllegalStateException("Unrecognized primitive class type type: " + type.getSimpleName()); 41 | } 42 | } 43 | return type; 44 | } 45 | 46 | private ReflectionUtil() { 47 | // NOOP 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /runescript-commons/src/main/java/me/waliedyassen/runescript/util/StreamUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.util; 9 | 10 | import java.io.DataOutputStream; 11 | import java.io.IOException; 12 | 13 | /** 14 | * Contains various useful utilities for writing to stream. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class StreamUtil { 19 | 20 | /** 21 | * Writes a triple-byte integer value to the specified {@link DataOutputStream stream}. 22 | * 23 | * @param stream 24 | * the stream that we want to write to. 25 | * @param value 26 | * the value that we want to write. 27 | * 28 | * @throws IOException 29 | * if anything occurs while writing the string to the stream. 30 | */ 31 | public static void writeTriByte(DataOutputStream stream, int value) throws IOException { 32 | stream.writeShort(value >> 8); 33 | stream.writeByte(value & 0xff); 34 | } 35 | 36 | /** 37 | * Writes a C-Style string (null terminated string) to the specified {@link DataOutputStream stream}. 38 | * 39 | * @param stream 40 | * the stream that we want to write to. 41 | * @param value 42 | * the value that we want to write. 43 | * 44 | * @throws IOException 45 | * if anything occurs while writing the string to the stream. 46 | */ 47 | public static void writeString(DataOutputStream stream, String value) throws IOException { 48 | stream.writeBytes(value); 49 | stream.writeByte(0); 50 | } 51 | 52 | private StreamUtil() { 53 | // NOOP 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runescript-commons/src/test/java/me/waliedyassen/runescript/commons/document/LineColumnTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.commons.document; 9 | 10 | import org.junit.jupiter.api.Test; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertFalse; 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | class LineColumnTest { 16 | 17 | private static final LineColumn ZERO_ZERO = new LineColumn(0, 0); 18 | private static final LineColumn ZERO_ONE = new LineColumn(0, 1); 19 | 20 | @Test 21 | void testLesserThan() { 22 | assertTrue(LineColumn.MIN.isLesserThan(LineColumn.MAX)); 23 | assertFalse(LineColumn.MAX.isLesserThan(LineColumn.MIN)); 24 | assertTrue(ZERO_ZERO.isLesserThan(ZERO_ONE)); 25 | assertFalse(ZERO_ONE.isLesserThan(ZERO_ZERO)); 26 | } 27 | 28 | @Test 29 | void testGreaterThan() { 30 | assertTrue(LineColumn.MAX.isGreaterThan(LineColumn.MIN)); 31 | assertFalse(LineColumn.MIN.isGreaterThan(LineColumn.MAX)); 32 | assertTrue(ZERO_ONE.isGreaterThan(ZERO_ZERO)); 33 | assertFalse(ZERO_ZERO.isGreaterThan(ZERO_ONE)); 34 | } 35 | 36 | @Test 37 | void testClone() { 38 | assertTrue(LineColumn.MIN.clone().equals(LineColumn.MIN)); 39 | assertFalse(LineColumn.MIN.clone().equals(LineColumn.MAX)); 40 | } 41 | } -------------------------------------------------------------------------------- /runescript-commons/src/test/java/me/waliedyassen/runescript/commons/document/SpanTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package me.waliedyassen.runescript.commons.document; 10 | 11 | import org.junit.jupiter.api.BeforeEach; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; 15 | 16 | class SpanTest { 17 | 18 | Span span; 19 | 20 | @BeforeEach 21 | void prepareRange() { 22 | span = new Span(1,5); 23 | } 24 | 25 | @Test 26 | void testClone() { 27 | assertEquals(span.clone(), span); 28 | } 29 | } -------------------------------------------------------------------------------- /runescript-commons/src/test/java/me/waliedyassen/runescript/type/TupleTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.type; 9 | 10 | import me.waliedyassen.runescript.type.primitive.PrimitiveType; 11 | import me.waliedyassen.runescript.type.tuple.TupleType; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import static org.junit.jupiter.api.Assertions.*; 15 | 16 | class TupleTypeTest { 17 | 18 | private static final TupleType TUPLE = new TupleType(new TupleType(PrimitiveType.INT.INSTANCE, PrimitiveType.STRING.INSTANCE), PrimitiveType.INT.INSTANCE, new TupleType(PrimitiveType.STRING.INSTANCE, PrimitiveType.BOOLEAN.INSTANCE)); 19 | private static final PrimitiveType[] TYPES = new PrimitiveType[]{PrimitiveType.INT.INSTANCE, PrimitiveType.STRING.INSTANCE, PrimitiveType.INT.INSTANCE, PrimitiveType.STRING.INSTANCE, PrimitiveType.BOOLEAN.INSTANCE}; 20 | 21 | @Test 22 | void testFlattening() { 23 | assertArrayEquals(TYPES, TUPLE.getFlattened()); 24 | } 25 | 26 | 27 | @Test 28 | void testEquals() { 29 | assertEquals(TUPLE, new TupleType(TYPES)); 30 | assertNotEquals(TUPLE, new Object()); 31 | assertNotEquals(null, TUPLE); 32 | } 33 | 34 | @Test 35 | void testRepresentation() { 36 | assertEquals("int,int", new TupleType(PrimitiveType.INT.INSTANCE, PrimitiveType.INT.INSTANCE).getRepresentation()); 37 | assertEquals("int,string,string", new TupleType(PrimitiveType.INT.INSTANCE, PrimitiveType.STRING.INSTANCE, new TupleType(PrimitiveType.STRING.INSTANCE)).getRepresentation()); 38 | } 39 | 40 | @Test 41 | void testNulls() { 42 | assertNull(TUPLE.getStackType()); 43 | assertNull(TUPLE.getDefaultValue()); 44 | } 45 | } -------------------------------------------------------------------------------- /runescript-compiler/pom.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 4.0.0 10 | 11 | me.waliedyassen.runescript 12 | runescript-parent 13 | 0.6-SNAPSHOT 14 | 15 | runescript-compiler 16 | RuneScript Compiler 17 | 18 | 19 | me.waliedyassen.runescript 20 | runescript-commons 21 | ${project.version} 22 | 23 | 24 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/CompiledScript.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.compiler.symbol.impl.script.ScriptInfo; 13 | 14 | /** 15 | * Represents a single compiled bytecode script. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @RequiredArgsConstructor 20 | public final class CompiledScript { 21 | 22 | /** 23 | * The name of the script. 24 | */ 25 | @Getter 26 | private final String name; 27 | 28 | // TODO: Add typing to the output. 29 | 30 | /** 31 | * The compiled bytecode data of the script. 32 | */ 33 | @Getter 34 | private final Object output; 35 | 36 | /** 37 | * The info of the script that was compiled. 38 | */ 39 | @Getter 40 | private final ScriptInfo info; 41 | } 42 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/CompiledScriptUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import lombok.Setter; 13 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 14 | import me.waliedyassen.runescript.compiler.syntax.ScriptSyntax; 15 | 16 | /** 17 | * Represents a single compiled unit of a script source file. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @Getter 22 | @Setter 23 | @RequiredArgsConstructor 24 | public final class CompiledScriptUnit extends CompiledUnit { 25 | 26 | /** 27 | * The AST script node of the compiled unit. 28 | */ 29 | private ScriptSyntax syntax; 30 | 31 | /** 32 | * The binary script of the compiled unit. 33 | */ 34 | private BinaryScript binaryScript; 35 | } 36 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/Instruction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen; 9 | 10 | import lombok.*; 11 | import me.waliedyassen.runescript.compiler.codegen.block.Block; 12 | import me.waliedyassen.runescript.compiler.codegen.opcode.Opcode; 13 | 14 | /** 15 | * Represents a single code instruction in our code generator. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @RequiredArgsConstructor 20 | @ToString 21 | public final class Instruction { 22 | 23 | /** 24 | * The opcode of this instruction. 25 | */ 26 | @Getter 27 | @Setter 28 | @NonNull 29 | private Opcode opcode; 30 | 31 | /** 32 | * The operand of the instruction. 33 | */ 34 | @Getter 35 | @Setter 36 | @NonNull 37 | private Object operand; 38 | 39 | /** 40 | * The owner block of this instruction. 41 | */ 42 | @Getter 43 | @Setter 44 | @ToString.Exclude 45 | protected Block owner; 46 | 47 | /** 48 | * Returns the operand casted to an integer value. 49 | * 50 | * @return the integer value of the operand. 51 | */ 52 | public int intOperand() { 53 | return ((Number) operand).intValue(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/LabelGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.block.Label; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.concurrent.atomic.AtomicInteger; 15 | 16 | /** 17 | * Represents the code generator label factory. 18 | * 19 | * @author Walied K. Yassen. 20 | */ 21 | public final class LabelGenerator { 22 | 23 | /** 24 | * The unique name counter. 25 | */ 26 | private final Map counters = new HashMap<>(); 27 | 28 | /** 29 | * The unique shared counter. 30 | */ 31 | private final AtomicInteger shared = new AtomicInteger(); 32 | 33 | /** 34 | * Generates a new unique {@link Label} object. 35 | * 36 | * @param name 37 | * the name of the label. 38 | * 39 | * @return the created {@link Label} object instance. 40 | */ 41 | public Label generate(String name) { 42 | var counter = counters.get(name); 43 | if (counter == null) { 44 | counters.put(name, counter = new AtomicInteger()); 45 | } 46 | return new Label(shared.getAndIncrement(), name + "_" + counter.getAndIncrement()); 47 | } 48 | 49 | /** 50 | * Resets the state of this label generator. 51 | */ 52 | public void reset() { 53 | counters.clear(); 54 | shared.set(0); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/block/Label.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.block; 9 | 10 | import lombok.Data; 11 | import lombok.Getter; 12 | 13 | /** 14 | * Represents a code label, used for branching and jumping to targets. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @Data 19 | public final class Label { 20 | 21 | /** 22 | * The id of the label. 23 | */ 24 | @Getter 25 | private final int id; 26 | 27 | /** 28 | * The name of the label. 29 | */ 30 | @Getter 31 | private final String name; 32 | 33 | /** 34 | * Checks hwether or not this label is the entry label. 35 | * 36 | * @return true if it is otherwise false. 37 | */ 38 | public boolean isEntryLabel() { 39 | // We do it this way because the entry label always has an id of 0 and it is way faster than comparing strings. 40 | return id == 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/local/Local.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.local; 9 | 10 | import lombok.EqualsAndHashCode; 11 | import lombok.Getter; 12 | import lombok.RequiredArgsConstructor; 13 | import me.waliedyassen.runescript.type.Type; 14 | 15 | /** 16 | * Represents a local variable/parameter. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | @RequiredArgsConstructor 21 | @EqualsAndHashCode 22 | public final class Local { 23 | 24 | /** 25 | * The local variable/parameter name. 26 | */ 27 | @Getter 28 | private final String name; 29 | 30 | /** 31 | * The local variable type. 32 | */ 33 | @Getter 34 | private final Type type; 35 | } 36 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/opcode/BasicOpcode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.opcode; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | 13 | /** 14 | * A basic implementation of the {@link Opcode} interface. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @RequiredArgsConstructor 19 | public final class BasicOpcode implements Opcode { 20 | 21 | /** 22 | * The code (or id) of the opcode. 23 | */ 24 | @Getter 25 | private final int code; 26 | 27 | /** 28 | * Whether or not the opcode is large. 29 | */ 30 | @Getter 31 | private final boolean large; 32 | } 33 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/opcode/Opcode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.opcode; 9 | 10 | /** 11 | * Represents a single RuneScript bytecode opcode. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public interface Opcode { 16 | 17 | /** 18 | * Gets the code number of the opcode. 19 | * 20 | * @return the code number of the opcode. 21 | */ 22 | int getCode(); 23 | 24 | /** 25 | * Checks whether or not this opcode is a large opcode. 26 | * 27 | * @return true if it is otherwise false. 28 | */ 29 | boolean isLarge(); 30 | } 31 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/optimizer/BlockOptimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.optimizer; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.block.Block; 11 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 12 | 13 | /** 14 | * Represents an {@link Optimization} that is ran on a block level instead of script.. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public abstract class BlockOptimization extends Optimization { 19 | 20 | /** 21 | * {@inheritDoc} 22 | */ 23 | @Override 24 | public int run(Optimizer optimizer, BinaryScript script) { 25 | var units = 0; 26 | for (var block : script.getBlockList().getBlocks()) { 27 | units += run(optimizer, script, block); 28 | } 29 | return units; 30 | } 31 | 32 | /** 33 | * Runs the optimization on the specified {@link Block}. 34 | * 35 | * @param optimizer the optimizer which is running this optimization. 36 | * @param script the script which the block is located in. 37 | * @param block the block to run on. 38 | * @return the amount of blocks that has been optimised. 39 | */ 40 | public abstract int run(Optimizer optimizer, BinaryScript script, Block block); 41 | } 42 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/optimizer/Optimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.optimizer; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 11 | 12 | /** 13 | * Represents a script optimization that is applied after the code generation and before the code writing. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public abstract class Optimization { 18 | 19 | /** 20 | * Runs the optimization on the specified {@link BinaryScript script}. 21 | * 22 | * @param optimizer 23 | * the optimizer which is running this optimization. 24 | * @param script 25 | * the script to run the optimization on. 26 | * 27 | * @return the amount of units that has been optimized. 28 | */ 29 | public abstract int run(Optimizer optimizer, BinaryScript script); 30 | 31 | /** 32 | * Cleans-up the state from the current run. 33 | * 34 | * @param optimizer 35 | * the optimizer which is running this optimizaiton. 36 | * @param script 37 | * the script we ran the optimization on. 38 | */ 39 | public abstract void clean(Optimizer optimizer, BinaryScript script); 40 | } 41 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/optimizer/impl/DeadBranchOptimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.optimizer.impl; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.block.Block; 11 | import me.waliedyassen.runescript.compiler.codegen.opcode.CoreOpcode; 12 | import me.waliedyassen.runescript.compiler.codegen.optimizer.BlockOptimization; 13 | import me.waliedyassen.runescript.compiler.codegen.optimizer.Optimizer; 14 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 15 | 16 | /** 17 | * Represents a dead branch optimization. 18 | * 19 | * @author Walied K. Y assen 20 | */ 21 | public final class DeadBranchOptimization extends BlockOptimization { 22 | 23 | /** 24 | * {@inheritDoc} 25 | */ 26 | @Override 27 | public int run(Optimizer optimizer, BinaryScript script, Block block) { 28 | var instruction = block.last(); 29 | if (instruction != null && optimizer.is(instruction, CoreOpcode.BRANCH)) { 30 | // We currently define dead branch if it's after a return 31 | // in the distant future, we may want to change that. 32 | var previous = block.previous(instruction); 33 | if (previous == null) { 34 | return 0; 35 | } 36 | if (optimizer.is(previous, CoreOpcode.RETURN)) { 37 | block.remove(instruction); 38 | return 1; 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void clean(Optimizer optimizer, BinaryScript script) { 49 | // NOOP 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/optimizer/impl/NaturalFlowOptimization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.optimizer.impl; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.block.Block; 11 | import me.waliedyassen.runescript.compiler.codegen.block.Label; 12 | import me.waliedyassen.runescript.compiler.codegen.opcode.CoreOpcode; 13 | import me.waliedyassen.runescript.compiler.codegen.optimizer.BlockOptimization; 14 | import me.waliedyassen.runescript.compiler.codegen.optimizer.Optimizer; 15 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 16 | 17 | /** 18 | * Represents the natural flow redundant jumps removal optimizations. 19 | * 20 | * @author Walied K. Yassen 21 | */ 22 | public final class NaturalFlowOptimization extends BlockOptimization { 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | @Override 28 | public int run(Optimizer optimizer, BinaryScript script, Block block) { 29 | var instruction = block.last(); 30 | if (instruction != null && optimizer.is(instruction, CoreOpcode.BRANCH)) { 31 | var label = (Label) instruction.getOperand(); 32 | if (script.getBlockList().isNextTo(block.getLabel(), label)) { 33 | block.remove(instruction); 34 | return 1; 35 | } 36 | } 37 | return 0; 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public void clean(Optimizer optimizer, BinaryScript script) { 45 | // NOOP 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/sw/SwitchCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.sw; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.compiler.codegen.block.Label; 13 | 14 | /** 15 | * A code generated switch case. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @RequiredArgsConstructor 20 | public final class SwitchCase { 21 | 22 | /** 23 | * The keys of the switch case. 24 | */ 25 | @Getter 26 | public final Object[] keys; 27 | 28 | /** 29 | * The label which the switch case will jump to. 30 | */ 31 | @Getter 32 | private final Label label; 33 | } 34 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/sw/SwitchMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.sw; 9 | 10 | import lombok.Getter; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * Represents a code generator switch tables map. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public final class SwitchMap { 21 | 22 | /** 23 | * The registered switch tables. 24 | */ 25 | @Getter 26 | private final Map tables = new HashMap<>(); 27 | 28 | 29 | /** 30 | * Generates a new {@link SwitchTable} object. 31 | * 32 | * @param cases 33 | * the cases of the switch table. 34 | * 35 | * @return the generated {@link SwitchTable} object. 36 | */ 37 | public SwitchTable generateTable(SwitchCase[] cases) { 38 | var switch_table = new SwitchTable(tables.size(), cases); 39 | tables.put(switch_table.getId(), switch_table); 40 | return switch_table; 41 | } 42 | 43 | /** 44 | * Resets the switch table. 45 | */ 46 | public void reset() { 47 | tables.clear(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/sw/SwitchTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.sw; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | 13 | /** 14 | * Represents a generated switch table. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @RequiredArgsConstructor 19 | public final class SwitchTable { 20 | 21 | /** 22 | * The id of the switch table. 23 | */ 24 | @Getter 25 | private final int id; 26 | 27 | /** 28 | * The cases that are within this switch table. 29 | */ 30 | @Getter 31 | private final SwitchCase[] cases; 32 | 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | @Override 38 | public String toString() { 39 | return "switch_" + id; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/writer/CodeWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.writer; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.script.BinaryScript; 11 | 12 | /** 13 | * Represents a script code writer, it takes {@link BinaryScript} object and converts (write) it to a different form which is 14 | * specified by the implementation of this type. 15 | * 16 | * @param 17 | * the return type for {@link #write(BinaryScript)} method. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public abstract class CodeWriter { 22 | 23 | /** 24 | * Performs the code writing for the specified {@link BinaryScript} object. 25 | * 26 | * @param script 27 | * the script to perform the code writing for. 28 | * 29 | * @return the output of the code writing operation, defined by the implementation of this type. 30 | */ 31 | public abstract R write(BinaryScript script); 32 | } 33 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/codegen/writer/bytecode/BytecodeInstruction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.writer.bytecode; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | 13 | /** 14 | * Represents a byte code instruction. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @RequiredArgsConstructor 19 | public final class BytecodeInstruction { 20 | 21 | /** 22 | * The opcode number of the instruction. 23 | */ 24 | @Getter 25 | private final int opcode; 26 | 27 | /** 28 | * Whether or not this instruction uses a large integer operand. 29 | */ 30 | @Getter 31 | private final boolean large; 32 | 33 | /** 34 | * The operand of this instruction. 35 | */ 36 | @Getter 37 | private final Object operand; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/lexer/Lexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.lexer; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.compiler.lexer.table.LexicalTable; 12 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 13 | import me.waliedyassen.runescript.compiler.lexer.token.Token; 14 | import me.waliedyassen.runescript.compiler.lexer.tokenizer.Tokenizer; 15 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken; 16 | 17 | /** 18 | * Represents the script parser {@link LexerBase} implementation. 19 | * 20 | * @author Walied K. Yassen 21 | */ 22 | public final class Lexer extends LexerBase { 23 | 24 | /** 25 | * The lexical table which the lexer is using. 26 | */ 27 | @Getter 28 | private final LexicalTable lexicalTable; 29 | 30 | /** 31 | * Constructs a new {@link Lexer} type object instance. 32 | * 33 | * @param tokenizer the tokenizer which we will take all the {@link Token} objects from. 34 | */ 35 | public Lexer(Tokenizer tokenizer) { 36 | super(tokenizer.range()); 37 | this.lexicalTable = tokenizer.getTable(); 38 | tokens: 39 | do { 40 | var token = tokenizer.parse(); 41 | switch (token.getKind()) { 42 | case EOF: 43 | break tokens; 44 | case COMMENT: 45 | continue tokens; 46 | default: 47 | tokens.add(token); 48 | } 49 | } while (true); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/lexer/tokenizer/Mode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.lexer.tokenizer; 9 | 10 | /** 11 | * Represents a parser mode, it tells what we are currently parsing whether it is string literal, integral literal, or 12 | * something else. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public enum Mode { 17 | /** 18 | * Indicates that the parser is currently not parsing anything. 19 | */ 20 | NONE, 21 | 22 | /** 23 | * Indicates that the parser is currently parsing an identifier. 24 | */ 25 | IDENTIFIER, 26 | 27 | /** 28 | * Indicates that the parser is currently parsing a string literal. 29 | */ 30 | STRING_LITERAL, 31 | 32 | /** 33 | * Indicates that the parser is currently parsing an interpolated string literal. 34 | */ 35 | ISTRING_LITERAL, 36 | 37 | /** 38 | * Indicates that the parser is currently parsing a number literal. 39 | */ 40 | NUMBER_LITERAL, 41 | 42 | /** 43 | * Indicates that the parser is currently parsing a hexadecimal literal. 44 | */ 45 | HEX_LITERAL, 46 | 47 | /** 48 | * Indicates that the parser is currently parsing a coord literal. 49 | */ 50 | COORDGRID_LITERAL, 51 | 52 | /** 53 | * Indicates that the parser is currently parsing a line comment. 54 | */ 55 | LINE_COMMENT, 56 | 57 | /** 58 | * Indicates that the parser is currently parsing a multi-line comment. 59 | */ 60 | MULTI_COMMENT 61 | } -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/message/impl/SyntaxDoneMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.message.impl; 9 | 10 | import lombok.Data; 11 | import lombok.EqualsAndHashCode; 12 | import me.waliedyassen.runescript.compiler.message.CompilerMessage; 13 | import me.waliedyassen.runescript.compiler.syntax.ScriptSyntax; 14 | 15 | /** 16 | * A message which is fired when a compiler have just finished parsing 17 | * the syntax of the input. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @Data 22 | @EqualsAndHashCode(callSuper = true) 23 | public final class SyntaxDoneMessage extends CompilerMessage { 24 | 25 | /** 26 | * The identifier of the script that we parsed. 27 | */ 28 | private final Object identifier; 29 | 30 | /** 31 | * The AST of the script that we parsed. 32 | */ 33 | private final ScriptSyntax script; 34 | } 35 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/semantics/SemanticError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.semantics; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.compiler.CompilerError; 12 | import me.waliedyassen.runescript.compiler.syntax.ScriptSyntax; 13 | import me.waliedyassen.runescript.compiler.syntax.SyntaxBase; 14 | 15 | /** 16 | * Represents a compiler error that occurred during the semantic analysis time. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public final class SemanticError extends CompilerError { 21 | 22 | /** 23 | * The owner script of the semantic error. 24 | */ 25 | @Getter 26 | private final ScriptSyntax script; 27 | 28 | /** 29 | * Constructs a new {@link CompilerError} type object instance. 30 | * 31 | * @param node the node which error occurred in. 32 | * @param message the message describing why the error has occurred. 33 | */ 34 | public SemanticError(SyntaxBase node, String message) { 35 | super(node.getSpan(), message); 36 | script = (ScriptSyntax) node.selectParent(owner -> owner instanceof ScriptSyntax); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/semantics/typecheck/TypeCheckAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.semantics.typecheck; 9 | 10 | /** 11 | * Represents the action that should be performed when returned from a child type checking. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public enum TypeCheckAction { 16 | 17 | /** 18 | * Skip the type checking for the parent node and make the parent node skip if necessary. 19 | */ 20 | SKIP, 21 | 22 | /** 23 | * Continue the type checking normally. 24 | */ 25 | CONTINUE; 26 | 27 | /** 28 | * Checks whether or not this action is a continue action. 29 | * 30 | * @return true if it is otherwise false. 31 | */ 32 | public boolean isContinue() { 33 | return this == CONTINUE; 34 | } 35 | } -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/symbol/impl/script/Annotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.symbol.impl.script; 9 | 10 | import lombok.EqualsAndHashCode; 11 | import lombok.Getter; 12 | import lombok.RequiredArgsConstructor; 13 | 14 | /** 15 | * Represents a single script annotation. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @RequiredArgsConstructor 20 | @EqualsAndHashCode 21 | public final class Annotation { 22 | 23 | /** 24 | * The name of the annotation. 25 | */ 26 | @Getter 27 | private final String name; 28 | 29 | /** 30 | * The value of the annotation. 31 | */ 32 | @Getter 33 | private final int value; 34 | } 35 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/SyntaxToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 12 | import me.waliedyassen.runescript.compiler.lexer.token.Token; 13 | 14 | /** 15 | * A token that is used in the Syntax Tree. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class SyntaxToken extends Token { 20 | 21 | /** 22 | * Constructs a new {@link SyntaxToken} type object instance. 23 | * 24 | * @param kind the kind of the token. 25 | * @param span the source code range of the token. 26 | * @param lexeme the raw text representation of the token. 27 | */ 28 | public SyntaxToken(Kind kind, Span span, String lexeme) { 29 | super(kind, span, lexeme); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/TypeSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | 14 | /** 15 | * @author Walied K. Yassen 16 | */ 17 | public final class TypeSyntax extends Syntax { 18 | 19 | /** 20 | * The token of the type. 21 | */ 22 | @Getter 23 | private final SyntaxToken token; 24 | 25 | /** 26 | * Constructs a new {@link SyntaxToken} type object instance. 27 | * 28 | * @param span the source c ode range of the syntax. 29 | * @param token the syntax token of the type. 30 | */ 31 | public TypeSyntax(Span span, SyntaxToken token) { 32 | super(span); 33 | this.token = token; 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public T accept(SyntaxVisitor visitor) { 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ArrayElementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | import me.waliedyassen.runescript.compiler.symbol.impl.ArrayInfo; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * Represents an array expression. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ArrayElementSyntax extends ExpressionSyntax { 22 | 23 | /** 24 | * The name of the array. 25 | */ 26 | @Getter 27 | private final IdentifierSyntax name; 28 | 29 | /** 30 | * The the element index in the array. 31 | */ 32 | @Getter 33 | private final ExpressionSyntax index; 34 | 35 | /** 36 | * The array symbol information. 37 | */ 38 | @Getter 39 | @Setter 40 | private ArrayInfo array; 41 | 42 | /** 43 | * Constructs a new {@link ArrayElementSyntax} type object instance. 44 | * 45 | * @param span 46 | * the node source code range. 47 | * @param name 48 | * the name of the array. 49 | * @param index 50 | * the element index in the array. 51 | */ 52 | public ArrayElementSyntax(Span span, IdentifierSyntax name, ExpressionSyntax index) { 53 | super(span); 54 | this.name = addChild(name); 55 | this.index = addChild(index); 56 | } 57 | 58 | /** 59 | * {@inheritDoc} 60 | */ 61 | @Override 62 | public T accept(SyntaxVisitor visitor) { 63 | return visitor.visit(this); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ArrayVariableSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | import me.waliedyassen.runescript.compiler.symbol.impl.ArrayInfo; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * An array variable with an index AST expression node. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ArrayVariableSyntax extends VariableSyntax { 22 | 23 | /** 24 | * The index expression of the array. 25 | */ 26 | @Getter 27 | private final ExpressionSyntax index; 28 | 29 | /** 30 | * The array info which is resolved at type checking phase. 31 | */ 32 | @Getter 33 | @Setter 34 | private ArrayInfo arrayInfo; 35 | 36 | /** 37 | * Constructs a new {@link ArrayVariableSyntax} type object instance. 38 | * 39 | * @param span 40 | * the node source code range. 41 | * @param name 42 | * the name of the variable. 43 | * @param index 44 | * the index of the array. 45 | */ 46 | public ArrayVariableSyntax(Span span, IdentifierSyntax name, ExpressionSyntax index) { 47 | super(span, name); 48 | this.index = index; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public T accept(SyntaxVisitor visitor) { 56 | return visitor.visit(this); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/CalcSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | 14 | /** 15 | * Represents an arithmetic calculate expression. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class CalcSyntax extends ExpressionSyntax { 20 | 21 | /** 22 | * The expression of the calc. 23 | */ 24 | @Getter 25 | private final ParExpressionSyntax expression; 26 | 27 | /** 28 | * Constructs a new {@link ExpressionSyntax} type object instance. 29 | * 30 | * @param span 31 | * the expression source code range. 32 | */ 33 | public CalcSyntax(Span span, ParExpressionSyntax expression) { 34 | super(span); 35 | this.expression = addChild(expression); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public T accept(SyntaxVisitor visitor) { 43 | return visitor.visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ConcatenationSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | 14 | /** 15 | * Represents an interpolated string concatenation node. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class ConcatenationSyntax extends ExpressionSyntax { 20 | 21 | /** 22 | * The expressions of the concatenation. 23 | */ 24 | @Getter 25 | private final ExpressionSyntax[] expressions; 26 | 27 | /** 28 | * Constructs a new {@link ConcatenationSyntax} type object instance. 29 | * 30 | * @param span 31 | * the node source code range. 32 | * @param expressions 33 | * the expressions of the concatenation. 34 | */ 35 | public ConcatenationSyntax(Span span, ExpressionSyntax[] expressions) { 36 | super(span); 37 | this.expressions = addChild(expressions); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public T accept(SyntaxVisitor visitor) { 45 | return visitor.visit(this); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ConstantSyntax.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr 9 | 10 | import me.waliedyassen.runescript.commons.document.Span 11 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor 13 | 14 | /** 15 | * Represents a constant node, a constant is temporal "variable" that will be replaced with it's value in the 16 | * compile-time. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | class ConstantSyntax(span: Span, val caretToken: SyntaxToken, val name: IdentifierSyntax) : ExpressionSyntax(span) { 21 | 22 | var value: Any? = null 23 | 24 | init { 25 | addChild(name) 26 | } 27 | 28 | override fun accept(visitor: SyntaxVisitor): T = visitor.visit(this) 29 | } -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/DynamicSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import lombok.ToString; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 14 | 15 | /** 16 | * Represents a dynamic expression that will be resolved at a latter phase in compiling. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | @ToString 21 | public final class DynamicSyntax extends ExpressionSyntax { 22 | 23 | /** 24 | * The dynamic name. 25 | */ 26 | @Getter 27 | private final IdentifierSyntax name; 28 | 29 | /** 30 | * Constructs a new {@link ExpressionSyntax} type object instance. 31 | * 32 | * @param span 33 | * the expression source code range. 34 | * @param name 35 | * the dynamic name. 36 | */ 37 | public DynamicSyntax(Span span, IdentifierSyntax name) { 38 | super(span); 39 | this.name = addChild(name); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public T accept(SyntaxVisitor visitor) { 47 | return visitor.visit(this); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ExpressionSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.Syntax; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | 14 | /** 15 | * Represents an expression node, all the language expressions must be subclasses of this class. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public abstract class ExpressionSyntax extends Syntax { 20 | 21 | /** 22 | * Constructs a new {@link ExpressionSyntax} type object instance. 23 | * 24 | * @param span the expression source code range. 25 | */ 26 | public ExpressionSyntax(Span span) { 27 | super(span); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public abstract T accept(SyntaxVisitor visitor); 35 | } 36 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/IdentifierSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import lombok.ToString; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * Represents an identifier node, an identifier is any word within the document that is not a keyword. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @ToString 22 | public final class IdentifierSyntax extends ExpressionSyntax { 23 | 24 | /** 25 | * The token of the identifier. 26 | */ 27 | @Getter 28 | private final SyntaxToken token; 29 | 30 | /** 31 | * Constructs a new {@link IdentifierSyntax} type object instance. 32 | * 33 | * @param span the identifier source code range. 34 | * @param token the token of the identifier. 35 | */ 36 | public IdentifierSyntax(Span span, SyntaxToken token) { 37 | super(span); 38 | this.token = token; 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public T accept(SyntaxVisitor visitor) { 46 | return null; 47 | } 48 | 49 | /** 50 | * Returns the text of the identifier. 51 | * 52 | * @return the text of the identifier. 53 | */ 54 | public String getText() { 55 | return token.getLexeme(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/ScopedVariableSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | import me.waliedyassen.runescript.compiler.util.VariableScope; 14 | 15 | 16 | /** 17 | * A scoped variable AST expression node. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ScopedVariableSyntax extends VariableSyntax { 22 | 23 | /** 24 | * The scope of the variable. 25 | */ 26 | @Getter 27 | private final VariableScope scope; 28 | 29 | /** 30 | * Constructs a new {@link ScopedVariableSyntax} type object instance. 31 | * 32 | * @param span 33 | * the node source code range. 34 | * @param scope 35 | * the scope of the varaible. 36 | * @param name 37 | * the name of the variable. 38 | */ 39 | public ScopedVariableSyntax(Span span, VariableScope scope, IdentifierSyntax name) { 40 | super(span, name); 41 | this.scope = scope; 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public T accept(SyntaxVisitor visitor) { 49 | return visitor.visit(this); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/VariableExpressionSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import lombok.ToString; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 14 | import me.waliedyassen.runescript.compiler.util.VariableScope; 15 | 16 | /** 17 | * Represents an AST variable expression. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @ToString 22 | public final class VariableExpressionSyntax extends ExpressionSyntax { 23 | 24 | /** 25 | * The scope of the variable. 26 | */ 27 | @Getter 28 | private final VariableScope scope; 29 | 30 | /** 31 | * The name of the variable. 32 | */ 33 | @Getter 34 | private final IdentifierSyntax name; 35 | 36 | /** 37 | * Constructs a new {@link VariableExpressionSyntax} type object instance. 38 | * 39 | * @param span 40 | * the expression source code range. 41 | * @param scope 42 | * the scope of the variable. 43 | * @param name 44 | * the name of the variable. 45 | */ 46 | public VariableExpressionSyntax(Span span, VariableScope scope, IdentifierSyntax name) { 47 | super(span); 48 | this.scope = scope; 49 | this.name = addChild(name); 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public T accept(SyntaxVisitor visitor) { 57 | return visitor.visit(this); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/VariableSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | 13 | /** 14 | * The base class for all of the AST variable nodes. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public abstract class VariableSyntax extends ExpressionSyntax { 19 | 20 | /** 21 | * The name of the variable. 22 | */ 23 | @Getter 24 | private final IdentifierSyntax name; 25 | 26 | /** 27 | * Constructs a new {@link VariableSyntax} type object instance. 28 | * 29 | * @param span 30 | * the node source code range. 31 | * @param name 32 | * the name of the variable. 33 | */ 34 | public VariableSyntax(Span span, IdentifierSyntax name) { 35 | super(span); 36 | this.name = name; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralBooleanSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | 13 | /** 14 | * Represents a boolean literal expression node. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LiteralBooleanSyntax extends LiteralExpressionSyntax { 19 | 20 | /** 21 | * Construct a new {@link LiteralBooleanSyntax} type object instance. 22 | * 23 | * @param span the node source code range. 24 | * @param value the boolean literal value 25 | */ 26 | public LiteralBooleanSyntax(Span span, Boolean value) { 27 | super(span, value); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public T accept(SyntaxVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralCoordgridSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | 13 | /** 14 | * Represents a coordgrid literal expression node. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LiteralCoordgridSyntax extends LiteralExpressionSyntax { 19 | 20 | /** 21 | * Constructs a new {@link LiteralCoordgridSyntax} type object instance. 22 | * 23 | * @param span the node source code range. 24 | * @param value the value of the literal. 25 | */ 26 | public LiteralCoordgridSyntax(Span span, int value) { 27 | super(span, value); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public T accept(SyntaxVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralExpressionSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.expr.ExpressionSyntax; 13 | 14 | /** 15 | * Represents a literal expression node. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public abstract class LiteralExpressionSyntax extends ExpressionSyntax { 20 | 21 | /** 22 | * The value of the literal. 23 | */ 24 | @Getter 25 | private final T value; 26 | 27 | /** 28 | * Constructs a new {@link LiteralExpressionSyntax} type object instance. 29 | * 30 | * @param span the node source code range. 31 | * @param value the value of the literal. 32 | */ 33 | LiteralExpressionSyntax(Span span, T value) { 34 | super(span); 35 | this.value = value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralIntegerSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | 13 | /** 14 | * Represents an integer literal expression node. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LiteralIntegerSyntax extends LiteralNumberSyntax { 19 | 20 | /** 21 | * Constructs a new {@link LiteralIntegerSyntax} type object instance. 22 | * 23 | * @param span the node source code range. 24 | * @param value the value of the literal. 25 | */ 26 | public LiteralIntegerSyntax(Span span, Integer value) { 27 | super(span, value); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public T accept(SyntaxVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralLongSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | 13 | /** 14 | * Represents a long integer literal expression node. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LiteralLongSyntax extends LiteralNumberSyntax { 19 | 20 | /** 21 | * Constructs a new {@link LiteralLongSyntax} type object instance. 22 | * 23 | * @param span the node source code range. 24 | * @param value the value of the literal. 25 | */ 26 | public LiteralLongSyntax(Span span, Long value) { 27 | super(span, value); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public T accept(SyntaxVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralNullSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 13 | import me.waliedyassen.runescript.compiler.lexer.token.Token; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * The Syntax Tree element for the null literal syntax. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class LiteralNullSyntax extends LiteralExpressionSyntax { 22 | 23 | /** 24 | * The word token of the null keyword. 25 | */ 26 | @Getter 27 | private final Token wordToken; 28 | 29 | /** 30 | * Constructs a new {@link LiteralNullSyntax} type object instance. 31 | * 32 | * @param span the expression source code range. 33 | * @param wordToken the word token of the null keyword. 34 | */ 35 | public LiteralNullSyntax(Span span, Token wordToken) { 36 | super(span, null); 37 | this.wordToken = wordToken; 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public T accept(SyntaxVisitor visitor) { 45 | return visitor.visit(this); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralNumberSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | 12 | /** 13 | * Represents a number literal expression node. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | abstract class LiteralNumberSyntax extends LiteralExpressionSyntax { 18 | 19 | /** 20 | * Constructs a new {@link LiteralNumberSyntax} type object instance. 21 | * 22 | * @param span the node source code range. 23 | * @param number the value of the literal. 24 | */ 25 | LiteralNumberSyntax(Span span, T number) { 26 | super(span, number); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralStringSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | 13 | /** 14 | * Represents a string expression node. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class LiteralStringSyntax extends LiteralExpressionSyntax { 19 | 20 | /** 21 | * Constructs a new {@link LiteralStringSyntax} type object instance. 22 | * 23 | * @param span the node source code range. 24 | * @param value the value of the literal. 25 | */ 26 | public LiteralStringSyntax(Span span, String value) { 27 | super(span, value); 28 | } 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public T accept(SyntaxVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/expr/literal/LiteralTypeSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.expr.literal; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 12 | import me.waliedyassen.runescript.type.primitive.PrimitiveType; 13 | 14 | /** 15 | * The Syntax Tree element for the type literal syntax. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class LiteralTypeSyntax extends LiteralExpressionSyntax { 20 | 21 | /** 22 | * Constructs a new {@link LiteralExpressionSyntax} type object instance. 23 | * 24 | * @param span the node source code range. 25 | * @param value the value of the literal. 26 | */ 27 | public LiteralTypeSyntax(Span span, PrimitiveType value) { 28 | super(span, value); 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public T accept(SyntaxVisitor visitor) { 36 | return visitor.visit(this); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/stmt/ErrorStatementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.stmt; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 12 | import me.waliedyassen.runescript.compiler.lexer.token.Token; 13 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 14 | 15 | public final class ErrorStatementSyntax extends StatementSyntax { 16 | 17 | private final Token token; 18 | private final Token semicolon; 19 | 20 | public ErrorStatementSyntax(Span span, Token token, Token semicolon) { 21 | super(span); 22 | this.token = token; 23 | this.semicolon = semicolon; 24 | } 25 | 26 | @Override 27 | public T accept(SyntaxVisitor visitor) { 28 | return null; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/stmt/ExpressionStatementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.stmt; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken; 13 | import me.waliedyassen.runescript.compiler.syntax.expr.ExpressionSyntax; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * Represents an expression statement. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ExpressionStatementSyntax extends StatementSyntax { 22 | 23 | /** 24 | * The token of the semicolon. 25 | */ 26 | @Getter 27 | private final SyntaxToken semicolonToken; 28 | 29 | /** 30 | * the expression of the statement. 31 | */ 32 | @Getter 33 | private final ExpressionSyntax expression; 34 | 35 | /** 36 | * Construct a new {@link StatementSyntax} type object instance. 37 | * 38 | * @param span the node source code range. 39 | * @param semicolonToken the token of the semicolon. 40 | * @param expression the statement expression. 41 | */ 42 | public ExpressionStatementSyntax(Span span, SyntaxToken semicolonToken, ExpressionSyntax expression) { 43 | super(span); 44 | this.semicolonToken = semicolonToken; 45 | this.expression = addChild(expression); 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public T accept(SyntaxVisitor visitor) { 53 | return visitor.visit(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/stmt/StatementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.stmt; 9 | 10 | import me.waliedyassen.runescript.commons.document.Span; 11 | import me.waliedyassen.runescript.compiler.syntax.Syntax; 12 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 13 | 14 | /** 15 | * Represents a code statement in the Abstract Syntax Tree. A code statement can be anything that represents an action 16 | * in code, such as perform a script execution, or execute another statement based on a given condition (if-while-for 17 | * blocks). 18 | *

19 | * This class is the base class for all of our statement types. Any statement must extend this class to be recognised by 20 | * our Abstract Syntax Tree. 21 | * 22 | * @author Walied K. Yassen 23 | */ 24 | public abstract class StatementSyntax extends Syntax { 25 | 26 | /** 27 | * Construct a new {@link StatementSyntax} type object instance. 28 | * 29 | * @param span the node source code range. 30 | */ 31 | public StatementSyntax(Span span) { 32 | super(span); 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public abstract T accept(SyntaxVisitor visitor); 40 | } 41 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/stmt/loop/BreakStatementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.stmt.loop; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken; 13 | import me.waliedyassen.runescript.compiler.syntax.stmt.StatementSyntax; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * The Syntax Tree element for the break loop control statement syntax. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class BreakStatementSyntax extends StatementSyntax { 22 | 23 | /** 24 | * The token of the control keyword. 25 | */ 26 | @Getter 27 | private final SyntaxToken controlToken; 28 | 29 | /** 30 | * The token of the semicolon. 31 | */ 32 | @Getter 33 | private final SyntaxToken semicolonToken; 34 | 35 | /** 36 | * Construct a new {@link BreakStatementSyntax} type object instance. 37 | * 38 | * @param span the node source code range. 39 | * @param controlToken the token of the control keyword. 40 | * @param semicolonToken the token of the semicolon. 41 | */ 42 | public BreakStatementSyntax(Span span, SyntaxToken controlToken, SyntaxToken semicolonToken) { 43 | super(span); 44 | this.controlToken = controlToken; 45 | this.semicolonToken = semicolonToken; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public T accept(SyntaxVisitor visitor) { 53 | return visitor.visit(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/syntax/stmt/loop/ContinueStatementSyntax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.syntax.stmt.loop; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.commons.document.Span; 12 | import me.waliedyassen.runescript.compiler.syntax.SyntaxToken; 13 | import me.waliedyassen.runescript.compiler.syntax.stmt.StatementSyntax; 14 | import me.waliedyassen.runescript.compiler.syntax.visitor.SyntaxVisitor; 15 | 16 | /** 17 | * The Syntax Tree element for the continue loop control statement syntax. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ContinueStatementSyntax extends StatementSyntax { 22 | 23 | /** 24 | * The toke nof the control keyword. 25 | */ 26 | @Getter 27 | private final SyntaxToken controlToken; 28 | 29 | /** 30 | * The token of the semicolon. 31 | */ 32 | @Getter 33 | private final SyntaxToken semicolon; 34 | 35 | /** 36 | * Construct a new {@link ContinueStatementSyntax} type object instance. 37 | * 38 | * @param span the node source code range. 39 | * @param controlToken the token of the control keyword. 40 | * @param semicolon the token of the semicolon. 41 | */ 42 | public ContinueStatementSyntax(Span span, SyntaxToken controlToken, SyntaxToken semicolon) { 43 | super(span); 44 | this.controlToken = controlToken; 45 | this.semicolon = semicolon; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public T accept(SyntaxVisitor visitor) { 53 | return visitor.visit(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /runescript-compiler/src/main/java/me/waliedyassen/runescript/compiler/util/VariableScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.util; 9 | 10 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 11 | 12 | /** 13 | * Represents a variable scope, it tells from where the variable can be accessed. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public enum VariableScope { 18 | 19 | /** 20 | * The variable is only available within the script its declared in. 21 | */ 22 | LOCAL, 23 | 24 | /** 25 | * The variable is available in any script. 26 | */ 27 | GLOBAL; 28 | 29 | /** 30 | * Attempts to find the {@link VariableScope} that is associated with the specified token {@link Kind kind}. 31 | * 32 | * @param kind 33 | * the scope token kind. 34 | * 35 | * @return the {@link VariableScope} if it was found otherwise {@code null}. 36 | */ 37 | public static VariableScope forKind(Kind kind) { 38 | switch (kind) { 39 | case DOLLAR: 40 | return LOCAL; 41 | case MOD: 42 | return GLOBAL; 43 | default: 44 | return null; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/TestHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.Instruction; 11 | import me.waliedyassen.runescript.compiler.codegen.InstructionMap; 12 | import me.waliedyassen.runescript.compiler.codegen.opcode.CoreOpcode; 13 | 14 | public final class TestHelper { 15 | 16 | public static Instruction dummyInstruction() { 17 | return new Instruction(dummyOpcode(), 0); 18 | } 19 | 20 | public static InstructionMap.MappedOpcode dummyOpcode() { 21 | return new InstructionMap.MappedOpcode(CoreOpcode.POP_INT_DISCARD, 0, true); 22 | } 23 | 24 | private TestHelper() { 25 | // NOOP 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/codegen/InstructionMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.opcode.CoreOpcode; 11 | import org.junit.jupiter.api.Test; 12 | 13 | import static org.junit.jupiter.api.Assertions.*; 14 | 15 | class InstructionMapTest { 16 | 17 | @Test 18 | void testReady() { 19 | var map = new InstructionMap(); 20 | assertFalse(map.isReady()); 21 | for (var opcode : CoreOpcode.values()) { 22 | map.registerCore(opcode, opcode.ordinal(), opcode.isLargeOperand()); 23 | } 24 | assertTrue(map.isReady()); 25 | } 26 | 27 | @Test 28 | void testLookup() { 29 | var map = new InstructionMap(); 30 | for (var opcode : CoreOpcode.values()) { 31 | map.registerCore(opcode, opcode.ordinal(), opcode.isLargeOperand()); 32 | } 33 | for (var opcode : CoreOpcode.values()) { 34 | var mapped = map.lookup(opcode); 35 | assertNotNull(mapped); 36 | assertEquals(opcode, mapped.getOpcode()); 37 | assertEquals(opcode.ordinal(), mapped.getCode()); 38 | assertEquals(opcode.isLargeOperand(), mapped.isLarge()); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/codegen/LabelGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen; 9 | 10 | import org.junit.jupiter.api.Test; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals; 13 | 14 | class LabelGeneratorTest { 15 | 16 | @Test 17 | void testGenerate() { 18 | var generator = new LabelGenerator(); 19 | assertEquals(0, generator.generate("test").getId()); 20 | assertEquals(1, generator.generate("test").getId()); 21 | assertEquals(2, generator.generate("dummy").getId()); 22 | assertEquals("test_2", generator.generate("test").getName()); 23 | } 24 | 25 | @Test 26 | void testReset() { 27 | var generator = new LabelGenerator(); 28 | assertEquals(0, generator.generate("test").getId()); 29 | generator.reset(); 30 | assertEquals(0, generator.generate("test").getId()); 31 | } 32 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/codegen/block/BlockMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.block; 9 | 10 | import me.waliedyassen.runescript.compiler.codegen.LabelGenerator; 11 | import org.junit.jupiter.api.BeforeAll; 12 | import org.junit.jupiter.api.Test; 13 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; 15 | import static org.junit.jupiter.api.Assertions.assertNotNull; 16 | 17 | class BlockMapTest { 18 | 19 | static LabelGenerator labelGenerator; 20 | 21 | @BeforeAll 22 | static void setupLabelGenerator() { 23 | labelGenerator = new LabelGenerator(); 24 | } 25 | 26 | @Test 27 | void testGenerate() { 28 | var map = new BlockMap(); 29 | var label = labelGenerator.generate("test"); 30 | assertEquals(map.generate(label).getLabel(), label); 31 | label = labelGenerator.generate("test"); 32 | assertNotNull(map.newBlock(label)); 33 | assertEquals(map.generate(label).getLabel(), label); 34 | assertEquals(2, map.getBlocks().size()); 35 | 36 | } 37 | 38 | @Test 39 | void resetReset() { 40 | var map = new BlockMap(); 41 | map.generate(labelGenerator.generate("test")); 42 | map.reset(); 43 | assertEquals(0, map.getBlocks().size()); 44 | } 45 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/codegen/block/LabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.block; 9 | 10 | import org.junit.jupiter.api.Test; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertFalse; 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | class LabelTest { 16 | 17 | @Test 18 | void testEntryLabel() { 19 | assertTrue(new Label(0, "entry").isEntryLabel()); 20 | assertFalse(new Label(1, "block").isEntryLabel()); 21 | } 22 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/codegen/opcode/CoreOpcodeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.codegen.opcode; 9 | 10 | import org.junit.jupiter.api.Test; 11 | 12 | import static org.junit.jupiter.api.Assertions.assertFalse; 13 | import static org.junit.jupiter.api.Assertions.assertTrue; 14 | 15 | class CoreOpcodeTest { 16 | 17 | @Test 18 | void testLargeOperand() { 19 | for (var opcode : CoreOpcode.values()) { 20 | switch (opcode){ 21 | case RETURN: 22 | case POP_INT_DISCARD: 23 | case POP_STRING_DISCARD: 24 | case ADD: 25 | case SUB: 26 | case MUL: 27 | case DIV: 28 | case MOD: 29 | case AND: 30 | case OR: 31 | assertFalse(opcode.isLargeOperand()); 32 | break; 33 | default: 34 | assertTrue(opcode.isLargeOperand()); 35 | break; 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/error/ThrowingErrorReporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.error; 9 | 10 | import me.waliedyassen.runescript.compiler.CompilerError; 11 | 12 | public final class ThrowingErrorReporter extends ErrorReporter { 13 | 14 | @Override 15 | public void addError(CompilerError error) { 16 | throw error; 17 | } 18 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/java/me/waliedyassen/runescript/compiler/util/VariableScopeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.compiler.util; 9 | 10 | import me.waliedyassen.runescript.compiler.lexer.token.Kind; 11 | import org.junit.jupiter.api.Test; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | 15 | class VariableScopeTest { 16 | 17 | @Test 18 | void testLookup(){ 19 | assertEquals(VariableScope.LOCAL, VariableScope.forKind(Kind.DOLLAR)); 20 | assertEquals(VariableScope.GLOBAL, VariableScope.forKind(Kind.MOD)); 21 | } 22 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/codegen/local_01.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,basic_defines](boolean $bool_param, int $int_param, string $string_param, long $long_param) 2 | def_int $my_int = 1234; 3 | def_string $my_string = "test"; 4 | def_boolean $my_true_bool = true; 5 | def_long $my_long = 1234L; 6 | def_boolean $my_false_bool = false; -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/codegen/operator_bitwise_and.rs2: -------------------------------------------------------------------------------- 1 | [proc,and](int $a, int $b)(int) 2 | return(calc($a & $b)); -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/codegen/operator_bitwise_or.rs2: -------------------------------------------------------------------------------- 1 | [proc,or](int $a, int $b)(int) 2 | return(calc($a | $b)); -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/array_01.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,caller_01] 2 | def_int $array0(1); 3 | def_int $array1(1); 4 | def_int $array2(1); 5 | ~test_01(array0, 0, array2); 6 | 7 | [proc,test_01](intarray $array0, int $index, intarray $array1)(int) 8 | return($array0(index)); 9 | 10 | -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/array_02.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,caller_02] 2 | def_int $array0(1); 3 | def_int $array2(1); 4 | ~test_02(array0, 0, array2); 5 | 6 | [proc,test_02](intarray $array0, int $index, intarray $array1)(int) 7 | return($array0(index)); 8 | 9 | -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/calc_01.rs2: -------------------------------------------------------------------------------- 1 | [proc,calc_01](int $parameter)(int) 2 | def_int $first = calc($parameter * 2 + 1); 3 | def_int $second = calc($parameter % 2 + 1); 4 | def_int $third = calc($parameter / 2 + 1); 5 | return(calc($first + $second - $third)); -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/calc_02.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,calc_02](boolean $parameter) 2 | // calc boolean + boolean should produce an error 3 | def_int $first = calc($parameter + true); 4 | // calc boolean + int should produce an error 5 | def_int $second = calc($parameter + 2); 6 | // this calc should produce no error 7 | def_int $third = calc(2 / 2 + 1); 8 | // arithmetic without calc should produce an error 9 | def_int $fourth = 2 + 2 / 2; -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/call_01.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,main] 2 | ~main(true); 3 | 4 | [proc,main](boolean $call_sub_01) 5 | if ($call_sub_01 = true) { 6 | @sub_01(0); 7 | } 8 | 9 | [label,sub_01](int $parameter) 10 | ~main(false); 11 | @sub_02(calc($parameter + 1)); 12 | 13 | [label,sub_02](int $parameter) 14 | -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/operator_bitwise_and.rs2: -------------------------------------------------------------------------------- 1 | [proc,test](int $a, int $b)(int) 2 | return(calc($a & $b)); -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/me/waliedyassen/runescript/compiler/semantics/typecheck/operator_bitwise_or.rs2: -------------------------------------------------------------------------------- 1 | [proc,or](int $a, int $b)(int) 2 | return(calc($a | $b)); -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/parse-script.rs2: -------------------------------------------------------------------------------- 1 | [trigger,name] 2 | // the first statement. 3 | if (true) { 4 | 5 | } 6 | // the second statement. 7 | if (false) { 8 | 9 | } -------------------------------------------------------------------------------- /runescript-compiler/src/test/resources/visitor-tree-script.rs2: -------------------------------------------------------------------------------- 1 | [clientscript,visitor_tree_test](int $int0, string $string1, int $int1, long $long0)(boolean) 2 | def_int $local0 = 0; 3 | def_long $local1; $local1 = ll; 4 | def_string $string1 = "string literal"; 5 | def_string $concatenation = "hello<^my_string_constant>"; 6 | dynamic_0; 7 | command(false); 8 | if ($local1 = 1l) { 9 | another_command(true); 10 | } 11 | if (false) { 12 | another_command(true); 13 | } else { 14 | 15 | } 16 | switch_int($local0) { 17 | case 0,1,2,3,4,5 : 18 | $string1 = "Less than 5"; 19 | case 6,7,8,9 : 20 | $string1 = "More than 5"; 21 | case default : 22 | $string1 = "Not a single digit"; 23 | } 24 | def_string $string2; 25 | switch_int($local0) { 26 | case 0,1,2,3,4,5 : 27 | $string2 = "Less than 5"; 28 | case 6,7,8,9 : 29 | $string2 = "More than 5"; 30 | } 31 | while ($int0 > 0) { 32 | $int0 = sub($int0, 1); 33 | } 34 | 35 | def_coord $coord = 0_50_50_32_32; 36 | return(~gosub_test($local0,$string1)); -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/file/FileType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.file; 9 | 10 | import me.waliedyassen.runescript.editor.ui.editor.Editor; 11 | 12 | import javax.swing.*; 13 | import java.nio.file.Path; 14 | 15 | /** 16 | * Represents a file type in our editor. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public interface FileType { 21 | 22 | /** 23 | * Creates an {@link Editor} for this file type. 24 | * 25 | * @param path the path of the file we are creating the editor for. 26 | * @return the created {@link Editor} type object instance. 27 | */ 28 | Editor createEditor(Path path); 29 | 30 | /** 31 | * Returns the name of the file type. 32 | * 33 | * @return the name of the file type. 34 | */ 35 | String getName(); 36 | 37 | /** 38 | * Returns the description of the file type. 39 | * 40 | * @return the description of the file type. 41 | */ 42 | String getDescription(); 43 | 44 | /** 45 | * Returns the extensions that are supported by this file type. 46 | * 47 | * @return the extensions that are supported by this file type. 48 | */ 49 | String[] getExtensions(); 50 | 51 | /** 52 | * Returns the icon of the file type. 53 | * 54 | * @return the icon of the file type. 55 | */ 56 | Icon getIcon(); 57 | } 58 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/file/impl/PlainFileType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.file.impl; 9 | 10 | import me.waliedyassen.runescript.editor.EditorIcons; 11 | import me.waliedyassen.runescript.editor.file.FileType; 12 | import me.waliedyassen.runescript.editor.ui.editor.Editor; 13 | import me.waliedyassen.runescript.editor.ui.editor.code.FileEditor; 14 | 15 | import javax.swing.*; 16 | import java.nio.file.Path; 17 | 18 | /** 19 | * The default file type that will be used in-case no file type was found. 20 | * 21 | * @author Walied K. Yassen 22 | */ 23 | public final class PlainFileType implements FileType { 24 | 25 | /** 26 | * {@inheritDoc} 27 | */ 28 | @Override 29 | public Editor createEditor(Path path) { 30 | return new FileEditor(this, path); 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | public String getName() { 38 | return "Plain Text File"; 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | @Override 45 | public String getDescription() { 46 | return "Plain Text File"; 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public String[] getExtensions() { 54 | return new String[0]; 55 | } 56 | 57 | /** 58 | * {@inheritDoc} 59 | */ 60 | @Override 61 | public Icon getIcon() { 62 | return EditorIcons.FILETYPE_FILE_ICON; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/file/impl/ProjectFileType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.file.impl; 9 | 10 | import me.waliedyassen.runescript.editor.Api; 11 | import me.waliedyassen.runescript.editor.EditorIcons; 12 | import me.waliedyassen.runescript.editor.file.FileType; 13 | import me.waliedyassen.runescript.editor.ui.editor.Editor; 14 | import me.waliedyassen.runescript.editor.ui.editor.project.ProjectEditor; 15 | 16 | import javax.swing.*; 17 | import java.nio.file.Path; 18 | 19 | /** 20 | * Represents the RuneScript Project File file type. 21 | * 22 | * @author Walied K. Yassen 23 | */ 24 | public final class ProjectFileType implements FileType { 25 | 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public Editor createEditor(Path path) { 31 | var currentProject = Api.getApi().getProjectManager().getCurrentProject().get(); 32 | return new ProjectEditor(path, currentProject); 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public String getName() { 40 | return "RuneScript Project File"; 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public String getDescription() { 48 | return "RuneScript Project File"; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public String[] getExtensions() { 56 | return new String[]{"rsproj"}; 57 | } 58 | 59 | /** 60 | * {@inheritDoc} 61 | */ 62 | @Override 63 | public Icon getIcon() { 64 | return EditorIcons.FILETYPE_FILE_ICON; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/file/impl/ScriptFileType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.file.impl; 9 | 10 | import me.waliedyassen.runescript.editor.EditorIcons; 11 | import me.waliedyassen.runescript.editor.file.FileType; 12 | import me.waliedyassen.runescript.editor.ui.editor.Editor; 13 | import me.waliedyassen.runescript.editor.ui.editor.code.CodeEditor; 14 | 15 | import javax.swing.*; 16 | import java.nio.file.Path; 17 | 18 | /** 19 | * Represent the RuneScript Script file type. 20 | * 21 | * @author Walied K. Yassen 22 | */ 23 | public final class ScriptFileType implements FileType { 24 | 25 | /** 26 | * An array of all the extensions this type su 27 | */ 28 | private static final String[] EXTENSIONS = new String[]{"cs2", "rs2"}; 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public Editor createEditor(Path path) { 35 | return new CodeEditor(this, path); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public String getName() { 43 | return "RuneScript Script File"; 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | @Override 50 | public String getDescription() { 51 | return "RuneScript Script File"; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public String[] getExtensions() { 59 | return EXTENSIONS; 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public Icon getIcon() { 67 | return EditorIcons.FILETYPE_SCRIPT_ICON; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/job/WorkExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.job; 9 | 10 | import lombok.Getter; 11 | 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.ScheduledExecutorService; 14 | 15 | /** 16 | * A static-class which contains the common executors we are using in the IDE. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public final class WorkExecutor { 21 | 22 | /** 23 | * A scheduled executor which uses only one thread to schedule all of it's jobs, it's used for low priority tasks. 24 | */ 25 | @Getter 26 | private static final ScheduledExecutorService singleThreadScheduler = Executors.newScheduledThreadPool(1); 27 | 28 | private WorkExecutor() { 29 | // NOOP 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/Pack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack; 9 | 10 | /** 11 | * The interface which should be implemented by all of the packing methods. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public interface Pack { 16 | 17 | /** 18 | * Packs the specified {@link PackFile} using this method. 19 | * 20 | * @param file the file to pack using this method. 21 | */ 22 | void pack(PackFile file); 23 | } 24 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/PackFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack; 9 | 10 | import lombok.Data; 11 | 12 | /** 13 | * Contains the data about a specific file that we want to pack. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | @Data 18 | public final class PackFile { 19 | 20 | /** 21 | * The id that was assigned to the file. 22 | */ 23 | private final int id; 24 | 25 | /** 26 | * The name of the file. 27 | */ 28 | private final String name; 29 | 30 | /** 31 | * The binary data of file. 32 | */ 33 | private final byte[] data; 34 | } 35 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/impl/FlatPack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack.impl; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | import lombok.SneakyThrows; 12 | import lombok.extern.slf4j.Slf4j; 13 | import me.waliedyassen.runescript.editor.pack.Pack; 14 | import me.waliedyassen.runescript.editor.pack.PackFile; 15 | 16 | import java.nio.file.Files; 17 | import java.nio.file.Path; 18 | import java.nio.file.StandardOpenOption; 19 | 20 | 21 | /** 22 | * Represents a {@link Pack} implementation that packs to a directory 23 | * 24 | * @author Walied K. Yassen 25 | */ 26 | @Slf4j 27 | @RequiredArgsConstructor 28 | public final class FlatPack implements Pack { 29 | 30 | /** 31 | * The path of hte directory we will be packing in. 32 | */ 33 | private final Path path; 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @SneakyThrows 39 | @Override 40 | public void pack(PackFile file) { 41 | var path = this.path.resolve(String.format("%d-%s", file.getId(), file.getName())); 42 | Files.write(path, file.getData(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/provider/PackProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack.provider; 9 | 10 | import me.waliedyassen.runescript.editor.pack.Pack; 11 | 12 | /** 13 | * A provider interface for {@link Pack} objects which requires an extension to be provided for each {@link Pack}. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public interface PackProvider { 18 | 19 | /** 20 | * Creates a new {@link Pack} object for the specified {@code packName}. 21 | * 22 | * @param packName the pack database name to create the {@link Pack} object for. 23 | * @return the created {@link Pack} object or {@code null} if we failed to open one. 24 | */ 25 | Pack create(String packName); 26 | } 27 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/provider/impl/FlatPackProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack.provider.impl; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | import lombok.SneakyThrows; 12 | import me.waliedyassen.runescript.editor.pack.impl.FlatPack; 13 | import me.waliedyassen.runescript.editor.pack.provider.PackProvider; 14 | 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | 18 | /** 19 | * A {@link PackProvider} implementation that is responsible for providing {@link FlatPack}. 20 | * 21 | * @author Walied K. Yassen 22 | */ 23 | @RequiredArgsConstructor 24 | public final class FlatPackProvider implements PackProvider { 25 | 26 | /** 27 | * The path which leads to the root directory that contains the pack databases. 28 | */ 29 | private final Path path; 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @SneakyThrows 35 | @Override 36 | public FlatPack create(String packName) { 37 | var directory = path.resolve(packName); 38 | if (!Files.exists(directory)) { 39 | Files.createDirectories(directory); 40 | } 41 | if (!Files.isDirectory(directory)) { 42 | throw new IllegalArgumentException(); 43 | } 44 | return new FlatPack(directory); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/pack/provider/impl/SQLitePackProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.pack.provider.impl; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | import me.waliedyassen.runescript.editor.pack.Pack; 12 | import me.waliedyassen.runescript.editor.pack.impl.SQLitePack; 13 | import me.waliedyassen.runescript.editor.pack.provider.PackProvider; 14 | 15 | import java.nio.file.Path; 16 | 17 | /** 18 | * A {@link PackProvider} implementation that is responsible for providing {@link SQLitePack}. 19 | * 20 | * @author Walied K. Yassen 21 | */ 22 | @RequiredArgsConstructor 23 | public final class SQLitePackProvider implements PackProvider { 24 | 25 | /** 26 | * The path which leads to the root directory that contains the SQLite databases. 27 | */ 28 | private final Path path; 29 | 30 | /** 31 | * {@inheritDoc} 32 | */ 33 | @Override 34 | public Pack create(String packName) { 35 | return new SQLitePack(path.resolve(packName + ".db").toAbsolutePath().toString()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/PackType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project; 9 | 10 | import me.waliedyassen.runescript.editor.pack.provider.PackProvider; 11 | import me.waliedyassen.runescript.editor.pack.provider.impl.FlatPackProvider; 12 | import me.waliedyassen.runescript.editor.pack.provider.impl.SQLitePackProvider; 13 | 14 | import java.nio.file.Path; 15 | 16 | /** 17 | * The packing type of a project. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public enum PackType { 22 | /** 23 | * Stores the output as files in the pack directory. 24 | */ 25 | FLATFILE { 26 | @Override 27 | public PackProvider newInstance(Path directory) { 28 | return new FlatPackProvider(directory); 29 | } 30 | }, 31 | 32 | /** 33 | * STore the output as entries in a sqlite database 34 | */ 35 | SQLITE { 36 | @Override 37 | public PackProvider newInstance(Path directory) { 38 | return new SQLitePackProvider(directory); 39 | } 40 | }; 41 | 42 | /** 43 | * Creates new {@link PackProvider} instance object. 44 | * 45 | * @param directory the directory which the packed database will be placed in. 46 | * @return the created {@link PackProvider} object. 47 | */ 48 | public abstract PackProvider newInstance(Path directory); 49 | } 50 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/ProjectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project; 9 | 10 | /** 11 | * A {@link RuntimeException} implementation for exceptions or errors that happen during the execution of the {@link 12 | * ProjectManager} functions. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public final class ProjectException extends RuntimeException { 17 | 18 | /** 19 | * Constructs a new {@link ProjectException} type object instance. 20 | * 21 | * @param message 22 | * the error message of the exception. 23 | */ 24 | public ProjectException(String message) { 25 | super(message); 26 | } 27 | 28 | 29 | /** 30 | * Constructs a new {@link ProjectException} type object instance. 31 | * 32 | * @param message 33 | * the error message of the exception. 34 | * @param cause 35 | * the original cause of the exception. 36 | */ 37 | public ProjectException(String message, Throwable cause) { 38 | super(message, cause); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/cache/CachedError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project.cache; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.commons.document.Span; 13 | 14 | /** 15 | * A cached error that is stored in a cached file. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | @RequiredArgsConstructor 20 | public final class CachedError { 21 | 22 | /** 23 | * The range of the error in the source code. 24 | */ 25 | @Getter 26 | private final Span span; 27 | 28 | /** 29 | * The line which contains the error. 30 | */ 31 | @Getter 32 | private final int line; 33 | 34 | /** 35 | * The message of the error. 36 | */ 37 | @Getter 38 | private final String message; 39 | } 40 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/compile/CompileResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project.compile; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.compiler.syntax.SyntaxBase; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * An object that holds the result of a compile call within a project. 19 | * 20 | * @author Walied K. Yassen 21 | */ 22 | @RequiredArgsConstructor 23 | public final class CompileResult { 24 | 25 | /** 26 | * A list of all the parsed script syntax. 27 | */ 28 | @Getter 29 | private final List syntax = new ArrayList<>(); 30 | } 31 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/compile/ProjectCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project.compile; 9 | 10 | import me.waliedyassen.runescript.compiler.CompiledUnit; 11 | import me.waliedyassen.runescript.compiler.Input; 12 | import me.waliedyassen.runescript.compiler.Output; 13 | import me.waliedyassen.runescript.compiler.syntax.SyntaxBase; 14 | import me.waliedyassen.runescript.editor.project.cache.unit.CacheUnit; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * Represents a bridge between the project and the compiler of a specific type of files. 20 | * 21 | * @param the type of Syntax Tree node this compiler produces. 22 | * @param the type of the compilation unit this compiler produces. 23 | * @author Walied K. Yassen 24 | */ 25 | public interface ProjectCompiler> { 26 | 27 | /** 28 | * Performs a compile call using the underlying compiler. 29 | * 30 | * @param input the input of the compiler. 31 | * @return the output of the compiler. 32 | */ 33 | Output compile(Input input) throws IOException; 34 | 35 | /** 36 | * Creates a new {@link CacheUnit} implementation object. 37 | * 38 | * @param path the file path of the cache unit. 39 | * @param fileName the file name of the cache unit. 40 | * @return the created {@link CacheUnit} object. 41 | */ 42 | CacheUnit createUnit(String path, String fileName); 43 | } 44 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/compile/ProjectCompilerProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project.compile; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * Responsible for managing and providing {@link ProjectCompiler} objects from file name extensions. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class ProjectCompilerProvider { 19 | 20 | /** 21 | * ِA map of all the registered compilers in this provider. 22 | */ 23 | private final Map> compilers = new HashMap<>(); 24 | 25 | /** 26 | * Registers the {@link ProjectCompiler} for the specified {@code extension}. 27 | * 28 | * @param extension the file name extension to register the compiler for. 29 | * @param compiler the compiler that we want to register. 30 | */ 31 | public void register(String extension, ProjectCompiler compiler) { 32 | compilers.put(extension, compiler); 33 | } 34 | 35 | /** 36 | * Returns the {@link ProjectCompiler} that is registered for the specified {@code extension}. 37 | * 38 | * @param extension the file name extension that we want to retrieve it's associated compiler. 39 | * @return the {@link ProjectCompiler} object if found otherwise {@code null}. 40 | */ 41 | public ProjectCompiler get(String extension) { 42 | return compilers.get(extension); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/project/dependency/CircularDependencyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.project.dependency; 9 | 10 | /** 11 | * a {@link RuntimeException} implementation which is raised when a circular dependency was found in a dependency 12 | * graph. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public final class CircularDependencyException extends RuntimeException { 17 | 18 | /** 19 | * Constructs a new {@link CircularDependencyException} type object instance. 20 | * 21 | * @param message the message of the exception. 22 | */ 23 | public CircularDependencyException(String message) { 24 | super(message); 25 | } 26 | 27 | /** 28 | * Constructs a new {@link CircularDependencyException} type object instance. 29 | * 30 | * @param message the message of the exception. 31 | * @param cause the cause of the exception. 32 | */ 33 | public CircularDependencyException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/property/PropertyChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.property; 9 | 10 | /** 11 | * A listener that listens to changes in a specific property or properties value. 12 | * 13 | * @param 14 | * the type of value the property or properties hold. 15 | */ 16 | @FunctionalInterface 17 | public interface PropertyChangeListener { 18 | 19 | /** 20 | * Invokes the listener. This will get called when a value is set and is different than the old value in a specific 21 | * property. 22 | * 23 | * @param property 24 | * the property which it's the value was changed. 25 | * @param oldValue 26 | * the old value of the property. 27 | * @param newValue 28 | * the new value of the property. 29 | */ 30 | void propertyChanged(Property property, T oldValue, T newValue); 31 | } 32 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/property/impl/BooleanProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.property.impl; 9 | 10 | import me.waliedyassen.runescript.editor.property.Property; 11 | 12 | /** 13 | * A {@link Property} implementation that holds a {@link Boolean} value. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public final class BooleanProperty extends Property { 18 | 19 | /** 20 | * Constructs a new {@link BooleanProperty} type object instance. 21 | */ 22 | public BooleanProperty() { 23 | this(false); 24 | } 25 | 26 | /** 27 | * Constructs a new {@link BooleanProperty} type object instance. 28 | * 29 | * @param value 30 | * the initial value of the property. 31 | */ 32 | public BooleanProperty(Boolean value) { 33 | super(value); 34 | } 35 | 36 | /** 37 | * Returns a {@link BooleanProperty} that will always hold the opposite value of this property, except for when the 38 | * value is {@code null} the returned property will also hold a {@code null} value. 39 | * 40 | * @return the negated {@link BooleanProperty} object. 41 | */ 42 | public BooleanProperty negate() { 43 | var negated = new BooleanProperty(); 44 | bind(value -> negated.set(value == null ? null : !value)); 45 | return negated; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/property/impl/ReferenceProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.property.impl; 9 | 10 | import me.waliedyassen.runescript.editor.property.Property; 11 | 12 | /** 13 | * A {@link Property} implementation that holds a reference value of type {@link T}. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public final class ReferenceProperty extends Property { 18 | 19 | /** 20 | * Constructs a new {@link ReferenceProperty} type object instance. 21 | */ 22 | public ReferenceProperty() { 23 | this(null); 24 | } 25 | 26 | /** 27 | * Constructs a new {@link ReferenceProperty} type object instance. 28 | * 29 | * @param value 30 | * the initial value of the reference. 31 | */ 32 | public ReferenceProperty(T value) { 33 | super(value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/property/impl/StringProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.property.impl; 9 | 10 | import me.waliedyassen.runescript.editor.property.Property; 11 | 12 | /** 13 | * A {@link Property} implementation that holds a {@link String} value. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public final class StringProperty extends Property { 18 | 19 | /** 20 | * Constructs a new {@link StringProperty} type object instance. 21 | */ 22 | public StringProperty() { 23 | this(""); 24 | } 25 | 26 | /** 27 | * Constructs a new {@link StringProperty} type object instance. 28 | * 29 | * @param value 30 | * the initial value of the property. 31 | */ 32 | public StringProperty(String value) { 33 | super(value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/settings/state/SettingsState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.settings.state; 9 | 10 | /** 11 | * The base class for all of the settings states. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public interface SettingsState { 16 | // NOOP 17 | } 18 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/shortcut/Shortcut.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.shortcut; 9 | 10 | import lombok.AccessLevel; 11 | import lombok.Getter; 12 | import lombok.RequiredArgsConstructor; 13 | 14 | import javax.swing.*; 15 | 16 | /** 17 | * A single shortcut in the shortcut system. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @RequiredArgsConstructor(access = AccessLevel.PACKAGE) 22 | public final class Shortcut { 23 | 24 | /** 25 | * The name of the shortcut. 26 | */ 27 | @Getter 28 | private final String name; 29 | 30 | /** 31 | * The key stroke of the shortcut. 32 | */ 33 | @Getter 34 | private final KeyStroke keyStroke; 35 | 36 | /** 37 | * The action to perform when the callback is executed. 38 | */ 39 | @Getter 40 | private final UiAction action; 41 | } 42 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/shortcut/UiAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.shortcut; 9 | 10 | /** 11 | * A functional interface that represents an UI action. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | @FunctionalInterface 16 | public interface UiAction { 17 | 18 | /** 19 | * Gets called when the ui action is being executed. 20 | * 21 | * @param source 22 | * the source UI attachment object. 23 | */ 24 | void execute(Object source); 25 | } 26 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/shortcut/common/CommonGroups.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.shortcut.common; 9 | 10 | import me.waliedyassen.runescript.editor.shortcut.ShortcutGroup; 11 | import me.waliedyassen.runescript.editor.shortcut.ShortcutManager; 12 | 13 | /** 14 | * Holds all of the common shortcut groups. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public interface CommonGroups { 19 | /** 20 | * The explorer tree shortcuts. 21 | */ 22 | ShortcutGroup EXPLORER = ShortcutManager.getInstance().createGroup("Explorer Shortcuts"); 23 | 24 | /** 25 | * The editor view shortcuts. 26 | */ 27 | ShortcutGroup EDITOR = ShortcutManager.getInstance().createGroup("Editor Shortcuts"); 28 | 29 | /** 30 | * The errors view shortcuts. 31 | */ 32 | ShortcutGroup ERRORS = ShortcutManager.getInstance().createGroup("Errors Shortcuts"); 33 | } 34 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/shortcut/common/CommonShortcuts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.shortcut.common; 9 | 10 | /** 11 | * Holds all of the common shortcut names. 12 | * 13 | * @author WaliedK. Yassen 14 | */ 15 | public interface CommonShortcuts { 16 | 17 | /** 18 | * The explorer close project shortcut name. 19 | */ 20 | String EXPLORER_CLOSE_PROJECT = "Explorer Close Project"; 21 | 22 | /** 23 | * The explorer close project shortcut name. 24 | */ 25 | String EXPLORER_DELETE = "Explorer Delete"; 26 | 27 | /** 28 | * The editor close file shortcut name. 29 | */ 30 | String EDITOR_CLOSE_FILE = "Close Editor File"; 31 | 32 | /** 33 | * The editor close file shortcut name. 34 | */ 35 | String EDITOR_SAVE_FILE = "Save Editor File"; 36 | } 37 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/dialog/DialogResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.dialog; 9 | 10 | /** 11 | * An enum holding all of the possible option dialog results. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public enum DialogResult { 16 | 17 | /** 18 | * The "Yes" option was selected in the dialog. 19 | */ 20 | YES, 21 | 22 | /** 23 | * The "No" option was selected in the dialog. 24 | */ 25 | NO, 26 | 27 | /** 28 | * The "Cancel" option was selected in the dialog. 29 | */ 30 | CANCEL, 31 | 32 | } 33 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/editor/code/completion/cache/AutoCompleteCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.editor.code.completion.cache; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.editor.ui.editor.code.completion.impl.CodeCompletion; 13 | import org.fife.ui.autocomplete.Completion; 14 | import org.fife.ui.autocomplete.CompletionProvider; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collections; 18 | import java.util.List; 19 | 20 | /** 21 | * A cache of {@link CodeCompletion} objects that are related. 22 | * 23 | * @author Walied K. Yassen 24 | */ 25 | @RequiredArgsConstructor 26 | public final class AutoCompleteCache { 27 | 28 | /** 29 | * A list of all the cached {@link CodeCompletion} objects. 30 | */ 31 | @Getter 32 | private final List completions = new ArrayList<>(); 33 | 34 | /** 35 | * The provider which instantiated this completion cache. 36 | */ 37 | @Getter 38 | private final CompletionProvider provider; 39 | 40 | /** 41 | * Adds a new {@link Completion} to the completions list in the appropriate place. 42 | * 43 | * @param completion the completion that we want to add to the completions list. 44 | */ 45 | public void addSorted(Completion completion) { 46 | var index = Collections.binarySearch(completions, completion); 47 | if (index < 0) { 48 | index = -(index + 1); 49 | } 50 | completions.add(index, completion); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/editor/code/completion/impl/CodeCompletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.editor.code.completion.impl; 9 | 10 | /** 11 | * The base class for all of our completion implementation. 12 | * 13 | * @author Walied K. Yassen 14 | */ 15 | public interface CodeCompletion { 16 | 17 | /** 18 | * {@inheritDoc} 19 | */ 20 | @Override 21 | boolean equals(Object o); 22 | 23 | /** 24 | * {@inheritDoc} 25 | */ 26 | @Override 27 | int hashCode(); 28 | } 29 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/editor/code/completion/impl/KeywordCompletion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.editor.code.completion.impl; 9 | 10 | import org.fife.ui.autocomplete.BasicCompletion; 11 | import org.fife.ui.autocomplete.CompletionProvider; 12 | 13 | /** 14 | * Represents a {@link CodeCompletion} implementation for a keyword. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class KeywordCompletion extends BasicCompletion implements CodeCompletion { 19 | 20 | /** 21 | * The keyword that we are auto completing. 22 | */ 23 | private final String keyword; 24 | 25 | /** 26 | * Constructs a new {@link KeywordCompletion} type object instance. 27 | * 28 | * @param provider the provider of the auto completion. 29 | * @param keyword the keyword that we are auto completing. 30 | */ 31 | public KeywordCompletion(CompletionProvider provider, String keyword) { 32 | super(provider, keyword, "Insert " + keyword + " keyword.", "Inserts a '" + keyword + "' at keyword at the current position."); 33 | this.keyword = keyword; 34 | setRelevance(5); 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public boolean equals(Object o) { 42 | return keyword.equals(o); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public int hashCode() { 50 | return keyword.hashCode(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/editor/code/parser/notice/ErrorNotice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.editor.code.parser.notice; 9 | 10 | import org.fife.ui.rsyntaxtextarea.parser.DefaultParserNotice; 11 | import org.fife.ui.rsyntaxtextarea.parser.Parser; 12 | 13 | import java.awt.*; 14 | 15 | /** 16 | * A parser notice that indicates there is an error somewhere. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public final class ErrorNotice extends DefaultParserNotice { 21 | 22 | /** 23 | * Constructs a new {@link ErrorNotice} type object instance. 24 | * 25 | * @param parser the parser which produced this error notice. 26 | * @param message the message of the error. 27 | * @param line the line which the error is located at. 28 | * @param offset the start offset of the error in source code. 29 | * @param width the width of the error in source code. 30 | */ 31 | public ErrorNotice(Parser parser, String message, int line, int offset, int width) { 32 | super(parser, message, line, offset, width); 33 | setLevel(Level.ERROR); 34 | setColor(Color.red); 35 | } 36 | } -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/editor/code/tokenMaker/CodeTokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.editor.code.tokenMaker; 9 | 10 | import org.fife.ui.rsyntaxtextarea.TokenTypes; 11 | 12 | /** 13 | * Holds all of the RuneScript code tokens that we are using for syntax highlighting and other stuff. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public interface CodeTokens { 18 | int NULL = TokenTypes.NULL; 19 | int WHITESPACE = TokenTypes.WHITESPACE; 20 | int STRING_LITERAL = TokenTypes.LITERAL_STRING_DOUBLE_QUOTE; 21 | int LINE_COMMENT = TokenTypes.COMMENT_EOL; 22 | int MULTILINE_COMMENT = TokenTypes.COMMENT_MULTILINE; 23 | int NUMBER_LITERAL = TokenTypes.LITERAL_NUMBER_DECIMAL_INT; 24 | int HEX_LITERAL = TokenTypes.LITERAL_NUMBER_HEXADECIMAL; 25 | int LOCAL_VARIABLE = TokenTypes.VARIABLE; 26 | int IDENTIFIER = TokenTypes.IDENTIFIER; 27 | int KEYWORD = TokenTypes.RESERVED_WORD; 28 | int TYPE_NAME = TokenTypes.RESERVED_WORD_2; 29 | int UNDEFINED = TokenTypes.DEFAULT_NUM_TOKEN_TYPES; 30 | int SEPARATOR = TokenTypes.SEPARATOR; 31 | int OPERATOR = TokenTypes.OPERATOR; 32 | int DECLARATION = UNDEFINED + 1; 33 | int STRING_INTERPOLATE = DECLARATION + 1; 34 | int COORDGRID_LITERAL = STRING_INTERPOLATE + 1; 35 | int GLOBAL_VARIABLE = COORDGRID_LITERAL + 1; 36 | int CONSTANT = GLOBAL_VARIABLE + 1; 37 | int COMMAND = CONSTANT + 1; 38 | int NUM_TOKENS = COMMAND + 1; 39 | } 40 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/explorer/ExplorerView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.explorer; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.editor.ui.explorer.tree.ExplorerTree; 12 | 13 | import javax.swing.*; 14 | import java.awt.*; 15 | 16 | /** 17 | * The explorer file tree docking view. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | public final class ExplorerView extends JPanel { 22 | 23 | /** 24 | * The docking {@code ID} for the explorer docking component. 25 | */ 26 | public static final String DOCK_ID = "explorer.dock"; 27 | 28 | /** 29 | * The tree of the explorer. 30 | */ 31 | @Getter 32 | private final ExplorerTree tree = new ExplorerTree(); 33 | 34 | /** 35 | * Constructs a new {@link ExplorerView} type object instance. 36 | */ 37 | public ExplorerView() { 38 | setLayout(new BorderLayout()); 39 | add(new JScrollPane(tree), BorderLayout.CENTER); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/explorer/tree/ExplorerModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package me.waliedyassen.runescript.editor.ui.explorer.tree; 10 | 11 | import javax.swing.tree.DefaultTreeModel; 12 | import javax.swing.tree.TreeNode; 13 | 14 | /** 15 | * The tree model of the project explorer tree. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class ExplorerModel extends DefaultTreeModel { 20 | 21 | /** 22 | * Constructs a new {@link ExplorerModel} type object instance. 23 | * 24 | * @param root 25 | * the root node of the explorer. 26 | */ 27 | public ExplorerModel(TreeNode root) { 28 | super(root); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/explorer/tree/ExplorerNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.explorer.tree; 9 | 10 | import lombok.Getter; 11 | import lombok.RequiredArgsConstructor; 12 | import me.waliedyassen.runescript.editor.ui.menu.action.ActionSource; 13 | 14 | import javax.swing.tree.DefaultMutableTreeNode; 15 | 16 | /** 17 | * The base class for all of the tree nodes in the project explorer tree. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @RequiredArgsConstructor 22 | public abstract class ExplorerNode extends DefaultMutableTreeNode implements ActionSource { 23 | 24 | /** 25 | * The tree which owns this explorer node. 26 | */ 27 | @Getter 28 | protected final ExplorerTree tree; 29 | 30 | /** 31 | * The value of the explorer node. 32 | */ 33 | @Getter 34 | protected final T value; 35 | 36 | /** 37 | * Gets called when we double click the node in the tree. 38 | */ 39 | public void onActionClick() { 40 | // NOOP 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/explorer/tree/lazy/LoadingNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.explorer.tree.lazy; 9 | 10 | import me.waliedyassen.runescript.editor.ui.explorer.tree.ExplorerNode; 11 | import me.waliedyassen.runescript.editor.ui.explorer.tree.ExplorerTree; 12 | import me.waliedyassen.runescript.editor.ui.menu.action.list.ActionList; 13 | 14 | /** 15 | * A placeholder node used to make the tree expandable so it will trigger the expand listener. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class LoadingNode extends ExplorerNode { 20 | 21 | /** 22 | * Constructs a new {@link LoadingNode} type object instance. 23 | * 24 | * @param tree the owner tree of the explorer node. 25 | */ 26 | public LoadingNode(ExplorerTree tree) { 27 | super(tree, null); 28 | setUserObject("Loading"); 29 | setAllowsChildren(false); 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | @Override 36 | public void populateActions(ActionList actionList) { 37 | // NOOP 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/menu/action/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.menu.action; 9 | 10 | import javax.swing.*; 11 | 12 | /** 13 | * The base class for every menu action in our system. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public interface Action { 18 | 19 | /** 20 | * Creates a new {@link JComponent} object which represents the action. 21 | * 22 | * @return the created {@link JComponent} object. 23 | */ 24 | JComponent createComponent(); 25 | } 26 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/menu/action/ActionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.menu.action; 9 | 10 | import lombok.Getter; 11 | import me.waliedyassen.runescript.editor.ui.menu.action.list.ActionList; 12 | 13 | /** 14 | * The action manager of the context and popup menu(s) of the editor. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class ActionManager { 19 | 20 | /** 21 | * The singleton instance of the {@link ActionManager} type. 22 | */ 23 | @Getter 24 | private static final ActionManager instance = new ActionManager(); 25 | 26 | /** 27 | * Prevent the creation of this type outside this class. 28 | */ 29 | private ActionManager() { 30 | // NOOP 31 | } 32 | 33 | /** 34 | * Creates anew {@link ActionList} type object instance. 35 | * 36 | * @param source 37 | * the source of the action list. 38 | * 39 | * @return the created {@link ActionList} object. 40 | */ 41 | public ActionList createList(Object source) { 42 | return new ActionList(source); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/menu/action/ActionSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.menu.action; 9 | 10 | import me.waliedyassen.runescript.editor.ui.menu.action.list.ActionList; 11 | 12 | /** 13 | * An interface which should be implemented in components they represent an action source which is basically any 14 | * component that should have right click action menu. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public interface ActionSource { 19 | 20 | /** 21 | * Populates the actions of the action source into the specified {@link ActionList}. 22 | * 23 | * @param actionList 24 | * the actions list to populate the actions into. 25 | */ 26 | void populateActions(ActionList actionList); 27 | } 28 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/menu/action/impl/Menu.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.menu.action.impl; 9 | 10 | import me.waliedyassen.runescript.editor.ui.menu.action.Action; 11 | import me.waliedyassen.runescript.editor.ui.menu.action.list.ActionList; 12 | 13 | import javax.swing.*; 14 | 15 | /** 16 | * An {@link Action} implementation which creates a {@link JMenu} object. 17 | * 18 | * @author Walied K. Yassen 19 | */ 20 | public final class Menu extends ActionList implements Action { 21 | 22 | /** 23 | * The title of the menu. 24 | */ 25 | private final String title; 26 | 27 | /** 28 | * Constructs a new {@link Menu} type object instance. 29 | * 30 | * @param source 31 | */ 32 | public Menu(Object source, String title) { 33 | super(source); 34 | this.title = title; 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public JComponent createComponent() { 42 | var menu = new JMenu(title); 43 | createComponents().forEach(menu::add); 44 | return menu; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/menu/action/impl/Separator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.menu.action.impl; 9 | 10 | import me.waliedyassen.runescript.editor.ui.menu.action.Action; 11 | 12 | import javax.swing.*; 13 | 14 | /** 15 | * An {@link Action} implementation which creates a {@link JPopupMenu.Separator} object. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class Separator implements Action { 20 | 21 | /** 22 | * {@inheritDoc} 23 | */ 24 | @Override 25 | public JComponent createComponent() { 26 | return new JPopupMenu.Separator(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/tabbedpane/TabComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.tabbedpane; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | 13 | /** 14 | * Represents a tab component for the tabbed pane. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public abstract class TabComponent extends JPanel { 19 | 20 | /** 21 | * Constructs a new {@link TabComponent} type object instance. 22 | * 23 | * @param layout the layout manager the component follows. 24 | */ 25 | public TabComponent(LayoutManager layout) { 26 | super(layout); 27 | setOpaque(false); 28 | } 29 | 30 | /** 31 | * Updates the title of the tab component. 32 | * 33 | * @param title the new tile of the tab component. 34 | */ 35 | public abstract void setTitle(String title); 36 | 37 | /** 38 | * Updates tooltip of the tab component. 39 | * 40 | * @param tooltip the new tooltip of the tab component. 41 | */ 42 | public abstract void setTooltip(String tooltip); 43 | } 44 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/tabbedpane/TabbedPane.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | 9 | package me.waliedyassen.runescript.editor.ui.tabbedpane; 10 | 11 | import javax.swing.*; 12 | 13 | /** 14 | * Represents a UI tabbed pane implementation. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public final class TabbedPane extends JTabbedPane { 19 | // NOOP 20 | } 21 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/ui/util/DelegatingMouseListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.ui.util; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | 12 | import java.awt.event.MouseEvent; 13 | import java.awt.event.MouseListener; 14 | 15 | /** 16 | * A delegating {@link MouseListener} implementation that delegates all of the calls to another specific {@link 17 | * MouseListener} object. 18 | * 19 | * @author Walied K. Yassen 20 | */ 21 | @RequiredArgsConstructor 22 | public abstract class DelegatingMouseListener implements MouseListener { 23 | 24 | /** 25 | * The delegate listener which we want to call. 26 | */ 27 | private final MouseListener delegate; 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public void mouseClicked(MouseEvent e) { 34 | delegate.mouseClicked(e); 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void mousePressed(MouseEvent e) { 42 | delegate.mousePressed(e); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public void mouseReleased(MouseEvent e) { 50 | delegate.mouseReleased(e); 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void mouseEntered(MouseEvent e) { 58 | delegate.mouseEntered(e); 59 | } 60 | 61 | /** 62 | * {@inheritDoc} 63 | */ 64 | @Override 65 | public void mouseExited(MouseEvent e) { 66 | delegate.mouseExited(e); 67 | } 68 | } -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/util/ex/SwingUtilitiesEx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.util.ex; 9 | 10 | 11 | import javax.swing.*; 12 | import java.awt.*; 13 | 14 | /** 15 | * An extension class for {@link SwingUtilities} utility class. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class SwingUtilitiesEx { 20 | 21 | /** 22 | * Returns the hit test spot boundary of the specified {@link Component component}. 23 | * 24 | * @param component the component which we want the the hit test spot boundary for. 25 | * @return the hit test spot boundary of the specified component as a {@link Rectangle} object. 26 | */ 27 | public static Rectangle getComponentHitTestBounds(Component component) { 28 | var location = component.getLocationOnScreen(); 29 | return new Rectangle(Math.max(location.x - 2, 0), location.y, component.getWidth(), component.getHeight()); 30 | } 31 | 32 | private SwingUtilitiesEx() { 33 | // NOOP 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /runescript-editor/src/main/java/me/waliedyassen/runescript/editor/vfs/VFSFileListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.editor.vfs; 9 | 10 | import java.nio.file.Path; 11 | 12 | /** 13 | * Represents a listener that can be found to a {@link VFSFile} and listen to it's events. 14 | * 15 | * @author Walied K. Yassen 16 | */ 17 | public interface VFSFileListener { 18 | 19 | /** 20 | * Gets called when an entity was just created. 21 | * 22 | * @param path the path of the entity that was created. 23 | */ 24 | void onEntityCreate(Path path); 25 | 26 | /** 27 | * Gets called when an entity was just deleted. 28 | * 29 | * @param path the path of the entity that was deleted. 30 | */ 31 | void onEntityDelete(Path path); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/com/formdev/flatlaf/FlatDarculaLaf.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | # 4 | # This Source Code Form is subject to the terms of the Mozilla Public 5 | # License, v. 2.0. If a copy of the MPL was not distributed with this 6 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | # 8 | 9 | #---- Button ---- 10 | 11 | Button.default.boldText=true 12 | @menuBackground=@background 13 | MenuBar.background=@menuBackground 14 | 15 | #---- Component ---- 16 | 17 | Component.focusWidth=0 18 | Component.innerFocusWidth=0 19 | Component.innerOutlineWidth=0 20 | Component.arrowType=triangle 21 | 22 | 23 | #---- ProgressBar ---- 24 | 25 | ProgressBar.foreground=#a0a0a0 26 | ProgressBar.selectionForeground=@background 27 | 28 | 29 | #---- RadioButton ---- 30 | 31 | RadioButton.icon.centerDiameter=5 -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/icons/favicon.png -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The icons in this folder are from IntelliJ IDEA Community Edition, 2 | which is licensed under the Apache 2.0 license. Copyright 2000-2020 JetBrains s.r.o. 3 | See: https://github.com/JetBrains/intellij-community/ -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/close_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/close_hovered.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/settings.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/idea/settings_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/tree/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/icons/tree/config.png -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/tree/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/icons/tree/file.png -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/tree/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/icons/tree/folder.png -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/icons/tree/script.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/icons/tree/script.png -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/project/osrs_default_triggers.toml: -------------------------------------------------------------------------------- 1 | [clientscript] 2 | support_returns=false 3 | support_arguments=true 4 | hook=true 5 | 6 | [proc] 7 | operator="tilde" 8 | opcode="gosub_with_params" 9 | support_returns=true 10 | support_arguments=true 11 | 12 | [label] 13 | operator="at" 14 | opcode="jump_with_params" 15 | support_returns=false 16 | support_arguments=true 17 | 18 | [if_button1] 19 | support_returns=false 20 | support_argument=false 21 | 22 | [if_button2] 23 | support_returns=false 24 | support_argument=false 25 | 26 | [if_button3] 27 | support_returns=false 28 | support_argument=false 29 | 30 | [if_button4] 31 | support_returns=false 32 | support_argument=false 33 | 34 | [if_button5] 35 | support_returns=false 36 | support_argument=false 37 | 38 | [if_button6] 39 | support_returns=false 40 | support_argument=false 41 | 42 | [if_button7] 43 | support_returns=false 44 | support_argument=false 45 | 46 | [if_button8] 47 | support_returns=false 48 | support_argument=false 49 | 50 | [if_button9] 51 | support_returns=false 52 | support_argument=false 53 | 54 | [if_button10] 55 | support_returns=false 56 | support_argument=false -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Bold-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Bold-Italic.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Bold.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-ExtraBold-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-ExtraBold-Italic.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-ExtraBold.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Italic.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Medium-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Medium-Italic.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Medium.ttf -------------------------------------------------------------------------------- /runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waleedyaseen/RuneScript/ed82ac7831d559e3d1c93c204f03f5c0a8ebf7b7/runescript-editor/src/main/resources/me/waliedyassen/runescript/editor/util/JetBrainsMono-Regular.ttf -------------------------------------------------------------------------------- /runescript-runtime/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | runescript-parent 12 | me.waliedyassen.runescript 13 | 0.6-SNAPSHOT 14 | 15 | 4.0.0 16 | runescript-runtime 17 | 0.6-SNAPSHOT 18 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/ScriptRuntimeSetup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime; 9 | 10 | /** 11 | * An interface which is responsible for setting up the runtime context. 12 | * 13 | * @param the type of the runtime. 14 | * @author Walied K. Yassen 15 | */ 16 | @FunctionalInterface 17 | public interface ScriptRuntimeSetup { 18 | 19 | /** 20 | * Sets-up the context of the specified {@link R runtime}. 21 | * 22 | * @param runtime the runetime to setup the context. 23 | */ 24 | void setup(R runtime); 25 | } 26 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/cache/ScriptCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.cache; 9 | 10 | import lombok.RequiredArgsConstructor; 11 | import me.waliedyassen.runescript.runtime.script.Script; 12 | 13 | /** 14 | * Represents a script cache that can be used for loading and storing the loaded scripts in memory for faster access. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @RequiredArgsConstructor 19 | public abstract class ScriptCache { 20 | 21 | /** 22 | * Returns the {@link Script} object with the specified {@code name}. 23 | * 24 | * @param id the id of the script to get. 25 | * @return the {@link Script} object if found otherwise {@code null}. 26 | */ 27 | public abstract Script get(int id); 28 | 29 | /** 30 | * Returns the {@link Script} object with the specified {@code name}. 31 | * 32 | * @param name the name of the script to get. 33 | * @return the {@link Script} object if found otherwise {@code null}. 34 | */ 35 | public abstract Script get(String name); 36 | } 37 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/executor/ExecutionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.executor; 9 | 10 | /** 11 | * A {@link RuntimeException} implementation that is raised when a problem occurs during the execution of a script of an 12 | * instruction. 13 | * 14 | * @author Walied K. Yassen 15 | */ 16 | public final class ExecutionException extends RuntimeException { 17 | 18 | /** 19 | * Constructs a {@link ExecutionException} type object instance. 20 | * 21 | * @param message 22 | * the error message of the exception 23 | */ 24 | public ExecutionException(String message) { 25 | super(message); 26 | } 27 | 28 | /** 29 | * Constructs a {@link ExecutionException} type object instance. 30 | * 31 | * @param message 32 | * the error message of the exception 33 | * @param cause 34 | * the parent cause of the exception. 35 | */ 36 | public ExecutionException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/executor/ScriptFramePool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.executor; 9 | 10 | import me.waliedyassen.runescript.runtime.ScriptFrame; 11 | 12 | import java.util.Stack; 13 | 14 | /** 15 | * Represents a pool for {@link ScriptFrame} objects. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public final class ScriptFramePool { 20 | 21 | /** 22 | * The maximum amount of objects that can be pushed onto the pool stack. 23 | */ 24 | private static final int POOL_SIZE = 512; 25 | 26 | /** 27 | * The stack which contains the pool objects. 28 | */ 29 | private static final Stack frames = new Stack<>(); 30 | 31 | /** 32 | * Pushes the specified {@link ScriptFrame} object back into the pool. 33 | * 34 | * @param frame the frame object to push back into the pool. 35 | */ 36 | public static void push(ScriptFrame frame) { 37 | if (frames.size() >= POOL_SIZE) { 38 | return; 39 | } 40 | frames.push(frame); 41 | } 42 | 43 | /** 44 | * Pops a {@link ScriptFrame} object from the pool or create new one if the pool had no objects available. 45 | * 46 | * @return the {@link ScriptFrame} object. 47 | */ 48 | public static ScriptFrame pop() { 49 | if (frames.isEmpty()) { 50 | return new ScriptFrame(); 51 | } 52 | return frames.pop(); 53 | } 54 | 55 | private ScriptFramePool() { 56 | // NOOP 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/executor/impl/ConsoleOps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.executor.impl; 9 | 10 | import me.waliedyassen.runescript.runtime.ScriptRuntime; 11 | import me.waliedyassen.runescript.runtime.executor.instruction.InstructionExecutor; 12 | 13 | 14 | /** 15 | * Contains all of the common console operations. 16 | * 17 | * @author Walied K. Yassen 18 | */ 19 | public interface ConsoleOps { 20 | 21 | /** 22 | * An instruction which writes to the console of the host VM. 23 | */ 24 | InstructionExecutor WRITECONSOLE = runtime -> System.out.println(runtime.popString()); 25 | } 26 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/executor/impl/StringOps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.executor.impl; 9 | 10 | import me.waliedyassen.runescript.runtime.ScriptRuntime; 11 | import me.waliedyassen.runescript.runtime.executor.instruction.InstructionExecutor; 12 | 13 | /** 14 | * Contains all of the common string operations. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | public interface StringOps { 19 | 20 | /** 21 | * Takes an X integer and turn it into a string form. 22 | */ 23 | InstructionExecutor TOSTRING = runtime -> runtime.pushString(Integer.toString(runtime.popInt())); 24 | } 25 | -------------------------------------------------------------------------------- /runescript-runtime/src/main/java/me/waliedyassen/runescript/runtime/executor/instruction/InstructionExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Walied K. Yassen, All rights reserved. 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | package me.waliedyassen.runescript.runtime.executor.instruction; 9 | 10 | import me.waliedyassen.runescript.runtime.ScriptRuntime; 11 | import me.waliedyassen.runescript.runtime.executor.ExecutionException; 12 | 13 | /** 14 | * An instruction executor, it is responsible for executing a specific instruction(s) in a runtime. 15 | * 16 | * @author Walied K. Yassen 17 | */ 18 | @FunctionalInterface 19 | public interface InstructionExecutor { 20 | 21 | /** 22 | * Executes the instruction in the specified runtime. 23 | * 24 | * @param runtime the runtime we are executing the instruction in. 25 | * @throws ExecutionException if anything occurs during the execution of the instruction. 26 | */ 27 | void execute(R runtime) throws ExecutionException; 28 | } 29 | -------------------------------------------------------------------------------- /version-rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | (?i).*M(?:-?\d+)? 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------