leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.06k stars 25 forks source link

Allow for arbitrary module attributes #21

Open leostera opened 4 years ago

leostera commented 4 years ago

While working on #19, the error traces pointed out that the Process.spawn function was shadowing Erlang's spawn. This can be overcomed with a compiler directive, which we can't write at the moment, such as -compile({no_auto_import, [spawn/1]})..

Allowing these compiler directives is useful for:

One way to fix this is to just use the compiler annotations where we can embed a string of raw Erlang, parse it, and merge it with the translated AST.

[@caramel.raw {|
-compile({no_auto_import, [spawn/1]}).
|}]

Definitely not pretty, but should be enough to unblock this while we figure out what the proper syntax for this is. Another alternative would be:

Caramel.ModAttributes.[
  compile (no_auto_import [ funref `spawn 1 ]); 
] [@caramel.module_attributes]

but building a DSL for this feels like a lot more work right now.