Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

!/src
!/src/**/*

/src/assets/js/ts.js

!/doc
!/doc/**/*

!/tests
!/tests/**/*


!/.github
!/.github/**/*

Expand Down
30 changes: 25 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The following is a minified version of the unmodified Typescript 5.2
}
async function compileJava(conf) {
try {
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/Metadata.java')).toString()
await fs.writeFile('Metadata.java', (await fs.readFile('src/me/topchetoeu/jscript/common/Metadata.java')).toString()
.replace('${VERSION}', conf.version)
.replace('${NAME}', conf.name)
.replace('${AUTHOR}', conf.author)
Expand All @@ -136,11 +136,22 @@ async function compileJava(conf) {
await fs.rm('Metadata.java');
}
}
async function jar(conf, project, mainClass) {
const args = [
'jar', '-c',
'-f', `dst/${project}-v${conf.version}.jar`,
];
if (mainClass) args.push('-e', mainClass);
args.push('-C', 'dst/classes', project.replaceAll('.', '/'));
console.log(args.join(' '));

await run(true, ...args);
}

(async () => {
try {
if (argv[2] === 'init-ts') {
await downloadTypescript('src/assets/js/ts.js');
await downloadTypescript('src/me/topchetoeu/jscript/utils/assets/js/ts.js');
}
else {
const conf = {
Expand All @@ -156,12 +167,21 @@ async function compileJava(conf) {
try { await fs.rm('dst', { recursive: true }); } catch {}

await Promise.all([
downloadTypescript('dst/classes/assets/js/ts.js'),
copy('src', 'dst/classes', v => !v.endsWith('.java')),
(async () => {
await copy('src', 'dst/classes', v => !v.endsWith('.java'));
// await downloadTypescript('dst/classes/me/topchetoeu/jscript/utils/assets/js/ts.js');
})(),
compileJava(conf),
]);

await run(true, 'jar', '-c', '-f', 'dst/jscript.jar', '-e', 'me.topchetoeu.jscript.Main', '-C', 'dst/classes', '.');
await Promise.all([
jar(conf, 'me.topchetoeu.jscript.common'),
jar(conf, 'me.topchetoeu.jscript.core'),
jar(conf, 'me.topchetoeu.jscript.lib'),
jar(conf, 'me.topchetoeu.jscript.utils'),
jar(conf, 'me.topchetoeu.jscript', 'me.topchetoeu.jscript.utils.JScriptRepl'),
]);

console.log('Done!');
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

public class Buffer {
private byte[] data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

import java.io.File;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

public class Location implements Comparable<Location> {
public static final Location INTERNAL = new Location(0, 0, new Filename("jscript", "native"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

public class Metadata {
private static final String VERSION = "${VERSION}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript;
package me.topchetoeu.jscript.common;

public interface ResultRunnable<T> {
T run();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.events;
package me.topchetoeu.jscript.common.events;

public interface Awaitable<T> {
public static interface ResultHandler<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.events;
package me.topchetoeu.jscript.common.events;

public class DataNotifier<T> implements Awaitable<T> {
private Notifier notifier = new Notifier();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.topchetoeu.jscript.events;
package me.topchetoeu.jscript.common.events;

import me.topchetoeu.jscript.exceptions.InterruptException;
import me.topchetoeu.jscript.core.exceptions.InterruptException;

public class Notifier {
private boolean ok = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package me.topchetoeu.jscript.json;
package me.topchetoeu.jscript.common.json;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import me.topchetoeu.jscript.Filename;
import me.topchetoeu.jscript.engine.Context;
import me.topchetoeu.jscript.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException;
import me.topchetoeu.jscript.exceptions.SyntaxException;
import me.topchetoeu.jscript.parsing.Operator;
import me.topchetoeu.jscript.parsing.ParseRes;
import me.topchetoeu.jscript.parsing.Parsing;
import me.topchetoeu.jscript.parsing.Token;
import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.core.exceptions.SyntaxException;
import me.topchetoeu.jscript.core.parsing.Operator;
import me.topchetoeu.jscript.core.parsing.ParseRes;
import me.topchetoeu.jscript.core.parsing.Parsing;
import me.topchetoeu.jscript.core.parsing.Token;

public class JSON {
public static Object toJs(JSONElement val) {
Expand Down Expand Up @@ -58,8 +58,8 @@ private static JSONElement fromJs(Context ctx, Object val, HashSet<Object> prev)

var res = new JSONMap();

for (var el : ((ObjectValue)val).keys(false)) {
var jsonEl = fromJs(ctx, ((ObjectValue)val).getMember(ctx, el), prev);
for (var el : Values.getMembers(ctx, val, false, false)) {
var jsonEl = fromJs(ctx, Values.getMember(ctx, val, el), prev);
if (jsonEl == null) continue;
if (el instanceof String || el instanceof Number) res.put(el.toString(), jsonEl);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json;
package me.topchetoeu.jscript.common.json;

public class JSONElement {
public static enum Type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json;
package me.topchetoeu.jscript.common.json;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json;
package me.topchetoeu.jscript.common.json;

import java.util.Collection;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.engine.Operation;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.engine.Operation;

public abstract class AssignableStatement extends Statement {
public abstract Statement toAssign(Statement val, Operation operation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import me.topchetoeu.jscript.engine.values.Values;
import me.topchetoeu.jscript.core.engine.values.Values;

public final class CalculateResult {
public final boolean exists;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.Vector;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.Environment;
import me.topchetoeu.jscript.engine.values.CodeFunction;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.core.engine.values.CodeFunction;

public class CompileTarget {
public final Vector<Instruction> target = new Vector<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import java.util.List;
import java.util.Vector;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.core.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class CompoundStatement extends Statement {
public final Statement[] statements;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

public class FunctionBody {
public final Instruction[] instructions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.engine.Operation;
import me.topchetoeu.jscript.exceptions.SyntaxException;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.core.exceptions.SyntaxException;

public class Instruction {
public static enum Type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public abstract class Statement {
private Location _loc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.exceptions.SyntaxException;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.core.exceptions.SyntaxException;

public class ThrowSyntaxStatement extends Statement {
public final String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation;
package me.topchetoeu.jscript.core.compilation;

import java.util.List;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.core.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class VariableDeclareStatement extends Statement {
public static class Pair {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.control;
package me.topchetoeu.jscript.core.compilation.control;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class BreakStatement extends Statement {
public final String label;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.control;
package me.topchetoeu.jscript.core.compilation.control;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class ContinueStatement extends Statement {
public final String label;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.control;
package me.topchetoeu.jscript.core.compilation.control;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class DebugStatement extends Statement {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.control;
package me.topchetoeu.jscript.core.compilation.control;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class DeleteStatement extends Statement {
public final Statement key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.control;
package me.topchetoeu.jscript.core.compilation.control;

import me.topchetoeu.jscript.Location;
import me.topchetoeu.jscript.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;

public class DoWhileStatement extends Statement {
public final Statement condition, body;
Expand Down
Loading