mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-10 13:29:32 -06:00
bugfix in the pattern matching compiler and a number of other fixes that I somehow did not push before
This commit is contained in:
@@ -119,7 +119,8 @@ typedef enum {
|
||||
PGF_INSTR_PUSH = 9,
|
||||
PGF_INSTR_EVAL = 10,
|
||||
PGF_INSTR_RET = 13,
|
||||
PGF_INSTR_FAIL = 15
|
||||
PGF_INSTR_DROP = 15,
|
||||
PGF_INSTR_FAIL = 16
|
||||
} PgfInstruction;
|
||||
|
||||
struct PgfPGF {
|
||||
|
||||
@@ -1093,6 +1093,28 @@ pgf_jit_function(PgfReader* rdr, PgfAbstr* abstr,
|
||||
jit_bare_ret(a*sizeof(PgfClosure*));
|
||||
break;
|
||||
}
|
||||
case PGF_INSTR_DROP: {
|
||||
size_t n = pgf_read_int(rdr);
|
||||
size_t target = pgf_read_int(rdr);
|
||||
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
gu_printf(out, err, "DROP %d %03d\n", n, target);
|
||||
#endif
|
||||
|
||||
if (n > 0)
|
||||
jit_addi_p(JIT_SP, JIT_SP, n*sizeof(PgfClosure*));
|
||||
|
||||
jit_insn *jump =
|
||||
jit_jmpi(jit_forward());
|
||||
|
||||
PgfSegmentPatch label_patch;
|
||||
label_patch.segment = target;
|
||||
label_patch.ref = jump;
|
||||
label_patch.is_abs = false;
|
||||
gu_buf_push(rdr->jit_state->segment_patches, PgfSegmentPatch, label_patch);
|
||||
|
||||
break;
|
||||
}
|
||||
case PGF_INSTR_FAIL:
|
||||
#ifdef PGF_JIT_DEBUG
|
||||
gu_printf(out, err, "FAIL\n");
|
||||
|
||||
@@ -136,36 +136,42 @@ instance Binary Equation where
|
||||
get = liftM2 Equ get get
|
||||
|
||||
instance Binary Instr where
|
||||
put (ENTER ) = putWord8 0
|
||||
put (CASE id l ) = putWord8 8 >> put (id,l)
|
||||
put (CASE_LIT (LInt n) l) = putWord8 16 >> put (n,l)
|
||||
put (CASE_LIT (LStr s) l) = putWord8 17 >> put (s,l)
|
||||
put (CASE_LIT (LFlt d) l) = putWord8 18 >> put (d,l)
|
||||
put (ALLOC n) = putWord8 24 >> put n
|
||||
put (PUT_CONSTR id) = putWord8 32 >> put id
|
||||
put (PUT_FUN id) = putWord8 40 >> put id
|
||||
put (PUT_CLOSURE l) = putWord8 48 >> put l
|
||||
put (PUT_LIT (LInt n)) = putWord8 56 >> put n
|
||||
put (PUT_LIT (LStr s)) = putWord8 57 >> put s
|
||||
put (PUT_LIT (LFlt d)) = putWord8 58 >> put d
|
||||
put (SET (HEAP n)) = putWord8 64 >> put n
|
||||
put (SET (ARG_VAR n)) = putWord8 65 >> put n
|
||||
put (SET (FREE_VAR n)) = putWord8 66 >> put n
|
||||
put (SET_PAD ) = putWord8 72
|
||||
put (PUSH (HEAP n)) = putWord8 80 >> put n
|
||||
put (PUSH (ARG_VAR n)) = putWord8 81 >> put n
|
||||
put (PUSH (FREE_VAR n)) = putWord8 82 >> put n
|
||||
put (EVAL (HEAP n) RecCall ) = putWord8 88 >> put n
|
||||
put (EVAL (ARG_VAR n) RecCall ) = putWord8 89 >> put n
|
||||
put (EVAL (FREE_VAR n) RecCall ) = putWord8 90 >> put n
|
||||
put (EVAL (HEAP n) (TailCall a b)) = putWord8 92 >> put n >> put a >> put b
|
||||
put (EVAL (ARG_VAR n) (TailCall a b)) = putWord8 93 >> put n >> put a >> put b
|
||||
put (EVAL (FREE_VAR n) (TailCall a b)) = putWord8 94 >> put n >> put a >> put b
|
||||
put (CALL id RecCall ) = putWord8 96 >> put id
|
||||
put (CALL id (TailCall a b)) = putWord8 100 >> put id >> put a >> put b
|
||||
put (FAIL ) = putWord8 104
|
||||
put (UPDATE ) = putWord8 112
|
||||
put (RET n) = putWord8 120 >> put n
|
||||
put (CHECK_ARGS n) = putWord8 0 >> put n
|
||||
put (CASE id n l ) = putWord8 4 >> put (id,n,l)
|
||||
put (CASE_LIT (LInt n) l) = putWord8 8 >> put (n,l)
|
||||
put (CASE_LIT (LStr s) l) = putWord8 9 >> put (s,l)
|
||||
put (CASE_LIT (LFlt d) l) = putWord8 10 >> put (d,l)
|
||||
put (ALLOC n) = putWord8 12 >> put n
|
||||
put (PUT_CONSTR id) = putWord8 16 >> put id
|
||||
put (PUT_CLOSURE l) = putWord8 20 >> put l
|
||||
put (PUT_LIT (LInt n)) = putWord8 24 >> put n
|
||||
put (PUT_LIT (LStr s)) = putWord8 25 >> put s
|
||||
put (PUT_LIT (LFlt d)) = putWord8 26 >> put d
|
||||
put (SET (HEAP n)) = putWord8 28 >> put n
|
||||
put (SET (ARG_VAR n)) = putWord8 29 >> put n
|
||||
put (SET (FREE_VAR n)) = putWord8 30 >> put n
|
||||
put (SET (GLOBAL id)) = putWord8 31 >> put id
|
||||
put (SET_PAD ) = putWord8 32
|
||||
put (PUSH (HEAP n)) = putWord8 36 >> put n
|
||||
put (PUSH (ARG_VAR n)) = putWord8 37 >> put n
|
||||
put (PUSH (FREE_VAR n)) = putWord8 38 >> put n
|
||||
put (PUSH (GLOBAL id)) = putWord8 39 >> put id
|
||||
put (EVAL (HEAP n) (RecCall )) = putWord8 40 >> put n
|
||||
put (EVAL (ARG_VAR n) (RecCall )) = putWord8 41 >> put n
|
||||
put (EVAL (FREE_VAR n) (RecCall )) = putWord8 42 >> put n
|
||||
put (EVAL (GLOBAL id) (RecCall )) = putWord8 43 >> put id
|
||||
put (EVAL (HEAP n) (TailCall a b c)) = putWord8 44 >> put n >> put (a,b,c)
|
||||
put (EVAL (ARG_VAR n) (TailCall a b c)) = putWord8 45 >> put n >> put (a,b,c)
|
||||
put (EVAL (FREE_VAR n) (TailCall a b c)) = putWord8 46 >> put n >> put (a,b,c)
|
||||
put (EVAL (GLOBAL id) (TailCall a b c)) = putWord8 47 >> put id >> put (a,b,c)
|
||||
put (EVAL (HEAP n) (UpdateCall b c)) = putWord8 48 >> put n >> put (b,c)
|
||||
put (EVAL (ARG_VAR n) (UpdateCall b c)) = putWord8 49 >> put n >> put (b,c)
|
||||
put (EVAL (FREE_VAR n) (UpdateCall b c)) = putWord8 50 >> put n >> put (b,c)
|
||||
put (EVAL (GLOBAL id) (UpdateCall b c)) = putWord8 51 >> put id >> put (b,c)
|
||||
put (RET h (TailCall a b c)) = putWord8 53 >> put h >> put a >> put b
|
||||
put (RET h (UpdateCall b c)) = putWord8 54 >> put h >> put b
|
||||
put (DROP n l ) = putWord8 60 >> put (n,l)
|
||||
put (FAIL ) = putWord8 64
|
||||
|
||||
instance Binary Type where
|
||||
put (DTyp hypos cat exps) = put (hypos,cat,exps)
|
||||
|
||||
@@ -15,31 +15,31 @@ data Literal =
|
||||
type CodeLabel = Int
|
||||
|
||||
data Instr
|
||||
= ENTER
|
||||
| CASE CId {-# UNPACK #-} !CodeLabel
|
||||
= CHECK_ARGS {-# UNPACK #-} !Int
|
||||
| CASE CId {-# UNPACK #-} !Int {-# UNPACK #-} !CodeLabel
|
||||
| CASE_LIT Literal {-# UNPACK #-} !CodeLabel
|
||||
| ALLOC {-# UNPACK #-} !Int
|
||||
| PUT_CONSTR CId
|
||||
| PUT_FUN CId
|
||||
| PUT_CLOSURE {-# UNPACK #-} !CodeLabel
|
||||
| PUT_LIT Literal
|
||||
| SET IVal
|
||||
| SET_PAD
|
||||
| PUSH IVal
|
||||
| EVAL IVal TailInfo
|
||||
| CALL CId TailInfo
|
||||
| RET {-# UNPACK #-} !Int TailInfo
|
||||
| DROP {-# UNPACK #-} !Int {-# UNPACK #-} !CodeLabel
|
||||
| FAIL
|
||||
| UPDATE
|
||||
| RET {-# UNPACK #-} !Int
|
||||
|
||||
data IVal
|
||||
= HEAP {-# UNPACK #-} !Int
|
||||
| ARG_VAR {-# UNPACK #-} !Int
|
||||
| FREE_VAR {-# UNPACK #-} !Int
|
||||
| GLOBAL CId
|
||||
|
||||
data TailInfo
|
||||
= RecCall
|
||||
| TailCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int
|
||||
| TailCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int {-# UNPACK #-} !Int
|
||||
| UpdateCall {-# UNPACK #-} !Int {-# UNPACK #-} !Int
|
||||
|
||||
ppLit (LStr s) = text (show s)
|
||||
ppLit (LInt n) = int n
|
||||
@@ -49,28 +49,29 @@ ppCode :: Int -> [[Instr]] -> Doc
|
||||
ppCode l [] = empty
|
||||
ppCode l (is:iss) = ppLabel l <+> vcat (map ppInstr is) $$ ppCode (l+1) iss
|
||||
|
||||
ppInstr (ENTER ) = text "ENTER"
|
||||
ppInstr (CASE id l ) = text "CASE " <+> ppCId id <+> ppLabel l
|
||||
ppInstr (CHECK_ARGS n) = text "CHECK_ARGS " <+> int n
|
||||
ppInstr (CASE id n l ) = text "CASE " <+> ppCId id <+> int n <+> ppLabel l
|
||||
ppInstr (CASE_LIT lit l ) = text "CASE_LIT " <+> ppLit lit <+> ppLabel l
|
||||
ppInstr (ALLOC n) = text "ALLOC " <+> int n
|
||||
ppInstr (PUT_CONSTR id) = text "PUT_CONSTR " <+> ppCId id
|
||||
ppInstr (PUT_FUN id) = text "PUT_FUN " <+> ppCId id
|
||||
ppInstr (PUT_CLOSURE l) = text "PUT_CLOSURE" <+> ppLabel l
|
||||
ppInstr (PUT_LIT lit ) = text "PUT_LIT " <+> ppLit lit
|
||||
ppInstr (SET v) = text "SET " <+> ppIVal v
|
||||
ppInstr (SET_PAD ) = text "SET_PAD"
|
||||
ppInstr (PUSH v) = text "PUSH " <+> ppIVal v
|
||||
ppInstr (EVAL v ti) = text "EVAL " <+> ppIVal v <+> ppTailInfo ti
|
||||
ppInstr (CALL v ti) = text "CALL " <+> ppCId v <+> ppTailInfo ti
|
||||
ppInstr (RET h (TailCall a b c)) = text "RET " <+> ppIVal (HEAP h) <+> text "tail" <> parens (int a <> comma <> int b)
|
||||
ppInstr (RET h (UpdateCall b c)) = text "RET " <+> ppIVal (HEAP h) <+> text "update" <> parens (int b)
|
||||
ppInstr (DROP n l ) = text "DROP " <+> int n <+> ppLabel l
|
||||
ppInstr (FAIL ) = text "FAIL"
|
||||
ppInstr (UPDATE ) = text "UPDATE"
|
||||
ppInstr (RET n) = text "RET " <+> int n
|
||||
|
||||
ppIVal (HEAP n) = text "hp" <> parens (int n)
|
||||
ppIVal (ARG_VAR n) = text "stk" <> parens (int n)
|
||||
ppIVal (FREE_VAR n) = text "env" <> parens (int n)
|
||||
ppIVal (GLOBAL id) = ppCId id
|
||||
|
||||
ppTailInfo RecCall = empty
|
||||
ppTailInfo (TailCall a b) = text "tail" <> parens (int a <> comma <> int b)
|
||||
ppTailInfo RecCall = empty
|
||||
ppTailInfo (TailCall a b c) = text "tail" <> parens (int a <> comma <> int b <> comma <> int c)
|
||||
ppTailInfo (UpdateCall b c) = text "update" <> parens (int b <> comma <> int c)
|
||||
|
||||
ppLabel l = text (let s = show l in replicate (3-length s) '0' ++ s)
|
||||
|
||||
Reference in New Issue
Block a user