Skip to content

Commit

Permalink
ubg notes
Browse files Browse the repository at this point in the history
SQUASHED: ubg-notes,
  • Loading branch information
onsetsu committed Jul 4, 2024
1 parent e8bc8ce commit 0886187
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Number of AST Nodes


<script>
import sloc from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm'

function countNodes(srcCode) {
let nodeCount = 0
srcCode.traverseAsAST({
enter(path) {
nodeCount++;
}
})
return nodeCount
}

// const srcURL = lively4url + '/../active-expressions/src/';
// function skip(fileURL) {
// return fileURL.endsWith('utils.js')
// }
// const srcURL = lively4url + '/../aexpr-ticking/src/';
// function skip(fileURL) {
// return fileURL.endsWith('utils.js')
// }
const srcURL = lively4url + '/../aexpr-interpretation/src/';
function skip(fileURL) {
return false && fileURL.includes('babelsberg') || fileURL.endsWith('utils.js')
}
// const srcURL = lively4url + '/../aexpr-source-transformation-propagation/src/';
// function skip(fileURL) {
// return false
// }
// const srcURL = lively4url + '/../babel-plugin-aexpr-source-transformation/';
// function skip(fileURL) {
// return !fileURL.endsWith('./index.js')
// }
const { contents: files } = await fetch(srcURL, {
method: "OPTIONS",
headers: {filelist: "true"}
}).then(r => r.json())

// lively.files.visualizeFileTreeMap(srcURL)


const metrics = []
for (let file of files) {
const fileURL = srcURL + file.name;
if (fileURL.endsWith('.js') && !skip(fileURL)) {
const code = await fileURL.fetchText();
const numNodes = countNodes(code)
const sLoc = sloc(code, 'js').source
metrics.push([fileURL, `${numNodes} (${sLoc})`])
}
}

<table>{...metrics.map(([file, numNodes]) => <tr><td>{file}</td><td>{numNodes}</td></tr>)}</table>
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Convention
- ast nodes 136 = 18 + 118
- sloc (29) = (1) + (28)

