package abstrasy.pcfx;
import abstrasy.Heap;
import abstrasy.Node;
import abstrasy.PCoder;
import abstrasy.SELF;
import abstrasy.ASymbol;
import abstrasy.interpreter.InterpreterException;
import abstrasy.interpreter.StdErrors;
/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
* http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/
public class PCFx_using extends PCFx {
public PCFx_using() {
}
/**
* eval
*
* @param startAt Node
* @return Node
* @throws Exception
* @todo Implémenter cette méthode abstrasy.PCFx
*/
public Node eval(Node startAt) throws Exception {
startAt.isGoodArgsCnt(4);
Node op=startAt.getSubNode(2, Node.TYPE_PCODE);
if(op.isPCode(PCoder.PC_DO)){
/**
* forme (using obj do{...})
*/
Node hnode = startAt.getSubNode(1, Node.VTYPE_DELEGABLE);
Node cnode = startAt.getSubNode(3, Node.TYPE_LAZY);
Heap.push();
Node old_self = SELF.swap(hnode); // vobject -> Self
cnode = cnode.exec(true);
SELF.restore(old_self);
Heap.pull();
return cnode;
}
else if(op.isPCode(PCoder.PC_RETURN)){
/**
* forme (using obj return 'symbol)
*/
Node hnode = startAt.getSubNode(1, Node.VTYPE_DELEGABLE);
Node cnode = startAt.getSubNode(3, Node.TYPE_QSYMBOL);
Heap.push();
Node old_self = SELF.swap(hnode); // vobject -> Self
cnode = Heap.getv(new ASymbol(PCoder.selfing(cnode.getSymbol().getStr())));
SELF.restore(old_self);
Heap.pull();
return cnode;
}
else{
throw new InterpreterException(StdErrors.extend(StdErrors.Syntax_error,"\'do\' or \'return\' expected"));
}
}
}