Re: Adding a Builtin to EUPHORIA

new topic     » goto parent     » topic index » view thread      » older message » newer message

Back to BRyan's topic:

BRyan said...

I think that there would be more contributions to Euphoria if some knowledgeable person

would document in "complete detailed" how to add a built-in "euphoria coded" function to the

source code.

This is one of the biggest stumbling blocks for the average user to contribute ideas.

The only documentation for adding to the source is still in a 2.x document which was

included by Rob years ago.

It's true that the documentation hasn't kept completely up with the code, and that's unfortunate. Largely from memory, here's what's required (maybe we can flesh this out and get it into the docs, or at least on the wiki):

  • Add the new name to reswords.e, opnames.e, opnames.h, keylist.e, redef.e, include/euphoria/keywords.e
  • shift.e: add it into op_info, with metadata about the opcode for your built-in
  • Add a new case in emit.e, or add the handling for it to an existing, compatible case (i.e., functions with the same sort of parameters)
  • be_execute.c:
    • add to appropriate place in code_set_pointers()
    • add to localjumptab
    • add case for execution to do_exec(), which may simply be a call to an implementation in be_runtime.c (which translated code could use, as well)
  • compile.e
    • add handler for translating
    • put call to handler in init_opcodes()
  • execute.e
    • add wrapper for execution
    • put call to wrapper in do_exec()
  • dis.e: add handler for your new function (it can probably use one of the generic formatters, unary, punary, binary, pbinary, etc)
  • Add documentation for your new routine in appropriate place (either a related std library file or a separate documentation file)

Adding a keyword or other new language feature requires changes to parsing and possibly scanning, inlining and forward referencing, potentially in addition to all of the above. This is typically more difficult than adding a built-in routine. Machine procs/funcs are a bit simpler.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu