ndreynolds / flathead Goto Github PK
View Code? Open in Web Editor NEWA toy JavaScript interpreter written in C
License: MIT License
A toy JavaScript interpreter written in C
License: MIT License
Hello,I want porting this componet to RTOS,but this source code hava too much stdio/FILE and so on func,
what can I do?
The current lexer for RegExp literals is pretty basic:
https://github.com/ndreynolds/flathead/blob/master/src/lexer.l#L116-119
It doesn't allow any spaces or forward slashes, but those should be allowed. It needs to be expanded to support the full grammar as given in the spec.
Add the body to func_new
in Function.c
and new tests to test_function_global.js
according to the spec. For example:
(new Function('x', 'y', 'return x * y'))(2, 2)
// 4
The trouble with this one is parsing the function body that's given as the last argument. It's going to need to get routed through Flex and Bison. There's a proof-of-concept load
function that treads in this water, but it needs some more work itself.
Hi team,
I found a segmentation fault error at src/eval.c:374( at function assign's first line).
Reproduction:
$ /path/to/flathead/bin/flat trigger.js
The content of trigger.js is :
var a =0[1,2];
make test
bin/test --dir test -x bin/flat
/usr/bin/env: node: 没有那个文件或目录
make: *** [test] 错误 127
Add support for RegExp separators to str_proto_split
in String.c
and new tests in test_string_global.js
.
Currently, only a string can be given as the separator, but the spec also allows a RegExp, e.g.
"Hello 1 word. Sentence number 2.".split(/(\d)/)
// ["Hello ", "1", " word. Sentence number ", "2", "."]
var result = [];
for (var i=0; i<2; i++) {
(function () {
var copy = i;
var func = function () {
return copy;
};
result.push(func);
}());
}
console.log(result[0]());
Flat will report Reference error while node engine does not:
$ ./flathead/bin/flat ./test.js
ReferenceError: copy is not defined
at ./test.js:6:10
at (anonymous function) in ./test.js:12:22
$ node ./test.js
0
for.js as below:
function test(times) {
var i;
for (i=0; i<times; i++) {
print("times " + i);
}
}
test(1000);
flat for.js
times 0
times 1
.....
times 857
// not output 858 to 999
Implement the try
and throw
statements (along with catch
and finally
) as specified in ES5.1 12.13 and 12.14.
The productions for these statements have already been added to the Bison grammar:
https://github.com/ndreynolds/flathead/blob/master/src/grammar.y#L445-467
To get try
, throw
and friends working, the existing state trace will probably need to be expanded to store pointers to evaluation states. We'll need to add new cases to the switch statement in eval.c and likely a few new functions below those for the implementation.
Add an implementation for String.prototype.replace to String.c
and tests to test_string_global.js
following the spec here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.