forge/rep: work in progress: compilation and execution
This commit is contained in:
		
							parent
							
								
									f9cb596252
								
							
						
					
					
						commit
						704ff5f2fd
					
				
					 5 changed files with 15 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
// Package forge implements sort of a stack-based interpreter.
 | 
			
		||||
// Package forge implements a stack-based interpreter.
 | 
			
		||||
package forge
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue