-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Triton Generation #16
Comments
API Design for BlocksI believe the predominant way to design the API for Examples from CL (defun king-of-confusion (w)
"Take a cons of two lists and make a list of conses.
Think of this function as being like a zipper."
(prog (x y z) ;Initialize x, y, z to NIL
(setq y (car w) z (cdr w))
loop
(cond ((null y) (return x))
((null z) (go err)))
rejoin
(setq x (cons (cons (car y) (car z)) x))
(setq y (cdr y) z (cdr z))
(go loop)
err
(cerror "Will self-pair extraneous items"
"Mismatch - gleep! ~S" y)
(setq z y)
(go rejoin))) Basically we just scan the list for any symbols. If we find a keywordl, construct a block over it. Then at the end form the collected labels. we shall call this API Design for FunctionsSince we want functions to closely resemble Construct a (defproc sudoku (-- verfied?) ; the ( -- verified?) is the stack effect
(entry-code-1) ... (entry-code-n)
(call-label)
:label-name-1
(label-name-1-code-1) ... (label-name-1-code-n)
:label-name-n
(label-name-n-code-1) ... (label-name-n-code-n)) |
Hey there! Designer of Triton VM here. Amazing that you're working on a compiler to Triton assembly! 🎉 First off, let me know if I can help in any way. That certainly includes questions, but also suggestions. For example, if a slight change in the VM's design makes writing compilers tremendously easier, I'm happy to discuss them. Secondly, a heads up: because Triton VM is not currently sound, achieving which is currently both our top priority and almost complete, we have a few changes to the instruction set planned. |
I can say that this list of wanted features is the exact top of my wish list of improvements to the assembler interface. Edit: Also, working on assembler stored in text files with the ability to add comments. |
Hello @jan-ferdinand Thank you for your interest. I would have to spend more time with the system but I do have a few questions
I will probably come up with more questions and suggestions as I start to get more familiar with the system. |
Following up on my previous comment, I've currently made an untested triton program However, if I had an a jump which left the the call stack as it were, I could easily write the same program like this ;; the (n -- n) is the stack effect, really just a comment, in honor of forth
(defproc fib (n -- n)
(push 1) (push 0) (call fib-general) return)
;; defproc will just place an implicit label to the whole block, so
;; the return goes to it
(defproc fib-general (a b n -- n)
(dup 2)
(if (begin (dup 1) add (swap 2) (push -1) add rot recruse)
return)) as (defun if (then else)
(let ((name-then (intern (symbol-name (gensym)) :keyword))
(name-else (intern (symbol-name (gensym)) :keyword))
(name-cont (intern (symbol-name (gensym)) :keyword)))
(begin
skiz
(goto name-then)
(goto name-else)
(add-label name-then then)
(goto name-cont)
(add-label name-else else)
(goto name-cont)
(make-label :name name-cont)))) where we simply jump to the |
|
No. As you say, If the argument of the |
Yeah it would live in program memory. I think there is a way of emulating it with I was thinking of implementing something like:
All these are my rough ideas, I haven't attempted to hack around the issue yet. I'll likely start on a more complicated example (sudoku) before trying to get around this.
Thank you for the link to some programs! And duly noted, I'll at some point hook up some rust code to load the code I've generated so I can get a quick way to test my code. |
Even though your original question 1 was about an instruction Pending further investigation into the corresponding associated costs, we might drop instruction |
Yeah that solution would work to denote an if (albeit one where the recursion happens on the branch), however I was also interested in it from an easy/simple control graph perspective. What I mean is as follows in current-label:
dup0
skiz
call if-wrapper
call else-wrapper
;; Code after the if would go here
if-wrapper:
pop
call if-branch
push 1
return
else-wrapper:
push 0 eq # logical not
skiz
call else-branch
return where one would want to add more code is at the end of (defun loop (loop-body)
(tagbody
(call body)
:body
loop-body (push -1) add (dup 0) skiz recurse return)) where the block before the label To see more examples I recommend checking out In the issue I lay out two solutions to how one might solve this issue. It took me quite a few hours of thought but If I could create a label after jumping, then none of these considerations would have to be made and the control flow graph would more closely resemble more typical control graphs. This means that LLVM has a good graph on what a loop Control Flow Graph looks like. The code would continue in For a primitive like Either way on Monday I'll just implement the change needed to make the current strategy work. |
I'm afraid I don't understand all the technical considerations involved in optimizing control flow graphs – or whether that string of words even makes sense. Would it help your efforts if you could compile to a higher-level language on top of Triton assembly? |
Depends on what is given I guess? For known patterns like For example I wrote a very similar model for Miden in the span of a day, and programs that followed it were in a few days from that. These compilers are kind of throw away compilers as they are just hacking and extending ontop of the VM features as I need them along with allowing me to mix the VM with meta level logic to handle the tedious bits of work, rather than implementing a more proper layer above it. Which works very well for trying to generate benchmarks of the given platform as I have full control of the generated code and its easy to maintain. For more serious projects like my Alucard, what matters tends to be the expression of the system when building ontop of a model, higher level features if they compose nicely can take work out of compilers like these, however if they are just known minor sugar ontop of the system then it would be about the same amount of work. |
Currently my code generator for Triton is quite primitive. I would like the following to be made
if
create new labels to continue at, it is important to be able to compose this with code that comes nextThe text was updated successfully, but these errors were encountered: