- Self-Defined Object System
- 07 Jan 2015 05:29:57 am
- Last edited by shkaboinka on 21 Apr 2018 06:13:11 am; edited 6 times in total
EDIT: JUST SKIP TO THIS POST for the best explanation of what this is all about (though the posts linked below are still interesting food for thought).
THIS THREAD IS CONVOLUTED TO START WITH.
SKIP AHEAD TO THIS CONCISE DESCRIPTION. (most accurate)
SKIP AHEAD TO THIS LONGER DESCRIPTION. (slightly outdated, but applicable)
SKIP AHEAD TO THIS JUSTIFICATION THEORY.
(Nevertheless, there are still some interesting ideas in these first several posts)
My goal is to build (a proof of concept for) a computer system in which the entire runtime is composed of objects that can be inspected and manipulated by the user at runtime, to the extent that even the language/compiler/system itself can be inspected & modified/redfined at runtime. This can be accomplished using a very lightweight self-defined object language. This idea came to me after reading The Deep Insights of Alan Kay and watching his video about Programming and Scaling, which inspired me to create language & system consistent with the Kay/Smalltalk idea of objects being a recursion of the notion of "computer" (and vice versa). I'm also borrowing from the DCI philosophy that true "OBJECT"-Orientation is about the objects themselves (classes are not necessary).
I invite anyone to explore/steal my ideas and code on this topic freely without my permission. I just want to further the potential that this approach may offer to the future of software.
The core language will define simple objects (which consist of mappings values, functions, or other objects), and will initially be implemented in JavaScript wherein objects an be compiled directly to JSON.
Here is some sample code, along with the JavaScript equivalent:
Code:
Plan of action:
The compiler will compile objects from source code into a form that allows them to be manipulated at runtime (e.g. add mappings to objects, get mappings by name, etc.), and will also generate a runtime interface for viewing/manipulating/creating all objects at runtime (both by the user and by code that has been compiled). The compiler & runtime will initially be in JavaScript, which already provides JSON as an ideal representation for the compiled objects (though the runtime interface will still be needed for the user).
I will then re-code the compiler in my object language and have it compile its own code (bootstrapping). This will allow the language to be extended or modified using only the language itself.
(At this point, I can now add code to the compiler for it to compile programs to various plaforms (e.g. JVM, CLR, z80), and then I could compile the compiler itself to various platforms. This step can be done at any point in this flow, though it would be cool to have it working on multiple platforms from the start and all using the same exact code.)
From here, I can modify the compiler to compile its own code (excluding the code for this part) into the program being compiled, so that the output program has the compiler built-in to its runtime framework. I'd also modify the runtime interface for the compiled objects to utlilize the compiled-compiler so that when objects are created at runtime, they can contain function-code that can be compiled on the fly! (Note: the code for the compiler should be small, because the language is small)
An interesting paradox occurs at this point:
The compiler and runtime-interface now exist as runtime objects, which means that they could be modified at runtime via the runtime interface, and the definition of the system & language are now self contained and modifiable within the running system. Though the compiler and source code that exist outside of the executing runtime remain as they were, it is now possible to keep program code within an executing runtime and compile it into execution (though perhaps this is pointless if you can just create and modify objects directly, anyway).
I'd have to have some UI features built-in to the underlying architecture to facilitate things like typing, drawing, I/O interfactions, etc. (and how these are approached would differ depending on implementation: JavaScript, .NET, etc., but I'd try to have the underlying system provide the same interface to my runtime). Initially I might code up a JavaScript UI to provide the user access to the runtime-object interface; though once that is in place, I might use that UI interface to create runtime objects that provide a different view of the data, making (some of) the "built-in" UI obsolete. Or perhaps I'd find ways to code up parts of the same interface using my object language, and then it's all modifiable internally.
Here is the grammar for the ENTIRE language so far:
Code:
THIS THREAD IS CONVOLUTED TO START WITH.
SKIP AHEAD TO THIS CONCISE DESCRIPTION. (most accurate)
SKIP AHEAD TO THIS LONGER DESCRIPTION. (slightly outdated, but applicable)
SKIP AHEAD TO THIS JUSTIFICATION THEORY.
(Nevertheless, there are still some interesting ideas in these first several posts)
My goal is to build (a proof of concept for) a computer system in which the entire runtime is composed of objects that can be inspected and manipulated by the user at runtime, to the extent that even the language/compiler/system itself can be inspected & modified/redfined at runtime. This can be accomplished using a very lightweight self-defined object language. This idea came to me after reading The Deep Insights of Alan Kay and watching his video about Programming and Scaling, which inspired me to create language & system consistent with the Kay/Smalltalk idea of objects being a recursion of the notion of "computer" (and vice versa). I'm also borrowing from the DCI philosophy that true "OBJECT"-Orientation is about the objects themselves (classes are not necessary).
I invite anyone to explore/steal my ideas and code on this topic freely without my permission. I just want to further the potential that this approach may offer to the future of software.
The core language will define simple objects (which consist of mappings values, functions, or other objects), and will initially be implemented in JavaScript wherein objects an be compiled directly to JSON.
Here is some sample code, along with the JavaScript equivalent:
Code:
myObj:(val:5, fun:[x,y:x+y], tuple:(1,2,3), fun2:[:do(a) do(b,c)])
myObj.val: someValue
myObj.tuple(0): someValue
myObj.fun2()
// JavaScript equivalent:
var myObj = { val:5, fun:function(x,y){return x+y;}, tuple:[1,2,3], fun2:function(){do(a); do(b,c);} };
myObj.val = someValue;
myObj.tuple[0] = someValue;
myObj.fun2();
Plan of action:
The compiler will compile objects from source code into a form that allows them to be manipulated at runtime (e.g. add mappings to objects, get mappings by name, etc.), and will also generate a runtime interface for viewing/manipulating/creating all objects at runtime (both by the user and by code that has been compiled). The compiler & runtime will initially be in JavaScript, which already provides JSON as an ideal representation for the compiled objects (though the runtime interface will still be needed for the user).
I will then re-code the compiler in my object language and have it compile its own code (bootstrapping). This will allow the language to be extended or modified using only the language itself.
(At this point, I can now add code to the compiler for it to compile programs to various plaforms (e.g. JVM, CLR, z80), and then I could compile the compiler itself to various platforms. This step can be done at any point in this flow, though it would be cool to have it working on multiple platforms from the start and all using the same exact code.)
From here, I can modify the compiler to compile its own code (excluding the code for this part) into the program being compiled, so that the output program has the compiler built-in to its runtime framework. I'd also modify the runtime interface for the compiled objects to utlilize the compiled-compiler so that when objects are created at runtime, they can contain function-code that can be compiled on the fly! (Note: the code for the compiler should be small, because the language is small)
An interesting paradox occurs at this point:
The compiler and runtime-interface now exist as runtime objects, which means that they could be modified at runtime via the runtime interface, and the definition of the system & language are now self contained and modifiable within the running system. Though the compiler and source code that exist outside of the executing runtime remain as they were, it is now possible to keep program code within an executing runtime and compile it into execution (though perhaps this is pointless if you can just create and modify objects directly, anyway).
I'd have to have some UI features built-in to the underlying architecture to facilitate things like typing, drawing, I/O interfactions, etc. (and how these are approached would differ depending on implementation: JavaScript, .NET, etc., but I'd try to have the underlying system provide the same interface to my runtime). Initially I might code up a JavaScript UI to provide the user access to the runtime-object interface; though once that is in place, I might use that UI interface to create runtime objects that provide a different view of the data, making (some of) the "built-in" UI obsolete. Or perhaps I'd find ways to code up parts of the same interface using my object language, and then it's all modifiable internally.
Here is the grammar for the ENTIRE language so far:
Code:
SOURCE :: STATEMENT*
STATEMENT :: EXPR [ MAPPING ]
MAPPING :: `:` EXPR
EXPR :: TERNARY
TERNARY :: CONDITION [ `?` CONDITION `,` CONDITION ]
CONDITION :: COMPARISON ( ( `&` | `|` ) COMPARISON )*
COMPARISON :: ADDITION ( ( `<` | `>` | `<=` | `>=` | `=` | `!=` | `~` | `!~` ) ADDITION )*
ADDITION :: MULTIPLE ( ( `+` | `-` ) MULTIPLE )*
MULTIPLE :: EXPONENT ( ( `*` | `/` | `%` ) EXPONENT )*
EXPONENT :: UNARY ( `^` UNARY )*
UNARY :: [`!`] VALUE ( `.` IDENT | `[` EXPR `]` | `(` [ EXPR ( `,` EXPR )* ] `)` )*
VALUE :: IDENT | STRING | NUMBER | FUNCTION | OBJECT
FUNCTION :: `[` [ IDENT ( `,` IDENT )* ] `:` SOURCE `]`
OBJECT :: `(` [ MEMBER ( `,` MEMBER )* ] `)`
MEMBER :: [ IDENT `:` ] EXPR
IDENT :: ( letter | `_` | `'` | `$` ) ( letter | digit | `_` | `'` | `$` )*
STRING :: `"` ( any character except `"` | `""` )* `"`