Hex Artifact Content
Not logged in

Artifact 7d3866629ed44664a781663b12301c5965976deb:

File src/th.h part of check-in [13e16c824a] - Create the interface between TH1 and the rest of fossil. Subscript is still being used, though. This is a preparatory step toward cutting over to TH1. by drh on 2008-02-13 16:21:58. Also file src/th.h part of check-in [588bb7cd73] - Merged to ed26056bb5. by aku on 2008-02-24 18:50:35.

0000: 0a 2f 2a 20 54 68 69 73 20 68 65 61 64 65 72 20  ./* This header 
0010: 66 69 6c 65 20 64 65 66 69 6e 65 73 20 74 68 65  file defines the
0020: 20 65 78 74 65 72 6e 61 6c 20 69 6e 74 65 72 66   external interf
0030: 61 63 65 20 74 6f 20 74 68 65 20 63 75 73 74 6f  ace to the custo
0040: 6d 20 53 63 72 69 70 74 69 6e 67 0a 2a 2a 20 4c  m Scripting.** L
0050: 61 6e 67 75 61 67 65 20 28 54 48 29 20 69 6e 74  anguage (TH) int
0060: 65 72 70 72 65 74 65 72 20 75 73 65 64 20 74 6f  erpreter used to
0070: 20 63 72 65 61 74 65 20 74 65 73 74 20 63 61 73   create test cas
0080: 65 73 20 66 6f 72 20 53 51 4c 69 74 65 52 54 2e  es for SQLiteRT.
0090: 20 54 68 65 0a 2a 2a 20 69 6e 74 65 72 70 72 65   The.** interpre
00a0: 74 65 64 20 6c 61 6e 67 75 61 67 65 20 61 6e 64  ted language and
00b0: 20 41 50 49 20 61 72 65 20 62 6f 74 68 20 62 61   API are both ba
00c0: 73 65 64 20 6f 6e 20 54 63 6c 2e 0a 2a 2f 0a 0a  sed on Tcl..*/..
00d0: 74 79 70 65 64 65 66 20 75 6e 73 69 67 6e 65 64  typedef unsigned
00e0: 20 63 68 61 72 20 75 63 68 61 72 3b 0a 0a 2f 2a   char uchar;../*
00f0: 0a 2a 2a 20 42 65 66 6f 72 65 20 63 72 65 61 74  .** Before creat
0100: 69 6e 67 20 61 6e 20 69 6e 74 65 72 70 72 65 74  ing an interpret
0110: 65 72 2c 20 74 68 65 20 61 70 70 6c 69 63 61 74  er, the applicat
0120: 69 6f 6e 20 6d 75 73 74 20 61 6c 6c 6f 63 61 74  ion must allocat
0130: 65 20 61 6e 64 0a 2a 2a 20 70 6f 70 75 6c 61 74  e and.** populat
0140: 65 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66  e an instance of
0150: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73   the following s
0160: 74 72 75 63 74 75 72 65 2e 20 49 74 20 6d 75 73  tructure. It mus
0170: 74 20 72 65 6d 61 69 6e 20 76 61 6c 69 64 0a 2a  t remain valid.*
0180: 2a 20 66 6f 72 20 74 68 65 20 6c 69 66 65 74 69  * for the lifeti
0190: 6d 65 20 6f 66 20 74 68 65 20 69 6e 74 65 72 70  me of the interp
01a0: 72 65 74 65 72 2e 0a 2a 2f 0a 73 74 72 75 63 74  reter..*/.struct
01b0: 20 54 68 5f 56 74 61 62 20 7b 0a 20 20 76 6f 69   Th_Vtab {.  voi
01c0: 64 20 2a 28 2a 78 4d 61 6c 6c 6f 63 29 28 75 6e  d *(*xMalloc)(un
01d0: 73 69 67 6e 65 64 20 69 6e 74 29 3b 0a 20 20 76  signed int);.  v
01e0: 6f 69 64 20 28 2a 78 46 72 65 65 29 28 76 6f 69  oid (*xFree)(voi
01f0: 64 20 2a 29 3b 0a 7d 3b 0a 74 79 70 65 64 65 66  d *);.};.typedef
0200: 20 73 74 72 75 63 74 20 54 68 5f 56 74 61 62 20   struct Th_Vtab 
0210: 54 68 5f 56 74 61 62 3b 0a 0a 2f 2a 0a 2a 2a 20  Th_Vtab;../*.** 
0220: 4f 70 61 71 75 65 20 68 61 6e 64 6c 65 20 66 6f  Opaque handle fo
0230: 72 20 69 6e 74 65 72 70 65 74 65 72 2e 0a 2a 2f  r interpeter..*/
0240: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20  .typedef struct 
0250: 54 68 5f 49 6e 74 65 72 70 20 54 68 5f 49 6e 74  Th_Interp Th_Int
0260: 65 72 70 3b 0a 0a 2f 2a 20 0a 2a 2a 20 43 72 65  erp;../* .** Cre
0270: 61 74 65 20 61 6e 64 20 64 65 6c 65 74 65 20 69  ate and delete i
0280: 6e 74 65 72 70 72 65 74 65 72 73 2e 20 0a 2a 2f  nterpreters. .*/
0290: 0a 54 68 5f 49 6e 74 65 72 70 20 2a 20 54 68 5f  .Th_Interp * Th_
02a0: 43 72 65 61 74 65 49 6e 74 65 72 70 28 54 68 5f  CreateInterp(Th_
02b0: 56 74 61 62 20 2a 70 56 74 61 62 29 3b 0a 76 6f  Vtab *pVtab);.vo
02c0: 69 64 20 54 68 5f 44 65 6c 65 74 65 49 6e 74 65  id Th_DeleteInte
02d0: 72 70 28 54 68 5f 49 6e 74 65 72 70 20 2a 29 3b  rp(Th_Interp *);
02e0: 0a 0a 2f 2a 20 0a 2a 2a 20 45 76 61 6c 75 61 74  ../* .** Evaluat
02f0: 65 20 61 6e 20 54 48 20 70 72 6f 67 72 61 6d 20  e an TH program 
0300: 69 6e 20 74 68 65 20 73 74 61 63 6b 20 66 72 61  in the stack fra
0310: 6d 65 20 69 64 65 6e 74 69 66 69 65 64 20 62 79  me identified by
0320: 20 70 61 72 61 6d 65 74 65 72 0a 2a 2a 20 69 46   parameter.** iF
0330: 72 61 6d 65 2c 20 61 63 63 6f 72 64 69 6e 67 20  rame, according 
0340: 74 6f 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  to the following
0350: 20 72 75 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20   rules:.**.**   
0360: 2a 20 49 66 20 69 46 72 61 6d 65 20 69 73 20 30  * If iFrame is 0
0370: 2c 20 74 68 69 73 20 6d 65 61 6e 73 20 74 68 65  , this means the
0380: 20 63 75 72 72 65 6e 74 20 66 72 61 6d 65 2e 0a   current frame..
0390: 2a 2a 0a 2a 2a 20 20 20 2a 20 49 66 20 69 46 72  **.**   * If iFr
03a0: 61 6d 65 20 69 73 20 6e 65 67 61 74 69 76 65 2c  ame is negative,
03b0: 20 74 68 65 6e 20 74 68 65 20 6e 74 68 20 66 72   then the nth fr
03c0: 61 6d 65 20 75 70 20 74 68 65 20 73 74 61 63 6b  ame up the stack
03d0: 2c 20 77 68 65 72 65 20 6e 20 69 73 20 0a 2a 2a  , where n is .**
03e0: 20 20 20 20 20 74 68 65 20 61 62 73 6f 6c 75 74       the absolut
03f0: 65 20 76 61 6c 75 65 20 6f 66 20 69 46 72 61 6d  e value of iFram
0400: 65 2e 20 41 20 76 61 6c 75 65 20 6f 66 20 2d 31  e. A value of -1
0410: 20 6d 65 61 6e 73 20 74 68 65 20 63 61 6c 6c 69   means the calli
0420: 6e 67 0a 2a 2a 20 20 20 20 20 70 72 6f 63 65 64  ng.**     proced
0430: 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 2a 20 49  ure..**.**   * I
0440: 66 20 69 46 72 61 6d 65 20 69 73 20 2b 76 65 2c  f iFrame is +ve,
0450: 20 74 68 65 6e 20 74 68 65 20 6e 74 68 20 66 72   then the nth fr
0460: 61 6d 65 20 66 72 6f 6d 20 74 68 65 20 62 6f 74  ame from the bot
0470: 74 6f 6d 20 6f 66 20 74 68 65 20 73 74 61 63 6b  tom of the stack
0480: 2e 0a 2a 2a 20 20 20 20 20 41 6e 20 69 46 72 61  ..**     An iFra
0490: 6d 65 20 76 61 6c 75 65 20 6f 66 20 31 20 6d 65  me value of 1 me
04a0: 61 6e 73 20 74 68 65 20 74 6f 70 6c 65 76 65 6c  ans the toplevel
04b0: 20 28 67 6c 6f 62 61 6c 29 20 66 72 61 6d 65 2e   (global) frame.
04c0: 0a 2a 2f 0a 69 6e 74 20 54 68 5f 45 76 61 6c 28  .*/.int Th_Eval(
04d0: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  Th_Interp *inter
04e0: 70 2c 20 69 6e 74 20 69 46 72 61 6d 65 2c 20 63  p, int iFrame, c
04f0: 6f 6e 73 74 20 75 63 68 61 72 20 2a 7a 50 72 6f  onst uchar *zPro
0500: 67 2c 20 69 6e 74 20 6e 50 72 6f 67 29 3b 0a 0a  g, int nProg);..
0510: 2f 2a 0a 2a 2a 20 45 76 61 6c 75 61 74 65 20 61  /*.** Evaluate a
0520: 20 54 48 20 65 78 70 72 65 73 73 69 6f 6e 2e 20   TH expression. 
0530: 54 68 65 20 72 65 73 75 6c 74 20 69 73 20 73 74  The result is st
0540: 6f 72 65 64 20 69 6e 20 74 68 65 20 0a 2a 2a 20  ored in the .** 
0550: 69 6e 74 65 72 70 72 65 74 65 72 20 72 65 73 75  interpreter resu
0560: 6c 74 2e 0a 2a 2f 0a 69 6e 74 20 54 68 5f 45 78  lt..*/.int Th_Ex
0570: 70 72 28 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e  pr(Th_Interp *in
0580: 74 65 72 70 2c 20 63 6f 6e 73 74 20 75 63 68 61  terp, const ucha
0590: 72 20 2a 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 0a  r *, int);../* .
05a0: 2a 2a 20 41 63 63 65 73 73 20 54 48 20 76 61 72  ** Access TH var
05b0: 69 61 62 6c 65 73 20 69 6e 20 74 68 65 20 63 75  iables in the cu
05c0: 72 72 65 6e 74 20 73 74 61 63 6b 20 66 72 61 6d  rrent stack fram
05d0: 65 2e 20 49 66 20 74 68 65 20 76 61 72 69 61 62  e. If the variab
05e0: 6c 65 20 6e 61 6d 65 0a 2a 2a 20 62 65 67 69 6e  le name.** begin
05f0: 73 20 77 69 74 68 20 22 3a 3a 22 2c 20 74 68 65  s with "::", the
0600: 20 6c 6f 6f 6b 75 70 20 69 73 20 69 6e 20 74 68   lookup is in th
0610: 65 20 74 6f 70 20 6c 65 76 65 6c 20 28 67 6c 6f  e top level (glo
0620: 62 61 6c 29 20 66 72 61 6d 65 2e 20 0a 2a 2f 0a  bal) frame. .*/.
0630: 69 6e 74 20 54 68 5f 47 65 74 56 61 72 28 54 68  int Th_GetVar(Th
0640: 5f 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74  _Interp *, const
0650: 20 75 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a   uchar *, int);.
0660: 69 6e 74 20 54 68 5f 53 65 74 56 61 72 28 54 68  int Th_SetVar(Th
0670: 5f 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74  _Interp *, const
0680: 20 75 63 68 61 72 20 2a 2c 20 69 6e 74 2c 20 63   uchar *, int, c
0690: 6f 6e 73 74 20 75 63 68 61 72 20 2a 2c 20 69 6e  onst uchar *, in
06a0: 74 29 3b 0a 69 6e 74 20 54 68 5f 4c 69 6e 6b 56  t);.int Th_LinkV
06b0: 61 72 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  ar(Th_Interp *, 
06c0: 63 6f 6e 73 74 20 75 63 68 61 72 20 2a 2c 20 69  const uchar *, i
06d0: 6e 74 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 75  nt, int, const u
06e0: 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e  char *, int);.in
06f0: 74 20 54 68 5f 55 6e 73 65 74 56 61 72 28 54 68  t Th_UnsetVar(Th
0700: 5f 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74  _Interp *, const
0710: 20 75 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a   uchar *, int);.
0720: 0a 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a 54  .typedef int (*T
0730: 68 5f 43 6f 6d 6d 61 6e 64 50 72 6f 63 29 28 54  h_CommandProc)(T
0740: 68 5f 49 6e 74 65 72 70 20 2a 2c 20 76 6f 69 64  h_Interp *, void
0750: 20 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 75   *, int, const u
0760: 63 68 61 72 20 2a 2a 2c 20 69 6e 74 20 2a 29 3b  char **, int *);
0770: 0a 0a 2f 2a 20 0a 2a 2a 20 52 65 67 69 73 74 65  ../* .** Registe
0780: 72 20 6e 65 77 20 63 6f 6d 6d 61 6e 64 73 2e 20  r new commands. 
0790: 0a 2a 2f 0a 69 6e 74 20 54 68 5f 43 72 65 61 74  .*/.int Th_Creat
07a0: 65 43 6f 6d 6d 61 6e 64 28 0a 20 20 54 68 5f 49  eCommand(.  Th_I
07b0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 0a  nterp *interp, .
07c0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e    const char *zN
07d0: 61 6d 65 2c 20 0a 20 20 2f 2a 20 69 6e 74 20 28  ame, .  /* int (
07e0: 2a 78 50 72 6f 63 29 28 54 68 5f 49 6e 74 65 72  *xProc)(Th_Inter
07f0: 70 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 69 6e 74  p *, void *, int
0800: 2c 20 63 6f 6e 73 74 20 75 63 68 61 72 20 2a 2a  , const uchar **
0810: 2c 20 69 6e 74 20 2a 29 2c 20 2a 2f 0a 20 20 54  , int *), */.  T
0820: 68 5f 43 6f 6d 6d 61 6e 64 50 72 6f 63 20 78 50  h_CommandProc xP
0830: 72 6f 63 2c 0a 20 20 76 6f 69 64 20 2a 70 43 6f  roc,.  void *pCo
0840: 6e 74 65 78 74 2c 0a 20 20 76 6f 69 64 20 28 2a  ntext,.  void (*
0850: 78 44 65 6c 29 28 54 68 5f 49 6e 74 65 72 70 20  xDel)(Th_Interp 
0860: 2a 2c 20 76 6f 69 64 20 2a 29 0a 29 3b 0a 0a 2f  *, void *).);../
0870: 2a 20 0a 2a 2a 20 44 65 6c 65 74 65 20 6f 72 20  * .** Delete or 
0880: 72 65 6e 61 6d 65 20 63 6f 6d 6d 61 6e 64 73 2e  rename commands.
0890: 0a 2a 2f 0a 69 6e 74 20 54 68 5f 52 65 6e 61 6d  .*/.int Th_Renam
08a0: 65 43 6f 6d 6d 61 6e 64 28 54 68 5f 49 6e 74 65  eCommand(Th_Inte
08b0: 72 70 20 2a 2c 20 63 6f 6e 73 74 20 75 63 68 61  rp *, const ucha
08c0: 72 20 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20  r *, int, const 
08d0: 75 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 0a  uchar *, int);..
08e0: 2f 2a 20 0a 2a 2a 20 50 75 73 68 20 61 20 6e 65  /* .** Push a ne
08f0: 77 20 73 74 61 63 6b 20 66 72 61 6d 65 20 28 6c  w stack frame (l
0900: 6f 63 61 6c 20 76 61 72 69 61 62 6c 65 20 63 6f  ocal variable co
0910: 6e 74 65 78 74 29 20 6f 6e 74 6f 20 74 68 65 20  ntext) onto the 
0920: 69 6e 74 65 72 70 72 65 74 65 72 20 0a 2a 2a 20  interpreter .** 
0930: 73 74 61 63 6b 2c 20 63 61 6c 6c 20 74 68 65 20  stack, call the 
0940: 66 75 6e 63 74 69 6f 6e 20 73 75 70 70 6c 69 65  function supplie
0950: 64 20 61 73 20 70 61 72 61 6d 65 74 65 72 20 78  d as parameter x
0960: 43 61 6c 6c 20 77 69 74 68 20 74 68 65 20 74 77  Call with the tw
0970: 6f 20 0a 2a 2a 20 63 6f 6e 74 65 78 74 20 61 72  o .** context ar
0980: 67 75 6d 65 6e 74 73 2c 20 0a 2a 2a 0a 2a 2a 20  guments, .**.** 
0990: 20 20 78 43 61 6c 6c 28 69 6e 74 65 72 70 2c 20    xCall(interp, 
09a0: 70 43 6f 6e 74 65 78 74 31 2c 20 70 43 6f 6e 74  pContext1, pCont
09b0: 65 78 74 32 29 0a 2a 2a 0a 2a 2a 20 2c 20 74 68  ext2).**.** , th
09c0: 65 6e 20 70 6f 70 20 74 68 65 20 66 72 61 6d 65  en pop the frame
09d0: 20 6f 66 66 20 6f 66 20 74 68 65 20 69 6e 74 65   off of the inte
09e0: 72 70 72 65 74 65 72 20 73 74 61 63 6b 2e 20 54  rpreter stack. T
09f0: 68 65 20 76 61 6c 75 65 20 72 65 74 75 72 6e 65  he value returne
0a00: 64 0a 2a 2a 20 62 79 20 74 68 65 20 78 43 61 6c  d.** by the xCal
0a10: 6c 28 29 20 66 75 6e 63 74 69 6f 6e 20 69 73 20  l() function is 
0a20: 72 65 74 75 72 6e 65 64 20 61 73 20 74 68 65 20  returned as the 
0a30: 72 65 73 75 6c 74 20 6f 66 20 74 68 69 73 20 66  result of this f
0a40: 75 6e 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54  unction..**.** T
0a50: 68 69 73 20 69 73 20 69 6e 74 65 6e 64 65 64 20  his is intended 
0a60: 66 6f 72 20 75 73 65 20 62 79 20 74 68 65 20 69  for use by the i
0a70: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66  mplementation of
0a80: 20 63 6f 6d 6d 61 6e 64 73 20 73 75 63 68 20 61   commands such a
0a90: 73 0a 2a 2a 20 74 68 6f 73 65 20 63 72 65 61 74  s.** those creat
0aa0: 65 64 20 62 79 20 5b 70 72 6f 63 5d 2e 0a 2a 2f  ed by [proc]..*/
0ab0: 0a 69 6e 74 20 54 68 5f 49 6e 46 72 61 6d 65 28  .int Th_InFrame(
0ac0: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  Th_Interp *inter
0ad0: 70 2c 0a 20 20 69 6e 74 20 28 2a 78 43 61 6c 6c  p,.  int (*xCall
0ae0: 29 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 76  )(Th_Interp *, v
0af0: 6f 69 64 20 2a 70 43 6f 6e 74 65 78 74 31 2c 20  oid *pContext1, 
0b00: 76 6f 69 64 20 2a 70 43 6f 6e 74 65 78 74 32 29  void *pContext2)
0b10: 2c 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6e 74 65  ,.  void *pConte
0b20: 78 74 31 2c 0a 20 20 76 6f 69 64 20 2a 70 43 6f  xt1,.  void *pCo
0b30: 6e 74 65 78 74 32 0a 29 3b 0a 0a 2f 2a 20 0a 2a  ntext2.);../* .*
0b40: 2a 20 56 61 6c 69 64 20 72 65 74 75 72 6e 20 63  * Valid return c
0b50: 6f 64 65 73 20 66 6f 72 20 78 50 72 6f 63 20 63  odes for xProc c
0b60: 61 6c 6c 62 61 63 6b 73 2e 0a 2a 2f 0a 23 64 65  allbacks..*/.#de
0b70: 66 69 6e 65 20 54 48 5f 4f 4b 20 20 20 20 20 20  fine TH_OK      
0b80: 20 30 0a 23 64 65 66 69 6e 65 20 54 48 5f 45 52   0.#define TH_ER
0b90: 52 4f 52 20 20 20 20 31 0a 23 64 65 66 69 6e 65  ROR    1.#define
0ba0: 20 54 48 5f 42 52 45 41 4b 20 20 20 20 32 0a 23   TH_BREAK    2.#
0bb0: 64 65 66 69 6e 65 20 54 48 5f 52 45 54 55 52 4e  define TH_RETURN
0bc0: 20 20 20 33 0a 23 64 65 66 69 6e 65 20 54 48 5f     3.#define TH_
0bd0: 43 4f 4e 54 49 4e 55 45 20 34 0a 0a 2f 2a 20 0a  CONTINUE 4../* .
0be0: 2a 2a 20 53 65 74 20 61 6e 64 20 67 65 74 20 74  ** Set and get t
0bf0: 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 20 72  he interpreter r
0c00: 65 73 75 6c 74 2e 20 0a 2a 2f 0a 69 6e 74 20 54  esult. .*/.int T
0c10: 68 5f 53 65 74 52 65 73 75 6c 74 28 54 68 5f 49  h_SetResult(Th_I
0c20: 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74 20 75  nterp *, const u
0c30: 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 63 6f  char *, int);.co
0c40: 6e 73 74 20 75 63 68 61 72 20 2a 54 68 5f 47 65  nst uchar *Th_Ge
0c50: 74 52 65 73 75 6c 74 28 54 68 5f 49 6e 74 65 72  tResult(Th_Inter
0c60: 70 20 2a 2c 20 69 6e 74 20 2a 29 3b 0a 75 63 68  p *, int *);.uch
0c70: 61 72 20 2a 54 68 5f 54 61 6b 65 52 65 73 75 6c  ar *Th_TakeResul
0c80: 74 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 69  t(Th_Interp *, i
0c90: 6e 74 20 2a 29 3b 0a 0a 2f 2a 0a 2a 2a 20 53 65  nt *);../*.** Se
0ca0: 74 20 61 6e 20 65 72 72 6f 72 20 6d 65 73 73 61  t an error messa
0cb0: 67 65 20 61 73 20 74 68 65 20 69 6e 74 65 72 70  ge as the interp
0cc0: 72 65 74 65 72 20 72 65 73 75 6c 74 2e 20 54 68  reter result. Th
0cd0: 69 73 20 61 6c 73 6f 0a 2a 2a 20 73 65 74 73 20  is also.** sets 
0ce0: 74 68 65 20 67 6c 6f 62 61 6c 20 73 74 61 63 6b  the global stack
0cf0: 2d 74 72 61 63 65 20 76 61 72 69 61 62 6c 65 20  -trace variable 
0d00: 24 3a 3a 74 68 5f 73 74 61 63 6b 5f 74 72 61 63  $::th_stack_trac
0d10: 65 2e 0a 2a 2f 0a 69 6e 74 20 54 68 5f 45 72 72  e..*/.int Th_Err
0d20: 6f 72 4d 65 73 73 61 67 65 28 54 68 5f 49 6e 74  orMessage(Th_Int
0d30: 65 72 70 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61  erp *, const cha
0d40: 72 20 2a 2c 20 63 6f 6e 73 74 20 75 63 68 61 72  r *, const uchar
0d50: 20 2a 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 0a 2a   *, int);../* .*
0d60: 2a 20 41 63 63 65 73 73 20 74 68 65 20 6d 65 6d  * Access the mem
0d70: 6f 72 79 20 6d 61 6e 61 67 65 6d 65 6e 74 20 66  ory management f
0d80: 75 6e 63 74 69 6f 6e 73 20 61 73 73 6f 63 69 61  unctions associa
0d90: 74 65 64 20 77 69 74 68 20 74 68 65 20 73 70 65  ted with the spe
0da0: 63 69 66 69 65 64 0a 2a 2a 20 69 6e 74 65 72 70  cified.** interp
0db0: 72 65 74 65 72 2e 0a 2a 2f 0a 76 6f 69 64 20 2a  reter..*/.void *
0dc0: 54 68 5f 4d 61 6c 6c 6f 63 28 54 68 5f 49 6e 74  Th_Malloc(Th_Int
0dd0: 65 72 70 20 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69  erp *, int);.voi
0de0: 64 20 54 68 5f 46 72 65 65 28 54 68 5f 49 6e 74  d Th_Free(Th_Int
0df0: 65 72 70 20 2a 2c 20 76 6f 69 64 20 2a 29 3b 0a  erp *, void *);.
0e00: 0a 2f 2a 20 0a 2a 2a 20 46 75 6e 63 74 69 6f 6e  ./* .** Function
0e10: 73 20 66 6f 72 20 68 61 6e 64 6c 69 6e 67 20 54  s for handling T
0e20: 48 20 6c 69 73 74 73 2e 0a 2a 2f 0a 69 6e 74 20  H lists..*/.int 
0e30: 54 68 5f 4c 69 73 74 41 70 70 65 6e 64 28 54 68  Th_ListAppend(Th
0e40: 5f 49 6e 74 65 72 70 20 2a 2c 20 75 63 68 61 72  _Interp *, uchar
0e50: 20 2a 2a 2c 20 69 6e 74 20 2a 2c 20 63 6f 6e 73   **, int *, cons
0e60: 74 20 75 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b  t uchar *, int);
0e70: 0a 69 6e 74 20 54 68 5f 53 70 6c 69 74 4c 69 73  .int Th_SplitLis
0e80: 74 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 63  t(Th_Interp *, c
0e90: 6f 6e 73 74 20 75 63 68 61 72 20 2a 2c 20 69 6e  onst uchar *, in
0ea0: 74 2c 20 75 63 68 61 72 20 2a 2a 2a 2c 20 69 6e  t, uchar ***, in
0eb0: 74 20 2a 2a 2c 20 69 6e 74 20 2a 29 3b 0a 0a 69  t **, int *);..i
0ec0: 6e 74 20 54 68 5f 53 74 72 69 6e 67 41 70 70 65  nt Th_StringAppe
0ed0: 6e 64 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20  nd(Th_Interp *, 
0ee0: 75 63 68 61 72 20 2a 2a 2c 20 69 6e 74 20 2a 2c  uchar **, int *,
0ef0: 20 63 6f 6e 73 74 20 75 63 68 61 72 20 2a 2c 20   const uchar *, 
0f00: 69 6e 74 29 3b 0a 0a 2f 2a 20 0a 2a 2a 20 46 75  int);../* .** Fu
0f10: 6e 63 74 69 6f 6e 73 20 66 6f 72 20 68 61 6e 64  nctions for hand
0f20: 6c 69 6e 67 20 6e 75 6d 62 65 72 73 20 61 6e 64  ling numbers and
0f30: 20 70 6f 69 6e 74 65 72 73 2e 0a 2a 2f 0a 69 6e   pointers..*/.in
0f40: 74 20 54 68 5f 54 6f 49 6e 74 28 54 68 5f 49 6e  t Th_ToInt(Th_In
0f50: 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74 20 75 63  terp *, const uc
0f60: 68 61 72 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 20  har *, int, int 
0f70: 2a 29 3b 0a 69 6e 74 20 54 68 5f 54 6f 44 6f 75  *);.int Th_ToDou
0f80: 62 6c 65 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c  ble(Th_Interp *,
0f90: 20 63 6f 6e 73 74 20 75 63 68 61 72 20 2a 2c 20   const uchar *, 
0fa0: 69 6e 74 2c 20 64 6f 75 62 6c 65 20 2a 29 3b 0a  int, double *);.
0fb0: 69 6e 74 20 54 68 5f 54 6f 50 74 72 28 54 68 5f  int Th_ToPtr(Th_
0fc0: 49 6e 74 65 72 70 20 2a 2c 20 63 6f 6e 73 74 20  Interp *, const 
0fd0: 75 63 68 61 72 20 2a 2c 20 69 6e 74 2c 20 76 6f  uchar *, int, vo
0fe0: 69 64 20 2a 2a 29 3b 0a 69 6e 74 20 54 68 5f 53  id **);.int Th_S
0ff0: 65 74 52 65 73 75 6c 74 49 6e 74 28 54 68 5f 49  etResultInt(Th_I
1000: 6e 74 65 72 70 20 2a 2c 20 69 6e 74 29 3b 0a 69  nterp *, int);.i
1010: 6e 74 20 54 68 5f 53 65 74 52 65 73 75 6c 74 44  nt Th_SetResultD
1020: 6f 75 62 6c 65 28 54 68 5f 49 6e 74 65 72 70 20  ouble(Th_Interp 
1030: 2a 2c 20 64 6f 75 62 6c 65 29 3b 0a 69 6e 74 20  *, double);.int 
1040: 54 68 5f 53 65 74 52 65 73 75 6c 74 50 74 72 28  Th_SetResultPtr(
1050: 54 68 5f 49 6e 74 65 72 70 20 2a 2c 20 76 6f 69  Th_Interp *, voi
1060: 64 20 2a 29 3b 0a 0a 2f 2a 0a 2a 2a 20 44 72 6f  d *);../*.** Dro
1070: 70 20 69 6e 20 72 65 70 6c 61 63 65 6d 65 6e 74  p in replacement
1080: 73 20 66 6f 72 20 74 68 65 20 63 6f 72 72 65 73  s for the corres
1090: 70 6f 6e 64 69 6e 67 20 73 74 61 6e 64 61 72 64  ponding standard
10a0: 20 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f   library functio
10b0: 6e 73 2e 0a 2a 2f 0a 69 6e 74 20 74 68 5f 73 74  ns..*/.int th_st
10c0: 72 6c 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 67  rlen(const unsig
10d0: 6e 65 64 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74  ned char *);.int
10e0: 20 74 68 5f 69 73 64 69 67 69 74 28 75 6e 73 69   th_isdigit(unsi
10f0: 67 6e 65 64 20 63 68 61 72 29 3b 0a 69 6e 74 20  gned char);.int 
1100: 74 68 5f 69 73 73 70 61 63 65 28 75 6e 73 69 67  th_isspace(unsig
1110: 6e 65 64 20 63 68 61 72 29 3b 0a 69 6e 74 20 74  ned char);.int t
1120: 68 5f 69 73 61 6c 6e 75 6d 28 75 6e 73 69 67 6e  h_isalnum(unsign
1130: 65 64 20 63 68 61 72 29 3b 0a 69 6e 74 20 74 68  ed char);.int th
1140: 5f 69 73 73 70 65 63 69 61 6c 28 75 6e 73 69 67  _isspecial(unsig
1150: 6e 65 64 20 63 68 61 72 29 3b 0a 75 63 68 61 72  ned char);.uchar
1160: 20 2a 74 68 5f 73 74 72 64 75 70 28 54 68 5f 49   *th_strdup(Th_I
1170: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 63  nterp *interp, c
1180: 6f 6e 73 74 20 75 63 68 61 72 20 2a 7a 2c 20 69  onst uchar *z, i
1190: 6e 74 20 6e 29 3b 0a 0a 2f 2a 0a 2a 2a 20 49 6e  nt n);../*.** In
11a0: 74 65 72 66 61 63 65 73 20 74 6f 20 72 65 67 69  terfaces to regi
11b0: 73 74 65 72 20 74 68 65 20 6c 61 6e 67 75 61 67  ster the languag
11c0: 65 20 65 78 74 65 6e 73 69 6f 6e 73 2e 0a 2a 2f  e extensions..*/
11d0: 0a 69 6e 74 20 74 68 5f 72 65 67 69 73 74 65 72  .int th_register
11e0: 5f 6c 61 6e 67 75 61 67 65 28 54 68 5f 49 6e 74  _language(Th_Int
11f0: 65 72 70 20 2a 69 6e 74 65 72 70 29 3b 20 20 20  erp *interp);   
1200: 20 20 20 20 20 20 20 20 20 2f 2a 20 74 68 5f 6c           /* th_l
1210: 61 6e 67 2e 63 20 2a 2f 0a 69 6e 74 20 74 68 5f  ang.c */.int th_
1220: 72 65 67 69 73 74 65 72 5f 73 71 6c 69 74 65 28  register_sqlite(
1230: 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  Th_Interp *inter
1240: 70 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20  p);             
1250: 20 2f 2a 20 74 68 5f 73 71 6c 69 74 65 2e 63 20   /* th_sqlite.c 
1260: 2a 2f 0a 69 6e 74 20 74 68 5f 72 65 67 69 73 74  */.int th_regist
1270: 65 72 5f 76 66 73 28 54 68 5f 49 6e 74 65 72 70  er_vfs(Th_Interp
1280: 20 2a 69 6e 74 65 72 70 29 3b 20 20 20 20 20 20   *interp);      
1290: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 74 68             /* th
12a0: 5f 76 66 73 2e 63 20 2a 2f 0a 69 6e 74 20 74 68  _vfs.c */.int th
12b0: 5f 72 65 67 69 73 74 65 72 5f 74 65 73 74 76 66  _register_testvf
12c0: 73 28 54 68 5f 49 6e 74 65 72 70 20 2a 69 6e 74  s(Th_Interp *int
12d0: 65 72 70 29 3b 20 20 20 20 20 20 20 20 20 20 20  erp);           
12e0: 20 20 2f 2a 20 74 68 5f 74 65 73 74 76 66 73 2e    /* th_testvfs.
12f0: 63 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 47 65 6e 65  c */../*.** Gene
1300: 72 61 6c 20 70 75 72 70 6f 73 65 20 68 61 73 68  ral purpose hash
1310: 20 74 61 62 6c 65 20 66 72 6f 6d 20 74 68 5f 6c   table from th_l
1320: 61 6e 67 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65  ang.c..*/.typede
1330: 66 20 73 74 72 75 63 74 20 54 68 5f 48 61 73 68  f struct Th_Hash
1340: 20 20 20 20 20 20 54 68 5f 48 61 73 68 3b 0a 74        Th_Hash;.t
1350: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 68  ypedef struct Th
1360: 5f 48 61 73 68 45 6e 74 72 79 20 54 68 5f 48 61  _HashEntry Th_Ha
1370: 73 68 45 6e 74 72 79 3b 0a 73 74 72 75 63 74 20  shEntry;.struct 
1380: 54 68 5f 48 61 73 68 45 6e 74 72 79 20 7b 0a 20  Th_HashEntry {. 
1390: 20 76 6f 69 64 20 2a 70 44 61 74 61 3b 0a 20 20   void *pData;.  
13a0: 75 63 68 61 72 20 2a 7a 4b 65 79 3b 0a 20 20 69  uchar *zKey;.  i
13b0: 6e 74 20 6e 4b 65 79 3b 0a 20 20 54 68 5f 48 61  nt nKey;.  Th_Ha
13c0: 73 68 45 6e 74 72 79 20 2a 70 4e 65 78 74 3b 20  shEntry *pNext; 
13d0: 20 20 20 20 2f 2a 20 49 6e 74 65 72 6e 61 6c 20      /* Internal 
13e0: 75 73 65 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b 0a 54  use only */.};.T
13f0: 68 5f 48 61 73 68 20 2a 54 68 5f 48 61 73 68 4e  h_Hash *Th_HashN
1400: 65 77 28 54 68 5f 49 6e 74 65 72 70 20 2a 29 3b  ew(Th_Interp *);
1410: 0a 76 6f 69 64 20 54 68 5f 48 61 73 68 44 65 6c  .void Th_HashDel
1420: 65 74 65 28 54 68 5f 49 6e 74 65 72 70 20 2a 2c  ete(Th_Interp *,
1430: 20 54 68 5f 48 61 73 68 20 2a 29 3b 0a 76 6f 69   Th_Hash *);.voi
1440: 64 20 54 68 5f 48 61 73 68 49 74 65 72 61 74 65  d Th_HashIterate
1450: 28 54 68 5f 49 6e 74 65 72 70 2a 2c 54 68 5f 48  (Th_Interp*,Th_H
1460: 61 73 68 2a 2c 76 6f 69 64 20 28 2a 78 29 28 54  ash*,void (*x)(T
1470: 68 5f 48 61 73 68 45 6e 74 72 79 2a 2c 20 76 6f  h_HashEntry*, vo
1480: 69 64 2a 29 2c 76 6f 69 64 2a 29 3b 0a 54 68 5f  id*),void*);.Th_
1490: 48 61 73 68 45 6e 74 72 79 20 2a 54 68 5f 48 61  HashEntry *Th_Ha
14a0: 73 68 46 69 6e 64 28 54 68 5f 49 6e 74 65 72 70  shFind(Th_Interp
14b0: 2a 2c 20 54 68 5f 48 61 73 68 2a 2c 20 63 6f 6e  *, Th_Hash*, con
14c0: 73 74 20 75 63 68 61 72 2a 2c 20 69 6e 74 2c 20  st uchar*, int, 
14d0: 69 6e 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 55 73 65  int);../*.** Use
14e0: 66 75 6c 20 66 75 6e 63 74 69 6f 6e 73 20 66 72  ful functions fr
14f0: 6f 6d 20 74 68 5f 6c 61 6e 67 2e 63 2e 0a 2a 2f  om th_lang.c..*/
1500: 0a 69 6e 74 20 54 68 5f 57 72 6f 6e 67 4e 75 6d  .int Th_WrongNum
1510: 41 72 67 73 28 54 68 5f 49 6e 74 65 72 70 20 2a  Args(Th_Interp *
1520: 69 6e 74 65 72 70 2c 20 63 6f 6e 73 74 20 63 68  interp, const ch
1530: 61 72 20 2a 7a 4d 73 67 29 3b 0a 0a 74 79 70 65  ar *zMsg);..type
1540: 64 65 66 20 73 74 72 75 63 74 20 54 68 5f 53 75  def struct Th_Su
1550: 62 43 6f 6d 6d 61 6e 64 20 7b 63 68 61 72 20 2a  bCommand {char *
1560: 7a 4e 61 6d 65 3b 20 54 68 5f 43 6f 6d 6d 61 6e  zName; Th_Comman
1570: 64 50 72 6f 63 20 78 50 72 6f 63 3b 7d 20 54 68  dProc xProc;} Th
1580: 5f 53 75 62 43 6f 6d 6d 61 6e 64 3b 0a 69 6e 74  _SubCommand;.int
1590: 20 54 68 5f 43 61 6c 6c 53 75 62 43 6f 6d 6d 61   Th_CallSubComma
15a0: 6e 64 28 54 68 5f 49 6e 74 65 72 70 2a 2c 76 6f  nd(Th_Interp*,vo
15b0: 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 75 63  id*,int,const uc
15c0: 68 61 72 2a 2a 2c 69 6e 74 2a 2c 54 68 5f 53 75  har**,int*,Th_Su
15d0: 62 43 6f 6d 6d 61 6e 64 2a 29 3b 0a              bCommand*);.