lausek / lovm2 Goto Github PK
View Code? Open in Web Editor NEWlausek's own virtual machine
Home Page: http://lausek.eu/lovm2
License: GNU General Public License v3.0
lausek's own virtual machine
Home Page: http://lausek.eu/lovm2
License: GNU General Public License v3.0
Problems:
co_value
and ru_value
) with basically the same operations defined on themDict
and List
in place/by reference. This makes the implementation of python like slices more difficult.Steps for redesign:
CoValue -> Value
RuValue
contains either a Value
or a Ref(Rc<RefCell<Value>>)
Box
for turning the top of stack into a Ref
Unbox
for turning the top of stack into a Value
(basically a clone)Pros:
Add
are defined for compile time values as wellCons:
RuValue
Loading SharedObjectModule
and lovm2 Module
require special initialization procedures yet the current process enforces too generic loading by only having acces to a GenericModule
object in load_and_import_filter.
We never really have access to the underlying types SharedObjectModule
or Module
because this behavior only returns a GenericModule
Line 132 in 2cbc256
And
, Or
)break
, continue
)1 + 2
are not optimized:10: Pushc(0)
11: Pushc(1)
12: Add
Branch
conditions into Jt
:10: ...
11: Not
12: Jf
13: ...
Branch
(doesn't happen anymore after introduction of LIR
?):25: ...
26: Jmp(27)
27: ....
func:
11: Pushc(0)
12: Ret
13: Pushc(1)
14: ...
HIR
is a confusing name. change it to HirUnit
(?)module_builder.entry()
instead of module_builder.add(ENTRY_POINT)
Label
LirElement
LoweringRuntime
to HirLoweringRuntime
that transforms HIR
-> LIR
emit
try to optimize the last instructions (depending on instruction)LirLoweringRuntime
that transforms LIR
-> Bytecode
Implement new instruction IGet(u16)
for retrieving items by index .get_by_index(usize)
.
list[0]
and list[1]
Dict
: | stack
CPush | [dict]
IterCreate | [iter]
...
IterNext | [list]
Duplicate | [list, list]
IGet(0) | [list, key]
LMove | [list]
IGet(1) | [value]
LMove | []
lovm2/src/lovm2_core/src/gen/hir/branch.rs
Lines 54 to 57 in 0a0b73f
Value { boxed, .. }
is weird as other expressions (e.g. function calls) could be boxed as well.
Box
Unbox
add_with_args
to module builder -> avoid with_args
on hir.code()
on hirAfter the Context
has been reconsidered #11 maybe multiple threads can be supported in future versions?
The Context
structure contains a lot of attributes that are not directly related to the programs state but rather the virtual machines configuration.
Line 63 in 2b865ed
The load_hook
and import_hook
callbacks are examples for such attributes. But also the interrupt table shouldn't really be necessary here.
Expr
an optional type// old
hir.step(Assign::var(n, 2));
// new
hir.assign(n, 2);
HasBlock
Current Assign::global()
and Assign::local()
API is cumbersome.
Assign::var(variable, expr)
ScopeGlobal
and ScopeLocal
local
, global
to Block
globals
to LirLoweringRuntime
(type: Vec<Variable>
)ScopeLocal
and ScopeGlobal
Assign::local
and Assign::global
AssignType
(?)Frame
and cache modules in the background?Add a function fn(name: &str) -> Option<Module>
to lovm2 that is dispatched whenever the interpreter needs to lookup modules for the Load
instruction.
None
value, continue with regular load path searchThis functionality is needed because
pylovm2
can generate modules from python code, but importing them into the vm is not suitable as it would require two mutable references to the vm itself. The new method narrows the mutation down to one reference only.
The current Module
looks like this:
main
globals
locals
consts
code
add
globals
locals
consts
code
idents
: globals
+ locals
consts
entries
: HashMap<Variable, usize>
mapping the function name to the offset inside code
code
which is the concatenated list of bytecode instructions from main
and add
main:
...
ret
add:
...
ret
Module
is expected to decrease by a lot
Module
CodeObject
according to new layout
ModuleProtocol
trait -> remove slot
methodModuleProtocol
CodeObjectFunction
wip name
CodeObject
and an offset
CallProtocol
XOr
Shl
Shr
define_code
from exported macros to testsCall
, LCall
instructions from (argn, ident_idx)
to (ident_idx, argn)
Cast
to Conv
lovm2_error
, lovm2_internals
,pylovm2
as extern crates in documentation too?lovm2_extend
usage documentationCode like:
CPush | LPush | GPush ...
Drop
Should be eliminated.
Easier name. Shouldn't be a problem as there is no lovm2
project on pypi.
The optimizer currently merges
Not, Jt => Jf
and vice versa but does not cover
Eq, Not => Ne
Importing common names such as Expr
creates confusions when used as a library. Solution: Expr -> LV2Expr
, Call -> LV2Call
etc.
takes top of stack as number -> drops that amount from stack. useful for vararg functions
optimization issue: #8
branch
.add_condition(Expr::not(Value::Bool(false)))
.push(Return::value(Value::Int(1)));
branch
.default_condition()
.push(Return::value(Value::Int(2)));
generates the following module. everything after offset 1 is unreachable. 2 constants can be avoided as well.
- consts: [Int(1), Int(2), Nil]
- idents: [main]
- code:
main:
0. Pushc(0) 1
1. Ret
2. Jmp(5)
3. Pushc(1) 2
4. Ret
5. Pushc(2) Nil
6. Ret
LirElement
sLirElement
is already accepted by a valid path.Entry(_)
can be reached by external calls, start adding following offsets to the valid path.Jmp
is detected, continue adding offsets at the jumps target locationJt
/Jf
is detected
Ret
is detected, stop adding offsetsOptimization
trait: postprocess(&mut self, _: &mut Vec<LirElement>)
Add a new HIR
structure for conditional values. Currently Branch
is only available but it is a statement requiring assignments.
add_condition(cond: Expr, expr: Expr)
default_condition(expr: Expr)
- required. Every condition in ExprBranch
must always return at least some valueConditional
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.