Package org.yinwang.yin.value

Examples of org.yinwang.yin.value.Value


public class Binder {

    public static void define(Node pattern, Value value, Scope env) {
        if (pattern instanceof Name) {
            String id = ((Name) pattern).id;
            Value v = env.lookupLocal(id);
            if (v != null) {
                Util.abort(pattern, "trying to redefine name: " + id);
            } else {
                env.putValue(id, value);
            }
View Full Code Here


        } catch (ParserException e) {
            Util.abort("parsing error: " + e);
            return null;
        }
        Scope s = Scope.buildInitTypeScope();
        Value ret = program.typecheck(s);

        while (!uncalled.isEmpty()) {
            List<FunType> toRemove = new ArrayList<>(uncalled);
            for (FunType ft : toRemove) {
                invokeUncalled(ft, s);
View Full Code Here

        if (fun.properties != null) {
            Declare.mergeType(fun.properties, funScope);
        }

        TypeChecker.self.callStack.add(fun);
        Value actual = fun.fun.body.typecheck(funScope);
        TypeChecker.self.callStack.remove(fun);

        Object retNode = fun.properties.lookupPropertyLocal(Constants.RETURN_ARROW, "type");

        if (retNode == null || !(retNode instanceof Node)) {
            Util.abort("illegal return type: " + retNode);
            return;
        }

        Value expected = ((Node) retNode).typecheck(funScope);
        if (!Type.subtype(actual, expected, true)) {
            Util.abort(fun.fun, "type error in return value, expected: " + expected + ", actual: " + actual);
        }
    }
View Full Code Here


    public static void main(String[] args) {
        TypeChecker tc = new TypeChecker(args[0]);
        TypeChecker.self = tc;
        Value result = tc.typecheck(args[0]);
        Util.msg(result.toString());
    }
View Full Code Here

        for (String key : properties.keySet()) {
            Object defaultValue = properties.lookupPropertyLocal(key, "default");
            if (defaultValue == null) {
                continue;
            } else if (defaultValue instanceof Value) {
                Value existing = s.lookup(key);
                if (existing == null) {
                    s.putValue(key, (Value) defaultValue);
                }
            } else {
                Util.abort("default value is not a value, shouldn't happen");
View Full Code Here

            }
            Object type = properties.lookupPropertyLocal(key, "type");
            if (type == null) {
                continue;
            } else if (type instanceof Value) {
                Value existing = s.lookup(key);
                if (existing == null) {
                    s.putValue(key, (Value) type);
                }
            } else {
                Util.abort("illegal type, shouldn't happen" + type);
View Full Code Here

        for (String field : unevaled.keySet()) {
            Map<String, Object> props = unevaled.lookupAllProps(field);
            for (Map.Entry<String, Object> e : props.entrySet()) {
                Object v = e.getValue();
                if (v instanceof Node) {
                    Value vValue = ((Node) v).interp(s);
                    evaled.put(field, e.getKey(), vValue);
                } else {
                    Util.abort("property is not a node, parser bug: " + v);
                }
            }
View Full Code Here

            } else {
                Map<String, Object> props = unevaled.lookupAllProps(field);
                for (Map.Entry<String, Object> e : props.entrySet()) {
                    Object v = e.getValue();
                    if (v instanceof Node) {
                        Value vValue = ((Node) v).typecheck(s);
                        evaled.put(field, e.getKey(), vValue);
                    } else {
                        Util.abort("property is not a node, parser bug: " + v);
                    }
                }
View Full Code Here

    public Value interp(Scope s) {
        Scope properties = Declare.evalProperties(propertyForm, s);

        if (parents != null) {
            for (Node p : parents) {
                Value pv = p.interp(s);
                properties.putAll(((RecordType) pv).properties);
            }
        }
        Value r = new RecordType(name.id, this, properties);
        s.putValue(name.id, r);
        return r;
    }
View Full Code Here

    public Value typecheck(Scope s) {
        Scope properties = Declare.typecheckProperties(propertyForm, s);

        if (parents != null) {
            for (Node p : parents) {
                Value pv = p.typecheck(s);
                if (!(pv instanceof RecordType)) {
                    Util.abort(p, "parent is not a record: " + pv);
                    return null;
                }
                Scope parentProps = ((RecordType) pv).properties;

                // check for duplicated keys
                for (String key : parentProps.keySet()) {
                    Value existing = properties.lookupLocalType(key);
                    if (existing != null) {
                        Util.abort(p, "conflicting field " + key +
                                " inherited from parent " + p + ": " + pv);
                        return null;
                    }
                }

                // add all properties or all fields in parent
                properties.putAll(parentProps);
            }
        }

        Value r = new RecordType(name.id, this, properties);
        s.putValue(name.id, r);
        return r;
    }
View Full Code Here

TOP

Related Classes of org.yinwang.yin.value.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.