Skip to content

Latest commit

 

History

History
2399 lines (1595 loc) · 47.7 KB

File metadata and controls

2399 lines (1595 loc) · 47.7 KB

ast

import "github.com/dev-kas/virtlang-go/v4/ast"

Index

type ArrayLiteral

type ArrayLiteral struct {
    Elements []Expr
    SourceMetadata
}

func (*ArrayLiteral) GetSourceMetadata

func (o *ArrayLiteral) GetSourceMetadata() SourceMetadata

func (*ArrayLiteral) GetType

func (o *ArrayLiteral) GetType() NodeType

type BinaryExpr

type BinaryExpr struct {
    LHS      Expr
    RHS      Expr
    Operator BinaryOperator
    SourceMetadata
}

func (*BinaryExpr) GetSourceMetadata

func (b *BinaryExpr) GetSourceMetadata() SourceMetadata

func (*BinaryExpr) GetType

func (b *BinaryExpr) GetType() NodeType

type BinaryOperator

type BinaryOperator string

const (
    Plus     BinaryOperator = "+"
    Minus    BinaryOperator = "-"
    Multiply BinaryOperator = "*"
    Divide   BinaryOperator = "/"
    Modulo   BinaryOperator = "%"
)

type BreakStmt

type BreakStmt struct {
    SourceMetadata
}

func (*BreakStmt) GetSourceMetadata

func (r *BreakStmt) GetSourceMetadata() SourceMetadata

func (*BreakStmt) GetType

func (r *BreakStmt) GetType() NodeType

type CallExpr

type CallExpr struct {
    Args   []Expr
    Callee Expr
    SourceMetadata
}

func (*CallExpr) GetSourceMetadata

func (c *CallExpr) GetSourceMetadata() SourceMetadata

func (*CallExpr) GetType

func (c *CallExpr) GetType() NodeType

type Class

type Class struct {
    Name        string
    Body        []Stmt
    Constructor *ClassMethod
    SourceMetadata
}

func (*Class) GetSourceMetadata

func (c *Class) GetSourceMetadata() SourceMetadata

func (*Class) GetType

func (c *Class) GetType() NodeType

type ClassMethod

type ClassMethod struct {
    Name     string
    Body     []Stmt
    Params   []string
    IsPublic bool
    SourceMetadata
}

func (*ClassMethod) GetSourceMetadata

func (c *ClassMethod) GetSourceMetadata() SourceMetadata

func (*ClassMethod) GetType

func (c *ClassMethod) GetType() NodeType

type ClassProperty

type ClassProperty struct {
    Name     string
    Value    Expr
    IsPublic bool
    SourceMetadata
}

func (*ClassProperty) GetSourceMetadata

func (c *ClassProperty) GetSourceMetadata() SourceMetadata

func (*ClassProperty) GetType

func (c *ClassProperty) GetType() NodeType

type CompareExpr

type CompareExpr struct {
    LHS      Expr
    RHS      Expr
    Operator CompareOperator
    SourceMetadata
}

func (*CompareExpr) GetSourceMetadata

func (c *CompareExpr) GetSourceMetadata() SourceMetadata

func (*CompareExpr) GetType

func (c *CompareExpr) GetType() NodeType

type CompareOperator

type CompareOperator string

const (
    LessThanEqual    CompareOperator = "<="
    LessThan         CompareOperator = "<"
    GreaterThanEqual CompareOperator = ">="
    GreaterThan      CompareOperator = ">"
    Equal            CompareOperator = "=="
    NotEqual         CompareOperator = "!="
)

type ContinueStmt

type ContinueStmt struct {
    SourceMetadata
}

func (*ContinueStmt) GetSourceMetadata

func (r *ContinueStmt) GetSourceMetadata() SourceMetadata

func (*ContinueStmt) GetType

func (r *ContinueStmt) GetType() NodeType

type Declaration

type Declaration interface {
    Stmt
    // contains filtered or unexported methods
}

type DestructureArrayElement

type DestructureArrayElement struct {
    Default             Expr
    Name                string
    DeconstructChildren DestructurePattern
    Skipped             bool
    SourceMetadata
}

func (*DestructureArrayElement) GetSourceMetadata

func (v *DestructureArrayElement) GetSourceMetadata() SourceMetadata

func (*DestructureArrayElement) GetType

func (v *DestructureArrayElement) GetType() NodeType

type DestructureArrayPattern

type DestructureArrayPattern struct {
    Elements []DestructureArrayElement
    Rest     *string
    SourceMetadata
}

