trompe

package module
v0.0.0-...-1473c49 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Trompe

Trompe is a strongly-typed scripting language with type inference. This is developed for handy scripting to clean up chores, which enables quick startup, interpretation (no need build configuration), and detecting type mismatch errors easily and quickly.

Current version is pre-pre-pre-alpha. See examples/ for more detail.

License

Trompe is licensed under the Apache License, Version 2.0.

Requirements

  • Go 1.10+
  • Antlr 4.7.1+

Build

$ make

Grammar

Comments
-- comment end of line
Unit
()
Boolean
true
false
Integers
12345
Floating-Point Numbers
123.45
0e10
Strings
"hello, world!"
Lists
[]
[1, 2, 3]
Tuple
(1, 2, 3)
Closure
Calling Functions
f()
f(1, 2 , 3)
Block
do
  ...
end
Variable Bindings
let x = 1
Defining Functions
def f(x) 
  x + 1
end
Conditions
if n == 0 then
  show("zero")
else 
  show("other")
end
Loop
for i in 1..15 do
  show(i)
end
Pattern Matching
case i do
when 0 then "0"
when 1 then "1"
when 2 then "2"
when _ then "_"
end
Type Annotations

TODO

  • Library
  • Partial application
  • Records
  • Variants
  • References and dereferences
  • Operator definition
  • Exception handling
  • Modules and traits
  • Tail call optimization

Author

SUZUKI Tetsuya (tetsuya.suzuki@gmail.com)

Documentation

Index

Constants

View Source
const (
	GenericError = iota
	InvalidArityError
	KeyError
)
View Source
const (
	OpNop = iota
	OpLoadUnit
	OpLoadTrue
	OpLoadFalse
	OpLoadZero   // load 0
	OpLoadOne    // load 1
	OpLoadNegOne // load -1
	OpLoadInt    // int
	OpLoadNone
	OpLoadRef
	OpLoadLit   // index of value in literal list
	OpLoadLocal // index
	OpLoadAttr  // index of literal string
	OpLoadArg   // index
	OpLoadModule
	OpStoreLocal // index of literal string
	OpStoreRef
	OpStoreAttr // index of literal string
	OpPop
	OpDup
	OpReturn
	OpReturnUnit
	OpLabel       // label number
	OpJump        // index
	OpBranchTrue  // index
	OpBranchFalse // index
	OpBranchNext  // label
	OpBegin
	OpEnd
	OpCall  // length
	OpPanic // kind
	OpEq
	OpNe
	OpLt
	OpLe
	OpGt
	OpGe
	OpMatch
	OpAdd
	OpSub
	OpMul
	OpDiv
	OpMod
	OpSome
	OpList  // length
	OpTuple // length
	OpClosedRange
	OpHalfOpenRange
	OpIter
)
View Source
const (
	OpPanicFatal = iota
	OpPanicMatch
)
View Source
const (
	ValueTypeUnit = iota
	ValueTypeBool
	ValueTypeInt
	ValueTypeString
	ValueTypeList
	ValueTypeTuple
	ValueTypeClos
	ValueTypeOption
	ValueTypeRange
	ValueTypeIter
	ValueTypePattern
	ValueTypeRef
)

Variables

View Source
var DebugMode = false
View Source
var ListNil = &List{nil, nil}
View Source
var ObjectValueTypeBool = "bool"
View Source
var ObjectValueTypeCode = "code"
View Source
var ObjectValueTypeFloat = "float"
View Source
var ObjectValueTypeInt = "int"
View Source
var ObjectValueTypeString = "string"
View Source
var ObjectValueTypeUnit = "unit"
View Source
var OpenedModules []*Module
View Source
var SharedFalse = &Bool{false}
View Source
var SharedNone = &Option{nil}
View Source
var SharedTrue = &Bool{true}
View Source
var SharedUnit = &Unit{}
View Source
var VerboseMode = false
View Source
var Version = "0.0.1"

Functions

func AddOpenedModule

func AddOpenedModule(m *Module)

func AddTopModule

func AddTopModule(m *Module)

func Debug

func Debug(format string, arg ...interface{})

func ErrorName

func ErrorName(ty int) string

func GetOpName

func GetOpName(op int) string

func Init

func Init()

func InstallLibCore

func InstallLibCore()

func InstallModules

