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

Wrong lamba parameter parsing #102

Open
ilpincy opened this issue Mar 8, 2022 · 2 comments
Open

Wrong lamba parameter parsing #102

ilpincy opened this issue Mar 8, 2022 · 2 comments

Comments

@ilpincy
Copy link
Member

ilpincy commented Mar 8, 2022

The following code listings generate different behavior. (A) is correct, (B) is wrong.

# Code (A), correct
f = function(a,b,c) {
  log(a,";",b,";",c)
}
f(1,2,3)
# Code (B), wrong
if(1) {
  f = function(a,b,c) {
    log(a,";",b,";",c)
  }
}
f(1,2,3)
# Assembly (A): correct, notice the lload statements
52:	pushnil	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
53:	pushs 1	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
58:	gload	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
59:	lload 1	|3,9,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
64:	pushs 2	|3,10,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
69:	lload 2	|3,15,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
74:	pushs 2	|3,16,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
79:	lload 3	|3,21,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
84:	pushi 5	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
89:	callc	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
90:	pop	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
# Assembly (B): correct, notice the lload statements
62:	pushnil	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
63:	pushs 1	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
68:	gload	|3,7,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
69:	lload 0	|3,9,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
74:	pushs 2	|3,10,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
79:	lload 1	|3,15,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
84:	pushs 2	|3,16,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
89:	lload 2	|3,21,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
94:	pushi 5	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
99:	callc	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz
100:	pop	|4,2,/Users/cpinciroli/Fabrica/Buzz/buzz/src/testing/testfunction.bzz

The problem is related to parsing, in particular when a lambda is created inside a block (in this case the if), but the if is not itself into a function().

I don't have a fix yet, need to check how to solve it.

@shivangvijay
Copy link

I'm getting output 1;2;3 with code A, and [nil];1;2 with code B.
I've just started exploring Buzz. Could you let me know which file contains the function implementation? I'm eager to contribute to your swarm robotics work.

@beltrame
Copy link
Contributor

It's not for the faint of heart, but you should look into buzzparser.c, where the assembly is generated. The function parse_if() and parse_lambda() might be a good point to start, there is likely something in there that is not properly set for this situation.

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

No branches or pull requests

3 participants