annotate code/lmc.tp @ 5:80e224fff567

Fix handling of true case in if:else
author Michael Pavone <pavone@retrodev.com>
date Fri, 25 Jul 2014 11:04:00 -0700
parents eaf0a014d18b
children 0ab6eb5f0190
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
1 {
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
2 inst <- :_name _args {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
3 #{
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
4 name <- _name
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
5 args <- _args
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
6 translateLabels <- :labelDict {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
7 missing <- #[]
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
8 foreach: args :idx arg {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
9 if: (object does: arg understand?: "isString?") && (arg isString?) {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
10 labelDict ifget: arg :translated {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
11 args set: idx translated
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
12 } else: {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
13 missing append: arg
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
14 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
15 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
16 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
17 missing
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
18 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
19 label <- ""
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
20 string <- {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
21 (if: label != "" { ";" . label . "\n " } else: { " " }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
22 ) . name . " " . (args join: " ")
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
23 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
24 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
25 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
26 _nextLabel <- 0
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
27 _setLabel <- :inst {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
28 inst
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
29 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
30 prog <- #{
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
31 instructions <- #[]
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
32 add <- :inst {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
33 instructions append: (_setLabel: inst)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
34 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
35 makeLabel <- :suffix {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
36 num <- _nextLabel
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
37 _nextLabel <- _nextLabel + 1
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
38 "" . num . "_" . suffix
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
39 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
40 labels <- dict hash
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
41 setLabel <- :name {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
42 labels set: name pc
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
43 _setLabel <- :inst {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
44 _setLabel <- :i { i }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
45 inst label!: name
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
46 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
47 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
48 pc <- { instructions length }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
49 print <- {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
50 foreach: instructions :idx i {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
51 missing <- i translateLabels: labels
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
52 if: (missing length) > 0 {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
53 error: "Undefined labels " . (missing join: ", ") . " at address " . idx
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
54 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
55 print: (string: i) . "\n"
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
56 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
57
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
58 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
59 }
2
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
60 error <- :msg {
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
61 (file stderr) write: "Error - " . msg . "\n"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
62 }
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
63
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
64 _exprHandlers <- dict hash
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
65
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
66 compileExpr <- :expr {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
67 _exprHandlers ifget: (expr nodeType) :handler {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
68 handler: expr
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
69 } else: {
2
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
70 error: "Unhandled node type " . (expr nodeType)
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
71 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
72 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
73
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
74 _exprHandlers set: (ast intlit) :expr {
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
75 prog add: (inst: "LDC" #[(expr val)])
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
76 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
77
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
78 _exprHandlers set: (ast sequence) :expr {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
79 count <- 0
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
80 foreach: (expr els) :idx el {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
81 compileExpr: el
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
82 count <- count + 1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
83 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
84 if: (expr array?) {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
85 count <- count - 1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
86 } else: {
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
87 prog add: (inst: "LDC" #[0])
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
88 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
89 while: { count > 0} do: {
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
90 prog add: (inst: "CONS" #[])
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
91 count <- count - 1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
92 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
93 }
2
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
94
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
95 _opNames <- dict hash
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
96 _opNames set: "+" "ADD"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
97 _opNames set: "-" "SUB"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
98 _opNames set: "*" "MUL"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
99 _opNames set: "/" "DIV"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
100 _opNames set: "|" "CONS"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
101 _opNames set: "=" "CEQ"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
102 _opNames set: ">" "CGT"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
103 _opNames set: ">=" "CGTE"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
104
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
105 _exprHandlers set: (ast binary) :expr {
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
106 if: (expr op) = "|" {
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
107 compileExpr: (expr left)
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
108 compileExpr: (expr right)
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
109 } else: {
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
110 compileExpr: (expr right)
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
111 compileExpr: (expr left)
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
112 }
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
113 _opNames ifget: (expr op) :i {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
114 prog add: (inst: i #[])
2
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
115 } else: {
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
116 error: "operator " . (expr op) . " is not supported"
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
117 }
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
118 }
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
119
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
120 _funHandlers <- dict hash
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
121 _funHandlers set: "if:else" :args {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
122 compileExpr: (args value)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
123 args <- args tail
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
124 tlabel <- prog makeLabel: "true"
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
125 flabel <- prog makeLabel: "false"
5
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
126 elabel <- prog makeLabel: "end"
4
eaf0a014d18b Use TSEL instead of SEL for if:else
Michael Pavone <pavone@retrodev.com>
parents: 3
diff changeset
127 prog add: (inst: "TSEL" #[
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
128 tlabel
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
129 flabel
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
130 ])
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
131 prog setLabel: tlabel
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
132 foreach: ((args value) expressions) :idx expr {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
133 compileExpr: expr
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
134 }
5
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
135 prog add: (inst: "LDC" #[1])
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
136 prog add: (inst: "TSEL" #[
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
137 elabel
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
138 elabel
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
139 ])
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
140 args <- args tail
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
141 prog setLabel: flabel
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
142 foreach: ((args value) expressions) :idx expr {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
143 compileExpr: expr
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
144 }
5
80e224fff567 Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents: 4
diff changeset
145 prog setLabel: elabel
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
146 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
147 _funHandlers set: "isInteger?" :args {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
148 compileExpr: (args value)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
149 prog add: (inst: "ATOM" #[])
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
150 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
151 _funHandlers set: "value" :args {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
152 compileExpr: (args value)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
153 prog add: (inst: "CAR" #[])
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
154 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
155 _funHandlers set: "tail" :args {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
156 compileExpr: (args value)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
157 prog add: (inst: "CDR" #[])
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
158 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
159
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
160 _exprHandlers set: (ast call) :expr {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
161 tc <- (expr tocall)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
162 if: (tc nodeType) = (ast sym) {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
163 _funHandlers ifget: (tc name) :handler {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
164 handler: (expr args)
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
165 } else: {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
166 error: "function calls not implemented yet"
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
167 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
168 } else: {
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
169 error: "call expression to value not implemented yet - " . tc
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
170 }
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
171 }
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
172 #{
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
173 compile <- :code {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
174 res <- parser top: code
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
175 if: res {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
176 outer <- res yield
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
177 main_fun <- false
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
178 others <- dict hash
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
179 foreach: (outer messages) :idx msg {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
180 if: ((msg to) name) = "main" {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
181 main_fun <- msg assign
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
182 } else: {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
183 others set: ((msg to) name) (msg assign)
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
184 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
185 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
186 foreach: (main_fun expressions) :idx expr {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
187 compileExpr: expr
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
188 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
189 foreach: others :name fun {
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
190 prog setLabel: name
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
191 foreach: (fun expressions) :idx expr {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
192 compileExpr: expr
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
193 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
194 }
3
a9a2ad99adfb Rework lmc a bit to support labels in generated code. Add support for certain special funcall expressions, namely: if:else, isInteger? value and tail which translate to SEL ATOM CAR and CDR respectively
Michael Pavone <pavone@retrodev.com>
parents: 2
diff changeset
195 print: prog
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
196 } else: {
2
71e8d638da5c Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents: 1
diff changeset
197 error: "Parse failed!"
1
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
198 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
199 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
200
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
201 compileFile <- :filename {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
202 f <- file open: filename
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
203 compile: (f readAll)
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
204 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
205
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
206 main <- :args {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
207 if: (args length) > 1 {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
208 compileFile: (args get: 1)
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
209 } else: {
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
210 print: "Usage lmc FILE\n"
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
211 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
212 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
213 }
68d1447bfdbe Support for compiling lists, tuples and integer literals in lmc. Added small test lm program for exercising compiler.
Michael Pavone <pavone@retrodev.com>
parents: 0
diff changeset
214 }