func InstallModules()

func NodeDesc

func NodeDesc(node Node) string

func StrToInt

func StrToInt(s string) (int, error)

func TestCompiledCodeFizzBuzzCompare

func TestCompiledCodeFizzBuzzCompare()

if arg1 == 3 then

show("Fizz")

else if arg1 == 5 then

show("Buzz")

else if arg1 == 15 then

show("FizzBuzz")

else

show(arg1)

end

func TestCompiledCodeFizzBuzzMatch

func TestCompiledCodeFizzBuzzMatch()

func TestCompiledCodeHelloWorld

func TestCompiledCodeHelloWorld()

show "Hello, world!"

func Verbose

func Verbose(format string, arg ...interface{})

Types

type AnonFunExpNode

type AnonFunExpNode struct {
	Open   Loc
	Close  Loc
	Params *ParamListNode
	In     Loc
	Stats  []StatNode
	Exp    ExpNode
}

func (*AnonFunExpNode) Loc

func (exp *AnonFunExpNode) Loc() *Loc

func (*AnonFunExpNode) WriteTo

func (exp *AnonFunExpNode) WriteTo(buf *bytes.Buffer)

type BlockNode

type BlockNode struct {
	Stats []Node
	// contains filtered or unexported fields
}

func (*BlockNode) Loc

func (block *BlockNode) Loc() *Loc

func (*BlockNode) WriteTo

func (block *BlockNode) WriteTo(buf *bytes.Buffer)

type Bool

type Bool struct {
	Value bool
}

func NewBool

func NewBool(b bool) *Bool

func ValueToBool

func ValueToBool(v Value) (*Bool, bool)

func (*Bool) Desc

func (b *Bool) Desc() string

func (*Bool) Type

func (b *Bool) Type() int

type BoolExpNode

type BoolExpNode struct {
	Value bool
	// contains filtered or unexported fields
}

func (*BoolExpNode) Loc

func (exp *BoolExpNode) Loc() *Loc

func (*BoolExpNode) WriteTo

func (exp *BoolExpNode) WriteTo(buf *bytes.Buffer)

type BoolPtnNode

type BoolPtnNode struct {
	Value bool
	// contains filtered or unexported fields
}

func (*BoolPtnNode) Loc

func (ptn *BoolPtnNode) Loc() *Loc

func (*BoolPtnNode) WriteTo

func (ptn *BoolPtnNode) WriteTo(buf *bytes.Buffer)

type CaseClauNode

type CaseClauNode struct {
	When   Loc
	Ptn    PtnNode
	In     *Loc
	Guard  ExpNode
	Then   Loc
	Action *BlockNode
}

func (*CaseClauNode) Loc

func (clau *CaseClauNode) Loc() *Loc

func (*CaseClauNode) WriteTo

func (clau *CaseClauNode) WriteTo(buf *bytes.Buffer)

type CaseStatNode

type CaseStatNode struct {
	Case       Loc
	Cond       ExpNode
	Claus      []CaseClauNode
	Else       *Loc
	ElseAction *BlockNode
}

func (*CaseStatNode) Loc

func (stat *CaseStatNode) Loc() *Loc

func (*CaseStatNode) WriteTo

func (stat *CaseStatNode) WriteTo(buf *bytes.Buffer)

type ChunkNode

type ChunkNode struct {
	Block *BlockNode
	// contains filtered or unexported fields
}

func (*ChunkNode) Loc

func (chunk *ChunkNode) Loc() *Loc

func (*ChunkNode) WriteTo

func (chunk *ChunkNode) WriteTo(buf *bytes.Buffer)

type Closure

type Closure interface {
	Arity() int
	Apply(*Interp, *Context, *Env) (Value, error)
}

func ValueToClos

func ValueToClos(v Value) (Closure, bool)

type CommentNode

type CommentNode struct {
	Begin Loc
	Text  Token
}

type CompiledCode

type CompiledCode struct {
	Id     int
	Syms   []string
	Lits   []Value
	Ops    []Opcode
	Labels map[int]int
}

func Compile

func Compile(path string, node Node) *CompiledCode

func NewCompiledCode

func NewCompiledCode() *CompiledCode

func (*CompiledCode) AddLit

func (code *CompiledCode) AddLit(value Value)

func (*CompiledCode) Apply

