p2
0.0
|
transform the ast to simple two-address lua-like bytecode. More...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include "p2.h"
#include "internal.h"
#include "ast.h"
#include "opcodes.h"
#include "asm.h"
#include <dlfcn.h>
Go to the source code of this file.
Data Structures | |
struct | PNLoop |
jump table for loops, for the 2 args b and c Note: only statically allocated (max 1024) More... | |
Macros | |
#define | PN_ASM1(ins, _a) f->asmb = (PN)potion_asm_op(P, (PNAsm *)f->asmb, (u8)ins, (int)_a, 0) |
#define | PN_ASM2(ins, _a, _b) f->asmb = (PN)potion_asm_op(P, (PNAsm *)f->asmb, (u8)ins, (int)_a, (int)_b) |
#define | PN_REG(f, reg) |
#define | PN_ARG(n, reg) |
#define | PN_BLOCK(reg, blk, sig) |
#define | PN_UPVAL(name) |
#define | PN_ARG_TABLE(args, reg, inc) potion_arg_asmb(P, f, loop, args, ®, inc) |
#define | SRC_TUPLE_AT(src, i) PN_SRC(PN_TUPLE_AT(PN_S(src,0), i)) |
#define | PN_ASM_DEBUG(REG, T) REG = potion_source_debug(P, f, T, REG) |
#define | MAX_JUMPS 1024 |
#define | LOAD_ARG() PN_ARG_TABLE(PN_S(t,1), breg, 1) |
#define | SIG_EXPR_MSG(name, expr) |
#define | READ_U8(ptr) ({u8 rpu = *ptr; ptr += sizeof(u8); rpu;}) |
#define | READ_PN(pn, ptr) ({PN rpn = *(PN *)ptr; ptr += pn; rpn;}) |
#define | READ_CONST(pn, ptr) |
#define | READ_TUPLE(ptr) |
#define | READ_VALUES(pn, ptr) |
#define | READ_PROTOS(pn, ptr) |
#define | WRITE_U8(un, ptr) ({*ptr = (u8)un; ptr += sizeof(u8);}) |
#define | WRITE_PN(pn, ptr) ({*(PN *)ptr = pn; ptr += sizeof(PN);}) |
#define | WRITE_CONST(val, ptr) |
#define | WRITE_TUPLE(tup, ptr) |
#define | WRITE_VALUES(tup, ptr) |
#define | WRITE_PROTOS(tup, ptr) |
Functions | |
PN | potion_sig_string (Potion *P, PN cl, PN sig) |
u8 | potion_source_debug (Potion *P, struct PNProto *volatile f, struct PNSource *volatile t, u8 reg) |
insert DEBUG ops for every new line More... | |
void | potion_source_asmb (Potion *, struct PNProto *volatile, struct PNLoop *, PN_SIZE, struct PNSource *volatile, u8) |
void | potion_arg_asmb (Potion *P, struct PNProto *volatile f, struct PNLoop *loop, PN args, u8 *reg, int inc) |
PN | potion_sig_compile (Potion *P, vPN(Proto) f, PN src) |
Converts a pre-compiled potion expr to a signature tuple. More... | |
PN | potion_proto_load (Potion *P, PN up, u8 pn, u8 **ptr) |
PN | potion_run (Potion *P, PN code, int jit) |
PN | potion_eval (Potion *P, PN bytes) |
void | potion_compiler_init (Potion *P) |
Variables | |
struct { | |
const char * name | |
const u8 args | |
} | potion_ops [] |
transform the ast to simple two-address lua-like bytecode.
A full three-address VM with possible SSA form is not needed. This is for highly dynamic languages, and the typed parts can be optimized differently.
implement the PNSource (AST) and PNProto (closure) methods, special signature handling (parsed extra) and compile, bytecode load and dump methods. Some special control methods are handled here and not in the parser. We do not need lexed keywords, and are free to extend everything dynamically.
(c) 2008 why the lucky stiff, the freelance professor (c) 2014 perl11.org
Definition in file compile.c.
#define PN_ASM1 | ( | ins, | |
_a | |||
) | f->asmb = (PN)potion_asm_op(P, (PNAsm *)f->asmb, (u8)ins, (int)_a, 0) |
#define PN_ASM2 | ( | ins, | |
_a, | |||
_b | |||
) | f->asmb = (PN)potion_asm_op(P, (PNAsm *)f->asmb, (u8)ins, (int)_a, (int)_b) |
#define PN_ARG | ( | n, | |
reg | |||
) |
#define PN_BLOCK | ( | reg, | |
blk, | |||
sig | |||
) |
#define PN_UPVAL | ( | name | ) |
#define PN_ARG_TABLE | ( | args, | |
reg, | |||
inc | |||
) | potion_arg_asmb(P, f, loop, args, ®, inc) |
#define SRC_TUPLE_AT | ( | src, | |
i | |||
) | PN_SRC(PN_TUPLE_AT(PN_S(src,0), i)) |
#define PN_ASM_DEBUG | ( | REG, | |
T | |||
) | REG = potion_source_debug(P, f, T, REG) |
#define LOAD_ARG | ( | ) | PN_ARG_TABLE(PN_S(t,1), breg, 1) |
#define SIG_EXPR_MSG | ( | name, | |
expr | |||
) |
#define READ_CONST | ( | pn, | |
ptr | |||
) |
#define READ_TUPLE | ( | ptr | ) |
#define READ_VALUES | ( | pn, | |
ptr | |||
) |
#define READ_PROTOS | ( | pn, | |
ptr | |||
) |
#define WRITE_CONST | ( | val, | |
ptr | |||
) |
#define WRITE_TUPLE | ( | tup, | |
ptr | |||
) |
#define WRITE_VALUES | ( | tup, | |
ptr | |||
) |
#define WRITE_PROTOS | ( | tup, | |
ptr | |||
) |
Converts a pre-compiled potion expr to a signature tuple.
Extract locals, apply type defaults and do type and param checks. Sigs are also ambigious, the parser usually compiles it down to expression trees, not to a sig tuple. Converts assign,pipe,value.
Not used by P2, as args2 generates the correct sig tuple in the parser already.
Name=Type, '|' optional '.' end ':='default type: 'o' (= PN object) Encode to 3-tuple AST_CODE: name type|modifier default
(x=n,y:=1) =>
const { ... } potion_ops[] |