-
Notifications
You must be signed in to change notification settings - Fork 0
jankom/Toylingo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
NEW CORE (very raw) IDEAS -- just typing my mind... revisit this ============== Context is the core of it all. We have only contexts and values and blocks. everything happens in a context (current-context is a list of contextes) an item can refer to a value in current context (word refers to value) or itself (number, string, block) refers to themselves: 'word :get-word set-word: 12345 "string" [ ] refers to value in context: word ; can refer to scalar value , or a do-block do-block is a context tree/list + a block of items , last expression when evaluating block of items is returned context:: ( native ( sum/2 ) my ( a ) ) do-block :: my<-native ;; ( sum 1 a/a ) a way to make a context: { a 5 @native } so a reader takes word-dict and empty block and starts reading program in: 1 2 3 => {} [ vn:1 vn:2 vn:3 ] a 2 3 => { a 1 } [ c:1 vn:2 vn:3 ] ; vn - value number a: 2 :a => { a 1 } [ cs:1 vn: 2 cg:1 ] ; ws - word set cg - word get ----- editing in crappy online editor , will make it consistent when I get this offlien make a context { a: 5 @native }=> { a 1 native 2 } { sw:1 5 ctx:2 } { a: 1} [ a ] { sw:1 5 ctx:2 } ^ ( gw:1 ) ; bind context to block ( do ( bind ( ( def { a: f } 2 ) ( a ) ) ) def takes context and values and serialy sets values to context items bind takes context and block and binds them together do takes a block and does it so context when defined has defined values context values can be changed (it would be great if they could be versioned / create new context out of old) bind takes whatever context and links it to block (so block has a initially empty uplink to context) do takes a block (bound or unbound) and does it, if it finds words that aren't defined in current context it throws an error. THAT IS ALL WE NEED TO START Then we add a way to call native funcs (already done to some degree), for funcs to consume words correctly (already done) IMPORTANT QUESTIONS! HOW DO WE HAVE OPTIONAL LAZY ALL THE WAY DOWN / UP ( && ) HOW TO DEFINE SAFE PURE FUNCTIONS????? SO WE CAN MAKE MOBILE (ower the wire) CODE fun ~ a ; a . 2 => fun ( a ) ( a ) 2 => ( ( fun ( a ) ( a ) ) 2 ) => returns 2 fun takes two blocks args and body and returns a Wrangle ~ interpreter for a imaginary language ================================================ == PARSER == Int - literal value String - literal value Word - active item (evaluates their value) GetWord - gets value from word (without SetWord - binds value to a word Block - doesn't evaluate, just passes along == SPACES == every item has to be separated by space like in Factor. This also meand every character is possible in name Except (1)!! "at-the-start == LANGUAGE HAS == Words Values (int,string,block,word,native) Contexts (bind them to blocks) == HOW TO SEPARATE VALUES FROM WORDS == Value like Native type has to be separated from any word. It's just temporarily assigned to some word. It could be in block of things. Native is a golang structure, and it can stand on it's own, be assigned to a word, pushed into block, etc. == NEXT == Make set-words work too in the parser Make the >> set-word: 123 ;; sample work (no natives needed yet) and other types Make Natives and make them work (the notation is already solved in Toylingo) == BLOCKS == Alternative syntax for blocks add: func -> a b | _add a b . <===> add: func [ a b ] [ _add a b ] a: either true -> join "mr." n | join "ms." n . <===> a: either true [ join "mr." n ] [ join "ms." n ] -old----old----old----old----old----old----old----old----old----old----old----old----old----old--- == WHAT WORKS NOW == lisp without parens notation (polish?) works!!! num1: 100 num2: add 100 200 num3: add 100 add 300 add 5 num5: add inc 2 inc add 1 2 inline assignment wors too num6: add num7: inc 100 inc 200 You can define native functions easily in Go!!! == WHAT NEXT == - make string value parsing work - think about generic ToyVal and make it smarter, what is right now is probably stupid - think about contexts, how to create them, now we have only global context - make parser for blocks (without eval) - bind contexts to blocks to create Functions! - find out how exactly goroutines and channels work in Go and how we can use them in Toylingo == RANDOM THROWAWAY IDEAS == -- main question now? -- Do we do natives as Lua with stack .OR. like Neko-vm with limited number of arguments? A: Lua ToyValue must be one generic type (Now Literal, but this now is prob. clumsy) A: __ Do we do polish notation or stack based postfix notation? A: poslih, rebol like! -- toylingo rebol like -- age: 100 year: add 200 20 -- toylingo stack based -- 100 :age 200 20 add :year 100 :age age: 20 :year "Janko" :name "my name is " name: join print 100 :port [ "hello world" ] :handler port: handler: serve { "janko" :name 31 :age [ "hi" print ] :say-hi } :person 'say-hi person of do 'age person of print 100 50 :my-age: add print ( value is retained on stack ) "my-age: " my-age: print
About
A toy interpreter of a toy language in Go
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published