Explorar o código

Shorter folder names. Got rid of outdated CSharp stuff.

Joeri Exelmans %!s(int64=6) %!d(string=hai) anos
pai
achega
1fea8fbf0d
Modificáronse 52 ficheiros con 3 adicións e 1304 borrados
  1. 0 77
      src/csharp_sccd_runtime/Association.cs
  2. 0 23
      src/csharp_sccd_runtime/AssociationException.cs
  3. 0 22
      src/csharp_sccd_runtime/AssociationReferenceException.cs
  4. 0 12
      src/csharp_sccd_runtime/AssociationWrapper.cs
  5. 0 38
      src/csharp_sccd_runtime/ConcurrentOutputListener.cs
  6. 0 89
      src/csharp_sccd_runtime/ControllerBase.cs
  7. 0 41
      src/csharp_sccd_runtime/Event.cs
  8. 0 105
      src/csharp_sccd_runtime/EventQueue.cs
  9. 0 22
      src/csharp_sccd_runtime/GameControllerBase.cs
  10. 0 11
      src/csharp_sccd_runtime/IOutputListener.cs
  11. 0 23
      src/csharp_sccd_runtime/InputException.cs
  12. 0 34
      src/csharp_sccd_runtime/InstanceWrapper.cs
  13. 0 12
      src/csharp_sccd_runtime/MyClass.cs
  14. 0 253
      src/csharp_sccd_runtime/ObjectManagerBase.cs
  15. 0 34
      src/csharp_sccd_runtime/OutputListener.cs
  16. 0 22
      src/csharp_sccd_runtime/ParameterException.cs
  17. 0 27
      src/csharp_sccd_runtime/Properties/AssemblyInfo.cs
  18. 0 22
      src/csharp_sccd_runtime/RunTimeException.cs
  19. 0 95
      src/csharp_sccd_runtime/RuntimeClassBase.cs
  20. 0 146
      src/csharp_sccd_runtime/ThreadsControllerBase.cs
  21. 0 55
      src/csharp_sccd_runtime/sccdlib.csproj
  22. 0 50
      src/csharp_sccd_runtime/sccdlib.sln
  23. 0 0
      src/python_sccd/compiler/__init__.py
  24. 0 0
      src/python_sccd/compiler/compiler_exceptions.py
  25. 0 0
      src/python_sccd/compiler/generic_generator.py
  26. 0 0
      src/python_sccd/compiler/generic_language_constructs.py
  27. 0 0
      src/python_sccd/compiler/javascript_writer.py
  28. 0 0
      src/python_sccd/compiler/lexer.py
  29. 0 0
      src/python_sccd/compiler/path_calculator.py
  30. 0 0
      src/python_sccd/compiler/python_writer.py
  31. 0 0
      src/python_sccd/compiler/sccd_constructs.py
  32. 0 0
      src/python_sccd/compiler/sccdc.py
  33. 0 0
      src/python_sccd/compiler/state_linker.py
  34. 0 0
      src/python_sccd/compiler/stateful_writer.py
  35. 0 0
      src/python_sccd/compiler/super_class_linker.py
  36. 0 0
      src/python_sccd/compiler/utils.py
  37. 0 0
      src/python_sccd/compiler/visitor.py
  38. 0 0
      src/python_sccd/runtime/__init__.py
  39. 0 0
      src/python_sccd/runtime/accurate_time.py
  40. 0 0
      src/python_sccd/runtime/event_queue.py
  41. 0 0
      src/python_sccd/runtime/infinity.py
  42. 0 0
      src/python_sccd/runtime/libs/__init__.py
  43. 0 0
      src/python_sccd/runtime/libs/drawing.py
  44. 0 0
      src/python_sccd/runtime/libs/ordered_set.py
  45. 0 0
      src/python_sccd/runtime/libs/ui.py
  46. 0 0
      src/python_sccd/runtime/libs/utils.py
  47. 0 0
      src/python_sccd/runtime/socket2event.py
  48. 0 0
      src/python_sccd/runtime/statecharts_core.py
  49. 0 0
      src/python_sccd/runtime/tkinter_eventloop.py
  50. 1 1
      src/setup.py
  51. 2 2
      test/Makefile
  52. 0 88
      test/run_tests.py

+ 0 - 77
src/csharp_sccd_runtime/Association.cs

@@ -1,77 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-
-namespace sccdlib
-{
-    /**
-     * wrapper object for one association relation
-     */
-    public class Association
-    {
-        string name;
-        string class_name;
-        int min_card;
-        int max_card;
-        List<InstanceWrapper> instances;
-        
-        public Association (string name, string class_name, int min_card, int max_card)
-        {
-            this.min_card = min_card;
-            this.max_card = max_card;
-            this.name = name;
-            this.class_name = class_name;
-            this.instances = new List<InstanceWrapper>();
-        }
-        
-        public string getName ()
-        {
-            return this.name;
-        }
-        
-        public string getClassName ()
-        {
-            return this.class_name;   
-        }
-        
-        public bool allowedToAdd ()
-        {
-            return ( (this.max_card == -1) || ( this.instances.Count < this.max_card ) );    
-        }
-        
-        public void addInstance (InstanceWrapper instance)
-        {
-            if (this.allowedToAdd ()) {
-                this.instances.Add (instance);
-            } else {
-                throw new AssociationException("Not allowed to add the instance to the association.");
-            }
-        }
-        
-        public ReadOnlyCollection<InstanceWrapper> getAllInstances ()
-        {
-            return this.instances.AsReadOnly();   
-        }
-        
-        /*
-        public List<InstanceWrapper> getAllInstances ()
-        {
-            return new List<InstanceWrapper>(this.instances);
-        }*/
-        
-        public InstanceWrapper getInstance(int index)
-        {
-            try 
-            {
-                return this.instances[index];
-            }
-            catch (ArgumentOutOfRangeException)
-            {
-                throw new AssociationException("Invalid index for fetching instance from association.");
-            }
-        }
-        
-    }
-}
-

