-
Notifications
You must be signed in to change notification settings - Fork 171
/
mvmcc.ops
60 lines (46 loc) · 1.51 KB
/
mvmcc.ops
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
BEGIN_OPS_PREAMBLE
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "parrot/dynext.h"
#include "nodes_parrot.h"
/* Prototype for compiler. */
char * MVM_mast_compile(VM, MASTNode *node, MASTNodeTypes *types, unsigned int *size);
/* Node types we're set up with. Not the best design, but hey, this code is
* throwaway. */
static MASTNodeTypes node_types;
END_OPS_PREAMBLE
/*
=item mvm_compiler_setup()
Initializes the compiler with the types it will work on.
=cut
*/
inline op mvm_compiler_setup(invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC, invar PMC) :base_core {
node_types.CompUnit = $1;
node_types.Frame = $2;
node_types.Op = $3;
node_types.SVal = $4;
node_types.IVal = $5;
node_types.NVal = $6;
node_types.Label = $7;
node_types.Local = $8;
node_types.Lexical = $9;
node_types.Call = $10;
node_types.Annotated = $11;
node_types.HandlerScope = $12;
}
/*
=item mvm_compiler_setup()
Calls the MoarVM MAST to bytecode compiler.
=cut
*/
inline op mvm_compile(invar PMC, in STR) :base_core {
Parrot_block_GC_mark(interp);
{
unsigned int output_size;
char *output = MVM_mast_compile(interp, $1, &node_types, &output_size);
FILE *fh = fopen(Parrot_str_to_cstring(interp, $2), "wb+");
fwrite(output, 1, output_size, fh);
fclose(fh);
}
Parrot_unblock_GC_mark(interp);
}