Skip to content

feat: refactor register, bind, and proxy to use s_expressions #32

Draft
thantos wants to merge 9 commits intomainfrom
sussman/s_expr_register
Draft

feat: refactor register, bind, and proxy to use s_expressions #32
thantos wants to merge 9 commits intomainfrom
sussman/s_expr_register

Conversation

@thantos
Copy link
Copy Markdown
Contributor

@thantos thantos commented Sep 23, 2022

Depends on: sam-goodwin/functionless#520

("REGISTER", stash = () => {}, stash[Symbol.from(functionless::AST)] = ast, stash)

("REGISTER_REF", stash=REGISTER_REF,x[Symbol.for(AST)]=ast)

("BIND",
   stash={ args: args, self: this, func: func },
   stash={ f: stash.func.bind(stash.self, ...stash.args), ...stash },
   typeof stash.f === "function" && (
       stash.f[Symbol.for("functionless:BoundThis")] = stash.self,
       stash.f[Symbol.for("functionless:BoundArgs")] = stash.args,
       stash.f[Symbol.for("functionless:TargetFunction")] = stash.func
   ),
   stash
)

("PROXY",
   stash={ args }, // ensure the args are only evaluated once
   stash={ proxy: new clss(...stash.args), ...stash }, // create the proxy
   globalThis.util.types.isProxy(stash.proxy) && (
      globalThis.proxies = globalThis.proxies ?? new globalThis.WeakMap(),
      proxyMap.set(stash.proxy, stash.args)
   ),
   proxy
)

@sam-goodwin
Copy link
Copy Markdown
Owner

I love it!!

Comment thread CONTRIBUTING.md
@@ -0,0 +1,16 @@
### Pre-req
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread src/closure_decorator.rs Outdated
Comment on lines +26 to +34
const REGISTER_FLAG: &str = "REGISTER_8269d1a8";
// (REGISTER_REF,stash[]=ast)
const REGISTER_REF_FLAG: &str = "REGISTER_REF_8269d1a8";
// // (BIND, ...)
const BIND_FLAG: &str = "BIND_8269d1a8";
// // (PROXY, ...)
const PROXY_FLAG: &str = "PROXY_8269d1a8";

const GLOBAL_THIS_NAME: &str = "global_8269d1a8";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of the hashes now. The chance of this occurring is almost zero

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which hashes? the salt? or you just mean in the flag/command names?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The salt on the end. That's just a crc of the word functionless lol

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed from the flag/command names, I originally tried to put the string there without setting stash, but something strips the string off as a no-op.

Comment thread src/closure_decorator.rs Outdated
Comment on lines +150 to +158
items.push(ModuleItem::Stmt(Stmt::Expr(ExprStmt {
expr: Box::new(Expr::Assign(AssignExpr {
span: DUMMY_SP,
op: AssignOp::Assign,
left: PatOrExpr::Expr(Box::new(Expr::Ident(self.stash.clone()))),
right: undefined_expr(),
})),
span: DUMMY_SP,
})))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, woops. I noticed that the stash value was being serialized and tried to clear the value, but this didn't work because it would need to cleared from the nested scopes too. Will remove.

Comment thread src/closure_decorator.rs Outdated
Comment thread src/closure_decorator.rs
expr.visit_mut_children_with(self)
}
}
Expr::Call(call) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove the visit_mut_call_expr handler? I don't think those two can co-exist

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did! I was scrambling to figure out how to return a different node type and found this beautiful function :-) the other one is removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants