python-plus-plus/ppp/ppp_object.ppp

29 lines
776 B
Plaintext
Raw Normal View History

import "ppp_types.ppp";
import "ppp_ast.ppp";
enum Object {
Int(int),
Str(str),
Bool(bool),
Void,
Type(Type),
Tuple(Type, Object[]),
List(Type, Object[]),
Array(Type, int, Object[]),
Function(Type, (str, (str, Type)[], Type, Statement, (str, (str, Type)[], Type, Statement, Object[]) -> Object)),
Return(Type, Object),
EnumValue(Type, str, (dict[str, Object] | Object[])),
EnumStruct(Type, dict[str, Object]),
Struct(Type, dict[str, Object])
}
func object_get_type(object: Object) -> Type {
match object in {
case Int(_) return Type.Int;
case Str(_) return Type.Str;
case Type(_) return Type.Type;
case Function(type_, _) return type_;
case EnumValue(type_, _, _) return type_;
case _ assert false, "Unimplemented object_get_type %s" % object;
}
}