feat: implement access to intrinsics
This commit is contained in:
parent
2b6d4a87ca
commit
163dfe7b6e
@ -36,7 +36,8 @@ public class Instruction {
|
||||
LOAD_ARR(0x31),
|
||||
LOAD_OBJ(0x32),
|
||||
LOAD_GLOB(0x33),
|
||||
LOAD_REGEX(0x34),
|
||||
LOAD_INTRINSICS(0x34),
|
||||
LOAD_REGEX(0x35),
|
||||
|
||||
LOAD_VAR(0x40),
|
||||
LOAD_MEMBER(0x41),
|
||||
@ -334,6 +335,9 @@ public class Instruction {
|
||||
public static Instruction loadGlob() {
|
||||
return new Instruction(Type.LOAD_GLOB);
|
||||
}
|
||||
public static Instruction loadIntrinsics(String key) {
|
||||
return new Instruction(Type.LOAD_INTRINSICS, key);
|
||||
}
|
||||
public static Instruction loadMember() {
|
||||
return new Instruction(Type.LOAD_MEMBER);
|
||||
}
|
||||
|
@ -157,6 +157,11 @@ public class InstructionRunner {
|
||||
frame.codePtr++;
|
||||
return null;
|
||||
}
|
||||
private static Value execLoadIntrinsics(Environment env, Instruction instr, Frame frame) {
|
||||
frame.push(Value.intrinsics(env).get((String)instr.get(0)));
|
||||
frame.codePtr++;
|
||||
return null;
|
||||
}
|
||||
private static Value execLoadArr(Environment env, Instruction instr, Frame frame) {
|
||||
var res = new ArrayValue();
|
||||
res.setSize(instr.get(0));
|
||||
@ -382,6 +387,7 @@ public class InstructionRunner {
|
||||
case LOAD_MEMBER: return execLoadMember(env, instr, frame);
|
||||
case LOAD_REGEX: return execLoadRegEx(env, instr, frame);
|
||||
case LOAD_GLOB: return execLoadGlob(env, instr, frame);
|
||||
case LOAD_INTRINSICS: return execLoadIntrinsics(env, instr, frame);
|
||||
case LOAD_ARGS: return execLoadArgs(env, instr, frame);
|
||||
case LOAD_THIS: return execLoadThis(env, instr, frame);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -65,6 +66,7 @@ public abstract class Value {
|
||||
public static final Key<ObjectValue> TYPE_ERR_PROTO = Key.of();
|
||||
public static final Key<ObjectValue> RANGE_ERR_PROTO = Key.of();
|
||||
public static final Key<ObjectValue> GLOBAL = Key.of();
|
||||
public static final Key<Map<String, Value>> INTRINSICS = Key.of();
|
||||
|
||||
public static final VoidValue UNDEFINED = new VoidValue("undefined", new StringValue("undefined"));
|
||||
public static final VoidValue NULL = new VoidValue("null", new StringValue("object"));
|
||||
@ -680,4 +682,7 @@ public abstract class Value {
|
||||
public static final ObjectValue global(Environment env) {
|
||||
return env.initFrom(GLOBAL, () -> new ObjectValue());
|
||||
}
|
||||
public static final Map<String, Value> intrinsics(Environment env) {
|
||||
return env.initFrom(INTRINSICS, () -> new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user