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

Implemented function expressions #382

Merged
merged 1 commit into from
May 9, 2020
Merged

Implemented function expressions #382

merged 1 commit into from
May 9, 2020

Conversation

Razican
Copy link
Member

@Razican Razican commented May 7, 2020

This also adds the name property to functions. It fixes #266 and makes progress towards #12.

There is one extra thing that is not solved though:

let a = function() {};
a.name;

This should show a, but this is currently not happening. I guess that the solution is to change the assignment expression to change the name of the function.

I duplicated most of the execution code for declarations/expressions, though, this can probably be improved in the future. I used this to set the name of the function:

val.set_field_slice("name", to_value(name.clone()));

This is not super spec compliant, but do you think it's good for now?

@Razican Razican added bug Something isn't working enhancement New feature or request labels May 7, 2020
@Razican Razican added this to the v0.8.0 milestone May 7, 2020
@github-actions
Copy link

github-actions bot commented May 7, 2020

Benchmark for de95f3e

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 485.0±22.54µs 486.3±13.93µs 100%
Expression (Lexer) 1990.8±75.35ns 1981.3±19.24ns 100%
Expression (Parser) 5.3±0.13µs 5.1±0.11µs 104%
Fibonacci (Execution) 3.3±0.15ms 3.3±0.03ms 101%
For loop (Execution) 503.6±19.15µs 505.9±8.71µs 100%
For loop (Lexer) 5.4±0.13µs 5.5±0.15µs 99%
For loop (Parser) 14.5±0.17µs 14.3±0.26µs 101%
Hello World (Lexer) 959.5±9.42ns 969.6±12.91ns 99%
Hello World (Parser) 2.3±0.06µs 2.4±0.10µs 97%
Symbols (Execution) 514.4±18.44µs 513.7±13.37µs 100%
undefined undefined 100%

This also adds the `name` property to functions.
@github-actions
Copy link

github-actions bot commented May 7, 2020

Benchmark for decbee6

Click to view benchmark
Test PR Benchmark Master Benchmark %
Create Realm 473.6±21.62µs 466.7±18.62µs 101%
Expression (Lexer) 1929.9±73.77ns 1912.0±69.85ns 101%
Expression (Parser) 5.2±0.16µs 4.9±0.15µs 104%
Fibonacci (Execution) 3.2±0.07ms 3.2±0.05ms 100%
For loop (Execution) 485.1±9.86µs 489.8±15.09µs 99%
For loop (Lexer) 5.2±0.19µs 5.2±0.09µs 101%
For loop (Parser) 13.9±0.33µs 13.8±0.38µs 101%
Hello World (Lexer) 944.3±47.82ns 935.7±47.56ns 101%
Hello World (Parser) 2.2±0.05µs 2.2±0.03µs 99%
Symbols (Execution) 500.4±11.00µs 494.6±10.50µs 101%
undefined undefined 100%

@Razican Razican requested review from jasonwilliams and HalidOdat and removed request for jasonwilliams May 9, 2020 11:52
@Razican Razican merged commit 9c9c463 into master May 9, 2020
@Razican Razican deleted the function_expr branch May 9, 2020 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic assigning named function to variable
2 participants