Compare commits

...

2 Commits

Author SHA1 Message Date
b791f3277e
refactor: split up code in 4 modules 2024-01-10 11:21:09 +02:00
5e6e6fea61
feat: some API improvements 2024-01-07 13:40:01 +02:00
174 changed files with 1135 additions and 1117 deletions

5
.gitignore vendored
View File

@ -2,12 +2,15 @@
!/src !/src
!/src/**/* !/src/**/*
/src/assets/js/ts.js /src/assets/js/ts.js
!/doc
!/doc/**/*
!/tests !/tests
!/tests/**/* !/tests/**/*
!/.github !/.github
!/.github/**/* !/.github/**/*

View File

@ -118,7 +118,7 @@ The following is a minified version of the unmodified Typescript 5.2
} }
async function compileJava(conf) { async function compileJava(conf) {
try { 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('${VERSION}', conf.version)
.replace('${NAME}', conf.name) .replace('${NAME}', conf.name)
.replace('${AUTHOR}', conf.author) .replace('${AUTHOR}', conf.author)
@ -136,11 +136,22 @@ async function compileJava(conf) {
await fs.rm('Metadata.java'); 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 () => { (async () => {
try { try {
if (argv[2] === 'init-ts') { if (argv[2] === 'init-ts') {
await downloadTypescript('src/assets/js/ts.js'); await downloadTypescript('src/me/topchetoeu/jscript/utils/assets/js/ts.js');
} }
else { else {
const conf = { const conf = {
@ -156,12 +167,21 @@ async function compileJava(conf) {
try { await fs.rm('dst', { recursive: true }); } catch {} try { await fs.rm('dst', { recursive: true }); } catch {}
await Promise.all([ await Promise.all([
downloadTypescript('dst/classes/assets/js/ts.js'), (async () => {
copy('src', 'dst/classes', v => !v.endsWith('.java')), await copy('src', 'dst/classes', v => !v.endsWith('.java'));
// await downloadTypescript('dst/classes/me/topchetoeu/jscript/utils/assets/js/ts.js');
})(),
compileJava(conf), 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!'); console.log('Done!');
} }
} }

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript; package me.topchetoeu.jscript.common;
public class Buffer { public class Buffer {
private byte[] data; private byte[] data;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript; package me.topchetoeu.jscript.common;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;

View File

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

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript; package me.topchetoeu.jscript.common;
public class Metadata { public class Metadata {
private static final String VERSION = "${VERSION}"; private static final String VERSION = "${VERSION}";

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript; package me.topchetoeu.jscript.common;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript; package me.topchetoeu.jscript.common;
public interface ResultRunnable<T> { public interface ResultRunnable<T> {
T run(); T run();

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.events; package me.topchetoeu.jscript.common.events;
public interface Awaitable<T> { public interface Awaitable<T> {
public static interface ResultHandler<T> { public static interface ResultHandler<T> {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.events; package me.topchetoeu.jscript.common.events;
public class DataNotifier<T> implements Awaitable<T> { public class DataNotifier<T> implements Awaitable<T> {
private Notifier notifier = new Notifier(); private Notifier notifier = new Notifier();

View File

@ -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 { public class Notifier {
private boolean ok = false; private boolean ok = false;

View File

@ -1,20 +1,20 @@
package me.topchetoeu.jscript.json; package me.topchetoeu.jscript.common.json;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
import me.topchetoeu.jscript.parsing.Operator; import me.topchetoeu.jscript.core.parsing.Operator;
import me.topchetoeu.jscript.parsing.ParseRes; import me.topchetoeu.jscript.core.parsing.ParseRes;
import me.topchetoeu.jscript.parsing.Parsing; import me.topchetoeu.jscript.core.parsing.Parsing;
import me.topchetoeu.jscript.parsing.Token; import me.topchetoeu.jscript.core.parsing.Token;
public class JSON { public class JSON {
public static Object toJs(JSONElement val) { public static Object toJs(JSONElement val) {
@ -58,8 +58,8 @@ public class JSON {
var res = new JSONMap(); var res = new JSONMap();
for (var el : ((ObjectValue)val).keys(false)) { for (var el : Values.getMembers(ctx, val, false, false)) {
var jsonEl = fromJs(ctx, ((ObjectValue)val).getMember(ctx, el), prev); var jsonEl = fromJs(ctx, Values.getMember(ctx, val, el), prev);
if (jsonEl == null) continue; if (jsonEl == null) continue;
if (el instanceof String || el instanceof Number) res.put(el.toString(), jsonEl); if (el instanceof String || el instanceof Number) res.put(el.toString(), jsonEl);
} }

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json; package me.topchetoeu.jscript.common.json;
public class JSONElement { public class JSONElement {
public static enum Type { public static enum Type {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json; package me.topchetoeu.jscript.common.json;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.json; package me.topchetoeu.jscript.common.json;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
public abstract class AssignableStatement extends Statement { public abstract class AssignableStatement extends Statement {
public abstract Statement toAssign(Statement val, Operation operation); public abstract Statement toAssign(Statement val, Operation operation);

View File

@ -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 class CalculateResult {
public final boolean exists; public final boolean exists;

View File

@ -1,14 +1,14 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Vector; import java.util.Vector;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.values.CodeFunction; import me.topchetoeu.jscript.core.engine.values.CodeFunction;
public class CompileTarget { public class CompileTarget {
public final Vector<Instruction> target = new Vector<>(); public final Vector<Instruction> target = new Vector<>();

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.values.FunctionStatement; import me.topchetoeu.jscript.core.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class CompoundStatement extends Statement { public class CompoundStatement extends Statement {
public final Statement[] statements; public final Statement[] statements;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
public class FunctionBody { public class FunctionBody {
public final Instruction[] instructions; public final Instruction[] instructions;

View File

@ -1,8 +1,8 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
public class Instruction { public class Instruction {
public static enum Type { public static enum Type {

View File

@ -1,8 +1,8 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public abstract class Statement { public abstract class Statement {
private Location _loc; private Location _loc;

View File

@ -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.core.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
public class ThrowSyntaxStatement extends Statement { public class ThrowSyntaxStatement extends Statement {
public final String name; public final String name;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation; package me.topchetoeu.jscript.core.compilation;
import java.util.List; import java.util.List;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.values.FunctionStatement; import me.topchetoeu.jscript.core.compilation.values.FunctionStatement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class VariableDeclareStatement extends Statement { public class VariableDeclareStatement extends Statement {
public static class Pair { public static class Pair {

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class BreakStatement extends Statement { public class BreakStatement extends Statement {
public final String label; public final String label;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ContinueStatement extends Statement { public class ContinueStatement extends Statement {
public final String label; public final String label;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class DebugStatement extends Statement { public class DebugStatement extends Statement {
@Override @Override

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class DeleteStatement extends Statement { public class DeleteStatement extends Statement {
public final Statement key; public final Statement key;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class DoWhileStatement extends Statement { public class DoWhileStatement extends Statement {
public final Statement condition, body; public final Statement condition, body;

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation.control; package me.topchetoeu.jscript.core.compilation.control;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ForInStatement extends Statement { public class ForInStatement extends Statement {
public final String varName; public final String varName;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ForStatement extends Statement { public class ForStatement extends Statement {
public final Statement declaration, assignment, condition, body; public final Statement declaration, assignment, condition, body;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class IfStatement extends Statement { public class IfStatement extends Statement {
public final Statement condition, body, elseBody; public final Statement condition, body, elseBody;

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ReturnStatement extends Statement { public class ReturnStatement extends Statement {
public final Statement value; public final Statement value;

View File

@ -1,15 +1,15 @@
package me.topchetoeu.jscript.compilation.control; package me.topchetoeu.jscript.core.compilation.control;
import java.util.HashMap; import java.util.HashMap;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.Instruction.Type; import me.topchetoeu.jscript.core.compilation.Instruction.Type;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class SwitchStatement extends Statement { public class SwitchStatement extends Statement {
public static class SwitchCase { public static class SwitchCase {

View File

@ -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.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ThrowStatement extends Statement { public class ThrowStatement extends Statement {
public final Statement value; public final Statement value;

View File

@ -1,13 +1,13 @@
package me.topchetoeu.jscript.compilation.control; package me.topchetoeu.jscript.core.compilation.control;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.GlobalScope; import me.topchetoeu.jscript.core.engine.scope.GlobalScope;
import me.topchetoeu.jscript.engine.scope.LocalScopeRecord; import me.topchetoeu.jscript.core.engine.scope.LocalScopeRecord;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class TryStatement extends Statement { public class TryStatement extends Statement {
public final Statement tryBody; public final Statement tryBody;

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation.control; package me.topchetoeu.jscript.core.compilation.control;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.Instruction.Type; import me.topchetoeu.jscript.core.compilation.Instruction.Type;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class WhileStatement extends Statement { public class WhileStatement extends Statement {
public final Statement condition, body; public final Statement condition, body;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ArrayStatement extends Statement { public class ArrayStatement extends Statement {
public final Statement[] statements; public final Statement[] statements;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class CallStatement extends Statement { public class CallStatement extends Statement {
public final Statement func; public final Statement func;

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.AssignableStatement; import me.topchetoeu.jscript.core.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ChangeStatement extends Statement { public class ChangeStatement extends Statement {
public final AssignableStatement value; public final AssignableStatement value;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ConstantStatement extends Statement { public class ConstantStatement extends Statement {
public final Object value; public final Object value;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class DiscardStatement extends Statement { public class DiscardStatement extends Statement {
public final Statement value; public final Statement value;

View File

@ -1,17 +1,17 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import java.util.Random; import java.util.Random;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.CompoundStatement; import me.topchetoeu.jscript.core.compilation.CompoundStatement;
import me.topchetoeu.jscript.compilation.FunctionBody; import me.topchetoeu.jscript.core.compilation.FunctionBody;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.compilation.Instruction.Type; import me.topchetoeu.jscript.core.compilation.Instruction.Type;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
public class FunctionStatement extends Statement { public class FunctionStatement extends Statement {
public final CompoundStatement body; public final CompoundStatement body;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class GlobalThisStatement extends Statement { public class GlobalThisStatement extends Statement {
@Override public boolean pure() { return true; } @Override public boolean pure() { return true; }

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class IndexAssignStatement extends Statement { public class IndexAssignStatement extends Statement {
public final Statement object; public final Statement object;

View File

@ -1,13 +1,13 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.AssignableStatement; import me.topchetoeu.jscript.core.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.compilation.Instruction.BreakpointType; import me.topchetoeu.jscript.core.compilation.Instruction.BreakpointType;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class IndexStatement extends AssignableStatement { public class IndexStatement extends AssignableStatement {
public final Statement object; public final Statement object;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
public class LazyAndStatement extends Statement { public class LazyAndStatement extends Statement {
public final Statement first, second; public final Statement first, second;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
public class LazyOrStatement extends Statement { public class LazyOrStatement extends Statement {
public final Statement first, second; public final Statement first, second;

View File

@ -1,13 +1,13 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class ObjectStatement extends Statement { public class ObjectStatement extends Statement {
public final Map<Object, Statement> map; public final Map<Object, Statement> map;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class OperationStatement extends Statement { public class OperationStatement extends Statement {
public final Statement[] args; public final Statement[] args;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class RegexStatement extends Statement { public class RegexStatement extends Statement {
public final String pattern, flags; public final String pattern, flags;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class TypeofStatement extends Statement { public class TypeofStatement extends Statement {
public final Statement value; public final Statement value;

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class VariableAssignStatement extends Statement { public class VariableAssignStatement extends Statement {
public final String name; public final String name;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class VariableIndexStatement extends Statement { public class VariableIndexStatement extends Statement {
public final int index; public final int index;

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.compilation.values; package me.topchetoeu.jscript.core.compilation.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.AssignableStatement; import me.topchetoeu.jscript.core.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileTarget; import me.topchetoeu.jscript.core.compilation.CompileTarget;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.compilation.Statement; import me.topchetoeu.jscript.core.compilation.Statement;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ScopeRecord; import me.topchetoeu.jscript.core.engine.scope.ScopeRecord;
public class VariableStatement extends AssignableStatement { public class VariableStatement extends AssignableStatement {
public final String name; public final String name;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -9,19 +9,21 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.engine.debug.DebugContext; import me.topchetoeu.jscript.core.engine.debug.DebugContext;
import me.topchetoeu.jscript.engine.frame.CodeFrame; import me.topchetoeu.jscript.core.engine.frame.CodeFrame;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.Symbol;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.lib.EnvironmentLib; import me.topchetoeu.jscript.lib.EnvironmentLib;
import me.topchetoeu.jscript.mapping.SourceMap; import me.topchetoeu.jscript.utils.mapping.SourceMap;
public class Context implements Extensions { public class Context implements Extensions {
public static final Context NULL = new Context(null);
public final Context parent; public final Context parent;
public final Environment environment; public final Environment environment;
public final CodeFrame frame; public final CodeFrame frame;

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
import java.util.HashMap; import java.util.HashMap;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.compilation.FunctionBody; import me.topchetoeu.jscript.common.events.Awaitable;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.compilation.FunctionBody;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.events.Awaitable; import me.topchetoeu.jscript.core.engine.values.Symbol;
public class Engine extends EventLoop implements Extensions { public class Engine extends EventLoop implements Extensions {
public static final HashMap<Long, FunctionBody> functions = new HashMap<>(); public static final HashMap<Long, FunctionBody> functions = new HashMap<>();

View File

@ -1,21 +1,21 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
import java.util.HashMap; import java.util.HashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.engine.debug.DebugContext; import me.topchetoeu.jscript.core.engine.debug.DebugContext;
import me.topchetoeu.jscript.engine.scope.GlobalScope; import me.topchetoeu.jscript.core.engine.scope.GlobalScope;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.engine.values.NativeFunction; import me.topchetoeu.jscript.core.engine.values.NativeFunction;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.Symbol;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.interop.NativeWrapperProvider; import me.topchetoeu.jscript.core.parsing.Parsing;
import me.topchetoeu.jscript.parsing.Parsing; import me.topchetoeu.jscript.utils.interop.NativeWrapperProvider;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class Environment implements Extensions { public class Environment implements Extensions {
@ -45,7 +45,7 @@ public class Environment implements Extensions {
private HashMap<Symbol, Object> data = new HashMap<>(); private HashMap<Symbol, Object> data = new HashMap<>();
public GlobalScope global; public GlobalScope global;
public WrappersProvider wrappers; public WrapperProvider wrappers;
@Override public <T> void add(Symbol key, T obj) { @Override public <T> void add(Symbol key, T obj) {
data.put(key, obj); data.put(key, obj);
@ -71,7 +71,7 @@ public class Environment implements Extensions {
return ext.init(COMPILE_FUNC, new NativeFunction("compile", args -> { return ext.init(COMPILE_FUNC, new NativeFunction("compile", args -> {
var source = args.getString(0); var source = args.getString(0);
var filename = args.getString(1); var filename = args.getString(1);
var env = Values.wrapper(args.convert(2, ObjectValue.class).getMember(args.ctx, Symbol.get("env")), Environment.class); var env = Values.wrapper(Values.getMember(args.ctx, args.get(2), Symbol.get("env")), Environment.class);
var isDebug = DebugContext.enabled(args.ctx); var isDebug = DebugContext.enabled(args.ctx);
var res = new ObjectValue(); var res = new ObjectValue();
@ -115,7 +115,7 @@ public class Environment implements Extensions {
return new Context(engine, this); return new Context(engine, this);
} }
public Environment(WrappersProvider nativeConverter, GlobalScope global) { public Environment(WrapperProvider nativeConverter, GlobalScope global) {
if (nativeConverter == null) nativeConverter = new NativeWrapperProvider(this); if (nativeConverter == null) nativeConverter = new NativeWrapperProvider(this);
if (global == null) global = new GlobalScope(); if (global == null) global = new GlobalScope();

View File

@ -1,11 +1,11 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.PriorityBlockingQueue;
import me.topchetoeu.jscript.ResultRunnable; import me.topchetoeu.jscript.common.ResultRunnable;
import me.topchetoeu.jscript.events.Awaitable; import me.topchetoeu.jscript.common.events.Awaitable;
import me.topchetoeu.jscript.events.DataNotifier; import me.topchetoeu.jscript.common.events.DataNotifier;
import me.topchetoeu.jscript.exceptions.InterruptException; import me.topchetoeu.jscript.core.exceptions.InterruptException;
public class EventLoop { public class EventLoop {
private static class Task implements Comparable<Task> { private static class Task implements Comparable<Task> {

View File

@ -1,6 +1,6 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.Symbol;
public interface Extensions { public interface Extensions {
<T> T get(Symbol key); <T> T get(Symbol key);

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine; package me.topchetoeu.jscript.core.engine;
public enum Operation { public enum Operation {
INSTANCEOF(2, false), INSTANCEOF(2, false),

View File

@ -0,0 +1,12 @@
package me.topchetoeu.jscript.core.engine;
import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.core.engine.values.ObjectValue;
public interface WrapperProvider {
public ObjectValue getProto(Class<?> obj);
public ObjectValue getNamespace(Class<?> obj);
public FunctionValue getConstr(Class<?> obj);
public WrapperProvider fork(Environment env);
}

View File

@ -1,17 +1,17 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeSet; import java.util.TreeSet;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Extensions; import me.topchetoeu.jscript.core.engine.Extensions;
import me.topchetoeu.jscript.engine.frame.CodeFrame; import me.topchetoeu.jscript.core.engine.frame.CodeFrame;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.Symbol;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.mapping.SourceMap; import me.topchetoeu.jscript.utils.mapping.SourceMap;
public class DebugContext implements DebugController { public class DebugContext implements DebugController {
public static final Symbol ENV_KEY = Symbol.get("Engine.debug"); public static final Symbol ENV_KEY = Symbol.get("Engine.debug");

View File

@ -1,14 +1,14 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.util.TreeSet; import java.util.TreeSet;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.frame.CodeFrame; import me.topchetoeu.jscript.core.engine.frame.CodeFrame;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.mapping.SourceMap; import me.topchetoeu.jscript.utils.mapping.SourceMap;
public interface DebugController { public interface DebugController {
/** /**

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
@ -9,14 +9,14 @@ import java.security.MessageDigest;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import me.topchetoeu.jscript.Metadata; import me.topchetoeu.jscript.common.Metadata;
import me.topchetoeu.jscript.Reading; import me.topchetoeu.jscript.common.Reading;
import me.topchetoeu.jscript.engine.debug.WebSocketMessage.Type; import me.topchetoeu.jscript.common.events.Notifier;
import me.topchetoeu.jscript.events.Notifier; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.common.json.JSONList;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.common.json.JSONMap;
import me.topchetoeu.jscript.json.JSONList; import me.topchetoeu.jscript.core.engine.debug.WebSocketMessage.Type;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
public class DebugServer { public class DebugServer {
public static String browserDisplayName = Metadata.name() + "/" + Metadata.version(); public static String browserDisplayName = Metadata.name() + "/" + Metadata.version();
@ -226,9 +226,9 @@ public class DebugServer {
public DebugServer() { public DebugServer() {
try { try {
this.favicon = Reading.resourceToStream("assets/debugger/favicon.png").readAllBytes(); this.favicon = Reading.resourceToStream("me/topchetoeu/jscript/utils/assets/debugger/favicon.png").readAllBytes();
this.protocol = Reading.resourceToStream("assets/debugger/protocol.json").readAllBytes(); this.protocol = Reading.resourceToStream("me/topchetoeu/jscript/utils/assets/debugger/protocol.json").readAllBytes();
this.index = Reading.resourceToString("assets/debugger/index.html") this.index = Reading.resourceToString("me/topchetoeu/jscript/utils/assets/debugger/index.html")
.replace("${NAME}", Metadata.name()) .replace("${NAME}", Metadata.name())
.replace("${VERSION}", Metadata.version()) .replace("${VERSION}", Metadata.version())
.replace("${AUTHOR}", Metadata.author()) .replace("${AUTHOR}", Metadata.author())

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
public interface Debugger extends DebugHandler, DebugController { public interface Debugger extends DebugHandler, DebugController {
void close(); void close();

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
public interface DebuggerProvider { public interface DebuggerProvider {
Debugger getDebugger(WebSocket socket, HttpRequest req); Debugger getDebugger(WebSocket socket, HttpRequest req);

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,29 +10,29 @@ import java.util.TreeSet;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.topchetoeu.jscript.Filename; import me.topchetoeu.jscript.common.Filename;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.common.events.Notifier;
import me.topchetoeu.jscript.compilation.Instruction.Type; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.common.json.JSONElement;
import me.topchetoeu.jscript.engine.Engine; import me.topchetoeu.jscript.common.json.JSONList;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.common.json.JSONMap;
import me.topchetoeu.jscript.engine.frame.CodeFrame; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.scope.GlobalScope; import me.topchetoeu.jscript.core.compilation.Instruction.Type;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.values.CodeFunction; import me.topchetoeu.jscript.core.engine.Engine;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.frame.CodeFrame;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.scope.GlobalScope;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.events.Notifier; import me.topchetoeu.jscript.core.engine.values.CodeFunction;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.json.JSONElement; import me.topchetoeu.jscript.core.engine.values.Symbol;
import me.topchetoeu.jscript.json.JSONList; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.mapping.SourceMap; import me.topchetoeu.jscript.core.parsing.Parsing;
import me.topchetoeu.jscript.parsing.Parsing; import me.topchetoeu.jscript.utils.mapping.SourceMap;
// very simple indeed // very simple indeed
public class SimpleDebugger implements Debugger { public class SimpleDebugger implements Debugger {
@ -124,8 +124,7 @@ public class SimpleDebugger implements Debugger {
this.global = frame.function.environment.global.obj; this.global = frame.function.environment.global.obj;
this.local = frame.getLocalScope(true); this.local = frame.getLocalScope(true);
this.capture = frame.getCaptureScope(true); this.capture = frame.getCaptureScope(true);
this.local.setPrototype(frame.ctx, capture); Values.makePrototypeChain(frame.ctx, global, capture, local);
this.capture.setPrototype(frame.ctx, global);
this.valstack = frame.getValStackScope(); this.valstack = frame.getValStackScope();
this.serialized = new JSONMap() this.serialized = new JSONMap()
@ -841,7 +840,7 @@ public class SimpleDebugger implements Debugger {
} }
else { else {
propDesc.set("name", Values.toString(ctx, key)); propDesc.set("name", Values.toString(ctx, key));
propDesc.set("value", serializeObj(ctx, obj.getMember(ctx, key))); propDesc.set("value", serializeObj(ctx, Values.getMember(ctx, obj, key)));
propDesc.set("writable", obj.memberWritable(key)); propDesc.set("writable", obj.memberWritable(key));
propDesc.set("enumerable", obj.memberEnumerable(key)); propDesc.set("enumerable", obj.memberEnumerable(key));
propDesc.set("configurable", obj.memberConfigurable(key)); propDesc.set("configurable", obj.memberConfigurable(key));
@ -850,7 +849,7 @@ public class SimpleDebugger implements Debugger {
} }
} }
var proto = obj.getPrototype(ctx); var proto = Values.getPrototype(ctx, obj);
var protoDesc = new JSONMap(); var protoDesc = new JSONMap();
protoDesc.set("name", "__proto__"); protoDesc.set("name", "__proto__");

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.common.json.JSONMap;
public class V8Error { public class V8Error {
public final String message; public final String message;

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.common.json.JSONMap;
public class V8Event { public class V8Event {
public final String name; public final String name;

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.json.JSONElement; import me.topchetoeu.jscript.common.json.JSONElement;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.common.json.JSONMap;
public class V8Message { public class V8Message {
public final String name; public final String name;

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import me.topchetoeu.jscript.json.JSON; import me.topchetoeu.jscript.common.json.JSON;
import me.topchetoeu.jscript.json.JSONMap; import me.topchetoeu.jscript.common.json.JSONMap;
public class V8Result { public class V8Result {
public final int id; public final int id;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -6,7 +6,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import me.topchetoeu.jscript.engine.debug.WebSocketMessage.Type; import me.topchetoeu.jscript.core.engine.debug.WebSocketMessage.Type;
public class WebSocket implements AutoCloseable { public class WebSocket implements AutoCloseable {
public long maxLength = 1 << 20; public long maxLength = 1 << 20;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.debug; package me.topchetoeu.jscript.core.engine.debug;
public class WebSocketMessage { public class WebSocketMessage {
public static enum Type { public static enum Type {

View File

@ -1,21 +1,21 @@
package me.topchetoeu.jscript.engine.frame; package me.topchetoeu.jscript.core.engine.frame;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.debug.DebugContext; import me.topchetoeu.jscript.core.engine.debug.DebugContext;
import me.topchetoeu.jscript.engine.scope.LocalScope; import me.topchetoeu.jscript.core.engine.scope.LocalScope;
import me.topchetoeu.jscript.engine.scope.ValueVariable; import me.topchetoeu.jscript.core.engine.scope.ValueVariable;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.CodeFunction; import me.topchetoeu.jscript.core.engine.values.CodeFunction;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.ScopeValue; import me.topchetoeu.jscript.core.engine.values.ScopeValue;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.exceptions.InterruptException; import me.topchetoeu.jscript.core.exceptions.InterruptException;
public class CodeFrame { public class CodeFrame {
public static enum TryState { public static enum TryState {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.frame; package me.topchetoeu.jscript.core.engine.frame;
public enum ConvertHint { public enum ConvertHint {
TOSTRING, TOSTRING,

View File

@ -1,20 +1,20 @@
package me.topchetoeu.jscript.engine.frame; package me.topchetoeu.jscript.core.engine.frame;
import java.util.Collections; import java.util.Collections;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Engine; import me.topchetoeu.jscript.core.engine.Engine;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.scope.ValueVariable; import me.topchetoeu.jscript.core.engine.scope.ValueVariable;
import me.topchetoeu.jscript.engine.values.ArrayValue; import me.topchetoeu.jscript.core.engine.values.ArrayValue;
import me.topchetoeu.jscript.engine.values.CodeFunction; import me.topchetoeu.jscript.core.engine.values.CodeFunction;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.Symbol; import me.topchetoeu.jscript.core.engine.values.Symbol;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
public class Runners { public class Runners {
public static Object execReturn(Context ctx, Instruction instr, CodeFrame frame) { public static Object execReturn(Context ctx, Instruction instr, CodeFrame frame) {

View File

@ -1,19 +1,20 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.values.FunctionValue; import me.topchetoeu.jscript.core.engine.values.FunctionValue;
import me.topchetoeu.jscript.engine.values.NativeFunction; import me.topchetoeu.jscript.core.engine.values.NativeFunction;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.core.exceptions.EngineException;
public class GlobalScope implements ScopeRecord { public class GlobalScope implements ScopeRecord {
public final ObjectValue obj; public final ObjectValue obj;
public boolean has(Context ctx, String name) { public boolean has(Context ctx, String name) {
return obj.hasMember(ctx, name, false); return Values.hasMember(null, obj, name, false);
} }
public Object getKey(String name) { public Object getKey(String name) {
return name; return name;
@ -21,7 +22,7 @@ public class GlobalScope implements ScopeRecord {
public GlobalScope globalChild() { public GlobalScope globalChild() {
var obj = new ObjectValue(); var obj = new ObjectValue();
obj.setPrototype(null, this.obj); Values.setPrototype(null, obj, this.obj);
return new GlobalScope(obj); return new GlobalScope(obj);
} }
public LocalScopeRecord child() { public LocalScopeRecord child() {
@ -29,12 +30,12 @@ public class GlobalScope implements ScopeRecord {
} }
public Object define(String name) { public Object define(String name) {
if (obj.hasMember(null, name, true)) return name; if (Values.hasMember(Context.NULL, obj, name, false)) return name;
obj.defineProperty(null, name, null); obj.defineProperty(Context.NULL, name, null);
return name; return name;
} }
public void define(String name, Variable val) { public void define(String name, Variable val) {
obj.defineProperty(null, name, obj.defineProperty(Context.NULL, name,
new NativeFunction("get " + name, args -> val.get(args.ctx)), new NativeFunction("get " + name, args -> val.get(args.ctx)),
new NativeFunction("set " + name, args -> { val.set(args.ctx, args.get(0)); return null; }), new NativeFunction("set " + name, args -> { val.set(args.ctx, args.get(0)); return null; }),
true, true true, true
@ -51,12 +52,12 @@ public class GlobalScope implements ScopeRecord {
} }
public Object get(Context ctx, String name) { public Object get(Context ctx, String name) {
if (!obj.hasMember(ctx, name, false)) throw EngineException.ofSyntax("The variable '" + name + "' doesn't exist."); if (!Values.hasMember(ctx, obj, name, false)) throw EngineException.ofSyntax("The variable '" + name + "' doesn't exist.");
else return obj.getMember(ctx, name); else return Values.getMember(ctx, obj, name);
} }
public void set(Context ctx, String name, Object val) { public void set(Context ctx, String name, Object val) {
if (!obj.hasMember(ctx, name, false)) throw EngineException.ofSyntax("The variable '" + name + "' doesn't exist."); if (!Values.hasMember(ctx, obj, name, false)) throw EngineException.ofSyntax("The variable '" + name + "' doesn't exist.");
if (!obj.setMember(ctx, name, val, false)) throw EngineException.ofSyntax("The global '" + name + "' is readonly."); if (!Values.setMember(ctx, obj, name, val)) throw EngineException.ofSyntax("The global '" + name + "' is readonly.");
} }
public Set<String> keys() { public Set<String> keys() {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
public interface ScopeRecord { public interface ScopeRecord {
public Object getKey(String name); public Object getKey(String name);

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
public class ValueVariable implements Variable { public class ValueVariable implements Variable {
public boolean readonly; public boolean readonly;

View File

@ -1,6 +1,6 @@
package me.topchetoeu.jscript.engine.scope; package me.topchetoeu.jscript.core.engine.scope;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
public interface Variable { public interface Variable {
Object get(Context ctx); Object get(Context ctx);

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -6,7 +6,7 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
// TODO: Make methods generic // TODO: Make methods generic
public class ArrayValue extends ObjectValue implements Iterable<Object> { public class ArrayValue extends ObjectValue implements Iterable<Object> {

View File

@ -1,12 +1,12 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.compilation.FunctionBody; import me.topchetoeu.jscript.core.compilation.FunctionBody;
import me.topchetoeu.jscript.compilation.Instruction; import me.topchetoeu.jscript.core.compilation.Instruction;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.frame.CodeFrame; import me.topchetoeu.jscript.core.engine.frame.CodeFrame;
import me.topchetoeu.jscript.engine.scope.ValueVariable; import me.topchetoeu.jscript.core.engine.scope.ValueVariable;
public class CodeFunction extends FunctionValue { public class CodeFunction extends FunctionValue {
public final int localsN; public final int localsN;

View File

@ -1,8 +1,8 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.util.List; import java.util.List;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
public abstract class FunctionValue extends ObjectValue { public abstract class FunctionValue extends ObjectValue {
public String name = ""; public String name = "";

View File

@ -1,7 +1,7 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.interop.Arguments; import me.topchetoeu.jscript.utils.interop.Arguments;
public class NativeFunction extends FunctionValue { public class NativeFunction extends FunctionValue {
public static interface NativeFunctionRunner { public static interface NativeFunctionRunner {

View File

@ -1,6 +1,6 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
public class NativeWrapper extends ObjectValue { public class NativeWrapper extends ObjectValue {
private static final Object NATIVE_PROTO = new Object(); private static final Object NATIVE_PROTO = new Object();

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -6,8 +6,8 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
public class ObjectValue { public class ObjectValue {
public static enum PlaceholderProto { public static enum PlaceholderProto {
@ -54,6 +54,13 @@ public class ObjectValue {
public LinkedHashSet<Object> nonConfigurableSet = new LinkedHashSet<>(); public LinkedHashSet<Object> nonConfigurableSet = new LinkedHashSet<>();
public LinkedHashSet<Object> nonEnumerableSet = new LinkedHashSet<>(); public LinkedHashSet<Object> nonEnumerableSet = new LinkedHashSet<>();
private Property getProperty(Context ctx, Object key) {
if (properties.containsKey(key)) return properties.get(key);
var proto = getPrototype(ctx);
if (proto != null) return proto.getProperty(ctx, key);
else return null;
}
public final boolean memberWritable(Object key) { public final boolean memberWritable(Object key) {
if (state == State.FROZEN) return false; if (state == State.FROZEN) return false;
return !values.containsKey(key) || !nonWritableSet.contains(key); return !values.containsKey(key) || !nonWritableSet.contains(key);
@ -159,6 +166,113 @@ public class ObjectValue {
return (ObjectValue)prototype; return (ObjectValue)prototype;
} }
public final boolean setPrototype(PlaceholderProto val) {
if (!extensible()) return false;
switch (val) {
case OBJECT: prototype = OBJ_PROTO; break;
case FUNCTION: prototype = FUNC_PROTO; break;
case ARRAY: prototype = ARR_PROTO; break;
case ERROR: prototype = ERR_PROTO; break;
case SYNTAX_ERROR: prototype = SYNTAX_ERR_PROTO; break;
case TYPE_ERROR: prototype = TYPE_ERR_PROTO; break;
case RANGE_ERROR: prototype = RANGE_ERR_PROTO; break;
case NONE: prototype = null; break;
}
return true;
}
/**
* A method, used to get the value of a field. If a property is bound to
* this key, but not a field, this method should return null.
*/
protected Object getField(Context ctx, Object key) {
if (values.containsKey(key)) return values.get(key);
var proto = getPrototype(ctx);
if (proto != null) return proto.getField(ctx, key);
else return null;
}
/**
* Changes the value of a field, that is bound to the given key. If no field is
* bound to this key, a new field should be created with the given value
* @return Whether or not the operation was successful
*/
protected boolean setField(Context ctx, Object key, Object val) {
if (val instanceof FunctionValue && ((FunctionValue)val).name.equals("")) {
((FunctionValue)val).name = Values.toString(ctx, key);
}
values.put(key, val);
return true;
}
/**
* Deletes the field bound to the given key.
*/
protected void deleteField(Context ctx, Object key) {
values.remove(key);
}
/**
* Returns whether or not there is a field bound to the given key.
* This must ignore properties
*/
protected boolean hasField(Context ctx, Object key) {
return values.containsKey(key);
}
public final Object getMember(Context ctx, Object key, Object thisArg) {
key = Values.normalize(ctx, key);
if ("__proto__".equals(key)) {
var res = getPrototype(ctx);
return res == null ? Values.NULL : res;
}
var prop = getProperty(ctx, key);
if (prop != null) {
if (prop.getter == null) return null;
else return prop.getter.call(ctx, Values.normalize(ctx, thisArg));
}
else return getField(ctx, key);
}
public final boolean setMember(Context ctx, Object key, Object val, Object thisArg, boolean onlyProps) {
key = Values.normalize(ctx, key); val = Values.normalize(ctx, val);
var prop = getProperty(ctx, key);
if (prop != null) {
if (prop.setter == null) return false;
prop.setter.call(ctx, Values.normalize(ctx, thisArg), val);
return true;
}
else if (onlyProps) return false;
else if (!extensible() && !values.containsKey(key)) return false;
else if (key == null) {
values.put(key, val);
return true;
}
else if ("__proto__".equals(key)) return setPrototype(ctx, val);
else if (nonWritableSet.contains(key)) return false;
else return setField(ctx, key, val);
}
public final boolean hasMember(Context ctx, Object key, boolean own) {
key = Values.normalize(ctx, key);
if (key != null && "__proto__".equals(key)) return true;
if (hasField(ctx, key)) return true;
if (properties.containsKey(key)) return true;
if (own) return false;
var proto = getPrototype(ctx);
return proto != null && proto.hasMember(ctx, key, own);
}
public final boolean deleteMember(Context ctx, Object key) {
key = Values.normalize(ctx, key);
if (!memberConfigurable(key)) return false;
properties.remove(key);
nonWritableSet.remove(key);
nonEnumerableSet.remove(key);
deleteField(ctx, key);
return true;
}
public final boolean setPrototype(Context ctx, Object val) { public final boolean setPrototype(Context ctx, Object val) {
val = Values.normalize(ctx, val); val = Values.normalize(ctx, val);
@ -186,111 +300,6 @@ public class ObjectValue {
} }
return false; return false;
} }
public final boolean setPrototype(PlaceholderProto val) {
if (!extensible()) return false;
switch (val) {
case OBJECT: prototype = OBJ_PROTO; break;
case FUNCTION: prototype = FUNC_PROTO; break;
case ARRAY: prototype = ARR_PROTO; break;
case ERROR: prototype = ERR_PROTO; break;
case SYNTAX_ERROR: prototype = SYNTAX_ERR_PROTO; break;
case TYPE_ERROR: prototype = TYPE_ERR_PROTO; break;
case RANGE_ERROR: prototype = RANGE_ERR_PROTO; break;
case NONE: prototype = null; break;
}
return true;
}
protected Property getProperty(Context ctx, Object key) {
if (properties.containsKey(key)) return properties.get(key);
var proto = getPrototype(ctx);
if (proto != null) return proto.getProperty(ctx, key);
else return null;
}
protected Object getField(Context ctx, Object key) {
if (values.containsKey(key)) return values.get(key);
var proto = getPrototype(ctx);
if (proto != null) return proto.getField(ctx, key);
else return null;
}
protected boolean setField(Context ctx, Object key, Object val) {
if (val instanceof FunctionValue && ((FunctionValue)val).name.equals("")) {
((FunctionValue)val).name = Values.toString(ctx, key);
}
values.put(key, val);
return true;
}
protected void deleteField(Context ctx, Object key) {
values.remove(key);
}
protected boolean hasField(Context ctx, Object key) {
return values.containsKey(key);
}
public final Object getMember(Context ctx, Object key, Object thisArg) {
key = Values.normalize(ctx, key);
if ("__proto__".equals(key)) {
var res = getPrototype(ctx);
return res == null ? Values.NULL : res;
}
var prop = getProperty(ctx, key);
if (prop != null) {
if (prop.getter == null) return null;
else return prop.getter.call(ctx, Values.normalize(ctx, thisArg));
}
else return getField(ctx, key);
}
public final Object getMember(Context ctx, Object key) {
return getMember(ctx, key, this);
}
public final boolean setMember(Context ctx, Object key, Object val, Object thisArg, boolean onlyProps) {
key = Values.normalize(ctx, key); val = Values.normalize(ctx, val);
var prop = getProperty(ctx, key);
if (prop != null) {
if (prop.setter == null) return false;
prop.setter.call(ctx, Values.normalize(ctx, thisArg), val);
return true;
}
else if (onlyProps) return false;
else if (!extensible() && !values.containsKey(key)) return false;
else if (key == null) {
values.put(key, val);
return true;
}
else if ("__proto__".equals(key)) return setPrototype(ctx, val);
else if (nonWritableSet.contains(key)) return false;
else return setField(ctx, key, val);
}
public final boolean setMember(Context ctx, Object key, Object val, boolean onlyProps) {
return setMember(ctx, Values.normalize(ctx, key), Values.normalize(ctx, val), this, onlyProps);
}
public final boolean hasMember(Context ctx, Object key, boolean own) {
key = Values.normalize(ctx, key);
if (key != null && "__proto__".equals(key)) return true;
if (hasField(ctx, key)) return true;
if (properties.containsKey(key)) return true;
if (own) return false;
var proto = getPrototype(ctx);
return proto != null && proto.hasMember(ctx, key, own);
}
public final boolean deleteMember(Context ctx, Object key) {
key = Values.normalize(ctx, key);
if (!memberConfigurable(key)) return false;
properties.remove(key);
nonWritableSet.remove(key);
nonEnumerableSet.remove(key);
deleteField(ctx, key);
return true;
}
public final ObjectValue getMemberDescriptor(Context ctx, Object key) { public final ObjectValue getMemberDescriptor(Context ctx, Object key) {
key = Values.normalize(ctx, key); key = Values.normalize(ctx, key);

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.scope.ValueVariable; import me.topchetoeu.jscript.core.engine.scope.ValueVariable;
public class ScopeValue extends ObjectValue { public class ScopeValue extends ObjectValue {
public final ValueVariable[] variables; public final ValueVariable[] variables;
@ -23,7 +23,7 @@ public class ScopeValue extends ObjectValue {
} }
var proto = getPrototype(ctx); var proto = getPrototype(ctx);
if (proto != null && proto.hasField(ctx, key) && proto.setField(ctx, key, val)) return true; if (proto != null && proto.hasMember(ctx, key, false) && proto.setField(ctx, key, val)) return true;
return super.setField(ctx, key, val); return super.setField(ctx, key, val);
} }

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.util.HashMap; import java.util.HashMap;

View File

@ -1,5 +1,7 @@
package me.topchetoeu.jscript.engine.values; package me.topchetoeu.jscript.core.engine.values;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,13 +12,13 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
import me.topchetoeu.jscript.engine.frame.ConvertHint; import me.topchetoeu.jscript.core.engine.frame.ConvertHint;
import me.topchetoeu.jscript.exceptions.ConvertException; import me.topchetoeu.jscript.core.exceptions.ConvertException;
import me.topchetoeu.jscript.exceptions.EngineException; import me.topchetoeu.jscript.core.exceptions.EngineException;
import me.topchetoeu.jscript.exceptions.SyntaxException; import me.topchetoeu.jscript.core.exceptions.SyntaxException;
import me.topchetoeu.jscript.lib.PromiseLib; import me.topchetoeu.jscript.lib.PromiseLib;
public class Values { public class Values {
@ -281,7 +283,7 @@ public class Values {
obj = normalize(ctx, obj); key = normalize(ctx, key); obj = normalize(ctx, obj); key = normalize(ctx, key);
if (obj == null) throw new IllegalArgumentException("Tried to access member of undefined."); if (obj == null) throw new IllegalArgumentException("Tried to access member of undefined.");
if (obj == NULL) throw new IllegalArgumentException("Tried to access member of null."); if (obj == NULL) throw new IllegalArgumentException("Tried to access member of null.");
if (obj instanceof ObjectValue) return object(obj).getMember(ctx, key); if (obj instanceof ObjectValue) return ((ObjectValue)obj).getMember(ctx, key, obj);
if (obj instanceof String && key instanceof Number) { if (obj instanceof String && key instanceof Number) {
var i = number(key); var i = number(key);
@ -307,7 +309,7 @@ public class Values {
if (obj == null) throw EngineException.ofType("Tried to access member of undefined."); if (obj == null) throw EngineException.ofType("Tried to access member of undefined.");
if (obj == NULL) throw EngineException.ofType("Tried to access member of null."); if (obj == NULL) throw EngineException.ofType("Tried to access member of null.");
if (key != null && "__proto__".equals(key)) return setPrototype(ctx, obj, val); if (key != null && "__proto__".equals(key)) return setPrototype(ctx, obj, val);
if (obj instanceof ObjectValue) return object(obj).setMember(ctx, key, val, false); if (obj instanceof ObjectValue) return ((ObjectValue)obj).setMember(ctx, key, val, obj, false);
var proto = getPrototype(ctx, obj); var proto = getPrototype(ctx, obj);
return proto.setMember(ctx, key, val, obj, true); return proto.setMember(ctx, key, val, obj, true);
@ -340,7 +342,7 @@ public class Values {
public static ObjectValue getPrototype(Context ctx, Object obj) { public static ObjectValue getPrototype(Context ctx, Object obj) {
if (obj == null || obj == NULL) return null; if (obj == null || obj == NULL) return null;
obj = normalize(ctx, obj); obj = normalize(ctx, obj);
if (obj instanceof ObjectValue) return object(obj).getPrototype(ctx); if (obj instanceof ObjectValue) return ((ObjectValue)obj).getPrototype(ctx);
if (ctx == null) return null; if (ctx == null) return null;
if (obj instanceof String) return ctx.get(Environment.STRING_PROTO); if (obj instanceof String) return ctx.get(Environment.STRING_PROTO);
@ -352,7 +354,12 @@ public class Values {
} }
public static boolean setPrototype(Context ctx, Object obj, Object proto) { public static boolean setPrototype(Context ctx, Object obj, Object proto) {
obj = normalize(ctx, obj); obj = normalize(ctx, obj);
return obj instanceof ObjectValue && object(obj).setPrototype(ctx, proto); return obj instanceof ObjectValue && ((ObjectValue)obj).setPrototype(ctx, proto);
}
public static void makePrototypeChain(Context ctx, Object... chain) {
for(var i = 1; i < chain.length; i++) {
setPrototype(ctx, chain[i], chain[i - 1]);
}
} }
public static List<Object> getMembers(Context ctx, Object obj, boolean own, boolean includeNonEnumerable) { public static List<Object> getMembers(Context ctx, Object obj, boolean own, boolean includeNonEnumerable) {
List<Object> res = new ArrayList<>(); List<Object> res = new ArrayList<>();
@ -367,7 +374,7 @@ public class Values {
while (proto != null) { while (proto != null) {
res.addAll(proto.keys(includeNonEnumerable)); res.addAll(proto.keys(includeNonEnumerable));
proto = proto.getPrototype(ctx); proto = getPrototype(ctx, proto);
} }
} }
@ -400,7 +407,7 @@ public class Values {
var res = new ObjectValue(); var res = new ObjectValue();
try { try {
var proto = Values.getMember(ctx, func, "prototype"); var proto = Values.getMember(ctx, func, "prototype");
res.setPrototype(ctx, proto); setPrototype(ctx, res, proto);
var ret = call(ctx, func, res, args); var ret = call(ctx, func, res, args);
@ -569,11 +576,11 @@ public class Values {
private void loadNext() { private void loadNext() {
if (next == null) value = null; if (next == null) value = null;
else if (consumed) { else if (consumed) {
var curr = object(next.call(ctx, iterator)); var curr = next.call(ctx, iterator);
if (curr == null) { next = null; value = null; } if (curr == null) { next = null; value = null; }
if (toBoolean(curr.getMember(ctx, "done"))) { next = null; value = null; } if (toBoolean(Values.getMember(ctx, curr, "done"))) { next = null; value = null; }
else { else {
this.value = curr.getMember(ctx, "value"); this.value = Values.getMember(ctx, curr, "value");
consumed = false; consumed = false;
} }
} }
@ -658,104 +665,107 @@ public class Values {
if (protoObj.values.size() + protoObj.properties.size() != 1) return false; if (protoObj.values.size() + protoObj.properties.size() != 1) return false;
return true; return true;
} }
private static void printValue(Context ctx, Object val, HashSet<Object> passed, int tab) { private static String toReadable(Context ctx, Object val, HashSet<Object> passed, int tab) {
if (tab == 0 && val instanceof String) { if (tab == 0 && val instanceof String) return (String)val;
System.out.print(val);
return;
}
if (passed.contains(val)) { if (passed.contains(val)) return "[circular]";
System.out.print("[circular]");
return;
}
var printed = true; var printed = true;
var res = new StringBuilder();
if (val instanceof FunctionValue) { if (val instanceof FunctionValue) {
System.out.print(val.toString()); res.append(val.toString());
var loc = val instanceof CodeFunction ? ((CodeFunction)val).loc() : null; var loc = val instanceof CodeFunction ? ((CodeFunction)val).loc() : null;
if (loc != null) System.out.print(" @ " + loc); if (loc != null) res.append(" @ " + loc);
} }
else if (val instanceof ArrayValue) { else if (val instanceof ArrayValue) {
System.out.print("["); res.append("[");
var obj = ((ArrayValue)val); var obj = ((ArrayValue)val);
for (int i = 0; i < obj.size(); i++) { for (int i = 0; i < obj.size(); i++) {
if (i != 0) System.out.print(", "); if (i != 0) res.append(", ");
else System.out.print(" "); else res.append(" ");
if (obj.has(i)) printValue(ctx, obj.get(i), passed, tab); if (obj.has(i)) res.append(toReadable(ctx, obj.get(i), passed, tab));
else System.out.print("<empty>"); else res.append("<empty>");
} }
System.out.print(" ] "); res.append(" ] ");
} }
else if (val instanceof NativeWrapper) { else if (val instanceof NativeWrapper) {
var obj = ((NativeWrapper)val).wrapped; var obj = ((NativeWrapper)val).wrapped;
System.out.print("Native " + obj.toString() + " "); res.append("Native " + obj.toString() + " ");
} }
else printed = false; else printed = false;
if (val instanceof ObjectValue) { if (val instanceof ObjectValue) {
if (tab > 3) { if (tab > 3) {
System.out.print("{...}"); return "{...}";
return;
} }
passed.add(val); passed.add(val);
var obj = (ObjectValue)val; var obj = (ObjectValue)val;
if (obj.values.size() + obj.properties.size() == 0 || isEmptyFunc(obj)) { if (obj.values.size() + obj.properties.size() == 0 || isEmptyFunc(obj)) {
if (!printed) System.out.println("{}"); if (!printed) res.append("{}\n");
} }
else { else {
System.out.println("{"); res.append("{\n");
for (var el : obj.values.entrySet()) { for (var el : obj.values.entrySet()) {
for (int i = 0; i < tab + 1; i++) System.out.print(" "); for (int i = 0; i < tab + 1; i++) System.out.print(" ");
printValue(ctx, el.getKey(), passed, tab + 1); res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
System.out.print(": "); res.append(": ");
printValue(ctx, el.getValue(), passed, tab + 1); res.append(toReadable(ctx, el.getValue(), passed, tab + 1));
System.out.println(","); res.append(",\n");
} }
for (var el : obj.properties.entrySet()) { for (var el : obj.properties.entrySet()) {
for (int i = 0; i < tab + 1; i++) System.out.print(" "); for (int i = 0; i < tab + 1; i++) System.out.print(" ");
printValue(ctx, el.getKey(), passed, tab + 1); res.append(toReadable(ctx, el.getKey(), passed, tab + 1));
System.out.println(": [prop],"); res.append(": [prop],\n");
} }
for (int i = 0; i < tab; i++) System.out.print(" "); for (int i = 0; i < tab; i++) res.append(" ");
System.out.print("}"); res.append("}");
} }
passed.remove(val); passed.remove(val);
} }
else if (val == null) System.out.print("undefined"); else if (val == null) return "undefined";
else if (val == Values.NULL) System.out.print("null"); else if (val == Values.NULL) return "null";
else if (val instanceof String) System.out.print("'" + val + "'"); else if (val instanceof String) return "'" + val + "'";
else System.out.print(Values.toString(ctx, val)); else return Values.toString(ctx, val);
return res.toString();
} }
public static void printValue(Context ctx, Object val) {
printValue(ctx, val, new HashSet<>(), 0); public static String toReadable(Context ctx, Object val) {
return toReadable(ctx, val, new HashSet<>(), 0);
} }
public static void printError(RuntimeException err, String prefix) { public static String errorToReadable(RuntimeException err, String prefix) {
prefix = prefix == null ? "Uncaught" : "Uncaught " + prefix; prefix = prefix == null ? "Uncaught" : "Uncaught " + prefix;
try {
if (err instanceof EngineException) { if (err instanceof EngineException) {
var ee = ((EngineException)err); var ee = ((EngineException)err);
System.out.println(prefix + " " + ee.toString(new Context(ee.engine, ee.env))); try {
} return prefix + " " + ee.toString(new Context(ee.engine, ee.env));
else if (err instanceof SyntaxException) {
System.out.println("Syntax error:" + ((SyntaxException)err).msg);
}
else if (err.getCause() instanceof InterruptedException) return;
else {
System.out.println("Internal error ocurred:");
err.printStackTrace();
}
} }
catch (EngineException ex) { catch (EngineException ex) {
System.out.println("Uncaught "); return prefix + " " + toReadable(new Context(ee.engine, ee.env), ee.value);
Values.printValue(null, ((EngineException)err).value);
System.out.println();
} }
} }
else if (err instanceof SyntaxException) {
return prefix + " SyntaxError " + ((SyntaxException)err).msg;
}
else if (err.getCause() instanceof InterruptedException) return "";
else {
var str = new ByteArrayOutputStream();
err.printStackTrace(new PrintStream(str));
return prefix + " internal error " + str.toString();
}
}
public static void printValue(Context ctx, Object val) {
System.out.print(toReadable(ctx, val));
}
public static void printError(RuntimeException err, String prefix) {
System.out.println(errorToReadable(err, prefix));
}
} }

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.exceptions; package me.topchetoeu.jscript.core.exceptions;
public class ConvertException extends RuntimeException { public class ConvertException extends RuntimeException {
public final String source, target; public final String source, target;

View File

@ -1,16 +1,16 @@
package me.topchetoeu.jscript.exceptions; package me.topchetoeu.jscript.core.exceptions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.engine.Context; import me.topchetoeu.jscript.core.engine.Context;
import me.topchetoeu.jscript.engine.Engine; import me.topchetoeu.jscript.core.engine.Engine;
import me.topchetoeu.jscript.engine.Environment; import me.topchetoeu.jscript.core.engine.Environment;
import me.topchetoeu.jscript.engine.debug.DebugContext; import me.topchetoeu.jscript.core.engine.debug.DebugContext;
import me.topchetoeu.jscript.engine.values.ObjectValue; import me.topchetoeu.jscript.core.engine.values.ObjectValue;
import me.topchetoeu.jscript.engine.values.Values; import me.topchetoeu.jscript.core.engine.values.Values;
import me.topchetoeu.jscript.engine.values.ObjectValue.PlaceholderProto; import me.topchetoeu.jscript.core.engine.values.ObjectValue.PlaceholderProto;
public class EngineException extends RuntimeException { public class EngineException extends RuntimeException {
public static class StackElement { public static class StackElement {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.jscript.exceptions; package me.topchetoeu.jscript.core.exceptions;
public class InterruptException extends RuntimeException { public class InterruptException extends RuntimeException {
public InterruptException() { } public InterruptException() { }

View File

@ -1,6 +1,6 @@
package me.topchetoeu.jscript.exceptions; package me.topchetoeu.jscript.core.exceptions;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
public class SyntaxException extends RuntimeException { public class SyntaxException extends RuntimeException {
public final Location loc; public final Location loc;

View File

@ -1,9 +1,9 @@
package me.topchetoeu.jscript.parsing; package me.topchetoeu.jscript.core.parsing;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.engine.Operation; import me.topchetoeu.jscript.core.engine.Operation;
public enum Operator { public enum Operator {
MULTIPLY("*", Operation.MULTIPLY, 13), MULTIPLY("*", Operation.MULTIPLY, 13),

View File

@ -1,10 +1,10 @@
package me.topchetoeu.jscript.parsing; package me.topchetoeu.jscript.core.parsing;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import me.topchetoeu.jscript.Location; import me.topchetoeu.jscript.common.Location;
import me.topchetoeu.jscript.parsing.Parsing.Parser; import me.topchetoeu.jscript.core.parsing.Parsing.Parser;
public class ParseRes<T> { public class ParseRes<T> {
public static enum State { public static enum State {

Some files were not shown because too many files have changed in this diff Show More