Giter Site home page Giter Site logo

franklin2412 / como-lang-ng Goto Github PK

View Code? Open in Web Editor NEW

This project forked from analang/como-lang-ng

0.0 2.0 0.0 235 KB

A programming language prototype implemented in C with an AST, Compiler, and Virtual Machine \@TODO Garbage Collection

License: GNU General Public License v3.0

Makefile 0.34% C 91.91% Lex 2.02% Yacc 4.23% Shell 0.02% Vim Script 1.28% Assembly 0.21%

como-lang-ng's Introduction

COMO: como object meta oriented

even.como

func isodd(num) {
	i = 0;
	odd = 0;
	while((i == num) == 0) {
		if(odd == 0) {
			odd = 1;
		} else {
			odd = 0;
		}
		i = i + 1;
	}
	return odd;
}

func print_even(num)
{
	while(num) {
		if(isodd(num)) {
			print(num + " is odd");
		} else {
			print(num + " is even");
		}
		num = num - 1;
	}
}

print_even(4);

range

func print_range(a, b) {
	while(a <= b) {
		print(a);
		a = a + 1;
	}
}

Build Requirements

I only compile this on UNIX like systems. You need the standard build tools such as autoconf, libtool, and flex and bison. Also there is a runtime requirement : libobject which you can get at https://github.com/libobject/libobject

License

Please see the file LICENSE located in the root directory of the project.

Virtual Machine

The compiler generates instructions of the custom instruction set (como_opcode.h) The virtual machine is stack based and only a few instructions take operands. Most instructions pop there arguments from the stack. Here is the relevant source code and instruction output generated from the compiler. This was run with the following command: ./como --print-asm test/for_loop

for(i = 5; i >= 0; i--)
{
  if(i % 2 == 0) {
    print(i);
  }
}
0       LABEL
1       LOAD_CONST 5
2       STORE_NAME i
3       LOAD_NAME i
4       LOAD_CONST 0
5       IS_GREATER_THAN_OR_EQUAL
6       JZ 25
7       LABEL
8       LOAD_NAME i
9       LOAD_CONST 2
10      IREM
11      LOAD_CONST 0
12      IS_EQUAL
13      JZ 17
14      LOAD_NAME i
15      IPRINT
16      JMP 18
17      LABEL
18      LABEL
19      POSTFIX_DEC
20      LOAD_NAME i
21      LOAD_CONST 0
22      IS_GREATER_THAN_OR_EQUAL
23      JZ 25
24      JMP 7
25      LABEL
26      HALT

Problems

  • There is no continue, or break statements in loops at this time. The first idea that comes to mind to implement this is to have the executor keep track if the VM is in a loop and store the correct JMP address. This is on the roadmap for 2017

como-lang-ng's People

Contributors

rmccullagh avatar cesquivias avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.