Skip to content

Instantly share code, notes, and snippets.

Last active August 30, 2022 11:42
Show Gist options
  • Save joseoliv/26272ccc83dac4cee88b464d80f60b94 to your computer and use it in GitHub Desktop.
Save joseoliv/26272ccc83dac4cee88b464d80f60b94 to your computer and use it in GitHub Desktop.
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 afterResTypes_codeToAdd {
// interpreted Cyan code
According to the method name, the Cyan code is interpreted in phase
afterResTypes or semAn. Methods of interfaces
can be implemented. To better understand this, see the documentation
for action_afterResTypes_semAn.
object OnOverride_afterResTypes_semAn_afterSemAn
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 semAn_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 semAn_missingUnaryMethod {
var String name = unarySymbol getSymbolString;
if name endsWith: "Test" {
Out println: "Methods ending with 'draw' have not been implemented yet";
return [. "JavaInterop 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 afterSemAn_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