-
Notifications
You must be signed in to change notification settings - Fork 22
/
stages.fy
70 lines (57 loc) · 1.69 KB
/
stages.fy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class Fancy Compiler Stages {
class Stage : Rubinius Compiler Stage {
define_method('initialize) |compiler last| {
sup = Rubinius Compiler Stage instance_method('initialize)
sup bind(self) call(compiler, last)
initialize: compiler last: last
}
def self stage: name next: next (nil) {
stage(name)
next_stage(next)
}
run = { self run; run_next() }
define_method('run, &run)
}
class FancyGenerator : Stage {
stage: 'fancy_bytecode next: Rubinius Compiler Encoder
read_write_slot: 'variable_scope
def initialize: compiler last: last {
@variable_scope = nil
compiler generator: self
}
def run {
@output = Rubinius Generator new()
@input variable_scope=(@variable_scope)
@input bytecode(@output)
@output close()
}
}
class FancyCodeParser : Stage {
stage: 'fancy_code next: FancyGenerator
read_write_slots: ['root, 'print]
def initialize: compiler last: last {
compiler parser: self
}
def input: @code file: @filename line: @line (1);
def run {
ast = Fancy Parser parse_code: @code file: @filename line: @line
# if: @print then: { ast inspect println }
@output = @root new(ast)
@output file=(@filename)
}
}
class FancyFileParser : Stage {
stage: 'fancy_file next: FancyGenerator
read_write_slots: ['root, 'print]
def initialize: compiler last: last {
compiler parser: self
}
def input: @filename line: @line (1);
def run {
ast = Fancy Parser parse_file: @filename line: @line
# if: @print then: { ast inspect println }
@output = @root new(ast)
@output file=(@filename)
}
}
}