app/assets/htmls/gobstones-code-runner.html in gobstones-code-runner-0.3.1 vs app/assets/htmls/gobstones-code-runner.html in gobstones-code-runner-0.4.1
- old
+ new
@@ -4365,11 +4365,11 @@
return dictionaries[CURRENT_LANGUAGE][message];
}
function i18nWithLanguage(code, thunk) {
if (!(code in dictionaries)) {
- throw Error('Invlid language code: ' + code);
+ throw Error('Invalid language code: ' + code);
}
var oldLanguage = CURRENT_LANGUAGE;
CURRENT_LANGUAGE = code;
try {
return thunk();
@@ -6392,10 +6392,21 @@
throw _iteratorError9;
}
}
}
+ this._primitiveProcedures[(0, _i18n.i18n)('PRIM:TypeCheck')] = new PrimitiveOperation([typeAny, typeAny, typeString], function (startPos, endPos, globalState, args) {
+ var v1 = args[0];
+ var v2 = args[1];
+ var errorMessage = args[2];
+ if ((0, _value.joinTypes)(v1.type(), v2.type()) === null) {
+ fail(startPos, endPos, 'typecheck-failed', [errorMessage.string, v1.type(), v2.type()]);
+ }
+ }, function (globalState, color) {
+ return null;
+ });
+
this._primitiveProcedures[(0, _i18n.i18n)('PRIM:PutStone')] = new PrimitiveOperation([typeColor()], noValidation, function (globalState, color) {
globalState.putStone(colorFromValue(color));
return null;
});
@@ -6605,10 +6616,19 @@
}
}, function (globalState, a, b) {
return a.mod(b);
});
+ this._primitiveFunctions['^'] = new PrimitiveOperation([typeInteger, typeInteger], function (startPos, endPos, globalState, args) {
+ var b = args[1];
+ if (b.lt(new _value.ValueInteger(0))) {
+ fail(startPos, endPos, 'negative-exponent', []);
+ }
+ }, function (globalState, a, b) {
+ return a.pow(b);
+ });
+
this._primitiveFunctions['-(unary)'] = new PrimitiveOperation([typeAny], function (startPos, endPos, globalState, args) {
var a = args[0];
validateTypeAmong(startPos, endPos, a, typesWithOpposite());
}, function (globalState, a) {
return genericOpposite(a);
@@ -7555,11 +7575,21 @@
key: 'mod',
value: function mod(other) {
var q = this.div(other);
return this.sub(q.mul(other));
}
+
+ /* Assumes that 'other' is non-negative */
+
}, {
+ key: 'pow',
+ value: function pow(other) {
+ var a = (0, _bigint.Integer)(this._number);
+ var b = (0, _bigint.Integer)(other._number);
+ return new ValueInteger(a.pow(b).toString());
+ }
+ }, {
key: 'eq',
value: function eq(other) {
return this.equal(other);
}
}, {
@@ -8749,10 +8779,33 @@
} else {
return delimiter;
}
}
+function formatTypes(string, type1, type2) {
+ var result = '';
+ for (var i = 0; i < string.length; i++) {
+ if (string[i] === '%' && i + 1 < string.length) {
+ if (string[i + 1] === '%') {
+ result += '%';
+ i++;
+ } else if (string[i + 1] === '1') {
+ result += typeAsNoun(type1);
+ i++;
+ } else if (string[i + 1] === '2') {
+ result += typeAsNoun(type2);
+ i++;
+ } else {
+ result += '%';
+ }
+ } else {
+ result += string[i];
+ }
+ }
+ return result;
+}
+
var LOCALE_ES = exports.LOCALE_ES = {
/* Descriptions of syntactic constructions and tokens */
'definition': 'una definición (de programa, función, procedimiento, o tipo)',
'pattern': 'un patrón (comodín "_", constructor aplicado a variables, o tupla)',
@@ -9107,16 +9160,23 @@
'errmsg:foreach-pattern-does-not-match': 'El elemento no coincide con el patrón esperado por el foreach.',
'errmsg:cannot-divide-by-zero': 'No se puede dividir por cero.',
+ 'errmsg:negative-exponent': 'El exponente de la potencia no puede ser negativo.',
+
'errmsg:list-cannot-be-empty': 'La lista no puede ser vacía.',
'errmsg:timeout': function errmsgTimeout(millisecs) {
return 'La ejecución del programa demoró más de ' + millisecs.toString() + 'ms.';
},
+ /* Typecheck */
+ 'errmsg:typecheck-failed': function errmsgTypecheckFailed(errorMessage, type1, type2) {
+ return formatTypes(errorMessage, type1, type2);
+ },
+
/* Board operations */
'errmsg:cannot-move-to': function errmsgCannotMoveTo(dirName) {
return 'No se puede mover hacia la dirección ' + dirName + ': cae afuera del tablero.';
},
@@ -9149,9 +9209,10 @@
'CONS:Dir0': 'Norte',
'CONS:Dir1': 'Este',
'CONS:Dir2': 'Sur',
'CONS:Dir3': 'Oeste',
+ 'PRIM:TypeCheck': 'TypeCheck',
'PRIM:BOOM': 'BOOM',
'PRIM:boom': 'boom',
'PRIM:PutStone': 'Poner',
'PRIM:RemoveStone': 'Sacar',
\ No newline at end of file