From ff44423a58063284dc568e3870a25343f8fec3c3 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:05:17 +0200 Subject: [PATCH] build: split up into multiple projects, use kotlin DLS --- .github/workflows/tagged-release.yml | 2 +- .gitignore | 40 +++++- build.gradle | 128 ------------------ build.gradle.kts | 23 ++++ buildSrc/build.gradle.kts | 7 + .../src/main/kotlin/common-java.gradle.kts | 12 ++ buildSrc/src/main/kotlin/common.gradle.kts | 11 ++ common/build.gradle.kts | 29 ++++ .../topchetoeu/j2s/common/FunctionBody.java | 0 .../me/topchetoeu/j2s/common/Instruction.java | 0 .../me/topchetoeu/j2s/common/Metadata.java | 0 .../me/topchetoeu/j2s/common/Operation.java | 0 .../me/topchetoeu/j2s/common/Reading.java | 0 .../j2s/common/SyntaxException.java | 0 .../j2s/common/environment/Environment.java | 0 .../j2s/common/environment/Key.java | 0 .../me/topchetoeu/j2s/common/json/JSON.java | 0 .../j2s/common/json/JSONElement.java | 0 .../topchetoeu/j2s/common/json/JSONList.java | 0 .../topchetoeu/j2s/common/json/JSONMap.java | 0 .../j2s/common/mapping/FunctionMap.java | 0 .../j2s/common/parsing/Filename.java | 0 .../j2s/common/parsing/Location.java | 0 .../j2s/common/parsing/ParseRes.java | 0 .../topchetoeu/j2s/common/parsing/Parser.java | 0 .../j2s/common/parsing/Parsing.java | 41 ++++-- .../topchetoeu/j2s/common/parsing/Source.java | 0 .../j2s/common/parsing/SourceLocation.java | 0 .../src}/main/resources/metadata.json | 0 .../me/topchetoeu/j2s/TestHelloWorld.java | 0 compilation/build.gradle.kts | 30 ++++ .../j2s/compilation/CompileResult.java | 0 .../j2s/compilation/CompoundNode.java | 0 .../j2s/compilation/DeferredIntSupplier.java | 0 .../j2s/compilation/FunctionNode.java | 0 .../compilation/FunctionStatementNode.java | 0 .../j2s/compilation/FunctionValueNode.java | 0 .../j2s/compilation/JavaScript.java | 0 .../j2s/compilation/LabelContext.java | 0 .../me/topchetoeu/j2s/compilation/Node.java | 0 .../j2s/compilation/NodeChildren.java | 0 .../topchetoeu/j2s/compilation/Parameter.java | 0 .../j2s/compilation/VariableDeclareNode.java | 0 .../j2s/compilation/control/BreakNode.java | 0 .../j2s/compilation/control/ContinueNode.java | 0 .../j2s/compilation/control/DebugNode.java | 0 .../j2s/compilation/control/DeleteNode.java | 0 .../j2s/compilation/control/DoWhileNode.java | 0 .../j2s/compilation/control/ForInNode.java | 0 .../j2s/compilation/control/ForNode.java | 0 .../j2s/compilation/control/IfNode.java | 0 .../j2s/compilation/control/ReturnNode.java | 0 .../j2s/compilation/control/SwitchNode.java | 0 .../j2s/compilation/control/ThrowNode.java | 0 .../j2s/compilation/control/TryNode.java | 0 .../j2s/compilation/control/WhileNode.java | 0 .../compilation/members/FieldMemberNode.java | 0 .../j2s/compilation/members/Member.java | 0 .../members/PropertyMemberNode.java | 0 .../compilation/patterns/AssignTarget.java | 0 .../patterns/AssignTargetLike.java | 0 .../compilation/patterns/ChangeTarget.java | 0 .../j2s/compilation/scope/FunctionScope.java | 0 .../j2s/compilation/scope/Variable.java | 0 .../j2s/compilation/scope/VariableIndex.java | 0 .../j2s/compilation/scope/VariableList.java | 0 .../j2s/compilation/values/ArgumentsNode.java | 0 .../j2s/compilation/values/ArrayNode.java | 0 .../compilation/values/GlobalThisNode.java | 0 .../j2s/compilation/values/ObjectNode.java | 0 .../j2s/compilation/values/RegexNode.java | 0 .../j2s/compilation/values/ThisNode.java | 0 .../j2s/compilation/values/VariableNode.java | 0 .../values/constants/BoolNode.java | 0 .../values/constants/NullNode.java | 0 .../values/constants/NumberNode.java | 9 -- .../values/constants/StringNode.java | 0 .../values/operations/AssignNode.java | 0 .../values/operations/CallNode.java | 0 .../values/operations/ChangeNode.java | 0 .../values/operations/DiscardNode.java | 0 .../values/operations/IndexNode.java | 0 .../values/operations/LazyAndNode.java | 0 .../values/operations/LazyOrNode.java | 0 .../values/operations/OperationNode.java | 0 .../values/operations/PostfixNode.java | 0 .../values/operations/TypeofNode.java | 0 .../values/operations/VariableAssignNode.java | 0 .../me/topchetoeu/j2s/TestHelloWorld.java | 14 ++ gradle.properties | 2 +- lib/build.gradle.kts | 68 ++++++++++ package.json => lib/package.json | 4 +- rollup.config.js => lib/rollup.config.js | 0 .../main/resources => lib/src}/lib/async.d.ts | 0 .../resources => lib/src}/lib/errors.d.ts | 0 .../src}/lib/globals/json.d.ts | 0 .../src}/lib/globals/map.d.ts | 0 .../src}/lib/globals/set.d.ts | 0 .../src}/lib/globals/weak-map.d.ts | 0 .../resources => lib/src}/lib/iterator.d.ts | 0 {src/main/resources => lib/src}/lib/lib.d.ts | 0 .../resources => lib/src}/lib/typing.d.ts | 0 .../src}/lib/values/array.d.ts | 0 .../src}/lib/values/boolean.d.ts | 0 .../src}/lib/values/function.d.ts | 0 .../src}/lib/values/number.d.ts | 0 .../src}/lib/values/object.d.ts | 0 .../src}/lib/values/regexp.d.ts | 0 .../src}/lib/values/string.d.ts | 0 .../src}/lib/values/symbol.d.ts | 0 .../libs => lib/src}/polyfills/callSuper.js | 2 +- .../src}/polyfills/classCallCheck.js | 2 +- .../libs => lib/src}/polyfills/createClass.js | 2 +- .../src}/polyfills/defineProperty.js | 2 +- .../src}/polyfills/getPrototypeOf.js | 2 +- .../libs => lib/src}/polyfills/inherits.js | 2 +- .../polyfills/possibleConstructorReturn.js | 0 .../src}/polyfills/readOnlyError.js | 0 .../src}/polyfills/setPrototypeOf.js | 2 +- {src/lib/libs => lib/src}/polyfills/typeof.js | 0 {src/lib/libs => lib/src/stdlib}/_entry.ts | 0 .../src/stdlib}/arrays/ArrayBuffer.ts | 0 .../src/stdlib}/arrays/Int32Array.ts | 0 .../src/stdlib}/arrays/TypedArray.ts | 0 .../src/stdlib}/arrays/Uint8Array.ts | 0 .../libs => lib/src/stdlib}/classes/date.ts | 0 .../libs => lib/src/stdlib}/classes/map.ts | 0 .../src/stdlib}/classes/promise.ts | 0 .../libs => lib/src/stdlib}/classes/set.ts | 0 .../src/stdlib}/namespaces/console.ts | 0 .../src/stdlib}/namespaces/json.ts | 0 .../src/stdlib}/namespaces/math.ts | 0 .../libs => lib/src/stdlib}/primordials.ts | 0 {src/lib/libs => lib/src/stdlib}/url.ts | 0 {src/lib/libs => lib/src/stdlib}/utils.ts | 0 .../libs => lib/src/stdlib}/values/array.ts | 4 +- .../libs => lib/src/stdlib}/values/boolean.ts | 0 .../libs => lib/src/stdlib}/values/errors.ts | 0 .../src/stdlib}/values/function.ts | 0 .../libs => lib/src/stdlib}/values/number.ts | 0 .../libs => lib/src/stdlib}/values/object.ts | 2 +- .../libs => lib/src/stdlib}/values/regex.ts | 0 .../libs => lib/src/stdlib}/values/string.ts | 0 .../libs => lib/src/stdlib}/values/symbol.ts | 0 {src/lib => lib/src}/transpiler/_entry.ts | 0 {src/lib => lib/src}/transpiler/babel.ts | 0 .../src}/transpiler/coffeescript.ts | 0 {src/lib => lib/src}/transpiler/map.ts | 0 .../src}/transpiler/transpiler.d.ts | 0 {src/lib => lib/src}/transpiler/typescript.ts | 0 tsconfig.json => lib/tsconfig.json | 2 +- repl/build.gradle.kts | 51 +++++++ .../me/topchetoeu/j2s/repl/SimpleRepl.java | 62 ++++++++- .../java/me/topchetoeu/j2s/repl/V8Error.java | 0 .../j2s/repl/debug/DebugServer.java | 0 .../topchetoeu/j2s/repl/debug/Debugger.java | 0 .../j2s/repl/debug/DebuggerProvider.java | 0 .../j2s/repl/debug/HttpRequest.java | 0 .../j2s/repl/debug/ScopeObject.java | 0 .../j2s/repl/debug/SimpleDebugger.java | 3 +- .../j2s/repl/debug/StackObject.java | 0 .../me/topchetoeu/j2s/repl/debug/V8Error.java | 0 .../me/topchetoeu/j2s/repl/debug/V8Event.java | 0 .../topchetoeu/j2s/repl/debug/V8Message.java | 0 .../topchetoeu/j2s/repl/debug/V8Result.java | 0 .../topchetoeu/j2s/repl/debug/WebSocket.java | 0 .../j2s/repl/debug/WebSocketMessage.java | 0 .../j2s/repl/mapping/NativeMapper.java | 0 .../src}/main/resources/debugger/favicon.png | Bin .../src}/main/resources/debugger/index.html | 0 .../main/resources/debugger/protocol.json | 0 .../me/topchetoeu/j2s/TestHelloWorld.java | 14 ++ runtime/build.gradle.kts | 30 ++++ .../j2s/runtime/ArgumentsValue.java | 0 .../me/topchetoeu/j2s/runtime/Compiler.java | 26 ++++ .../me/topchetoeu/j2s/runtime/Engine.java | 0 .../me/topchetoeu/j2s/runtime/EventLoop.java | 0 .../java/me/topchetoeu/j2s/runtime/Frame.java | 0 .../j2s/runtime/InstructionRunner.java | 0 .../topchetoeu/j2s/runtime/JSONConverter.java | 0 .../j2s/runtime/debug/DebugContext.java | 0 .../j2s/runtime/debug/DebugHandler.java | 0 .../runtime/exceptions/EngineException.java | 0 .../j2s/runtime/values/KeyCache.java | 0 .../topchetoeu/j2s/runtime/values/Member.java | 0 .../topchetoeu/j2s/runtime/values/Value.java | 0 .../runtime/values/functions/Arguments.java | 0 .../values/functions/CodeFunction.java | 0 .../values/functions/FunctionValue.java | 0 .../values/functions/NativeFunction.java | 0 .../values/objects/ArrayLikeValue.java | 0 .../runtime/values/objects/ArrayValue.java | 0 .../runtime/values/objects/ObjectValue.java | 0 .../objects/buffers/Int32ArrayValue.java | 0 .../objects/buffers/Int8ArrayValue.java | 0 .../objects/buffers/TypedArrayValue.java | 0 .../objects/buffers/Uint8ArrayValue.java | 0 .../runtime/values/primitives/BoolValue.java | 0 .../values/primitives/PrimitiveValue.java | 0 .../values/primitives/StringValue.java | 0 .../values/primitives/SymbolValue.java | 0 .../runtime/values/primitives/UserValue.java | 0 .../runtime/values/primitives/VoidValue.java | 0 .../primitives/numbers/DoubleValue.java | 0 .../values/primitives/numbers/IntValue.java | 0 .../primitives/numbers/NumberValue.java | 0 .../me/topchetoeu/j2s/TestHelloWorld.java | 14 ++ settings.gradle | 12 -- settings.gradle.kts | 18 +++ .../me/topchetoeu/j2s/runtime/Compiler.java | 81 ----------- 210 files changed, 486 insertions(+), 267 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/common-java.gradle.kts create mode 100644 buildSrc/src/main/kotlin/common.gradle.kts create mode 100644 common/build.gradle.kts rename {src => common/src}/main/java/me/topchetoeu/j2s/common/FunctionBody.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/Instruction.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/Metadata.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/Operation.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/Reading.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/SyntaxException.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/environment/Environment.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/environment/Key.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/json/JSON.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/json/JSONElement.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/json/JSONList.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/json/JSONMap.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/mapping/FunctionMap.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/Filename.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/Location.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/ParseRes.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/Parser.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java (91%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/Source.java (100%) rename {src => common/src}/main/java/me/topchetoeu/j2s/common/parsing/SourceLocation.java (100%) rename {src => common/src}/main/resources/metadata.json (100%) rename {src => common/src}/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java (100%) create mode 100644 compilation/build.gradle.kts rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/CompileResult.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/CompoundNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/DeferredIntSupplier.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/FunctionNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/FunctionStatementNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/FunctionValueNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/JavaScript.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/LabelContext.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/Node.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/NodeChildren.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/Parameter.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/VariableDeclareNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/BreakNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/ContinueNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/DebugNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/DeleteNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/DoWhileNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/ForInNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/ForNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/IfNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/ReturnNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/SwitchNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/ThrowNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/TryNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/control/WhileNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/members/FieldMemberNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/members/Member.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/members/PropertyMemberNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTarget.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTargetLike.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/patterns/ChangeTarget.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/scope/FunctionScope.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/scope/Variable.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/scope/VariableIndex.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/scope/VariableList.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/ArgumentsNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/ArrayNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/GlobalThisNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/ObjectNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/RegexNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/ThisNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/VariableNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/constants/BoolNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/constants/NullNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java (82%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/constants/StringNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/AssignNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/CallNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/ChangeNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/DiscardNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/IndexNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyAndNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyOrNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/OperationNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/PostfixNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/TypeofNode.java (100%) rename {src => compilation/src}/main/java/me/topchetoeu/j2s/compilation/values/operations/VariableAssignNode.java (100%) create mode 100644 compilation/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java create mode 100644 lib/build.gradle.kts rename package.json => lib/package.json (78%) rename rollup.config.js => lib/rollup.config.js (100%) rename {src/main/resources => lib/src}/lib/async.d.ts (100%) rename {src/main/resources => lib/src}/lib/errors.d.ts (100%) rename {src/main/resources => lib/src}/lib/globals/json.d.ts (100%) rename {src/main/resources => lib/src}/lib/globals/map.d.ts (100%) rename {src/main/resources => lib/src}/lib/globals/set.d.ts (100%) rename {src/main/resources => lib/src}/lib/globals/weak-map.d.ts (100%) rename {src/main/resources => lib/src}/lib/iterator.d.ts (100%) rename {src/main/resources => lib/src}/lib/lib.d.ts (100%) rename {src/main/resources => lib/src}/lib/typing.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/array.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/boolean.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/function.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/number.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/object.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/regexp.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/string.d.ts (100%) rename {src/main/resources => lib/src}/lib/values/symbol.d.ts (100%) rename {src/lib/libs => lib/src}/polyfills/callSuper.js (71%) rename {src/lib/libs => lib/src}/polyfills/classCallCheck.js (74%) rename {src/lib/libs => lib/src}/polyfills/createClass.js (93%) rename {src/lib/libs => lib/src}/polyfills/defineProperty.js (76%) rename {src/lib/libs => lib/src}/polyfills/getPrototypeOf.js (64%) rename {src/lib/libs => lib/src}/polyfills/inherits.js (79%) rename {src/lib/libs => lib/src}/polyfills/possibleConstructorReturn.js (100%) rename {src/lib/libs => lib/src}/polyfills/readOnlyError.js (100%) rename {src/lib/libs => lib/src}/polyfills/setPrototypeOf.js (65%) rename {src/lib/libs => lib/src}/polyfills/typeof.js (100%) rename {src/lib/libs => lib/src/stdlib}/_entry.ts (100%) rename {src/lib/libs => lib/src/stdlib}/arrays/ArrayBuffer.ts (100%) rename {src/lib/libs => lib/src/stdlib}/arrays/Int32Array.ts (100%) rename {src/lib/libs => lib/src/stdlib}/arrays/TypedArray.ts (100%) rename {src/lib/libs => lib/src/stdlib}/arrays/Uint8Array.ts (100%) rename {src/lib/libs => lib/src/stdlib}/classes/date.ts (100%) rename {src/lib/libs => lib/src/stdlib}/classes/map.ts (100%) rename {src/lib/libs => lib/src/stdlib}/classes/promise.ts (100%) rename {src/lib/libs => lib/src/stdlib}/classes/set.ts (100%) rename {src/lib/libs => lib/src/stdlib}/namespaces/console.ts (100%) rename {src/lib/libs => lib/src/stdlib}/namespaces/json.ts (100%) rename {src/lib/libs => lib/src/stdlib}/namespaces/math.ts (100%) rename {src/lib/libs => lib/src/stdlib}/primordials.ts (100%) rename {src/lib/libs => lib/src/stdlib}/url.ts (100%) rename {src/lib/libs => lib/src/stdlib}/utils.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/array.ts (98%) rename {src/lib/libs => lib/src/stdlib}/values/boolean.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/errors.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/function.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/number.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/object.ts (99%) rename {src/lib/libs => lib/src/stdlib}/values/regex.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/string.ts (100%) rename {src/lib/libs => lib/src/stdlib}/values/symbol.ts (100%) rename {src/lib => lib/src}/transpiler/_entry.ts (100%) rename {src/lib => lib/src}/transpiler/babel.ts (100%) rename {src/lib => lib/src}/transpiler/coffeescript.ts (100%) rename {src/lib => lib/src}/transpiler/map.ts (100%) rename {src/lib => lib/src}/transpiler/transpiler.d.ts (100%) rename {src/lib => lib/src}/transpiler/typescript.ts (100%) rename tsconfig.json => lib/tsconfig.json (85%) create mode 100644 repl/build.gradle.kts rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java (93%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/V8Error.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/DebugServer.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/Debugger.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/DebuggerProvider.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/HttpRequest.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/ScopeObject.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java (99%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/StackObject.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/V8Error.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/V8Event.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/V8Message.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/V8Result.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/WebSocket.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/debug/WebSocketMessage.java (100%) rename {src => repl/src}/main/java/me/topchetoeu/j2s/repl/mapping/NativeMapper.java (100%) rename {src => repl/src}/main/resources/debugger/favicon.png (100%) rename {src => repl/src}/main/resources/debugger/index.html (100%) rename {src => repl/src}/main/resources/debugger/protocol.json (100%) create mode 100644 repl/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java create mode 100644 runtime/build.gradle.kts rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/ArgumentsValue.java (100%) create mode 100644 runtime/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/Engine.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/EventLoop.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/Frame.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/InstructionRunner.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/JSONConverter.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/debug/DebugContext.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/debug/DebugHandler.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/exceptions/EngineException.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/KeyCache.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/Member.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/Value.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/functions/Arguments.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/functions/CodeFunction.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/functions/FunctionValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/functions/NativeFunction.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayLikeValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/ObjectValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int32ArrayValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int8ArrayValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/TypedArrayValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Uint8ArrayValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/BoolValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/PrimitiveValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/StringValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/SymbolValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/UserValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/VoidValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/DoubleValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/IntValue.java (100%) rename {src => runtime/src}/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/NumberValue.java (100%) create mode 100644 runtime/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 src/main/java/me/topchetoeu/j2s/runtime/Compiler.java diff --git a/.github/workflows/tagged-release.yml b/.github/workflows/tagged-release.yml index 2e91459..fe0c87b 100644 --- a/.github/workflows/tagged-release.yml +++ b/.github/workflows/tagged-release.yml @@ -31,4 +31,4 @@ jobs: # api_key: "${{secrets.TOKEN}}" files: | LICENSE - build/libs/*.jar \ No newline at end of file + */build/libs/*.jar \ No newline at end of file diff --git a/.gitignore b/.gitignore index fdbebb6..e52fa74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,40 @@ /* -!/src +/buildSrc/* +!/buildSrc +!/buildSrc +!/buildSrc/src +!/buildSrc/build.gradle.kts + +/common/* +!/common +!/common/src +!/common/build.gradle.kts + +/runtime/* +!/runtime +!/runtime/src +!/runtime/build.gradle.kts + +/compilation/* +!/compilation +!/compilation/src +!/compilation/build.gradle.kts + +/repl/* +!/repl +!/repl/src +!/repl/build.gradle.kts + +/lib/* +!/lib +!/lib/src +!/lib/build.gradle.kts +!/lib/package.json +!/lib/tsconfig.json +!/lib/rollup.config.js + +# !/src !/doc !/tests !/.github @@ -10,8 +44,8 @@ !/LICENSE !/README.md -!/settings.gradle -!/build.gradle +!/settings.gradle.kts +!/build.gradle.kts !/gradle.properties !/package.json diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 924947e..0000000 --- a/build.gradle +++ /dev/null @@ -1,128 +0,0 @@ -import java.text.SimpleDateFormat - -plugins { - id 'application'; - id 'com.github.node-gradle.node' version '5.0.0'; - id 'net.nemerosa.versioning' version '2.15.0'; - id 'org.ajoberstar.grgit' version '5.0.0-rc.3'; // required by gradle - - // TODO: figure out how to integrate proguard - // id "com.github.xaverkapeller.proguard-annotations" -} - -base.archivesName = project.project_name; -version = project.project_version; -group = project.project_group; -description = 'ES5-compliant JavaScript interpreter'; - -node { - version = '20.0.0'; - npmVersion = '8.0.0'; - download = true; -} - -task compileEnv(type: NpmTask) { - dependsOn npmInstall; - - inputs.files('rollup.config.js'); - inputs.dir('src/lib/libs'); - outputs.files("build/js/env.js"); - - // group = 'build' - args = ['run', 'build-env']; -} -task compileTypescript(type: NpmTask) { - dependsOn npmInstall; - - inputs.files('rollup.config.js'); - inputs.dir('src/lib/transpiler'); - outputs.files("build/js/ts.js"); - // nom nom tasty ram - environment.put("NODE_OPTIONS", "--max-old-space-size=4096"); - - // group = 'build' - args = ['run', 'build-ts']; -} - - -repositories { - mavenCentral(); -} - -dependencies { - annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'; - compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'; - testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'; - testRuntimeOnly 'org.junit.platform:junit-platform-launcher'; -} - -java { - sourceCompatibility = JavaVersion.VERSION_17; - targetCompatibility = JavaVersion.VERSION_17; - - toolchain { - languageVersion = JavaLanguageVersion.of(17); - } -} - -configure([tasks.compileJava]) { - options.release = 8; -} - -jar { - manifest { - attributes( - 'Main-Class': project.main_class, - 'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), - 'Build-Branch': versioning.info.branch, - 'Build-Revision': versioning.info.commit, - 'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", - 'Build-Author': 'TopchetoEU', - ); - } -} - -application { - mainClass = project.main_class; - applicationDefaultJvmArgs = ['-Xmx2G', '-Xms2G', '-server', '-Dfile.encoding=UTF-8']; -} - -distZip { - eachFile { file -> - if (file.path.contains('bin')) { - file.exclude(); - } - } -} - -distTar { - eachFile { file -> - if (file.path.contains('bin')) { - file.exclude(); - } - } -} - -processResources { - dependsOn compileEnv; - dependsOn compileTypescript; - - from("build/js") { - into "lib"; - } - - filesMatching "metadata.json", { - expand( - version: project.project_version, - name: project.project_name, - ); - } -} - -test { - useJUnitPlatform(); -} - -wrapper { - gradleVersion = '8.10'; -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..ab0eb6f --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("base"); +} + +version = properties["project_version"].toString(); +group = properties["project_group"].toString(); +description = "ES5-compliant JavaScript interpreter"; + +tasks.wrapper { + gradleVersion = "8.10"; +} + +tasks.build { + subprojects.forEach { proj -> + dependsOn(proj.tasks.named("build")); + doLast { + copy { + from(proj.buildDir.resolve("libs")); + into("$buildDir/libs"); + } + } + } +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..86fc1d2 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +repositories { + mavenCentral(); +} + +plugins { + `kotlin-dsl` +} diff --git a/buildSrc/src/main/kotlin/common-java.gradle.kts b/buildSrc/src/main/kotlin/common-java.gradle.kts new file mode 100644 index 0000000..d243fb2 --- /dev/null +++ b/buildSrc/src/main/kotlin/common-java.gradle.kts @@ -0,0 +1,12 @@ +plugins { + id("common"); +} + +java { + sourceCompatibility = JavaVersion.VERSION_17; + targetCompatibility = JavaVersion.VERSION_17; + + toolchain { + languageVersion = JavaLanguageVersion.of(17); + } +} diff --git a/buildSrc/src/main/kotlin/common.gradle.kts b/buildSrc/src/main/kotlin/common.gradle.kts new file mode 100644 index 0000000..9dffd80 --- /dev/null +++ b/buildSrc/src/main/kotlin/common.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("java"); +} + +version = rootProject.version; +group = "${rootProject.group}.${project.name}"; +base.archivesName = "${properties["project_name"]}-${project.name}"; + +tasks.named("compileJava") { + options.release.set(8); +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..81f8252 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("common-java"); +} + +description = "A collection of utils and structures for the rest of the project"; + +repositories { + mavenCentral(); +} + +dependencies { + annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2"); + testRuntimeOnly("org.junit.platform:junit-platform-launcher"); +} + +tasks.processResources { + filesMatching("metadata.json", { + expand( + "version" to properties["project_version"], + "name" to properties["project_name"], + ); + }); +} + +tasks.test { + useJUnitPlatform(); +} diff --git a/src/main/java/me/topchetoeu/j2s/common/FunctionBody.java b/common/src/main/java/me/topchetoeu/j2s/common/FunctionBody.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/FunctionBody.java rename to common/src/main/java/me/topchetoeu/j2s/common/FunctionBody.java diff --git a/src/main/java/me/topchetoeu/j2s/common/Instruction.java b/common/src/main/java/me/topchetoeu/j2s/common/Instruction.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/Instruction.java rename to common/src/main/java/me/topchetoeu/j2s/common/Instruction.java diff --git a/src/main/java/me/topchetoeu/j2s/common/Metadata.java b/common/src/main/java/me/topchetoeu/j2s/common/Metadata.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/Metadata.java rename to common/src/main/java/me/topchetoeu/j2s/common/Metadata.java diff --git a/src/main/java/me/topchetoeu/j2s/common/Operation.java b/common/src/main/java/me/topchetoeu/j2s/common/Operation.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/Operation.java rename to common/src/main/java/me/topchetoeu/j2s/common/Operation.java diff --git a/src/main/java/me/topchetoeu/j2s/common/Reading.java b/common/src/main/java/me/topchetoeu/j2s/common/Reading.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/Reading.java rename to common/src/main/java/me/topchetoeu/j2s/common/Reading.java diff --git a/src/main/java/me/topchetoeu/j2s/common/SyntaxException.java b/common/src/main/java/me/topchetoeu/j2s/common/SyntaxException.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/SyntaxException.java rename to common/src/main/java/me/topchetoeu/j2s/common/SyntaxException.java diff --git a/src/main/java/me/topchetoeu/j2s/common/environment/Environment.java b/common/src/main/java/me/topchetoeu/j2s/common/environment/Environment.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/environment/Environment.java rename to common/src/main/java/me/topchetoeu/j2s/common/environment/Environment.java diff --git a/src/main/java/me/topchetoeu/j2s/common/environment/Key.java b/common/src/main/java/me/topchetoeu/j2s/common/environment/Key.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/environment/Key.java rename to common/src/main/java/me/topchetoeu/j2s/common/environment/Key.java diff --git a/src/main/java/me/topchetoeu/j2s/common/json/JSON.java b/common/src/main/java/me/topchetoeu/j2s/common/json/JSON.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/json/JSON.java rename to common/src/main/java/me/topchetoeu/j2s/common/json/JSON.java diff --git a/src/main/java/me/topchetoeu/j2s/common/json/JSONElement.java b/common/src/main/java/me/topchetoeu/j2s/common/json/JSONElement.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/json/JSONElement.java rename to common/src/main/java/me/topchetoeu/j2s/common/json/JSONElement.java diff --git a/src/main/java/me/topchetoeu/j2s/common/json/JSONList.java b/common/src/main/java/me/topchetoeu/j2s/common/json/JSONList.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/json/JSONList.java rename to common/src/main/java/me/topchetoeu/j2s/common/json/JSONList.java diff --git a/src/main/java/me/topchetoeu/j2s/common/json/JSONMap.java b/common/src/main/java/me/topchetoeu/j2s/common/json/JSONMap.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/json/JSONMap.java rename to common/src/main/java/me/topchetoeu/j2s/common/json/JSONMap.java diff --git a/src/main/java/me/topchetoeu/j2s/common/mapping/FunctionMap.java b/common/src/main/java/me/topchetoeu/j2s/common/mapping/FunctionMap.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/mapping/FunctionMap.java rename to common/src/main/java/me/topchetoeu/j2s/common/mapping/FunctionMap.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/Filename.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Filename.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/Filename.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/Filename.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/Location.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Location.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/Location.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/Location.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/ParseRes.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/ParseRes.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/ParseRes.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/ParseRes.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/Parser.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Parser.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/Parser.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/Parser.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java similarity index 91% rename from src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java index 6fae150..3f0082f 100644 --- a/src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java +++ b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Parsing.java @@ -1,7 +1,6 @@ package me.topchetoeu.j2s.common.parsing; import me.topchetoeu.j2s.common.SyntaxException; -import me.topchetoeu.j2s.compilation.values.constants.NumberNode; public class Parsing { public static boolean isDigit(Character c) { @@ -346,8 +345,8 @@ public class Parsing { if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus"); return ParseRes.failed(); } - else if (negative) return ParseRes.res(-(whole + fract) * NumberNode.power(10, exponent), n); - else return ParseRes.res((whole + fract) * NumberNode.power(10, exponent), n); + else if (negative) return ParseRes.res(-(whole + fract) * power(10, exponent), n); + else return ParseRes.res((whole + fract) * power(10, exponent), n); } public static ParseRes parseFloat(Source src, int i, boolean withMinus) { var n = skipEmpty(src, i); @@ -406,9 +405,10 @@ public class Parsing { if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus"); return ParseRes.failed(); } - else if (negative) return ParseRes.res(-(whole + fract) * NumberNode.power(10, exponent), n); - else return ParseRes.res((whole + fract) * NumberNode.power(10, exponent), n); + else if (negative) return ParseRes.res(-(whole + fract) * power(10, exponent), n); + else return ParseRes.res((whole + fract) * power(10, exponent), n); } + public static ParseRes parseInt(Source src, int i, String alphabet, boolean withMinus) { var n = skipEmpty(src, i); @@ -425,16 +425,20 @@ public class Parsing { n += 2; var res = parseHex(src, i); - if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Incomplete hexadecimal literal"); + if (!res.isSuccess()) + return res.chainError(src.loc(i + n), "Incomplete hexadecimal literal"); n += res.n; - if (negative) return ParseRes.res(-res.result, n); - else return ParseRes.res(res.result, n); + if (negative) + return ParseRes.res(-res.result, n); + else + return ParseRes.res(res.result, n); } while (true) { var digit = alphabet.indexOf(Character.toLowerCase(src.at(i + n, '\0'))); - if (digit < 0) break; + if (digit < 0) + break; parsedAny = true; result *= alphabet.length(); @@ -443,10 +447,21 @@ public class Parsing { } if (!parsedAny) { - if (negative) return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus"); + if (negative) + return ParseRes.error(src.loc(i + n), "Expected number immediatly after minus"); return ParseRes.failed(); - } - else if (negative) return ParseRes.res(-result, n); - else return ParseRes.res(result, n); + } else if (negative) + return ParseRes.res(-result, n); + else + return ParseRes.res(result, n); + } + + private static double power(double a, long b) { + if (b == 0) return 1; + if (b == 1) return a; + if (b < 0) return 1 / power(a, -b); + + if ((b & 1) == 0) return power(a * a, b / 2); + else return a * power(a * a, b / 2); } } diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/Source.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java diff --git a/src/main/java/me/topchetoeu/j2s/common/parsing/SourceLocation.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/SourceLocation.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/common/parsing/SourceLocation.java rename to common/src/main/java/me/topchetoeu/j2s/common/parsing/SourceLocation.java diff --git a/src/main/resources/metadata.json b/common/src/main/resources/metadata.json similarity index 100% rename from src/main/resources/metadata.json rename to common/src/main/resources/metadata.json diff --git a/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java b/common/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java similarity index 100% rename from src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java rename to common/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java diff --git a/compilation/build.gradle.kts b/compilation/build.gradle.kts new file mode 100644 index 0000000..83e799e --- /dev/null +++ b/compilation/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("common-java"); +} + +description = "A compiler of EcmaScript 5 code to J2S bytecode"; + +repositories { + mavenCentral(); +} + +dependencies { + annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2"); + testRuntimeOnly("org.junit.platform:junit-platform-launcher"); + implementation(project(":common")); +} + +tasks.processResources { + filesMatching("metadata.json", { + expand( + "version" to properties["project_version"], + "name" to properties["project_name"], + ); + }); +} + +tasks.test { + useJUnitPlatform(); +} diff --git a/src/main/java/me/topchetoeu/j2s/compilation/CompileResult.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/CompileResult.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/CompileResult.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/CompileResult.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/CompoundNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/CompoundNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/CompoundNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/CompoundNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/DeferredIntSupplier.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/DeferredIntSupplier.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/DeferredIntSupplier.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/DeferredIntSupplier.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/FunctionNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/FunctionNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/FunctionStatementNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionStatementNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/FunctionStatementNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionStatementNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/FunctionValueNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionValueNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/FunctionValueNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/FunctionValueNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/JavaScript.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/JavaScript.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/JavaScript.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/JavaScript.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/LabelContext.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/LabelContext.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/LabelContext.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/LabelContext.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/Node.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/Node.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/Node.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/Node.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/NodeChildren.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/NodeChildren.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/NodeChildren.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/NodeChildren.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/Parameter.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/Parameter.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/Parameter.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/Parameter.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/VariableDeclareNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/VariableDeclareNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/VariableDeclareNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/VariableDeclareNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/BreakNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/BreakNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/BreakNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/BreakNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/ContinueNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ContinueNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/ContinueNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ContinueNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/DebugNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DebugNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/DebugNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DebugNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/DeleteNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DeleteNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/DeleteNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DeleteNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/DoWhileNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DoWhileNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/DoWhileNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/DoWhileNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/ForInNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ForInNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/ForInNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ForInNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/ForNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ForNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/ForNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ForNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/IfNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/IfNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/IfNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/IfNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/ReturnNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ReturnNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/ReturnNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ReturnNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/SwitchNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/SwitchNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/SwitchNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/SwitchNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/ThrowNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ThrowNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/ThrowNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/ThrowNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/TryNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/TryNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/TryNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/TryNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/control/WhileNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/control/WhileNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/control/WhileNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/control/WhileNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/members/FieldMemberNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/members/FieldMemberNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/members/FieldMemberNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/members/FieldMemberNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/members/Member.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/members/Member.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/members/Member.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/members/Member.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/members/PropertyMemberNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/members/PropertyMemberNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/members/PropertyMemberNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/members/PropertyMemberNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTarget.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTarget.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTarget.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTarget.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTargetLike.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTargetLike.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTargetLike.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/AssignTargetLike.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/patterns/ChangeTarget.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/ChangeTarget.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/patterns/ChangeTarget.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/patterns/ChangeTarget.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/scope/FunctionScope.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/FunctionScope.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/scope/FunctionScope.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/FunctionScope.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/scope/Variable.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/Variable.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/scope/Variable.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/Variable.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableIndex.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableIndex.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/scope/VariableIndex.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableIndex.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableList.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableList.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/scope/VariableList.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/scope/VariableList.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/ArgumentsNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ArgumentsNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/ArgumentsNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ArgumentsNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/ArrayNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ArrayNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/ArrayNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ArrayNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/GlobalThisNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/GlobalThisNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/GlobalThisNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/GlobalThisNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/ObjectNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ObjectNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/ObjectNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ObjectNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/RegexNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/RegexNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/RegexNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/RegexNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/ThisNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ThisNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/ThisNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/ThisNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/VariableNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/VariableNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/VariableNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/VariableNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/constants/BoolNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/BoolNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/constants/BoolNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/BoolNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NullNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NullNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/constants/NullNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NullNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java similarity index 82% rename from src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java index b45053c..8003f09 100644 --- a/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java +++ b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/NumberNode.java @@ -23,15 +23,6 @@ public class NumberNode extends Node { this.value = value; } - public static double power(double a, long b) { - if (b == 0) return 1; - if (b == 1) return a; - if (b < 0) return 1 / power(a, -b); - - if ((b & 1) == 0) return power(a * a, b / 2); - else return a * power(a * a, b / 2); - } - public static ParseRes parse(Source src, int i) { var n = Parsing.skipEmpty(src, i); var loc = src.loc(i + n); diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/constants/StringNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/StringNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/constants/StringNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/constants/StringNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/AssignNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/AssignNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/AssignNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/AssignNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/CallNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/CallNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/CallNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/CallNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/ChangeNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/ChangeNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/ChangeNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/ChangeNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/DiscardNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/DiscardNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/DiscardNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/DiscardNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/IndexNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/IndexNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/IndexNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/IndexNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyAndNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyAndNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyAndNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyAndNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyOrNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyOrNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyOrNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/LazyOrNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/OperationNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/OperationNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/OperationNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/OperationNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/PostfixNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/PostfixNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/PostfixNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/PostfixNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/TypeofNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/TypeofNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/TypeofNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/TypeofNode.java diff --git a/src/main/java/me/topchetoeu/j2s/compilation/values/operations/VariableAssignNode.java b/compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/VariableAssignNode.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/compilation/values/operations/VariableAssignNode.java rename to compilation/src/main/java/me/topchetoeu/j2s/compilation/values/operations/VariableAssignNode.java diff --git a/compilation/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java b/compilation/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java new file mode 100644 index 0000000..638e19d --- /dev/null +++ b/compilation/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java @@ -0,0 +1,14 @@ +package me.topchetoeu.j2s; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestHelloWorld { + + @Test + public void testHelloWorld() { + final String message = "Hello World!"; + assertEquals("Hello World!", message); + } +} diff --git a/gradle.properties b/gradle.properties index 2b8d90c..f593671 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ project_group = me.topchetoeu project_name = j2s -project_version = 0.10.3-beta +project_version = 0.10.4-beta main_class = me.topchetoeu.j2s.repl.SimpleRepl diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts new file mode 100644 index 0000000..11034d7 --- /dev/null +++ b/lib/build.gradle.kts @@ -0,0 +1,68 @@ +import com.github.gradle.node.npm.task.NpmTask; + +plugins { + id("common"); + id("com.github.node-gradle.node") version "5.0.0"; +} + +tasks.compileJava { + enabled = false +} +tasks.classes { + enabled = false +} + +node { + version = "20.0.0"; + npmVersion = "8.0.0"; + download = true; +} + +tasks.register("compileStdlib") { + dependsOn("npmInstall"); + + inputs.files("rollup.config.js"); + inputs.dir("src/stdlib"); + outputs.files("build/js/stdlib.js"); + + args.set(listOf("run", "build-env")); +} +tasks.register("compileTranspiler") { + dependsOn("npmInstall"); + + inputs.files("rollup.config.js"); + inputs.dir("src/transpiler"); + outputs.files("build/js/transpiler.js"); + // nom nom tasty ram + environment.put("NODE_OPTIONS", "--max-old-space-size=4096"); + + args.set(listOf("run", "build-ts")); +} + +tasks.jar { + manifest { + attributes( + "Main-Class" to properties["main_class"].toString(), + "Build-Author" to "TopchetoEU", + ); + } +} + +tasks.processResources { + dependsOn("compileStdlib"); + dependsOn("compileTranspiler"); + + from("build/js") { + into("lib"); + } + from("src/lib") { + into("lib"); + } + + filesMatching("metadata.json", { + expand( + "version" to properties["project_version"].toString(), + "name" to properties["project_name"].toString(), + ); + }) +} diff --git a/package.json b/lib/package.json similarity index 78% rename from package.json rename to lib/package.json index 1d1eca7..0a6fb17 100644 --- a/package.json +++ b/lib/package.json @@ -1,7 +1,7 @@ { "scripts": { - "build-env": "rollup -c --environment INPUT:src/lib/libs/_entry.ts,OUTPUT:build/js/index.js,POLYFILLS:src/lib/libs/polyfills", - "build-ts": "rollup -c --environment INPUT:src/lib/transpiler/_entry.ts,OUTPUT:build/js/ts.js" + "build-env": "rollup -c --environment INPUT:src/stdlib/_entry.ts,OUTPUT:build/js/stdlib.js,POLYFILLS:src/polyfills", + "build-ts": "rollup -c --environment INPUT:src/transpiler/_entry.ts,OUTPUT:build/js/transpiler.js" }, "dependencies": { "@babel/core": "^7.26.0", diff --git a/rollup.config.js b/lib/rollup.config.js similarity index 100% rename from rollup.config.js rename to lib/rollup.config.js diff --git a/src/main/resources/lib/async.d.ts b/lib/src/lib/async.d.ts similarity index 100% rename from src/main/resources/lib/async.d.ts rename to lib/src/lib/async.d.ts diff --git a/src/main/resources/lib/errors.d.ts b/lib/src/lib/errors.d.ts similarity index 100% rename from src/main/resources/lib/errors.d.ts rename to lib/src/lib/errors.d.ts diff --git a/src/main/resources/lib/globals/json.d.ts b/lib/src/lib/globals/json.d.ts similarity index 100% rename from src/main/resources/lib/globals/json.d.ts rename to lib/src/lib/globals/json.d.ts diff --git a/src/main/resources/lib/globals/map.d.ts b/lib/src/lib/globals/map.d.ts similarity index 100% rename from src/main/resources/lib/globals/map.d.ts rename to lib/src/lib/globals/map.d.ts diff --git a/src/main/resources/lib/globals/set.d.ts b/lib/src/lib/globals/set.d.ts similarity index 100% rename from src/main/resources/lib/globals/set.d.ts rename to lib/src/lib/globals/set.d.ts diff --git a/src/main/resources/lib/globals/weak-map.d.ts b/lib/src/lib/globals/weak-map.d.ts similarity index 100% rename from src/main/resources/lib/globals/weak-map.d.ts rename to lib/src/lib/globals/weak-map.d.ts diff --git a/src/main/resources/lib/iterator.d.ts b/lib/src/lib/iterator.d.ts similarity index 100% rename from src/main/resources/lib/iterator.d.ts rename to lib/src/lib/iterator.d.ts diff --git a/src/main/resources/lib/lib.d.ts b/lib/src/lib/lib.d.ts similarity index 100% rename from src/main/resources/lib/lib.d.ts rename to lib/src/lib/lib.d.ts diff --git a/src/main/resources/lib/typing.d.ts b/lib/src/lib/typing.d.ts similarity index 100% rename from src/main/resources/lib/typing.d.ts rename to lib/src/lib/typing.d.ts diff --git a/src/main/resources/lib/values/array.d.ts b/lib/src/lib/values/array.d.ts similarity index 100% rename from src/main/resources/lib/values/array.d.ts rename to lib/src/lib/values/array.d.ts diff --git a/src/main/resources/lib/values/boolean.d.ts b/lib/src/lib/values/boolean.d.ts similarity index 100% rename from src/main/resources/lib/values/boolean.d.ts rename to lib/src/lib/values/boolean.d.ts diff --git a/src/main/resources/lib/values/function.d.ts b/lib/src/lib/values/function.d.ts similarity index 100% rename from src/main/resources/lib/values/function.d.ts rename to lib/src/lib/values/function.d.ts diff --git a/src/main/resources/lib/values/number.d.ts b/lib/src/lib/values/number.d.ts similarity index 100% rename from src/main/resources/lib/values/number.d.ts rename to lib/src/lib/values/number.d.ts diff --git a/src/main/resources/lib/values/object.d.ts b/lib/src/lib/values/object.d.ts similarity index 100% rename from src/main/resources/lib/values/object.d.ts rename to lib/src/lib/values/object.d.ts diff --git a/src/main/resources/lib/values/regexp.d.ts b/lib/src/lib/values/regexp.d.ts similarity index 100% rename from src/main/resources/lib/values/regexp.d.ts rename to lib/src/lib/values/regexp.d.ts diff --git a/src/main/resources/lib/values/string.d.ts b/lib/src/lib/values/string.d.ts similarity index 100% rename from src/main/resources/lib/values/string.d.ts rename to lib/src/lib/values/string.d.ts diff --git a/src/main/resources/lib/values/symbol.d.ts b/lib/src/lib/values/symbol.d.ts similarity index 100% rename from src/main/resources/lib/values/symbol.d.ts rename to lib/src/lib/values/symbol.d.ts diff --git a/src/lib/libs/polyfills/callSuper.js b/lib/src/polyfills/callSuper.js similarity index 71% rename from src/lib/libs/polyfills/callSuper.js rename to lib/src/polyfills/callSuper.js index 5cfc655..7074188 100644 --- a/src/lib/libs/polyfills/callSuper.js +++ b/lib/src/polyfills/callSuper.js @@ -1,4 +1,4 @@ -import { func, object } from "../primordials.ts"; +import { func, object } from "../stdlib/primordials.ts"; export default function _callSuper(self, constr, args) { return func.construct(object.getPrototype(constr), func.target(1), args || []); diff --git a/src/lib/libs/polyfills/classCallCheck.js b/lib/src/polyfills/classCallCheck.js similarity index 74% rename from src/lib/libs/polyfills/classCallCheck.js rename to lib/src/polyfills/classCallCheck.js index 0290a6f..0100703 100644 --- a/src/lib/libs/polyfills/classCallCheck.js +++ b/lib/src/polyfills/classCallCheck.js @@ -1,4 +1,4 @@ -import { func } from "../primordials.ts"; +import { func } from "../stdlib/primordials.ts"; export default function _classCallCheck() { if (func.invokeTypeInfer() !== "new") throw new TypeError("Cannot call a class as a function"); diff --git a/src/lib/libs/polyfills/createClass.js b/lib/src/polyfills/createClass.js similarity index 93% rename from src/lib/libs/polyfills/createClass.js rename to lib/src/polyfills/createClass.js index 2876e9f..1da41a7 100644 --- a/src/lib/libs/polyfills/createClass.js +++ b/lib/src/polyfills/createClass.js @@ -1,4 +1,4 @@ -import { object } from "../primordials.ts"; +import { object } from "../stdlib/primordials.ts"; function _defineProperties(target, arr) { if (!arr) return; diff --git a/src/lib/libs/polyfills/defineProperty.js b/lib/src/polyfills/defineProperty.js similarity index 76% rename from src/lib/libs/polyfills/defineProperty.js rename to lib/src/polyfills/defineProperty.js index c04e49a..24fb84e 100644 --- a/src/lib/libs/polyfills/defineProperty.js +++ b/lib/src/polyfills/defineProperty.js @@ -1,4 +1,4 @@ -import { object } from "../primordials.ts"; +import { object } from "../stdlib/primordials.ts"; export default function _defineProperty(obj, key, val) { if (obj == null) return; diff --git a/src/lib/libs/polyfills/getPrototypeOf.js b/lib/src/polyfills/getPrototypeOf.js similarity index 64% rename from src/lib/libs/polyfills/getPrototypeOf.js rename to lib/src/polyfills/getPrototypeOf.js index 7ff675f..518dce4 100644 --- a/src/lib/libs/polyfills/getPrototypeOf.js +++ b/lib/src/polyfills/getPrototypeOf.js @@ -1,4 +1,4 @@ -import { object } from "../primordials.ts"; +import { object } from "../stdlib/primordials.ts"; export default function _getPrototypeOf(obj) { return object.getPrototype(obj) || null; diff --git a/src/lib/libs/polyfills/inherits.js b/lib/src/polyfills/inherits.js similarity index 79% rename from src/lib/libs/polyfills/inherits.js rename to lib/src/polyfills/inherits.js index ad73632..3d2edfa 100644 --- a/src/lib/libs/polyfills/inherits.js +++ b/lib/src/polyfills/inherits.js @@ -1,4 +1,4 @@ -import { object } from "../primordials.ts"; +import { object } from "../stdlib/primordials.ts"; export default function _inherits(t, e) { if (e == null) { diff --git a/src/lib/libs/polyfills/possibleConstructorReturn.js b/lib/src/polyfills/possibleConstructorReturn.js similarity index 100% rename from src/lib/libs/polyfills/possibleConstructorReturn.js rename to lib/src/polyfills/possibleConstructorReturn.js diff --git a/src/lib/libs/polyfills/readOnlyError.js b/lib/src/polyfills/readOnlyError.js similarity index 100% rename from src/lib/libs/polyfills/readOnlyError.js rename to lib/src/polyfills/readOnlyError.js diff --git a/src/lib/libs/polyfills/setPrototypeOf.js b/lib/src/polyfills/setPrototypeOf.js similarity index 65% rename from src/lib/libs/polyfills/setPrototypeOf.js rename to lib/src/polyfills/setPrototypeOf.js index 63a984b..30003ea 100644 --- a/src/lib/libs/polyfills/setPrototypeOf.js +++ b/lib/src/polyfills/setPrototypeOf.js @@ -1,4 +1,4 @@ -import { object } from "../primordials"; +import { object } from "../stdlib/primordials"; export default function _setPrototypeOf(obj, proto) { object.setPrototype(obj, proto); diff --git a/src/lib/libs/polyfills/typeof.js b/lib/src/polyfills/typeof.js similarity index 100% rename from src/lib/libs/polyfills/typeof.js rename to lib/src/polyfills/typeof.js diff --git a/src/lib/libs/_entry.ts b/lib/src/stdlib/_entry.ts similarity index 100% rename from src/lib/libs/_entry.ts rename to lib/src/stdlib/_entry.ts diff --git a/src/lib/libs/arrays/ArrayBuffer.ts b/lib/src/stdlib/arrays/ArrayBuffer.ts similarity index 100% rename from src/lib/libs/arrays/ArrayBuffer.ts rename to lib/src/stdlib/arrays/ArrayBuffer.ts diff --git a/src/lib/libs/arrays/Int32Array.ts b/lib/src/stdlib/arrays/Int32Array.ts similarity index 100% rename from src/lib/libs/arrays/Int32Array.ts rename to lib/src/stdlib/arrays/Int32Array.ts diff --git a/src/lib/libs/arrays/TypedArray.ts b/lib/src/stdlib/arrays/TypedArray.ts similarity index 100% rename from src/lib/libs/arrays/TypedArray.ts rename to lib/src/stdlib/arrays/TypedArray.ts diff --git a/src/lib/libs/arrays/Uint8Array.ts b/lib/src/stdlib/arrays/Uint8Array.ts similarity index 100% rename from src/lib/libs/arrays/Uint8Array.ts rename to lib/src/stdlib/arrays/Uint8Array.ts diff --git a/src/lib/libs/classes/date.ts b/lib/src/stdlib/classes/date.ts similarity index 100% rename from src/lib/libs/classes/date.ts rename to lib/src/stdlib/classes/date.ts diff --git a/src/lib/libs/classes/map.ts b/lib/src/stdlib/classes/map.ts similarity index 100% rename from src/lib/libs/classes/map.ts rename to lib/src/stdlib/classes/map.ts diff --git a/src/lib/libs/classes/promise.ts b/lib/src/stdlib/classes/promise.ts similarity index 100% rename from src/lib/libs/classes/promise.ts rename to lib/src/stdlib/classes/promise.ts diff --git a/src/lib/libs/classes/set.ts b/lib/src/stdlib/classes/set.ts similarity index 100% rename from src/lib/libs/classes/set.ts rename to lib/src/stdlib/classes/set.ts diff --git a/src/lib/libs/namespaces/console.ts b/lib/src/stdlib/namespaces/console.ts similarity index 100% rename from src/lib/libs/namespaces/console.ts rename to lib/src/stdlib/namespaces/console.ts diff --git a/src/lib/libs/namespaces/json.ts b/lib/src/stdlib/namespaces/json.ts similarity index 100% rename from src/lib/libs/namespaces/json.ts rename to lib/src/stdlib/namespaces/json.ts diff --git a/src/lib/libs/namespaces/math.ts b/lib/src/stdlib/namespaces/math.ts similarity index 100% rename from src/lib/libs/namespaces/math.ts rename to lib/src/stdlib/namespaces/math.ts diff --git a/src/lib/libs/primordials.ts b/lib/src/stdlib/primordials.ts similarity index 100% rename from src/lib/libs/primordials.ts rename to lib/src/stdlib/primordials.ts diff --git a/src/lib/libs/url.ts b/lib/src/stdlib/url.ts similarity index 100% rename from src/lib/libs/url.ts rename to lib/src/stdlib/url.ts diff --git a/src/lib/libs/utils.ts b/lib/src/stdlib/utils.ts similarity index 100% rename from src/lib/libs/utils.ts rename to lib/src/stdlib/utils.ts diff --git a/src/lib/libs/values/array.ts b/lib/src/stdlib/values/array.ts similarity index 98% rename from src/lib/libs/values/array.ts rename to lib/src/stdlib/values/array.ts index 4973fb2..e818063 100644 --- a/src/lib/libs/values/array.ts +++ b/lib/src/stdlib/values/array.ts @@ -1,6 +1,6 @@ -import { Error } from "../values/errors.ts"; +import { Error } from "./errors.ts"; import { func, object, string } from "../primordials.ts"; -import { String } from "../values/string.ts"; +import { String } from "./string.ts"; import { limitI, symbols, wrapI } from "../utils.ts"; export const Array = (() => { diff --git a/src/lib/libs/values/boolean.ts b/lib/src/stdlib/values/boolean.ts similarity index 100% rename from src/lib/libs/values/boolean.ts rename to lib/src/stdlib/values/boolean.ts diff --git a/src/lib/libs/values/errors.ts b/lib/src/stdlib/values/errors.ts similarity index 100% rename from src/lib/libs/values/errors.ts rename to lib/src/stdlib/values/errors.ts diff --git a/src/lib/libs/values/function.ts b/lib/src/stdlib/values/function.ts similarity index 100% rename from src/lib/libs/values/function.ts rename to lib/src/stdlib/values/function.ts diff --git a/src/lib/libs/values/number.ts b/lib/src/stdlib/values/number.ts similarity index 100% rename from src/lib/libs/values/number.ts rename to lib/src/stdlib/values/number.ts diff --git a/src/lib/libs/values/object.ts b/lib/src/stdlib/values/object.ts similarity index 99% rename from src/lib/libs/values/object.ts rename to lib/src/stdlib/values/object.ts index aa53c28..3ebfba4 100644 --- a/src/lib/libs/values/object.ts +++ b/lib/src/stdlib/values/object.ts @@ -4,7 +4,7 @@ import { Number } from "./number.ts"; import { func, object } from "../primordials.ts"; import { String } from "./string.ts"; import { symbols, valueKey } from "../utils.ts"; -import { Symbol } from "../values/symbol.ts"; +import { Symbol } from "./symbol.ts"; export const Object = (() => { class Object { diff --git a/src/lib/libs/values/regex.ts b/lib/src/stdlib/values/regex.ts similarity index 100% rename from src/lib/libs/values/regex.ts rename to lib/src/stdlib/values/regex.ts diff --git a/src/lib/libs/values/string.ts b/lib/src/stdlib/values/string.ts similarity index 100% rename from src/lib/libs/values/string.ts rename to lib/src/stdlib/values/string.ts diff --git a/src/lib/libs/values/symbol.ts b/lib/src/stdlib/values/symbol.ts similarity index 100% rename from src/lib/libs/values/symbol.ts rename to lib/src/stdlib/values/symbol.ts diff --git a/src/lib/transpiler/_entry.ts b/lib/src/transpiler/_entry.ts similarity index 100% rename from src/lib/transpiler/_entry.ts rename to lib/src/transpiler/_entry.ts diff --git a/src/lib/transpiler/babel.ts b/lib/src/transpiler/babel.ts similarity index 100% rename from src/lib/transpiler/babel.ts rename to lib/src/transpiler/babel.ts diff --git a/src/lib/transpiler/coffeescript.ts b/lib/src/transpiler/coffeescript.ts similarity index 100% rename from src/lib/transpiler/coffeescript.ts rename to lib/src/transpiler/coffeescript.ts diff --git a/src/lib/transpiler/map.ts b/lib/src/transpiler/map.ts similarity index 100% rename from src/lib/transpiler/map.ts rename to lib/src/transpiler/map.ts diff --git a/src/lib/transpiler/transpiler.d.ts b/lib/src/transpiler/transpiler.d.ts similarity index 100% rename from src/lib/transpiler/transpiler.d.ts rename to lib/src/transpiler/transpiler.d.ts diff --git a/src/lib/transpiler/typescript.ts b/lib/src/transpiler/typescript.ts similarity index 100% rename from src/lib/transpiler/typescript.ts rename to lib/src/transpiler/typescript.ts diff --git a/tsconfig.json b/lib/tsconfig.json similarity index 85% rename from tsconfig.json rename to lib/tsconfig.json index c24d63a..0ca823e 100644 --- a/tsconfig.json +++ b/lib/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src/lib/**/*.ts", "src/main/resources/lib/lib.d.ts"], + "include": ["**/*.ts"], "compilerOptions": { "strict": true, "esModuleInterop": true, diff --git a/repl/build.gradle.kts b/repl/build.gradle.kts new file mode 100644 index 0000000..934dd1e --- /dev/null +++ b/repl/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + id("common-java"); + id("com.gradleup.shadow") version "9.0.0-beta4"; +} + +description = "A simple REPL for the interpreter, can be used for simple prototyping"; + +repositories { + mavenCentral(); +} + +dependencies { + annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2"); + testRuntimeOnly("org.junit.platform:junit-platform-launcher"); + implementation(project(":common")); + implementation(project(":compilation")); + implementation(project(":runtime")); + implementation(project(":lib")); +} + +tasks.processResources { + filesMatching("metadata.json", { + expand( + "version" to properties["project_version"], + "name" to properties["project_name"], + ); + }); +} + +tasks.test { + useJUnitPlatform(); +} + + +tasks.jar { + dependsOn("shadowJar"); + + manifest { + attributes( + "Main-Class" to properties["main_class"], + // 'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), + // 'Build-Branch': versioning.info.branch, + // 'Build-Revision': versioning.info.commit, + // 'Build-Jdk': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", + // 'Build-Author': 'TopchetoEU', + ); + } +} + diff --git a/src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java b/repl/src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java similarity index 93% rename from src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java index 5c51078..52da439 100644 --- a/src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java +++ b/repl/src/main/java/me/topchetoeu/j2s/repl/SimpleRepl.java @@ -13,9 +13,11 @@ import java.util.Optional; import java.util.WeakHashMap; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; +import java.util.function.Function; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import me.topchetoeu.j2s.common.FunctionBody; import me.topchetoeu.j2s.common.Metadata; import me.topchetoeu.j2s.common.Reading; import me.topchetoeu.j2s.common.SyntaxException; @@ -23,9 +25,13 @@ import me.topchetoeu.j2s.common.environment.Environment; import me.topchetoeu.j2s.common.environment.Key; import me.topchetoeu.j2s.common.json.JSON; import me.topchetoeu.j2s.common.parsing.Filename; +import me.topchetoeu.j2s.common.parsing.Location; +import me.topchetoeu.j2s.compilation.CompileResult; +import me.topchetoeu.j2s.compilation.JavaScript; import me.topchetoeu.j2s.repl.debug.DebugServer; import me.topchetoeu.j2s.repl.debug.Debugger; import me.topchetoeu.j2s.repl.debug.SimpleDebugger; +import me.topchetoeu.j2s.repl.mapping.NativeMapper; import me.topchetoeu.j2s.runtime.ArgumentsValue; import me.topchetoeu.j2s.runtime.Compiler; import me.topchetoeu.j2s.runtime.Engine; @@ -35,6 +41,7 @@ import me.topchetoeu.j2s.runtime.JSONConverter; import me.topchetoeu.j2s.runtime.debug.DebugContext; import me.topchetoeu.j2s.runtime.exceptions.EngineException; import me.topchetoeu.j2s.runtime.values.Value; +import me.topchetoeu.j2s.runtime.values.functions.CodeFunction; import me.topchetoeu.j2s.runtime.values.functions.FunctionValue; import me.topchetoeu.j2s.runtime.values.functions.NativeFunction; import me.topchetoeu.j2s.runtime.values.objects.ArrayLikeValue; @@ -52,6 +59,21 @@ import me.topchetoeu.j2s.runtime.values.primitives.VoidValue; import me.topchetoeu.j2s.runtime.values.primitives.numbers.NumberValue; public class SimpleRepl { + public static final Compiler DEFAULT_COMPILER = (env, filename, raw, mapper) -> { + try { + var res = JavaScript.compile(env, filename, raw, true); + var body = res.body(); + DebugContext.get(env).onSource(filename, raw); + registerFunc(env, body, res, mapper); + return new CodeFunction(env, filename.toString(), body, new Value[0][]); + } + catch (SyntaxException e) { + var res = EngineException.ofSyntax(e.msg); + res.add(env, e.loc.filename() + "", e.loc); + throw res; + } + }; + static Thread engineTask, debugTask; static Engine engine = new Engine(); static Environment environment = Environment.empty(), tsEnvironment; @@ -775,18 +797,39 @@ public class SimpleRepl { EventLoop.get(stubEnv).pushMsg( false, stubEnv, - new Filename(Metadata.name(), "init.js"), Reading.resourceToString("lib/index.js"), + new Filename(Metadata.name(), "init.js"), Reading.resourceToString("lib/stdlib.js"), Value.UNDEFINED ).get(); return env; } + private static Compiler wrap(Compiler first, Environment compilerEnv, Environment targetEnv, FunctionValue factory) { + var curr = new NativeFunction(args -> { + var filename = Filename.parse(args.get(0).toString(args.env)); + var src = args.get(1).toString(args.env); + var mapper = (FunctionValue)args.get(2); + return first.compile(targetEnv, filename, src, NativeMapper.unwrap(args.env, mapper)); + }); + + var next = (FunctionValue)factory.apply(compilerEnv, Value.UNDEFINED, curr); + + return (env, filename, source, map) -> { + return (FunctionValue)next.apply( + compilerEnv, Value.UNDEFINED, + StringValue.of(filename.toString()), + StringValue.of(source), + new NativeMapper(map) + ); + }; + } + + private static Environment initEnv() { var env = new Environment(); env.add(EventLoop.KEY, engine); env.add(DebugContext.KEY, new DebugContext()); - env.add(Compiler.KEY, Compiler.DEFAULT); + env.add(Compiler.KEY, DEFAULT_COMPILER); // env.add(CompileResult.DEBUG_LOG); var glob = Value.global(env); @@ -848,16 +891,25 @@ public class SimpleRepl { return Value.UNDEFINED; })); - var ts = Reading.resourceToString("lib/ts.js"); + var ts = Reading.resourceToString("lib/transpiler.js"); if (ts != null) EventLoop.get(tsEnvironment).pushMsg( false, tsEnvironment, - new Filename(Metadata.name(), "ts.js"), ts, + new Filename(Metadata.name(), "transpiler.js"), ts, Value.UNDEFINED, setter ).get(); - var tsCompiler = Compiler.get(environment).wrap(tsEnvironment, environment, tsCompilerFactory[0]); + var tsCompiler = wrap(Compiler.get(environment), tsEnvironment, environment, tsCompilerFactory[0]); environment.add(Compiler.KEY, tsCompiler); } + private static void registerFunc(Environment env, FunctionBody body, CompileResult res, Function mapper) { + var map = res.map(mapper); + + DebugContext.get(env).onFunctionLoad(body, map); + + for (var i = 0; i < body.children.length; i++) { + registerFunc(env, body.children[i], res.children.get(i), mapper); + } + } public static void main(String args[]) throws InterruptedException { SimpleRepl.args = args; diff --git a/src/main/java/me/topchetoeu/j2s/repl/V8Error.java b/repl/src/main/java/me/topchetoeu/j2s/repl/V8Error.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/V8Error.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/V8Error.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/DebugServer.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/DebugServer.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/DebugServer.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/DebugServer.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/Debugger.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/Debugger.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/Debugger.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/Debugger.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/DebuggerProvider.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/DebuggerProvider.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/DebuggerProvider.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/DebuggerProvider.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/HttpRequest.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/HttpRequest.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/HttpRequest.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/HttpRequest.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/ScopeObject.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/ScopeObject.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/ScopeObject.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/ScopeObject.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java similarity index 99% rename from src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java index c1d80b2..793a722 100644 --- a/src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java +++ b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/SimpleDebugger.java @@ -24,6 +24,7 @@ import me.topchetoeu.j2s.common.json.JSONMap; import me.topchetoeu.j2s.common.mapping.FunctionMap; import me.topchetoeu.j2s.common.parsing.Filename; import me.topchetoeu.j2s.common.parsing.Location; +import me.topchetoeu.j2s.repl.SimpleRepl; import me.topchetoeu.j2s.runtime.Compiler; import me.topchetoeu.j2s.runtime.Engine; import me.topchetoeu.j2s.runtime.EventLoop; @@ -634,7 +635,7 @@ public class SimpleDebugger implements Debugger { env.remove(DebugContext.KEY); env.remove(EventLoop.KEY); env.remove(Value.GLOBAL); - env.add(Compiler.KEY, Compiler.DEFAULT); + env.add(Compiler.KEY, SimpleRepl.DEFAULT_COMPILER); env.add(EventLoop.KEY, engine); env.add(Value.GLOBAL, codeFrame.variables); diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/StackObject.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/StackObject.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/StackObject.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/StackObject.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/V8Error.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Error.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/V8Error.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Error.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/V8Event.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Event.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/V8Event.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Event.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/V8Message.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Message.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/V8Message.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Message.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/V8Result.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Result.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/V8Result.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/V8Result.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocket.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocket.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/WebSocket.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocket.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocketMessage.java b/repl/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocketMessage.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/debug/WebSocketMessage.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/debug/WebSocketMessage.java diff --git a/src/main/java/me/topchetoeu/j2s/repl/mapping/NativeMapper.java b/repl/src/main/java/me/topchetoeu/j2s/repl/mapping/NativeMapper.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/repl/mapping/NativeMapper.java rename to repl/src/main/java/me/topchetoeu/j2s/repl/mapping/NativeMapper.java diff --git a/src/main/resources/debugger/favicon.png b/repl/src/main/resources/debugger/favicon.png similarity index 100% rename from src/main/resources/debugger/favicon.png rename to repl/src/main/resources/debugger/favicon.png diff --git a/src/main/resources/debugger/index.html b/repl/src/main/resources/debugger/index.html similarity index 100% rename from src/main/resources/debugger/index.html rename to repl/src/main/resources/debugger/index.html diff --git a/src/main/resources/debugger/protocol.json b/repl/src/main/resources/debugger/protocol.json similarity index 100% rename from src/main/resources/debugger/protocol.json rename to repl/src/main/resources/debugger/protocol.json diff --git a/repl/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java b/repl/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java new file mode 100644 index 0000000..638e19d --- /dev/null +++ b/repl/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java @@ -0,0 +1,14 @@ +package me.topchetoeu.j2s; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestHelloWorld { + + @Test + public void testHelloWorld() { + final String message = "Hello World!"; + assertEquals("Hello World!", message); + } +} diff --git a/runtime/build.gradle.kts b/runtime/build.gradle.kts new file mode 100644 index 0000000..99d76a1 --- /dev/null +++ b/runtime/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("common-java"); +} + +description = "The runtime of J2S, used to execute J2S bytecode"; + +repositories { + mavenCentral(); +} + +dependencies { + annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2"); + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2"); + testRuntimeOnly("org.junit.platform:junit-platform-launcher"); + implementation(project(":common")); +} + +tasks.processResources { + filesMatching("metadata.json", { + expand( + "version" to properties["project_version"], + "name" to properties["project_name"], + ); + }); +} + +tasks.test { + useJUnitPlatform(); +} diff --git a/src/main/java/me/topchetoeu/j2s/runtime/ArgumentsValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/ArgumentsValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/ArgumentsValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/ArgumentsValue.java diff --git a/runtime/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java new file mode 100644 index 0000000..f2ec26d --- /dev/null +++ b/runtime/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java @@ -0,0 +1,26 @@ +package me.topchetoeu.j2s.runtime; + +import java.util.function.Function; + +import me.topchetoeu.j2s.common.environment.Environment; +import me.topchetoeu.j2s.common.environment.Key; +import me.topchetoeu.j2s.common.parsing.Filename; +import me.topchetoeu.j2s.common.parsing.Location; +import me.topchetoeu.j2s.runtime.exceptions.EngineException; +import me.topchetoeu.j2s.runtime.values.functions.FunctionValue; + +public interface Compiler { + public Key KEY = new Key<>(); + + public FunctionValue compile(Environment env, Filename filename, String source, Function map); + + public static Compiler get(Environment ext) { + return ext.get(KEY, (env, filename, src, map) -> { + throw EngineException.ofError("No compiler attached to engine"); + }); + } + + public static FunctionValue compileFunc(Environment env, Filename filename, String raw) { + return get(env).compile(env, filename, raw, v -> v); + } +} diff --git a/src/main/java/me/topchetoeu/j2s/runtime/Engine.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/Engine.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/Engine.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/Engine.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/EventLoop.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/EventLoop.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/EventLoop.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/EventLoop.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/Frame.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/Frame.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/Frame.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/Frame.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/InstructionRunner.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/InstructionRunner.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/InstructionRunner.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/InstructionRunner.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/JSONConverter.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/JSONConverter.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/JSONConverter.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/JSONConverter.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugContext.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugContext.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/debug/DebugContext.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugContext.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugHandler.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugHandler.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/debug/DebugHandler.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/debug/DebugHandler.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/exceptions/EngineException.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/exceptions/EngineException.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/exceptions/EngineException.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/exceptions/EngineException.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/KeyCache.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/KeyCache.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/KeyCache.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/KeyCache.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/Member.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/Member.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/Member.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/Member.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/Value.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/Value.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/Value.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/Value.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/functions/Arguments.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/Arguments.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/functions/Arguments.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/Arguments.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/functions/CodeFunction.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/CodeFunction.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/functions/CodeFunction.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/CodeFunction.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/functions/FunctionValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/FunctionValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/functions/FunctionValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/FunctionValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/functions/NativeFunction.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/NativeFunction.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/functions/NativeFunction.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/functions/NativeFunction.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayLikeValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayLikeValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayLikeValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayLikeValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ArrayValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ObjectValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ObjectValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/ObjectValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/ObjectValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int32ArrayValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int32ArrayValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int32ArrayValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int32ArrayValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int8ArrayValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int8ArrayValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int8ArrayValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Int8ArrayValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/TypedArrayValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/TypedArrayValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/TypedArrayValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/TypedArrayValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Uint8ArrayValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Uint8ArrayValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Uint8ArrayValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/objects/buffers/Uint8ArrayValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/BoolValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/BoolValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/BoolValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/BoolValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/PrimitiveValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/PrimitiveValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/PrimitiveValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/PrimitiveValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/StringValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/StringValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/StringValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/StringValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/SymbolValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/SymbolValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/SymbolValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/SymbolValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/UserValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/UserValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/UserValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/UserValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/VoidValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/VoidValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/VoidValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/VoidValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/DoubleValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/DoubleValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/DoubleValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/DoubleValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/IntValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/IntValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/IntValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/IntValue.java diff --git a/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/NumberValue.java b/runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/NumberValue.java similarity index 100% rename from src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/NumberValue.java rename to runtime/src/main/java/me/topchetoeu/j2s/runtime/values/primitives/numbers/NumberValue.java diff --git a/runtime/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java b/runtime/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java new file mode 100644 index 0000000..638e19d --- /dev/null +++ b/runtime/src/main/test/java/me/topchetoeu/j2s/TestHelloWorld.java @@ -0,0 +1,14 @@ +package me.topchetoeu.j2s; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestHelloWorld { + + @Test + public void testHelloWorld() { + final String message = "Hello World!"; + assertEquals("Hello World!", message); + } +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 222af2c..0000000 --- a/settings.gradle +++ /dev/null @@ -1,12 +0,0 @@ -pluginManagement { - repositories { - mavenCentral(); - gradlePluginPortal(); - } -} - -plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'; -} - -rootProject.name = properties.project_name; diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..f66048b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,18 @@ +pluginManagement { + repositories { + mavenCentral(); + gradlePluginPortal(); + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"; +} + +// rootProject.name = properties.project_name; + +include(":lib"); +include(":common"); +include(":repl"); +include(":runtime"); +include(":compilation"); \ No newline at end of file diff --git a/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java b/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java deleted file mode 100644 index a0bed47..0000000 --- a/src/main/java/me/topchetoeu/j2s/runtime/Compiler.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.topchetoeu.j2s.runtime; - -import java.util.function.Function; - -import me.topchetoeu.j2s.common.FunctionBody; -import me.topchetoeu.j2s.common.SyntaxException; -import me.topchetoeu.j2s.common.environment.Environment; -import me.topchetoeu.j2s.common.environment.Key; -import me.topchetoeu.j2s.common.parsing.Filename; -import me.topchetoeu.j2s.common.parsing.Location; -import me.topchetoeu.j2s.compilation.CompileResult; -import me.topchetoeu.j2s.compilation.JavaScript; -import me.topchetoeu.j2s.repl.mapping.NativeMapper; -import me.topchetoeu.j2s.runtime.debug.DebugContext; -import me.topchetoeu.j2s.runtime.exceptions.EngineException; -import me.topchetoeu.j2s.runtime.values.Value; -import me.topchetoeu.j2s.runtime.values.functions.CodeFunction; -import me.topchetoeu.j2s.runtime.values.functions.FunctionValue; -import me.topchetoeu.j2s.runtime.values.functions.NativeFunction; -import me.topchetoeu.j2s.runtime.values.primitives.StringValue; - -public interface Compiler { - public static final Compiler DEFAULT = (env, filename, raw, mapper) -> { - try { - var res = JavaScript.compile(env, filename, raw, true); - var body = res.body(); - DebugContext.get(env).onSource(filename, raw); - registerFunc(env, body, res, mapper); - return new CodeFunction(env, filename.toString(), body, new Value[0][]); - } - catch (SyntaxException e) { - var res = EngineException.ofSyntax(e.msg); - res.add(env, e.loc.filename() + "", e.loc); - throw res; - } - }; - - public Key KEY = new Key<>(); - - public FunctionValue compile(Environment env, Filename filename, String source, Function map); - - public default Compiler wrap(Environment compilerEnv, Environment targetEnv, FunctionValue factory) { - var curr = new NativeFunction(args -> { - var filename = Filename.parse(args.get(0).toString(args.env)); - var src = args.get(1).toString(args.env); - var mapper = (FunctionValue)args.get(2); - return this.compile(targetEnv, filename, src, NativeMapper.unwrap(args.env, mapper)); - }); - - var next = (FunctionValue)factory.apply(compilerEnv, Value.UNDEFINED, curr); - - return (env, filename, source, map) -> { - return (FunctionValue)next.apply( - compilerEnv, Value.UNDEFINED, - StringValue.of(filename.toString()), - StringValue.of(source), - new NativeMapper(map) - ); - }; - } - - public static Compiler get(Environment ext) { - return ext.get(KEY, (env, filename, src, map) -> { - throw EngineException.ofError("No compiler attached to engine"); - }); - } - - static void registerFunc(Environment env, FunctionBody body, CompileResult res, Function mapper) { - var map = res.map(mapper); - - DebugContext.get(env).onFunctionLoad(body, map); - - for (var i = 0; i < body.children.length; i++) { - registerFunc(env, body.children[i], res.children.get(i), mapper); - } - } - - public static FunctionValue compileFunc(Environment env, Filename filename, String raw) { - return get(env).compile(env, filename, raw, v -> v); - } -}