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

JIT: If a function/method is built-in, reference it directly #2398

Open
gfwilliams opened this issue Aug 4, 2023 · 1 comment
Open

JIT: If a function/method is built-in, reference it directly #2398

gfwilliams opened this issue Aug 4, 2023 · 1 comment

Comments

@gfwilliams
Copy link
Member

gfwilliams commented Aug 4, 2023

Right now, JIT creates code on demand, but it looks everything up on the fly.

As an example:

function turnOn() { "jit"
  digitalWrite(LED1,1);
}

roughly translates to:

  • Look up digitalWrite
  • Look up LED1
  • call digitalWrite with LED1 and 1

or.....

function draw() { "jit"
  g.drawLine(0,0,100,100);
}

roughly translates to:

  • Look up g
  • Look up drawLine on g
  • call drawLine with this=g,0,0,100,100

I think it's probably safe to assume that in both cases we could look the relevant thing up at JIT time and if it is built into the interpreter (or it's defined const), we could just use it direct?

edit: sometimes code does overload an old implementation (eg maybe g.drawLine may be patched with a fixed version) but as long as that is done before JIT parses the function we'd be fine

It should translate to a pretty drastic speed improvement.

@gfwilliams
Copy link
Member Author

There is now a partial implementation of this. digitalWrite(LED1,1); now uses digitalWrite and LED1 directly (rather than searching).

Handling g.drawLine is more problematic as we're not sure if g is going to change. It's pretty clear for g.drawLine, but x.toString() will expect to call the toString function for whatever x is. For console.log/etc where console is itself a builtin this makes a lot of sense though.

We currently store our vars list as just a list of var names, but I think to do this properly we'd want to change it to include full paths, like "console.log" - which then get appended only if we know that the first part was a builtin too. All a lot more work though.

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

No branches or pull requests

1 participant