-
Notifications
You must be signed in to change notification settings - Fork 1
Syntax
Archetypes serve as the interface between application code and the model sandbox. Archetypes can only inherit from other Archetypes. Application developers create their desired Archetypes in Sandbox Model Language code declaring certain methods and fields native to signify that their calling or manipulation is done by the application managing the instance of the Virtual Machine. Archetypes also specify which states an object can enter.
archetype identifier_archetype_name
{
native type_name identifier_variable1_name;
property type_name identifier_property1_name;
type_name identifier_variable2_name;
state default
{
native identifier_method1_name()
{
}
}
state identifier_state1_name
{
type_name identifier_variable3_name;
native identifier_method1_name()
{
identifier_variable3_name = 1;
}
}
state identifier_state2_name
{
}
}
Objects are the instanced residents of the Sandbox Virtual Machines. Objects can inherit from either other Objects or from Archetypes, but the base class must always be an Archetype. Objects cannot define native fields, but they can override native methods.
object identifier_object_name is identifier_base_name
{
property type_name identifier_property1_name;
type_name identifier_variable2_name;
state default
{
native identifier_method1_name()
{
}
}
state identifier_state1_name
{
type_name identifier_variable3_name;
native identifier_method1_name()
{
identifier_variable3_name = 1;
}
type_name
}
state identifier_state2_name
{
}
}
Inheritance is declared using the is keyword. Archetypes and Objects can both inherit from Archetypes. Objects, however, can only inherit from other Objects. All fields and properties are inherited.
archetype identifier_derived_archetype is identifier_base_archetype
{
}
object identifier_object_name is identifier_archetype_name
{
}
object identifier_object_name is identifier_base_object
{
}
The following is illegal, however. Archetypes cannot ever derive from an object
object identifier_archetype_name is identifier_object_name
{
}
Variables are declared within the scope of a method.
archetype some_archetype
{
state default
{
integer get_a_number()
{
integer some_variable = 9;
return some_variable;
}
}
}
Variables declared in state scope or object/archetype scope are fields. Fields are not accessible from outside their owner object.
archetype some_archetype
{
integer some_field;
state default
{
integer a_state_field;
}
}
Variables declared in the object/archetype scope with the keyword property are properties. Properties are accessible from both other objects and the managing Application.
archetype some_archetype
{
property integer some_property;
state default
{
}
}
The keyword native is used to signify that a field or method is managed by the Application controlling an instance of the Sandbox Virtual Machine.
A field marked native can only be changed from outside of the Sandbox Virtual Machine.
Methods marked native have no return type and are called by the managing Application.
All Sandbox Virtual Machine objects possess the default state. Additional states can be defined in Archetypes and can be used to change object behavior based on the current state. In addition, variables can be scoped at a state level or at an object level. All methods must have a basic definition provided in the default state; if a method does not have a special state definition, the default state's method definition is used.
archetype magic_number_provider
{
state default
{
# This method will be redefined by test_state
integer magic_number()
{
return 0;
}
# This method will not be redefined by test_state.
string get_message()
{
return "Hello, World";
}
}
state test_state
{
# If the object is in this state, this definition will be used instead of default
integer magic_number()
{
return 42;
}
}
}
An object's state can be changed from an internal method by setting its state property.
archetype state_switch_tester
{
state default
{
# This method will change the object state to test_state
void change_state()
{
state = "test_state"
}
}
state test_state
{
}
}