Skip to content

Instantly share code, notes, and snippets.

@moredhel
Last active November 30, 2016 13:01
Show Gist options
  • Select an option

  • Save moredhel/cc49bfd2e80b889b461f1c9b50065e03 to your computer and use it in GitHub Desktop.

Select an option

Save moredhel/cc49bfd2e80b889b461f1c9b50065e03 to your computer and use it in GitHub Desktop.

The following is a description of the coverage phase.

type ObjectMap = Immutable.Map<Name, ObjectLitType>
type Name = string;

interface ObjectLitType {
    type: 'object-lit',
    properties: Immutable.Map<String, Immutable.List<Type>>
    call?: Immutable.List<FunctionLitType>
}

type Type
    = BuiltinType
    | FunctionRefType
    | ObjectLitType
    | FunctionLitType

interface BuiltinType {
    type: BasicTypes
    action: Action
}

interface ObjectLitType {
    type: 'object-lit',
    properties: Immutable.Map<String, Immutable.List<Type>>
    call?: Immutable.List<FunctionLitType>
}

interface FunctionLitType {
    type: 'function-lit'
    parameters: Immutable.List<Parameter>,
    returnType: Type
}

interface Parameter {
    type: Type
}

interface FunctionRefType {
    type: 'function',
    name: string,
    action: Action
}

enum Action {
    Set,
    Get,
    Apply
}

type BasicTypes
    = "number"
    | "string"
    | "boolean"
    | "void"
    | "any"
    | "undefined"


The ObjectMap contains references for all objects.

New functions are given a new name using a gensym and attached to the ObjectMap with a reference in the location using an ObjectLit and setting/appending to the call? property.

This phase takes the collection phase and generates types that are then passed on to the output phase.

type Aggregation = Immutable.Map<string, PropertyType>

type PropertyType
  = AggFunctionType
  | AggObjectType
  | AggBuiltinType
  
interface AggFunctionType {
  type: "function",
  parameters: Immutable.List<Immutable.List<PropertyType>>,
  returnType: Immutable.List<PropertyType>
}

interface AggObjectType {
  type: "object",
  types: Immutable.List<Aggregation|PropertyType>
}

interface AggBuiltinType {
  type: "builtin",
  value: BasicTypes
}

type BasicTypes
    = "number"
    | "string"
    | "boolean"
    | "void"
    | "any"
    | "undefined"

Firstly we map over every <string, PropertyType> pair in the passed in Aggregation data.

If it is an AggFunctionType:

export function functionName(string, number): void

If it is an AggBuiltinType:

export var varName: string|number

If it is an AggObjectType:

export var objectName: {prop1: string, prop2: { prop21: number }, prop3(number): undefined}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment