builtin

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VoidType = iota
)

Variables

View Source
var AccountType = &ClassType{
	Name: "Account",
	InstanceFields: &FieldMap{
		Data: map[string]*Field{
			"name": {
				Type: &ast.TypeRef{Name: []string{"String"}},
				Name: "name",
				Modifiers: []ast.Node{
					&ast.Modifier{
						Name: "public",
					},
				},
			},
			"website": {
				Type: &ast.TypeRef{Name: []string{"String"}},
				Name: "website",
				Modifiers: []ast.Node{
					&ast.Modifier{
						Name: "public",
					},
				},
			},
			"field1__c": {
				Type: &ast.TypeRef{Name: []string{"String"}},
				Name: "field1__c",
				Modifiers: []ast.Node{
					&ast.Modifier{
						Name: "public",
					},
				},
			},
		},
	},
}
View Source
var BooleanType = &ClassType{
	Name: "Boolean",
}
View Source
var DoubleType = &ClassType{
	Name: "Double",
}
View Source
var IntegerType = &ClassType{
	Name: "Integer",
}
View Source
var ListType = &ClassType{
	Name: "List",
	Modifiers: []ast.Node{
		&ast.Modifier{
			Name: "public",
		},
	},
	Constructors: []*ast.ConstructorDeclaration{
		{
			Modifiers: []ast.Node{
				&ast.Modifier{
					Name: "public",
				},
			},
			Parameters:     []ast.Node{},
			NativeFunction: func(params []interface{}) {},
		},
		{
			Modifiers: []ast.Node{
				&ast.Modifier{
					Name: "public",
				},
			},
			Parameters: []ast.Node{
				&ast.Parameter{
					Type: &ast.TypeRef{
						Name: []string{"List"},
						Parameters: []ast.Node{
							&ast.TypeRef{
								Name: []string{"T:1"},
							},
						},
					},
					Name: "list",
				},
			},
			NativeFunction: func(params []interface{}) {
				listObj := params[1].(*Object)
				listParams := listObj.Extra["records"].([]*Object)
				newListParams := make([]*Object, len(listParams))
				for i, listParam := range listParams {
					newListParams[i] = &Object{
						ClassType: listParam.ClassType,
					}
				}
				this := params[0].(*Object)
				this.Extra = map[string]interface{}{
					"records": newListParams,
				}
			},
		},
	},
	InstanceFields: NewFieldMap(),
	InstanceMethods: &MethodMap{
		Data: map[string][]ast.Node{
			"size": {
				&ast.MethodDeclaration{
					Name: "size",
					Modifiers: []ast.Node{
						&ast.Modifier{Name: "public"},
					},
					NativeFunction: func(this interface{}, params []interface{}, options ...interface{}) interface{} {
						thisObj := this.(*Object)
						return len(thisObj.Extra["records"].([]*Object))
					},
				},
			},
			"isNext": {
				&ast.MethodDeclaration{
					Name: "next",
					NativeFunction: func(this interface{}, params []interface{}, options ...interface{}) interface{} {
						thisObj := this.(*Object)
						counter := thisObj.Extra["counter"].(int)
						return thisObj.Extra["records"].([]*Object)[counter]
					},
				},
			},
			"next": {
				&ast.MethodDeclaration{
					Name: "next",
					NativeFunction: func(this interface{}, params []interface{}, options ...interface{}) interface{} {
						thisObj := this.(*Object)
						counter := thisObj.Extra["counter"].(int)
						return thisObj.Extra["records"].([]*Object)[counter]
					},
				},
			},
		},
	},
}
View Source
var MapType = &ClassType{
	Name: "Map",
}
View Source
var PrimitiveClasses []*ClassType
View Source
var SetType = &ClassType{
	Name: "Set",
}
View Source
var StringType = &ClassType{
	Name: "String",
}
View Source
var System = &ClassType{
	Name: "System",
	StaticMethods: &MethodMap{
		Data: map[string][]ast.Node{
			"debug": {
				&ast.MethodDeclaration{
					Name: "debug",
					Modifiers: []ast.Node{
						&ast.Modifier{Name: "public"},
					},
					NativeFunction: func(this interface{}, parameter []interface{}, options ...interface{}) interface{} {
						o := parameter[0].(*Object)
						stdout := options[0].(io.Writer)
						fmt.Fprintln(stdout, String(o))
						return nil
					},
				},
			},
			"assertequals": {
				&ast.MethodDeclaration{
					Name: "assertequals",
					Modifiers: []ast.Node{
						&ast.Modifier{Name: "public"},
					},
					NativeFunction: func(this interface{}, parameter []interface{}, options ...interface{}) interface{} {
						expected := parameter[0].(*Object)
						actual := parameter[1].(*Object)
						if expected.Value() != actual.Value() {
							fmt.Printf("expected: %s, actual: %s\n", String(expected), String(actual))
						}
						return nil
					},
				},
			},
		},
	},
}

Functions

func String

func String(o *Object) string

