Commit Graph

14 Commits

Author SHA1 Message Date
Justus Winter a1ad5d6a30
gpgscm: Make tags mandatory.
* tests/gpgscm/opdefines.h: Make tags mandatory.
* tests/gpgscm/scheme.c: Likewise.
* tests/gpgscm/scheme.h: Likewise.
--

Tags provide a constant-time lookup mechanism for almost every object.
This is useful for the interpreter itself, and the code for tags is
tiny.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:30 +02:00
Justus Winter e1bb9326dc
gpgscm: Add and use opcode for reversing a list in place.
* tests/gpgscm/lib.scm (string-split-pln): Use 'reverse!'.
(string-rtrim): Likewise.
* tests/gpgscm/opdefines.h (reverse!): New opcode.
* tests/gpgscm/scheme.c (opexe_0): Handle new opcode.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:28 +02:00
Justus Winter 7dff6248bd
gpgscm: Move dispatch table into rodata.
* tests/gpgscm/opdefines.h: Use 0 instead of NULL.
* tests/gpgscm/scheme.c (op_code_info): Use char arrays instead of
pointers, make arity parameters smaller.
(INF_ARG): Adapt.
(_OP_DEF): Likewise.
(dispatch_table): Likewise.
(procname): Likewise.
(Eval_cycle): Likewise.
(scheme_init_custom_alloc): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:25 +02:00
Justus Winter e7ed9822e2
gpgscm: Remove now obsolete dispatcher function from the opcodes.
* tests/gpgscm/opdefines.h: Remove now obsolete dispatcher function
from the opcodes.
* tests/gpgscm/scheme-private.h (_OP_DEF): Adapt.
* tests/gpgscm/scheme.c (dispatch_func): Remove type declaration.
(op_code_info): Remove 'func'.
(_OP_DEF): Adapt.
(Eval_Cycle): Always call 'opexe_0'.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:22 +02:00
Justus Winter ddf444828b
gpgscm: Merge 'opexe_6'.
* tests/gpgscm/scheme.c (opexe_6): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:21 +02:00
Justus Winter 1379df4453
gpgscm: Merge 'opexe_5'.
* tests/gpgscm/scheme.c (opexe_5): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:19 +02:00
Justus Winter 4f835104b9
gpgscm: Merge 'opexe_4'.
* tests/gpgscm/scheme.c (opexe_4): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:18 +02:00
Justus Winter d591ab65d3
gpgscm: Merge 'opexe_3'.
* tests/gpgscm/scheme.c (opexe_3): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:16 +02:00
Justus Winter 6cad38228f
gpgscm: Merge 'opexe_2'.
* tests/gpgscm/scheme.c (opexe_2): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:15 +02:00
Justus Winter 154af876f0
gpgscm: Merge 'opexe_1'.
* tests/gpgscm/scheme.c (opexe_1): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-04-10 14:57:13 +02:00
Justus Winter 404e8a4136 gpgscm: Keep a history of calls for error messages.
* tests/gpgscm/init.scm (vm-history-print): New function.
* tests/gpgscm/opdefines.h: New opcodes 'CALLSTACK_POP', 'APPLY_CODE',
and 'VM_HISTORY'.
* tests/gpgscm/scheme-private.h (struct history): New definition.
(struct scheme): New field 'history'.
* tests/gpgscm/scheme.c (gc): Mark objects in the history.
(history_free): New function.
(history_init): Likewise.
(history_mark): Likewise.
(add_mod): New macro.
(sub_mod): Likewise.
(tailstack_clear): New function.
(callstack_pop): Likewise.
(callstack_push): Likewise.
(tailstack_push): Likewise.
(tailstack_flatten): Likewise.
(callstack_flatten): Likewise.
(history_flatten): Likewise.
(opexe_0): New variable 'callsite', keep track of the expression if it
is a call, implement the new opcodes, record function applications in
the history.
(opexe_6): Implement new opcode.
(scheme_init_custom_alloc): Initialize history.
(scheme_deinit): Free history.
* tests/gpgscm/scheme.h (USE_HISTORY): New macro.
--

This patch makes TinySCHEME keep a history of function calls.  This
history can be used to produce helpful error messages.  The history
data structure is inspired by MIT/GNU Scheme.

Signed-off-by: Justus Winter <justus@g10code.com>

fu history
2016-12-08 17:15:20 +01:00
Justus Winter fcf5aea446 gpgscm: Implement tags.
* tests/gpgscm/opdefines.h: Add opcodes to create and retrieve tags.
* tests/gpgscm/scheme.c (T_TAGGED): New macro.
(mk_tagged_value): New function.
(has_tag): Likewise.
(get_tag): Likewise.
(mark): Mark tag.
(opexe_4): Implement new opcodes.
* tests/gpgscm/scheme.h (USE_TAGS): New macro.
--

Tags are similar to property lists, but property lists can only be
attached to symbols.  Tags can not be attached to an existing object,
but a tagged copy can be created.  Once done, the tag can be
manipulated in constant time.

Using this during parsing will enable us to produce meaningful error
messages.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 17:15:20 +01:00
Justus Winter d8df804272 gpgscm: Fix property lists.
* tests/gpgscm/opdefines.h (put, get): Check arguments.  Also rename
to 'set-symbol-property' and 'symbol-property', the names used by
Guile, because put and get are too unspecific.
* tests/gpgscm/scheme.c (hasprop): Only symbols have property lists.
(get_property): New function.
(set_property): Likewise.
(opexe_4): Use the new functions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-22 12:09:47 +01:00
Justus Winter cb989504cd tests/gpgscm: Verbatim import of latest TinySCHEME.
Revision 110 from svn://svn.code.sf.net/p/tinyscheme/code/trunk

* tests/gpgscm/COPYING: New file.
* tests/gpgscm/Manual.txt: Likewise.
* tests/gpgscm/init.scm: Likewise.
* tests/gpgscm/opdefines.h: Likewise.
* tests/gpgscm/scheme-private.h: Likewise.
* tests/gpgscm/scheme.c: Likewise.
* tests/gpgscm/scheme.h: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:36:27 +02:00