forge/rep: Compile() basically working
This commit is contained in:
		
							parent
							
								
									373c9484c8
								
							
						
					
					
						commit
						434fba79d8
					
				
					 2 changed files with 11 additions and 1 deletions
				
			
		|  | @ -2,11 +2,12 @@ package rep | |||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"git.sr.ht/~cco/go-scopes/forge" | ||||
| ) | ||||
| 
 | ||||
| // maybe: code, defs, string, int, float | ||||
| // may be: code, defs, string, int, float | ||||
| type citem interface{} | ||||
| 
 | ||||
| // code, represented by a slice | ||||
|  | @ -29,12 +30,17 @@ func (ci code) Compile(f forge.FE) forge.FPtr { | |||
| 			} else { | ||||
| 				fmt.Println(err) | ||||
| 			} | ||||
| 		case code: | ||||
| 			c.Append(i.Compile(f)) | ||||
| 		} | ||||
| 	} | ||||
| 	return c.Reset() | ||||
| } | ||||
| 
 | ||||
| func compStr(f forge.FE, s string) (forge.FItem, error) { | ||||
| 	if strings.HasPrefix(s, "'") { | ||||
| 		return forge.FItem(strings.Trim(s, "'")), nil | ||||
| 	} | ||||
| 	if v, ok := f.Voc().Lookup(s); ok { | ||||
| 		return forge.FItem(v), nil | ||||
| 	} | ||||
|  |  | |||
|  | @ -43,4 +43,8 @@ func RepTest(t *testing.T) { | |||
| 	c := src.Compile(fe) | ||||
| 	fe.Call(c) | ||||
| 	t.AssertEqual(fe.Pop(), 6) | ||||
| 	src = rep.Code(rep.Code("dup", "dup", "*", "*"), "'cube'", "reg") | ||||
| 	fe.Call(src.Compile(fe)) | ||||
| 	fe.Call(rep.Code(3, "cube").Compile(fe)) | ||||
| 	t.AssertEqual(fe.Pop(), 27) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue