Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

thantos
Copy link
Contributor

@thantos thantos commented Sep 23, 2022

Depends on: functionless/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

I love it!!

@@ -0,0 +1,16 @@
### Pre-req

Choose a reason for hiding this comment

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

Thank you!

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";

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
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?

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
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 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,
})))

Choose a reason for hiding this comment

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

Why?

Copy link
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.

src/closure_decorator.rs Outdated Show resolved Hide resolved
}
}
Expr::Call(call) => {

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
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
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