func (*DestructureArrayPattern) GetSourceMetadata

func (v *DestructureArrayPattern) GetSourceMetadata() SourceMetadata

func (*DestructureArrayPattern) GetType

func (v *DestructureArrayPattern) GetType() NodeType

type DestructureDeclaration

type DestructureDeclaration struct {
    Constant bool
    Pattern  DestructurePattern
    Value    Expr
    SourceMetadata
}

func (*DestructureDeclaration) GetSourceMetadata

func (v *DestructureDeclaration) GetSourceMetadata() SourceMetadata

func (*DestructureDeclaration) GetType

func (v *DestructureDeclaration) GetType() NodeType

type DestructureObjectPattern

type DestructureObjectPattern struct {
    Properties []DestructureObjectProperty
    Rest       *string
    SourceMetadata
}

func (*DestructureObjectPattern) GetSourceMetadata

func (v *DestructureObjectPattern) GetSourceMetadata() SourceMetadata

func (*DestructureObjectPattern) GetType

func (v *DestructureObjectPattern) GetType() NodeType

type DestructureObjectProperty

type DestructureObjectProperty struct {
    Key                 string
    Default             Expr
    Name                string
    DeconstructChildren DestructurePattern
    SourceMetadata
}

func (*DestructureObjectProperty) GetSourceMetadata

func (v *DestructureObjectProperty) GetSourceMetadata() SourceMetadata

func (*DestructureObjectProperty) GetType

func (v *DestructureObjectProperty) GetType() NodeType

type DestructurePattern

type DestructurePattern interface {
    Expr
    // contains filtered or unexported methods
}

type Expr

type Expr interface {
    GetType() NodeType
    GetSourceMetadata() SourceMetadata
}

type FnDeclaration

type FnDeclaration struct {
    Params    []string
    Name      string
    Body      []Stmt
    Anonymous bool
    SourceMetadata
}

func (*FnDeclaration) GetSourceMetadata

func (f *FnDeclaration) GetSourceMetadata() SourceMetadata

func (*FnDeclaration) GetType

func (f *FnDeclaration) GetType() NodeType

type Identifier

type Identifier struct {
    Symbol string
    SourceMetadata
}

func (*Identifier) GetSourceMetadata

func (i *Identifier) GetSourceMetadata() SourceMetadata

func (*Identifier) GetType

func (i *Identifier) GetType() NodeType

type IfStatement

type IfStatement struct {
    Body      []Stmt
    Condition Expr
    Else      []Stmt         // Optional else block
    ElseIf    []*IfStatement // Optional else-if branches
    SourceMetadata
}

func (*IfStatement) GetSourceMetadata

func (i *IfStatement) GetSourceMetadata() SourceMetadata

func (*IfStatement) GetType

func (i *IfStatement) GetType() NodeType

type LogicalExpr

type LogicalExpr struct {
    LHS      *Expr // Optional LHS for unary operators
    RHS      Expr
    Operator LogicalOperator
    SourceMetadata
}

func (*LogicalExpr) GetSourceMetadata

func (l *LogicalExpr) GetSourceMetadata() SourceMetadata

func (*LogicalExpr) GetType

func (l *LogicalExpr) GetType() NodeType

type LogicalOperator

type LogicalOperator string

const (
    LogicalAND           LogicalOperator = "&&"
    LogicalOR            LogicalOperator = "||"
    LogicalNilCoalescing LogicalOperator = "??"
    LogicalNOT           LogicalOperator = "!"
)

type MemberExpr

type MemberExpr struct {
    Object   Expr
    Value    Expr
    Computed bool
    SourceMetadata
}

func (*MemberExpr) GetSourceMetadata

func (m *MemberExpr) GetSourceMetadata() SourceMetadata

func (*MemberExpr) GetType

func (m *MemberExpr) GetType() NodeType

type NodeType

type NodeType int

const (
    ProgramNode NodeType = iota
    VarDeclarationNode
    FnDeclarationNode
    IfStatementNode
    ClassNode
    ClassMethodNode
    ClassPropertyNode
    WhileLoopNode
    VarAssignmentExprNode
    TryCatchStmtNode
    MemberExprNode
    ReturnStmtNode
    BreakStmtNode
    ContinueStmtNode
    CallExprNode
    PropertyNode
    ObjectLiteralNode
    ArrayLiteralNode
    NumericLiteralNode
    StringLiteralNode
    IdentifierNode
    CompareExprNode
    BinaryExprNode
    LogicalExprNode
    DestructureDeclarationNode
    DestructureArrayPatternNode
    DestructureArrayElementNode
    DestructureObjectPatternNode
    DestructureObjectPropertyNode
)

func (NodeType) String

func (n NodeType) String() string

type NumericLiteral

type NumericLiteral struct {
    Value float64
    SourceMetadata
}

func (*NumericLiteral) GetSourceMetadata

func (n *NumericLiteral) GetSourceMetadata() SourceMetadata

func (*NumericLiteral) GetType

func (n *NumericLiteral) GetType() NodeType

type ObjectLiteral

type ObjectLiteral struct {
    Properties []Property
    SourceMetadata
}

func (*ObjectLiteral) GetSourceMetadata

func (o *ObjectLiteral) GetSourceMetadata() SourceMetadata

func (*ObjectLiteral) GetType

func (o *ObjectLiteral) GetType() NodeType

type Program

type Program struct {
    Stmts []Stmt
    SourceMetadata
}

func (*Program) GetSourceMetadata

func (p *Program) GetSourceMetadata() SourceMetadata

func (*Program) GetType

func (p *Program) GetType() NodeType

type Property

type Property struct {
    Key   string
    Value Expr
    SourceMetadata
}

func (*Property) GetSourceMetadata

func (p *Property) GetSourceMetadata() SourceMetadata

func (*Property) GetType

func (p *Property) GetType() NodeType

type ReturnStmt

type ReturnStmt struct {
    Value Expr
    SourceMetadata
}

func (*ReturnStmt) GetSourceMetadata

func (r *ReturnStmt) GetSourceMetadata() SourceMetadata

func (*ReturnStmt) GetType

func (r *ReturnStmt) GetType() NodeType

type SourceMetadata

type SourceMetadata struct {
    StartLine   int
    StartColumn int
    EndLine     int
    EndColumn   int
    Filename    string
}

type Stmt

type Stmt interface {
    GetType() NodeType
    GetSourceMetadata() SourceMetadata
}

type StringLiteral

type StringLiteral struct {
    Value string
    SourceMetadata
}

func (*StringLiteral) GetSourceMetadata

func (s *StringLiteral) GetSourceMetadata() SourceMetadata

func (*StringLiteral) GetType

func (s *StringLiteral) GetType() NodeType

type TryCatchStmt

type TryCatchStmt struct {
    Try      []Stmt
    Catch    []Stmt
    CatchVar string
    SourceMetadata
}

func (*TryCatchStmt) GetSourceMetadata

func (t *TryCatchStmt) GetSourceMetadata() SourceMetadata

func (*TryCatchStmt) GetType

func (t *TryCatchStmt) GetType() NodeType

type VarAssignmentExpr

type VarAssignmentExpr struct {
    Assignee Expr
    Value    Expr
    SourceMetadata
}

func (*VarAssignmentExpr) GetSourceMetadata

func (v *VarAssignmentExpr) GetSourceMetadata() SourceMetadata

func (*VarAssignmentExpr) GetType

func (v *VarAssignmentExpr) GetType() NodeType

type VarDeclaration

type VarDeclaration struct {
    Constant   bool
    Identifier string
    Value      Expr
    SourceMetadata
}

func (*VarDeclaration) GetSourceMetadata

func (v *VarDeclaration) GetSourceMetadata() SourceMetadata

func (*VarDeclaration) GetType

func (v *VarDeclaration) GetType() NodeType

type WhileLoop

type WhileLoop struct {
    Body      []Stmt
    Condition Expr
    SourceMetadata
}

func (*WhileLoop) GetSourceMetadata

func (w *WhileLoop) GetSourceMetadata() SourceMetadata

func (*WhileLoop) GetType

func (w *WhileLoop) GetType() NodeType

debugger

import "github.com/dev-kas/virtlang-go/v4/debugger"

Index

Variables

Define what can be debugged

var Debuggables = map[ast.NodeType]struct{}{
    ast.VarDeclarationNode:    {},
    ast.VarAssignmentExprNode: {},
    ast.IfStatementNode:       {},
    ast.WhileLoopNode:         {},
    ast.ReturnStmtNode:        {},
    ast.ContinueStmtNode:      {},
    ast.BreakStmtNode:         {},
    ast.TryCatchStmtNode:      {},
    ast.CallExprNode:          {},
    ast.FnDeclarationNode:     {},
    ast.ClassNode:             {},
    ast.ClassMethodNode:       {},
    ast.ClassPropertyNode:     {},
    ast.ProgramNode:           {},
}