+ 0 - 23
src/csharp_sccd_runtime/AssociationException.cs

@@ -1,23 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class AssociationException : RunTimeException
-    {
-        public AssociationException ()
-        {
-        }
-        
-        public AssociationException(string message)
-            : base(message)
-        {
-        }
-    
-        public AssociationException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-    }
-  
-}
-

+ 0 - 22
src/csharp_sccd_runtime/AssociationReferenceException.cs

@@ -1,22 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class AssociationReferenceException : RunTimeException
-    {
-        public AssociationReferenceException ()
-        {
-        }
-        
-        public AssociationReferenceException(string message)
-            : base(message)
-        {
-        }
-    
-        public AssociationReferenceException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-    }
-}
-

+ 0 - 12
src/csharp_sccd_runtime/AssociationWrapper.cs

@@ -1,12 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class AssociationWrapper
-    {
-        public AssociationWrapper ()
-        {
-        }
-    }
-}
-

+ 0 - 38
src/csharp_sccd_runtime/ConcurrentOutputListener.cs

@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class ConcurrentOutputListener : IOutputListener
-    {
-        ConcurrentQueue<Event> queue = new ConcurrentQueue<Event>();
-        List<string> ports = new List<string>();
-        
-        public ConcurrentOutputListener (string[] port_names)
-        {
-            foreach (string port_name in port_names)
-            {
-                this.ports.Add (port_name);
-            }
-        }
-        
-        public void add (Event output_event)
-        {
-            if (this.ports.Count == 0 || this.ports.Contains (output_event.getPort ())) {
-                this.queue.Enqueue (output_event);
-            }
-        }
-                
-        public Event fetch ()
-        {
-            Event fetched_event;
-            bool success = this.queue.TryDequeue (out fetched_event);
-            if (success) {
-                return fetched_event;
-            }
-            return null;
-        }
-    }
-}
-

+ 0 - 89
src/csharp_sccd_runtime/ControllerBase.cs

@@ -1,89 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public abstract class ControllerBase
-    {
-        protected ObjectManagerBase object_manager;
-        protected bool done = false;
-        protected List<string> input_ports = new List<string>();
-        protected EventQueue input_queue = new EventQueue();
-
-        protected List<string> output_ports = new List<string>();
-        protected List<IOutputListener> output_listeners = new List<IOutputListener>();
-
-        public ControllerBase ()
-        {
-        }
-
-        protected void addInputPort(string port_name)
-        {
-            this.input_ports.Add(port_name);
-        }
-        
-        protected void addOutputPort(string port_name)
-        {
-            this.output_ports.Add(port_name);
-        }
-
-        public void broadcast(Event new_event)
-        {
-            this.object_manager.broadcast(new_event);
-        }
-        
-        public virtual void start()
-        {
-            this.object_manager.start();
-        }
-    
-        public virtual void stop()
-        {
-        }
-
-        public void outputEvent(Event output_event)
-        {
-            foreach (IOutputListener listener in this.output_listeners)
-            {
-                listener.add(output_event);
-            }
-        }
-        
-        public IOutputListener addOutputListener(string[] ports)
-        {
-            IOutputListener listener = this.createOutputListener(ports);
-            this.output_listeners.Add(listener);
-            return listener;
-        }
-        
-        protected virtual IOutputListener createOutputListener (string[] ports)
-        {
-            return new OutputListener(ports);   
-        }
-        
-        public virtual void addInput(Event input_event, double time_offset = 0.0)
-        {   
-            if ( input_event.getName() == "" )
-                throw new InputException("Input event can't have an empty name.");
-            
-            if ( !this.input_ports.Contains (input_event.getPort()) )
-                throw new InputException("Input port mismatch.");
-            
-            this.input_queue.Add(input_event, time_offset);
-        }
-    
-        public virtual void addEventList(List<Tuple<Event,double>> event_list)
-        {
-            foreach (Tuple<Event,double> event_tuple in event_list)
-            {   
-                this.addInput (event_tuple.Item1, event_tuple.Item2);
-            }
-        }
-        
-        public ObjectManagerBase getObjectManager ()
-        {
-            return this.object_manager;
-        }
-    }
-}
-

+ 0 - 41
src/csharp_sccd_runtime/Event.cs

@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class Event
-    {
-        string name = "";
-        string port = "";
-        object[] parameters;
-        
-
-        public Event (string name = "", string port = "", object[] parameters = null)
-        {
-            this.name = name;
-            this.port = port;
-            this.parameters = (parameters == null ? new object[] {} : parameters);
-        }
-
-        public string getName ()
-        {
-            return this.name;
-        }
-
-        public string getPort ()
-        {
-            return this.port;
-        }
-        
-        public object[] getParameters ()
-        {
-            return this.parameters;
-        }
-        
-        public override string ToString()
-        {
-            return string.Format("(event name : {0}; port : {1}; parameters : [{2}])", this.name, this.port, string.Join(", ", this.parameters));
-        }
-    }
-}
-

+ 0 - 105
src/csharp_sccd_runtime/EventQueue.cs

