Skip to content

Instantly share code, notes, and snippets.

@joseoliv
joseoliv / afti_dsa_test(MetSig,UMS,Ret).myan
Created Jun 24, 2019
afti_dsa_test(MetSig,UMS,Ret).myan
View afti_dsa_test(MetSig,UMS,Ret).myan
var String funcName;
func afti_beforeMethodCodeList {
return [ [. MetSig, "fp = \"c\";".], [. UMS, "unaryReturn = Ret;" .] ];
}
func afti_codeToAdd {
var java.lang.String ssi = "func succ: Int n -> Int";
var String s = ssi;
View RunFile.cyan
package metaobjectTest
@doc{*
This metaobject works like action_afti_dsa but the
Myan code is read from the file that is the first parameter. So, instead
of putting the Myan code attached to the annotation, it is read from
the file, which may be preceded by a package name. The file should have
extension myan and be in the –-data directory of the package. Usage example:
View Rpn.cyan
package metaobjectTest
@doc{*
Annotation 'rpn' takes an expression in Reverse Polish Notation (RPN)
in the attached DSL and evaluates it at compile-time. The annotation
is an expression of type Int. Only positive integer numbers are allowed
in the RPN expression.
This is a demonstration metaobject.
View SubRestrictOverrideTo.cyan
package main
open
object SubRestrictOverrideTo extends metaobjectTest.RestrictOverrideTo
override
func myprint { }
end
View RestrictOverrideTo.cyan
package metaobjectTest
@doc{*
Annotation 'restrictOverrideTo' should be attached to
a method. Its parameter list is composed of prototype names,
with the package. The annotated method can only be
overridden in those prototypes.
*}
open
object RestrictOverrideTo
View ImplementRestrictImplementation.cyan
package metaobjectTest
object ImplementRestrictImplementation implements RestrictImplementation
func run {
}
override
func myprint { }
@joseoliv
joseoliv / RestrictImplementation
Last active Jun 24, 2019
restrictImplementation
View RestrictImplementation
package metaobjectTest
@doc{*
Annotation 'restrictImplementation' should be attached to
an interface. Its parameter list is composed of prototypes.
The interface can only be implemented by prototypes that
are in the list or its subprototypes.
*}
View RenameMethod.cyan
package metaobjectTest
@doc{*
Annotation 'renameMethod' should be attached to a prototype.
It takes at least two parameters: the first is a method name
and the others are the new selectors for the method. Example:
@renameMethod("at:1 with:2", "myAt:", "myWith:")
This annotation will rename method "at:1 with: 2" to "myAt:1 myWith:2".
Overloaded methods cannot be renamed.
View ReadOnly.cyan
package metaobjectTest
@doc{*
Annotation 'readOnly' should be attached to a method.
It assures that there is no assignment to either
shared or non-shared fields inside the method.
Note that does not guarantee that the method does
not change the receiver fields (self fields). These
can be changed by methods called by the attached method:
View PrototypeCallOnly.cyan
package metaobjectTest
@doc{*
Annotation 'prototypeCallOnly' should be attached to a method.
It assures that the method is only called with a prototype
as receiver. This is a replacement for 'static' methods
of Java/C++/C#. An annotated method cannot access
non-shared fields and it should be final (either
declared with 'final' or the prototype is final).