interpreter

package
v0.0.0-...-ef6f610 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BUILTIN_MATH the built in math system function
	BUILTIN_MATH string = "--builtin-do-math!"
	// BUILTIN_COMPARE comparison functions
	BUILTIN_COMPARE string = "--builtin-do-compare!"
	// BUILTIN_COMPARE_ARITHMETIC arithmetic comparison functions
	BUILTIN_COMPARE_ARITHMETIC string = "--builtin-do-compare-arithmetic!"
	// BUILTIN_BOOL boolean algebra functions
	BUILTIN_BOOL string = "--builtin-do-bool!"
	// BUILTIN_BITWISE bitwise functions
	BUILTIN_BITWISE string = "--builtin-do-bitwise!"
)
View Source
const (
	// USE include function
	USE string = "use"
	// TYPE type function
	TYPE string = "type"
	// MAP_ACCESS map access function
	MAP_ACCESS string = "[]"
	// FREE object store free function
	FREE string = "free"
	// EXEC_FILE current file
	EXEC_FILE string = "EXEC-FILE"
	// SELF current process id
	SELF string = "self"
)

noinspection GoSnakeCaseUsage

Variables

View Source
var BasePath string

BasePath base path from which to import stdlib

View Source
var LibBasePath string

LibBasePath path from which to import libraries

View Source
var Nothing = Node{
	Value:    0,
	NodeType: 0,
}

Nothing represents an empty return (int 0)

Functions

func CopyVariableState

func CopyVariableState(variables, ctx *map[string]Node)

CopyVariableState copy the variable state to another map

func DumpNode

func DumpNode(node Node) string

DumpNode returns the string representation of a node

func EnsureSingleType

func EnsureSingleType(val *Node, nth int, nt NodeType, who string)

EnsureSingleType ensures the variable type of the parameter for a native function is valid

func EnsureType

func EnsureType(val *[]Node, nth int, nt NodeType, who string)

EnsureType ensures the variable type of the parameter for a native function is valid

func EnsureTypes

func EnsureTypes(val *[]Node, nth int, nt []NodeType, who string)

EnsureTypes ensures the variable type of the parameter for a native function is valid

func Hash

func Hash(node Node) (string, error)

Hash returns md5 hash taken from any object

func LoadObject

func LoadObject(key int) (interface{}, bool)

LoadObject load an object from the object store by its ptr

func ReplaceEnd

func ReplaceEnd(s, old, new string, n int) string

ReplaceEnd replaces a substring in a string starting from the end

func Rev

func Rev(s string) string

Rev reserves a string

func StoreObject

func StoreObject(val interface{}) int

StoreObject store an object and return a pseudo ptr to it

Types

type FnLiteral

type FnLiteral struct {
	Parameters []string
	Body       []parser.Node
	Context    map[string]Node
}

FnLiteral a function literal (block)

type ListNode

type ListNode struct {
	Values []Node
}

ListNode a list value

type MacroDef

type MacroDef struct {
	Parameters []MacroParameter
	Body       []parser.Node
}

MacroDef definition of a macro function

type MacroParameter

type MacroParameter struct {
	Parameter string
	Literal   bool
}

MacroParameter parameter of a macro function

type MapNode

type MapNode struct {
	Values map[string]Node
}

MapNode a map node

type Node

type Node struct {
	Value    interface{}
	NodeType NodeType
}

Node a variable node

func AtomNode

func AtomNode(val string) Node

AtomNode returns an interpreter.Node from a string

func BoolNode

func BoolNode(val bool) Node

BoolNode returns an interpreter.Node from a bool

func DoVariableCall

func DoVariableCall(node parser.Node, val Node, variables *map[string]Node) Node

DoVariableCall calls a fn variable

func FloatNode

func FloatNode(val float64) Node

FloatNode returns an interpreter.Node from a float64

func IntNode

func IntNode(val int) Node

IntNode returns an interpreter.Node from an int

func NodeList

func NodeList(val []Node) Node

NodeList returns an interpreter.Node from a []Node

func NodeMap

func NodeMap(val map[string]Node) Node

NodeMap returns an interpreter.Node from a map[string]Node

func OptionNode

func OptionNode(val Node, err bool) Node

OptionNode return an optional node

func Run

func Run(nodes []parser.Node, variables *map[string]Node) (returnVal Node)

Run run an AST

func StringNode

func StringNode(val string) Node

StringNode returns an interpreter.Node from a string

func (*Node) Bigger

func (node *Node) Bigger(compareTo Node) bool

Bigger > operator for Node

func (*Node) Smaller

func (node *Node) Smaller(compareTo Node) bool

Smaller < operator for Node

type NodeType

type NodeType uint8

NodeType a variable type

const (
	// NODETYPE_INT int variable type
	NODETYPE_INT NodeType = 0
	// NODETYPE_FLOAT float variable type
	NODETYPE_FLOAT NodeType = 1
	// NODETYPE_STRING string variable type
	NODETYPE_STRING NodeType = 2
	// NODETYPE_BOOL bool variable type
	NODETYPE_BOOL NodeType = 3
	// NODETYPE_ATOM atom variable type
	NODETYPE_ATOM NodeType = 4
	// NODETYPE_FN function literal
	NODETYPE_FN NodeType = 5
	// NODETYPE_LIST list type
	NODETYPE_LIST NodeType = 6
	// NODETYPE_MAP map type
	NODETYPE_MAP NodeType = 7
	// NODETYPE_STRUCT struct type
	NODETYPE_STRUCT NodeType = 8
	// NODETYPE_MACRO macro type
	NODETYPE_MACRO NodeType = 9
)

func (NodeType) String

func (nt NodeType) String() string

type StructDef

type StructDef struct {
	Parameters []string
}

StructDef struct definition

Jump to

Keyboard shortcuts

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