Comments (16)
Do let me know if you have stuff you want to get sorted before dealing with this. I can come back :)
from caramel.
Some more progress today. I have the README example running. Hello Joe! (RIP)
A few things needed:
-
Copied process.erl and beam_io.erl into my project and manually fixed up the errors and warnings in both. The other .erl files (maps.erl etc) fight with the OTP modules with the same names - I think they need to go back to being prefixed even if it means lots of name mangling / unmangling.
-
Provide a stdlib-path. The default stdlib-path for caramelc isn't right any more. I had to use --stdlib-path /home/sean/.opam/default/lib/caramel/stdlib
-
Added a .merlin file to my erlang project to get ocaml editor support. Io wasn't found - I had to change the code to Beam_io:format for merlin to find the definition.
Super nice :)
from caramel.
Closer and closer. stdlib-path default now works for me after make install from latest head.
Still a few smaller things I'm sure you already have on your list:
- The generated process.erl still has type variables the erlang compiler doesn't like
- I kind of feel the need for an Io.ml so merlin can work. You have beam_io.ml - I guess this is a workaround for some other issue?
I will have a go at writing some more programs and exploring the possibilities
from caramel.
process.erl looking good. no more warnings :)
Beam.Io.format fixes merlin, but compiles to:
beam__io:format(<<"current_state: ~p\n">>, [State | []])
beam__io is not an erlang module in the tree. beam_io.erl exists in your generated files but uses a non existing '__unsafe_fmt'(S, X).
As an experiment I renamed beam_io.ml to io.ml and changed the dune files and beam.ml to match. Everything now seems to work.. but I'm not experienced with ocaml so don't know what else I might have broken.
from caramel.
Thanks for bringing this up! Excellent point. I'll have to add a flag so there could be multiple compilation targets at one go. Then Caramel can ship its .erl stdlib as well so you can just point to it with erlc
's -pa
path flags.
Working out a rebar3 plugin would be fantastic 🙌🏼 I'm thinking the plugin could just download the appropriate binary and then you have full control over the paths of the stdlib as well.
from caramel.
Sounds great!
from caramel.
Oops! Apparently the word "fix" closes the issue 😅
from caramel.
Seeing some compile errors in the generated stdlib_process.erl:
===> Compiling src/stdlib_process.erl failed
src/stdlib_process.erl:17: type variable 'A' is only used once (is unbound)
src/stdlib_process.erl:19: function '__caramel_recv'/0 undefined
src/stdlib_process.erl:25: type variable 'A' is only used once (is unbound)
src/stdlib_process.erl:29: function recv/0 undefined
src/stdlib_process.erl:36: ambiguous call of overridden pre R14 auto-imported BIF spawn/1
- use erlang:spawn/1 or "-compile({no_auto_import,[spawn/1]})." to resolve name clash
I'm on OTP 23
from caramel.
I managed to clear out all those errors you mentioned, except the recv/0
function being undefined. This is a blocking issue I need to fix first: #10
from caramel.
I think #10 is a good next thing to get done. After that this issue might be resolved.
I'll make a new issue for allowing compiler annotations that can be turned into module attributes, to allow for -compile({no_auto_import,[spawn/1]})
to be set. This seems useful as well.
from caramel.
Regarding the --stdlib-path flag, keep an eye on this build -- it fixes the paths so you can use make install
and it'll find the stdlib there too. I tried it locally and it seemed to work on Ubuntu 20.04.
from caramel.
Regarding the additional .erl files -- currently the only one that is included in the release tarball is process.erl
, since the rest should be empty or point to types that should be mapped to OTP types.
from caramel.
@seanhinde yup! getting there 🚀
The latest head should produce the following process.erl
, which for me compiles without warnings on Erlang 23. Could you try on a clean build and see if you get the same file?
% Source code generated with Caramel.
-module(process).
-export_type([after_time/0]).
-export_type([recv/1]).
-export([contramap/2]).
-export([make/1]).
-export([recv/1]).
-export([send/2]).
-type after_time() :: infinity
| {bounded, integer()}
.
-type recv(M) :: fun((after_time()) -> option:t(M)).
-spec recv(after_time()) -> option:t(any()).
recv(Timeout) ->
F = fun (T) -> receive X -> {some, X} after T -> none end end,
case Timeout of
infinity -> F(infinity);
{bounded, T} -> F(T)
end.
-spec make(fun((erlang:pid(), recv(_m)) -> _a)) -> erlang:pid().
make(F) -> erlang:spawn(fun
() ->
Pid = erlang:self(),
F(Pid, fun recv/1)
end).
-spec send(erlang:pid(), _m) -> ok.
send(Proc, Msg) -> erlang:send(Proc, Msg).
-spec contramap(fun((_b) -> _a), erlang:pid()) -> erlang:pid().
contramap(F, Pid) -> make(fun
(_self, Recv) ->
case Recv(infinity) of
{some, A} -> send(Pid, F(A));
none -> ok
end
end).
For 2) could you try using the full path? Beam.Io.format
? The Beam
module is opened by default, but otherwise should still be available.
from caramel.
Sweet! Yeah there'll be some .erl files that are not included in the actual release (beam_io.erl
being one of them), since they are just compilation garbage.
Could you try making a local alias?
module Io = Beam.Io
Or with an explicit open?
open Beam
from caramel.
@seanhinde I figured what was breaking with the module name and now its called just io.ml
:) so Merlin should work just fine now.
Quite a ride! 🎢 -- thanks for all the feedback btw, it helped me get the release in order and I'm a lot happier with it now. We covered:
- fixing the stdlib path to work with dune install structure
- ship process.erl as part of the stdlib and make sure it compiles without errors
- fix the Io module name
Let me know if you give that rebar3 plugin a shot :) if rebar3 supports plugins that are nested within a git repo, i'd be happy to include it in here too.
Closing this for now, feel free to open other issues if you find anything 🙌🏼
from caramel.
Thanks so much. Super cool. I'll take a look at a rebar3 plugin - no promises when though - I will also spend some time using the system.
from caramel.
Related Issues (20)
- Fix windows dependencies cache on CI HOT 1
- Annotating types for function arguments compiles to wrong erlang HOT 1
- Nested let-in expressions compile to wrong erlang HOT 12
- Fun references of operators have the wrong arity and module name HOT 2
- Pipe operator support HOT 4
- Make it clear to see what's different from the standard OCaml lang+runtime HOT 1
- Add a hello world snippet in the frontpage HOT 1
- Make it clear we need Erlang installed
- Idiomatic Elixir wrappers for generated code
- Unclear behavior with externals HOT 1
- Mention caramel parse command in CONTRIBUTING.md
- Support aliases in patterns
- The sources of the following couldn't be obtained, aborting: - erlang.0.0.14
- Generate unique variable names to deal with name shadowing and Erlang bindings escaping expression blocks HOT 2
- Map Literal syntax HOT 2
- Atom/Variant which is just underscore is a Syntax Error HOT 2
- Are parameterized modules/functors available? HOT 3
- Wrong Compiler Version in Release 0.1.1 HOT 1
- Function declarations with explicit type annotations compile to the wrong Erlang code HOT 8
- build with latest ocaml 4.14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from caramel.