ScriptStack 1.0.4
Loading...
Searching...
No Matches
ScriptStack.Runtime.Interpreter Class Reference

The Interpreter finally interprets the parse tree in form of a token stream returned from the ScriptStack.Compiler.Parser. More...

Public Member Functions

 Interpreter (Function function, List< object > parameters)
 Interpreter (Function function)
 Interpreter (Script script, List< object > parameters)
 Interpreter (Script script)
void Reset ()
uint Interpret (uint instructions)
uint Interpret (TimeSpan interval)
uint Interpret ()

Properties

Script Script [get]
bool Interrupt [get, set]
ReadOnlyCollection< InterpreterJobs [get]
bool Interrupted [get]
bool Finished [get]
int NextInstruction [get]
ReadOnlyCollection< FunctionFunctionStack [get]
ReadOnlyCollection< object > ParameterStack [get]
Memory LocalMemory [get]
Host Handler [get, set]

Detailed Description

The Interpreter finally interprets the parse tree in form of a token stream returned from the ScriptStack.Compiler.Parser.

Todo
Evaluate!!! member access

Definition at line 17 of file Interpreter.cs.

Constructor & Destructor Documentation

◆ Interpreter() [1/4]

ScriptStack.Runtime.Interpreter.Interpreter ( Function function,
List< object > parameters )

Definition at line 1586 of file Interpreter.cs.

1587 {
1588
1589 if (function.ParameterCount != parameters.Count)
1590 throw new ExecutionException("Die Funktion '" + function.Name + "' wurde mit " + parameters.Count + " statt erwartet " + function.ParameterCount + " Parametern aufgerufen.");
1591
1592 this.function = function;
1593
1594 script = function.Executable.Script;
1595
1596 executable = script.Executable;
1597
1598 functionStack = new Stack<FunctionFrame>();
1599
1600 parameterStack = new Stack<object>();
1601
1602 locks = new Dictionary<object, Instruction>();
1603
1604 jobs = new List<Interpreter>();
1605
1606 host = null;
1607
1608 interrupt = false;
1609
1610 Reset();
1611
1612 foreach (object parameter in parameters)
1613 {
1614
1615 if (parameter == null)
1616 parameterStack.Push(NullReference.Instance);
1617
1618 else
1619 {
1620
1621 Type parameterType = parameter.GetType();
1622
1623 if (parameterType == typeof(NullReference))
1624 parameterStack.Push(NullReference.Instance);
1625
1626 else if (parameterType == typeof(int)
1627 || parameterType == typeof(float)
1628 || parameterType == typeof(double)
1629 || parameterType == typeof(bool)
1630 || parameterType == typeof(string)
1631 || parameterType == typeof(char)
1632 || parameterType == typeof(ArrayList))
1633 parameterStack.Push(parameter);
1634
1635 else
1636 throw new ExecutionException("Der Typ '" + parameterType.Name + "' ist kein generischer Typ.");
1637
1638 }
1639
1640 }
1641
1642 }

References Reset().

◆ Interpreter() [2/4]

ScriptStack.Runtime.Interpreter.Interpreter ( Function function)

Definition at line 1644 of file Interpreter.cs.

1644 :
1645 this(function, new List<object>())
1646 {
1647 }

◆ Interpreter() [3/4]

ScriptStack.Runtime.Interpreter.Interpreter ( Script script,
List< object > parameters )

Definition at line 1649 of file Interpreter.cs.

1649 :
1650 this(script.Executable.MainFunction, parameters)
1651 {
1652 }

References Script.

◆ Interpreter() [4/4]

ScriptStack.Runtime.Interpreter.Interpreter ( Script script)

Definition at line 1654 of file Interpreter.cs.

1654 :
1655 this(script.Executable.MainFunction, new List<object>())
1656 {
1657 }

References Script.

Member Function Documentation

◆ Interpret() [1/3]

uint ScriptStack.Runtime.Interpreter.Interpret ( )

Definition at line 1748 of file Interpreter.cs.

1749 {
1750
1751 localMemory.ExposeTemporaryVariables();
1752
1753 interrupted = false;
1754
1755 uint executed = 0;
1756
1757 while (!Finished && !interrupted)
1758 {
1759
1760 ExecuteInstruction();
1761
1762 ++executed;
1763
1764 executed += ExecuteBackgroundJobs();
1765
1766 }
1767
1768 localMemory.HideTemporaryVariables();
1769
1770 return executed;
1771
1772 }

References Finished.

◆ Interpret() [2/3]

uint ScriptStack.Runtime.Interpreter.Interpret ( TimeSpan interval)

Definition at line 1717 of file Interpreter.cs.