@@ -1,105 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    /// <summary>
-    /// Abstracting the event Queue. Currently uses a List to store it's content, but could have better performance when built on a priority queue.
-    /// </summary>
-    public class EventQueue
-    {
-        private class EventQueueEntry
-        {
-            double time_offset;
-            Event e;
-            
-            public EventQueueEntry(Event e, double time_offset)
-            {
-                this.e = e;
-                this.time_offset = time_offset;
-            }
-            
-            public void decreaseTime(double offset)
-            {
-                this.time_offset -= offset;   
-            }
-            
-            public Event getEvent()
-            {
-                return this.e;
-            }
-            
-            public double getTime ()
-            {
-                return this.time_offset;
-            }
-            
-        }
-
-        List<EventQueueEntry> event_list = new List<EventQueueEntry>();
-                
-        public void Add (Event e, double time_offset)
-        {
-            EventQueueEntry entry = new EventQueueEntry(e,time_offset);
-            //We maintain a sorted stable list
-            int insert_index = 0;
-            for (int index = this.event_list.Count-1; index >= 0; index--)
-            {
-                if (this.event_list[index].getTime() <= time_offset)
-                {
-                    insert_index = index + 1;
-                    break;
-                }
-            }
-            this.event_list.Insert(insert_index, entry);
-        }
-
-        public void decreaseTime(double offset)
-        {
-            foreach (EventQueueEntry e in this.event_list)
-                e.decreaseTime(offset);
-        }
-        
-        public bool isEmpty()
-        {
-            return this.event_list.Count == 0;
-        }
-        
-        
-        /// <summary>
-        /// Gets the earliest time.
-        /// </summary>
-        /// <returns>
-        /// The earliest time. Positive infinity if no events are present.
-        /// </returns>
-        public double getEarliestTime ()
-        {
-            if (this.isEmpty())
-            {
-                return double.PositiveInfinity;
-            }
-            else
-            {
-                return this.event_list[0].getTime();
-            }
-        }
-
-        public List<Event> popDueEvents ()
-        {
-            List<Event> result = new List<Event> ();
-            if (this.isEmpty() || this.event_list[0].getTime() > 0.0)
-                //There are no events, or the earliest event isn't due, so we can already return an emtpy result
-                return result;
-
-            int index = 0;
-            while (index < this.event_list.Count && this.event_list[index].getTime() <= 0.0)
-            {
-                result.Add(this.event_list[index].getEvent()); //Add all events that are due (offset less than 0) to the result
-                index++;
-            }
-            this.event_list.RemoveRange(0, result.Count);
-            return result;
-        }
-    }
-}
-

+ 0 - 22
src/csharp_sccd_runtime/GameControllerBase.cs

@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class GameControllerBase : ControllerBase
-    {
-        public GameControllerBase ()
-            : base()
-        {        
-        }
-        
-        public void update(double delta)
-        {  
-            this.input_queue.decreaseTime(delta);
-            foreach(Event e in this.input_queue.popDueEvents())
-                this.broadcast (e);
-            this.object_manager.stepAll(delta);
-        }
-    }
-}
-

+ 0 - 11
src/csharp_sccd_runtime/IOutputListener.cs

@@ -1,11 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public interface IOutputListener
-    {
-        void add (Event output_event);
-        Event fetch ();
-    }
-}
-

+ 0 - 23
src/csharp_sccd_runtime/InputException.cs

@@ -1,23 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class InputException : RunTimeException
-    {
-        public InputException ()
-        {
-        }
-        
-        public InputException(string message)
-            : base(message)
-        {
-        }
-    
-        public InputException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-    }
-  
-}
-

+ 0 - 34
src/csharp_sccd_runtime/InstanceWrapper.cs

@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class InstanceWrapper
-    {
-        RuntimeClassBase instance;
-        Dictionary<string,Association> associations = new Dictionary<string, Association>();
-        
-        
-        public InstanceWrapper (RuntimeClassBase instance, List<Association> associations)
-        {
-            this.instance = instance;
-            foreach (var association in associations) {
-                this.associations[association.getName()] = association;   
-            }
-        }
-        
-        public Association getAssociation (string name)
-        {
-            try{
-                return this.associations[name];
-            }catch (KeyNotFoundException) {
-                throw new AssociationReferenceException("Unknown association.");
-            }
-        }
-        
-        public RuntimeClassBase getInstance ()
-        {
-            return this.instance;
-        }
-    }
-}

+ 0 - 12
src/csharp_sccd_runtime/MyClass.cs

@@ -1,12 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-	public class MyClass
-	{
-		public MyClass ()
-		{
-		}
-	}
-}
-

+ 0 - 253
src/csharp_sccd_runtime/ObjectManagerBase.cs

@@ -1,253 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-namespace sccdlib
-{
-    public abstract class ObjectManagerBase
-    {
-        protected ControllerBase controller;
-        EventQueue events = new EventQueue();
-        Dictionary<RuntimeClassBase,InstanceWrapper> instances_map = new Dictionary<RuntimeClassBase,InstanceWrapper> ();
-        
-        public ObjectManagerBase (ControllerBase controller)
-        {
-            this.controller = controller;
-        }
-       
-        
-        public void addEvent (Event input_event, double time_offset = 0.0)
-        {
-            this.events.Add (input_event, time_offset);
-        }
-        
-        public void broadcast (Event new_event)
-        {
-            foreach (RuntimeClassBase instance in this.instances_map.Keys)
-                instance.addEvent(new_event);
-        }
-        
-        public  double getWaitTime()
-        {
-            //first get waiting time of the object manager's events
-            double smallest_time = this.events.getEarliestTime();
-            //check all the instances
-            foreach (RuntimeClassBase instance in this.instances_map.Keys)
-                smallest_time = Math.Min(smallest_time, instance.getEarliestEventTime());
-            return smallest_time;
-        }
-        
-        public void step (double delta)
-        {
-            this.events.decreaseTime(delta);
-            foreach( Event e in this.events.popDueEvents())
-                this.handleEvent (e);
-        }
-        
-        private void handleEvent (Event handle_event)
-        {
-            string event_name = handle_event.getName ();
-            if (event_name == "narrow_cast") {
-                this.handleNarrowCastEvent(handle_event.getParameters());
-            } else if (event_name == "broad_cast") {
-                this.handleBroadCastEvent(handle_event.getParameters());
-            } else if (event_name == "create_instance") {
-                this.handleCreateEvent(handle_event.getParameters());
-            } else if (event_name == "associate_instance") {
-                this.handleAssociateEvent(handle_event.getParameters());
-            } else if (event_name == "start_instance") {
-                this.handleStartInstanceEvent(handle_event.getParameters());
-            }
-        }
-        
-        public void stepAll (double delta)
-        {
-            this.step(delta);
-            foreach (RuntimeClassBase instance in this.instances_map.Keys)
-                instance.step(delta);
-        }
-    
-        
-        public void start ()
-        {
-            foreach (RuntimeClassBase instance in this.instances_map.Keys)
-                instance.start(); 
-        }
-        
-        /// <summary>
-        /// Processes the association reference.
-        /// </summary>
-        /// <returns>
-        /// The association reference.
-        /// </returns>
-        /// <param name='input_string'>
-        /// Input_string.
-        /// </param>
-        private List<Tuple<string, int>> processAssociationReference (string input_string)
-        {
-            if (input_string.Length == 0)
-                throw new AssociationReferenceException("Empty association reference.");
-            string[] path_string = input_string.Split (new char[] {'/'});
-            Regex regex = new Regex(@"^([a-zA-Z_]\w*)(?:\[(\d+)\])?$");
-            
-            var result = new List<Tuple<string, int>>();
-            
-            foreach (string string_piece in path_string) {
-                Match match = regex.Match (string_piece);
-                if (match.Success ){
-                    string name = match.Groups[1].ToString ();
-                    int index;
-                    if (match.Groups[2].Success)
-                        int.TryParse(match.Groups[2].ToString(), out index);
-                    else
-                        index = -1;
-                    result.Add( new Tuple<string, int>(name,index));
-                }else{
-                    throw new AssociationReferenceException("Invalid entry in association reference.");
-                }   
-            }
-            return result;
-        }
-        
-        /// <summary>
-        /// Gets the instances.
-        /// </summary>
-        /// <returns>
-        /// The instances.
-        /// </returns>
-        /// <param name='source'>
-        /// Source.
-        /// </param>
-        /// <param name='traversal_list'>
-        /// Traversal_list.
-        /// </param>
-        private List<InstanceWrapper> getInstances (RuntimeClassBase source, List<Tuple<string, int>> traversal_list)
-        {
-            var currents = new List<InstanceWrapper> ();
-            currents.Add (this.instances_map [source]);
-            foreach (Tuple<string, int> tuple in traversal_list) {
-                var nexts = new List<InstanceWrapper> ();
-                foreach ( InstanceWrapper current in currents ){
-                    Association association = current.getAssociation (tuple.Item1);   
-                    if (tuple.Item2 >= 0 )
-                        nexts.Add ( association.getInstance(tuple.Item2) );
-                    else if (tuple.Item2 == -1)
-                        nexts.AddRange ( association.getAllInstances() );
-                    else
-                        throw new AssociationReferenceException("Incorrect index in association reference.");
-                }
-                currents = nexts;
-            }
-            return currents;
-        }
-        
-        /// <summary>
-        /// Handles the start instance event.
-        /// </summary>
-        /// <param name='parameters'>
-        /// [0] The instance the event originates from.
-        /// [1] An association reference string targeting the instance to start.
-        /// </param>
-        private void handleStartInstanceEvent (object[] parameters)
-        {
-            if (parameters.Length != 2) {
-                throw new ParameterException ("The start instance event needs 2 parameters.");    
-            } else {
-                RuntimeClassBase source = (RuntimeClassBase) parameters[0];
-                var traversal_list = this.processAssociationReference((string) parameters [1]);
-                
-                foreach( InstanceWrapper i in this.getInstances (source, traversal_list)){
-                    i.getInstance().start();
-                }
-            }
-        }
-        
-        /// <summary>
-        /// Handles the broad cast event.
-        /// </summary>
-        /// <param name='parameters'>
-        /// [0] The event to be broadcasted.
-        /// </param>
-        private void handleBroadCastEvent(object[] parameters)
-        {
-            if (parameters.Length != 1 ) 
-                throw new ParameterException ("The broadcast event needs 1 parameter.");   
-            this.broadcast((Event)parameters[0]); 
-        }
-
-        private void handleCreateEvent (object[] parameters)
-        {
-            if (parameters.Length < 2) {
-                throw new ParameterException ("The create event needs at least 2 parameters.");   
-            } else {
-                RuntimeClassBase source = (RuntimeClassBase)parameters [0];
-                string association_name = (string)parameters [1];
-                Association association = this.instances_map[source].getAssociation (association_name);
-                if (association.allowedToAdd ()){
-                    int constructor_parameters_length = parameters.Length -2;
-                    object[] constructor_parameters = new object[constructor_parameters_length];
-                    Array.Copy(parameters, 2, constructor_parameters, 0, constructor_parameters_length);
-                    InstanceWrapper new_instance_wrapper = this.createInstance(association.getClassName (), constructor_parameters);
-                    association.addInstance (new_instance_wrapper);
-                    source.addEvent(
-                        new Event(name: "instance_created", parameters : new object[] {association_name})
-                    );
-                }else{
-                    source.addEvent (
-                        new Event(name: "instance_creation_error", parameters : new object[] {association_name})    
-                    );
-                }    
-            }
-        }
-        
-                
-        private void handleAssociateEvent (object[] parameters)
-        {
-            if (parameters.Length != 3) {
-                throw new ParameterException ("The associate_instance event needs 3 parameters.");
-            } else {
-                RuntimeClassBase source = (RuntimeClassBase)parameters [0];
-                List<InstanceWrapper> to_copy_list = this.getInstances (source, this.processAssociationReference ((string)parameters [1]));
-                if (to_copy_list.Count != 1)
-                    throw new AssociationReferenceException ("Invalid source association reference.");
-                InstanceWrapper wrapped_to_copy_instance = to_copy_list [0];
-                List<Tuple<string,int>> dest_list = this.processAssociationReference ((string)parameters [2]);
-                if (dest_list.Count == 0)
-                    throw new AssociationReferenceException ("Invalid destination association reference.");
-                Tuple<string,int> last_tuple = dest_list [dest_list.Count - 1];
-                if (last_tuple.Item2 != -1)
-                    throw new AssociationReferenceException ("Last association name in association reference should not be accompanied by an index.");
-                dest_list.RemoveAt (dest_list.Count - 1);
-                foreach (InstanceWrapper i in this.getInstances(source, dest_list)) {
-                    i.getAssociation (last_tuple.Item1).addInstance (wrapped_to_copy_instance);
-                }
-            }
-        }
-            
-        private void handleNarrowCastEvent(object[] parameters)
-        {
-            if (parameters.Length != 3){
-                throw new ParameterException ("The associate_instance event needs 3 parameters.");
-            }else{
-                RuntimeClassBase source = (RuntimeClassBase)parameters [0];
-                Event cast_event = (Event) parameters[2];
-                foreach (InstanceWrapper i in this.getInstances(source, this.processAssociationReference( (string) parameters[1])))
-                    i.getInstance ().addEvent(cast_event);
-            
-            }
-        }   
-        
-        
-        protected abstract InstanceWrapper instantiate(string class_name, object[] construct_params);
-
-            
-        public InstanceWrapper createInstance(string class_name, object[] construct_params)
-        {
-            InstanceWrapper iw = this.instantiate(class_name, construct_params);
-            if (iw != null)
-                this.instances_map[iw.getInstance ()] = iw;
-            return iw;
-        }
-    }
-}
-

+ 0 - 34
src/csharp_sccd_runtime/OutputListener.cs

@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class OutputListener : IOutputListener
-    {
-        Queue<Event> queue = new Queue<Event>();
-        List<string> ports = new List<string>();
-        
-        public OutputListener (string[] port_names)
-        {
-            foreach (string port_name in port_names)
-            {
-                this.ports.Add (port_name);
-            }
-        }
-        
-        public void add (Event output_event)
-        {
-            if (this.ports.Count == 0 || this.ports.Contains (output_event.getPort ())) {
-                this.queue.Enqueue (output_event);
-            }
-        }
-                
-        public Event fetch ()
-        {
-            if (this.queue.Count > 0)
-                return this.queue.Dequeue ();
-            return null;
-        }
-    }
-}
-

+ 0 - 22
src/csharp_sccd_runtime/ParameterException.cs

@@ -1,22 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class ParameterException : RunTimeException
-    {
-        public ParameterException ()
-        {
-        }      
-                
-        public ParameterException(string message)
-            : base(message)
-        {
-        }
-    
-        public ParameterException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-    }
-}
-

+ 0 - 27
src/csharp_sccd_runtime/Properties/AssemblyInfo.cs

@@ -1,27 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-// Information about this assembly is defined by the following attributes. 
-// Change them to the values specific to your project.
-
-[assembly: AssemblyTitle("csharp_runtime")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("gl3nn")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
-// The form "{Major}.{Minor}.*" will automatically update the build and revision,
-// and "{Major}.{Minor}.{Build}.*" will update just the revision.
-
-[assembly: AssemblyVersion("1.0.*")]
-
-// The following attributes are used to specify the signing key for the assembly, 
-// if desired. See the Mono documentation for more information about signing.
-
-//[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile("")]
-

+ 0 - 22
src/csharp_sccd_runtime/RunTimeException.cs

@@ -1,22 +0,0 @@
-using System;
-
-namespace sccdlib
-{
-    public class RunTimeException : Exception
-    {
-        public RunTimeException ()
-        {
-        }
-        
-        public RunTimeException(string message)
-            : base(message)
-        {
-        }
-    
-        public RunTimeException(string message, Exception inner)
-            : base(message, inner)
-        {
-        }
-    }
-}
-

+ 0 - 95
src/csharp_sccd_runtime/RuntimeClassBase.cs

@@ -1,95 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public abstract class RuntimeClassBase
-    {
-
-        protected bool active = false;
-        protected bool state_changed = false;
-        protected EventQueue events = new EventQueue();
-        protected ControllerBase controller;
-        protected ObjectManagerBase object_manager;
-        protected Dictionary<int,double> timers = null;
-
-        public RuntimeClassBase ()
-        {
-        }
-        
-        public void addEvent (Event input_event, double time_offset = 0.0)
-        {
-            this.events.Add (input_event, time_offset);
-        }
-        
-        
-        public double getEarliestEventTime ()
-        {
-            if (this.timers != null)
-            {
-                double smallest_timer_value = double.PositiveInfinity;
-                foreach (double timer_value in this.timers.Values)
-                {
-                    if (timer_value < smallest_timer_value)
-                        smallest_timer_value = timer_value;
-                }
-                return Math.Min(this.events.getEarliestTime(), smallest_timer_value); 
-            }
-            return this.events.getEarliestTime();   
-        }
-
-        /// <summary>
-        /// Execute statechart
-        /// </summary>
-        /// <param name='delta'>
-        /// Time passed since last step.
-        /// </param>
-        public void step(double delta)
-        {
-            if (!this.active)
-                return;
-
-            this.events.decreaseTime(delta);
-
-            if (this.timers != null && this.timers.Count > 0)
-            {
-                var next_timers = new Dictionary<int,double>();
-                foreach(KeyValuePair<int,double> pair in this.timers)
-                {
-                    double new_time = pair.Value - delta;
-                    if (new_time <= 0.0)
-                        this.addEvent (new Event("_" + pair.Key + "after"), new_time);
-                    else
-                        next_timers[pair.Key] = new_time;
-                }
-                this.timers = next_timers;
-            }
-
-            this.microstep();
-            while (this.state_changed)
-                this.microstep();
-        }
-        
-        private void microstep ()
-        {
-            List<Event> due = this.events.popDueEvents();
-            if (due.Count == 0) {
-                this.transition ();   
-            } else {
-                foreach (Event e in due)
-                {
-                    this.transition(e);
-                }
-            }
-        }
-        
-        protected abstract void transition (Event e = null);
-        
-        public virtual void start ()
-        {
-            this.active = true;
-        }
-        
-    }
-}
-

