1
1
import { Opaque } from "glimmer-util" ;
2
2
3
3
import {
4
- CompileInto ,
5
- SymbolLookup ,
6
4
Statement as StatementSyntax ,
7
5
Expression as ExpressionSyntax
8
6
} from '../../syntax' ;
9
7
10
8
import SymbolTable from '../../symbol-table' ;
11
9
12
- import {
13
- LabelOpcode ,
14
- EnterOpcode ,
15
- PutValueOpcode ,
16
- SimpleTest ,
17
- TestOpcode ,
18
- JumpUnlessOpcode ,
19
- ExitOpcode
20
- } from '../../compiled/opcodes/vm' ;
21
-
22
- import {
23
- PutPartialDefinitionOpcode ,
24
- PutDynamicPartialDefinitionOpcode ,
25
- EvaluatePartialOpcode
26
- } from '../../compiled/opcodes/partial' ;
10
+ import OpcodeBuilderDSL from '../../compiled/opcodes/builder' ;
27
11
28
12
import * as Syntax from '../core' ;
29
13
import Environment from '../../environment' ;
@@ -35,7 +19,7 @@ export class StaticPartialSyntax extends StatementSyntax {
35
19
super ( ) ;
36
20
}
37
21
38
- compile ( compiler : CompileInto & SymbolLookup , env : Environment , symbolTable : SymbolTable ) {
22
+ compile ( dsl : OpcodeBuilderDSL , env : Environment , symbolTable : SymbolTable ) {
39
23
let name = String ( this . name . inner ( ) ) ;
40
24
41
25
if ( ! env . hasPartial ( name , symbolTable ) ) {
@@ -44,8 +28,8 @@ export class StaticPartialSyntax extends StatementSyntax {
44
28
45
29
let definition = env . lookupPartial ( name , symbolTable ) ;
46
30
47
- compiler . append ( new PutPartialDefinitionOpcode ( definition ) ) ;
48
- compiler . append ( new EvaluatePartialOpcode ( symbolTable ) ) ;
31
+ dsl . putPartialDefinition ( definition ) ;
32
+ dsl . evaluatePartial ( ) ;
49
33
}
50
34
}
51
35
@@ -56,32 +40,21 @@ export class DynamicPartialSyntax extends StatementSyntax {
56
40
super ( ) ;
57
41
}
58
42
59
- compile ( compiler : CompileInto & SymbolLookup , env : Environment , symbolTable : SymbolTable ) {
60
- let name = this . name . compile ( compiler , env , symbolTable ) ;
61
-
62
- /*
63
- // Enter(BEGIN, END)
64
- // BEGIN: Noop
65
- // PutArgs
66
- // NameToPartial
67
- // Test
68
- // JumpUnless(END)
69
- // EvaluatePartial
70
- // END: Noop
71
- // Exit
72
- */
73
-
74
- let BEGIN = new LabelOpcode ( "BEGIN" ) ;
75
- let END = new LabelOpcode ( "END" ) ;
76
-
77
- compiler . append ( new EnterOpcode ( BEGIN , END ) ) ;
78
- compiler . append ( BEGIN ) ;
79
- compiler . append ( new PutValueOpcode ( name ) ) ;
80
- compiler . append ( new TestOpcode ( SimpleTest ) ) ;
81
- compiler . append ( new JumpUnlessOpcode ( END ) ) ;
82
- compiler . append ( new PutDynamicPartialDefinitionOpcode ( symbolTable ) ) ;
83
- compiler . append ( new EvaluatePartialOpcode ( symbolTable ) ) ;
84
- compiler . append ( END ) ;
85
- compiler . append ( new ExitOpcode ( ) ) ;
43
+ compile ( dsl : OpcodeBuilderDSL ) {
44
+ let { name } = this ;
45
+
46
+ dsl . startLabels ( ) ;
47
+
48
+ dsl . putValue ( name ) ;
49
+ dsl . test ( 'simple' ) ;
50
+ dsl . enter ( 'BEGIN' , 'END' ) ;
51
+ dsl . label ( 'BEGIN' ) ;
52
+ dsl . jumpUnless ( 'END' ) ;
53
+ dsl . putDynamicPartialDefinition ( ) ;
54
+ dsl . evaluatePartial ( ) ;
55
+ dsl . label ( 'END' ) ;
56
+ dsl . exit ( ) ;
57
+
58
+ dsl . stopLabels ( ) ;
86
59
}
87
60
}
0 commit comments