Created
July 25, 2009 05:21
-
-
Save atsushieno/154708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/mml_macro_expander.cs | |
=================================================================== | |
--- src/mml_macro_expander.cs (revision 85) | |
+++ src/mml_macro_expander.cs (working copy) | |
@@ -82,12 +82,17 @@ | |
void ExpandMacro (MmlSemanticMacro macro) | |
{ | |
+//Console.Write ("Expanding macro {0}, from {1} operation(s)", macro.Name, macro.Data.Count); | |
if (macro.Expanded != null) | |
return; | |
+ macro.Expanded = new List<MmlOperationUse> (); | |
-//Console.Write ("Expanding macro {0}, from {1} operation(s)", macro.Name, macro.Data.Count); | |
+ ExpandMacro (macro.Arguments, macro.Data, macro.Expanded, macro); | |
+ } | |
- foreach (var variable in macro.Arguments) | |
+ internal void ExpandMacro (List<MmlSemanticVariable> args, List<MmlOperationUse> src, List<MmlOperationUse> output, MmlSemanticMacro macro) | |
+ { | |
+ foreach (var variable in args) | |
if (variable.DefaultValue == null) | |
variable.FillDefaultValue (); | |
@@ -95,11 +100,9 @@ | |
throw new MmlException (String.Format ("Illegally recursive macro reference to {0} is found", macro.Name), null); | |
expansion_stack.Push (macro); | |
- macro.Expanded = new List<MmlOperationUse> (); | |
+ ExpandContent (src, output, -1); | |
+//Console.WriteLine (" ... into {0} operation(s)", output.Count); | |
- ExpandContent (macro.Data, macro.Expanded, -1); | |
-//Console.WriteLine (" ... into {0} operation(s)", macro.Expanded.Count); | |
- | |
expansion_stack.Pop (); | |
} | |
Index: src/mml_compiler_main.cs | |
=================================================================== | |
--- src/mml_compiler_main.cs (revision 83) | |
+++ src/mml_compiler_main.cs (working copy) | |
@@ -82,6 +82,7 @@ | |
{ | |
var l = new List<MmlPrimitiveOperation> (); | |
l.Add (new MmlPrimitiveOperation () { Name = "__LET"}); | |
+ l.Add (new MmlPrimitiveOperation () { Name = "__APPLY"}); | |
l.Add (new MmlPrimitiveOperation () { Name = "__CALC"}); | |
l.Add (new MmlPrimitiveOperation () { Name = "__MIDI"}); | |
l.Add (new MmlPrimitiveOperation () { Name = "__MIDI_NOTE"}); | |
Index: src/mml_variable_processor.cs | |
=================================================================== | |
--- src/mml_variable_processor.cs (revision 83) | |
+++ src/mml_variable_processor.cs (working copy) | |
@@ -427,6 +427,15 @@ | |
var argpair = rctx.MacroArguments.LastOrDefault (a => a.Key.Name == aname); | |
rctx.MacroArguments.Remove (argpair); | |
break; | |
+ case "__APPLY": | |
+ var oa = oper.Arguments [0]; | |
+ oa.Resolve (rctx, MmlDataType.String); | |
+ string apparg = oa.StringValue; | |
+ var macro = source.Macros.LastOrDefault (mm => mm.Name == apparg); | |
+ if (macro == null) | |
+ throw new MmlException (String.Format ("Macro {0} was not found used in __APPLY operation", aname), oper.Location); | |
+ ProcessOperations (track, rctx, macro.Expanded, 0, macro.Expanded.Count); | |
+ break; | |
case "__MIDI": | |
oper.ValidateArguments (rctx, oper.Arguments.Count); | |
var mop = new MmlResolvedEvent (pop, rctx.TimelinePosition); | |
Index: default-macro.mml | |
=================================================================== | |
--- default-macro.mml (revision 84) | |
+++ default-macro.mml (working copy) | |
@@ -41,31 +41,6 @@ | |
#variable __current_note_step:number = 0 // temporary (work) variable | |
#variable __current_note_gate:number = 0 // temporary (work) variable | |
-// FIXME: define spectra macros so that we can safely remove "spectra" type. | |
-// FIXME: allow multi-line syntax in the syntax specification so that this can be valid. | |
-// m is macro name | |
-#comment | |
-#macro SPECTRA_SQUARE m:string,id:number,sv:number,ev:number, \ | |
- sd:number,ed:number,ts:number,es:number,delta:number,rt:number { \ | |
- __LET {"__work_step_start", $__timeline_position} \ | |
- __LET {"__timeline_position", $__timeline_position + $sd} \ | |
- __APPLY {$m, $sv} \ | |
- [ \ | |
- [ \ | |
- __LET {"__timeline_position", $__timeline_position + $es} \ | |
- __APPLY {$m, $delta} \ | |
- ] $ts / $es \ | |
- [ \ | |
- __LET {"__timeline_position", $__timeline_position + $es} \ | |
- __APPLY {$m, -$delta} \ | |
- ] $ts / $es \ | |
- ] $rt \ | |
- __LET {"__timeline_position", $__timeline_position + $ed} \ | |
- __APPLY {$m, $ev} \ | |
- __LET {"__timeline_position", $__work_step_start} \ | |
- } | |
-#endcomment | |
- | |
// Primitive MIDI operations | |
// NON (8n), NOFF (9n), PAF (An), CC (Bn), PROGRAM (Cn), CAF (Dn), PITCH (En), EX (F0,F7), META (FF) | |
@@ -203,3 +178,31 @@ | |
// (it should be allowewd because / is not a primitive operation but an operator for | |
// mul_div_expr.) | |
#macro ] repeat:number { __LOOP_END{$repeat} } | |
+ | |
+// ---- SPECTRA ---- | |
+#variable __work_step_start:number = 0 | |
+// FIXME: define spectra macros so that we can safely remove "spectra" type. | |
+#alias SPECTRA_ARG_DEF id:number, sv:number, ev:number, sd:number, ed:number, ts:number, es:number, delta:number, rt:number | |
+#alias SPECTRA_ARG_USE $id, $sv, $ev, $sd:, $ed, $ts, $es, $delta, $rt | |
+// m is macro name | |
+#macro SPECTRA_SQUARE m:string, SPECTRA_ARG_DEF { \ | |
+ __LET {"__work_step_start", $__timeline_position} \ | |
+ __LET {"__timeline_position", $__timeline_position + $sd} \ | |
+ __APPLY {$m, $sv} \ | |
+ [ \ | |
+ [ \ | |
+ __LET {"__timeline_position", $__timeline_position + $es} \ | |
+ __APPLY {$m, $delta} \ | |
+ ] $ts / $es \ | |
+ [ \ | |
+ __LET {"__timeline_position", $__timeline_position + $es} \ | |
+ __APPLY {$m, -$delta} \ | |
+ ] $ts / $es \ | |
+ ] $rt \ | |
+ __LET {"__timeline_position", $__timeline_position + $ed} \ | |
+ __APPLY {$m, $ev} \ | |
+ __LET {"__timeline_position", $__work_step_start} \ | |
+ } | |
+ | |
+#macro P_ SPECTRA_ARG_DEF { SPECTRA_SQUARE "P", SPECTRA_ARG_USE } | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment