Add a reserved input code for 'self', the current lambda.
Correct an error in the documentation for the condition bytecode(s). Adjust the printer to limit the depth of non-cyclic object output.
This commit is contained in:
parent
e18863c3ad
commit
8f263daffc
|
|
@ -132,8 +132,9 @@ binary-expr: up to 63 (01..3f), 1 out, 2 in
|
||||||
27 (set! out (nextafter in1 in2)) ; float float
|
27 (set! out (nextafter in1 in2)) ; float float
|
||||||
28 (set! out (remainder in1 in2)) ; float float
|
28 (set! out (remainder in1 in2)) ; float float
|
||||||
29 (set! out (scalb in1 in2)) ; float float
|
29 (set! out (scalb in1 in2)) ; float float
|
||||||
conditional: 1AAAAAAA; 1 out, 2 in + fA
|
conditional: 1 out, 3 in
|
||||||
AA (set! out (if fA in1 in2)) ; in2 if fA == #f, in1 otherwise
|
; 0x80 <= AA <= 0xf7 (f0-f119)
|
||||||
|
AA (set! AA (if in1 in2 in3)) ; in3 if in1 == #f, in2 otherwise
|
||||||
statement: up to 64 (40..7f), 3 in
|
statement: up to 64 (40..7f), 3 in
|
||||||
; binary statements
|
; binary statements
|
||||||
40 (set-box! in in) ; box value
|
40 (set-box! in in) ; box value
|
||||||
|
|
@ -150,7 +151,8 @@ in:
|
||||||
gN (00NNNNNN) [global, N < 64]
|
gN (00NNNNNN) [global, N < 64]
|
||||||
iN (01NNNNNN) [instance, N < 64]
|
iN (01NNNNNN) [instance, N < 64]
|
||||||
fN (1NNNNNNN) [frame, N < 120]
|
fN (1NNNNNNN) [frame, N < 120]
|
||||||
-- (11111NNN) [reserved, N < 5]
|
-- (11111NNN) [reserved, N < 4]
|
||||||
|
self (11111100) [current lambda]
|
||||||
argv (11111101) [argument list]
|
argv (11111101) [argument list]
|
||||||
k (11111110) [continuation]
|
k (11111110) [continuation]
|
||||||
ctx (11111111) [dynamic context]
|
ctx (11111111) [dynamic context]
|
||||||
|
|
|
||||||
10
gc.c
10
gc.c
|
|
@ -920,7 +920,10 @@ typedef struct seen_value
|
||||||
static void _fprint_value(FILE *f, value_t v, seen_value_t *seen)
|
static void _fprint_value(FILE *f, value_t v, seen_value_t *seen)
|
||||||
{
|
{
|
||||||
seen_value_t new_seen = { v, seen };
|
seen_value_t new_seen = { v, seen };
|
||||||
|
int depth = 0;
|
||||||
|
|
||||||
|
if (is_object(v) && !(is_float(v) || is_byte_string(v) || is_builtin_fn(v)))
|
||||||
|
{
|
||||||
for (seen_value_t *sv = seen; sv; sv = sv->prev)
|
for (seen_value_t *sv = seen; sv; sv = sv->prev)
|
||||||
{
|
{
|
||||||
if (v == sv->value)
|
if (v == sv->value)
|
||||||
|
|
@ -928,6 +931,13 @@ static void _fprint_value(FILE *f, value_t v, seen_value_t *seen)
|
||||||
fputs("#<cycle>", f);
|
fputs("#<cycle>", f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (++depth >= 3)
|
||||||
|
{
|
||||||
|
fputs("...", f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v == NIL)
|
if (v == NIL)
|
||||||
|
|
|
||||||
16
interp.c
16
interp.c
|
|
@ -10,6 +10,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
|
|
@ -86,6 +87,12 @@ value_t run_interpreter(value_t lambda, value_t argv)
|
||||||
* Now 'lambda' really is a lambda structure instance (or builtin).
|
* Now 'lambda' really is a lambda structure instance (or builtin).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
fprint_value(stderr, state.lambda.value); fputc('\n', stderr);
|
||||||
|
fprint_value(stderr, state.argv.value); fputc('\n', stderr);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (is_builtin_fn(state.lambda.value))
|
if (is_builtin_fn(state.lambda.value))
|
||||||
{
|
{
|
||||||
/* Builtin functions replace the byte-code and tail-call
|
/* Builtin functions replace the byte-code and tail-call
|
||||||
|
|
@ -214,11 +221,10 @@ static value_t make_lambda(interp_state_t *state, value_t templ)
|
||||||
byte_string_t *t_inst;
|
byte_string_t *t_inst;
|
||||||
value_t temp;
|
value_t temp;
|
||||||
|
|
||||||
if (struct_is_a(templ, lambda_type_root.value))
|
/* If it's not a template object, just return as-is. */
|
||||||
|
if (!struct_is_a(templ, template_type_root.value))
|
||||||
return templ;
|
return templ;
|
||||||
|
|
||||||
release_assert(struct_is_a(templ, template_type_root.value));
|
|
||||||
|
|
||||||
register_gc_root(&templ_root, templ);
|
register_gc_root(&templ_root, templ);
|
||||||
register_gc_root(&lambda_root, make_struct(lambda_type_root.value, LAMBDA_SLOTS));
|
register_gc_root(&lambda_root, make_struct(lambda_type_root.value, LAMBDA_SLOTS));
|
||||||
|
|
||||||
|
|
@ -518,7 +524,9 @@ static value_t get_input(const interp_state_t *state, fixnum_t var)
|
||||||
release_assert(var < state->nframe);
|
release_assert(var < state->nframe);
|
||||||
return vec->elements[var];
|
return vec->elements[var];
|
||||||
}
|
}
|
||||||
/* 248 ... 252 are reserved */
|
/* 248 ... 251 are reserved */
|
||||||
|
case 252:
|
||||||
|
return state->lambda.value;
|
||||||
case 253:
|
case 253:
|
||||||
return state->argv.value;
|
return state->argv.value;
|
||||||
case 254:
|
case 254:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue