i need some yaegi's design or Structural doc ? #1507
-
I'm learning the source code for about 7 days, I know a little about working theory but I don't know why? eg: thx for your time ! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
@ldez first thx for corect my spelling so instantly; and do you have some design doc for learner? |
Beta Was this translation helpful? Give feedback.
-
@kevinleegithup you are asking hard questions 😄
When I started this interpreter project, I was first very happy to see that the Golang authors included a full Go parser and some AST (Abstract Syntax Tree) tooling in the standard library but then I found it too cumbersome to use, and not suitable to my purposes. Even walking the tree was strange and inefficient to me. At that time I was fluent in C, but still beginning and poor at Go, and could not fit my design into theirs, with all the interface intricacies. So I decided to still use their parser, but convert their AST representation to mine, the In my approach, the AST nodes are more uniform, and most of interesting properties derive from their location in the tree rather than their own kind, i.e. what ancestors, children, etc. Another important reason is that I tend to annotate the AST to store the information computed during compilation, like the location and size of data in the stack frame, or informations about the control flow (what next instruction to jump to ?).
CFG stands for Control Flow Graph. For example in the IF instruction, you have a TRUE block executed if the test is true and a FALSE block otherwise. In case of FOR loops, your graph becomes cyclic, and you loop between the body block and test block. An important thing, but that I never saw properly described in the literature, is that you can mathematically map a CFG over an AST, thus completely avoid the necessity of an intermediate representation language, and store all the results from compiling simply as AST annotations (additional fields in AST nodes). I also found that the original stdlib AST was sometime structurally wrong (in rare cases) and made it impossible to map correctly the CFG, so I also fixed it during AST conversion.
Yes. But we have isolated the insecure parts in order to properly sandbox interpreters and make sure that they can run untrusted code without endangering the host process. It is still possible to run in unrestricted mode and have access to the full library. |
Beta Was this translation helpful? Give feedback.
-
Finally I made a post: https://marc.vertes.org/yaegi-internals 😅 I will maybe do a PR to incorporate it in the docs |
Beta Was this translation helpful? Give feedback.
-
fyi, as part of learning the internals of yaegi, I created this little structexplorer tool to help visualise what is going on |
Beta Was this translation helpful? Give feedback.
@kevinleegithup you are asking hard questions 😄
When I started this interpreter project, I was first very happy to see that the Golang authors included a full Go parser and some AST (Abstract Syntax Tree) tooling in the standard library but then I found it too cumbersome to use, and not suitable to my purposes. Even walking the tree was strange and inefficient to me. At that time I was fluent in C, but still beginning and poor at Go, and could not fit my design into theirs, with all the interface intricacies. So I decided to still use their parser, but convert their AST representation to mine, the
node
struct.In my approach, the AST nodes are…