Commit graph

21850 commits

Author SHA1 Message Date
Idan Horowitz 70fc0a528c Kernel: Increase m_bytes_out only once during transmission
We were accidentally increasing m_bytes_out by the packet size and then
immediately calling send_packet(), which did the same thing as well.
2021-06-11 00:56:32 +02:00
Andreas Kling 9ee5029bc5 LibJS: Basic bytecode support for computed member expressions
Expressions like foo[1 + 2] now work, and you can assign to them
as well! :^)
2021-06-11 00:36:18 +02:00
Ali Mohammad Pur b47246ec70 LibJS: Switch AST.{h,cpp} to east const 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur 3234697eca LibJS: Implement generator functions (only in bytecode mode) 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur c53a86a3fe LibJS: Resolve the `this' value in call expression bytecode 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur 4cfdfb6a88 LibJS: Automatically split linear bytecode into multiple blocks
...instead of crashing :^)
2021-06-11 00:30:09 +02:00
Ali Mohammad Pur 7b2c838162 AK: Make NonnullRefPtrVector constructible from Vector<NonnullRefPtr> 2021-06-11 00:30:09 +02:00
Idan Horowitz 8527f00065 LibJS: Allow and check for detached ArrayBuffers
This is required by the specification and will be used for the
$262.detachArrayBuffer method in test262.
2021-06-10 22:44:26 +01:00
Idan Horowitz 7d6db3f09b LibJS: Throw TypeError on non-object this value in ArrayBuffer methods
`1. If Type(O) is not Object, throw a TypeError exception.`
2021-06-10 22:44:26 +01:00
Idan Horowitz bc95201aaf LibJS: Dont mask non-RangeError exceptions in ArrayBuffer construction
Non-RangeError exceptions can be thrown by user implementations of
valueOf (which are called by to_index), and the specification disallows
changing the type of the thrown error.
2021-06-10 22:44:26 +01:00
Idan Horowitz 8dc86c6aad LibJS: Bring ArrayBuffer.prototype.slice closer to spec
The exception order was incorrect in the old implementation, and it
did not use the Symbol.species constructor as required by the spec.
2021-06-10 22:44:26 +01:00
Idan Horowitz b041108a1e LibJS: Explicitly return and accept a Function* in species_constructor
The second argument (the default constructor) and the return value have
to be constructors (as a result functions), so we can require that
explicitly by using appropriate types.
2021-06-10 22:44:26 +01:00
Daniel Bertalan 4531f689ff Userland: Fix incorrect iflag/oflag printing in stty
The `c_iflag` and `c_oflag` fields were swapped in the source code which
caused the bit values to be interpreted as the wrong flag. It was a
stupid mistake on my part.
2021-06-10 23:44:14 +02:00
Andreas Kling 93a07ba962 LibJS: Remove GlobalObject& argument from VM::construct()
We can just get the global object from the constructor function.
2021-06-10 23:17:29 +02:00
Andreas Kling f5feb1d2cd LibJS: Very basic support for "new" construction in bytecode VM
This patch adds a CallType to the Bytecode::Op::Call instruction,
which can be either Call or Construct. We then generate Construct
calls for the NewExpression AST node.

When executed, these get fed into VM::construct().
2021-06-10 23:01:49 +02:00
Andreas Kling c3c68399b5 LibJS: Generate bytecode for entering nested lexical environments
This adds a new PushLexicalEnvironment instruction that creates a new
LexicalEnvironment and pushes it on the VM's scope stack.

There is no corresponding PopLexicalEnvironment instruction yet,
so this will behave incorrectly with let/const scopes for example.
2021-06-10 22:20:23 +02:00
Andreas Kling d560ee118d LibJS: Allocate 4 KiB for Bytecode::BasicBlock
There's no reason not to, since we're using mmap() for these anyway
and that gives us memory in 4 KiB increments. :^)
2021-06-10 21:59:49 +02:00
Andreas Kling 22c803d8e5 LibJS: Always keep the global object in bytecode VM register $1 2021-06-10 21:59:49 +02:00
Andreas Kling b3e6a6c1cd LibJS: Perform function instantiation in bytecode
This replaces Bytecode::Op::EnterScope with a new NewFunction op that
instantiates a ScriptFunction from a given FunctionNode (AST).

This is then used to instantiate the local functions directly from
bytecode when entering a ScopeNode. :^)
2021-06-10 21:59:49 +02:00
Andreas Kling 941be2dcc2 LibJS: Add empty bytecode generation for VariableDeclaration
These will be partly handled by the relevant ScopeNode due to
hoisting, same basic idea as function declarations.

VariableDeclaration needs to do some work, but let's stub it out
first and start empty.
2021-06-10 21:59:49 +02:00
Gunnar Beutner 67cc31a74f LibJS: Implement bytecode generation for try..catch..finally
EnterUnwindContext pushes an unwind context (exception handler and/or
finalizer) onto a stack.

LeaveUnwindContext pops the unwind context from that stack.

Upon return to the interpreter loop we check whether the VM has an
exception pending. If no unwind context is available we return from the
loop. If an exception handler is available we clear the VM's exception,
put the exception value into the accumulator register, clear the unwind
context's handler and jump to the handler. If no handler is available
but a finalizer is available we save the exception value + metadata (for
 later use by ContinuePendingUnwind), clear the VM's exception, pop the
unwind context and jump to the finalizer.

ContinuePendingUnwind checks whether a saved exception is available. If
no saved exception is available it jumps to the resume label. Otherwise
it stores the exception into the VM.

The Jump after LeaveUnwindContext could be integrated into the
LeaveUnwindContext instruction. I've kept them separate for now to make
the bytecode more readable.

> try { 1; throw "x" } catch (e) { 2 } finally { 3 }; 4
1:
[   0] EnterScope
[  10] EnterUnwindContext handler:@4 finalizer:@3
[  38] EnterScope
[  48] LoadImmediate 1
[  60] NewString 1 ("x")
[  70] Throw
<for non-terminated blocks: insert LeaveUnwindContext + Jump @3 here>
2:
[   0] LoadImmediate 4
3:
[   0] EnterScope
[  10] LoadImmediate 3
[  28] ContinuePendingUnwind resume:@2
4:
[   0] SetVariable 0 (e)
[  10] EnterScope
[  20] LoadImmediate 2
[  38] LeaveUnwindContext
[  3c] Jump @3

String Table:
0: e
1: x
2021-06-10 21:59:46 +02:00
Luke d2f1476428 Kernel: Add support for the RTL8168E-VL variant to the RTL8168 driver
Specifically chip version 17.
2021-06-10 21:54:51 +02:00
Idan Horowitz a898e01d4d Kernel: Add driver for RTL8168 & RTL8111 NICs
These are pretty common on older LGA1366 & LGA1150 motherboards.

NOTE: Since the registers datasheets for all versions of the chip
besides versions 1 - 3  are still under NDAs i had to collect
several "magical vendor constants" from the *BSD driver and the
linux driver that i was not able to name verbosely, and as such
these are labeled with the comment "vendor magic values".
2021-06-10 21:54:51 +02:00
Gunnar Beutner de6d032273 LibJS: Show the VM's last value after executing bytecode programs 2021-06-10 21:47:25 +02:00
Gunnar Beutner 3a8f913eee LibJS: Don't generate bytecode after we've encountered a parser error 2021-06-10 21:47:25 +02:00
Gunnar Beutner 319a60043b LibJS: Let the bytecode interpreter set the VM's last value 2021-06-10 21:47:25 +02:00
Egor Ananyin 023df8e596 Ports: Add LLVM port 2021-06-10 20:21:08 +01:00
Egor Ananyin 794cf8eef4 LibC: Use EX_IOERR instead of EX_IOER 2021-06-10 20:21:08 +01:00
Egor Ananyin 142f9db5bd Ports: Add pre_fetch to .port_include.sh 2021-06-10 20:21:08 +01:00
xyanrch a0412e0d5e LibJS: Implement bytecode generation for BreakStatement 2021-06-10 21:48:20 +04:30
Apoorv Mishra 73cf16f643
Documentation: Specify minimum required QEMU version 2021-06-10 17:28:26 +01:00
Daniel Bertalan 3752775a1e LibVT: Implement DECIC/DECDC
This commit adds support for these escape sequences that are used for
scrolling multiple lines at once. In the current, unoptimized
implementation, these just call the `scroll_left` and `scroll_right`
APIs multiple times.

It's a VT420 feature.
2021-06-10 17:18:02 +02:00
Daniel Bertalan a3c4397432 Kernel: Re-render console after echoing characters
If we do not flush the dirty lines, characters typed in canonical mode
only appear after the virtual console has been switched away from, or
the application has been killed. Instead, we now immediately perform the
flush.
2021-06-10 17:18:02 +02:00
Daniel Bertalan ce9460de59 Kernel+LibVT: Fix selection with scrollback wrap-around
If lines are removed from the tail of the scrollback buffer, the
previous line indices will refer to different lines; therefore we need
to offset them.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 13991eade7 LibVT: Implement DECFI and DECBI
These escape sequences are the horizontal scrolling equivalents of `IND`
and `RI`. Normally, they move the cursor forward or backward. But if
they hit the margins (which we just treat as the first and last
columns), they scroll the line.

Another VT420 feature done.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 89843cd692 Kernel+LibVT: Implement left-right scrolling
This commit implements the left/right scrolling used in the `ICH`/`DCH`
escape sequences for `VirtualConsole`. This brings us one step closer to
VT420/xterm compatibility.

We can now finally remove the last escape sequence related `ifdef`s.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 7419569a2b Kernel+LibVT: Add function for deleting a range of characters
Previously, this was done by telling the client to put a space at each
character in the range. This was inefficient, because a large number of
function calls took place and incorrect, as the ANSI standard dictates
that character attributes should be cleared as well.

The newly added `clear_in_line` function solves this issue. It performs
just one bounds check when it's called and can be implemented as a
pretty tight loop.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 8f8fd9c5a8 LibVT+Kernel: Support clearing the scrollback buffer
As per the `xterm ctlseqs` documentation, `\e3J` should clear the
scrollback buffer, and leave the visible lines unchanged.

This commit fixes a FIXME.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 221ba1aac8 LibVT: Improve scrolling performance
Previously, we would remove lines from the buffer, create new lines and
insert them into the buffer when we scrolled. Since scrolling does not
always happen at the last line, this meant `Line` objects were
pointlessly moved forwards, and then immediately backwards.

We now swap them in-place and clear those lines that are "inserted". As
a result, performance is better and scrolling is smoother in `vim` and
`nano`.
2021-06-10 17:18:02 +02:00
Daniel Bertalan fe58d15b5b LibVT: Fix ECH not clearing lines
The `num` parameter should be treated as an offset from the cursor
position, not from the beginning of the line. The previous behavior
caused fragments of previous lines to be visible when moving the entire
buffer in vim (e.g. with `gg` and `G`).

The debug messages I used while fixing it are also included in this
commit. These will help diagnose further issues if they arise.
2021-06-10 17:18:02 +02:00
Daniel Bertalan ae6bdc4e29 LibVT+Kernel: Clean up scroll API
This commit cleans up some of the `#ifdef`-ed code smell in
`Terminal`, by extending the scroll APIs to take a range of lines as a
parameter. This makes it possible to use the same code for `IL`/`DL` as
for scrolling.

