commit 41ea15a86671a887bc435316a4aed7272ab31881
parent 31058e349a15f3683cebc5dec57e77503944aebc
Author: gduperon <gduperon@5d9ba3ac-444b-4713-9fb3-0b58e79229a2>
Date: Tue, 13 Apr 2010 19:40:57 +0000
Nettoyage, ajout d'un saut conditionnel (sz)
git-svn-id: https://projetud.info-ufr.univ-montp2.fr/svn/flin607-2009-gduperon@14 5d9ba3ac-444b-4713-9fb3-0b58e79229a2
Diffstat:
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/jsvm/vm.js b/jsvm/vm.js
@@ -1,3 +1,9 @@
+function init() {
+ window.setTimeout("log('Start'); window.setTimeout('test_vm_call_and_compile()', 0);", 100);
+}
+
+/* **************************************** */
+
Array.prototype.append = function(array2) {
for (i = 0; i < array2.length; i++) {
this[this.length] = array2[i];
@@ -34,6 +40,12 @@ function log(str) {
$('log').insert("<div>" + str + "</div>");
}
+function trace(str) {
+ if (typeof console != "undefined") {
+ console.log(str);
+ }
+}
+
function error(str) {
$('log').insert("<div class=\"error\">" + str + "</div>");
_error();
@@ -67,7 +79,7 @@ function vm() {
var instr = instructions[this.ip];
var op = this.operations[instr.operation];
var args = instr.arguments;
- console.log(this.ip + " : [" + this.stack.join(",") + "] (" + instr.display() + ")");
+ trace(this.ip + " : [" + this.stack.join(",") + "] (" + instr.display() + ")");
op.eval.apply(this, args);
}
return this.stack;
@@ -136,6 +148,11 @@ function vm() {
display : function(instr) { return "jump " + instr; },
eval : function(instr) { this.ip = instr - 1; }
},
+ // N'exécute pas l'instruction suivante ssi le sommet de la pile vaut 0 (Skip if Zero)
+ sz: {
+ display : function() { return "sz"; },
+ eval : function() { if (this.stack.peek(0) == 0) { this.ip++; } }
+ },
// Appeller la fonction instr, avec nbparam paramètres.
call: {
display : function(instr, nbparam) { return "call " + instr; },
@@ -261,7 +278,7 @@ function bloc(uid, name, nbEntrees, nbSorties) {
// On empile chaque paramètre du bloc à appeler.
for (var entree = 0; entree < b.nbEntrees; entree++) {
var dep = this.portdeps[n][entree];
- if (dep == undefined) {
+ if (typeof dep == "undefined") {
error("Entrée " + entree + " manquante pour le bloc " + n + " (" + b.name + ") de " + this.name);
}
var pos = stackpos[dep.blocSortie] + dep.portSortie;
@@ -337,7 +354,7 @@ function bloc(uid, name, nbEntrees, nbSorties) {
});
}
-function init() {
+function test_vm_call_and_compile() {
w = new world("Brave");
wPlus = w.newBloc("+", 2, 1);
wOne = w.newBloc("1", 0, 1);