+ 0 - 146
src/csharp_sccd_runtime/ThreadsControllerBase.cs

@@ -1,146 +0,0 @@
-using System;
-using System.Threading;
-using System.Collections.Generic;
-
-namespace sccdlib
-{
-    public class ThreadsControllerBase : ControllerBase
-    {
-        bool stop_thread = false;
-        bool keep_running;
-        Thread thread = null;
-        Mutex input_mutex = new Mutex(false);
-        Mutex stop_thread_mutex = new Mutex(false);
-        AutoResetEvent wait_handle = new AutoResetEvent(false);
-        DateTime last_recorded_time = DateTime.UtcNow;
-        
-        public ThreadsControllerBase (bool keep_running = true)
-            : base()
-        {          
-            this.keep_running = keep_running;
-            this.thread = new Thread (new ThreadStart (this.run));
-        }
-        
-        private void handleInput(double delta)
-        {
-            this.input_mutex.WaitOne(-1);
-            this.input_queue.decreaseTime(delta);
-            foreach(Event e in this.input_queue.popDueEvents())
-                this.broadcast (e);
-            this.input_mutex.ReleaseMutex();
-        }
-        
-        public override void start()
-        {
-            this.thread.Start ();
-        }
-    
-        public override void stop()
-        {
-            this.stop_thread_mutex.WaitOne(-1);
-            this.stop_thread = true;
-            this.stop_thread_mutex.ReleaseMutex ();
-            this.wait_handle.Set();
-        }
-        
-        
-        private double getWaitTime ()
-        {
-            this.input_mutex.WaitOne (-1);
-            double wait_time = Math.Min (this.object_manager.getWaitTime (), this.input_queue.getEarliestTime ());
-            this.input_mutex.ReleaseMutex ();
-    
-            if (double.IsPositiveInfinity (wait_time)) {
-                if (this.done) {
-                    this.done = false;
-                } else {
-                    this.done = true;
-                    return 0.0;
-                }
-            }
-            return wait_time;
-        }
-    
-        private void handleWaiting ()
-        {
-            double wait_time = this.getWaitTime ();
-            if (wait_time <= 0.0)
-                return;
-            if (double.IsPositiveInfinity(wait_time))
-            {
-                if (this.keep_running)
-                {
-                    this.wait_handle.WaitOne(-1); //Wait until signal
-                }
-                else
-                {
-                    this.stop_thread_mutex.WaitOne(-1);
-                    this.stop_thread = true;
-                    this.stop_thread_mutex.ReleaseMutex();
-                }
-            }
-            else if (wait_time != 0.0)
-            {
-                //Calculate how much wait time is left.
-                double actual_wait_time = (wait_time - DateTime.UtcNow.Subtract(this.last_recorded_time).TotalSeconds); //In seconds and double
-                if (actual_wait_time > 0.0)
-                {
-                    this.wait_handle.Reset();
-                    this.wait_handle.WaitOne((int)Math.Ceiling(actual_wait_time * 1000)); //Convert to seconds and int round up
-                }
-            }
-        }
-    
-        private void run()
-        {
-            this.last_recorded_time = DateTime.UtcNow;
-            base.start ();
-            DateTime previous_recorded_time;
-            double last_iteration_time = 0.0;
-
-            while (true)
-            {
-                this.handleInput(last_iteration_time);
-                //Compute the new state based on internal events
-                this.object_manager.stepAll(last_iteration_time);
-
-                this.handleWaiting();
-                
-                this.stop_thread_mutex.WaitOne (-1);
-                if (this.stop_thread) 
-                    break;
-                this.stop_thread_mutex.ReleaseMutex ();
-                
-                previous_recorded_time = this.last_recorded_time;
-                this.last_recorded_time = DateTime.UtcNow;
-                last_iteration_time = this.last_recorded_time.Subtract(previous_recorded_time).TotalSeconds;
-            }
-        }
-    
-        public void join()
-        {
-            this.thread.Join ();
-        }
-    
-        public override void addInput(Event input_event, double time_offset = 0.0)
-        {
-            this.input_mutex.WaitOne (-1);
-            base.addInput (input_event, time_offset); //TODO Add time to offset that has already passed, so that next subtraction evens it out? Also Gameloop then!
-            this.input_mutex.ReleaseMutex ();
-            this.wait_handle.Set();
-        }
-    
-        public override void addEventList(List<Tuple<Event,double>> event_list)
-        {
-            this.input_mutex.WaitOne (-1);
-            base.addEventList (event_list);
-            this.input_mutex.ReleaseMutex ();
-        }
-        
-        protected override IOutputListener createOutputListener (string[] ports)
-        {
-            return new ConcurrentOutputListener(ports);   
-        }
-    }
-}
-