func (code *CompiledCode) Apply(ip *Interp, ctx *Context, env *Env) (Value, error)

func (*CompiledCode) Arity

func (code *CompiledCode) Arity() int

func (*CompiledCode) Desc

func (code *CompiledCode) Desc() string

func (*CompiledCode) Inspect

func (code *CompiledCode) Inspect() string

func (*CompiledCode) LiteralDesc

func (code *CompiledCode) LiteralDesc(i int) string

func (*CompiledCode) Type

func (code *CompiledCode) Type() int

type CondOpExpNode

type CondOpExpNode struct {
	Colon Loc
	Q     Loc
	Cond  ExpNode
	True  ExpNode
	False ExpNode
}

func (*CondOpExpNode) Loc

func (exp *CondOpExpNode) Loc() *Loc

func (*CondOpExpNode) WriteTo

func (exp *CondOpExpNode) WriteTo(buf *bytes.Buffer)

type ConsPtnNode

type ConsPtnNode struct {
	Left  PtnNode
	Sep   Loc
	Right PtnNode
}

func (*ConsPtnNode) Loc

func (ptn *ConsPtnNode) Loc() *Loc

func (*ConsPtnNode) WriteTo

func (ptn *ConsPtnNode) WriteTo(buf *bytes.Buffer)

type Context

type Context struct {
	Parent  *Context
	Module  *Module
	Clos    Closure
	Args    []Value
	NumArgs int
}

func NewContext

func NewContext(parent *Context,
	module *Module,
	clos Closure,
	args []Value,
	numArgs int) Context

type DefStatNode

type DefStatNode struct {
	Def    Loc
	Name   Token
	Open   Loc
	Params *ParamListNode
	Close  Loc
	Block  BlockNode
	End    Loc
}

func (*DefStatNode) Loc

func (stat *DefStatNode) Loc() *Loc

func (*DefStatNode) WriteTo

func (stat *DefStatNode) WriteTo(buf *bytes.Buffer)

type EltListNode

type EltListNode struct {
	Open  Loc
	Close Loc
	Elts  []Node
	Seps  []Loc
}

func (*EltListNode) Loc

func (exp *EltListNode) Loc() *Loc

func (*EltListNode) WriteTo

func (elts *EltListNode) WriteTo(buf *bytes.Buffer)

type EltPtnListNode

type EltPtnListNode struct {
	Open  Loc
	Close Loc
	Elts  []PtnNode
	Seps  []Loc
}

func (*EltPtnListNode) Loc

func (elts *EltPtnListNode) Loc() *Loc

func (*EltPtnListNode) WriteTo

func (elts *EltPtnListNode) WriteTo(buf *bytes.Buffer)

type Env

type Env struct {
	Parent  *Env
	Attrs   map[string]Value
	Imports []*Module
}

func NewEnv

func NewEnv(src *Env) *Env

func (*Env) AddImport

func (env *Env) AddImport(m *Module)

func (*Env) Get

func (env *Env) Get(name string) Value

func (*Env) Set

func (env *Env) Set(name string, value Value)

TODO: Set -> Add

type ExpNode

type ExpNode interface {
	Node
}

type ForStatNode

type ForStatNode struct {
	For   Loc
	In    Loc
	Do    Loc
	End   Loc
	Ptn   PtnNode
	Exp   ExpNode
	Block BlockNode
}

func (*ForStatNode) Loc

func (stat *ForStatNode) Loc() *Loc

func (*ForStatNode) WriteTo

func (stat *ForStatNode) WriteTo(buf *bytes.Buffer)

type FunCallExpNode

type FunCallExpNode struct {
	Callable Node
	Args     EltListNode
}

func (*FunCallExpNode) Loc

func (exp *FunCallExpNode) Loc() *Loc

func (*FunCallExpNode) WriteTo

func (exp *FunCallExpNode) WriteTo(buf *bytes.Buffer)

type IfCondNode

type IfCondNode struct {
	If     Loc
	Cond   ExpNode
	Then   Loc
	Action BlockNode
}

func (*IfCondNode) Loc

func (cond *IfCondNode) Loc() *Loc

func (*IfCondNode) WriteTo

func (cond *IfCondNode) WriteTo(buf *bytes.Buffer)

type IfStatNode

