All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.prompto.statement.AssignTupleStatement.js Maven / Gradle / Ivy

var SimpleStatement = require("./SimpleStatement").SimpleStatement;
var TupleType = require("../type/TupleType").TupleType;
var AnyType = require("../type/AnyType").AnyType;
var VoidType = require("../type/VoidType").VoidType;
var Variable = require("../runtime/Variable").Variable;
var TupleValue = require("../value/TupleValue").TupleValue;
var Integer = require("../value/Integer").Integer;
var ExpressionValue = require("../value/ExpressionValue").ExpressionValue;

function AssignTupleStatement(names, expression) {
	SimpleStatement.call(this);
	this.names = names;
	this.expression = expression;
	return this;
}

AssignTupleStatement.prototype = Object.create(SimpleStatement.prototype);
AssignTupleStatement.prototype.constructor = AssignTupleStatement;

/*
@Override
public boolean equals(Object obj) {
	if(obj==this)
		return true;
	if(obj==null)
		return false;
	if(!(obj instanceof AssignTupleStatement))
		return false;
	AssignTupleStatement other = (AssignTupleStatement)obj;
	return this.getNames().equals(other.getNames())
			&& this.getExpression().equals(other.getExpression());
}

*/

AssignTupleStatement.prototype.check = function(context) {
	var type = this.expression.check(context);
	if(type!=TupleType.instance) {
		throw new SyntaxError("Expecting a tuple expression, got " + type.getName());
	}
	this.names.forEach(function(name) {
		var actual = context.getRegistered(name);
		if(actual==null) {
            var actualType = this.expression.check(context);
			context.registerValue(new Variable(name, actualType));
		} else {
			// need to check type compatibility
			var actualType = actual.getType(context);
			var newType = this.expression.check(context);
            actualType.checkAssignableFrom(context, newType);
		}
	}, this);
	return VoidType.instance;
};

AssignTupleStatement.prototype.interpret = function(context) {
	var object = this.expression.interpret(context);
	if(!(object instanceof TupleValue)) {
		throw new SyntaxError("Expecting a tuple expression, got " + typeof(object));
	}
	for(var i=0;i
        
Related Artifacts
Related Groups
-->


© 2015 - 2025 Weber Informatics LLC | Privacy Policy