Visitar URL original
Smirk.Core.Bytecode
smirk
Copyright(c) Nadia Yvette Chambers 2026
LicenseApache-2.0
Safe HaskellNone
LanguageGHC2021

Smirk.Core.Bytecode

Description

Defines the low-level virtual machine bytecode instruction set (Opcode) used by the Pike-style non-backtracking / thread-stepped VM in VM. Includes relative jumping, nondeterministic thread branching (OpSplit), capture slot registers (OpSaveStart, OpSaveEnd), and lookaround subprograms.

Synopsis

Documentation

data Opcode Source #

Low-level bytecode instruction for the Smirk regex virtual machine.

Constructors

OpChar !Char

Match a single literal character

OpClass !CharClass

Match a character class or set

OpAnchor !Anchor

Assert a zero-width anchor condition

OpSplit !Int !Int

Fork execution: try relative offset 1, alternative at offset 2

OpJump !Int

Unconditional relative jump by specified offset

OpSaveStart !Int

Save current input position as start of capture group $n$

OpSaveEnd !Int

Save current input position as end of capture group $n$

OpAssertLookahead !(Vector Opcode) !Bool

Zero-width lookahead assertion: subprogram and polarity

OpAssertLookbehind !(Vector Opcode) !Bool

Zero-width lookbehind assertion: subprogram and polarity

OpMatchBackRef !Int

Match dynamic slice previously captured by group $n$

OpMatch

Successful match reached; terminate thread

Instances

Instances details
Eq Opcode Source # 
Instance details

Defined in Smirk.Core.Bytecode

Methods

(==) :: Opcode -> Opcode -> Bool

(/=) :: Opcode -> Opcode -> Bool

Generic Opcode Source # 
Instance details

Defined in Smirk.Core.Bytecode

Associated Types

type Rep Opcode 
Instance details

Defined in Smirk.Core.Bytecode

type Rep Opcode = D1 ('MetaData "Opcode" "Smirk.Core.Bytecode" "smirk-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "OpChar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char)) :+: C1 ('MetaCons "OpClass" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CharClass))) :+: (C1 ('MetaCons "OpAnchor" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Anchor)) :+: (C1 ('MetaCons "OpSplit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpJump" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))))) :+: ((C1 ('MetaCons "OpSaveStart" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "OpSaveEnd" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpAssertLookahead" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector Opcode)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))) :+: (C1 ('MetaCons "OpAssertLookbehind" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector Opcode)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)) :+: (C1 ('MetaCons "OpMatchBackRef" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpMatch" 'PrefixI 'False) (U1 :: Type -> Type)))))

Methods

from :: Opcode -> Rep Opcode x

to :: Rep Opcode x -> Opcode

Show Opcode Source # 
Instance details

Defined in Smirk.Core.Bytecode

Methods

showsPrec :: Int -> Opcode -> ShowS

show :: Opcode -> String

showList :: [Opcode] -> ShowS

type Rep Opcode Source # 
Instance details

Defined in Smirk.Core.Bytecode

type Rep Opcode = D1 ('MetaData "Opcode" "Smirk.Core.Bytecode" "smirk-0.1.0.0-inplace" 'False) (((C1 ('MetaCons "OpChar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char)) :+: C1 ('MetaCons "OpClass" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 CharClass))) :+: (C1 ('MetaCons "OpAnchor" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Anchor)) :+: (C1 ('MetaCons "OpSplit" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpJump" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))))) :+: ((C1 ('MetaCons "OpSaveStart" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: (C1 ('MetaCons "OpSaveEnd" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpAssertLookahead" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector Opcode)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)))) :+: (C1 ('MetaCons "OpAssertLookbehind" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Vector Opcode)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)) :+: (C1 ('MetaCons "OpMatchBackRef" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :+: C1 ('MetaCons "OpMatch" 'PrefixI 'False) (U1 :: Type -> Type)))))

type Program = Vector Opcode Source #

Compiled bytecode sequence indexed as a contiguous vector.

data Regex Source #

Complete compiled regular expression ready for VM execution.

Constructors

Regex 

Fields

  • originalPattern :: !Text

    Original PCRE source pattern string

  • program :: !Program

    Compiled bytecode instruction vector

  • groupNames :: !(Map Text Int)

    Mapping from named capture groups to 1-based indices

  • maxGroupIndex :: !Int

    Highest capture group index allocated in the pattern

Instances

Instances details
Eq Regex Source # 
Instance details

Defined in Smirk.Core.Bytecode

Methods

(==) :: Regex -> Regex -> Bool

(/=) :: Regex -> Regex -> Bool

Generic Regex Source # 
Instance details

Defined in Smirk.Core.Bytecode

Associated Types

type Rep Regex 
Instance details

Defined in Smirk.Core.Bytecode

type Rep Regex = D1 ('MetaData "Regex" "Smirk.Core.Bytecode" "smirk-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Regex" 'PrefixI 'True) ((S1 ('MetaSel ('Just "originalPattern") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "program") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Program)) :*: (S1 ('MetaSel ('Just "groupNames") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map Text Int)) :*: S1 ('MetaSel ('Just "maxGroupIndex") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))))

Methods

from :: Regex -> Rep Regex x

to :: Rep Regex x -> Regex

Show Regex Source # 
Instance details

Defined in Smirk.Core.Bytecode

Methods

showsPrec :: Int -> Regex -> ShowS

show :: Regex -> String

showList :: [Regex] -> ShowS

type Rep Regex Source # 
Instance details

Defined in Smirk.Core.Bytecode

type Rep Regex = D1 ('MetaData "Regex" "Smirk.Core.Bytecode" "smirk-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Regex" 'PrefixI 'True) ((S1 ('MetaSel ('Just "originalPattern") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text) :*: S1 ('MetaSel ('Just "program") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Program)) :*: (S1 ('MetaSel ('Just "groupNames") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map Text Int)) :*: S1 ('MetaSel ('Just "maxGroupIndex") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))))