internal

package
v0.0.0-...-229c56e Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TmplMatching = template.Must(template.New("matching").Parse(`
	// {{.LocalFn }}
	if bytes.Equal(args[:4], {{.Sel}}) {
		var err error
		if len(args) != 4 + {{.CdLen}} {
			return 1
		}
		{{range $i, $e := .ConvFns}}x{{$i}}, err := stylus.{{$e}}(args[4+({{$i}}*32):4+32+({{$i}}*32)])
		if err != nil {
			return 1
		}
		{{end}}{{if .HasErrReturn}}rd{{.LocalFn}}, err :{{else}}err {{end}}= sr.{{.LocalFn}}({{range $i, $e := .ConvFns}}x{{$i}},{{end}})
		if err != nil {
			if d, ok := stylus.IsStylusErr(err); ok {
				stylus.Rd = d
			}
			return 1
		} else {
			return 0
		}
		if rc != 0 {
			return rc
		}
		{{if .HasErrReturn}}
		stylus.Rd = append(stylus.Rd, {{.ReturnFn}}(rd{{.LocalFn}})...){{end}}
	}`,
))
View Source
var TmplPreamble = template.Must(template.New("preamble").Parse(`package main

// Code generated by github.com/af-afk/stylus version {{.Rev}}

import (
	"reflect"
	"bytes"

	stylusHost "github.com/af-afk/stylus/host"
	"github.com/af-afk/stylus"
)

//go:inline
func unsafePtr(x any) int32 {
	return *(*int32)(reflect.ValueOf(x).UnsafePointer())
}

//export user_entrypoint
func userEntrypoint(cdlen int32) int32 {
	stylusHost.PayForMemoryGrow(0)
	args := make([]byte, cdlen)
	stylusHost.ReadArgs(unsafePtr(&args))
	var rc int32
	defer func() {
		stylusHost.StorageFlushCache(false)
		stylusHost.WriteResult(unsafePtr(&stylus.Rd), int32(len(stylus.Rd)))
	}()
	if len(args) < 4 {
		return 1
	}
	var sr {{.StructName}}{{range .Args}}
	sr.{{.Name}} = {{.SetupFn}}(){{end}}
	defer func() {
		if r := recover(); r != nil {
			rc = 1
		}
	}()
	`,
))

Functions

func Generate

func Generate(out, werr io.Writer, fst *token.FileSet, files ...File) error

func OutputMatching

func OutputMatching(w io.Writer, localFn string, sel []byte, convFns []string, returnFn string, hasErrReturn bool) error

OutputMatching template code to the generated file. Takes the local function to do conversion from, the selector computed as keccak256, all of the conversion functions needed for each argument, and whether the contract actually returns a separate field for error.

func OutputPreamble

func OutputPreamble(w io.Writer, name string, args ...PreambleField) error

Types

type File

type File struct {
	Name  string
	Decls []ast.Decl
}

type PreambleField

type PreambleField struct {
	Name, SetupFn string
}

Jump to

Keyboard shortcuts

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