1718 {
1719
1720 DateTime end = DateTime.Now + interval;
1721
1722 localMemory.ExposeTemporaryVariables();
1723
1724 interrupted = false;
1725
1726 uint executed = 0;
1727
1728 while (!Finished && !interrupted)
1729 {
1730
1731 ExecuteInstruction();
1732
1733 ++executed;
1734
1735 executed += ExecuteBackgroundJobs();
1736
1737 if (DateTime.Now >= end)
1738 break;
1739
1740 }
1741
1742 localMemory.HideTemporaryVariables();
1743
1744 return executed;
1745
1746 }

References Finished.

◆ Interpret() [3/3]

uint ScriptStack.Runtime.Interpreter.Interpret ( uint instructions)

Definition at line 1691 of file Interpreter.cs.

1692 {
1693
1694 localMemory.ExposeTemporaryVariables();
1695
1696 interrupted = false;
1697
1698 uint executed = 0;
1699
1700 while (!Finished && !interrupted && executed < instructions)
1701 {
1702
1703 ExecuteInstruction();
1704
1705 ++executed;
1706
1707 executed += ExecuteBackgroundJobs();
1708
1709 }
1710
1711 localMemory.HideTemporaryVariables();
1712
1713 return executed;
1714
1715 }

References Finished.

◆ Reset()

void ScriptStack.Runtime.Interpreter.Reset ( )

Definition at line 1659 of file Interpreter.cs.

1660 {
1661
1662 functionStack.Clear();
1663
1664 FunctionFrame functionFrame = new FunctionFrame();
1665
1666 functionFrame.function = function;
1667
1668 functionFrame.localMemory = Memory.AllocateLocalMemory(executable.ScriptMemory);
1669
1670 functionFrame.nextInstruction = (int) function.EntryPoint.Address;
1671
1672 functionStack.Push(functionFrame);
1673
1674 parameterStack.Clear();
1675
1676 instruction = null;
1677
1678 localMemory = functionFrame.localMemory;
1679
1680 foreach (object currentLock in locks.Keys)
1681 script.Manager.Locks.Remove(currentLock);
1682
1683 locks.Clear();
1684
1685 finished = false;
1686
1687 interrupted = false;
1688
1689 }

References ScriptStack.Runtime.Memory.AllocateLocalMemory(), and ScriptStack.Runtime.Memory.Remove().

Referenced by Interpreter().

Property Documentation

◆ Finished

bool ScriptStack.Runtime.Interpreter.Finished
get

Definition at line 1799 of file Interpreter.cs.

1800 {
1801 get { return finished; }
1802 }

Referenced by Interpret(), Interpret(), and Interpret().

◆ FunctionStack

ReadOnlyCollection<Function> ScriptStack.Runtime.Interpreter.FunctionStack
get

Definition at line 1813 of file Interpreter.cs.

1814 {
1815 get
1816 {
1817 List<Function> listFunctions = new List<Function>();
1818 foreach (FunctionFrame functionFrame in functionStack)
1819 listFunctions.Add(functionFrame.function);
1820 return new List<Function>(listFunctions).AsReadOnly();
1821 }
1822 }

◆ Handler

Host ScriptStack.Runtime.Interpreter.Handler
getset

Definition at line 1834 of file Interpreter.cs.

1835 {
1836 get { return host; }
1837 set { host = value; }
1838 }

◆ Interrupt

bool ScriptStack.Runtime.Interpreter.Interrupt
getset

Definition at line 1783 of file Interpreter.cs.

1784 {
1785 get { return interrupt; }
1786 set { interrupt = value; }
1787 }

◆ Interrupted

bool ScriptStack.Runtime.Interpreter.Interrupted
get

Definition at line 1794 of file Interpreter.cs.

1795 {
1796 get { return interrupted; }
1797 }

◆ Jobs

ReadOnlyCollection<Interpreter> ScriptStack.Runtime.Interpreter.Jobs
get

Definition at line 1789 of file Interpreter.cs.

1790 {
1791 get { return jobs.AsReadOnly(); }
1792 }

◆ LocalMemory

Memory ScriptStack.Runtime.Interpreter.LocalMemory
get

Definition at line 1829 of file Interpreter.cs.

1830 {
1831 get { return localMemory; }
1832 }

◆ NextInstruction

int ScriptStack.Runtime.Interpreter.NextInstruction
get

Definition at line 1804 of file Interpreter.cs.

1805 {
1806 get
1807 {
1808 if (functionStack.Count == 0) return -1;
1809 return functionStack.Peek().nextInstruction;
1810 }
1811 }

◆ ParameterStack

ReadOnlyCollection<object> ScriptStack.Runtime.Interpreter.ParameterStack
get

Definition at line 1824 of file Interpreter.cs.

1825 {
1826 get { return new List<object>(parameterStack).AsReadOnly(); }
1827 }

◆ Script

Script ScriptStack.Runtime.Interpreter.Script
get

Definition at line 1778 of file Interpreter.cs.

1779 {
1780 get { return script; }
1781 }

Referenced by Interpreter(), and Interpreter().


The documentation for this class was generated from the following file: