-
Notifications
You must be signed in to change notification settings - Fork 562
[Cookbook] Adding new Keywords and Operators to Wren
Wren is a hackable language, simple and slim hence you can easily extend it to suit your needs.
For this simple process @CRFriedman wrote:
Creating a token for it in the lexer:
-
Add a TokenType in https://github.com/wren-lang/wren/blob/4d1d0d972efffd072f6a7baa5c37f312258c3955/src/vm/wren_compiler.c#L53-L138
-
Define a precedence for it in https://github.com/wren-lang/wren/blob/4d1d0d972efffd072f6a7baa5c37f312258c3955/src/vm/wren_compiler.c#L1581-L1602
-
Create an operator callback for it in https://github.com/wren-lang/wren/blob/4d1d0d972efffd072f6a7baa5c37f312258c3955/src/vm/wren_compiler.c#L2602-L2678 that emits bytecode for <first_expr> <second_expr> <custom bytecode>.
-
To define new bytecode tweak https://github.com/wren-lang/wren/blob/main/src/vm/wren_opcodes.h and https://github.com/wren-lang/wren/blob/main/src/vm/wren_vm.c.