type IfStatNode struct {
	Cond       []IfCondNode
	Else       *Loc
	ElseAction *BlockNode
	End        Loc
}

func (*IfStatNode) Loc

func (stat *IfStatNode) Loc() *Loc

func (*IfStatNode) WriteTo

func (stat *IfStatNode) WriteTo(buf *bytes.Buffer)

type Int

type Int struct {
	Value int
}

func NewInt

func NewInt(i int) *Int

func ValueToInt

func ValueToInt(v Value) (*Int, bool)

func (*Int) Desc

func (i *Int) Desc() string

func (*Int) Type

func (i *Int) Type() int

type IntExpNode

type IntExpNode struct {
	Value Token
}

func (*IntExpNode) Loc

func (exp *IntExpNode) Loc() *Loc

func (*IntExpNode) WriteTo

func (exp *IntExpNode) WriteTo(buf *bytes.Buffer)

type IntPtnNode

type IntPtnNode struct {
	Value Token
}

func (*IntPtnNode) Loc

func (ptn *IntPtnNode) Loc() *Loc

func (*IntPtnNode) WriteTo

func (ptn *IntPtnNode) WriteTo(buf *bytes.Buffer)

type Interp

type Interp struct {
	Top *Module
}

func NewInterp

func NewInterp(top *Module) *Interp

func (*Interp) Eval

func (ip *Interp) Eval(ctx *Context, env *Env, code *CompiledCode) (Value, error)

type Iter

type Iter interface {
	Value
	Next() Value
}

func NewIter

func NewIter(val Value) Iter

func ValueToIter

func ValueToIter(v Value) (Iter, bool)

type LetStatNode

type LetStatNode struct {
	Let Loc
	Ptn PtnNode
	Eq  Loc
	Exp ExpNode
}

func (*LetStatNode) Loc

func (stat *LetStatNode) Loc() *Loc

func (*LetStatNode) WriteTo

func (stat *LetStatNode) WriteTo(buf *bytes.Buffer)

type List

type List struct {
	Value Value
	Next  *List
}

func NewList

func NewList(value Value) *List

func ValueToList

func ValueToList(v Value) (*List, bool)

func (*List) Cons

func (l *List) Cons(value Value) *List

func (*List) Desc

func (l *List) Desc() string

func (*List) Len

func (l *List) Len() int

func (*List) Type

func (l *List) Type() int

type ListExpNode

type ListExpNode struct {
	Elts EltListNode
}

func (*ListExpNode) Loc

func (exp *ListExpNode) Loc() *Loc

func (*ListExpNode) WriteTo

func (exp *ListExpNode) WriteTo(buf *bytes.Buffer)

type ListPtnNode

type ListPtnNode struct {
	Elts EltPtnListNode
}

func (*ListPtnNode) Loc

func (ptn *ListPtnNode) Loc() *Loc

func (*ListPtnNode) WriteTo

func (ptn *ListPtnNode) WriteTo(buf *bytes.Buffer)

type Loc

type Loc struct {
	Start Pos
	End   Pos
}

func NewLocAntlr

func NewLocAntlr(tok antlr.Token) Loc

type Module

type Module struct {
	Parent *Module
	Subs   map[string]*Module
	Name   string
	File   string
	Env    *Env
}
var RootModule *Module

func GetModule

func GetModule(path string) *Module

func NewModule

func NewModule(parent *Module, name string) *Module

func (*Module) AddAttr

func (m *Module) AddAttr(name string, value Value)

func (*Module) AddPrim

func (m *Module) AddPrim(name string,
	f func(*Context, []Value, int) (Value, error),
	arity int)

func (*Module) AddSub

func (m *Module) AddSub(sub *Module)

func (*Module) GetAttr

func (m *Module) GetAttr(name string) Value

func (*Module) Path

func (m *Module) Path() string

type Node

type Node interface {
	Loc() *Loc
	WriteTo(*bytes.Buffer)
}

type NoneExpNode

type NoneExpNode struct {
	// contains filtered or unexported fields
}

func (*NoneExpNode) Loc

func (exp *NoneExpNode) Loc() *Loc

func (*NoneExpNode) WriteTo

func (exp *NoneExpNode) WriteTo(buf *bytes.Buffer)

type ObjectAttr

type ObjectAttr struct {
	Name  string       `json:"name"`
	Value *ObjectValue `json:"value"`
}

