Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bfaf05986d
Fetching contributors…

Cannot retrieve contributors at this time

124 lines (90 sloc) 3.039 kb
possible syntax for mole ("M0 Overlay LanguagE")
*******
*types*
*******
I propose that we have 5 types; INSP for registers and cs, which is a C-like
string. (This probably won't be exactly like a C-string, but close enough that
C code can use it if needed.)
registers: I, N, S, P
primitive string: cs
*****************
*constant values*
*****************
This describes what kind of constants can be used in mole code.
int: [1-9]\d*
float: ...
hex: 0[xX][0-9a-fA-F]+
octal: 0[0-7]+
string: "[...]" (with escapes)
************************
*compile-time constants*
************************
**********************
*working with strings*
**********************
Strings pretend to be 0-indexed. They actually also store their length and
encoding as the first five values. The length is stored as a 4B int and the
encoding is stored in one byte, with 3 unused bytes for padding. The string
for "hello, worlds?" would look as follows in memory:
0x0 0x4 0x8 0xA 0x10 0x14
---------------------------------------------------------------------------------------------
|0x0|0x0|0x0|0xC|0x0|0x0|0x0|0x1| h | e | l | l | o | , | | w | o | r | l | d | s | ? |\0 |
---------------------------------------------------------------------------------------------
size encoding 0x0 0x4 0x8 0xA
*********
*structs*
*********
Once a struct is defined, it can be used wherever any other type can be used.
Struct members are accessed using the '.' notation, as in C. sizeof() can be
used to determine the number of bytes required by the struct. This is similar
to C, except that sizeof() is purely a compile-time construct and can not be
used to calculate the length of an array.
struct {
I int_thingy;
N n_thingy;
} struct_thingy;
var I quux;
var struct_thingy st;
st = m0::sys_alloc sizeof(struct_thingy)
***********
*functions*
***********
chunk main (I a1, I a2, I a3) {
const I stdout 1;
const cs hello "ohai. im in ur m0";
// annotation for the right file will be added by m1 compiler
m0::print_i stdout, hello;
var I i_thingy;
i_thingy += a3++;
c::fprintf(stdout, "asdfw %d\n", i_thingy);
call_chunk "chunk_name", arg_array;
}
**************
*composed ops*
**************
* acts like an inline function
* has temporary registers, decleared inline
* does not have an explict return statement
composed init_cf(P new_cf, I retpc_label) {
alloc_cf:
tmp I cf_size = 256;
tmp I flags = 0;
new_cf = m0::gc_alloc cf_size, flags;
init_cf_copy:
new_cf[INTERP] = cf[INTERP];
new_cf[CHUNK] = cf[CHUNK];
new_cf[CONSTS] = cf[CONSTS];
new_cf[MDS] = cf[MDS]
new_cf[BCS] = cf[BCS]
new_cf[PCF] = cf[CF];
new_cf[CF] = new_cf;
init_cf_zero:
new_cf[EH] = 0;
new_cf[RETPC] = 0;
new_cf[SPILLCF] = 0;
RETPC = retpc_label;
init_cf_pc:
new_cf[PC] = post_set;
CF = new_cf;
post_set:
}
Jump to Line
Something went wrong with that request. Please try again.