diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b36cc8..94de5684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,12 @@ All notable changes to this project will be documented in this file. ## ??? - Unreleased +- Add `ffi/jitfn` to allow calling function pointers generated at runtime from machine code. + Bring your own assembler, though. - Channels can now be marshalled. Pending state is not saved, only items in the channel. - Use the new `.length` function pointer on abstract types for lengths. Adding a `length` method will still work as well. -- Support byte views on abstract types with the `bytes` function pointer. +- Support byte views on abstract types with the `.bytes` function pointer. - Add the `u` format specifier to printf family functions. - Allow printing 64 integer types in `printf` and `string/format` family functions. - Allow importing modules from custom directories more easily with the `@` prefix diff --git a/examples/jitfn/jitfn.janet b/examples/jitfn/jitfn.janet index 2c668895..5f786c18 100644 --- a/examples/jitfn/jitfn.janet +++ b/examples/jitfn/jitfn.janet @@ -10,3 +10,4 @@ (def signature (ffi/signature :default :void)) (ffi/call f signature) (print "called a jitted function with FFI!") +(print "machine code: " (describe (string/slice f))) diff --git a/src/core/ffi.c b/src/core/ffi.c index 9794626a..3978154a 100644 --- a/src/core/ffi.c +++ b/src/core/ffi.c @@ -244,10 +244,17 @@ static JanetByteView janet_ffijit_getbytes(void *p, size_t s) { return bytes; } +static size_t janet_ffijit_length(void *p, size_t s) { + (void) s; + JanetFFIJittedFn *fn = p; + return fn->size; +} + const JanetAbstractType janet_type_ffijit = { .name = "ffi/jitfn", .gc = janet_ffijit_gc, - .bytes = janet_ffijit_getbytes + .bytes = janet_ffijit_getbytes, + .length = janet_ffijit_length }; typedef struct {