Skip to content

Instantly share code, notes, and snippets.

@joseoliv joseoliv/Inline.cyan
Last active Jun 14, 2019

Embed
What would you like to do?
inline
package metaobjectTest
@doc{*
Annotation 'inline' should be attached to a final method. It
replaces any message passings to the method by the attached DSL code.
The DSL code may use the parameters, which are re-calculated if
parameter 'once' to the annotation is not used.
All methods of the prototype Inline are final because it is a
final prototype.
*}
object Inline
func run {
var value = threeTimes: 3;
assert value == 9;
value = threeTimes: next;
assert value == 3;
nextValue = 0;
value = threeTimesOnce: 3;
assert value == 9;
nextValue = 0;
// value = 1 + 1 + 1
value = threeTimesOnce: next;
assert value == 3;
}
@inline{* 3*n *}
func threeTimes: Int n -> Int = n;
@inline(once){* n + n + n *}
func threeTimesOnce: Int n -> Int = n;
func next -> Int { ++nextValue; return nextValue; }
var Int nextValue = 0;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.