Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

low-level C-family language that spits out M0

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 docs
Octocat-spinner-32 examples few editions to examples [WIP]. Improve variable naming. And most imp… June 18, 2012
Octocat-spinner-32 failures
Octocat-spinner-32 src
Octocat-spinner-32 t
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CREDITS
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 run_m1.sh
README.md

M1

low-level C-family language that spits out M0

Overview

M1 was defined as a C-like language but much simplified. C is a very large language, and its syntax allows to implement many types of hacks. The goal of M1 is to implement a useful subset, extended with specific functionality (and syntax) that is useful to implement Parrot. As a result of being a restricted subset of C, the language forces to use a "standardized" way of using the language.

Ideas for future features

  • Built-in splint-like checks
  • Built-in coding standards checks (resulting in syntax errors if not adhered to)

Running

After downloading the source code, just type "make". Then invoke ./m1 .

Testing M1

To run the M1 test suite:

make test

Language grammar

Insert M1 grammar here.

Implementation

M1 is implemented in C. The parser is implemented using Bison, whereas the lexer is implemented using Flex. The compiler consists of the following modules

  • Lexer (m1.l)
  • Parser (m1.y)
  • Abstract Syntax Tree nodes (m1_ast.c,h)
  • Code generator (m1_codegen.c,h)

Other files include:

  • Compiler definition (m1_compiler.h)
  • Source code annotations for splint (m1_ann.h)

The M1 compiler is reentrant; the parser and lexer that are generated are therefore also reentrant. {{note: a few things to fix for this}}.

Abstract Syntax Tree

During the parsing phase, the parser invokes AST node constructors. Most expressions and statements are represented by m1_expression nodes. Keeping the number of node types limited simplifies the AST, which makes it easier to understand the compiler.

Code generator

The code generator walks the AST, and generates instructions for each node, if applicable. Most functions in the code generator return a m1_reg structure, which represents a register, containing the register number and register type. The m1_reg structure that is returned contains the register that will hold the result of the evaluation of the AST node.

License

Artistic 2.0

Something went wrong with that request. Please try again.