Re: Some questions with D and webassembly
On Friday, 3 March 2023 at 13:42:55 UTC, ryuukk_ wrote: On Friday, 3 March 2023 at 03:32:37 UTC, TheZipCreator wrote: [...] https://discourse.llvm.org/t/rfc-webassembly-reference-types-in-clang/66939 it says it is an opaque type, maybe just need to be ``void*``? Also there are new intrinsics, maybe you can define them like this: ```D alias externref_t = void*; pragma(LDC_intrinsic, "llvm.wasm.table.set.externref.i32") extern(C) void llvm_wasm_table_set_externref(void*, int, externref_t); pragma(LDC_intrinsic, "llvm.wasm.table.get.externref.i32") extern(C) externref_t llvm_wasm_table_get_externref(void*, int); ``` Using `void*` doesn't appear to work (and looking at the generated wasm it seems to reduce it to `i32`, which is not the right type unfortunately). I guess what I could do is have a global array in js which stores all objects I'll need to access, then just access them via the index into that array but that feels like a hack especially when `externref` is a thing that exists.
Some questions with D and webassembly
In webassembly, there's a type called `externref`, which opaquely represents a javascript object. So, you could do this for example, with this javascript: ```js class Foo { constructor(x) { this.x = x; } } const imports = { env: { fooNew: (x) => new Foo(x), fooX: (foo) => foo.x, fooSetX: (foo, x) => { foo.x = x; } } } WebAssembly.instantiateStreaming(fetch("./foo.wasm"), imports).then(module => { let foo = module.instance.exports.f(); console.log(foo.x); // 5 module.instance.exports.g(foo); console.log(foo.x); // 8 }); ``` and this webassembly: ```wat (module (import "env" "fooNew" (func $fooNew (param i32) (result externref))) (import "env" "fooX" (func $fooX (result i32))) (import "env" "fooSetX" (func $fooSetX (param externref) (param i32))) (func (export "f") (result externref) i32.const 5 call $fooNew) (func (export "g") (param $foo externref) local.get $foo i32.const 8 call $fooSetX)) ``` 5 and 8 get logged. Equivalent D to the webassembly part would be: ```d extern(C): // how to get this externref type? externref fooNew(int); externref fooX(externref); void fooSetX(externref, int); externref f() { return fooNew(); } void g(externref foo) { fooSetX(foo, 8); } ``` problem being, there exists no `externref` type. So how would you achieve it with ldc2? B) In the javascript WebAssembly API, you can pass in memory like so: ```js const imports = { "mem": new WebAssembly.Memory({ initial: 1 }) } WebAssembly.instantiateStreaming(fetch("bar.wasm"), imports, module => { ... }); ``` then in WebAssembly ```wat (import "mem" (memory 1)) ``` so how could I do that in D? That is, I want the memory that D uses to be accessible to javascript (this way I can pass pointers between JS and D)
Re: Coding Challenges - Dlang or Generic
On Tuesday, 10 January 2023 at 00:17:18 UTC, Paul wrote: Greetings Dlang-ers I was wondering if anyone knew of any coding challenges available where the input and output are specified and its left to the programmer to find a solution? Free would be nice but even paid services would be worth considering. I'm taking a D class right now and it has little challenges in the lessons where much of the work is done for you, but I'm thinking of a site/service that is dedicated to these types of challenges (without doing any work for you). [...] while not specifically D-related, the code golf stack exchange is good place to find challenges (even if you're not golfing).
Re: Mixin helper help
On Thursday, 12 January 2023 at 08:03:34 UTC, John Chapman wrote: I'm obviously doing something wrong, but don't quite understand. ```d mixin template helper() { mixin("writeln(12);"); } struct Foo { void opDispatch(string name)() { import std.stdio; mixin helper!(); //mixin("writeln(12);"); } } void main() { Foo.init.opDispatch!"bar"(); } ``` The compiler emits these errors about the mixin ("writeln(12);"): unexpected `(` in declarator basic type expected, not `12` found `12` when expecting `)` no identifier for declarator `writeln(_error_)` semicolon expected following function declaration declaration expected, not `)` Why does the commented code work but the mixin not? Thanks for any pointers. This is not the purpose mixin templates are meant to serve. They're for copying declarations into scopes (and as such only support declarations in them). Instead, I think what you want is ```d template helper() { const char[] helper = `writeln(12);`; } struct Foo { void opDispatch(string name)() { import std.stdio; mixin(helper!()); } } void main() { Foo.init.opDispatch!"bar"(); } ```
GDC binary for windows?
is there a compiled binary of GDC anywhere? I looked at https://www.gdcproject.org/downloads, and the link there goes to winlibs, but after downloading the archive I couldn't find gdc anywhere in it. I did some research and [it appears they removed it](https://forum.dlang.org/thread/rcfevunwsgydorekw...@forum.dlang.org?page=2) for whatever reason. In the release archives there are some windows GDC binaries but those are all old versions and they lack the compiler flags I need (specifically `-fno-druntime`). So, are there binaries that still exist somewhere or do I just have to try to compile it from source?
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 23:03:49 UTC, Adam D Ruppe wrote: Here's the patch for ogg, you can download those two files off git master too works great! thanks
Re: Seeking in arsd.simpleaudio?
On Sunday, 20 November 2022 at 21:57:03 UTC, Adam D Ruppe wrote: On Sunday, 20 November 2022 at 20:34:44 UTC, Adam D Ruppe wrote: i'll get back to you in a lil i went overbudget lol. but yeah the seek function in the underlying lib fails and idk why it is so hard to even trace what error actually happened in these C codebases I can imagine, errors in C are extremely annoying. I guess in the meantime I'll just use a python script to cut the audio before execution
Seeking in arsd.simpleaudio?
I'm currently making a library to do programmatic animation (akin to [manim](https://www.manim.community/) but for D and a different style) and for audio arsd.simpleaudio seems like the only real option (all the others I could find are too low-level for my taste) but if I want to skip to a specific section of the video, then I'd need to be able to seek the audio to that location too, and it appears that arsd.simpleaudio doesn't have a seek function. Is there a way to do this via other means? I want something like: ```d import arsd.simpleaudio, arsd.vorbis; void main() { AudioOutputThread aot = AudioOutputThread(true); aot.playOgg("myAudio.ogg"); import std.datetime; aot.seek(5.seconds); // or maybe this could be directly in .playOgg } ``` so how would you implement this hypothetical `seek` function? (or if you could tell me a different library that already has this functionality that'd be great too)
Re: How do I get line numbers using pegged?
On Monday, 15 August 2022 at 23:38:09 UTC, Paul Backus wrote: On Monday, 15 August 2022 at 22:55:30 UTC, TheZipCreator wrote: [...] It looks like the parse tree in pegged stores the start and end byte indices of the portion of the input text it corresponds to: https://github.com/PhilippeSigaud/Pegged/blob/v0.4.6/pegged/peg.d#L251-L252 It should be possible to compute line numbers based on these indices. ah, that's what I was looking for, thanks
How do I get line numbers using pegged?
So I've looked at the [pegged library](https://github.com/PhilippeSigaud/Pegged) and used it a little bit and it seems really good. But there doesn't seem like there's a built-in way to get line numbers of nodes in the parse tree (or maybe I'm missing something). This would useful because if an error occurs during interpreting/compiling, you could give the user a line number where their error occurred by just getting the line number of the node that's currently being processed. Is there a way to do this in pegged?
Interfacing with user-supplied binary or obj file
So I'm making an interpreter for my custom scripting language and I want to allow users to write libraries in languages other than said scripting language (for efficiency). For example, you should be able to write a mathematics library in D, compile it, then write a simple wrapper in my language and then be able to import it to your script to use (similar to a lot of Python libraries). So how exactly could I do this without requiring to user to recompile the interpreter every time they want to use a new library? Is there some way I could dynamically link in compiled .obj files?