Skip to content

Commit

Permalink
support more opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ewfian committed Apr 15, 2023
1 parent 7b3ea12 commit 8fa9362
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pickle
from pathlib import Path

ps = list(Path("..").glob("*.js"))

filehandler = open(b"path.pkl", "wb")
pickle.dump({"source": ps}, filehandler)
24 changes: 24 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,24 @@ export class Parser {
}

// Classes
case OP.INST: {
const module = reader.line();
const name = reader.line();
const args = stack;
stack = metastack.pop();
const cls = this.resolveClass(module, name);
const obj = this.newObject(cls, ...args);
stack.push(obj);
break;
}
case OP.OBJ: {
const args = stack;
const cls = args.pop();
stack = metastack.pop();
const obj = this.newObject(cls, ...args);
stack.push(obj);
break;
}
case OP.NEWOBJ: {
const args = stack.pop();
const cls = stack.pop();
Expand All @@ -310,6 +328,12 @@ export class Parser {
case OP.BINPERSID:
stack.push(this.persistent_load(stack.pop()));
break;
case OP.REDUCE: {
const args = stack.pop();
const func = stack.pop();
stack.push(this.newObject(func, ...args));
break;
}
case OP.BUILD: {
const state = stack.pop();
const obj = stack[stack.length - 1];
Expand Down

0 comments on commit 8fa9362

Please sign in to comment.