Esempio n. 1
0
        private void CreateExternalBindings()
        {
            foreach (AsmEvent evt in _scripts.GetOrderedModules().SelectMany(module => module.GetOrderedEvents()))
            {
                for (int i = 0; i < evt.Count; i++)
                {
                    JsmOperation operation = evt[i];
                    switch (operation.Command)
                    {
                    case JsmCommand.REQ:
                    case JsmCommand.REQEW:
                    case JsmCommand.REQSW:
                    {
                        AsmSegment                source           = evt.Segments.GetSegmentByOffset(i);
                        AsmValueSource            labelTargetEvent = AsmValueSource.Create(evt, i - 1);
                        AsmAbsoluteRequestBinding binding          = new AsmAbsoluteRequestBinding(source, i - source.Offset, operation.Argument, labelTargetEvent);
                        source.OutputBindings.Add(binding);
                        AsmSegment[] targets = binding.ResolveTargets();
                        if (targets != null)
                        {
                            foreach (AsmSegment target in targets)
                            {
                                target.InputBindings.Add(binding);
                            }
                        }
                        break;
                    }

                    case JsmCommand.PREQ:
                    case JsmCommand.PREQEW:
                    case JsmCommand.PREQSW:
                    {
                        AsmSegment                source           = evt.Segments.GetSegmentByOffset(i);
                        AsmValueSource            labelTargetEvent = AsmValueSource.Create(evt, i - 1);
                        AsmRelativeRequestBinding binding          = new AsmRelativeRequestBinding(source, i - source.Offset, operation.Argument, labelTargetEvent);
                        source.OutputBindings.Add(binding);
                        AsmSegment[] targets = binding.ResolveTargets();
                        if (targets != null)
                        {
                            foreach (AsmSegment target in targets)
                            {
                                target.InputBindings.Add(binding);
                            }
                        }
                        break;
                    }
                    }
                }
            }
        }
Esempio n. 2
0
 AsmValueSource IAsmReadableCommandStack.Pop()
 {
     return(AsmValueSource.Create(_script, _offset++));
 }
Esempio n. 3
0
        private void CreateInternalBindings(AsmSegments segments, List <int> jumpFrom, List <int> jumpTo)
        {
            for (int s = 0; s < segments.Count - 1; s++)
            {
                AsmSegment   source = segments[s];
                AsmSegment   target = segments[s + 1];
                JsmOperation last   = source[source.Length - 1];
                if (last.Command == JsmCommand.JPF)
                {
                    AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), true);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
                else if (last.Command != JsmCommand.JMP)
                {
                    AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
            }

            for (int i = 0; i < jumpFrom.Count; i++)
            {
                int fromIndex = jumpFrom[i];
                int toIndex   = jumpTo[i];

                AsmSegment source = segments.GetSegmentByOffset(fromIndex);
                AsmSegment target = segments.GetSegmentByOffset(toIndex);

                JsmOperation last = source[source.Length - 1];
                if (last.Command == JsmCommand.JMP)
                {
                    AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
                else if (last.Command == JsmCommand.JPF)
                {
                    AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), false);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
            }
        }