litecode

package module
v0.0.0-...-f89bd9f Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: Unlicense Imports: 14 Imported by: 0

README

litecode

Semi-working Luau bytecode interpreter

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(filename string, oLevel ...uint8) (bytecode []byte, err error)

func Deserialise

func Deserialise(data []byte) (deserialised, error)

func MakeFn

func MakeFn(name string, fn func(args Args) (r Rets, err error)) [2]any

func ToString

func ToString(a any) string

Types

type Args

type Args struct {
	Co   *Coroutine
	List []any
	// contains filtered or unexported fields
}

func (*Args) CheckNextArg

func (a *Args) CheckNextArg()

func (*Args) GetAny

func (a *Args) GetAny(optV ...any) (arg any)

func (*Args) GetBool

func (a *Args) GetBool(optV ...bool) bool

func (*Args) GetBuffer

func (a *Args) GetBuffer(optV ...*Buffer) *Buffer

func (*Args) GetCoroutine

func (a *Args) GetCoroutine(optV ...*Coroutine) *Coroutine

func (*Args) GetFunction

func (a *Args) GetFunction(optV ...Function) Function

func (*Args) GetNumber

func (a *Args) GetNumber(optV ...float64) float64

func (*Args) GetString

func (a *Args) GetString(optV ...string) string

func (*Args) GetTable

func (a *Args) GetTable(optV ...*Table) *Table

func (*Args) GetVector

func (a *Args) GetVector(optV ...Vector) Vector

type Buffer

type Buffer []byte

type Coroutine

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

func Load

func Load(module deserialised, filepath string, o uint8, env map[any]any, requireCache ...map[string]Rets) (co Coroutine, cancel func())

func (*Coroutine) Error

func (co *Coroutine) Error(err error)

func (*Coroutine) Resume

func (co *Coroutine) Resume(args ...any) (r Rets, err error)

type Function

type Function *func(co *Coroutine, args ...any) (r Rets, err error)

Functions and Tables are used as pointees normally, as they need to be hashed

func Fn

func Fn(f func(co *Coroutine, args ...any) (r Rets, err error)) Function

type Rets

type Rets []any

type Status

type Status uint8

Functions and Tables are used as pointees normally, as they need to be hashed

const (
	CoSuspended Status = iota
	CoRunning
	CoNormal
	CoDead
)

type Table

type Table struct {
	Array []any
	Hash  map[any]any
	// contains filtered or unexported fields
}

Q why are tables like this

A:

1: the reference implementation of tables is too complex: rehashing and resizing is a pain but not too bad, array boundaries are worse and I don't want 1.5k lines of code just for that, and Go does a resizing-like thing automatically with slices anyway

2: the way nodes are implemented works well in C++ and not in Go (plus I don't know if it's actually O(1) for node lookups??)

3: rehashing etc is slower than just using a slice... somehow. most of this program is between 10-20x slower than the reference implementation, but the tables (which were previously like 50x slower) are now only like 2-3x slower for large allocations (bench/largealloc.luau)

4: having an array part is actually nice for iteration and for large tables (as opposed to the lua4 way, where it's *just* a hash part), the way it's done here is simpler though we have to move stuff around and between the array and node parts more explicitly

5: very weird quirks arise from table length implementations etc. the nil stuff can easily be forgiven, it's the stuff with creating a table and getting a length afterwards (see tests/clear.luau) that is fucking devilish; this is one of the few parts that puts Luau, as the language at the top of my favourites list, in jeopardy

6: we don't actually break *that* much compatibility doing it this way, right??

7: if anyone tells you tables are simple THEY ARE LYING, CALL THEM OUT ON THEIR SHIT

func NewTable

func NewTable(toHash [][2]any) *Table

func (*Table) ForceSet

func (t *Table) ForceSet(k, v any)

func (*Table) Get

func (t *Table) Get(k any) any

func (*Table) GetHash

func (t *Table) GetHash(k any) any

func (*Table) Iter

func (t *Table) Iter() iter.Seq2[any, any]

1.23 goes hard

func (*Table) Len

func (t *Table) Len() int

O(1) length, bitchesss

func (*Table) Set

func (t *Table) Set(k, v any) error

func (*Table) SetArray

func (t *Table) SetArray(i int, v any)

func (*Table) SetHash

func (t *Table) SetHash(k, v any)

func (*Table) String

func (t *Table) String() (s string)

dbg

type Vector

type Vector [4]float32

Jump to

Keyboard shortcuts

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