Commit graph

1614 commits

Author SHA1 Message Date
Andreas Kling
f405cb6a77 LibJS: Implement basic MemberExpression parsing
At last we can parse "hello friends".length :^)
2020-03-12 13:05:57 +01:00
Andreas Kling
ed100bc6f4 LibJS: Implement basic lexing + parsing of StringLiteral
This still includes the double-quote characters (") but at least the
AST comes out right.
2020-03-12 13:05:06 +01:00
Oriko
d8a73dd979 LibGUI: Parse #include statements separately 2020-03-12 12:37:13 +01:00
Liav A
b13417ddb4 ACPI: Examine bit width in Generic address structure before asserting
Also, the switch-case flow is simplified for IO access within a Generic
address strucuture's handling.
2020-03-12 12:36:38 +01:00
Alex Muscar
673848f472
LibGUI: Track window visibility with a separate flag (#1424)
See https://github.com/SerenityOS/serenity/pull/1410 for the motivation.
2020-03-12 12:32:28 +01:00
howar6hill
01133733dd
LibJS: Allow functions to take arguments (#1405) 2020-03-12 12:22:13 +01:00
Andreas Kling
425fd3ce51 LibJS: Defer Value construction until a Literal is executed
Remove the need to construct a full Value during parsing. This means
we don't have to worry about plumbing the heap into the parser.

The Literal ASTNode now has a bunch of subclasses that synthesize a
Value on demand.
2020-03-12 12:19:11 +01:00
Andreas Kling
0d42097cf1 LibJS: Forgot to move add/sub/typed_eq to Value.cpp 2020-03-12 09:26:23 +01:00
Stephan Unverwerth
f3a9eba987 LibJS: Add Javascript lexer and parser
This adds a basic Javascript lexer and parser. It can parse the
currently existing demo programs. More work needs to be done to
turn it into a complete parser than can parse arbitrary JS Code.

The lexer outputs tokens with preceeding whitespace and comments
in the trivia member. This should allow us to generate the exact
source code by concatenating the generated tokens.

The parser is written in a way that it always returns a complete
syntax tree. Error conditions are represented as nodes in the
tree. This simplifies the code and allows it to be used as an
early stage parser, e.g for parsing JS documents in an IDE while
editing the source code.:
2020-03-12 09:25:49 +01:00
Florian Stellbrink
17705d23fb LibJS: Fix string roots not being collected
Previously objects were the only heap
allocated value. Now there are also strings.

This replaces a usage of is_object with is_cell.
Without this change strings could be garbage
collected while still being used in an active scope.
2020-03-12 07:50:49 +01:00
Marios Prokopakis
8cf962a102
Userland: Set the mask of a network adapter with ifconfig (#1388)
A new IP address or a new network mask can be specified in the command
line arguments of ifconfig to replace the old values of a given network
adapter. Additionally, more information is being printed for each adapter.
2020-03-11 21:30:41 +01:00
Alex Muscar
4c9bb266df
LibGUI: Don't update windows that aren't visible (#1410)
Because the ID of a hidden window is 0, the window server will
fail to update them when the system theme is changed. This
manifests when an application has multiple windows, some of
which are hidden, and the system theme is changed (see
https://github.com/SerenityOS/serenity/issues/1378).

This PR changes the window code to ignore update messages if
the window has the ID 0--is hidden.

Ideally the window ID would not change, and visibility would be
managed separately.
2020-03-11 21:28:19 +01:00
Tibor Nagy
39a843470c LibWeb: Skip non-font files when looking for fonts instead of asserting 2020-03-11 21:27:03 +01:00
Tibor Nagy
6c32882f05 LibGfx: Do not assert on failed font file loads
Return a nullptr to signal an error instead.
2020-03-11 21:27:03 +01:00
Tibor Nagy
cebf6a7039 LibGUI: Skip non-font files in the FontDatabase constructor 2020-03-11 21:27:03 +01:00
Oriko
8d54e4e012 LibGUI: Highlight various number literals 2020-03-11 21:26:47 +01:00
0xtechnobabble
df40c85f80
LibJS: Allow the choice of a scope of declaration for a variable (#1408)
Previously, we were assuming all declared variables were bound to a
block scope, now, with the addition of declaration types, we can bind
a variable to a block scope using `let`, or a function scope (the scope
of the inner-most enclosing function of a `var` declaration) using
`var`.
2020-03-11 20:09:20 +01:00
Andreas Kling
542108421e LibJS: Support "hello friends".length
The above snippet is a MemberExpression that necessitates the implicit
construction of a StringObject wrapper around a PrimitiveString.

We then do a property lookup (a "get") on the StringObject, where we
find the "length" property. This is pretty neat! :^)
2020-03-11 19:00:26 +01:00
Andreas Kling
6ec6fa1a02 LibJS: Add StringObject, an Object wrapper around primitive strings
This object will (soon) be implicitly created to wrap a primitive
string when one is used in a context that requires an object.
2020-03-11 19:00:26 +01:00
Andreas Kling
111ef762f6 LibJS: Add a new PrimitiveString class to hold GC-allocated strings 2020-03-11 19:00:22 +01:00
Andreas Kling
29c7a5dcbe LibJS: Simplify Literal::dump() 2020-03-11 19:00:20 +01:00
Oriko
7b13fb557b LibGUI: Fix overflow crash in highlighter 2020-03-11 13:24:52 +01:00
Oriko
d58cf1a05d LibGUI: Syntax highlight string escape sequences 2020-03-11 10:16:55 +01:00
Oriko
03b1748d3f LibGUI: Clear old syntax highlighting 2020-03-11 10:05:01 +01:00
Andreas Kling
ddb5c995c6 LibJS: Let's say that Identifier is an Expression for now
This allows us to tighten typing in various other classes.
2020-03-10 12:29:28 +01:00
Andreas Kling
7de35118a9 LibJS: Move Value ops into Value.cpp and tweak BinaryOp names 2020-03-10 12:29:00 +01:00
Andreas Kling
fe6bd9650f LibJS: Use Value::to_boolean() wherever we haven't checked is_boolean()
Unless we've verified that a Value is a boolean, we should not be
calling as_bool() on it.
2020-03-10 12:28:10 +01:00
Alex Muscar
81c6f72134
EventLoop: Don't destroy ID allocator (#1403)
The ID allocator is destroyed before a timer in HackStudio is
is unregistered leading to an access violation.

Fixes #1382.
2020-03-10 11:31:37 +01:00
Andreas Kling
a0e18f4450 LibJS: Oops, non-zero values should boolify to true, not false 2020-03-10 10:08:42 +01:00
Andreas Kling
dc0b091c31 LibJS: Implement basic boolean coercion
We can't expect the conditionals in "if" and "while" statements to
always return a bool, so we need to know how to boolify a JS::Value.
2020-03-10 08:47:36 +01:00
Andreas Kling
386867da9f LibJS: Add a convenience helper for visiting a JS::Value
We only really care to visit values if they refer to a Cell, but it's
nice to be able to say visit(some_value).
2020-03-09 22:19:06 +01:00
Andreas Kling
05c80cac20 LibJS: Make the GC marking phase cycle-proof
Don't visit cells that are already marked. This prevents the marking
phase from looping forever when two cells refer to each other.

Also do the marking directly from the CellVisitor, removing another
unnecessary phase of the collector. :^)
2020-03-09 22:18:03 +01:00
Andreas Kling
0d6be2cac2 LibJS: Make FunctionDeclaration and CallExpression scope-aware 2020-03-09 21:53:39 +01:00
Andreas Kling
363c40e3f3 LibJS: Make sure we mark everything reachable from the scope stack
This ensures that local variables survive GC.
2020-03-09 21:49:20 +01:00
Andreas Kling
26165cd92a LibJS: Add a very simple ObjectExpression for "var x = {}"
This allows us to allocate an empty new Object on the GC heap.
2020-03-09 21:49:20 +01:00
Andreas Kling
15d8b9c671 LibJS: Add magical "$gc" function that can be called to trigger GC
This will be immensely useful for testing.
2020-03-09 21:49:20 +01:00
Andreas Kling
1382dbc5e1 LibJS: Add basic support for (scoped) variables
It's now possible to assign expressions to variables. The variables are
put into the current scope of the interpreter.

Variable lookup follows the scope chain, ending in the global object.
2020-03-09 21:49:20 +01:00
Andreas Kling
c6e54d2a49 LibJS: Simplify Heap::mark_live_cells()
Instead of iterating over every single cell, simply iterate over the
live cells and mark them from there.

Thanks to Blam for suggesting this! :^)
2020-03-09 19:36:15 +01:00
0xtechnobabble
5e817ee678 LibJS: Move logical not operator to new unary expression class 2020-03-09 19:33:07 +01:00
0xtechnobabble
65343388b8 LibJS: Add new bitwise and relational operators
Do note that when it comes to evaluating binary expressions, we are
asserting in multiple contexts that the values we're operating on are
numbers, we should probably handle other value types to be more tolerant
in the future, since for example, adding a number and a string, in
which case the number is converted to a string implicitly which is then
concatenated, although ugly, is valid javascript.
2020-03-09 19:33:07 +01:00
howar6hill
11aac6fdce
LibJS: Remove superfluous explicit in AST.h (#1395) 2020-03-09 14:37:08 +01:00
Liav A
032ce1948e LibBareMetal: Return FlatPtr from PhysicalAddress::offset_in_page() 2020-03-09 10:53:13 +01:00
howar6hill
1c83c5ed08 LibJS: Implement While statements 2020-03-09 10:13:27 +01:00
Stephan Unverwerth
1207187e97 LibJS: GC: Remove clear_all_mark_bits()
Clearing all marked flags has been integrated into the sweep function,
saving an additional full iteration over the heap.
2020-03-09 07:32:09 +01:00
Andreas Kling
63e4b744ed LibJS: Add a basic mark&sweep garbage collector :^)
Objects can now be allocated via the interpreter's heap. Objects that
are allocated in this way will need to be provably reachable from at
least one of the known object graph roots.

The roots are currently determined by Heap::collect_roots().

Anything that wants be collectable garbage should inherit from Cell,
the fundamental atom of the GC heap.

This is pretty neat! :^)
2020-03-08 19:23:58 +01:00
howar6hill
e72fb8f594 LibC: Fix a bug involving miscalculating week counts of last year 2020-03-08 13:56:01 +01:00
howar6hill
df40847c52 LibC: Reimplement asctime() in terms of strftime() 2020-03-08 13:56:01 +01:00
Andreas Kling
37fc6c117c Userspace: Add missing #includes now that AK/StdLibExtras.h is smaller 2020-03-08 13:06:51 +01:00
Andreas Kling
b1058b33fb AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it
possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-08 13:06:51 +01:00
howar6hill
10e0d4a196
LibCore: Add format option for DateTime::to_string() (#1358) 2020-03-08 11:35:26 +01:00