type BreakpointManager

type BreakpointManager struct {
    Breakpoints map[string]bool
}

func NewBreakpointManager

func NewBreakpointManager() *BreakpointManager

func (*BreakpointManager) Clear

func (bm *BreakpointManager) Clear()

func (*BreakpointManager) Has

func (bm *BreakpointManager) Has(file string, line int) bool

func (*BreakpointManager) Remove

func (bm *BreakpointManager) Remove(file string, line int)

func (*BreakpointManager) Set

func (bm *BreakpointManager) Set(file string, line int)

type CallStack

type CallStack []StackFrame

func DeepCopyCallStack

func DeepCopyCallStack(stack CallStack) CallStack

DeepCopyCallStack creates a deep copy of the call stack

type Debugger

type Debugger struct {
    BreakpointManager BreakpointManager
    Environment       *environment.Environment
    State             State
    CurrentFile       string
    CurrentLine       int
    CallStack         CallStack
    Snapshots         Snapshots
    // contains filtered or unexported fields
}

func NewDebugger

func NewDebugger(env *environment.Environment) *Debugger

func (*Debugger) Continue

func (d *Debugger) Continue() error

func (*Debugger) IsDebuggable

func (d *Debugger) IsDebuggable(nodeType ast.NodeType) bool

func (*Debugger) Pause

func (d *Debugger) Pause() error

func (*Debugger) PopFrame

func (d *Debugger) PopFrame()

func (*Debugger) PushFrame

func (d *Debugger) PushFrame(frame StackFrame)

func (*Debugger) ShouldStop

func (d *Debugger) ShouldStop(filename string, line int) bool

func (*Debugger) StepInto

func (d *Debugger) StepInto() error

func (*Debugger) StepOut

func (d *Debugger) StepOut() error

func (*Debugger) StepOver

func (d *Debugger) StepOver() error

func (*Debugger) TakeSnapshot

func (d *Debugger) TakeSnapshot()

func (*Debugger) WaitIfPaused

func (d *Debugger) WaitIfPaused(nodeType ast.NodeType)

type Snapshot

type Snapshot struct {
    Stack CallStack
    Env   *environment.Environment
}

type Snapshots

type Snapshots []Snapshot

type StackFrame

type StackFrame struct {
    Name     string
    Filename string
    Line     int
}

type State

type State string

const (
    RunningState  State = "running"
    PausedState   State = "paused"
    SteppingState State = "stepping"
)

type StepType

type StepType string

const (
    StepInto StepType = "step_into"
    StepOver StepType = "step_over"
    StepOut  StepType = "step_out"
)

environment

import "github.com/dev-kas/virtlang-go/v4/environment"

Index

type Environment

type Environment struct {
    Parent    *Environment
    Variables map[string]*shared.RuntimeValue
    Constants map[string]struct{}
    Global    bool
    Mutex     sync.RWMutex
}

func DeepCopy

func DeepCopy(env *Environment) *Environment

DeepCopy creates a deep copy of the environment

func NewEnvironment

func NewEnvironment(fork *Environment) *Environment

func (*Environment) AssignVar

func (e *Environment) AssignVar(name string, value shared.RuntimeValue) (*shared.RuntimeValue, *errors.RuntimeError)

func (*Environment) DeclareVar

func (e *Environment) DeclareVar(name string, value shared.RuntimeValue, constant bool) (*shared.RuntimeValue, *errors.RuntimeError)

func (*Environment) LookupVar

func (e *Environment) LookupVar(name string) (*shared.RuntimeValue, *errors.RuntimeError)

func (*Environment) Resolve

func (e *Environment) Resolve(varname string) (*Environment, *errors.RuntimeError)

errors

import "github.com/dev-kas/virtlang-go/v4/errors"

Index

type InternalCommunicationProtocol

type InternalCommunicationProtocol struct {
    Type   InternalCommunicationProtocolTypes
    RValue *shared.RuntimeValue
}

type InternalCommunicationProtocolTypes

--- InternalCommunicationProtocol ---

type InternalCommunicationProtocolTypes int

const (
    ICP_Return InternalCommunicationProtocolTypes = iota
    ICP_Continue
    ICP_Break
)

type LexerError

--- LexerError ---

type LexerError struct {
    Character rune     // The problematic character
    Pos       Position // Position (Line/Col) of the character
    Message   string   // Optional: for specific messages like "unclosed comment"
}

