JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

asm

core-api


    cfunction
    src/core/asm.c on line 1071, column 1

    (asm assembly &opt flags)

    Returns a new function that is the compiled result of the assembly. 
    The syntax for the assembly can be found on the Janet website, and 
    should correspond to the return value of disasm. Will throw an 
    error on invalid assembly. Supports a keyword `flags` to control 
    assembly. The only supported flag is `:o`, which will optimize 
    bytecode automatically.


1 exampleSign in to add an example
Loading...
# see https://janet-lang.org/docs/abstract_machine.html

(def plus10
 (asm 
   '{
     :arity 1
     :bytecode @[(ldi 1 10)    # $1 = 10
                 (add 2 0 1)   # $2 = $0 + $1
                 (ret 2)]}))   # return $2

(plus10 1) # -> 11
felixrPlayground