about summary refs log tree commit diff
path: root/pkg/lang/vm/text/errors.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-31 14:41:19 +0000
committerMel <einebeere@gmail.com>2022-08-31 14:41:19 +0000
commit00adb146a20d2985fd014c92b9d5cc07e0ab09b9 (patch)
tree6c3e06a6c95c5a6ec4a7654b42599c5aa7a0aa81 /pkg/lang/vm/text/errors.go
parentaeb63ade341572bb307f23ff7c501c48957cc7d4 (diff)
downloadjinx-00adb146a20d2985fd014c92b9d5cc07e0ab09b9.tar.zst
jinx-00adb146a20d2985fd014c92b9d5cc07e0ab09b9.zip
Add FromData function to create values easier
Diffstat (limited to 'pkg/lang/vm/text/errors.go')
0 files changed, 0 insertions, 0 deletions
tiline */ .highlight .cp { color: #E5E5E5 } /* Comment.Preproc */ .highlight .cpf { color: #0F0 } /* Comment.PreprocFile */ .highlight .c1 { color: #0F0 } /* Comment.Single */ .highlight .cs { color: #0F0 } /* Comment.Special */ .highlight .gd { color: #DDD } /* Generic.Deleted */ .highlight .ge { color: #DDD } /* Generic.Emph */ .highlight .ges { color: #DDD } /* Generic.EmphStrong */ .highlight .gr { color: #DDD } /* Generic.Error */ .highlight .gh { color: #DDD } /* Generic.Heading */ .highlight .gi { color: #DDD } /* Generic.Inserted */ .highlight .go { color: #DDD } /* Generic.Output */ .highlight .gp { color: #DDD } /* Generic.Prompt */ .highlight .gs { color: #DDD } /* Generic.Strong */ .highlight .gu { color: #DDD } /* Generic.Subheading */ .highlight .gt { color: #DDD } /* Generic.Traceback */ .highlight .kc { color: #F00 } /* Keyword.Constant */ .highlight .kd { color: #F00 } /* Keyword.Declaration */ .highlight .kn { color: #F00 } /* Keyword.Namespace */ .highlight .kp { color: #F00 } /* Keyword.Pseudo */ .highlight .kr { color: #F00 } /* Keyword.Reserved */ .highlight .kt { color: #EE82EE } /* Keyword.Type */ .highlight .ld { color: #DDD } /* Literal.Date */ .highlight .m { color: #F0F } /* Literal.Number */ .highlight .s { color: #87CEEB } /* Literal.String */ .highlight .na { color: #DDD } /* Name.Attribute */ .highlight .nb { color: #DDD } /* Name.Builtin */ .highlight .nc { color: #DDD } /* Name.Class */ .highlight .no { color: #7FFFD4 } /* Name.Constant */ .highlight .nd { color: #DDD } /* Name.Decorator */ .highlight .ni { color: #DDD } /* Name.Entity */ .highlight .ne { color: #DDD } /* Name.Exception */ .highlight .nf { color: #FF0 } /* Name.Function */ .highlight .nl { color: #DDD } /* Name.Label */ .highlight .nn { color: #DDD } /* Name.Namespace */ .highlight .nx { color: #DDD } /* Name.Other */ .highlight .py { color: #DDD } /* Name.Property */ .highlight .nt { color: #DDD } /* Name.Tag */ .highlight .nv { color: #EEDD82 } /* Name.Variable */ .highlight .ow { color: #F00 } /* Operator.Word */ .highlight .pm { color: #DDD } /* Punctuation.Marker */ .highlight .w { color: #DDD } /* Text.Whitespace */ .highlight .mb { color: #F0F } /* Literal.Number.Bin */ .highlight .mf { color: #F0F } /* Literal.Number.Float */ .highlight .mh { color: #F0F } /* Literal.Number.Hex */ .highlight .mi { color: #F0F } /* Literal.Number.Integer */ .highlight .mo { color: #F0F } /* Literal.Number.Oct */ .highlight .sa { color: #87CEEB } /* Literal.String.Affix */ .highlight .sb { color: #87CEEB } /* Literal.String.Backtick */ .highlight .sc { color: #87CEEB } /* Literal.String.Char */ .highlight .dl { color: #87CEEB } /* Literal.String.Delimiter */ .highlight .sd { color: #87CEEB } /* Literal.String.Doc */ .highlight .s2 { color: #87CEEB } /* Literal.String.Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
package code

import (
	"bytes"
	"encoding/binary"
	"math"
	"strings"
)

type Raw []byte

type Code struct {
	code      Raw
	debugInfo DebugInfo
}

func New(code Raw, info DebugInfo) Code {
	return Code{
		code:      code,
		debugInfo: info,
	}
}

func (c *Code) Len() int {
	return len(c.code)
}

func (c *Code) Code() Raw {
	return c.code
}

func (c *Code) Debug() *DebugInfo {
	return &c.debugInfo
}

func (c *Code) GetOp(at int) (Op, int) {
	return Op(c.code[at]), 1
}

func (c *Code) GetUint(at int) (uint64, int) {
	advance := 8
	x := binary.LittleEndian.Uint64(c.code[at : at+advance])
	return x, advance
}

func (c *Code) GetInt(at int) (int64, int) {
	x, advance := c.GetUint(at)
	return int64(x), advance
}

func (c *Code) GetFloat(at int) (float64, int) {
	x, advance := c.GetUint(at)
	return math.Float64frombits(x), advance
}

func (c *Code) GetString(at int) (string, int) {
	advance := 0
	reader := bytes.NewReader(c.code[at:])
	builder := strings.Builder{}

	for {
		r, size, err := reader.ReadRune()
		advance += size

		if err != nil {
			break
		}

		if r == 0 {
			break
		}

		builder.WriteRune(r)
	}

	return builder.String(), advance
}