1 / 15

Stacky

Stacky. By Andrew Horn And Ryan Kluck. Language Features. The basic data structure that this language utilizes is a stack Each function gets its own stack All variables are assigned memory locations All operations and functions can only be evaluated by being pushed onto the stack.

nellie
Download Presentation

Stacky

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stacky By Andrew Horn And Ryan Kluck

  2. Language Features The basic data structure that this language utilizes is a stack Each function gets its own stack All variables are assigned memory locations All operations and functions can only be evaluated by being pushed onto the stack

  3. Types of Arguments Integers Function calls Memory calls Operator calls Condition calls

  4. Things you can push Numbers Functions Function declarations (lambda expressions) Operators (including conditionals) push(1,2,3); push(:swap); push(func::{return 0}); push(1,2,+); push(1,2,<);

  5. Return Statements A return statement pushes the returned values back onto the stack the returning function was called from in the order specified in the return statement The code on the right pushes 2 and 5 onto the stack, then calls swap which returns [5,2] which is concatenated onto the end of the stack in main func:swap:2{ return(0,1); } func:main:{ push(2,5); push(:swap); }

  6. Basic Syntax The example on the right is a properly formatted program that push 1 onto the stack in main, and then pushes the copy function onto the stack Copy pops 1 parameter off the main stack and returns that element and a copy of that element. Both the original element and the copy are pushed onto the main stack func:copy:1{ return(0,0); } func:main:{ push(1); push(:copy); }

  7. Access To The Stack A called function may access any number of values from the stack Any values passed to a function will be popped from the stack

  8. Memory Memory locations can be assigned to hold any argument as variable The code on the right pushes swap onto the stack, and then pops it off and stores it in memory. Then it pushes 1,2,3, and 4 onto the stack It then pops 4 off the stack and stores it in memory location 1, and pulls swap in from memory location 0 func:swap:2{ return(0,1); } func:main:{ push(:swap,>[0]); push(1,2,3,4,>[1],<[0]); }

  9. Functions A function is declared by func:<functionName>:<number of parameters>{} If number of parameters is not present this value is 0 by default The number of parameters is how many parameters are popped off of the stack when the function is pushed onto the stack func:swap:2{ return(0,1); } func:two:{ push(2); return(0); }

  10. Functions Continued If a function is pushed onto a stack without enough parameters for the function to run, it will remain on stack until it can run, is popped off, or the main function terminates func:swap:2{ return(0,1); } func:main:{ push(1); push(:swap); push(2); push(:swap); }

  11. If Statements An if statement peeks at the values in the stack without popping them If statements are post fix The code on the right tests if location the second element in the stack is greater than the top element and if so swaps them func:main:{ push(2,1); if(1 0 >){ push(:swap); } }

  12. While Loops While loops test if a stack location is 0 and iterate until this happens The code on the right pops values off the stack with each iteration, until the top value is 0 func:pop:1{} func:main:{ push(0,2,3,4); while(0){ push(:pop); } }

  13. While Loops Continued While loops can also use conditionals The code on the right tests if the top two elements on the stack are equal, and if not keeps popping elements off until this condition is met func:pop:1{} func:main:{ push(1,2,2,3,4); while(0 1 !=){ push(:pop); } }

  14. Potential Future Improvements Strings (should be implemented as a list of characters on the stack) Lazy evaluation Overloading SQL

More Related