Skip to content

Commit

Permalink
Rename actual state and graph to $
Browse files Browse the repository at this point in the history
  • Loading branch information
canmingir committed Jan 12, 2024
1 parent 7a077c3 commit c5358a5
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Scope.js
@@ -1,5 +1,5 @@
// eslint-disable-next-line no-unused-vars
const state = require("./state").state;
const state = require("./state").$;
const { append } = require("./lang/estree/estree");
const Identifier = require("./lang/ast/Identifier");

Expand Down
14 changes: 7 additions & 7 deletions src/graph.js
@@ -1,26 +1,26 @@
// TODO Rename this to `$`
const graph = {
const $ = {
classes: {
name: "classes",
},
};

function retrieve(identifier) {
if (typeof identifier === "string") {
return graph[identifier];
return $[identifier];
} else {
return graph[identifier.generate()];
return $[identifier.generate()];
}
}

function clear() {
for (let property in graph) {
delete graph[property];
for (let property in $) {
delete $[property];
}

graph["classes"] = { name: "classes" };
$["classes"] = { name: "classes" };
}

module.exports.graph = graph;
module.exports.$ = $;
module.exports.retrieve = retrieve;
module.exports.clear = clear;
2 changes: 1 addition & 1 deletion src/lib/revive.js
Expand Up @@ -62,7 +62,7 @@ setImmediate(() => {
let state, graph;

setImmediate(() => {
state = require("../state").state;
state = require("../state");
graph = require("../graph");
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/serialize.js
@@ -1,8 +1,8 @@
let state, graph;

setImmediate(() => {
state = require("../state").state;
graph = require("../graph").graph;
state = require("../state").$;
graph = require("../graph").$;
});

function serialize(input, source, acc = {}) {
Expand Down
8 changes: 3 additions & 5 deletions src/nuc/DELETE$OBJECT.js
Expand Up @@ -16,10 +16,8 @@ class DELETE$OBJECT extends DELETE {
const list = node.class.list.toString();
state.delete(scope, `${list}.${name}`);

const index = state.state[list].findIndex(
(object) => object.id === node.key
);
state.state[list].splice(index, 1);
const index = state.$[list].findIndex((object) => object.id === node.key);
state.$[list].splice(index, 1);
}

return super.run();
Expand All @@ -32,7 +30,7 @@ class DELETE$OBJECT extends DELETE {
delete node.next[key];
}

delete graph.graph[node.key];
delete graph.$[node.key];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nuc/DELETE$VARIABLE.js
Expand Up @@ -9,7 +9,7 @@ class DELETE$VARIABLE extends DELETE {
delete node.next[key];
}

delete graph.graph[node.key];
delete graph.$[node.key];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/nuc/DELETE.js
Expand Up @@ -48,8 +48,8 @@ class DELETE {

const name = node.name;
delete node.object.properties[name];
delete graph.graph[node.key];
graph.graph[node.key] = empty;
delete graph.$[node.key];
graph.$[node.key] = empty;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nuc/EXPRESSION.js
Expand Up @@ -122,7 +122,7 @@ class EXPRESSION {

const temporary = new NODE(node);
// TODO NODE Direct
graph.graph[node] = temporary;
graph.$[node] = temporary;
return temporary;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/nuc/FOR.js
Expand Up @@ -25,7 +25,7 @@ class FOR {
let list = [];
let key = array[this.index].id;

if (key !== undefined && graph.graph[key]) {
if (key !== undefined && graph.$[key]) {
let object = array[this.index++].id;
let statements = [$LET(this.variable.node, object)];
list.push(
Expand Down
28 changes: 16 additions & 12 deletions src/nuc/NODE.js
@@ -1,4 +1,4 @@
const { graph } = require("../graph");
const graph = require("../graph");
const transaction = require("../transaction");

let sequence = 0;
Expand All @@ -19,27 +19,31 @@ class NODE {

// TODO Move this to graph
static register(key, node) {
transaction.register(graph, key, node);
transaction.register(graph.$, key, node);
}

static replace(sourceKey, targetNode) {
transaction.register(targetNode.block, graph[sourceKey].block);

for (let node in graph[sourceKey].next) {
transaction.register(targetNode.next, node, graph[sourceKey].next[node]);
transaction.register(graph[sourceKey].next, node, undefined);
transaction.register(targetNode.block, graph.$[sourceKey].block);

for (let node in graph.$[sourceKey].next) {
transaction.register(
targetNode.next,
node,
graph.$[sourceKey].next[node]
);
transaction.register(graph.$[sourceKey].next, node, undefined);
}

for (let node in graph[sourceKey].previous) {
transaction.register(graph[node].next, sourceKey, undefined);
for (let node in graph.$[sourceKey].previous) {
transaction.register(graph.$[node].next, sourceKey, undefined);
}

transaction.register(graph, sourceKey, targetNode);
transaction.register(graph.$, sourceKey, targetNode);
}

static direct(sourceKey, targetKey, targetNode) {
transaction.register(graph[sourceKey].next, targetKey, targetNode);
transaction.register(targetNode.previous, sourceKey, graph[sourceKey]);
transaction.register(graph.$[sourceKey].next, targetKey, targetNode);
transaction.register(targetNode.previous, sourceKey, graph.$[sourceKey]);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/stack.js
Expand Up @@ -95,7 +95,6 @@ function process(statements, prior, options = {}) {
break;
}
case statement instanceof $: {
// TODO Move prepare check here
if (instruction.before && !statement.prepared) {
statement.before(instruction.scope);
statement.prepared = true;
Expand Down Expand Up @@ -199,7 +198,7 @@ function process(statements, prior, options = {}) {
}
}

skip: if (!(statement instanceof $)) {
skip: {
if (statement.type === "CLASS" && instruction.scope.prior) {
break skip;
}
Expand Down
14 changes: 7 additions & 7 deletions src/state.js
@@ -1,11 +1,11 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-eval */
// TODO Rename this to `$`
const state = {
const $ = {
classes: [],
};
const state = $;
const _transaction = require("./transaction");
const { graph: _graph } = require("./graph");
const { $: $graph } = require("./graph");
const { event } = require("./event");
const _ = require("lodash");
const { v4: uuid } = require("uuid");
Expand Down Expand Up @@ -42,14 +42,14 @@ function del(scope, variable) {
module.exports.throw = (scope, exception) => eval(`throw ${exception}`);

function clear() {
for (let property in state) {
delete state[property];
for (let property in $) {
delete $[property];
}

state["classes"] = [];
$["classes"] = [];
}

module.exports.state = state; // will be private
module.exports.$ = $;
module.exports.assign = assign;
module.exports.call = call;
module.exports.expression = expression;
Expand Down
4 changes: 2 additions & 2 deletions src/transaction.js
Expand Up @@ -12,7 +12,7 @@ function end() {

function register(p1, p2, p3) {
// eslint-disable-next-line no-unused-vars
const { state } = require("./state");
const state = require("./state").$;

if (!p1) return;

Expand All @@ -39,7 +39,7 @@ function register(p1, p2, p3) {
}

function rollback() {
const { state } = require("./state"); // eslint-disable-line no-unused-vars
const state = require("./state").$; // eslint-disable-line no-unused-vars

while (list.length) {
let transaction = list.pop();
Expand Down

0 comments on commit c5358a5

Please sign in to comment.