Permalink
Browse files

Converted hard-coded if into call to target-generator.

  • Loading branch information...
1 parent 2529df4 commit 1431f80af95f23b9e754036bda28e27c1965c3e7 @gnuvince gnuvince committed May 22, 2012
Showing with 28 additions and 11 deletions.
  1. +9 −7 gsc/_t-univ.scm
  2. +11 −4 gsc/target_js.scm
  3. +8 −0 gsc/target_php.scm
View
@@ -383,13 +383,15 @@
(true (ifjump-true gvm-instr))
(false (ifjump-false gvm-instr))
(adj (sp-adjust ctx (frame-size (gvm-instr-frame gvm-instr)) " ")))
- (gen "if ("
- (prim-applic ctx test opnds #t)
- ") "
- "{ " adj "return " (translate-gvm-opnd ctx (make-lbl true)) "; }"
- " else "
- "{ " adj "return " (translate-gvm-opnd ctx (make-lbl false)) "; }"
- (targ-gen 'label-stop))))
+ (gen
+ (targ-gen 'if
+ (prim-applic ctx test opnds #t)
+ (gen adj
+ "return " (translate-gvm-opnd ctx (make-lbl true)) ";")
+ (gen adj
+ "return " (translate-gvm-opnd ctx (make-lbl false)) ";"))
+ (targ-gen 'label-stop))))
+
((switch)
;; TODO
View
@@ -21,6 +21,12 @@
(define (die msg) (gen "throw \"" msg "\";\n"))
(define (copy a b) (gen a " = " b ";\n"))
(define (apply_ a b) (gen a " = " b ";\n"))
+ (define (if_ cond_ then else_)
+ (gen "if (" cond_ ") {\n"
+ then "\n"
+ "} else {\n"
+ else_
+ "}\n"))
(let ((fn (case msg
((entry-point) entry-point)
@@ -40,6 +46,7 @@
((die) die)
((copy) copy)
((apply) apply_)
+ ((if) if_)
(else
(compiler-internal-error "unknown message" msg)))))
(apply fn args)))
@@ -52,12 +59,12 @@ var stack = [];
var sp = -1;
var nargs = 0;
var nextpc = null;
-var yield;
+var _yield;
if (this.hasOwnProperty('setTimeout')) {
- yield = this.setTimeout;
+ _yield = this.setTimeout;
} else {
- yield = function() {};
+ _yield = function() {};
}
@@ -97,7 +104,7 @@ glo["print"] = lbl1_print;
function run(pc) {
nextpc = pc;
while (nextpc !== null) {
- yield("", 0);
+ _yield("", 0);
pc = nextpc;
nextpc = null;
while (pc !== null) {
View
@@ -29,6 +29,13 @@
(define (die msg) (gen "die(\"" msg "\\n\");\n"))
(define (copy a b) (gen a " = " b ";\n"))
(define (apply_ a b) (gen a " = " b ";\n"))
+ (define (if_ cond_ then else_)
+ (gen "if (" cond_ ") {\n"
+ then "\n"
+ "} else {\n"
+ else_
+ "}\n"))
+
(let ((fn (case msg
@@ -49,6 +56,7 @@
((die) die)
((copy) copy)
((apply) apply_)
+ ((if) if_)
(else
(compiler-internal-error "unknown message" msg)))))
(apply fn args)))

0 comments on commit 1431f80

Please sign in to comment.