atomvm / AtomVM

Tiny Erlang VM
https://www.atomvm.net
Apache License 2.0
1.48k stars 103 forks source link

Trying to port elixir library #1174

Closed Ridtt closed 2 months ago

Ridtt commented 4 months ago

Hello, im trying to compile elixir library into .avm pack using mix atomvm.packbeam

Only errors left I have is -

error: following modules or functions are not available on AtomVM:

Is to possible to implement?

I have big hope to run my existing binary structures decoding/encoding library in targets like wasm and stm32.

I could replace those functions but underlaying deps using this too. Looks very common.

UncleGrumpy commented 4 months ago

You should be able to use an erlang:error/1 or erlang:throw/1.

UncleGrumpy commented 4 months ago

I have big hope to run my existing binary structures decoding/encoding library in targets like wasm and stm32.

Not to diminish your hopes, but both of those platforms have limited support. Depending on what you are hoping to accomplish they may well work for your needs, but the esp32 platform has the best level of support, and the pico(w) is also quite capable for networking and basic gpio. STM32 has gpio support but no networking yet, and no I2C or SPI, but if you are familiar with the platform any contributions are more than welcome.

UncleGrumpy commented 4 months ago

You should be able to use an erlang:error/1 or erlang:throw/1.

Actually from looking at the docs :erlang:raise/1 is probably what you are looking for.

https://hexdocs.pm/elixir/main/RuntimeError.html

Ridtt commented 3 months ago

@UncleGrumpy Thank you for such a warm answer! I want you to know I decided not dig into your great project more atm, there is lack of what I need currently. I will have my eyesight on it, project idea is really brave thing to even imagine, you have my respect.

In real word scenario from my perspective besides implementation of all vm opcodes would be super interesting to have an option to write implementation or just declare i need to include it from elixir codebase (I need Enum.into to compile deps, for example).

And second one is way to provide native language implementations, mix of something like embassy/rtic and rustler.

In other words some generic solution to extend from elixir and from native. You declaring your extensions, everything become tiny, unused shrinking, you can go deep and fast as required and it’s automagically merged into high level elixir app.

I’m writing embedded software in rust currently, if only I could make elixir abstractions over my rust drivers and run arbitrary elixir code for top level without worry of some elixir functionality not included. Sounds like a dream.

Thank you again for what you are doing and dreaming, best regards.

Ridtt commented 3 months ago

@UncleGrumpy

I just don’t really understand needs for i2c and other stuff like this be part of this project, rtic/embassy have all required drivers for example, such wrapper could be easily just imported by end user. But what could be not is microseconds interruption handling, circular DAC multiplexing with less then millisecond on multichannel into buffers and every non trivial work every coprocessor for example wants to do fast. What is the reason repeat all those spi/i2c’s etc if it’s not a game changer? I can turn switches on raspberry pi running Linux with gpio driver or read write spi. Can I do that fast? No. It’s still child play. I can run ADC for example on cheapest stm mcu millions times per second, accumulate reading, extract waveform and provide it as event to running elixir process for example, perfect real word task solved for some industrial sensors reader can now process pipeline next step. And we could have even cluster of such things, communicated by SPI for example.

I see only way to change this into flawless victory is give user easy and known way to integrate native parts or whole underlying native framework.

Like plug your IO here (qspi, spi, i2s, can, etc etc)

Plug your socket based networking here (WiFi, Ethernet, GPRS, custom LoRa implementation don’t care)

Plug your drivers here and so on.

I’m sorry if such my dreams going way to far from this project goals, but this is crazy and brave itself like I said before anyway.