1/9/14

Stitie Virtual Machine & Ola AH Programming Language.

Object graph can be in-memory model of a running program, so Stitie Space, 3D graph of Stitie Machine objects can be considered as such as well.

Each Stitie Machine in this graph consists of state & of code (strategy). Strategies can have access to state - for example: via proper 'awareness interface' - so Stitie Machines are objects.... Stitie Machines can send messages to each other, so can communicate and collaborate.

In theory, one could adopt this model and programming style, create graph of object somehow then let the objects do their common task(s).

How to create graph of objects for stitie space? It can be done via programmatic interface, for now static and troublesome for use.... but someday it will be better syntax, easier to use, even at runtime.

Writing stitie machine based language interpreter is not so hard after all, in fact we have it planned.... but not too prematurely, we do not want users to get used to immature syntax, then force them to switch their thinking habits later without true reason. First we need to develop stitie machine, a language semantics and paradigm (Spaceful Programming Paradigm?) as a Java and Google Go libraries, perhaps.

This language will be called and named: 'Ola AH' ( AH stands for: AH Mantra for speech , but also for: 'Anti-hack'. Just as there can be F-18 fighter plane or F-18 AA, 'Anti-Air' version.... that there can be also language version focused on countering hacking. Author of this language strives for it to be true State-of-the-Art in that respect.)

Perhaps we'll develop other development tools as well.

See also: Virtual Machine, Stitie Machine 1.2 'Satellite', Stitie Machine 1.1 'Sunsail', Stitie Machine 1.0 'Core', Stitie Machine, Properties of Stitie Machine, 'AH' mode of 'Ola AH' Programming Language.


----


Example of stitie machine object graph construction in Java:

(it's very troublesome for now, we need 'Ola AH' language for terse, beautiful, sexy and elegant syntax. hopefully not without sense of humour.)


public class SunsailTest {

  public static void main(String[] args) {
    // create few Stitie Machines
    StitieMachineSpaceImpl space = new StitieMachineSpaceImpl(10);

    // get one of stitie machines
    StitieMachine am = space.getStitieMachineAtAbsolutePosition(5, 5, 5);
    // send commandchain
    LinkedList nsmDirs = new LinkedList();
    nsmDirs.add(Direction.MIDDLE_LEFT_MIDDLE);
    nsmDirs.add(Direction.MIDDLE_RIGHT_MIDDLE);

    State nsm1state = new HashMapStateImpl();
    nsm1state.addObjectProperty("storedNumber", 1);
    CommandChain ccForNsm1 = new CommandChainImpl(nsm1state, null, null);
    Tail moveLeftToNsm1Tail = new Tail(Direction.MIDDLE_LEFT_MIDDLE,
      ccForNsm1);

    State nsm2state = new HashMapStateImpl();
    nsm2state.addObjectProperty("storedNumber", 2);
    CommandChain ccForNsm2 = new CommandChainImpl(nsm2state, null, null);
    Tail moveRightToNsm2Tail = new Tail(Direction.MIDDLE_RIGHT_MIDDLE,
      ccForNsm2);

    Collection tailsAtAm = new LinkedList();
    tailsAtAm.add(moveLeftToNsm1Tail);
    tailsAtAm.add(moveRightToNsm2Tail);

    CommandChain ccForAm = new CommandChainImpl(new HashMapStateImpl(),
      new AdditionStrategy(nsmDirs), Boolean.TRUE, Boolean.TRUE,
      Boolean.FALSE, tailsAtAm);
    am.getRouter().routeCommandChain(ccForAm);

    // execute evaluation
    am.getStrategy().execute();

    // query result
    int result = (Integer) am.getState().getObjectProperty(
      "expressionValue");

    // print to console
    System.out.println(result);
  }
}

final class AdditionStrategy implements Strategy, StitieMachineCoreAware {
  private Sunsail s;
  public final Collection operands;

  public AdditionStrategy(final Collection operands) {
    this.operands = operands;
  }

  @Override
  public void execute() {
    if (s == null) {
      throw new IllegalStateException();
    }

    int r = 0;
    for (final Direction direction : operands) {
      final State state = s.getState(direction);
      r += (Integer) state.getObjectProperty("storedNumber");
    }

    final State resultState = s.getState();
    resultState.addObjectProperty("expressionValue", r);
  }

  @Override
  public void setStitieMachineCore(StitieMachineCore smc) {
    this.s = new Sunsail(smc);
  }

  @Override
  public State getState() {
    return s.getState();
  }

  @Override
  public void setState(State state) {
    s.setState(state);
  }
}

(this code is also automated test for Stitie Machine 1.1 'Sunsail', a part of 'Sunsail' code, in outdated version).

No comments:

Post a Comment