func NewObjectAttr

func NewObjectAttr(name string, value *ObjectValue) *ObjectAttr

type ObjectCode

type ObjectCode struct {
	Id   int            `json:"id"`
	Syms []string       `json:"symbols"`
	Lits []*ObjectValue `json:"literals"`
	Ops  []int          `json:"opcodes"`
}

func NewObjectCode

func NewObjectCode(id int, ops []Opcode) *ObjectCode

func (*ObjectCode) AddLit

func (code *ObjectCode) AddLit(value *ObjectValue)

func (*ObjectCode) AddOp

func (code *ObjectCode) AddOp(op int)

func (*ObjectCode) AddSym

func (code *ObjectCode) AddSym(name string)

func (*ObjectCode) Decode

func (objCode *ObjectCode) Decode(file *ObjectFile)

type ObjectFile

type ObjectFile struct {
	Name     string        `json:"name"`
	Attrs    []*ObjectAttr `json:"attrs"`
	Codes    []*ObjectCode `json:"codes"`
	CodeVals map[int]*CompiledCode
	// contains filtered or unexported fields
}

func NewObjectFile

func NewObjectFile(name string) *ObjectFile

func UnmarshalObjectFile

func UnmarshalObjectFile(data []byte) (*ObjectFile, error)

func (*ObjectFile) AddAttr

func (file *ObjectFile) AddAttr(attr *ObjectAttr)

func (*ObjectFile) AddCode

func (file *ObjectFile) AddCode(code *ObjectCode)

func (*ObjectFile) AddCompiledCode

func (file *ObjectFile) AddCompiledCode(code *CompiledCode)

func (*ObjectFile) Decode

func (file *ObjectFile) Decode() *Module

func (*ObjectFile) Marshal

func (file *ObjectFile) Marshal() ([]byte, error)

type ObjectValue

type ObjectValue struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

func NewObjectValue

func NewObjectValue(ty string, value string) *ObjectValue

func NewObjectValueBool

func NewObjectValueBool(value bool) *ObjectValue

func NewObjectValueCode

func NewObjectValueCode(i int) *ObjectValue

func (*ObjectValue) Decode

func (value *ObjectValue) Decode(file *ObjectFile) Value

type Opcode

type Opcode = int

type Option

type Option struct {
	Value Value // nullable
}

func NewOption

func NewOption(v Value) *Option

func ValueToOption

func ValueToOption(v Value) (*Option, bool)

func (*Option) Desc

func (o *Option) Desc() string

func (*Option) Type

func (o *Option) Type() int

type ParamListNode

type ParamListNode struct {
	Names []Token
	Sep   []Loc
}

func (*ParamListNode) Loc

func (params *ParamListNode) Loc() *Loc

func (*ParamListNode) NameStrs

func (params *ParamListNode) NameStrs() []string

func (*ParamListNode) WriteTo

func (params *ParamListNode) WriteTo(buf *bytes.Buffer)

type ParenExpNode

type ParenExpNode struct {
	Open  Loc
	Close Loc
	Exp   Node
}

func (*ParenExpNode) Loc

func (exp *ParenExpNode) Loc() *Loc

func (*ParenExpNode) WriteTo

func (exp *ParenExpNode) WriteTo(buf *bytes.Buffer)

type Pattern

type Pattern struct {
	Comp ptnComp
}

func NewPatternFromNode

func NewPatternFromNode(n PtnNode) *Pattern

func (*Pattern) Desc

func (p *Pattern) Desc() string

func (*Pattern) Eval

func (p *Pattern) Eval(env *Env, v Value) bool

func (*Pattern) Type

func (p *Pattern) Type() int

type Pos

type Pos struct {
	Line   int
	Col    int
	Offset int
}

type PrimFun

type PrimFun = func(*Context, []Value, int) (Value, error)

type Primitive

type Primitive struct {
	Func PrimFun
	// contains filtered or unexported fields
}

func NewPrim

func NewPrim(f func(*Context, []Value, int) (Value, error),
	arity int) *Primitive

func (*Primitive) Apply

func (prim *Primitive) Apply(interp *Interp, ctx *Context, env *Env) (Value, error)

func (*Primitive) Arity

func (prim *Primitive) Arity() int

func (*Primitive) Desc

