Every repository with this icon (
Every repository with this icon (
| Description: | Code from my series on writing a Ruby compiler in Ruby edit |
-
Comments
-
Example:
bignum_value.should == 0x8000_0000_0000_0000Comments
-
gcc will not compile variable references that start with an at-sign (@). need to change names of instance and class variables to something else, for example:
@var = classnameinstancevar @@var = classnameclassvaror something similar.
Comments
Changing the name is actually the smallest part of the problem - we also need to create a static "slot table" (fast) or hash table (slow, but more flexible) to store the instance variables.
For now I think I'd like to go with a slot table like the vtable, and just count the number of '@' var's that are mentioned in the class definitions. This will not be sufficient when we look at adding support for eval() (and also instance_variable_set, as well as instance_eval, possibly more), but for now there's no way for the code to increase this, so worst case it will over-allocate space.
There's the added wrinkle of supporting #defined? but that can be handled by creating a specific value to mean "undefined"
For class variables the solution would be similar but not the same, since class variables are shared with the subclasses of a class (while class instance variables are not).
-
Handling Symbol and Fixnum (and true, false and nil)
0 comments Created 6 months ago by vidarhMRI uses type tagging for those. Need to decide whether to do type tagging (more complex code) or do what Python does (memoize small integers) - the benefit of the latter is simpler code. Another alternative is to do method calls, but handle Fixnum "specially" for inline caching... This will cause crashes when we get the compiler to compile.
The simplest may be to implement Fixnum/Symbol as normal classes to start with.
True, false and nil are much simpler as they're single objects so avoiding type tagging is ok to start with, though not necessarily good in terms of performance.
Comments
-
Transform "local variables" to method calls when they're not really variables...
0 comments Created 6 months ago by vidarhThe parser will treat "foo" by itself as a local variable because it initially doesn't know if it's a local variable or a method call. When we have identified the set of local variables, we need to transform the set of what looks like local vars but isn't in the identified set into [:callm, :self, var,[]] instead.
(Note: This also forces us to ensure the s-expression syntax is exempt from being rewritten, and to rewrite of any calls to C functions to use the s-expression syntax to still have a way of calling out... Maybe time to look at FFI instead soon)
Comments
-
ClassScope should inherity from ModuleScope. ModuleScope needs to hold constants.
"Global" constants should be held in a module scope - either make GlobalScope inherit from ModuleScope too, or introduce a ModuleScope in between GlobalScope and the next step down.
Need provisional support for "include" as well as dereferencing ("::"). Note that currently "::" is treated as :callm. Probably need to reverse that change and rewrite to :callm or keep as :deref depending on the right hand side.
Comments
-
Method call in method body (e.g: attr_accessor) causes "nested" calls
1 comment Created 6 months ago by vidarhclass Foo attr_accessor :seq endthe attr_accessor bit turns into:
# callm :self.:attr_accessor subl $20, %esp movl $2, %ebx movl Foo, %eax movl %eax, (%esp) movl $3481, 4(%esp) movl (%eax), %edx movl 12(%edx), %eax call *%eax addl $20, %esp # callm self.attr_accessor END call *%eaxComments











