Mercurial > repos > icfp2014
annotate code/lmc.tp @ 6:0ab6eb5f0190
Implement not, < and <=
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 25 Jul 2014 11:46:34 -0700 |
parents | 80e224fff567 |
children | afd55b32549b |
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: { |
6 | 116 if: (expr op) = "<" { |
117 prog add: (inst: "CGTE" #[]) | |
118 prog add: (inst: "LDC" #[0]) | |
119 prog add: (inst: "CEQ" #[]) | |
120 } else: { | |
121 if: (expr op) = "<=" { | |
122 prog add: (inst: "CGT" #[]) | |
123 prog add: (inst: "LDC" #[0]) | |
124 prog add: (inst: "CEQ" #[]) | |
125 } else: { | |
126 error: "operator " . (expr op) . " is not supported" | |
127 } | |
128 } | |
2
71e8d638da5c
Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents:
1
diff
changeset
|
129 } |
71e8d638da5c
Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents:
1
diff
changeset
|
130 } |
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
|
131 |
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 _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
|
133 _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
|
134 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
|
135 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
|
136 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
|
137 flabel <- prog makeLabel: "false" |
5
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
138 elabel <- prog makeLabel: "end" |
4
eaf0a014d18b
Use TSEL instead of SEL for if:else
Michael Pavone <pavone@retrodev.com>
parents:
3
diff
changeset
|
139 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
|
140 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
|
141 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 ]) |
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 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
|
144 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
|
145 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
|
146 } |
5
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
147 prog add: (inst: "LDC" #[1]) |
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
148 prog add: (inst: "TSEL" #[ |
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
149 elabel |
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
150 elabel |
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
151 ]) |
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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 } |
5
80e224fff567
Fix handling of true case in if:else
Michael Pavone <pavone@retrodev.com>
parents:
4
diff
changeset
|
157 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
|
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 _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
|
160 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
|
161 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
|
162 } |
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 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
|
164 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
|
165 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
|
166 } |
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 _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
|
168 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
|
169 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
|
170 } |
6 | 171 _funHandlers set: "not" :args { |
172 compileExpr: (args value) | |
173 prog add: (inst: "LDC" #[0]) | |
174 prog add: (inst: "CEQ" #[]) | |
175 } | |
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
|
176 |
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
|
177 _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
|
178 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
|
179 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
|
180 _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
|
181 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
|
182 } 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
|
183 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
|
184 } |
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
|
185 } 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
|
186 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
|
187 } |
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
|
188 } |
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
|
189 #{ |
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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 } 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
|
200 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
|
201 } |
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 } |
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 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
|
204 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
|
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 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
|
207 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
|
208 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
|
209 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
|
210 } |
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 } |
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
|
212 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
|
213 } else: { |
2
71e8d638da5c
Add operator support to lmc
Michael Pavone <pavone@retrodev.com>
parents:
1
diff
changeset
|
214 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
|
215 } |
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
|
216 } |
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
|
217 |
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
|
218 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
|
219 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
|
220 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
|
221 } |
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
|
222 |
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
|
223 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
|
224 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
|
225 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
|
226 } 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
|
227 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
|
228 } |
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
|
229 } |
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
|
230 } |
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
|
231 } |