func NewLexerError

func NewLexerError(char rune, pos Position) *LexerError

NewLexerError creates a new LexerError for an unexpected character (Message will be empty).

func NewLexerErrorf

func NewLexerErrorf(pos Position, charForContext rune, format string, args ...interface{}) *LexerError

NewLexerErrorf creates a new LexerError with a custom message. 'charForContext' can be the opening delimiter (e.g., '/' for unclosed comment) or 0 if not relevant. The Message field will be populated by the formatted string.

func (*LexerError) Error

func (e *LexerError) Error() string

type ParserError

--- ParserError --- Often, ParserError is very similar to SyntaxError.

type ParserError struct {
    Token   string   // The literal of the unexpected token
    Start   Position // Start position of the token
    End     Position // End position of the token
    Message string   // Optional: More specific message about why it's an error
}

func NewParserError

func NewParserError(tokenLiteral string, start, end Position) *ParserError

NewParserError creates a new ParserError for an unexpected token.

func NewParserErrorf

func NewParserErrorf(start, end Position, format string, args ...interface{}) *ParserError

NewParserErrorf creates a new ParserError with a custom formatted message.

func (*ParserError) Error

func (e *ParserError) Error() string

type Position

type Position struct {
    Line int // 1-based line number
    Col  int // 1-based column number
}

type RuntimeError

--- RuntimeError ---

type RuntimeError struct {
    Message                       string
    InternalCommunicationProtocol *InternalCommunicationProtocol
}

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

type SyntaxError

--- SyntaxError ---

type SyntaxError struct {
    Expected string   // What was expected
    Got      string   // What was actually found (e.g., token literal or type)
    Start    Position // Start position of the problematic syntax
    End      Position // End position of the problematic syntax
    Message  string   // Optional additional message
}

func NewSyntaxError

func NewSyntaxError(expected string, gotLiteral string, start, end Position) *SyntaxError

NewSyntaxError creates a new SyntaxError. 'gotLiteral' is often the token.Literal that caused the error. 'start' and 'end' define the span of the problematic token/syntax.

func NewSyntaxErrorf

func NewSyntaxErrorf(start, end Position, format string, args ...interface{}) *SyntaxError

NewSyntaxErrorf creates a new SyntaxError with a custom message.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

evaluator

import "github.com/dev-kas/virtlang-go/v4/evaluator"

Index

func Evaluate

func Evaluate(astNode ast.Stmt, env *environment.Environment, dbgr *debugger.Debugger) (*shared.RuntimeValue, *errors.RuntimeError)

`dbgr` circulates the evaluator

helpers

import "github.com/dev-kas/virtlang-go/v4/helpers"

Index

func IsTruthy

func IsTruthy(value *shared.RuntimeValue) bool

IsTruthy determines whether a VirtLang RuntimeValue should be considered "truthy" in boolean contexts (like if statements and while loops).

Truthiness rules: - Boolean: true is truthy, false is falsy - Number: non-zero is truthy, zero is falsy - String: non-empty is truthy, empty is falsy - Nil: always falsy - Object: always truthy (even empty objects) - Array: always truthy (even empty arrays) - Function: always truthy - NativeFN: always truthy - ClassInstance: always truthy - Class: always truthy - Unknown: always truthy

lexer

import "github.com/dev-kas/virtlang-go/v4/lexer"

Index

Variables

var KEYWORDS = map[string]TokenType{
    "let":      Let,
    "const":    Const,
    "fn":       Fn,
    "if":       If,
    "else":     Else,
    "while":    WhileLoop,
    "try":      Try,
    "catch":    Catch,
    "return":   Return,
    "break":    Break,
    "continue": Continue,
    "class":    Class,
    "public":   Public,
    "private":  Private,
}

var REVERSE_KEYWORDS = make(map[TokenType]string, len(KEYWORDS))

func IsAlpha

func IsAlpha(r rune) bool

func IsAlphaNumeric

func IsAlphaNumeric(r rune) bool

func IsBinaryOperator

func IsBinaryOperator(r rune) bool

func IsComparisonOperator

func IsComparisonOperator(r string) bool

func IsLogicalOperator

func IsLogicalOperator(r string) bool

func IsNumeric

func IsNumeric(r rune) bool

func IsSkippable

func IsSkippable(r rune) bool

func Stringify

func Stringify(t TokenType) string

func UnescapeString

func UnescapeString(s string) (string, error)

type Token

type Token struct {
    Type      TokenType
    Literal   string
    StartLine int
    StartCol  int
    EndLine   int
    EndCol    int
}

func NewToken

func NewToken(value string, tokenType TokenType, startLine, startCol, endLine, endCol int) Token

func Tokenize

func Tokenize(srcCode string) ([]Token, *errors.LexerError)

type TokenType

type TokenType int

const (
    Number          TokenType = iota // 0 - 9
    Identifier                       // a - z A - Z 0 - 9 _ $
    Equals                           // =
    BinOperator                      // / * + _
    OParen                           // (
    CParen                           // )
    Let                              // let
    Const                            // const
    SemiColon                        // ;
    Comma                            // ,
    Colon                            // :
    OBrace                           // {
    CBrace                           // }
    OBracket                         // [
    CBracket                         // ]
    Dot                              // .
    Fn                               // fn
    ComOperator                      // < == > != <= >=
    If                               // if
    Else                             // else
    String                           // '...' "..."
    WhileLoop                        // while
    Comment                          // /*...*/ //...
    Try                              // try
    Catch                            // catch
    Return                           // return
    Break                            // break
    Continue                         // continue
    Class                            // class
    Public                           // public
    Private                          // private
    LogicalOperator                  // && || ?? !
    EOF                              // end of file
)

parser

import "github.com/dev-kas/virtlang-go/v4/parser"

Index

type Parser

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

func New

func New(filename string) *Parser

func (*Parser) ProduceAST

func (p *Parser) ProduceAST(srcCode string) (*ast.Program, error)

shared

import "github.com/dev-kas/virtlang-go/v4/shared"

Index

func Stringify

func Stringify(v ValueType) string

type RuntimeValue

type RuntimeValue struct {
    Type  ValueType
    Value any
}

type ValueType

type ValueType int

const (
    Nil ValueType = iota
    Number
    Boolean
    Object
    Array
    NativeFN
    Function
    String
    Class
    ClassInstance
)

values

import "github.com/dev-kas/virtlang-go/v4/values"

Index

func MK_ARRAY

func MK_ARRAY(value []shared.RuntimeValue) shared.RuntimeValue

func MK_BOOL

func MK_BOOL(value bool) shared.RuntimeValue

func MK_CLASS

func MK_CLASS(name string, body []ast.Stmt, constructor *ast.ClassMethod, declarationEnv *environment.Environment) shared.RuntimeValue

func MK_CLASS_INSTANCE

func MK_CLASS_INSTANCE(class *ClassValue, publics map[string]bool, data *environment.Environment) shared.RuntimeValue

func MK_NATIVE_FN

func MK_NATIVE_FN(fn NativeFunction) shared.RuntimeValue

func MK_NIL

func MK_NIL() shared.RuntimeValue

func MK_NUMBER

func MK_NUMBER(value float64) shared.RuntimeValue

func MK_OBJECT

func MK_OBJECT(value map[string]*shared.RuntimeValue) shared.RuntimeValue

func MK_STRING

func MK_STRING(value string) shared.RuntimeValue

type ClassInstanceValue

type ClassInstanceValue struct {
    Type    shared.ValueType
    Class   ClassValue
    Publics map[string]bool
    Data    *environment.Environment
}

type ClassValue

type ClassValue struct {
    Type           shared.ValueType
    Value          any
    Name           string
    Body           []ast.Stmt
    DeclarationEnv *environment.Environment
    Constructor    *ast.ClassMethod
}

type FunctionValue

type FunctionValue struct {
    Type           shared.ValueType
    Value          any
    Name           string
    Params         []string
    DeclarationEnv *environment.Environment
    Body           []ast.Stmt
}

type NativeFunction

type NativeFunction func(args []shared.RuntimeValue, env *environment.Environment) (*shared.RuntimeValue, *errors.RuntimeError)

testhelpers

import "github.com/dev-kas/virtlang-go/v4/internal/testhelpers"

Index

func EvalNode

func EvalNode(t *testing.T, node ast.Expr) *shared.RuntimeValue

EvalNode evaluates a manually constructed AST node directly

func ExpectParseError

func ExpectParseError(t *testing.T, src string)

ExpectParseError checks that parsing fails for invalid sources

func MustEval

func MustEval(t *testing.T, src string) (*shared.RuntimeValue, *environment.Environment)

MustEval evaluates source code fully (parse -> eval) and returns the value and environment

func MustParse

func MustParse(t *testing.T, src string) *ast.Program

MustParse parses source code and returns AST program or fails the test

Generated by gomarkdoc