Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Vihan committed Jun 17, 2016
2 parents 3d03529 + 807d3d3 commit 48cfc76
Show file tree
Hide file tree
Showing 21 changed files with 500 additions and 44 deletions.
7 changes: 7 additions & 0 deletions .babelrc
@@ -0,0 +1,7 @@
{
"presets": ["es2015"],
"plugins": [
"babel-plugin-transform-class-properties",
"babel-plugin-add-module-exports"
]
}
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,22 @@
<!-- NOTE: If you have a PROPOSAL, then
this does not apply to you.
In that case, include a clear
definiton, a formal grammar for
your proposal, examples, and why
that feature would be helpful.
-->

**Version:** the version you're runnning. Found through `cheddar -V`

### Problem

Describe what exactly the problem you've found is.
Try not to just specify your particular instance.
Additionally, attempt to be as detailed as possible.

### Desired Behavior

### How to Reproduce

1. Do ...
2. Then do ...
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,3 +1,5 @@
node_modules
dist
coverage
coverage
update
npm-debug.log
10 changes: 10 additions & 0 deletions .travis.yml
Expand Up @@ -11,6 +11,16 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
install:
- npm install -g codeclimate-test-reporter
after_success:
- npm run coveralls
- bash <(curl -s https://codecov.io/bash)
- codeclimate-test-reporter < ./coverage/lcov.info
addons:
codeclimate:
repo_token:
- secure: CODECLIMATE_REPO_TOKEN
cache:
directories:
- node_modules
Expand Down
11 changes: 9 additions & 2 deletions Makefile
@@ -1,4 +1,11 @@
default:
babel --minify
build:
babel
install:
./bin/install
test:
./node_modules/.bin/mocha --reporter spec

babel-node ./node_modules/.bin/babel-istanbul cover _mocha
clean:
rm -rf ./dist/
.PHONY: test
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,11 @@
<a href="https://travis-ci.org/cheddar-lang/Cheddar"><img alt="Travis Status" src="https://travis-ci.org/cheddar-lang/Cheddar.svg?branch=master"></a>
<a href="https://gitter.im/cheddar-lang/Cheddar?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img alt="Join the chat at https://gitter.im/cheddar-lang/Cheddar" src="https://badges.gitter.im/cheddar-lang/Cheddar.svg"></a>
<a href="https://codeclimate.com/github/cheddar-lang/Cheddar"><img src="https://codeclimate.com/github/cheddar-lang/Cheddar/badges/gpa.svg" /></a>
<a href="https://codecov.io/gh/cheddar-lang/Cheddar">
<img src="https://codecov.io/gh/cheddar-lang/Cheddar/branch/master/graph/badge.svg" alt="Codecov" />
</a>
<a href='https://coveralls.io/github/cheddar-lang/Cheddar?branch=tests'><img src='https://coveralls.io/repos/github/cheddar-lang/Cheddar/badge.svg?branch=tests' alt='Coverage Status' /></a>
<img src='https://david-dm.org/cheddar-lang/Cheddar.svg' alt='Dependency Status' />
</p>

## Installation
Expand Down
10 changes: 8 additions & 2 deletions package.json
@@ -1,21 +1,27 @@
{
"name": "cheddar",
"version": "0.0.317",
"version": "0.1.2",
"dependencies": {
"colors": "^1.1.2",
"commander": "^2.9.0",
"readline": "^1.3.0"
},
"scripts": {
"prepublish": "./node_modules/.bin/grunt build --minify",
"build": "./node_modules/.bin/grunt build"
"build": "./node_modules/.bin/grunt build",
"test": "make test",
"coveralls": "make test && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.9.1",
"babel-istanbul": "^0.8.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"codecov.io": "^0.1.6",
"coveralls": "^2.11.9",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
"grunt-cli": "^1.2.0",
Expand Down
35 changes: 20 additions & 15 deletions src/cli/cheddar.es6
@@ -1,24 +1,29 @@
#!/usr/bin/env node

const pjson = require('../../package.json');
const program = require('commander');
const child_process = require('child_process');
const tty = require('tty');
const fs = require('fs');

/*== Handle REPL Seperately ==*/
if (!process.argv[2]) {
child_process.fork(__dirname + (tty.isatty(0) ? '/repl.js' : '/prog.js'));
}
if (!module.parent) {
/*== Handle REPL Seperately ==*/
if (!process.argv[2]) {
child_process.fork(__dirname + (tty.isatty(0) ? '/repl.js' : '/prog.js'));
}

program
.version(pjson.version)
.usage('[files ...] [options]')
.option('-e, --eval [code]', 'executes code, passed inline. implicit return')
.option('-E, --exec [code]', 'executes code, passed inline')
.option('-f, --file [path]', 'executes file')
.option('-i, --repl', 'Enters repl')
.parse(process.argv);
program
.version(pjson.version)
.usage('[files ...] [options]')
.option('-e, --eval [code]', 'executes code, passed inline. implicit return')
.option('-E, --exec [code]', 'executes code, passed inline')
.option('-f, --file [path]', 'executes file')
.option('-i, --repl', 'Enters repl')
.parse(process.argv);

program.args.forEach(file => child_process.exec(
`${__dirname}/prog.js < ${file}`
));
program.args.forEach(file => child_process.exec(
`${__dirname}/prog.js < ${file}`
));
} else {
module.exports = require('./prog');
}
56 changes: 41 additions & 15 deletions src/cli/prog.es6
@@ -1,23 +1,49 @@
#!/usr/bin/env node

import CheddarScope from '../interpreter/core/env/scope';

import cheddar from '../interpreter/exec';
import tokenizer from '../tokenizer/tok';

let GLOBAL_SCOPE = new CheddarScope();
import dep_String from '../interpreter/core/primitives/String';
import dep_Bool from '../interpreter/core/primitives/Bool';
import dep_Number from '../interpreter/core/primitives/Number';
import dep_Array from '../interpreter/core/primitives/Array';

import CheddarVariable from '../interpreter/core/env/var';

const CONSTANT = { Writeable: false };
let GLOBAL_SCOPE = new CheddarScope(null, new Map([
["String" , new CheddarVariable(dep_String, CONSTANT)],
["Number" , new CheddarVariable(dep_Number, CONSTANT)],
["Array" , new CheddarVariable(dep_Array , CONSTANT)],
["Boolean", new CheddarVariable(dep_Bool , CONSTANT)]
]));

let STDIN = "";
let chunk;
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
chunk = process.stdin.read();
if (chunk !== null)
STDIN += chunk;
});
process.stdin.on('end', () => {
let Tokenizer = new tokenizer(STDIN, 0);
let Result = Tokenizer.exec();
if (!module.parent) {
let STDIN = "";
let chunk;
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
chunk = process.stdin.read();
if (chunk !== null)
STDIN += chunk;
});
process.stdin.on('end', () => {
let Tokenizer = new tokenizer(STDIN, 0);
let Result = Tokenizer.exec();

let Executor = new cheddar(Result, GLOBAL_SCOPE);
Executor.exec();
});
let Executor = new cheddar(Result, GLOBAL_SCOPE);
Executor.exec();
});
} else {
module.exports = function(code, done, scope) {
let Tokenizer = new tokenizer(code, 0);
let Result = Tokenizer.exec();

let Executor = new cheddar(Result, scope || GLOBAL_SCOPE);
Executor.exec();

if (done) done(Executor);
}
}
18 changes: 16 additions & 2 deletions src/interpreter/core/eval/eval.es6
Expand Up @@ -29,7 +29,9 @@ import CheddarOperatorToken from '../../../tokenizer/literals/op';
import CheddarArrayToken from '../../../tokenizer/parsers/array';
import CheddarVariableToken from '../../../tokenizer/literals/var';