func TypeName

func TypeName(v interface{}) string

Types

type ClassMap

type ClassMap struct {
	Data map[string]*ClassType
}

*

  • ClassMap

func NewClassMap

func NewClassMap() *ClassMap

func NewClassMapWithPrimivie

func NewClassMapWithPrimivie(classTypes []*ClassType) *ClassMap

func PrimitiveClassMap

func PrimitiveClassMap() *ClassMap

func (*ClassMap) Clear

func (m *ClassMap) Clear()

func (*ClassMap) Get

func (m *ClassMap) Get(k string) (*ClassType, bool)

func (*ClassMap) Set

func (m *ClassMap) Set(k string, n *ClassType)

type ClassType

type ClassType struct {
	Annotations      []ast.Node
	Modifiers        []ast.Node
	Name             string
	SuperClass       ast.Node
	ImplementClasses []ast.Node
	Constructors     []*ast.ConstructorDeclaration
	InstanceFields   *FieldMap
	StaticFields     *FieldMap
	InstanceMethods  *MethodMap
	StaticMethods    *MethodMap
	InnerClasses     *ClassMap
	Extra            map[string]interface{}
	Location         *ast.Location
	Parent           ast.Node
}

func (*ClassType) Equals

func (t *ClassType) Equals(other *ClassType) bool

func (*ClassType) IsGeneric

func (t *ClassType) IsGeneric() bool

func (*ClassType) IsPrimitive

func (t *ClassType) IsPrimitive() bool

func (*ClassType) String

func (t *ClassType) String() string

type Field

type Field struct {
	Type       ast.Node
	Modifiers  []ast.Node
	Name       string
	Expression ast.Node
	Location   *ast.Location
	Parent     ast.Node
}

func (*Field) AccessModifier

func (f *Field) AccessModifier() string

func (*Field) Is

func (f *Field) Is(name string) bool

func (*Field) IsAbstract

func (f *Field) IsAbstract() bool

func (*Field) IsOverride

func (f *Field) IsOverride() bool

func (*Field) IsPrivate

func (f *Field) IsPrivate() bool

func (*Field) IsProtected

func (f *Field) IsProtected() bool

func (*Field) IsPublic

func (f *Field) IsPublic() bool

func (*Field) IsVirtual

func (f *Field) IsVirtual() bool

type FieldMap

type FieldMap struct {
	Data map[string]*Field
}

func NewFieldMap

func NewFieldMap() *FieldMap

func (*FieldMap) Get

func (m *FieldMap) Get(k string) (*Field, bool)

func (*FieldMap) Set

func (m *FieldMap) Set(k string, n *Field)

type MethodMap

type MethodMap struct {
	Data map[string][]ast.Node
}

func NewMethodMap

func NewMethodMap() *MethodMap

func (*MethodMap) Add

func (m *MethodMap) Add(k string, n ast.Node)

func (*MethodMap) All

func (m *MethodMap) All() [][]ast.Node

func (*MethodMap) Get

func (m *MethodMap) Get(k string) ([]ast.Node, bool)

func (*MethodMap) Set

func (m *MethodMap) Set(k string, n []ast.Node)

type NameSpaceStore

type NameSpaceStore struct {
	Data map[string]*ClassMap
}

*

  • NameSpaces

func NewNameSpaceStore

func NewNameSpaceStore() *NameSpaceStore

func (*NameSpaceStore) Add

func (m *NameSpaceStore) Add(k string, n *ClassType)

func (*NameSpaceStore) Get

func (m *NameSpaceStore) Get(k string) (*ClassMap, bool)

func (*NameSpaceStore) Set

func (m *NameSpaceStore) Set(k string, n *ClassMap)

type Object

type Object struct {
	ClassType      *ClassType
	InstanceFields *ObjectMap
	GenericType    []*ClassType
	Extra          map[string]interface{}
	ToString       func(*Object) string
}

func CreateObject

func CreateObject(t *ClassType) *Object

func (*Object) BoolValue

func (o *Object) BoolValue() bool

func (*Object) DoubleValue

func (o *Object) DoubleValue() float64

func (*Object) IntegerValue

func (o *Object) IntegerValue() int

func (*Object) StringValue

func (o *Object) StringValue() string

func (*Object) Value

func (o *Object) Value() interface{}

type ObjectMap

type ObjectMap struct {
	Data map[string]*Object
}

*

  • ObjectMap

func NewObjectMap

func NewObjectMap() *ObjectMap

func (*ObjectMap) All

func (m *ObjectMap) All() map[string]*Object

func (*ObjectMap) Get

func (m *ObjectMap) Get(k string) (*Object, bool)

func (*ObjectMap) Set

func (m *ObjectMap) Set(k string, n *Object)

type ToStringer

type ToStringer struct {
	Indent int
}

func (*ToStringer) AddIndent

func (v *ToStringer) AddIndent(f func())

func (*ToStringer) String

func (v *ToStringer) String(o *Object) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL