Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package metaobjectTest
Annotations of this metaobject should be attached to a method.
The attached DSL code is made in Myan, which supports interpreted Cyan
within parameterless methods declared with 'func':
func afti_codeToAdd {
// interpreted Cyan code
According to the method name, the Cyan code is interpreted in phase
afti or dsa. Methods of interfaces
can be implemented. To better understand this, see the documentation
for action_afti_dsa.
object OnOverride_afti_dsa_afsa
func run {
// a compilation warning with a custom error message
self selfTest;
// if uncommented, a regular compilation error
// self alienMethod;
// replace all keyword messages (without a declared method)
// with more than 3 keywords by 0
// Since this annotation is attached to a unary method,
// this method is not really used. Demonstration only.
func dsa_missingKeywordMethod {
let Int size = message getkeywordParameterList size;
if size > 3 {
var aType = env searchPackagePrototype: "cyan.lang", "Int";
return [. "0", aType .];
// an warning message for unary message passings
// ending with 'Test'
// It is necessary to return, in this case, an expression
// that replaces the message passing. Otherwise the
// compiler will issue an error
func dsa_missingUnaryMethod {
var String name = unarySymbol getSymbolString;
if name endsWith: "Test" {
Out println: "Methods ending with 'draw' have not been implemented yet";
return [. "Null nop", "cyan.lang", "Nil" .];
// only prototypes whose names start with 'Sub' can override
// this method. A message is printed, but no error is issued
func afsa_checkOverride {
let String subProtoName = method getDeclaringObject getName;
let String methodName = method getName;
if !(subProtoName startsWith: "Sub") {
Out println: "I am really sorry, but method " ++
methodName ++ " can only be overridden in prototypes whose name " ++
"start with 'Sub'";
func draw {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment