Пример #1
0
package rift

import (
	"fmt"

	"github.com/hialin/hialin/nex"
	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("rift")

type funcSignature struct {
	name      string
	arguments []string
	function  fn
}

var (
	ErrEmpty          = fmt.Errorf("Cannot run empty rift code body")
	ErrNoSuchFunction = fmt.Errorf("Cannot find rift function with this name")
	ErrBadArguments   = fmt.Errorf("Bad rift function arguments")
)

var operations = make(map[string]funcSignature)

func run(ctx nex.Nex, code []nex.Nex) error {
	if len(code) == 0 {
		return ErrEmpty
	}
	funcname := code[0]
	args := code[1:]
Пример #2
0
import (
	"image"
	"image/color"
	"io/ioutil"
	"os"
	"path/filepath"
	"unicode"

	"github.com/hialin/hialin/trace"

	"github.com/golang/freetype"
	"github.com/golang/freetype/truetype"
	"golang.org/x/image/math/fixed"
)

var tlog = trace.New("assets")

type em float32

// Vec2 exported
type Vec2 [2]float32

// Vec3 exported
type Vec3 [3]float32

const (
	tabWidth              = 4
	leadingFactor float64 = 1.2

	lowRune   rune = 32
	highRune  rune = 127
Пример #3
0
	"github.com/hialin/hialin/parse"
	"github.com/hialin/hialin/trace"
)

// TODO: go client renderer for the current protocol
// TODO: Hdm new protocol with client
// 		- at init: send font data + complete scene tree
// 		- with tests
// TODO: Description language for:
// 		1. layout and visual style
// 		2. parsing and creating interpretations
// TODO: rift with (xpath/jquery) language for manipulating and displaying nodes
// TODO: nex scanner, lexer
// TODO: parse and nicely display grammars in client

var tlog = trace.New("main")

var cfgFileName = "config.json"
var serverAddress = "localhost:7512"
var singleProcess = true

func main() {
	defer tlog.FuncLog(tlog.Func("main"))

	cpuProfile := flag.String("cpu-profile", "", "write cpu profile to file")
	isServerProcess := flag.Bool("s", false, "start hialin server only")

	flag.Parse()

	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
Пример #4
0
package hlgl

import (
	mgl "github.com/go-gl/mathgl/mgl32"

	"github.com/hialin/hialin/assets"
	"github.com/hialin/hialin/trace"

	"github.com/hialin/hialin/client/llgl"
)

var tlog = trace.New("hlgl")

var (
	fpsCounter FpsCounter

	state = struct {
		angle float32
		data  []float32

		projection mgl.Mat4
		camera     mgl.Mat4
		model      mgl.Mat4
	}{}

	glstate = struct {
		vbo llgl.Vbo

		program llgl.Program

		projectionUL llgl.UniformLocation
Пример #5
0
package netserv

import (
	"io"
	"io/ioutil"
	"net/http"
	"strings"

	"golang.org/x/net/websocket"

	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("netserv")

func fileServerClosure(dirpath string) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {

		defer tlog.FuncLog(tlog.Func("fileServer(" + dirpath + ")"))

		filename := r.URL.Path[1:]
		if filename == "" {
			filename = "main.html"
		}
		filepath := dirpath + filename

		body, err := ioutil.ReadFile(filepath)
		if err != nil {
			http.Error(w, err.Error(), http.StatusNotFound)
			tlog.Println("GET 404: " + filepath)
		} else {
Пример #6
0
import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"

	"github.com/hialin/hialin/nex"
	"github.com/hialin/hialin/parse/internal/engine/grammar"
	"github.com/hialin/hialin/parse/internal/engine/lexer"
	"github.com/hialin/hialin/parse/internal/engine/parser"

	"github.com/hialin/hialin/parse/internal/engine/syms"
	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("parse.golang")

var (
	GoInterpretation = nex.NewType("GoInterpretation", nex.ProgramInterpretation)

	GoEntity = nex.NewType("GoEntity", nex.ProgramEntity)

	Term       = nex.NewType("Term", GoEntity)
	NonTerm    = nex.NewType("NonTerm", GoEntity)
	ParseError = nex.NewType("ParseError", GoEntity, nex.ErrorMark)
	Expected   = nex.NewType("Expected", ParseError)

	nonTermMap = make(map[syms.SymbolID]nex.Type)
)

var (
Пример #7
0
package syms

import (
	"bytes"
	"fmt"
	"sort"
	"strings"

	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("parse.engine.syms")

type SymbolSet struct {
	props []SymbolProp
	ids   map[string]SymbolID
}

type SymbolProp struct {
	Name   string
	IsTerm bool
}
type SymbolID int

const (
	ERROR SymbolID = iota
	EOF
	EMPTY
	ANY
	WS
	EOL
Пример #8
0
package parse

import (
	"bufio"
	"os"
	"strings"

	"github.com/hialin/hialin/nex"
	"github.com/hialin/hialin/parse/internal/langs/golang"
	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("parse")

// Parse function returns a parse nex tree of the file
func Parse(filePath string) nex.Nex {
	if strings.HasSuffix(filePath, ".go") {
		f, err := os.Open(filePath)
		if !tlog.Ok(err) {
			return nex.NewErrorNex(err)
		}
		defer f.Close()
		reader := bufio.NewReader(f)
		return golang.Parse(reader)
	}
	// if strings.HasSuffix(filePath, ".json") {
	// 	return json.Parse(filePath)
	// }
	return nex.NewErrorNexFromString("unknown file, cannot parse")
}
Пример #9
0
package lexer

import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io"

	"github.com/hialin/hialin/parse/internal/engine/syms"
	"github.com/hialin/hialin/trace"

	"unicode"
)

var tlog = trace.New("parse.engine.lexer")

type Token struct {
	ID  syms.SymbolID
	Str string
}

// Lexer exported
type Lexer interface {
	// SetReader exported
	SetReader(io.Reader)
	// GetSymbolSet exported
	GetSymbolSet() *syms.SymbolSet
	// Ignore allows ignoring specific symbols
	Ignore(syms.SymbolID)
	// Ident makes a new identifier
Пример #10
0
package unused

import (
	"bytes"

	"go/ast"
	"go/parser"
	"go/token"

	"github.com/hialin/hialin/trace"
)

var tlog = trace.New("ast")

func main() {
	testAst()
}

func testAst() {
	fset := token.NewFileSet()
	file, err := parser.ParseFile(fset, "vis/sdf.go", nil, 0)
	tlog.Ok(err)

	ast.Walk(&FuncVisitor{0}, file)

	// printer.Fprint(os.Stdout, fset, file)
}

type FuncVisitor struct {
	indent int
}
Пример #11
0
	"runtime"

	"github.com/hialin/hialin/trace"

	"github.com/go-gl/gl/v3.3-core/gl"
	"github.com/go-gl/glfw/v3.1/glfw"
)

const (
	DEBUG = false
)

var window *glfw.Window
var running = true

var tlog = trace.New("llgl")

func InitDisplay(title string) error {
	defer tlog.FuncLog(tlog.Func("InitDisplay"))

	runtime.LockOSThread()

	err := glfw.Init()
	if err != nil {
		return err
	}

	monitor := glfw.GetPrimaryMonitor()
	mode := monitor.GetVideoMode()
	tlog.Println("monitor mode", mode)
Пример #12
0
		case string:
			s = append(s, x)
		case lexer.Token:
			s = append(s, x.Str)
		default:
			s = append(s, fmt.Sprintf("%#v", x))
		}
	}
	rstr := r.String(*g.Syms, -1)
	ret := rstr + " (" + strings.Join(s, ")(") + ")"
	return ret, nil
}

///////////////////////////////////////////////////////////////////////////////

var tlog = trace.New("parse.engine.grammar")

var identRe = regexp.MustCompile(`\pL[\pL\pM\pN]*`)

var tokenRe = regexp.MustCompile(`[\pL\pM\pN\pP]*(\+|\?|\*)?`)

func NewGrammarBlock(l lexer.Lexer, ruleBlock string, funcMap map[string]UserFn) (Grammar, error) {
	// defer tlog.FuncLog(tlog.Func("NewGrammarBlock"))
	var rules []Rule
	arrowSep := "→"
	defineSep := "::="
	subruleSep := "|"
	ruleHandlerPrefix := "@"
	ruleList := strings.Split(ruleBlock, "\n")
	synthSymbols := make(map[string]bool)
	var lhsID syms.SymbolID