Skip to end of metadata
Go to start of metadata
Unknown macro: {style}


Unknown macro: {font-family}

I'm going to use the SPIM simulator to run my MIPS code once it is produced.


Variables are absolutely indispensable for writing programs. Basically the only program you can write without them is a print statement of literals. Consequently, they are one of the first node types I should handle, otherwise I'd be unable to test my compiler until completely done.

Local variables of numeric types are easy to handle in statically typed languages since they are primitives. In Python, however, all variables refer to objects. I'm still going to start with just local integer variables, though.

Objects are stored on the heap. A local variable has a slot on the stack, but the value on the stack is just a pointer to the object on the heap. An object has a type (immutable) and a value. The type is itself an object, so this will be a reference to the type. I assume that the type is where information such as method signatures lies.

function type: attributes: name (string), globalnamespace (dictionary), defaultvalues (tuple), docstring (string), containingmodule (string), closure (tuple of one cell for each free var), dict (dictionary of additional attr)

class type (ie: type types): attributes: name, inheritance, namespace dictionary


Function calls are not generally considered to be imperative to making a program (in the sense that variables are). Arithmetic operations are simply function calls, though, so there is really very little to do that does not use a function. For example, a = 2 + 4 is the same as a = (2).__add__(4), and this is (I think) how it is actually executed, since, after all, the integers 2 and 4 are objects, so the concept of "primitive operations" is not applicable.

Functions are not the only callable objects. Classobjs are callable ... . In addition, a class may define __call__ , so that instances of the class become callable. I believe that the only times that f(a*) is valid are when either f has type classObj or has the attribute __call__ . In general, __call__ is a method-wrapper, which I think means that it is a C function. Note that it is up to the Class to define __call__ , defining it on an instance is not sufficient.

  • No labels