still fixing issues

This commit is contained in:
Danny Yoo 2011-02-21 17:43:58 -05:00
parent a9586c97d5
commit d192d1cacb
4 changed files with 59 additions and 38 deletions

View File

@ -192,12 +192,16 @@
(let: loop : String ([val : Any (Const-const stmt)]) (let: loop : String ([val : Any (Const-const stmt)])
(cond [(symbol? val) (cond [(symbol? val)
(format "~s" (symbol->string val))] (format "~s" (symbol->string val))]
[(list? val) [(pair? val)
(format "_list(~a)" (string-join (map loop val) (format "[~a, ~a]"
","))] (loop (car val))
(loop (cdr val)))]
[(empty? val)
(format "undefined")]
[else [else
(format "~s" val)]))) (format "~s" val)])))
(: assemble-op-expression ((U PrimitiveOperator TestOperator) (Listof OpArg) -> String)) (: assemble-op-expression ((U PrimitiveOperator TestOperator) (Listof OpArg) -> String))
(define (assemble-op-expression op-name inputs) (define (assemble-op-expression op-name inputs)
(let ([assembled-inputs (map assemble-input inputs)]) (let ([assembled-inputs (map assemble-input inputs)])
@ -250,13 +254,10 @@
(first assembled-inputs))] (first assembled-inputs))]
[(extend-environment/prefix) [(extend-environment/prefix)
(format "new ExtendedPrefixEnvironment(~a, ~a)" (format "new ExtendedPrefixEnvironment(~a, ~a)"
(second assembled-inputs)
(first assembled-inputs))]
#;[(lookup-variable-value)
(format "((~a).globalBindings[~a])"
(second assembled-inputs) (second assembled-inputs)
(first assembled-inputs))]))) (first assembled-inputs))])))
(: assemble-op-statement (PerformOperator (Listof OpArg) -> String)) (: assemble-op-statement (PerformOperator (Listof OpArg) -> String))
(define (assemble-op-statement op-name inputs) (define (assemble-op-statement op-name inputs)
(let ([assembled-inputs (map assemble-input inputs)]) (let ([assembled-inputs (map assemble-input inputs)])

View File

@ -80,7 +80,7 @@
(make-instruction-sequence (make-instruction-sequence
'() '()
(list target) (list target)
`(,(make-AssignImmediateStatement target (make-Const exp)))))) `(,(make-AssignImmediateStatement target (make-Const (Constant-v exp)))))))
(: compile-quoted (Quote CompileTimeEnvironment Target Linkage -> InstructionSequence)) (: compile-quoted (Quote CompileTimeEnvironment Target Linkage -> InstructionSequence))
(define (compile-quoted exp cenv target linkage) (define (compile-quoted exp cenv target linkage)

View File

@ -7,44 +7,59 @@
// function closures are Closures // function closures are Closures
// primitive procedures are regular functions. // primitive procedures are regular functions.
var Primitives = {
'=': function(argl) {
return argl[0] === argl[1][0];
},
'+': function(argl) {
return argl[0] + argl[1][0];
},
'*': function(argl) {
return argl[0] * argl[1][0];
},
'-': function(argl) {
return argl[0] - argl[1][0];
},
'/': function(argl) {
return argl[0] / argl[1][0];
}
};
var TopEnvironment = function() { var TopEnvironment = function() {
this.globalBindings = {
'=': function(argl) {
return argl[0] === argl[1][0];
},
'+': function(argl) {
return argl[0] + argl[1][0];
},
'*': function(argl) {
return argl[0] * argl[1][0];
},
'-': function(argl) {
return argl[0] - argl[1][0];
},
'/': function(argl) {
return argl[0] / argl[1][0];
}
};
this.valss = []; this.valss = [];
}; };
var ExtendedPrefixEnvironment = function(parent, vs) { var ExtendedPrefixEnvironment = function(parent, vs) {
var vals = []; var vals = [];
this.names = [];
while(vs) { while(vs) {
if (parent.globalBindings[vs[0]]) { this.names.push(vs[0]);
vals.push(parent.globalBindings[vs[0]]); if (Primitives[vs[0]]) {
vals.push(Primitives[vs[0]]);
} else { } else {
vals.push(undefined); vals.push(undefined);
} }
vs = vs[1]; vs = vs[1];
} }
this.valss = parent.valss.slice(); this.valss = parent.valss.slice();
this.valss.unshift(vals); this.valss.unshift(vals);
this.globalBindings = parent.globalBindings; };
ExtendedPrefixEnvironment.prototype.lookup = function(name) {
var i;
for (i = 0; i < this.names.length; i++) {
if (this.names[i] === name) {
return this.valss[0][i];
}
}
return undefined;
}; };
var ExtendedEnvironment = function(parent, vs) { var ExtendedEnvironment = function(parent, vs) {
@ -55,7 +70,6 @@ var ExtendedEnvironment = function(parent, vs) {
} }
this.valss = parent.valss.slice(); this.valss = parent.valss.slice();
this.valss.unshift(vals); this.valss.unshift(vals);
this.globalBindings = parent.globalBindings;
}; };

View File

@ -63,9 +63,12 @@
(define-struct: SaveStatement ([reg : Symbol]) #:transparent) (define-struct: SaveStatement ([reg : Symbol]) #:transparent)
(define-struct: RestoreStatement ([reg : Symbol]) #:transparent) (define-struct: RestoreStatement ([reg : Symbol]) #:transparent)
(define-struct: Label ([name : Symbol])) (define-struct: Label ([name : Symbol])
(define-struct: Reg ([name : Symbol])) #:transparent)
(define-struct: Const ([const : Any])) (define-struct: Reg ([name : Symbol])
#:transparent)
(define-struct: Const ([const : Any])
#:transparent)
(define-type OpArg (U Const Label Reg)) (define-type OpArg (U Const Label Reg))
@ -144,7 +147,8 @@
;; Lexical environments ;; Lexical environments
;; A toplevel prefix contains a list of toplevel variables. ;; A toplevel prefix contains a list of toplevel variables.
(define-struct: Prefix ([names : (Listof Symbol)])) (define-struct: Prefix ([names : (Listof Symbol)])
#:transparent)
;; A compile-time environment is a (listof (listof symbol)). ;; A compile-time environment is a (listof (listof symbol)).
;; A lexical address is either a 2-tuple (depth pos), or 'not-found. ;; A lexical address is either a 2-tuple (depth pos), or 'not-found.
@ -153,7 +157,9 @@
(define-type LexicalAddress (U LocalAddress PrefixAddress)) (define-type LexicalAddress (U LocalAddress PrefixAddress))
(define-struct: LocalAddress ([depth : Natural] (define-struct: LocalAddress ([depth : Natural]
[pos : Natural])) [pos : Natural])
#:transparent)
(define-struct: PrefixAddress ([depth : Natural] (define-struct: PrefixAddress ([depth : Natural]
[pos : Natural] [pos : Natural]
[name : Symbol])) [name : Symbol])
#:transparent)