Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeProgram(program *Program) ([]byte, error)
- type ApplicationSource
- type BinaryOperation
- func NewAssignExpressionOp(symbolRef int, expression *Expression) BinaryOperation
- func NewBindOp(symbolRef int, symbolType BinaryType) BinaryOperation
- func NewEnterScope() BinaryOperation
- func NewExitScopeOp() BinaryOperation
- func NewExpressionOp(expr *Expression) BinaryOperation
- func NewGrowOperation(symbolRef int, amount int, elemType BinaryType) BinaryOperation
- func NewIndexAssignOp(symbol int, index *Expression, expression *Expression) BinaryOperation
- func NewJumpIfNotOp(target int, condition *Expression) BinaryOperation
- func NewJumpIfOp(target int, condition *Expression) BinaryOperation
- func NewJumpOp(target int) BinaryOperation
- func NewReturnValueOp(value *Expression) BinaryOperation
- func NewShrinkOperation(symbolRef int, amount int) BinaryOperation
- type BinaryOperator
- type BinarySymbol
- type BinaryType
- type BinaryTypedValue
- type BuiltinFunction
- type CompileJob
- type Compiler
- type Composition
- type Expression
- func NewArrayExpression(elements []*BinaryTypedValue) *Expression
- func NewConstantExpression(value any, valueType BinaryType) *Expression
- func NewFunctionExpression(functionPC int, args []*FunctionArgument) *Expression
- func NewIndexIntoExpression(symbol int, index *Expression) *Expression
- func NewVSymbolExpression(symbolRef int) *Expression
- type ExpressionToken
- type ExpressionTreeNode
- type ExternalModuleSource
- type FunctionArgument
- type FunctionCallPlaceholder
- type FunctionDefinition
- type GSKeyword
- type ImportDirective
- type IntermediateExpression
- type IntermediateOperation
- type IntermediateOperationType
- type IntermediateProgram
- type IntermediateType
- type IntermediateVar
- type Kind
- type ModuleSource
- type ModuleSourceRootType
- type Numeric
- type Operation
- type OperationType
- type PartialExpression
- type PartialExpressionType
- type Program
- type Runtime
- type SourceFile
- type TokenType
- type TypeConstraint
- type UnparsedFunction
- type VSymbol
Constants ¶
const ( SINGULAR = 1 COMPOSITION = 2 )
Variables ¶
var APPLICATION_REGEX = regexp.MustCompile(`(?m)application (.*)$`)
var ARG_SPLIT_REGEX = regexp.MustCompile(`(?m)[\s,(]+([^,\s()]*)`)
var BOOLEAN_LITERAL = regexp.MustCompile(`(?m)^(?:true)?(?:false)?$`)
var BRANCH_TAG_REGEX = regexp.MustCompile(`(?m)@branch=([0-9a-zA-Z\.]*)`)
var CHAR_LITERAL = regexp.MustCompile(`(?mU)'.{1}'`)
var COMMENT_REGEX = regexp.MustCompile(`(?m)^//.*`)
var Compositions = []Composition{ { Type: BT_LIST, Pattern: regexp.MustCompile(`(?m)^List<(.*)>$`), Constraints: []TypeConstraint{VALID_TYPE}, }, { Type: BT_VECTOR, Pattern: regexp.MustCompile(`(?m)^Vector<(.*)>$`), Constraints: []TypeConstraint{NUMERIC}, }, { Type: BT_TENSOR, Pattern: regexp.MustCompile(`(?m)^Tensor<(.*)>$`), Constraints: []TypeConstraint{NUMERIC}, }, { Type: BT_MAP, Pattern: regexp.MustCompile(`(?m)^Map<(.*)\s*,\s*(.*)>$`), Constraints: []TypeConstraint{COMPARABLE, VALID_TYPE}, }, { Type: BT_POINTER, Pattern: regexp.MustCompile(`(?m)^\*(.*)$`), Constraints: []TypeConstraint{VALID_TYPE}, }, }
var DEBUG_DUMP_FQSC = true
var EMPTY_LINE_REGEX = regexp.MustCompile(`(?m)^\n`)
var EXTERNAL_DIRECTIVE_REGEX = regexp.MustCompile(`(?mU)external ([a-zA-Z]*) from "(.*)"`)
var EXTERNAL_SYMBOL_REGEX = regexp.MustCompile(`(?m)((?:[a-zA-Z#]{1}[a-zA-Z0-9]?)*)\.((?:[a-zA-Z]{1}[a-zA-Z0-9]?)*)`)
this regex matches any access to an external properties (for example db.Connect() will match with CG1 being the module name and CG2 being the property)
var FLOAT_LITERAL = regexp.MustCompile(`(?m)^\-?[0-9]+\.{1}[0-9]+$`)
var FOREACH_LINE_REGEX = regexp.MustCompile(`(?mU)foreach ([a-zA-z_]{1}[a-zA-Z0-9-_]*) in ([a-zA-z_]{1}[a-zA-Z0-9-_]*) {`)
matches foreach loop heads 'foreach element in list {' GS1 matches the local loop variable name GS2 martches the list being iterated over
var FOR_LINE_REGEX = regexp.MustCompile(`(?mU)for let ([a-zA-z_]{1}[a-zA-Z0-9-_]*): ([a-zA-Z0-9]*) = (.*); (.*);(.*) {`)
matches for loop heads 'for i: int32 = 0; i < 10; i++ {' G1 is the loop iterator name G2 is the loop iterator type G3 is the initial value of the iterator G4 is the loop condition G5 is the loop action (increment or decrement)
var FUNCTION_ARG_REGEX = regexp.MustCompile(`(?m)(\(.*\))`)
var FUNC_NAME_REGEX = regexp.MustCompile(`(?mU)func ([^#]*)\(`)
this package will contain the preprocessor for goscript
var FUNC_REGEX = regexp.MustCompile(`(?msU)func (#[a-zA-Z_]{1}[a-zA-Z0-9_]*)\((.*)\) (?:=> ([a-zA-Z0-9]*) )?{\n(.*)}\n>`)
var IMPORT_ALIAS_REGEX = regexp.MustCompile(`import "(.*)" as (.*)`)
var IMPORT_REGEX = regexp.MustCompile(`import "(.*)"\s*\n`)
var INTEGER_LITERAL = regexp.MustCompile(`(?m)^\-?[0-9]+$`)
var KEYWORDS = [...]GSKeyword{FOR, FOREACH, LET, FUNC, GSK_RETURN, STRUCT, CONST, BREAK, CLOSING_BRACKET}
iterable list of all keywords
var LET_LINE_REGEX = regexp.MustCompile(`(?m)let ([a-zA-z_]{1}[a-zA-Z0-9-_]*): ([a-zA-Z0-9<>]*)(?:[ \n]= (.*))?`)
matches let myvar: string = "dfg" lines G1 is the variable name G2 is the variable type G3 is the optional value that is assigned
var MULTILINE_STRING_LITERAL = MULTILINE_STRING_REGEX
var MULTILINE_STRING_REGEX = regexp.MustCompile(`(?Us)\x60.*\x60`)
var PRIORITY_OPS = []string{"*", "/"}
var RETURN_LINE_REGEX = regexp.MustCompile(`(?m)return\s?(.*)?$`)
match return statements 'return test' G1 matches the name of the symbol being returned
var SIMPLE_STRING_REGEX = regexp.MustCompile(`(?mU)".*[^\\]"`)
var STDPATH = "../../../goscript/gs_standard"
var STRING_LITERAL = SIMPLE_STRING_REGEX
regexes for all primitive literals
var SYMBOL_NAME = regexp.MustCompile(`(?m)[a-zA-Z_]{1}[a-zA-Z0-9_]*`)
regex that matches any symbol in goscript
var TESTS = "../../../goscript/gs_workspace"
var VENDORPATH = "../../../goscript/gs_vendor"
var VERSION_TAG_REGEX = regexp.MustCompile(`(?m)@version=([\^0-9\.]*)`)
Functions ¶
func EncodeProgram ¶
Types ¶
type ApplicationSource ¶
type ApplicationSource struct { ApplicationFile SourceFile // path to the main file Modules []*ModuleSource // list of local and standard libarary modules }
type BinaryOperation ¶
type BinaryOperation struct { Type OperationType `json:",omitempty" bson:",omitempty"` // which operation should be performed Args []any `json:",omitempty" bson:",omitempty"` // the arguments passed to the operation }
func NewAssignExpressionOp ¶
func NewAssignExpressionOp(symbolRef int, expression *Expression) BinaryOperation
func NewBindOp ¶
func NewBindOp(symbolRef int, symbolType BinaryType) BinaryOperation
func NewEnterScope ¶
func NewEnterScope() BinaryOperation
func NewExitScopeOp ¶
func NewExitScopeOp() BinaryOperation
func NewExpressionOp ¶
func NewExpressionOp(expr *Expression) BinaryOperation
func NewGrowOperation ¶
func NewGrowOperation(symbolRef int, amount int, elemType BinaryType) BinaryOperation
func NewIndexAssignOp ¶
func NewIndexAssignOp(symbol int, index *Expression, expression *Expression) BinaryOperation
func NewJumpIfNotOp ¶
func NewJumpIfNotOp(target int, condition *Expression) BinaryOperation
func NewJumpIfOp ¶
func NewJumpIfOp(target int, condition *Expression) BinaryOperation
func NewJumpOp ¶
func NewJumpOp(target int) BinaryOperation
func NewReturnValueOp ¶
func NewReturnValueOp(value *Expression) BinaryOperation
func NewShrinkOperation ¶
func NewShrinkOperation(symbolRef int, amount int) BinaryOperation
func (*BinaryOperation) String ¶
func (b *BinaryOperation) String() string
type BinaryOperator ¶
type BinaryOperator byte
const ( BO_CONSTANT BinaryOperator = 1 BO_PLUS BinaryOperator = 2 BO_MINUS BinaryOperator = 3 BO_MULTIPLY BinaryOperator = 4 BO_DIVIDE BinaryOperator = 5 BO_FUNCTION_CALL BinaryOperator = 6 // represents a function that returns a constant BO_VSYMBOL BinaryOperator = 7 BO_EQUALS BinaryOperator = 8 BO_GREATER BinaryOperator = 9 BO_LESSER BinaryOperator = 10 BO_GREATER_EQUALS BinaryOperator = 11 BO_LESSER_EQUALS BinaryOperator = 12 BO_INDEX_INTO BinaryOperator = 13 // indexes into an array BO_FUNCTION_CALL_PLACEHOLDER BinaryOperator = 14 BO_VSYMBOL_PLACEHOLDER BinaryOperator = 15 BO_BUILTIN_CALL BinaryOperator = 16 BO_NULLEXPR BinaryOperator = 17 )
func (BinaryOperator) String ¶
func (b BinaryOperator) String() string
type BinarySymbol ¶
type BinarySymbol struct { Name string `json:",omitempty" bson:",omitempty"` Value *BinaryTypedValue `json:",omitempty" bson:",omitempty"` }
type BinaryType ¶
type BinaryType byte
const ( BT_INT8 BinaryType = 1 BT_INT16 BinaryType = 2 BT_INT32 BinaryType = 3 BT_INT64 BinaryType = 4 BT_UINT8 BinaryType = 5 BT_UINT16 BinaryType = 6 BT_UINT32 BinaryType = 7 BT_UINT64 BinaryType = 8 BT_STRING BinaryType = 9 BT_CHAR BinaryType = 10 BT_BYTE BinaryType = 11 BT_FLOAT32 BinaryType = 12 BT_FLOAT64 BinaryType = 13 BT_ANY BinaryType = 14 BT_STRUCT BinaryType = 15 BT_BOOLEAN BinaryType = 16 BT_LIST BinaryType = 17 BT_NOTYPE BinaryType = 18 BT_EXPRESSION BinaryType = 19 BT_VECTOR BinaryType = 20 BT_TENSOR BinaryType = 21 BT_MAP BinaryType = 22 BT_POINTER BinaryType = 23 BT_NULL BinaryType = 24 )
func (BinaryType) String ¶
func (b BinaryType) String() string
type BinaryTypedValue ¶
type BinaryTypedValue struct { Type BinaryType `json:",omitempty" bson:",omitempty"` Value any `json:",omitempty" bson:",omitempty"` }
func (*BinaryTypedValue) String ¶
func (bv *BinaryTypedValue) String() string
type BuiltinFunction ¶
type BuiltinFunction byte
const ( BF_LEN BuiltinFunction = 1 BF_PRINT BuiltinFunction = 2 BF_PRINTLN BuiltinFunction = 3 BF_PRINTF BuiltinFunction = 4 BF_MIN BuiltinFunction = 5 BF_MAX BuiltinFunction = 6 BF_INPUT BuiltinFunction = 7 BF_INPUTLN BuiltinFunction = 8 BF_TOUINT8 BuiltinFunction = 9 BF_TOUINT16 BuiltinFunction = 10 BF_TOUINT32 BuiltinFunction = 11 BF_TOUINT64 BuiltinFunction = 12 BF_TOINT8 BuiltinFunction = 13 BF_TOINT16 BuiltinFunction = 14 BF_TOINT32 BuiltinFunction = 15 BF_TOINT64 BuiltinFunction = 16 BF_TOFLOAT32 BuiltinFunction = 17 BF_TOFLOAT64 BuiltinFunction = 18 BF_TOSTRING BuiltinFunction = 19 BF_TOCHAR BuiltinFunction = 20 BF_TOBYTE BuiltinFunction = 21 )
type CompileJob ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
func NewCompiler ¶
func NewCompiler() *Compiler
type Composition ¶
type Composition struct { Type BinaryType Pattern *regexp.Regexp Constraints []TypeConstraint }
type Expression ¶
type Expression struct { LeftExpression *Expression `json:",omitempty" bson:",omitempty"` RightExpression *Expression `json:",omitempty" bson:",omitempty"` Operator BinaryOperator `json:",omitempty" bson:",omitempty"` Value *BinaryTypedValue `json:",omitempty" bson:",omitempty"` Ref int `json:",omitempty" bson:",omitempty"` Args []*FunctionArgument `json:",omitempty" bson:",omitempty"` }
Expression represents an expression tree. If the expression is a constant, the left and right pointers wil be nil, while the opertor is BO_CONSTANT. In this case value is non nil and holds the constant value of the expression. If the expression is a function, the value will hold the function reference.
func NewArrayExpression ¶
func NewArrayExpression(elements []*BinaryTypedValue) *Expression
func NewConstantExpression ¶
func NewConstantExpression(value any, valueType BinaryType) *Expression
func NewFunctionExpression ¶
func NewFunctionExpression(functionPC int, args []*FunctionArgument) *Expression
func NewIndexIntoExpression ¶
func NewIndexIntoExpression(symbol int, index *Expression) *Expression
func NewVSymbolExpression ¶
func NewVSymbolExpression(symbolRef int) *Expression
func (*Expression) IsConstant ¶
func (e *Expression) IsConstant() bool
func (*Expression) IsFunction ¶
func (e *Expression) IsFunction() bool
func (*Expression) String ¶
func (e *Expression) String() string
type ExpressionToken ¶
func (*ExpressionToken) String ¶
func (e *ExpressionToken) String() string
type ExpressionTreeNode ¶
type ExpressionTreeNode struct { ID uint64 Left uint64 Right uint64 Operator BinaryOperator IsChild bool }
type ExternalModuleSource ¶
type ExternalModuleSource struct { Name string // module name URL string // url from which to clone the module Version string // version expression that must match the git tag version (empty=latest) Branch string // branch from which to get the version (empty=master) }
ExternalModuleSource will be used by the depgraph resolver to load this module
type FunctionArgument ¶
type FunctionArgument struct { Expression *Expression `json:",omitempty" bson:",omitempty"` SymbolRef int `json:",omitempty" bson:",omitempty"` }
type FunctionCallPlaceholder ¶
type FunctionCallPlaceholder struct { Name string SymbolName []string Args []*Expression }
type FunctionDefinition ¶
type FunctionDefinition struct { Name string Accepts []*IntermediateVar Returns IntermediateType Operations []*IntermediateOperation }
func (*FunctionDefinition) String ¶
func (f *FunctionDefinition) String() string
type ImportDirective ¶
type ImportDirective struct { RootType ModuleSourceRootType // which root path the module should be imported from Name string // name of the module to be imported RawDirective string // the unprocessed directive ImportPath string // the import path of the module without the root prefix Alias string // the alias in the import directive }
type IntermediateExpression ¶
type IntermediateExpression struct { Left *IntermediateExpression Right *IntermediateExpression Operator BinaryOperator Value *BinaryTypedValue // only set when the expression is a constant Ref int Args []*FunctionArgument }
type IntermediateOperation ¶
type IntermediateOperation struct { Type IntermediateOperationType Args []any }
type IntermediateOperationType ¶
type IntermediateOperationType byte
const ( IM_NOP IntermediateOperationType = 0 IM_ASSIGN IntermediateOperationType = 1 IM_FOR IntermediateOperationType = 2 IM_CLOSING_BRACKET IntermediateOperationType = 3 IM_CALL IntermediateOperationType = 4 IM_BREAK IntermediateOperationType = 5 IM_RETURN IntermediateOperationType = 6 IM_FOREACH IntermediateOperationType = 7 IM_EXPRESSION IntermediateOperationType = 8 )
type IntermediateProgram ¶
type IntermediateProgram struct { Entrypoint FunctionDefinition Functions []*FunctionDefinition }
type IntermediateType ¶
type IntermediateType struct { Type BinaryType KeyType *IntermediateType ValueType *IntermediateType IsComposed bool }
type IntermediateVar ¶
type IntermediateVar struct { Name string Type IntermediateType }
type ModuleSource ¶
type ModuleSource struct { Name string // name of the module Path string // actual path of the module relative to its root ImportPath string // the path using which this module can be imported (without its prefix) RootType ModuleSourceRootType // type of the root this module can be found under Files []SourceFile // paths to all the files in the module Hash string // the hash uniquely identifying this module Content string // merged content of all files (happens in preprocessor) Imports map[string]*ImportDirective // map of the aliased module name to the module import }
type ModuleSourceRootType ¶
type ModuleSourceRootType byte
const ( VENDOR ModuleSourceRootType = 1 // modules that have this type will be searched in the vendor directory STANDARD ModuleSourceRootType = 2 // modules that have this type will be searched in the standard library LOCAL ModuleSourceRootType = 3 // modules that have this type will be searched locally in your project )
type Operation ¶
type Operation struct { Type OperationType Args []any }
type OperationType ¶
type OperationType byte
const ( ASSIGN OperationType = 1 // assign an expression resolution to a symbol INDEX_ASSIGN OperationType = 2 // assign an expression resolution to a an index of an array symbol BIND OperationType = 3 // binds a symbol to the current scope RETURN OperationType = 4 // return a value EXPRESSION OperationType = 5 // call a function without assigning its return value to anything ENTER_SCOPE OperationType = 6 // enters a a new scope EXIT_SCOPE OperationType = 7 // exits the current scope JUMP OperationType = 8 // jumps to the address in arg0 JUMP_IF OperationType = 9 // jumps to the address in arg1 if the condition in arg0 is true JUMP_IF_NOT OperationType = 10 // jumps to the address in arg1 if the condition in arg0 is false GROW OperationType = 11 // grows the array symbol in arg0 by the amount of indices in arg1 SHRINK OperationType = 12 // shrinks the array symbol in arg0 by the amount of indices in arg1 )
type PartialExpression ¶
type PartialExpression struct {
IsOperator bool // otherwise is assumed to be a value of some kind
}
type PartialExpressionType ¶
type PartialExpressionType byte
const ( OPERATOR PartialExpressionType = 1 CONSTANT PartialExpressionType = 2 SYMBOL PartialExpressionType = 3 )
type Program ¶
type Program struct { Operations []BinaryOperation SymbolTableSize int }
func (*Program) EncodeBSON ¶
type Runtime ¶
type Runtime struct { SymbolTable []*BinaryTypedValue SymbolScopeStack [][]int // [scope depth][symbols] ProgramCounter int Program Program }
func NewRuntime ¶
func NewRuntime() *Runtime
func (*Runtime) Exec ¶
Exec will reset the runtime and then run the specified program until it completes
func (*Runtime) ResolveExpression ¶
func (r *Runtime) ResolveExpression(e *Expression) *BinaryTypedValue
ResolveExpression will recursively resolve the expression to a typed value.
type SourceFile ¶
type SourceFile struct { Path string // path to the source file Content string // content of the source file Imports map[string]*ImportDirective // aliased imports only set in the main file }
type TypeConstraint ¶
type TypeConstraint byte
const ( UNCONSTRAINED TypeConstraint = 1 VALID_TYPE TypeConstraint = 2 UNCOMPOSED TypeConstraint = 3 NUMERIC TypeConstraint = 4 COMPARABLE TypeConstraint = 5 )
type UnparsedFunction ¶
type VSymbol ¶
type VSymbol struct { Name string Value any Type BinaryType }