Note that the current scrolling implementation is very naive, and does
many insertions/deletions in the middle of arrays, whereas swaps should
be enough. This optimization will come in a later commit.

The `linefeed` override was removed from `VirtualConsole`. Previously,
it exhibited incorrect behavior by moving to column 0. Now that we use
the method defined in `Terminal`, code which relied on this behavior
stopped working. We go instead go through the TTY layer which handles
the various output flags. Passing the input character-by-character
seems a bit excessive, so a fix for it will come in another PR.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 5f92790489 LibVT: Fix out-of-bounds reads in ICH/DCH escape sequences
Previously, entering too big counts for these commands could cause a
wrap-around with the cell indices.

Also, we are now correctly copying the cell attributes as well as the
code point.
2021-06-10 17:18:02 +02:00
Luke 00a83a2957 LibJS: Make removed elements in Array.prototype.splice spec compliant
It wasn't using has_property, was directly appending to indexed
properties and wasn't setting the length.
2021-06-10 10:04:06 +01:00
Luke bc540de0af LibJS: Pass in actual_delete_count to removed array creation in splice
More specifically, Array.prototype.splice. Additionally adds a missing
exception check to the array creation and a link to the spec.

Fixes create-non-array-invalid-len.js in the splice tests in test262.
This test timed out instead of throwing an "Invalid array length"
exception.
2021-06-10 10:04:06 +01:00
Idan Horowitz f63ef4f196 LibJS: Stop asserting in {Set,Test}IntegrityLevel on missing descriptor
As per the specification (7.3.15 SetIntegrityLevel):
i. Let currentDesc be ? O.[[GetOwnProperty]](k).
ii. If currentDesc is not undefined, then...
2021-06-10 09:20:05 +01:00
Linus Groh b639bf64f2 LibJS: Use create_list_from_array_like() in Function.prototype.apply() 2021-06-09 23:46:37 +01:00
Linus Groh f932da095e LibJS: Use create_list_from_array_like() in Reflect.{apply,construct}() 2021-06-09 23:46:37 +01:00
Linus Groh ad7aa05cc6 LibJS: Implement the CreateListFromArrayLike() abstract operation
We already have two separate implementations of this, so let's do it
properly. The optional value type check is done by a callback function
that returns Result<void, ErrorType> - value type accepted or message
for TypeError, that is.
2021-06-09 23:46:37 +01:00
Luke 5da94b30eb LibJS: Add logical assignment bytecode generation 2021-06-10 00:28:34 +02:00
Andreas Kling 4bc98fd39f LibJS: Only "var" declarations go in the global object at program level
"let" and "const" go in the lexical environment.

This fixes one part of #4001 (Lexically declared variables are mixed up
with global object properties)
2021-06-09 23:25:16 +02:00