+ 0 - 55
src/csharp_sccd_runtime/sccdlib.csproj

@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>10.0.0</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectGuid>{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <RootNamespace>sccdlib</RootNamespace>
-    <AssemblyName>sccdlib</AssemblyName>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug</OutputPath>
-    <DefineConstants>DEBUG;</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <ConsolePause>false</ConsolePause>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>none</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release</OutputPath>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <ConsolePause>false</ConsolePause>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Event.cs" />
-    <Compile Include="ObjectManagerBase.cs" />
-    <Compile Include="InstanceWrapper.cs" />
-    <Compile Include="Association.cs" />
-    <Compile Include="OutputListener.cs" />
-    <Compile Include="ControllerBase.cs" />
-    <Compile Include="GameControllerBase.cs" />
-    <Compile Include="RuntimeClassBase.cs" />
-    <Compile Include="AssociationException.cs" />
-    <Compile Include="IOutputListener.cs" />
-    <Compile Include="ConcurrentOutputListener.cs" />
-    <Compile Include="AssociationReferenceException.cs" />
-    <Compile Include="RunTimeException.cs" />
-    <Compile Include="ParameterException.cs" />
-    <Compile Include="EventQueue.cs" />
-    <Compile Include="ThreadsControllerBase.cs" />
-    <Compile Include="InputException.cs" />
-  </ItemGroup>
-  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>

+ 0 - 50
src/csharp_sccd_runtime/sccdlib.sln

@@ -1,50 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sccdlib", "sccdlib.csproj", "{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}"
-EndProject
-Global
-	GlobalSection(SolutionConfigurationPlatforms) = preSolution
-		Debug|Any CPU = Debug|Any CPU
-		Release|Any CPU = Release|Any CPU
-	EndGlobalSection
-	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{B4A57EE1-3C90-4B43-9ACA-43821CB35EA0}.Release|Any CPU.Build.0 = Release|Any CPU
-	EndGlobalSection
-	GlobalSection(MonoDevelopProperties) = preSolution
-		StartupItem = sccdlib.csproj
-		Policies = $0
-		$0.TextStylePolicy = $1
-		$1.inheritsSet = VisualStudio
-		$1.inheritsScope = text/plain
-		$1.scope = text/x-csharp
-		$0.CSharpFormattingPolicy = $2
-		$2.IndentSwitchBody = True
-		$2.AnonymousMethodBraceStyle = NextLine
-		$2.PropertyBraceStyle = NextLine
-		$2.PropertyGetBraceStyle = NextLine
-		$2.PropertySetBraceStyle = NextLine
-		$2.EventBraceStyle = NextLine
-		$2.EventAddBraceStyle = NextLine
-		$2.EventRemoveBraceStyle = NextLine
-		$2.StatementBraceStyle = NextLine
-		$2.ElseNewLinePlacement = NewLine
-		$2.CatchNewLinePlacement = NewLine
-		$2.FinallyNewLinePlacement = NewLine
-		$2.WhileNewLinePlacement = DoNotCare
-		$2.ArrayInitializerWrapping = DoNotChange
-		$2.ArrayInitializerBraceStyle = NextLine
-		$2.BeforeMethodDeclarationParentheses = False
-		$2.BeforeMethodCallParentheses = False
-		$2.BeforeConstructorDeclarationParentheses = False
-		$2.BeforeDelegateDeclarationParentheses = False
-		$2.NewParentheses = False
-		$2.SpacesBeforeBrackets = False
-		$2.inheritsSet = Mono
-		$2.inheritsScope = text/x-csharp
-		$2.scope = text/x-csharp
-	EndGlobalSection
-EndGlobal

src/python_sccd/python_sccd_compiler/__init__.py → src/python_sccd/compiler/__init__.py


src/python_sccd/python_sccd_compiler/compiler_exceptions.py → src/python_sccd/compiler/compiler_exceptions.py


src/python_sccd/python_sccd_compiler/generic_generator.py → src/python_sccd/compiler/generic_generator.py


src/python_sccd/python_sccd_compiler/generic_language_constructs.py → src/python_sccd/compiler/generic_language_constructs.py


src/python_sccd/python_sccd_compiler/javascript_writer.py → src/python_sccd/compiler/javascript_writer.py


src/python_sccd/python_sccd_compiler/lexer.py → src/python_sccd/compiler/lexer.py


src/python_sccd/python_sccd_compiler/path_calculator.py → src/python_sccd/compiler/path_calculator.py


src/python_sccd/python_sccd_compiler/python_writer.py → src/python_sccd/compiler/python_writer.py


src/python_sccd/python_sccd_compiler/sccd_constructs.py → src/python_sccd/compiler/sccd_constructs.py


src/python_sccd/python_sccd_compiler/sccdc.py → src/python_sccd/compiler/sccdc.py


src/python_sccd/python_sccd_compiler/state_linker.py → src/python_sccd/compiler/state_linker.py


src/python_sccd/python_sccd_compiler/stateful_writer.py → src/python_sccd/compiler/stateful_writer.py


src/python_sccd/python_sccd_compiler/super_class_linker.py → src/python_sccd/compiler/super_class_linker.py


src/python_sccd/python_sccd_compiler/utils.py → src/python_sccd/compiler/utils.py


src/python_sccd/python_sccd_compiler/visitor.py → src/python_sccd/compiler/visitor.py


src/python_sccd/python_sccd_runtime/__init__.py → src/python_sccd/runtime/__init__.py


src/python_sccd/python_sccd_runtime/accurate_time.py → src/python_sccd/runtime/accurate_time.py


src/python_sccd/python_sccd_runtime/event_queue.py → src/python_sccd/runtime/event_queue.py


src/python_sccd/python_sccd_runtime/infinity.py → src/python_sccd/runtime/infinity.py


src/python_sccd/python_sccd_runtime/libs/__init__.py → src/python_sccd/runtime/libs/__init__.py


src/python_sccd/python_sccd_runtime/libs/drawing.py → src/python_sccd/runtime/libs/drawing.py


src/python_sccd/python_sccd_runtime/libs/ordered_set.py → src/python_sccd/runtime/libs/ordered_set.py


src/python_sccd/python_sccd_runtime/libs/ui.py → src/python_sccd/runtime/libs/ui.py


src/python_sccd/python_sccd_runtime/libs/utils.py → src/python_sccd/runtime/libs/utils.py


src/python_sccd/python_sccd_runtime/socket2event.py → src/python_sccd/runtime/socket2event.py


src/python_sccd/python_sccd_runtime/statecharts_core.py → src/python_sccd/runtime/statecharts_core.py


src/python_sccd/python_sccd_runtime/tkinter_eventloop.py → src/python_sccd/runtime/tkinter_eventloop.py


+ 1 - 1
src/setup.py

@@ -7,5 +7,5 @@ setup(name="sccd",
       author_email="Simon.VanMierlo@uantwerpen.be",
       url="http://msdl.cs.mcgill.ca/people/simonvm",
       packages=['sccd', 'sccd.runtime', 'sccd.runtime.libs', 'sccd.compiler'],
-      package_dir={'sccd': 'python_sccd', 'sccd.runtime': 'python_sccd/python_sccd_runtime', 'sccd.runtime.libs': 'python_sccd/python_sccd_runtime/libs', 'sccd.compiler': 'python_sccd/python_sccd_compiler'}
+      package_dir={'sccd': 'python_sccd', 'sccd.runtime': 'python_sccd/runtime', 'sccd.runtime.libs': 'python_sccd/runtime/libs', 'sccd.compiler': 'python_sccd/compiler'}
 )

+ 2 - 2
test/Makefile

@@ -37,8 +37,8 @@ test_javascript: all_javascript run_tests.html
 	$(BROWSER) run_tests.html &
 
 test_python:      ## Run Python tests.
-test_python: all_python run_tests.py
-	$(PYTHON) run_tests.py
+test_python:
+	$(PYTHON) test.py $(SRC_DIRS)
 
 $(BUILD_DIR)/%.py : %.xml
 	mkdir -p $(dir $@)

+ 0 - 88
test/run_tests.py

@@ -1,88 +0,0 @@
-import sys
-import os
-import importlib
-import unittest
-
-from sccd.runtime.statecharts_core import *
-
-BUILD_DIR = "build"
-
-class PyTestCase(unittest.TestCase):
-    def __init__(self, file_name):
-        unittest.TestCase.__init__(self)
-        self.file_name = file_name
-        self.name = os.path.splitext(self.file_name)[0]
-        self.module = importlib.import_module(self.name.replace(os.path.sep, "."))
-
-    def __str__(self):
-        return self.file_name
-
-    def runTest(self):
-        inputs = self.module.Test.input_events
-        expected = self.module.Test.expected_events
-
-        controller = self.module.Controller(False)
-
-        if inputs:
-            for i in inputs:
-                controller.addInput(Event(i.name, i.port, i.parameters), int(i.time_offset * 1000))
-
-        if not expected:
-            controller.start()
-            return
-
-        output_ports = set()
-        expected_result = []
-        for s in expected:
-            slot = []
-            for event in s:
-                slot.append(event)
-                output_ports.add(event.port)
-            if slot:
-                expected_result.append(slot)
-
-        output_listener = controller.addOutputListener(list(output_ports))
-
-        def check_output():
-            # check output
-            for (slot_index, slot) in enumerate(expected_result, start=1) : 
-                for entry in slot:
-                    output_event = output_listener.fetch(0)
-                    self.assertNotEqual(output_event, None, "Not enough output events on selected ports while checking for event %s" % entry)
-                    matches = True
-                    if output_event.name != entry.name :
-                        matches = False
-                    if output_event.port != entry.port :
-                        matches = False
-                    compare_parameters = output_event.getParameters()
-                    if len(entry.parameters) != len(compare_parameters) :
-                        matches = False
-                    for index in range(len(entry.parameters)) :
-                        if entry.parameters[index] !=  compare_parameters[index]:
-                            matches = False
-
-                    self.assertTrue(matches, self.name + ", expected results slot " + str(slot_index) + " mismatch. Expected " + str(entry) + ", but got " + str(output_event) +  " instead.") # no match found in the options
-
-            # check if there are no extra events
-            next_event = output_listener.fetch(0)
-            self.assertEqual(next_event, None, "More output events than expected on selected ports: " + str(next_event))
-            
-        controller.start()
-        check_output()
-        
-if __name__ == '__main__':
-    suite = unittest.TestSuite()
-
-    for r, dirs, files in os.walk(BUILD_DIR):
-        for file in files:
-            if file.endswith(".py") and not file.startswith("_"):
-                suite.addTest(PyTestCase(os.path.join(r, file)))
-    # for d in os.listdir("target_py"):
-    #     subdir = os.path.join("target_py", d)
-    #     if not os.path.isdir(subdir):
-    #         continue
-    #     for f in os.listdir(subdir):
-    #         if f.endswith(".py") and not f.startswith("_"):
-    #             suite.addTest(PyTestCase(os.path.join(subdir, f)))
-
-    unittest.TextTestRunner(verbosity=2).run(suite)