-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added thread expression with syntax thread { #body }
- Loading branch information
1 parent
18c1753
commit 1ca3147
Showing
13 changed files
with
173 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace Hassium.Compiler.Parser.Ast | ||
{ | ||
public class ThreadNode: AstNode | ||
{ | ||
public AstNode Body { get { return Children[0]; } } | ||
|
||
public ThreadNode(SourceLocation location, AstNode body) | ||
{ | ||
this.SourceLocation = location; | ||
Children.Add(body); | ||
} | ||
|
||
public override void Visit(IVisitor visitor) | ||
{ | ||
visitor.Accept(this); | ||
} | ||
public override void VisitChildren(IVisitor visitor) | ||
{ | ||
foreach (AstNode child in Children) | ||
child.Visit(visitor); | ||
} | ||
} | ||
} | ||
|
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
namespace Hassium.Runtime.Objects.Types | ||
{ | ||
public class HassiumThread: HassiumObject | ||
{ | ||
public static new HassiumTypeDefinition TypeDefinition = new HassiumTypeDefinition("thread"); | ||
|
||
public Thread Thread { get; private set; } | ||
|
||
public HassiumThread(VirtualMachine vm, HassiumMethod method, StackFrame.Frame frame) | ||
{ | ||
VirtualMachine newVM = vm.Clone() as VirtualMachine; | ||
newVM.ExceptionReturns = new Dictionary<HassiumMethod, int>(); | ||
newVM.Handlers = new Stack<HassiumExceptionHandler>(); | ||
newVM.Stack = new Stack<HassiumObject>(); | ||
newVM.StackFrame = new StackFrame(); | ||
Thread = new Thread(() => method.Invoke(newVM, frame)); | ||
|
||
AddType(TypeDefinition); | ||
AddAttribute("isAlive", new HassiumProperty(get_isAlive)); | ||
AddAttribute("start", start, 0); | ||
AddAttribute("stop", stop, 0); | ||
} | ||
|
||
public HassiumBool get_isAlive(VirtualMachine vm, params HassiumObject[] args) | ||
{ | ||
return new HassiumBool(Thread.IsAlive); | ||
} | ||
public HassiumNull start(VirtualMachine vm, params HassiumObject[] args) | ||
{ | ||
Thread.Start(); | ||
return HassiumObject.Null; | ||
} | ||
public HassiumNull stop(VirtualMachine vm, params HassiumObject[] args) | ||
{ | ||
Thread.Abort(); | ||
return HassiumObject.Null; | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Hassium.Runtime | ||
{ | ||
public class VirtualMachineContext | ||
{ | ||
public VirtualMachineContext() | ||
{ | ||
} | ||
} | ||
} | ||
|