Skip to content

Commit 0fe4d68

Browse files
committed
Initial commit
0 parents  commit 0fe4d68

File tree

6 files changed

+1239
-0
lines changed

6 files changed

+1239
-0
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2016 Baptiste Augrain
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@kaoscript/runtime
2+
=================================================================
3+
4+
*@kaoscript/runtime* provides the runtime for Kaoscript
5+
6+
License
7+
-------
8+
9+
Copyright © 2016 Baptiste Augrain
10+
11+
Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).

build/runtime.js

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
module.exports = function() {
2+
var {Class, Type} = require("../src/runtime.js");
3+
var __ks_Array = {};
4+
Class.newClassMethod({
5+
class: Array,
6+
name: "map",
7+
final: __ks_Array,
8+
function: function(array, iterator) {
9+
if(array === undefined || array === null) {
10+
throw new Error("Missing parameter 'array'");
11+
}
12+
if(!Type.isArray(array)) {
13+
throw new Error("Invalid type for parameter 'array'");
14+
}
15+
if(iterator === undefined || iterator === null) {
16+
throw new Error("Missing parameter 'iterator'");
17+
}
18+
if(!Type.isFunction(iterator)) {
19+
throw new Error("Invalid type for parameter 'iterator'");
20+
}
21+
let results = [];
22+
for(let index = 0, __ks_0 = array.length, item; index < __ks_0; ++index) {
23+
item = array[index];
24+
results.push(iterator(item, index));
25+
}
26+
return results;
27+
},
28+
signature: {
29+
min: 2,
30+
max: 2,
31+
parameters: [
32+
{
33+
type: "Array",
34+
min: 1,
35+
max: 1
36+
},
37+
{
38+
type: "Function",
39+
min: 1,
40+
max: 1
41+
}
42+
]
43+
}
44+
});
45+
Class.newClassMethod({
46+
class: Array,
47+
name: "map",
48+
final: __ks_Array,
49+
function: function(array, iterator, condition) {
50+
if(array === undefined || array === null) {
51+
throw new Error("Missing parameter 'array'");
52+
}
53+
if(!Type.isArray(array)) {
54+
throw new Error("Invalid type for parameter 'array'");
55+
}
56+
if(iterator === undefined || iterator === null) {
57+
throw new Error("Missing parameter 'iterator'");
58+
}
59+
if(!Type.isFunction(iterator)) {
60+
throw new Error("Invalid type for parameter 'iterator'");
61+
}
62+
if(condition === undefined || condition === null) {
63+
throw new Error("Missing parameter 'condition'");
64+
}
65+
if(!Type.isFunction(condition)) {
66+
throw new Error("Invalid type for parameter 'condition'");
67+
}
68+
let results = [];
69+
for(let index = 0, __ks_0 = array.length, item; index < __ks_0; ++index) {
70+
item = array[index];
71+
if(condition(item, index)) {
72+
results.push(iterator(item, index));
73+
}
74+
}
75+
return results;
76+
},
77+
signature: {
78+
min: 3,
79+
max: 3,
80+
parameters: [
81+
{
82+
type: "Array",
83+
min: 1,
84+
max: 1
85+
},
86+
{
87+
type: "Function",
88+
min: 2,
89+
max: 2
90+
}
91+
]
92+
}
93+
});
94+
var __ks_Function = {};
95+
Class.newClassMethod({
96+
class: Function,
97+
name: "curry",
98+
final: __ks_Function,
99+
function: function() {
100+
if(arguments.length < 2) {
101+
throw new Error("Wrong number of arguments");
102+
}
103+
let __ks_i = -1;
104+
if(Type.isFunction(arguments[++__ks_i])) {
105+
var self = arguments[__ks_i];
106+
}
107+
else throw new Error("Invalid type for parameter 'self'")
108+
if(arguments.length > 2) {
109+
var bind = arguments[++__ks_i];
110+
}
111+
else {
112+
var bind = null;
113+
}
114+
var args = arguments[++__ks_i];
115+
return function(...supplements) {
116+
return self.apply(bind, args.concat(supplements));
117+
};
118+
},
119+
signature: {
120+
min: 2,
121+
max: 3,
122+
parameters: [
123+
{
124+
type: "Function",
125+
min: 1,
126+
max: 1
127+
},
128+
{
129+
type: "Any",
130+
min: 1,
131+
max: 2
132+
}
133+
]
134+
}
135+
});
136+
Class.newClassMethod({
137+
class: Function,
138+
name: "vcurry",
139+
final: __ks_Function,
140+
function: function(self, bind = null, ...args) {
141+
if(self === undefined || self === null) {
142+
throw new Error("Missing parameter 'self'");
143+
}
144+
if(!Type.isFunction(self)) {
145+
throw new Error("Invalid type for parameter 'self'");
146+
}
147+
return function(...supplements) {
148+
return self.apply(bind, args.concat(supplements));
149+
};
150+
},
151+
signature: {
152+
min: 1,
153+
max: Infinity,
154+
parameters: [
155+
{
156+
type: "Function",
157+
min: 1,
158+
max: 1
159+
},
160+
{
161+
type: "Any",
162+
min: 0,
163+
max: Infinity
164+
}
165+
]
166+
}
167+
});
168+
var __ks_Object = {};
169+
Class.newClassMethod({
170+
class: Object,
171+
name: "append",
172+
final: __ks_Object,
173+
function: function(object, ...args) {
174+
if(object === undefined || object === null) {
175+
throw new Error("Missing parameter 'object'");
176+
}
177+
for(let __ks_0 = 0, __ks_1 = args.length, arg; __ks_0 < __ks_1; ++__ks_0) {
178+
arg = args[__ks_0];
179+
if(arg) {
180+
for(let key in arg) {
181+
let value = arg[key];
182+
object[key] = value;
183+
}
184+
}
185+
}
186+
return object;
187+
},
188+
signature: {
189+
min: 1,
190+
max: Infinity,
191+
parameters: [
192+
{
193+
type: "Any",
194+
min: 1,
195+
max: Infinity
196+
}
197+
]
198+
}
199+
});
200+
Class.newClassMethod({
201+
class: Object,
202+
name: "map",
203+
final: __ks_Object,
204+
function: function(object, iterator) {
205+
if(object === undefined || object === null) {
206+
throw new Error("Missing parameter 'object'");
207+
}
208+
if(!Type.isObject(object)) {
209+
throw new Error("Invalid type for parameter 'object'");
210+
}
211+
if(iterator === undefined || iterator === null) {
212+
throw new Error("Missing parameter 'iterator'");
213+
}
214+
if(!Type.isFunction(iterator)) {
215+
throw new Error("Invalid type for parameter 'iterator'");
216+
}
217+
let results = [];
218+
for(let item in object) {
219+
let index = object[item];
220+
results.push(iterator(item, index));
221+
}
222+
return results;
223+
},
224+
signature: {
225+
min: 2,
226+
max: 2,
227+
parameters: [
228+
{
229+
type: "Object",
230+
min: 1,
231+
max: 1
232+
},
233+
{
234+
type: "Function",
235+
min: 1,
236+
max: 1
237+
}
238+
]
239+
}
240+
});
241+
Class.newClassMethod({
242+
class: Object,
243+
name: "map",
244+
final: __ks_Object,
245+
function: function(object, iterator, condition) {
246+
if(object === undefined || object === null) {
247+
throw new Error("Missing parameter 'object'");
248+
}
249+
if(!Type.isObject(object)) {
250+
throw new Error("Invalid type for parameter 'object'");
251+
}
252+
if(iterator === undefined || iterator === null) {
253+
throw new Error("Missing parameter 'iterator'");
254+
}
255+
if(!Type.isFunction(iterator)) {
256+
throw new Error("Invalid type for parameter 'iterator'");
257+
}
258+
if(condition === undefined || condition === null) {
259+
throw new Error("Missing parameter 'condition'");
260+
}
261+
if(!Type.isFunction(condition)) {
262+
throw new Error("Invalid type for parameter 'condition'");
263+
}
264+
let results = [];
265+
for(let item in object) {
266+
let index = object[item];
267+
if(condition(item, index)) {
268+
results.push(iterator(item, index));
269+
}
270+
}
271+
return results;
272+
},
273+
signature: {
274+
min: 3,
275+
max: 3,
276+
parameters: [
277+
{
278+
type: "Object",
279+
min: 1,
280+
max: 1
281+
},
282+
{
283+
type: "Function",
284+
min: 2,
285+
max: 2
286+
}
287+
]
288+
}
289+
});
290+
return {
291+
Array: Array,
292+
Class: Class,
293+
Function: Function,
294+
Object: Object,
295+
Type: Type,
296+
__ks_Array: __ks_Array,
297+
__ks_Function: __ks_Function,
298+
__ks_Object: __ks_Object
299+
};
300+
}

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@kaoscript/runtime",
3+
"description": "Runtime for Kaoscript",
4+
"version": "0.1.0",
5+
"author": {
6+
"name": "Baptiste Augrain",
7+
"email": "daiyam@zokugun.org"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/kaoscript/runtime"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/kaoscript/runtime/issues"
15+
},
16+
"licenses": [
17+
{
18+
"type": "MIT",
19+
"url": "http://www.opensource.org/licenses/mit-license.php"
20+
}
21+
],
22+
"main": "build/runtime.js",
23+
"files": [
24+
"build",
25+
"src"
26+
],
27+
"dependencies": {
28+
},
29+
"devDependencies": {
30+
},
31+
"engines": {
32+
"node": ">= 6.0.0"
33+
},
34+
"kaoscript": {
35+
"main": "src/runtime.ks"
36+
}
37+
}

0 commit comments

Comments
 (0)