Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 161 lines (117 sloc) 4.703 kb
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
1 possible syntax for mole ("M0 Overlay LanguagE")
bfaf059 cotto add thoughts on constants and types
cotto authored
2 *******
3 *types*
4 *******
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
5
79b7f4d cotto Revert some thoughts from lucian++.
cotto authored
6 I propose that we have 5 types; INSP for registers and cs, which is a C-like
7 string. (This probably won't be exactly like a C-string, but close enough that
8 C code can use it if needed.)
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
9
10 registers: I, N, S, P
11 primitive string: cs
12
13
bfaf059 cotto add thoughts on constants and types
cotto authored
14 *****************
15 *constant values*
16 *****************
17
18 This describes what kind of constants can be used in mole code.
19
20 int: [1-9]\d*
21 float: ...
22 hex: 0[xX][0-9a-fA-F]+
23 octal: 0[0-7]+
24 string: "[...]" (with escapes)
25
26
27
28 ************************
29 *compile-time constants*
30 ************************
31
79b7f4d cotto Revert some thoughts from lucian++.
cotto authored
32
bfaf059 cotto add thoughts on constants and types
cotto authored
33
34 **********************
35 *working with strings*
36 **********************
37
79b7f4d cotto Revert some thoughts from lucian++.
cotto authored
38 Strings pretend to be 0-indexed. They actually also store their length and
39 encoding as the first five values. The length is stored as a 4B int and the
bfaf059 cotto add thoughts on constants and types
cotto authored
40 encoding is stored in one byte, with 3 unused bytes for padding. The string
41 for "hello, worlds?" would look as follows in memory:
42
43 0x0 0x4 0x8 0xA 0x10 0x14
44 ---------------------------------------------------------------------------------------------
45 |0x0|0x0|0x0|0xC|0x0|0x0|0x0|0x1| h | e | l | l | o | , | | w | o | r | l | d | s | ? |\0 |
46 ---------------------------------------------------------------------------------------------
47 size encoding 0x0 0x4 0x8 0xA
48
49
50
51 *********
52 *structs*
53 *********
54
8f3c90e cotto add random thoughts of calling conventions
cotto authored
55 Structs may be defined as below. Once a struct is defined, it can be used
56 wherever any other type can be used. If a register is of a struct type, it is
57 assumed to point to a region of memory with the specified layout. Struct
58 members are accessed using the '->' notation, as in C. sizeof() can be used to
59 determine the number of bytes required by the struct. This is similar to C,
60 except that sizeof() is purely a compile-time construct and can not be used to
61 calculate the length of an array.
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
62
63 struct {
64 I int_thingy;
65 N n_thingy;
66 } struct_thingy;
67
bfaf059 cotto add thoughts on constants and types
cotto authored
68 var I quux;
3450704 cotto add missing semicolons
cotto authored
69
bfaf059 cotto add thoughts on constants and types
cotto authored
70 var struct_thingy st;
71
9372f39 cotto specify chunk and composed ops a bit more completely
cotto authored
72 st = m0::sys_alloc sizeof(struct_thingy);
8f3c90e cotto add random thoughts of calling conventions
cotto authored
73 st->int_thingy = 39292934;
74 st->n_thingy = 332.66;
bfaf059 cotto add thoughts on constants and types
cotto authored
75
76
9372f39 cotto specify chunk and composed ops a bit more completely
cotto authored
77 ********
78 *chunks*
79 ********
80
81 Chunks are similar to functions. They have a constants table, a metadata table
82 and a bytecode segment. Values can be added to the constants table by
83 declaring a value with the keyword "const". Annotations may be added
84 automatically by the mole compiler and can also be added manually with the .ann
85 "key" "value" syntax.
86
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
87
88 chunk main (I a1, I a2, I a3) {
89 const I stdout 1;
90 const cs hello "ohai. im in ur m0";
91
92 // annotation for the right file will be added by m1 compiler
93 m0::print_i stdout, hello;
94 var I i_thingy;
95 i_thingy += a3++;
96 c::fprintf(stdout, "asdfw %d\n", i_thingy);
6bb5ee1 cotto more syntax thoughts
cotto authored
97 call_chunk "chunk_name", arg_array;
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
98 }
99
bfaf059 cotto add thoughts on constants and types
cotto authored
100
8f3c90e cotto add random thoughts of calling conventions
cotto authored
101
102 *********************
103 *calling conventions*
104 *********************
105
106 I don't know. There are a couple options:
107
108 1) The first is that all calling conventions need to be dealt with explicitly.
109 This isn't nearly as bad as it'd be under M0 because of composed ops and it
110 would allow a very high degree of control without requiring the management of
111 all the minutae of the calling conventions more than once.
112
113 2) The second option is to have a default set of calling conventions that are
114 used with a simple minimalist syntax, but to allow them to be overridden with
115 composed ops.
116
117 3) The third option is to say that only the builtins can be used for control
118 flow. For a very experimental language like mole, this approach is probably
119 insane.
120
121
bfaf059 cotto add thoughts on constants and types
cotto authored
122 **************
123 *composed ops*
124 **************
125
9372f39 cotto specify chunk and composed ops a bit more completely
cotto authored
126 mole supports syntax to create composed ops which behave similarly to built-in
127 M0 ops. The syntax is similar to chunnks with a few differences. Composed ops
b7b1189 cotto make composed op definition less ambiguous
cotto authored
128 are declared using the "composed" keyword and do not have return statements.
129 Any values that the composed op needs to modify should passed as arguments.
130 Using a return statement in composed op is a syntax error. Composed ops may
131 take an arbitrary number of arguments. Variables may be declared in composed
132 ops as in functions. composed ops are similar to inlined functions in C.
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
133
6bb5ee1 cotto more syntax thoughts
cotto authored
134 composed init_cf(P new_cf, I retpc_label) {
135 alloc_cf:
9372f39 cotto specify chunk and composed ops a bit more completely
cotto authored
136 I cf_size = 256;
137 I flags = 0;
6bb5ee1 cotto more syntax thoughts
cotto authored
138 new_cf = m0::gc_alloc cf_size, flags;
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
139
6bb5ee1 cotto more syntax thoughts
cotto authored
140 init_cf_copy:
141 new_cf[INTERP] = cf[INTERP];
142 new_cf[CHUNK] = cf[CHUNK];
143 new_cf[CONSTS] = cf[CONSTS];
3450704 cotto add missing semicolons
cotto authored
144 new_cf[MDS] = cf[MDS];
145 new_cf[BCS] = cf[BCS];
6bb5ee1 cotto more syntax thoughts
cotto authored
146 new_cf[PCF] = cf[CF];
147 new_cf[CF] = new_cf;
148
149 init_cf_zero:
150 new_cf[EH] = 0;
151 new_cf[RETPC] = 0;
152 new_cf[SPILLCF] = 0;
153 RETPC = retpc_label;
154
155 init_cf_pc:
156 new_cf[PC] = post_set;
157 CF = new_cf;
158
159 post_set:
ef0bd22 cotto add initial uncomplete thoughts of mole syntax
cotto authored
160 }
Something went wrong with that request. Please try again.