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

confusion between functions, identifiers, and names #24

Open
julochrobak opened this issue Oct 1, 2013 · 0 comments
Open

confusion between functions, identifiers, and names #24

julochrobak opened this issue Oct 1, 2013 · 0 comments

Comments

@julochrobak
Copy link
Contributor

I looked at the possibility to support some basic namespaces for built-in functions, for example math for mathematical functions (math.Round, math.Trunc, math.Abs), or str for string operations (str.Title, str.ToLower), and so on... However, I realized there is a bug with the current implementation which is somehow related to what looked at, i.e. IDENT '.' IDENT ( … ) or postfix_expression '.' postfix_expression (…).

The issue is that every function name is registered in the "names" map of the declarations, and the Decls.UseIdent function registers it as an identifier as well, always with a nil value because no value is ever assigned to this identifier, which is in fact just a function name…

This confusion between names, identifiers, and functions also leads to variety of strange situations:

$ bin/comp '{trunc}'
{ "trunc": panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x15d77]

goroutine 1 [running]:
main.Object.Quote(0xc2000bf750, 0x1, 0x1, 0xc2000c0420, 0xc200000008, ...)
/Users/julo/comp/src/comp/value.go:252 +0x417
main.(*Object).Quote(0xc200090680, 0xc2000c0420, 0xc200000008,     0xc2000c0c90, 0xc200090620, ...)
/Users/julo/comp/src/comp/decls.go:0 +0xb3
main.Command(0x7fff5fbffae1, 0x7, 0x2b40a0, 0x0, 0x24, ...)
/Users/julo/comp/src/comp/main.go:32 +0x1cd
main.main()
/Users/julo/comp/src/comp/main.go:90 +0x1a0

goroutine 2 [syscall]:

goroutine 3 [runnable]:

$ bin/comp 'trunc'
$

$ bin/comp '[ 0 | trunc <- [0,1], trunc(trunc) ]'
[ 0 ]

$ bin/comp '[ trunc | trunc <- [0,1], trunc(trunc) ]'
'trunc' is already declared

$ bin/comp '[ trunc | t <- [0,1], trunc(t) ]'
[ panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x15709]
…
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

1 participant