[aexpr-ticking](https://github.com/active-expressions/aexpr-ticking.git)
e9b4034
e9b4034606dd286ac494f20293cf7e7e9649e0ac

- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./aexpr-ticking.js 18 (1)
- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./ticking/ticking-active-expressions.js 118 (28)

# Interpretation
- ast nodes 787 = 12+182+224+369
- sloc (170) = (1)+(43)+(51)+(75)

[aexpr-interpretation](https://github.com/active-expressions/aexpr-interpretation.git)
46d1d17
46d1d175b4cb040bda636fe871ef5d2f70f5e3e8

- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./aexpr-interpretation.js 12 (1)
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/property-accessor.js 182 (43)
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/listener.js 224 (51)
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/interpretation-active-expressions.js 369 (75)

# Compilation
- ast nodes 2281 = 730+1551
- sloc (471) = (169)+(302)

[aexpr-source-transformation-propagation](https://github.com/active-expressions/aexpr-source-transformation-propagation.git)
3154d05
3154d05af0ce410b041eb312ba57f7d32a6e7672

- https://lively-kernel.org/lively4/aexpr/../aexpr-source-transformation-propagation/src/./aexpr-source-transformation-propagation.js 730 (169)

[babel-plugin-aexpr-source-transformation](https://github.com/active-expressions/babel-plugin-aexpr-source-transformation.git)
54a712a
54a712a45175f98c0f0a627770ae811759b195da

- https://lively-kernel.org/lively4/aexpr/../babel-plugin-aexpr-source-transformation/./index.js 1551 (302)

---

---

2820 + null

all ref
5794 = 1707 + 1267 + 2820

all aexpr
3038 = 274 + 672 + 2092

interpret aexpr
926 = 787 + 139

sum aexprs
3964 = 3038 + 926

1707 - 274
1267 - 672
2820 - 2092

subsec:impl_comparison
subsec:impl_complexity
subsec:impl_qualitative_analysis
subsec:impl_quantitative_analysis


3018 = 2092 + 787 + 139
Original file line number Diff line number Diff line change
@@ -1,56 +1,23 @@
console.log(123)
export default function ({ template, types: t }) {
return {
name: 'sample data bindings (<~)',
visitor: {
Program(program) {
// handle squiggly arrow operator
function leftRightOfSquigglyArrow(path) {
if (!path.isBinaryExpression()) { return [] }
if (path.node.operator !== '<') { return [] }

let right
const expression = path.get('right')
if (expression.isUnaryExpression() && expression.node.operator === '~') {
right = expression.get('argument')
} else {
expression.traverse({
UnaryExpression(unary) {
if (unary.node.operator !== '~') { return }
if (expression.node.loc.start.index !== unary.node.loc.start.index) { return }
unary.stop()
unary.replaceWith(unary.get('argument').node)
right = expression
}
})
}
debugger
if (!right) { return [] }

const left = path.get('left')
if (!left.isLVal()) {
throw left.buildCodeFrameError("Unassignable left-hand side of data binding")
}

return [left, right]
}

program.traverse({
ExpressionStatement(expressionStatementPath) {
const path = expressionStatementPath.get('expression');
ExpressionStatement(stmt) {
const path = stmt.get('expression');
const [left, right] = leftRightOfSquigglyArrow(path);
if (!left || !right) {
// path.replaceWith(t.numberLiteral(123))
return
}

const valueName = right.scope.generateUidIdentifier('value')
const bindingTemplate = template(`aexpr(() => EXPRESSION)
.dataflow(${valueName.name} => REFERENCE = ${valueName.name})`)
path.replaceWith(bindingTemplate({
REFERENCE: left.node,
EXPRESSION: right.node,
}))
if (!left || !right) { return }

// path.replaceWith(t.numberLiteral(123))

// const name = path.scope.generateUidIdentifier('value').name;
// const db = template(`ae(EXPR).onChange(${name} => REF = ${name})`)({
// EXPR: right,
// REF: left
// });
// path.replaceWith(db)
}
})
}
Expand All @@ -59,7 +26,35 @@ export default function ({ template, types: t }) {
}


function leftRightOfSquigglyArrow(path) {
if (!path.isBinaryExpression()) { return [] }
if (path.node.operator !== '<') { return [] }

let right
const expression = path.get('right')
if (expression.isUnaryExpression() && expression.node.operator === '~') {
right = expression.get('argument')
} else {
expression.traverse({
UnaryExpression(unary) {
if (unary.node.operator !== '~') { return }
if (expression.node.loc.start.index !== unary.node.loc.start.index) { return }
unary.stop()
unary.replaceWith(unary.get('argument').node)
right = expression
}
})
}
if (!right) { return [] }

const left = path.get('left')
if (!left.isLVal()) {
throw left.buildCodeFrameError("Unassignable left-hand side of data binding")
}

console.warn('squiggly arrow found')
return [left.node, right.node]
}



Expand All @@ -68,10 +63,8 @@ export default function ({ template, types: t }) {



// const valueName = right.scope.generateUidIdentifier('value')
// const bindingTemplate = template(`aexpr(() => EXPRESSION)
// .dataflow(${valueName.name} => REFERENCE = ${valueName.name})`)
// path.replaceWith(bindingTemplate({
// REFERENCE: left.node,
// EXPRESSION: right.node,
// }))
// const db = template(`aexpr(() => SOURCE).dataflow(v => TARGET = v)`)({
// SOURCE: right,
// TARGET: left,
// });
// path.replaceWith(db)
12 changes: 12 additions & 0 deletions src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const target = document.getElementById('target');

target.style.width <~ that.style.width






ae(that.style.width).onChange(v => target.style.width = v)
import { AExprRegistry } from 'src/client/reactive/active-expression/ae-registry.js'
AExprRegistry.allAsArray().last.dispose()
26 changes: 2 additions & 24 deletions src/components/widgets/ubg-cards-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,8 @@ export default class UBGCardEntry extends Morph {
this.classList.toggle('out-of-range', !inRange);
}

updateToFilter(filter) {
let matching

if (filter.startsWith('>')) {
let functionBody = 'return ' + filter.substring(1).trim();
let filterFunction = new Function('c', functionBody);
matching = !!filterFunction(this.card)
} else {
filter = filter.toLowerCase();

const card = this.card;
const id = card.getId();
const name = card.getName();
const cardType = card.getType()
const element = card.getElement();
const cost = card.getCost();
const text = card.getText();
const notes = card.getNotes();
const tags = card.getTags().join(' ');
const aspects = [id, name, cardType, element, cost, text, notes, tags];

matching = aspects.some(aspect => (aspect + '').toLowerCase().match(new RegExp(filter, 'gmi')));
}

updateToFilter(filterFunction) {
const matching = filterFunction(this.card)
this.classList.toggle('match', matching);
this.classList.toggle('hidden', !matching);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/ubg-cards.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</style>
<div id='layout'>
<div id="buttons">
<input id="filter" title="Ctrl+/" placeholder="filter, e.g. fire\b"/>
<input id="filter" title="Ctrl+/" placeholder="filter: regex fire\b or > c.getId() > 1000"/>
<button id="sortById" title="sort cards by id"><i class="fa fa-sort" aria-hidden="true"></i>by id</button>
<button id="sortByName" title="sort cards by name"><i class="fa fa-sort" aria-hidden="true"></i>by name</button>
<input id="rangeStart" title="min id" placeholder="min"/>
Expand Down
27 changes: 26 additions & 1 deletion src/components/widgets/ubg-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,35 @@ export default class Cards extends Morph {
});
}

functionForFilter(filter) {
if (filter.startsWith('>')) {
let functionBody = `return !!(${filter.substring(1).trim()})`;
return new Function('c', functionBody);
}

filter = filter.toLowerCase();
const regex = new RegExp(filter, 'gmi')

return function filterFunction(card) {
const id = card.getId();
const name = card.getName();
const cardType = card.getType()
const element = card.getElement();
const cost = card.getCost();
const text = card.getText();
const notes = card.getNotes();
const tags = card.getTags().join(' ');

const aspects = [id, name, cardType, element, cost, text, notes, tags];
return aspects.some(aspect => (aspect + '').toLowerCase().match(regex));
}
}

updateItemsToFilter() {
const filterValue = this.filterValue;
const filterFunction = this.functionForFilter(filterValue);
this.allEntries.forEach(entry => {
entry.updateToFilter(filterValue);
entry.updateToFilter(filterFunction);
});
}

Expand Down
14 changes: 7 additions & 7 deletions src/plugin-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,11 @@ async function aexprViaDirectivePlugins(options = {}) {
await importDefaultOf('babel-plugin-syntax-async-generators'),
await importDefaultOf('babel-plugin-syntax-object-rest-spread'),
await importDefaultOf('babel-plugin-syntax-class-properties'),
await importDefaultOf('babel-plugin-sample-data-bindings'),
await importDefaultOf('babel-plugin-var-recorder'),
[await importDefaultOf('babel-plugin-ILA'), {
executedIn: 'file'
}],
[await importDefaultOf('babel-plugin-sample-data-bindings'), {
executedIn: 'file'
}],
[await importDefaultOf('babel-plugin-databindings'), {
executedIn: 'file'
}],
Expand Down Expand Up @@ -492,17 +490,19 @@ async function workspacePlugins(options = {}) {
])


const enableAExprsInWorkspace = localStorage.getItem("DisableAExpWorkspace") !== "true";
if (enableAExprsInWorkspace) {
result.push(await importDefaultOf('babel-plugin-sample-data-bindings'))
}

result.push(...await doitPlugins())

result.push(await importDefaultOf('babel-plugin-var-recorder'))

if (localStorage.getItem("DisableAExpWorkspace") !== "true") {
if (enableAExprsInWorkspace) {
result.push([await importDefaultOf('babel-plugin-ILA'), {
executedIn: 'file'
}])
result.push([await importDefaultOf('babel-plugin-sample-data-bindings'), {
executedIn: 'file'
}])
result.push([await importDefaultOf('babel-plugin-databindings'), {
executedIn: 'file'
}])
Expand Down

0 comments on commit 0886187

Please sign in to comment.