|
| 1 | +package com.forthix.forthic.annotations; |
| 2 | + |
| 3 | +import java.lang.annotation.ElementType; |
| 4 | +import java.lang.annotation.Retention; |
| 5 | +import java.lang.annotation.RetentionPolicy; |
| 6 | +import java.lang.annotation.Target; |
| 7 | + |
| 8 | +/** |
| 9 | + * Annotation for Forthic word methods. |
| 10 | + * |
| 11 | + * Auto-registers word and handles stack marshalling. |
| 12 | + * Word name defaults to method name, but can be overridden. |
| 13 | + * |
| 14 | + * Example: |
| 15 | + * <pre> |
| 16 | + * {@literal @}Word(stackEffect = "( a:number b:number -- sum:number )", description = "Adds two numbers") |
| 17 | + * public Object ADD(Object a, Object b) { |
| 18 | + * return ((Number)a).doubleValue() + ((Number)b).doubleValue(); |
| 19 | + * } |
| 20 | + * |
| 21 | + * {@literal @}Word(stackEffect = "( rec:any field:any -- value:any )", description = "Get value from record", name = "REC@") |
| 22 | + * public Object REC_at(Object rec, Object field) { |
| 23 | + * // Word name will be "REC@" instead of "REC_at" |
| 24 | + * return ((Map)rec).get(field); |
| 25 | + * } |
| 26 | + * </pre> |
| 27 | + */ |
| 28 | +@Retention(RetentionPolicy.RUNTIME) |
| 29 | +@Target(ElementType.METHOD) |
| 30 | +public @interface Word { |
| 31 | + /** |
| 32 | + * Forthic stack notation (e.g., "( a:any b:any -- sum:number )") |
| 33 | + */ |
| 34 | + String stackEffect(); |
| 35 | + |
| 36 | + /** |
| 37 | + * Human-readable description for documentation |
| 38 | + */ |
| 39 | + String description() default ""; |
| 40 | + |
| 41 | + /** |
| 42 | + * Custom word name (defaults to method name if empty) |
| 43 | + */ |
| 44 | + String name() default ""; |
| 45 | +} |
0 commit comments