import CheddarVariable from '../env/var';
import CheddarClass from '../env/class';
import NIL from '../consts/nil';

// Call stack wrapper
Expand Down Expand Up @@ -102,8 +104,20 @@ export default class CheddarEval extends CheddarCallStack {
if (OPERATOR === CheddarError.NO_OP_BEHAVIOR) {
return CheddarErrorDesc.get(OPERATOR)
.replace(/\$0/g, Operation.Tokens[0])
.replace(/\$1/g, TOKEN ? TOKEN.constructor.Name : "nil")
.replace(/\$2/g, DATA ? DATA.constructor.Name : "nil");
.replace(/\$1/g, TOKEN ? (
TOKEN.constructor.Name || (
TOKEN.prototype instanceof CheddarClass
? "Class"
: "nil"
)
) : "nil")
.replace(/\$2/g, DATA ? (
DATA.constructor.Name || (
DATA.prototype instanceof CheddarClass
? "Class"
: "nil"
)
) : "nil");
} else {
this.put(OPERATOR);
}
Expand Down
1 change: 1 addition & 0 deletions src/interpreter/core/primitives/Array.es6
Expand Up @@ -18,6 +18,7 @@ export default class CheddarArray extends CheddarClass {
this.value = [];

for (let i = 0; i < items.length; i++) {
console.log(items[i]);
if (items[i] instanceof CheddarClass) {
// Is a class
this.value.push(items[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/core/primitives/cast/string.es6
Expand Up @@ -11,7 +11,7 @@ import CheddarNumberToken from '../../../../tokenizer/literals/number';
import HelperInit from '../../../../helpers/init';

export default new Map([
[CheddarNumber, (LHS) => {
['Number', (LHS) => {
let Attempt = new CheddarNumberToken(LHS, 0).exec();
if (Attempt instanceof CheddarLexer)
return HelperInit(CheddarNumber, ...Attempt._Tokens);
Expand Down
11 changes: 5 additions & 6 deletions src/interpreter/core/primitives/op/number.es6
Expand Up @@ -8,12 +8,13 @@ import HelperInit from '../../../../helpers/init';
// from Cyoce the almighty platypus modified;
// http://chat.stackexchange.com/transcript/message/27392766#27392766
const range = (a, b) => {
let CheddarNumber = require('../Number');
if (a > b) return range(b, a).reverse();
b = ~~b;
var iPart = a - ~~a;
a = ~~a;
var out = Array(b - a + 1);
while (b + iPart >= a) out[b - a] = b-- + iPart;
while (b + iPart >= a) out[b - a] = HelperInit(CheddarNumber, 10, 0, b-- + iPart);
if(iPart) out.pop();
return out;
};
Expand Down Expand Up @@ -157,10 +158,8 @@ export default new Map([

[':', (LHS, RHS) => {
let CheddarArray = require("../Array");
if (LHS === null)
return HelperInit(CheddarArray, range(0, ~~RHS.value - Math.sign(~~RHS.value)));
else if (RHS instanceof LHS.constructor)
return HelperInit(CheddarArray, range(LHS.value, RHS.value));
if (LHS && RHS instanceof LHS.constructor)
return HelperInit(CheddarArray, ...range(LHS.value, RHS.value));
else
return CheddarError.NO_OP_BEHAVIOR;
}],
Expand Down Expand Up @@ -221,7 +220,7 @@ export default new Map([
['acos', (LHS, RHS) => LHS === null
? HelperInit(RHS.constructor, 10, 0, Math.acos(RHS.value))
: CheddarError.NO_OP_BEHAVIOR],
['asin', (LHS, RHS) => LHS === null
['atan', (LHS, RHS) => LHS === null
? HelperInit(RHS.constructor, 10, 0, Math.atan(RHS.value))
: CheddarError.NO_OP_BEHAVIOR],

Expand Down
1 change: 1 addition & 0 deletions test/cheddar/casting.cdr
@@ -0,0 +1 @@
print "1+1=" + String::(1+1)
11 changes: 11 additions & 0 deletions test/cheddar/literals.cdr
@@ -0,0 +1,11 @@
"string";
'string';
123;
123.456;
0b101;
0o777;
0xFF;
true;
false;
[1,2,3];
[1, 2, 3];
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -0,0 +1 @@
--recursive
19 changes: 19 additions & 0 deletions test/test.js.template
@@ -0,0 +1,19 @@
var chai = require('chai');

chai.should();

var someFunction = (a, b) => a + b;

describe('something', () => {
it ('should do something', () => {
someFunction(3, 2).should.equal(5);
})
it ('should test stdout', function(){
it('tests', function(done) {
proc.stdout.once('data', function(output) {
expect(output.toString('utf-8')).to.eq('Would you like to play?\n');
done();
});
});
})
})
29 changes: 29 additions & 0 deletions test/tests/config/alias.js
@@ -0,0 +1,29 @@
var chai = require('chai');

chai.should();

// the .es6 files won't work, because they use import which node doesn't support. that's why we have babel-node, it means the code coverage shows the lines on the ES6 files too
// oh, okay, currently the `make test` doesn't use babel-node I don't think, should I just add `babel-node` to the beginning
// thouguh, but babel-node still have to compile a lot of stuff (almost all of cheddar)
// in which case idk if we should recompile
// tests should be called before you commit to origin, not necessarily every ten minutes. I wouldn't worry about speed
// ;_; okay
import CheddarString from '../../../src/interpreter/core/primitives/String.es6';
import CheddarNumber from '../../../src/interpreter/core/primitives/Number.es6';
import CheddarArray from '../../../src/interpreter/core/primitives/Array.es6' ;
import CheddarBool from '../../../src/interpreter/core/primitives/Bool.es6' ;

var result = new Map([
['String', CheddarString],
['Number', CheddarNumber],
['Array' , CheddarArray ],
['Bool' , CheddarBool ],
]);

var Alias = require('../../../src/interpreter/core/config/alias.es6');

describe('alias config', () => {
it ('should provide a correct result', () => {
Alias.should.deep.equal(result);
})
})

0 comments on commit 48cfc76

Please sign in to comment.