func (prim *Primitive) Desc() string

func (*Primitive) Type

func (prim *Primitive) Type() int

type ProgCounter

type ProgCounter struct {
	Count  int
	Code   *CompiledCode
	Labels map[int]int
	// contains filtered or unexported fields
}

TODO: private

func NewProgCounter

func NewProgCounter(code *CompiledCode) ProgCounter

func (*ProgCounter) AddLabel

func (pc *ProgCounter) AddLabel(n int)

func (*ProgCounter) HasNext

func (pc *ProgCounter) HasNext() bool

func (*ProgCounter) Jump

func (pc *ProgCounter) Jump(n int)

func (*ProgCounter) Next

func (pc *ProgCounter) Next() int

type Program

type Program struct {
	Path string
	Code *CompiledCode
}

type PtnNode

type PtnNode interface {
	Node
}

type Range

type Range struct {
	Start int
	End   int
	Close bool
}

func NewRange

func NewRange(start int, end int, close bool) *Range

func (*Range) Desc

func (r *Range) Desc() string

func (*Range) NewIter

func (r *Range) NewIter() Iter

func (*Range) Type

func (r *Range) Type() int

type RangeExpNode

type RangeExpNode struct {
	Left  ExpNode
	Op    Token
	Close bool
	Right ExpNode
}

func (*RangeExpNode) Loc

func (exp *RangeExpNode) Loc() *Loc

func (*RangeExpNode) WriteTo

func (exp *RangeExpNode) WriteTo(buf *bytes.Buffer)

type RangeIter

type RangeIter struct {
	// contains filtered or unexported fields
}

func (*RangeIter) Desc

func (iter *RangeIter) Desc() string

func (*RangeIter) Next

func (iter *RangeIter) Next() Value

func (*RangeIter) Type

func (iter *RangeIter) Type() int

type Ref

type Ref struct {
	Path string
	// contains filtered or unexported fields
}

func NewRef

func NewRef(path string, mod *Module) *Ref

func ValueToRef

func ValueToRef(v Value) (*Ref, bool)

func (*Ref) Desc

func (r *Ref) Desc() string

func (*Ref) Module

func (r *Ref) Module() *Module

func (*Ref) Type

func (r *Ref) Type() int

type RetStatNode

type RetStatNode struct {
	Ret Loc
	Exp ExpNode
}

func (*RetStatNode) Loc

func (stat *RetStatNode) Loc() *Loc

func (*RetStatNode) WriteTo

func (stat *RetStatNode) WriteTo(buf *bytes.Buffer)

type RuntimeError

type RuntimeError struct {
	Context *Context
	Type    int
	Reason  string
}

func NewInvalidArityError

func NewInvalidArityError(ctx *Context, nargs int) *RuntimeError

func NewKeyError

func NewKeyError(ctx *Context, name string) *RuntimeError

func NewRuntimeError

func NewRuntimeError(ctx *Context, ty int, reason string) *RuntimeError

func ValidateArity

func ValidateArity(ctx *Context, expected int, actual int) *RuntimeError

func (*RuntimeError) Error

func (err *RuntimeError) Error() string

type ShortDefStatNode

type ShortDefStatNode struct {
	Def    Loc
	Name   Token
	Open   Loc
	Params *ParamListNode
	Close  Loc
	Eq     Loc
	Exp    ExpNode
}

func (*ShortDefStatNode) Loc

func (stat *ShortDefStatNode) Loc() *Loc

func (*ShortDefStatNode) WriteTo

func (stat *ShortDefStatNode) WriteTo(buf *bytes.Buffer)

type SomeExpNode

type SomeExpNode struct {
	SomeLoc Loc
	Value   ExpNode
}

func (*SomeExpNode) Loc

func (exp *SomeExpNode) Loc() *Loc

func (*SomeExpNode) WriteTo

func (exp *SomeExpNode) WriteTo(buf *bytes.Buffer)

type Stack

type Stack struct {
	Locals []Value
	Index  int // -1 start
}

func NewStack

func NewStack(len int) Stack

func (*Stack) Inspect

func (s *Stack) Inspect()

func (*Stack) Pop

func (s *Stack) Pop()

func (*Stack) Push

func (s *Stack) Push(value Value)

func (*Stack) Set

func (s *Stack) Set(i int, value Value)

