-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding wip translation from Rye to Eyr
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package evaldo | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/refaktor/rye/env" | ||
) | ||
|
||
func CompileWord(block *env.Block, ps *env.ProgramState, word env.Word, eyrBlock *env.Block) { | ||
// LOCAL FIRST | ||
found, object, _ := findWordValue(ps, word) | ||
pos := ps.Ser.GetPos() | ||
if found { | ||
switch obj := object.(type) { | ||
case env.Integer: | ||
eyrBlock.Series.Append(obj) | ||
case env.Builtin: | ||
for i := 0; i < obj.Argsn; i++ { | ||
// fmt.Println("**") | ||
block = CompileStepRyeToEyr(block, ps, eyrBlock) | ||
} | ||
eyrBlock.Series.Append(word) | ||
} | ||
} else { | ||
ps.ErrorFlag = true | ||
if !ps.FailureFlag { | ||
ps.Ser.SetPos(pos) | ||
ps.Res = env.NewError2(5, "word not found: "+word.Print(*ps.Idx)) | ||
} | ||
} | ||
} | ||
|
||
func CompileRyeToEyr(block *env.Block, ps *env.ProgramState, eyrBlock *env.Block) *env.Block { | ||
for block.Series.Pos() < block.Series.Len() { | ||
block = CompileStepRyeToEyr(block, ps, eyrBlock) | ||
} | ||
return block | ||
} | ||
|
||
func CompileStepRyeToEyr(block *env.Block, ps *env.ProgramState, eyrBlock *env.Block) *env.Block { | ||
// for block.Series.Pos() < block.Series.Len() { | ||
switch xx := block.Series.Pop().(type) { | ||
case env.Word: | ||
// fmt.Println("W") | ||
CompileWord(block, ps, xx, eyrBlock) | ||
// get value of word | ||
// if function | ||
// get argnum | ||
// add argnum args to mstack (values, words or compiled expressions (recur)) | ||
// add word to mstack | ||
// else add word to value list | ||
case env.Opword: | ||
fmt.Println("O") | ||
case env.Pipeword: | ||
fmt.Println("P") | ||
case env.Integer: | ||
// fmt.Println("I") | ||
eyrBlock.Series.Append(xx) | ||
} | ||
// } | ||
return block | ||
} |