compiler

package
v0.0.0-...-203d217 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApplyFunctionInside func(fn object.Object, args []object.Object) object.Object
View Source
var Builtins = []*object.Builtin{}

Builtins tüm builtin fonksiyonları içeren global değişken

View Source
var PreBuiltFunctions = builtins

Functions

func BasicAuth

func BasicAuth(h httprouter.Handle, requiredUser, requiredPassword string) httprouter.Handle

func CompileToELF

func CompileToELF(filename string, output string) error

CompileFile compiles an O language file to a portable ELF binary

func DebugInterface

func DebugInterface(a interface{})

func HashKeyExist

func HashKeyExist(hash *object.Hash, hashpair object.HashPair) bool

func MakeStruct

func MakeStruct(typeName string, vals map[string]interface{}) interface{}

func ParseJson

func ParseJson(data []byte) *object.Hash

func ParseJsonToString

func ParseJsonToString(data object.Object) string

func ParseXML

func ParseXML(file string) *object.Hash

Types

type Bytecode

type Bytecode struct {
	Instructions code.Instructions
	Constants    []object.Object
}

Bytecode contains the Instructions our Compiler generated and the Constants the Compiler evaluated

type CompilationScope

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

CompilationScope - Before we start compiling a function's body (enter a new scope) we push a new CompilationScope on to the scopes stack. While compiling inside this scope, the emit method of the compiler will modify only the fields of the current CompilationScope. Once we're done compiling the function, we leave the scope by popping it off the scopes stack and putting the instructions in a new *object.CompiledFunction

type Compiler

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

Compiler defines our compiler with instructions which hold the generated bytecode, constants which serve as our constant pool, and the last and previous instructions

func New

func New() *Compiler

New creates and returns a pointer to a Compiler with initialized instructions & constants

func NewWithState

func NewWithState(s *SymbolTable, constants []object.Object) *Compiler

NewWithState creates a new compiler with the passed in symbol table and constants (needed in REPL)

func (*Compiler) Bytecode

func (c *Compiler) Bytecode() *vm.Bytecode

Bytecode returns a pointer to a Bytecode intialized with our compilers instructions & constants

func (*Compiler) Compile

func (c *Compiler) Compile(node ast.Node) error

Compile walks the AST recursively and compiles nodes

func (*Compiler) Errors

func (c *Compiler) Errors() []string

func (*Compiler) RegisterBuiltin

func (c *Compiler) RegisterBuiltin(name string, builtin *object.Builtin)

RegisterBuiltin düzeltmesi

type ELF64Header

type ELF64Header struct {
	Magic      [4]byte
	Class      byte
	Endian     byte
	EVers      byte
	OSABI      byte
	ABIVersion byte
	Padding    [7]byte
	Type       uint16
	Machine    uint16
	Version    uint32
	Entry      uint64
	PHOff      uint64
	SHOff      uint64
	Flags      uint32
	EHSize     uint16
	PHOffSize  uint16
	PHOffNum   uint16
	SHOffSize  uint16
	SHOffNum   uint16
	SHStrNdx   uint16
}

ELF structures

type ELF64ProgramHeader

type ELF64ProgramHeader struct {
	Type     uint32
	Flags    uint32
	Offset   uint64
	VAddr    uint64
	PAddr    uint64
	FileSize uint64
	MemSize  uint64
	Align    uint64
}

type ELFCompiler

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

ELFCompiler generates portable ELF binaries from O language source code

func NewELFCompiler

func NewELFCompiler() *ELFCompiler

NewELFCompiler creates a new ELF compiler instance

func (*ELFCompiler) Compile

func (c *ELFCompiler) Compile(node ast.Node) error

Compile compiles an AST node to machine code

func (*ELFCompiler) GenerateELF

func (c *ELFCompiler) GenerateELF() ([]byte, error)

GenerateELF creates a complete ELF binary

type ELFSymbol

type ELFSymbol struct {
	Name   string
	Offset int64
	Type   ELFSymbolType
}

ELFSymbol represents a symbol in the binary

type ELFSymbolType

type ELFSymbolType int
const (
	SymFunction ELFSymbolType = iota
	SymVariable
	SymString
)

type EmittedInstruction

type EmittedInstruction struct {
	Opcode   code.Opcode
	Position int
}

EmittedInstruction represents an instruction through an opcode and it's position

type ServerFunction

type ServerFunction struct {
	Name   string
	Router *gin.Engine
}

func NewServer

func NewServer(name string) *ServerFunction

func (*ServerFunction) RouterGenerator

func (fn *ServerFunction) RouterGenerator(obj object.Object) *ServerFunction

func (*ServerFunction) Server

func (fn *ServerFunction) Server(args ...object.Object) object.Object

type Symbol

type Symbol struct {
	Name  string
	Scope SymbolScope
	Index int
}

Symbol - Holds all the necessary info about a symbol - Name, Scope, and Index

type SymbolScope

type SymbolScope string

SymbolScope - Type alias for a string. Used in a Symbol to define it's scope.

const (
	GlobalScope   SymbolScope = "GLOBAL"
	LocalScope    SymbolScope = "LOCAL"
	BuiltinScope  SymbolScope = "BUILTIN"
	FreeScope     SymbolScope = "FREE"
	FunctionScope SymbolScope = "FUNCTION"
)

Define all our scopes

type SymbolTable

type SymbolTable struct {
	Outer       *SymbolTable
	FreeSymbols []Symbol
	// contains filtered or unexported fields
}

SymbolTable holds a "store" which is a map of strings to Symbols, an int of number of definitions, and "Outer" which defines it's parent scope

func NewEnclosedSymbolTable

func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable

NewEnclosedSymbolTable takes an outer parent symbol table and returns a pointer to the new enclosed SymbolTable after attaching the outer parent to the new one

func NewSymbolTable

func NewSymbolTable() *SymbolTable

NewSymbolTable creates and returns a pointer to a symbol table initialized with a "store"

func (*SymbolTable) Define

func (s *SymbolTable) Define(name string) Symbol

Define takes a name and creates a symbol with the name, an index, and assigns scope. It then assigns the symbol to the SymbolTable's store, increases numDefinitions and returns the symbol.

func (*SymbolTable) DefineBuiltin

func (s *SymbolTable) DefineBuiltin(index int, name string) Symbol

DefineBuiltin creates and returns a symbol within builtin scope

func (*SymbolTable) DefineFunctionName

func (s *SymbolTable) DefineFunctionName(name string) Symbol

DefineFunctionName creates a new Symbol with FunctionScope and adds it to the s.store

func (*SymbolTable) Resolve

func (s *SymbolTable) Resolve(name string) (Symbol, bool)

Resolve takes a name, looks for it in the SymbolTable's store, and returns it if found along with a boolean representing whether it was found

Jump to

Keyboard shortcuts

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