forge/rep: work in progress: compilation and execution

This commit is contained in:
Helmut Merz 2023-09-08 18:16:07 +02:00
parent f9cb596252
commit 704ff5f2fd
5 changed files with 15 additions and 6 deletions

View file

@ -17,6 +17,11 @@ func NewVoc[V any](parent *Vocabulary[V]) *Vocabulary[V] {
data: VocData[V]{},
}
}
func (voc *Vocabulary[V]) Parent() *Vocabulary[V] {
return voc.parent
}
func (voc *Vocabulary[V]) Register(name string, it V) {
vi, ok := voc.data[name]
if ok {

View file

@ -1,4 +1,4 @@
// Package forge implements sort of a stack-based interpreter.
// Package forge implements a stack-based interpreter.
package forge
import (

View file

@ -8,12 +8,16 @@ import (
func ParseJson(inp string) coderep {
var raw interface{}
err := json.Unmarshal([]byte(inp), &raw)
return ParseJsonToTarget(inp, &raw)
}
func ParseJsonToTarget(inp string, target *interface{}) coderep {
err := json.Unmarshal([]byte(inp), target)
if err != nil {
log.Error(err).Msg("rep.ParseJson")
return nil
}
rep := prepare(raw)
rep := prepare(*target)
return rep
}

View file

@ -72,7 +72,7 @@ func makeCode(ri []interface{}) code {
return c
}
// module - code definitions, represented by a map
// module - code definitions, represented by a map that is used as a forge vocabulary
type module map[string]citem

View file

@ -33,7 +33,7 @@ func (it *gofunc) Code() fptr {
}
func (it *gofunc) Name() string {
return string(it.name)
return it.name
}
// acode: anonymous forge code
@ -70,5 +70,5 @@ func FCode(n string, c fptr) XT {
}
func (it *fcode) Name() string {
return string(it.name)
return it.name
}