func (*Stack) Sharedet

func (s *Stack) Sharedet(i int) Value

func (*Stack) Top

func (s *Stack) Top() Value

func (*Stack) TopPop

func (s *Stack) TopPop() Value

type StatNode

type StatNode interface {
	Node
}

type StrExpNode

type StrExpNode struct {
	Value Token
}

func (*StrExpNode) Loc

func (exp *StrExpNode) Loc() *Loc

func (*StrExpNode) WriteTo

func (exp *StrExpNode) WriteTo(buf *bytes.Buffer)

type StrPtnNode

type StrPtnNode struct {
	Value Token
}

func (*StrPtnNode) Loc

func (ptn *StrPtnNode) Loc() *Loc

func (*StrPtnNode) WriteTo

func (ptn *StrPtnNode) WriteTo(buf *bytes.Buffer)

type String

type String struct {
	Value string
}

func NewString

func NewString(s string) *String

func ValueToString

func ValueToString(v Value) (*String, bool)

func (*String) Desc

func (s *String) Desc() string

func (*String) Type

func (s *String) Type() int

type Token

type Token struct {
	Loc  Loc
	Text string
}

func NewToken

func NewToken(loc Loc, text string) Token

func NewTokenAntlr

func NewTokenAntlr(tok antlr.Token) Token

type Tuple

type Tuple struct {
	Values []Value
}

func NewTuple

func NewTuple(v ...Value) *Tuple

func ValueToTuple

func ValueToTuple(v Value) (*Tuple, bool)

func (*Tuple) Desc

func (t *Tuple) Desc() string

func (*Tuple) Len

func (t *Tuple) Len() int

func (*Tuple) Type

func (t *Tuple) Type() int

type TupleExpNode

type TupleExpNode struct {
	Elts EltListNode
}

func (*TupleExpNode) Loc

func (exp *TupleExpNode) Loc() *Loc

func (*TupleExpNode) WriteTo

func (exp *TupleExpNode) WriteTo(buf *bytes.Buffer)

type TuplePtnNode

type TuplePtnNode struct {
	Elts EltPtnListNode
}

func (*TuplePtnNode) Loc

func (ptn *TuplePtnNode) Loc() *Loc

func (*TuplePtnNode) WriteTo

func (ptn *TuplePtnNode) WriteTo(buf *bytes.Buffer)

type Unit

type Unit struct{}

func (*Unit) Desc

func (u *Unit) Desc() string

func (*Unit) Type

func (u *Unit) Type() int

type UnitExpNode

type UnitExpNode struct {
	Open  Loc
	Close Loc
}

func (*UnitExpNode) Loc

func (exp *UnitExpNode) Loc() *Loc

func (*UnitExpNode) WriteTo

func (exp *UnitExpNode) WriteTo(buf *bytes.Buffer)

type UnitPtnNode

type UnitPtnNode struct {
	Open  Loc
	Close Loc
}

func (*UnitPtnNode) Loc

func (ptn *UnitPtnNode) Loc() *Loc

func (*UnitPtnNode) WriteTo

func (ptn *UnitPtnNode) WriteTo(buf *bytes.Buffer)

type Value

type Value interface {
	Type() int
	Desc() string
}

func GetModuleAttr

func GetModuleAttr(ms []*Module, name string) Value

func LibCoreId

func LibCoreId(ctx *Context, args []Value, nargs int) (Value, error)

func LibCoreShow

func LibCoreShow(ctx *Context, args []Value, nargs int) (Value, error)

func Run

func Run(file string, code *CompiledCode) (Value, error)

type VarExpNode

type VarExpNode struct {
	Name Token
}

func NewVarExpNode

func NewVarExpNode(name Token) VarExpNode

func (*VarExpNode) Loc

func (exp *VarExpNode) Loc() *Loc

func (*VarExpNode) WriteTo

func (exp *VarExpNode) WriteTo(buf *bytes.Buffer)

type VarPtnNode

type VarPtnNode struct {
	Name Token
}

func (*VarPtnNode) Loc

func (ptn *VarPtnNode) Loc() *Loc

func (*VarPtnNode) WriteTo

func (ptn *VarPtnNode) WriteTo(buf *bytes.Buffer)

Directories

Path Synopsis
cmd
lang
lib

Jump to

Keyboard shortcuts

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