-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72b730f
commit c99dc58
Showing
11 changed files
with
204 additions
and
23 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
1 change: 1 addition & 0 deletions
1
SocietalConstructionToolTests/Snapshots/ParserTests/PredicateArgument.verified.txt
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 @@ | ||
(start (class_def class Citizen ( (args_def (type int) townId) ) { (class_body (state state Child { (statement_list (statement (enter enter Adult ;))) }) (state state Adult { (statement_list (statement (enter enter Adult ;))) })) }) (function function duplicate ( (args_def (type Predicate) p) ) -> (type int) { (statement_list (statement (if if ( (expression (expression (call_expression count ( (args_call (expression p)) ))) > (expression (literal 1))) ) { (statement_list (statement (return return (expression (literal 1)) ;))) })) (statement (return return (expression (literal 0)) ;))) }) (function function Setup ( args_def ) -> (type void) { (statement_list (statement (declaration (type Predicate) x = (expression (agent_predicate Citizen :: Child ( (args_agent townId : (expression (literal 1))) ))) ;)) (statement (if if ( (expression (call_expression duplicate ( (args_call (expression x)) ))) ) { (statement_list (statement (exit exit ( ) ;))) }))) }) <EOF>) |
1 change: 1 addition & 0 deletions
1
SocietalConstructionToolTests/Snapshots/ParserTests/ReturnPredicate.verified.txt
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 @@ | ||
(start (class_def class Citizen ( (args_def (type int) townId) ) { (class_body (state state Child { (statement_list (statement (enter enter Adult ;))) }) (state state Adult { (statement_list (statement (enter enter Adult ;))) })) }) (function function getChildPredicate ( (args_def (type int) id) ) -> (type Predicate) { (statement_list (statement (return return (expression (agent_predicate Citizen :: Child ( (args_agent townId : (expression id)) ))) ;))) }) (function function Setup ( args_def ) -> (type void) { (statement_list (statement (declaration (type int) townId = (expression (literal 5)) ;)) (statement (declaration (type int) childrenCount = (expression (call_expression count ( (args_call (expression (call_expression getChildPredicate ( (args_call (expression townId)) )))) ))) ;))) }) <EOF>) |
67 changes: 67 additions & 0 deletions
67
SocietalConstructionToolTests/Snapshots/TranslatorTests/PredicateArgument.verified.txt
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,67 @@ | ||
namespace SctGenerated | ||
{ | ||
using Sct.Runtime; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class GlobalClass | ||
{ | ||
public static void __sct_Setup(IRuntimeContext ctx) | ||
{ | ||
QueryPredicate __sct_x = new QueryPredicate("__sct_Citizen", "__sct_Child", new Dictionary<String, dynamic>(new KeyValuePair<String, dynamic>[] { new KeyValuePair<String, dynamic>("__sct_townId", 1) })); | ||
if (__sct_duplicate(ctx, __sct_x) != 0) | ||
{ | ||
ctx.ExitRuntime(); | ||
return true; | ||
} | ||
} | ||
|
||
public static long __sct_duplicate(IRuntimeContext ctx, Predicate __sct_p) | ||
{ | ||
if (((ctx.QueryHandler.Count(ctx, __sct_p) > 1) ? 1 : 0) != 0) | ||
{ | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public class __sct_Citizen : BaseAgent | ||
{ | ||
private int __sct_townId { get => Fields["__sct_townId"]; set => Fields["__sct_townId"] = value; } | ||
|
||
public __sct_Citizen(String state, IDictionary<String, dynamic> fields) : base(state, fields) | ||
{ | ||
} | ||
|
||
private bool __sct_Child(IRuntimeContext ctx) | ||
{ | ||
Enter(ctx, "__sct_Adult"); | ||
return true; | ||
return false; | ||
} | ||
|
||
private bool __sct_Adult(IRuntimeContext ctx) | ||
{ | ||
Enter(ctx, "__sct_Adult"); | ||
return true; | ||
return false; | ||
} | ||
|
||
public override void Update(IRuntimeContext ctx) | ||
{ | ||
_ = State switch | ||
{ | ||
"__sct_Child" => __sct_Child(ctx), | ||
"__sct_Adult" => __sct_Adult(ctx)}; | ||
} | ||
} | ||
|
||
public static void RunSimulation(IRuntimeContext ctx) | ||
{ | ||
Runtime runtime = new Runtime(); | ||
__sct_Setup(ctx); | ||
runtime.Run(ctx); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
SocietalConstructionToolTests/Snapshots/TranslatorTests/ReturnPredicate.verified.txt
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,58 @@ | ||
namespace SctGenerated | ||
{ | ||
using Sct.Runtime; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class GlobalClass | ||
{ | ||
public static void __sct_Setup(IRuntimeContext ctx) | ||
{ | ||
long __sct_townId = 5; | ||
long __sct_childrenCount = ctx.QueryHandler.Count(ctx, __sct_getChildPredicate(ctx, __sct_townId)); | ||
} | ||
|
||
public static QueryPredicate __sct_getChildPredicate(IRuntimeContext ctx, int __sct_id) | ||
{ | ||
return new QueryPredicate("__sct_Citizen", "__sct_Child", new Dictionary<String, dynamic>(new KeyValuePair<String, dynamic>[] { new KeyValuePair<String, dynamic>("__sct_townId", __sct_id) })); | ||
} | ||
|
||
public class __sct_Citizen : BaseAgent | ||
{ | ||
private int __sct_townId { get => Fields["__sct_townId"]; set => Fields["__sct_townId"] = value; } | ||
|
||
public __sct_Citizen(String state, IDictionary<String, dynamic> fields) : base(state, fields) | ||
{ | ||
} | ||
|
||
private bool __sct_Child(IRuntimeContext ctx) | ||
{ | ||
Enter(ctx, "__sct_Adult"); | ||
return true; | ||
return false; | ||
} | ||
|
||
private bool __sct_Adult(IRuntimeContext ctx) | ||
{ | ||
Enter(ctx, "__sct_Adult"); | ||
return true; | ||
return false; | ||
} | ||
|
||
public override void Update(IRuntimeContext ctx) | ||
{ | ||
_ = State switch | ||
{ | ||
"__sct_Child" => __sct_Child(ctx), | ||
"__sct_Adult" => __sct_Adult(ctx)}; | ||
} | ||
} | ||
|
||
public static void RunSimulation(IRuntimeContext ctx) | ||
{ | ||
Runtime runtime = new Runtime(); | ||
__sct_Setup(ctx); | ||
runtime.Run(ctx); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
SocietalConstructionToolTests/Snapshots/TypeCheckerTests/PredicateVariable.verified.txt
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 @@ | ||
emptyString |
23 changes: 23 additions & 0 deletions
23
SocietalConstructionToolTests/TestFiles/Parser/PredicateArgument.sct
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,23 @@ | ||
class Citizen(int townId) { | ||
state Child { | ||
enter Adult; | ||
} | ||
|
||
state Adult { | ||
enter Adult; | ||
} | ||
} | ||
|
||
function duplicate(Predicate p) -> int{ | ||
if (count(p) > 1) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
function Setup() -> void { | ||
Predicate x = Citizen::Child(townId:1); | ||
if (duplicate(x)) { | ||
exit(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
SocietalConstructionToolTests/TestFiles/Parser/ReturnPredicate.sct
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,18 @@ | ||
class Citizen(int townId) { | ||
state Child { | ||
enter Adult; | ||
} | ||
|
||
state Adult { | ||
enter Adult; | ||
} | ||
} | ||
|
||
function getChildPredicate(int id) -> Predicate { | ||
return Citizen::Child(townId: id); | ||
} | ||
|
||
function Setup() -> void { | ||
int townId = 5; | ||
int childrenCount = count(getChildPredicate(townId)); | ||
} |
12 changes: 12 additions & 0 deletions
12
SocietalConstructionToolTests/TestFiles/Typechecker/PredicateVariable.sct
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,12 @@ | ||
class Foo(int a, int b) { | ||
state Bar { | ||
enter Bar; | ||
} | ||
} | ||
|
||
function Setup() -> void { | ||
Predicate x = Foo::Bar(a:5); | ||
if(exists(x)){ | ||
int y = 5; | ||
} | ||
} |