mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
Update copyright date, fix types, remove trailing whitespace.
This commit is contained in:
parent
ef5eed2c21
commit
6f3bc3d577
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2018 Calvin Rose
|
Copyright (c) 2019 Calvin Rose
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
/* Check a subset of numbers against system implementation.
|
/* Check a subset of numbers against system implementation.
|
||||||
* Note that this depends on the system implementation being correct,
|
* Note that this depends on the system implementation being correct,
|
||||||
* which may not be the case for old or non complient systems. Also,
|
* which may not be the case for old or non compliant systems. Also,
|
||||||
* we cannot check against bases other 10. */
|
* we cannot check against bases other 10. */
|
||||||
|
|
||||||
/* Compare valid c numbers to system implementation. */
|
/* Compare valid c numbers to system implementation. */
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2018 Calvin Rose
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -63,11 +63,11 @@ notation with a radix besides 10, use the `&` symbol to indicate the exponent ra
|
|||||||
## Arithmetic Functions
|
## Arithmetic Functions
|
||||||
|
|
||||||
Besides the 5 main arithmetic functions, janet also supports a number of math functions
|
Besides the 5 main arithmetic functions, janet also supports a number of math functions
|
||||||
taken from the C library `<math.h>`, as well as bitwise operators that behave like they
|
taken from the C library `<math.h>`, as well as bit-wise operators that behave like they
|
||||||
do in C or Java. Functions like `math/sin`, `math/cos`, `math/log`, and `math/exp` will
|
do in C or Java. Functions like `math/sin`, `math/cos`, `math/log`, and `math/exp` will
|
||||||
behave as expected to a C programmer. They all take either 1 or 2 numeric arguments and
|
behave as expected to a C programmer. They all take either 1 or 2 numeric arguments and
|
||||||
return a real number (never an integer!) Bitwise functions are all prefixed with b.
|
return a real number (never an integer!) Bit-wise functions are all prefixed with b.
|
||||||
Thet are `bnot`, `bor`, `bxor`, `band`, `blshift`, `brshift`, and `brushift`. Bitwise
|
They are `bnot`, `bor`, `bxor`, `band`, `blshift`, `brshift`, and `brushift`. Bit-wise
|
||||||
functions only work on integers.
|
functions only work on integers.
|
||||||
|
|
||||||
# Strings, Keywords and Symbols
|
# Strings, Keywords and Symbols
|
||||||
@ -321,16 +321,16 @@ there relationship to each other.
|
|||||||
| ---------- | ------- | --------------- |
|
| ---------- | ------- | --------------- |
|
||||||
| Indexed | Array | Tuple |
|
| Indexed | Array | Tuple |
|
||||||
| Dictionary | Table | Struct |
|
| Dictionary | Table | Struct |
|
||||||
| Byteseq | Buffer | String (Symbol) |
|
| Bytes | Buffer | String |
|
||||||
|
|
||||||
Indexed types are linear lists of elements than can be accessed in constant time with an integer index.
|
Indexed types are linear lists of elements than can be accessed in constant time with an integer index.
|
||||||
Indexed types are backed by a single chunk of memory for fast access, and are indexed from 0 as in C.
|
Indexed types are backed by a single chunk of memory for fast access, and are indexed from 0 as in C.
|
||||||
Dictionary types associate keys with values. The difference between dictionaries and indexed types
|
Dictionary types associate keys with values. The difference between dictionaries and indexed types
|
||||||
is that dictionaries are not limited to integer keys. They are backed by a hashtable and also offer
|
is that dictionaries are not limited to integer keys. They are backed by a hashtable and also offer
|
||||||
constant time lookup (and insertion for the mutable case).
|
constant time lookup (and insertion for the mutable case).
|
||||||
Finally, the 'byteseq' abstraction is any type that contains a sequence of bytes. A byteseq associates
|
Finally, the 'bytes' abstraction is any type that contains a sequence of bytes. A 'bytes' value or byteseq associates
|
||||||
integer keys (the indices) with integer values between 0 and 255 (the byte values). In this way,
|
integer keys (the indices) with integer values between 0 and 255 (the byte values). In this way,
|
||||||
they behave much like Arrays and Tuples. However, one cannot put non integer values into a byteseq.
|
they behave much like Arrays and Tuples. However, one cannot put non integer values into a byteseq
|
||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
(def mytuple (tuple 1 2 3))
|
(def mytuple (tuple 1 2 3))
|
||||||
@ -544,7 +544,7 @@ control is returned to the calling fiber. The parent fiber must then check what
|
|||||||
fiber is in to differentiate errors from return values from user defined signals.
|
fiber is in to differentiate errors from return values from user defined signals.
|
||||||
|
|
||||||
To create a fiber, user the `fiber/new` function. The fiber constructor take one or two arguments.
|
To create a fiber, user the `fiber/new` function. The fiber constructor take one or two arguments.
|
||||||
the first, necessary argument is the function that the fiber will execute. This function must accept
|
The first, necessary argument is the function that the fiber will execute. This function must accept
|
||||||
an arity of zero. The next optional argument is a collection of flags checking what kinds of
|
an arity of zero. The next optional argument is a collection of flags checking what kinds of
|
||||||
signals to trap and return via `resume`. This is useful so
|
signals to trap and return via `resume`. This is useful so
|
||||||
the programmer does not need to handle all different kinds of signals from a fiber. Any un-trapped signals
|
the programmer does not need to handle all different kinds of signals from a fiber. Any un-trapped signals
|
||||||
@ -639,7 +639,7 @@ using janet's builtin quasiquoting facilities.
|
|||||||
```
|
```
|
||||||
|
|
||||||
This is functionally identical to our previous version `defn2`, but written in such
|
This is functionally identical to our previous version `defn2`, but written in such
|
||||||
a way that the macro output is more clear. The leading backtick is shorthand for the
|
a way that the macro output is more clear. The leading tilde `~` is shorthand for the
|
||||||
`(quasiquote x)` special form, which is like `(quote x)` except we can unquote
|
`(quasiquote x)` special form, which is like `(quote x)` except we can unquote
|
||||||
expressions inside it. The comma in front of `name` and `args` is an unquote, which
|
expressions inside it. The comma in front of `name` and `args` is an unquote, which
|
||||||
allows us to put a value in the quasiquote. Without the unquote, the symbol \'name\'
|
allows us to put a value in the quasiquote. Without the unquote, the symbol \'name\'
|
||||||
@ -720,7 +720,7 @@ to be 10. The problem is the reuse of the symbol x inside the macro, which overs
|
|||||||
binding.
|
binding.
|
||||||
|
|
||||||
Janet provides a general solution to this problem in terms of the `(gensym)` function, which returns
|
Janet provides a general solution to this problem in terms of the `(gensym)` function, which returns
|
||||||
a symbol which is guarenteed to be unique and not collide with any symbols defined previously. We can define
|
a symbol which is guaranteed to be unique and not collide with any symbols defined previously. We can define
|
||||||
our macro once more for a fully correct macro.
|
our macro once more for a fully correct macro.
|
||||||
|
|
||||||
```lisp
|
```lisp
|
||||||
|
@ -33,7 +33,7 @@ false
|
|||||||
Janet symbols are represented a sequence of alphanumeric characters
|
Janet symbols are represented a sequence of alphanumeric characters
|
||||||
not starting with a digit or a colon. They can also contain the characters
|
not starting with a digit or a colon. They can also contain the characters
|
||||||
\!, @, $, \%, \^, \&, \*, -, \_, +, =, \|, \~, :, \<, \>, ., \?, \\, /, as
|
\!, @, $, \%, \^, \&, \*, -, \_, +, =, \|, \~, :, \<, \>, ., \?, \\, /, as
|
||||||
well as any Unicode codepoint not in the ascii range.
|
well as any Unicode codepoint not in the ASCII range.
|
||||||
|
|
||||||
By convention, most symbols should be all lower case and use dashes to connect words
|
By convention, most symbols should be all lower case and use dashes to connect words
|
||||||
(sometimes called kebab case).
|
(sometimes called kebab case).
|
||||||
@ -120,7 +120,7 @@ delimited string. A string can also be define to start with a certain number of
|
|||||||
backquotes, and will end the same number of backquotes. Long strings
|
backquotes, and will end the same number of backquotes. Long strings
|
||||||
do not contain escape sequences; all bytes will be parsed literally until
|
do not contain escape sequences; all bytes will be parsed literally until
|
||||||
ending delimiter is found. This is useful
|
ending delimiter is found. This is useful
|
||||||
for definining multiline strings with literal newline characters, unprintable
|
for defining multi-line strings with literal newline characters, unprintable
|
||||||
characters, or strings that would otherwise require many escape sequences.
|
characters, or strings that would otherwise require many escape sequences.
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -155,7 +155,7 @@ the buffer must be prefixed with the '@' character.
|
|||||||
|
|
||||||
Tuples are a sequence of white space separated values surrounded by either parentheses
|
Tuples are a sequence of white space separated values surrounded by either parentheses
|
||||||
or brackets. The parser considers any of the characters ASCII 32, \\0, \\f, \\n, \\r or \\t
|
or brackets. The parser considers any of the characters ASCII 32, \\0, \\f, \\n, \\r or \\t
|
||||||
to be whitespace.
|
to be white-space.
|
||||||
|
|
||||||
```
|
```
|
||||||
(do 1 2 3)
|
(do 1 2 3)
|
||||||
@ -173,7 +173,7 @@ Arrays are the same as tuples, but have a leading @ to indicate mutability.
|
|||||||
|
|
||||||
## Structs
|
## Structs
|
||||||
|
|
||||||
Structs are represented by a sequence of whitespace delimited key value pairs
|
Structs are represented by a sequence of white-space delimited key value pairs
|
||||||
surrounded by curly braces. The sequence is defined as key1, value1, key2, value2, etc.
|
surrounded by curly braces. The sequence is defined as key1, value1, key2, value2, etc.
|
||||||
There must be an even number of items between curly braces or the parser will
|
There must be an even number of items between curly braces or the parser will
|
||||||
signal a parse error. Any value can be a key or value. Using nil as a key or
|
signal a parse error. Any value can be a key or value. Using nil as a key or
|
||||||
@ -202,10 +202,9 @@ that they are mutable.
|
|||||||
## Comments
|
## Comments
|
||||||
|
|
||||||
Comments begin with a \# character and continue until the end of the line.
|
Comments begin with a \# character and continue until the end of the line.
|
||||||
There are no multiline comments. For ricm multiline comments, use a
|
There are no multi-line comments.
|
||||||
string literal.
|
|
||||||
|
|
||||||
## Shorthands
|
## Shorthand
|
||||||
|
|
||||||
Often called reader macros in other lisps, Janet provides several shorthand
|
Often called reader macros in other lisps, Janet provides several shorthand
|
||||||
notations for some forms.
|
notations for some forms.
|
||||||
|
@ -197,7 +197,7 @@ The r-value can be any expression, and the l-value should be a bound var.
|
|||||||
|
|
||||||
Similar to `(quote x)`, but allows for unquoting within x. This makes quasiquote useful for
|
Similar to `(quote x)`, but allows for unquoting within x. This makes quasiquote useful for
|
||||||
writing macros, as a macro definition often generates a lot of templated code with a
|
writing macros, as a macro definition often generates a lot of templated code with a
|
||||||
few custom values. The shorthand for quasiquote is a leading tilda `~` before a form. With
|
few custom values. The shorthand for quasiquote is a leading tilde `~` before a form. With
|
||||||
that form, `(unquote x)` will evaluate and insert x into the unquote form. The shorthand for
|
that form, `(unquote x)` will evaluate and insert x into the unquote form. The shorthand for
|
||||||
`(unquote x)` is `,x`.
|
`(unquote x)` is `,x`.
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ by their short names as presented to the assembler rather than their numerical v
|
|||||||
Each instruction is also listed with a signature, which are the arguments the instruction
|
Each instruction is also listed with a signature, which are the arguments the instruction
|
||||||
expects. There are a handful of instruction signatures, which combine the arity and type
|
expects. There are a handful of instruction signatures, which combine the arity and type
|
||||||
of the instruction. The assembler does not
|
of the instruction. The assembler does not
|
||||||
do any typechecking per closure, but does prevent jumping to invalid instructions and
|
do any type-checking per closure, but does prevent jumping to invalid instructions and
|
||||||
failure to return or error.
|
failure to return or error.
|
||||||
|
|
||||||
### Notation
|
### Notation
|
||||||
@ -148,7 +148,7 @@ failure to return or error.
|
|||||||
|
|
||||||
* Some operators in the description have the suffix 'i' or 'r'. These indicate
|
* Some operators in the description have the suffix 'i' or 'r'. These indicate
|
||||||
that these operators correspond to integers or real numbers only, respectively. All
|
that these operators correspond to integers or real numbers only, respectively. All
|
||||||
bitwise operators and bit shifts only work with integers.
|
bit-wise operators and bit shifts only work with integers.
|
||||||
|
|
||||||
* The `>>>` indicates unsigned right shift, as in Java. Because all integers in janet are
|
* The `>>>` indicates unsigned right shift, as in Java. Because all integers in janet are
|
||||||
signed, we differentiate the two kinds of right bit shift.
|
signed, we differentiate the two kinds of right bit shift.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -215,7 +215,7 @@ static Janet cfun_insert(int32_t argc, Janet *argv) {
|
|||||||
static const JanetReg cfuns[] = {
|
static const JanetReg cfuns[] = {
|
||||||
{"array/new", cfun_new,
|
{"array/new", cfun_new,
|
||||||
JDOC("(array/new capacity)\n\n"
|
JDOC("(array/new capacity)\n\n"
|
||||||
"Creates a new empty array with a preallocated capacity. The same as "
|
"Creates a new empty array with a pre-allocated capacity. The same as "
|
||||||
"(array) but can be more efficient if the maximum size of an array is known.")
|
"(array) but can be more efficient if the maximum size of an array is known.")
|
||||||
},
|
},
|
||||||
{"array/pop", cfun_pop,
|
{"array/pop", cfun_pop,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -55,7 +55,7 @@ struct JanetAssembler {
|
|||||||
JanetTable defs; /* symbol -> funcdefs index */
|
JanetTable defs; /* symbol -> funcdefs index */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Janet opcode descriptions in lexographic order. This
|
/* Janet opcode descriptions in lexicographic order. This
|
||||||
* allows a binary search over the elements to find the
|
* allows a binary search over the elements to find the
|
||||||
* correct opcode given a name. This works in reasonable
|
* correct opcode given a name. This works in reasonable
|
||||||
* time and is easier to setup statically than a hash table or
|
* time and is easier to setup statically than a hash table or
|
||||||
@ -742,7 +742,7 @@ JanetAssembleResult janet_asm(Janet source, int flags) {
|
|||||||
|
|
||||||
/* Disassembly */
|
/* Disassembly */
|
||||||
|
|
||||||
/* Find the deinfintion of an instruction given the instruction word. Return
|
/* Find the definition of an instruction given the instruction word. Return
|
||||||
* NULL if not found. */
|
* NULL if not found. */
|
||||||
static const JanetInstructionDef *janet_asm_reverse_lookup(uint32_t instr) {
|
static const JanetInstructionDef *janet_asm_reverse_lookup(uint32_t instr) {
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -783,7 +783,7 @@ static Janet tup4(Janet w, Janet x, Janet y, Janet z) {
|
|||||||
return janet_wrap_tuple(janet_tuple_end(tup));
|
return janet_wrap_tuple(janet_tuple_end(tup));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given an argument, convert it to the appriate integer or symbol */
|
/* Given an argument, convert it to the appropriate integer or symbol */
|
||||||
Janet janet_asm_decode_instruction(uint32_t instr) {
|
Janet janet_asm_decode_instruction(uint32_t instr) {
|
||||||
const JanetInstructionDef *def = janet_asm_reverse_lookup(instr);
|
const JanetInstructionDef *def = janet_asm_reverse_lookup(instr);
|
||||||
Janet name;
|
Janet name;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -46,14 +46,14 @@ static int fixarity3(JanetFopts opts, JanetSlot *args) {
|
|||||||
return janet_v_count(args) == 3;
|
return janet_v_count(args) == 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic hanldling for $A = op $B */
|
/* Generic handling for $A = op $B */
|
||||||
static JanetSlot genericSS(JanetFopts opts, int op, JanetSlot s) {
|
static JanetSlot genericSS(JanetFopts opts, int op, JanetSlot s) {
|
||||||
JanetSlot target = janetc_gettarget(opts);
|
JanetSlot target = janetc_gettarget(opts);
|
||||||
janetc_emit_ss(opts.compiler, op, target, s, 1);
|
janetc_emit_ss(opts.compiler, op, target, s, 1);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic hanldling for $A = $B op I */
|
/* Generic handling for $A = $B op I */
|
||||||
static JanetSlot genericSSI(JanetFopts opts, int op, JanetSlot s, int32_t imm) {
|
static JanetSlot genericSSI(JanetFopts opts, int op, JanetSlot s, int32_t imm) {
|
||||||
JanetSlot target = janetc_gettarget(opts);
|
JanetSlot target = janetc_gettarget(opts);
|
||||||
janetc_emit_ssi(opts.compiler, op, target, s, imm, 1);
|
janetc_emit_ssi(opts.compiler, op, target, s, imm, 1);
|
||||||
@ -136,7 +136,7 @@ static JanetSlot do_apply(JanetFopts opts, JanetSlot *args) {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Varidadic operators specialization */
|
/* Variadic operators specialization */
|
||||||
|
|
||||||
static JanetSlot do_add(JanetFopts opts, JanetSlot *args) {
|
static JanetSlot do_add(JanetFopts opts, JanetSlot *args) {
|
||||||
return opreduce(opts, args, JOP_ADD, janet_wrap_integer(0));
|
return opreduce(opts, args, JOP_ADD, janet_wrap_integer(0));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -236,7 +236,7 @@ JanetSlot janetc_resolve(
|
|||||||
scope->flags |= JANET_SCOPE_ENV;
|
scope->flags |= JANET_SCOPE_ENV;
|
||||||
scope = scope->child;
|
scope = scope->child;
|
||||||
|
|
||||||
/* Propogate env up to current scope */
|
/* Propagate env up to current scope */
|
||||||
int32_t envindex = -1;
|
int32_t envindex = -1;
|
||||||
while (scope) {
|
while (scope) {
|
||||||
if (scope->flags & JANET_SCOPE_FUNCTION) {
|
if (scope->flags & JANET_SCOPE_FUNCTION) {
|
||||||
@ -725,7 +725,7 @@ static Janet cfun(int32_t argc, Janet *argv) {
|
|||||||
static const JanetReg cfuns[] = {
|
static const JanetReg cfuns[] = {
|
||||||
{"compile", cfun,
|
{"compile", cfun,
|
||||||
JDOC("(compile ast env [, source])\n\n"
|
JDOC("(compile ast env [, source])\n\n"
|
||||||
"Compiles an Abstract Sytnax Tree (ast) into a janet function. "
|
"Compiles an Abstract Syntax Tree (ast) into a janet function. "
|
||||||
"Pair the compile function with parsing functionality to implement "
|
"Pair the compile function with parsing functionality to implement "
|
||||||
"eval. Returns a janet function and does not modify ast. Throws an "
|
"eval. Returns a janet function and does not modify ast. Throws an "
|
||||||
"error if the ast cannot be compiled.")
|
"error if the ast cannot be compiled.")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# The core janet library
|
# The core janet library
|
||||||
# Copyright 2018 (C) Calvin Rose
|
# Copyright 2019 (C) Calvin Rose
|
||||||
|
|
||||||
###
|
###
|
||||||
###
|
###
|
||||||
@ -469,7 +469,7 @@
|
|||||||
accum)
|
accum)
|
||||||
|
|
||||||
(defmacro if-let
|
(defmacro if-let
|
||||||
"Make mutliple bindings, anf if all are truthy,
|
"Make multiple bindings, and if all are truthy,
|
||||||
evaluate the tru form. If any are false or nil, evaluate
|
evaluate the tru form. If any are false or nil, evaluate
|
||||||
the fal form. Bindings have the same syntax as the let macro."
|
the fal form. Bindings have the same syntax as the let macro."
|
||||||
[bindings tru fal &]
|
[bindings tru fal &]
|
||||||
@ -576,7 +576,7 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
(def sort
|
(def sort
|
||||||
"(sort xs [, by])\n\nSort an array in-place. Uses quicksort and is not a stable sort."
|
"(sort xs [, by])\n\nSort an array in-place. Uses quick-sort and is not a stable sort."
|
||||||
(do
|
(do
|
||||||
|
|
||||||
(defn partition
|
(defn partition
|
||||||
@ -859,13 +859,13 @@
|
|||||||
(put _env 'walk-dict nil)
|
(put _env 'walk-dict nil)
|
||||||
|
|
||||||
(defn postwalk
|
(defn postwalk
|
||||||
"Do a postorder traversal of a data sructure and call (f x)
|
"Do a post-order traversal of a data structure and call (f x)
|
||||||
on every visitation."
|
on every visitation."
|
||||||
[f form]
|
[f form]
|
||||||
(f (walk (fn [x] (postwalk f x)) form)))
|
(f (walk (fn [x] (postwalk f x)) form)))
|
||||||
|
|
||||||
(defn prewalk
|
(defn prewalk
|
||||||
"Similar to postwalk, but do preorder traversal."
|
"Similar to postwalk, but do pre-order traversal."
|
||||||
[f form]
|
[f form]
|
||||||
(walk (fn [x] (prewalk f x)) (f form)))
|
(walk (fn [x] (prewalk f x)) (f form)))
|
||||||
|
|
||||||
@ -1024,7 +1024,7 @@ value, one key will be ignored."
|
|||||||
res)
|
res)
|
||||||
|
|
||||||
(defn distinct
|
(defn distinct
|
||||||
"Returns an array of the the deduplicated values in xs."
|
"Returns an array of the deduplicated values in xs."
|
||||||
[xs]
|
[xs]
|
||||||
(def ret @[])
|
(def ret @[])
|
||||||
(def seen @{})
|
(def seen @{})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -381,6 +381,8 @@ static const JanetReg cfuns[] = {
|
|||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
|
|
||||||
/* Utility for inline assembly */
|
/* Utility for inline assembly */
|
||||||
static void janet_quick_asm(
|
static void janet_quick_asm(
|
||||||
JanetTable *env,
|
JanetTable *env,
|
||||||
@ -599,6 +601,7 @@ static const uint32_t bnot_asm[] = {
|
|||||||
JOP_BNOT,
|
JOP_BNOT,
|
||||||
JOP_RETURN
|
JOP_RETURN
|
||||||
};
|
};
|
||||||
|
#endif /* ifndef JANET_NO_BOOTSTRAP */
|
||||||
|
|
||||||
JanetTable *janet_core_env(void) {
|
JanetTable *janet_core_env(void) {
|
||||||
JanetTable *env = janet_table(0);
|
JanetTable *env = janet_table(0);
|
||||||
@ -607,6 +610,7 @@ JanetTable *janet_core_env(void) {
|
|||||||
/* Load main functions */
|
/* Load main functions */
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, cfuns);
|
||||||
|
|
||||||
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
janet_quick_asm(env, JANET_FUN_YIELD, "debug", 0, 1, debug_asm, sizeof(debug_asm),
|
janet_quick_asm(env, JANET_FUN_YIELD, "debug", 0, 1, debug_asm, sizeof(debug_asm),
|
||||||
JDOC("(debug)\n\n"
|
JDOC("(debug)\n\n"
|
||||||
"Throws a debug signal that can be caught by a parent fiber and used to inspect "
|
"Throws a debug signal that can be caught by a parent fiber and used to inspect "
|
||||||
@ -645,7 +649,7 @@ JanetTable *janet_core_env(void) {
|
|||||||
"Returns the length or count of a data structure in constant time as an integer. For "
|
"Returns the length or count of a data structure in constant time as an integer. For "
|
||||||
"structs and tables, returns the number of key-value pairs in the data structure."));
|
"structs and tables, returns the number of key-value pairs in the data structure."));
|
||||||
janet_quick_asm(env, JANET_FUN_BNOT, "bnot", 1, 1, bnot_asm, sizeof(bnot_asm),
|
janet_quick_asm(env, JANET_FUN_BNOT, "bnot", 1, 1, bnot_asm, sizeof(bnot_asm),
|
||||||
JDOC("(bnot x)\n\nReturns the bitwise inverse of integer x."));
|
JDOC("(bnot x)\n\nReturns the bit-wise inverse of integer x."));
|
||||||
make_apply(env);
|
make_apply(env);
|
||||||
|
|
||||||
/* Variadic ops */
|
/* Variadic ops */
|
||||||
@ -667,13 +671,13 @@ JanetTable *janet_core_env(void) {
|
|||||||
"values. Division by two integers uses truncating division."));
|
"values. Division by two integers uses truncating division."));
|
||||||
templatize_varop(env, JANET_FUN_BAND, "band", -1, -1, JOP_BAND,
|
templatize_varop(env, JANET_FUN_BAND, "band", -1, -1, JOP_BAND,
|
||||||
JDOC("(band & xs)\n\n"
|
JDOC("(band & xs)\n\n"
|
||||||
"Returns the bitwise and of all values in xs. Each x in xs must be an integer."));
|
"Returns the bit-wise and of all values in xs. Each x in xs must be an integer."));
|
||||||
templatize_varop(env, JANET_FUN_BOR, "bor", 0, 0, JOP_BOR,
|
templatize_varop(env, JANET_FUN_BOR, "bor", 0, 0, JOP_BOR,
|
||||||
JDOC("(bor & xs)\n\n"
|
JDOC("(bor & xs)\n\n"
|
||||||
"Returns the bitwise or of all values in xs. Each x in xs must be an integer."));
|
"Returns the bit-wise or of all values in xs. Each x in xs must be an integer."));
|
||||||
templatize_varop(env, JANET_FUN_BXOR, "bxor", 0, 0, JOP_BXOR,
|
templatize_varop(env, JANET_FUN_BXOR, "bxor", 0, 0, JOP_BXOR,
|
||||||
JDOC("(bxor & xs)\n\n"
|
JDOC("(bxor & xs)\n\n"
|
||||||
"Returns the bitwise xor of all values in xs. Each in xs must be an integer."));
|
"Returns the bit-wise xor of all values in xs. Each in xs must be an integer."));
|
||||||
templatize_varop(env, JANET_FUN_LSHIFT, "blshift", 1, 1, JOP_SHIFT_LEFT,
|
templatize_varop(env, JANET_FUN_LSHIFT, "blshift", 1, 1, JOP_SHIFT_LEFT,
|
||||||
JDOC("(blshift x & shifts)\n\n"
|
JDOC("(blshift x & shifts)\n\n"
|
||||||
"Returns the value of x bit shifted left by the sum of all values in shifts. x "
|
"Returns the value of x bit shifted left by the sum of all values in shifts. x "
|
||||||
@ -732,12 +736,13 @@ JanetTable *janet_core_env(void) {
|
|||||||
|
|
||||||
/* Platform detection */
|
/* Platform detection */
|
||||||
janet_def(env, "janet/version", janet_cstringv(JANET_VERSION),
|
janet_def(env, "janet/version", janet_cstringv(JANET_VERSION),
|
||||||
"The version number of the running janet program.");
|
JDOC("The version number of the running janet program."));
|
||||||
janet_def(env, "janet/build", janet_cstringv(JANET_BUILD),
|
janet_def(env, "janet/build", janet_cstringv(JANET_BUILD),
|
||||||
"The build identifier of the running janet program.");
|
JDOC("The build identifier of the running janet program."));
|
||||||
|
|
||||||
/* Allow references to the environment */
|
/* Allow references to the environment */
|
||||||
janet_def(env, "_env", ret, "The environment table for the current scope.");
|
janet_def(env, "_env", ret, JDOC("The environment table for the current scope."));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Set as gc root */
|
/* Set as gc root */
|
||||||
janet_gcroot(janet_wrap_table(env));
|
janet_gcroot(janet_wrap_table(env));
|
||||||
@ -760,8 +765,10 @@ JanetTable *janet_core_env(void) {
|
|||||||
janet_lib_asm(env);
|
janet_lib_asm(env);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
/* Run bootstrap source */
|
/* Run bootstrap source */
|
||||||
janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL);
|
janet_dobytes(env, janet_gen_core, janet_gen_core_size, "core.janet", NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -274,7 +274,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"\t:line - the current source line of the stack frame\n"
|
"\t:line - the current source line of the stack frame\n"
|
||||||
"\t:name - the human friendly name of the function\n"
|
"\t:name - the human friendly name of the function\n"
|
||||||
"\t:pc - integer indicating the location of the program counter\n"
|
"\t:pc - integer indicating the location of the program counter\n"
|
||||||
"\t:source - string with filename or other identifier for the source code\n"
|
"\t:source - string with the file path or other identifier for the source code\n"
|
||||||
"\t:slots - array of all values in each slot\n"
|
"\t:slots - array of all values in each slot\n"
|
||||||
"\t:tail - boolean indicating a tail call")
|
"\t:tail - boolean indicating a tail call")
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -61,7 +61,7 @@ static int32_t janetc_const(JanetCompiler *c, Janet x) {
|
|||||||
if (janet_equals(x, scope->consts[i]))
|
if (janet_equals(x, scope->consts[i]))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
/* Ensure not too many constsants. */
|
/* Ensure not too many constants. */
|
||||||
if (len >= 0xFFFF) {
|
if (len >= 0xFFFF) {
|
||||||
janetc_cerror(c, "too many constants");
|
janetc_cerror(c, "too many constants");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -211,7 +211,7 @@ int janet_fiber_funcframe_tail(JanetFiber *fiber, JanetFunction *func) {
|
|||||||
Janet *stack = fiber->data + fiber->frame;
|
Janet *stack = fiber->data + fiber->frame;
|
||||||
Janet *args = fiber->data + fiber->stackstart;
|
Janet *args = fiber->data + fiber->stackstart;
|
||||||
|
|
||||||
/* Detatch old function */
|
/* Detach old function */
|
||||||
if (NULL != janet_fiber_frame(fiber)->func)
|
if (NULL != janet_fiber_frame(fiber)->func)
|
||||||
janet_env_detach(janet_fiber_frame(fiber)->env);
|
janet_env_detach(janet_fiber_frame(fiber)->env);
|
||||||
janet_fiber_frame(fiber)->env = NULL;
|
janet_fiber_frame(fiber)->env = NULL;
|
||||||
@ -414,7 +414,7 @@ static const JanetReg cfuns[] = {
|
|||||||
JDOC("(fiber/maxstack fib)\n\n"
|
JDOC("(fiber/maxstack fib)\n\n"
|
||||||
"Gets the maximum stack size in janet values allowed for a fiber. While memory for "
|
"Gets the maximum stack size in janet values allowed for a fiber. While memory for "
|
||||||
"the fiber's stack is not allocated up front, the fiber will not allocated more "
|
"the fiber's stack is not allocated up front, the fiber will not allocated more "
|
||||||
"than this amount and will throw a stackoverflow error if more memory is needed. ")
|
"than this amount and will throw a stack-overflow error if more memory is needed. ")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fiber/setmaxstack", cfun_setmaxstack,
|
"fiber/setmaxstack", cfun_setmaxstack,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -53,7 +53,7 @@ JanetAbstractType janet_io_filetype = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Check argupments to fopen */
|
/* Check arguments to fopen */
|
||||||
static int checkflags(const uint8_t *str) {
|
static int checkflags(const uint8_t *str) {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int32_t i;
|
int32_t i;
|
||||||
@ -133,7 +133,6 @@ static Janet janet_io_popen(int32_t argc, Janet *argv) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Open a a file and return a userdata wrapper around the C file API. */
|
|
||||||
static Janet janet_io_fopen(int32_t argc, Janet *argv) {
|
static Janet janet_io_fopen(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
const uint8_t *fname = janet_getstring(argv, 0);
|
const uint8_t *fname = janet_getstring(argv, 0);
|
||||||
@ -305,13 +304,13 @@ static const JanetReg cfuns[] = {
|
|||||||
{
|
{
|
||||||
"file/open", janet_io_fopen,
|
"file/open", janet_io_fopen,
|
||||||
JDOC("(file/open path [,mode])\n\n"
|
JDOC("(file/open path [,mode])\n\n"
|
||||||
"Open a file. path is files absolute or relative path, and "
|
"Open a file. path is an absolute or relative path, and "
|
||||||
"mode is a set of flags indicating the mode to open the file in. "
|
"mode is a set of flags indicating the mode to open the file in. "
|
||||||
"mode is a keyword where each character represents a flag. If the file "
|
"mode is a keyword where each character represents a flag. If the file "
|
||||||
"cannot be opened, returns nil, otherwise returns the new file handle. "
|
"cannot be opened, returns nil, otherwise returns the new file handle. "
|
||||||
"Mode flags:\n\n"
|
"Mode flags:\n\n"
|
||||||
"\tr - allow reading from the file\n"
|
"\tr - allow reading from the file\n"
|
||||||
"\tw - allow witing to the file\n"
|
"\tw - allow writing to the file\n"
|
||||||
"\ta - append to the file\n"
|
"\ta - append to the file\n"
|
||||||
"\tb - open the file in binary mode (rather than text mode)\n"
|
"\tb - open the file in binary mode (rather than text mode)\n"
|
||||||
"\t+ - append to the file instead of overwriting it")
|
"\t+ - append to the file instead of overwriting it")
|
||||||
@ -327,7 +326,7 @@ static const JanetReg cfuns[] = {
|
|||||||
"file/read", janet_io_fread,
|
"file/read", janet_io_fread,
|
||||||
JDOC("(file/read f what [,buf])\n\n"
|
JDOC("(file/read f what [,buf])\n\n"
|
||||||
"Read a number of bytes from a file into a buffer. A buffer can "
|
"Read a number of bytes from a file into a buffer. A buffer can "
|
||||||
"be provided as an optional fourth argument. otherwise a new buffer "
|
"be provided as an optional fourth argument, otherwise a new buffer "
|
||||||
"is created. 'what' can either be an integer or a keyword. Returns the "
|
"is created. 'what' can either be an integer or a keyword. Returns the "
|
||||||
"buffer with file contents. "
|
"buffer with file contents. "
|
||||||
"Values for 'what':\n\n"
|
"Values for 'what':\n\n"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -610,7 +610,7 @@ static const uint8_t *unmarshal_one_env(
|
|||||||
data = unmarshal_one(st, data, &fiberv, flags);
|
data = unmarshal_one(st, data, &fiberv, flags);
|
||||||
if (!janet_checktype(fiberv, JANET_FIBER)) longjmp(st->err, UMR_EXPECTED_FIBER);
|
if (!janet_checktype(fiberv, JANET_FIBER)) longjmp(st->err, UMR_EXPECTED_FIBER);
|
||||||
env->as.fiber = janet_unwrap_fiber(fiberv);
|
env->as.fiber = janet_unwrap_fiber(fiberv);
|
||||||
/* Unmarshaling fiber may set values */
|
/* Unmarshalling fiber may set values */
|
||||||
if (env->offset != 0 && env->offset != offset) longjmp(st->err, UMR_UNKNOWN);
|
if (env->offset != 0 && env->offset != offset) longjmp(st->err, UMR_UNKNOWN);
|
||||||
if (env->length != 0 && env->length != length) longjmp(st->err, UMR_UNKNOWN);
|
if (env->length != 0 && env->length != length) longjmp(st->err, UMR_UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
@ -645,7 +645,7 @@ static const uint8_t *unmarshal_one_def(
|
|||||||
*out = st->lookup_defs[index];
|
*out = st->lookup_defs[index];
|
||||||
} else {
|
} else {
|
||||||
/* Initialize with values that will not break garbage collection
|
/* Initialize with values that will not break garbage collection
|
||||||
* if unmarshaling fails. */
|
* if unmarshalling fails. */
|
||||||
JanetFuncDef *def = janet_gcalloc(JANET_MEMORY_FUNCDEF, sizeof(JanetFuncDef));
|
JanetFuncDef *def = janet_gcalloc(JANET_MEMORY_FUNCDEF, sizeof(JanetFuncDef));
|
||||||
def->environments_length = 0;
|
def->environments_length = 0;
|
||||||
def->defs_length = 0;
|
def->defs_length = 0;
|
||||||
@ -786,7 +786,7 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
fiber->data = NULL;
|
fiber->data = NULL;
|
||||||
fiber->child = NULL;
|
fiber->child = NULL;
|
||||||
|
|
||||||
/* Set frame later so fiber can be GCed at anytime if unmarshaling fails */
|
/* Set frame later so fiber can be GCed at anytime if unmarshalling fails */
|
||||||
int32_t frame = 0;
|
int32_t frame = 0;
|
||||||
int32_t stack = 0;
|
int32_t stack = 0;
|
||||||
int32_t stacktop = 0;
|
int32_t stacktop = 0;
|
||||||
@ -802,7 +802,6 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
if ((int32_t)(frame + JANET_FRAME_SIZE) > fiber->stackstart ||
|
if ((int32_t)(frame + JANET_FRAME_SIZE) > fiber->stackstart ||
|
||||||
fiber->stackstart > fiber->stacktop ||
|
fiber->stackstart > fiber->stacktop ||
|
||||||
fiber->stacktop > fiber->maxstack) {
|
fiber->stacktop > fiber->maxstack) {
|
||||||
/* printf("bad flags and ints.\n"); */
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,7 +831,6 @@ static const uint8_t *unmarshal_one_fiber(
|
|||||||
Janet funcv;
|
Janet funcv;
|
||||||
data = unmarshal_one(st, data, &funcv, flags + 1);
|
data = unmarshal_one(st, data, &funcv, flags + 1);
|
||||||
if (!janet_checktype(funcv, JANET_FUNCTION)) {
|
if (!janet_checktype(funcv, JANET_FUNCTION)) {
|
||||||
/* printf("bad root func.\n"); */
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
func = janet_unwrap_function(funcv);
|
func = janet_unwrap_function(funcv);
|
||||||
@ -1154,20 +1152,20 @@ static const JanetReg cfuns[] = {
|
|||||||
"can the later be unmarshalled to reconstruct the initial value. "
|
"can the later be unmarshalled to reconstruct the initial value. "
|
||||||
"Optionally, one can pass in a reverse lookup table to not marshal "
|
"Optionally, one can pass in a reverse lookup table to not marshal "
|
||||||
"aliased values that are found in the table. Then a forward"
|
"aliased values that are found in the table. Then a forward"
|
||||||
"lookup table can be used to recover the origrinal janet value when "
|
"lookup table can be used to recover the original janet value when "
|
||||||
"unmarshaling.")
|
"unmarshalling.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"unmarshal", cfun_unmarshal,
|
"unmarshal", cfun_unmarshal,
|
||||||
JDOC("(unmarshal buffer [,lookup])\n\n"
|
JDOC("(unmarshal buffer [,lookup])\n\n"
|
||||||
"Unmarshal a janet value from a buffer. An optional lookup table "
|
"Unmarshal a janet value from a buffer. An optional lookup table "
|
||||||
"can be provided to allow for aliases to be resolved. Returns the value "
|
"can be provided to allow for aliases to be resolved. Returns the value "
|
||||||
"unmarshaled from the buffer.")
|
"unmarshalled from the buffer.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"env-lookup", cfun_env_lookup,
|
"env-lookup", cfun_env_lookup,
|
||||||
JDOC("(env-lookup env)\n\n"
|
JDOC("(env-lookup env)\n\n"
|
||||||
"Creates a forward lookup table for unmarshaling from an environment. "
|
"Creates a forward lookup table for unmarshalling from an environment. "
|
||||||
"To create a reverse lookup table, use the invert function to swap keys "
|
"To create a reverse lookup table, use the invert function to swap keys "
|
||||||
"and values in the returned table.")
|
"and values in the returned table.")
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -95,12 +95,12 @@ static const JanetReg cfuns[] = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"not", janet_not,
|
"not", janet_not,
|
||||||
JDOC("(not x)\n\nReturns the boolen inverse of x.")
|
JDOC("(not x)\n\nReturns the boolean inverse of x.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"math/random", janet_rand,
|
"math/random", janet_rand,
|
||||||
JDOC("(math/random)\n\n"
|
JDOC("(math/random)\n\n"
|
||||||
"Returns a uniformly distrbuted random number between 0 and 1.")
|
"Returns a uniformly distributed random number between 0 and 1.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"math/seedrandom", janet_srand,
|
"math/seedrandom", janet_srand,
|
||||||
@ -179,10 +179,12 @@ static const JanetReg cfuns[] = {
|
|||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_math(JanetTable *env) {
|
void janet_lib_math(JanetTable *env) {
|
||||||
janet_cfuns(env, NULL, cfuns);
|
janet_cfuns(env, NULL, cfuns);
|
||||||
|
#ifndef JANET_NO_BOOTSTRAP
|
||||||
janet_def(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
janet_def(env, "math/pi", janet_wrap_number(3.1415926535897931),
|
||||||
JDOC("The value pi."));
|
JDOC("The value pi."));
|
||||||
janet_def(env, "math/e", janet_wrap_number(2.7182818284590451),
|
janet_def(env, "math/e", janet_wrap_number(2.7182818284590451),
|
||||||
JDOC("The base of the natural log."));
|
JDOC("The base of the natural log."));
|
||||||
janet_def(env, "math/inf", janet_wrap_number(INFINITY),
|
janet_def(env, "math/inf", janet_wrap_number(INFINITY),
|
||||||
JDOC("The number representing positive infinity"));
|
JDOC("The number representing positive infinity"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -75,7 +75,7 @@ static int valid_utf8(const uint8_t *str, int32_t len) {
|
|||||||
if ((str[j] >> 6) != 2) return 0;
|
if ((str[j] >> 6) != 2) return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for overlong encodings */
|
/* Check for overlong encoding */
|
||||||
if ((nexti == i + 2) && str[i] < 0xC2) return 0;
|
if ((nexti == i + 2) && str[i] < 0xC2) return 0;
|
||||||
if ((str[i] == 0xE0) && str[i + 1] < 0xA0) return 0;
|
if ((str[i] == 0xE0) && str[i + 1] < 0xA0) return 0;
|
||||||
if ((str[i] == 0xF0) && str[i + 1] < 0x90) return 0;
|
if ((str[i] == 0xF0) && str[i + 1] < 0x90) return 0;
|
||||||
@ -308,7 +308,7 @@ static int tokenchar(JanetParser *p, JanetParseState *state, uint8_t c) {
|
|||||||
p->error = "symbol literal cannot start with a digit";
|
p->error = "symbol literal cannot start with a digit";
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* Don't do full utf8 check unless we have seen non ascii characters. */
|
/* Don't do full utf-8 check unless we have seen non ascii characters. */
|
||||||
int valid = (!state->argn) || valid_utf8(p->buf, blen);
|
int valid = (!state->argn) || valid_utf8(p->buf, blen);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
p->error = "invalid utf-8 in symbol";
|
p->error = "invalid utf-8 in symbol";
|
||||||
@ -777,7 +777,7 @@ static const JanetReg cfuns[] = {
|
|||||||
{
|
{
|
||||||
"parser/error", cfun_error,
|
"parser/error", cfun_error,
|
||||||
JDOC("(parser/error parser)\n\n"
|
JDOC("(parser/error parser)\n\n"
|
||||||
"If the parser is in the error state, returns the message asscoiated with "
|
"If the parser is in the error state, returns the message associated with "
|
||||||
"that error. Otherwise, returns nil. Also flushes the parser state and parser "
|
"that error. Otherwise, returns nil. Also flushes the parser state and parser "
|
||||||
"queue, so be sure to handle everything in the queue before calling "
|
"queue, so be sure to handle everything in the queue before calling "
|
||||||
"parser/error.")
|
"parser/error.")
|
||||||
@ -804,14 +804,14 @@ static const JanetReg cfuns[] = {
|
|||||||
"Returns a string representation of the internal state of the parser. "
|
"Returns a string representation of the internal state of the parser. "
|
||||||
"Each byte in the string represents a nested data structure. For example, "
|
"Each byte in the string represents a nested data structure. For example, "
|
||||||
"if the parser state is '([\"', then the parser is in the middle of parsing a "
|
"if the parser state is '([\"', then the parser is in the middle of parsing a "
|
||||||
"string inside of square brackets inside parens. Can be used to augment a repl prompt.")
|
"string inside of square brackets inside parentheses. Can be used to augment a REPL prompt.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parser/where", cfun_where,
|
"parser/where", cfun_where,
|
||||||
JDOC("(parser/where parser)\n\n"
|
JDOC("(parser/where parser)\n\n"
|
||||||
"Returns the current line number and column number of the parser's location "
|
"Returns the current line number and column number of the parser's location "
|
||||||
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
"in the byte stream as a tuple (line, column). Lines and columns are counted from "
|
||||||
"1, (the first byte is line1, column 1) and a newline is considered ascii 0x0A.")
|
"1, (the first byte is line 1, column 1) and a newline is considered ASCII 0x0A.")
|
||||||
},
|
},
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -57,7 +57,7 @@ static int32_t count_trailing_ones(uint32_t x) {
|
|||||||
/* Get N bits */
|
/* Get N bits */
|
||||||
#define nbits(N) (ithbit(N) - 1)
|
#define nbits(N) (ithbit(N) - 1)
|
||||||
|
|
||||||
/* Copy a regsiter allocator */
|
/* Copy a register allocator */
|
||||||
void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocator *src) {
|
void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocator *src) {
|
||||||
size_t size;
|
size_t size;
|
||||||
dest->count = src->count;
|
dest->count = src->count;
|
||||||
@ -153,78 +153,3 @@ void janetc_regalloc_freetemp(JanetcRegisterAllocator *ra, int32_t reg, JanetcRe
|
|||||||
if (reg < 0xF0)
|
if (reg < 0xF0)
|
||||||
janetc_regalloc_free(ra, reg);
|
janetc_regalloc_free(ra, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable multi-slot allocation for now. */
|
|
||||||
|
|
||||||
/*
|
|
||||||
static int32_t checkrange(JanetcRegisterAllocator *ra, int32_t start, int32_t end) {
|
|
||||||
int32_t startchunk = start / 32;
|
|
||||||
int32_t endchunk = end / 32;
|
|
||||||
for (int32_t chunk = startchunk; chunk <= endchunk; chunk++) {
|
|
||||||
while (ra->count <= chunk) pushchunk(ra);
|
|
||||||
uint32_t mask = 0xFFFFFFFF;
|
|
||||||
if (chunk == startchunk)
|
|
||||||
mask &= ~nbits(start & 0x1F);
|
|
||||||
if (chunk == endchunk)
|
|
||||||
mask &= nbits(end & 0x1F);
|
|
||||||
uint32_t block = ra->chunks[chunk];
|
|
||||||
uint32_t masking = mask & block;
|
|
||||||
if (masking) {
|
|
||||||
int32_t nextbit = (block == 0xFFFFFFFF)
|
|
||||||
? 32
|
|
||||||
: count_trailing_zeros(masking) + 1;
|
|
||||||
return chunk * 32 + nextbit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void markrange(JanetcRegisterAllocator *ra, int32_t start, int32_t end) {
|
|
||||||
int32_t startchunk = start / 32;
|
|
||||||
int32_t endchunk = end / 32;
|
|
||||||
for (int32_t chunk = startchunk; chunk <= endchunk; chunk++) {
|
|
||||||
uint32_t mask = 0xFFFFFFFF;
|
|
||||||
if (chunk == startchunk)
|
|
||||||
mask &= ~nbits(start & 0x1F);
|
|
||||||
if (chunk == endchunk)
|
|
||||||
mask &= nbits(end & 0x1F);
|
|
||||||
ra->chunks[chunk] |= mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void janetc_regalloc_freerange(JanetcRegisterAllocator *ra, int32_t start, int32_t n) {
|
|
||||||
int32_t end = start + n - 1;
|
|
||||||
int32_t startchunk = start / 32;
|
|
||||||
int32_t endchunk = end / 32;
|
|
||||||
for (int32_t chunk = startchunk; chunk <= endchunk; chunk++) {
|
|
||||||
uint32_t mask = 0;
|
|
||||||
if (chunk == startchunk)
|
|
||||||
mask |= nbits(start & 0x1F);
|
|
||||||
if (chunk == endchunk)
|
|
||||||
mask |= ~nbits(end & 0x1F);
|
|
||||||
ra->chunks[chunk] &= mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t janetc_regalloc_n(JanetcRegisterAllocator *ra, int32_t n) {
|
|
||||||
int32_t start = 0, end = 0, next = 0;
|
|
||||||
while (next >= 0) {
|
|
||||||
start = next;
|
|
||||||
end = start + n - 1;
|
|
||||||
next = checkrange(ra, start, end);
|
|
||||||
}
|
|
||||||
markrange(ra, start, end);
|
|
||||||
if (end > ra->max)
|
|
||||||
ra->max = end;
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t janetc_regalloc_call(JanetcRegisterAllocator *ra, int32_t callee, int32_t nargs) {
|
|
||||||
if (checkrange(ra, callee, callee + nargs) < 0) {
|
|
||||||
markrange(ra, callee + 1, callee + nargs);
|
|
||||||
return callee;
|
|
||||||
}
|
|
||||||
return janetc_regalloc_n(ra, nargs + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -44,7 +44,7 @@ typedef struct {
|
|||||||
int32_t count; /* number of chunks in chunks */
|
int32_t count; /* number of chunks in chunks */
|
||||||
int32_t capacity; /* amount allocated for chunks */
|
int32_t capacity; /* amount allocated for chunks */
|
||||||
int32_t max; /* The maximum allocated register so far */
|
int32_t max; /* The maximum allocated register so far */
|
||||||
int32_t regtemps; /* Hold which tempregistered are alloced. */
|
int32_t regtemps; /* Hold which temp. registers are allocated. */
|
||||||
} JanetcRegisterAllocator;
|
} JanetcRegisterAllocator;
|
||||||
|
|
||||||
void janetc_regalloc_init(JanetcRegisterAllocator *ra);
|
void janetc_regalloc_init(JanetcRegisterAllocator *ra);
|
||||||
@ -57,11 +57,4 @@ void janetc_regalloc_freetemp(JanetcRegisterAllocator *ra, int32_t reg, JanetcRe
|
|||||||
void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocator *src);
|
void janetc_regalloc_clone(JanetcRegisterAllocator *dest, JanetcRegisterAllocator *src);
|
||||||
void janetc_regalloc_touch(JanetcRegisterAllocator *ra, int32_t reg);
|
void janetc_regalloc_touch(JanetcRegisterAllocator *ra, int32_t reg);
|
||||||
|
|
||||||
/* Mutli-slot allocation disabled */
|
|
||||||
/*
|
|
||||||
int32_t janetc_regalloc_n(JanetcRegisterAllocator *ra, int32_t n);
|
|
||||||
int32_t janetc_regalloc_call(JanetcRegisterAllocator *ra, int32_t callee, int32_t nargs);
|
|
||||||
void janetc_regalloc_freerange(JanetcRegisterAllocator *ra, int32_t regstart, int32_t n);
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -511,7 +511,7 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv)
|
|||||||
/* Recompile in the function scope */
|
/* Recompile in the function scope */
|
||||||
cond = janetc_value(subopts, argv[0]);
|
cond = janetc_value(subopts, argv[0]);
|
||||||
if (!(cond.flags & JANET_SLOT_CONSTANT)) {
|
if (!(cond.flags & JANET_SLOT_CONSTANT)) {
|
||||||
/* If not an infinte loop, return nil when condition false */
|
/* If not an infinite loop, return nil when condition false */
|
||||||
janetc_emit_si(c, JOP_JUMP_IF, cond, 2, 0);
|
janetc_emit_si(c, JOP_JUMP_IF, cond, 2, 0);
|
||||||
janetc_emit(c, JOP_RETURN_NIL);
|
janetc_emit(c, JOP_RETURN_NIL);
|
||||||
}
|
}
|
||||||
@ -536,7 +536,7 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv)
|
|||||||
return janetc_cslot(janet_wrap_nil());
|
return janetc_cslot(janet_wrap_nil());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compile jump to whiletop */
|
/* Compile jump to :whiletop */
|
||||||
labeljt = janet_v_count(c->buffer);
|
labeljt = janet_v_count(c->buffer);
|
||||||
janetc_emit(c, JOP_JUMP);
|
janetc_emit(c, JOP_JUMP);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -27,10 +27,10 @@
|
|||||||
|
|
||||||
/* The VM state. Rather than a struct that is passed
|
/* The VM state. Rather than a struct that is passed
|
||||||
* around, the vm state is global for simplicity. If
|
* around, the vm state is global for simplicity. If
|
||||||
* at some point a a global state object, or context,
|
* at some point a global state object, or context,
|
||||||
* is required to be passed around, this is waht would
|
* is required to be passed around, this is what would
|
||||||
* be in it. However, thread local globals for interpreter
|
* be in it. However, thread local global variables for interpreter
|
||||||
* state should allow easy multithreading. */
|
* state should allow easy multi-threading. */
|
||||||
|
|
||||||
/* How many VM stacks have been entered */
|
/* How many VM stacks have been entered */
|
||||||
extern JANET_THREAD_LOCAL int janet_vm_stackn;
|
extern JANET_THREAD_LOCAL int janet_vm_stackn;
|
||||||
@ -39,7 +39,7 @@ extern JANET_THREAD_LOCAL int janet_vm_stackn;
|
|||||||
* Set and unset by janet_run. */
|
* Set and unset by janet_run. */
|
||||||
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber;
|
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber;
|
||||||
|
|
||||||
/* The global registry for c functions. Used to store metadata
|
/* The global registry for c functions. Used to store meta-data
|
||||||
* along with otherwise bare c function pointers. */
|
* along with otherwise bare c function pointers. */
|
||||||
extern JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
extern JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -1070,14 +1070,14 @@ static const JanetReg cfuns[] = {
|
|||||||
"string/ascii-lower", cfun_asciilower,
|
"string/ascii-lower", cfun_asciilower,
|
||||||
JDOC("(string/ascii-lower str)\n\n"
|
JDOC("(string/ascii-lower str)\n\n"
|
||||||
"Returns a new string where all bytes are replaced with the "
|
"Returns a new string where all bytes are replaced with the "
|
||||||
"lowercase version of themselves in ascii. Does only a very simple "
|
"lowercase version of themselves in ASCII. Does only a very simple "
|
||||||
"case check, meaning no unicode support.")
|
"case check, meaning no unicode support.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"string/ascii-upper", cfun_asciiupper,
|
"string/ascii-upper", cfun_asciiupper,
|
||||||
JDOC("(string/ascii-upper str)\n\n"
|
JDOC("(string/ascii-upper str)\n\n"
|
||||||
"Returns a new string where all bytes are replaced with the "
|
"Returns a new string where all bytes are replaced with the "
|
||||||
"uppercase version of themselves in ascii. Does only a very simple "
|
"uppercase version of themselves in ASCII. Does only a very simple "
|
||||||
"case check, meaning no unicode support.")
|
"case check, meaning no unicode support.")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -21,23 +21,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Use a custom double parser instead of libc's strtod for better portability
|
/* Use a custom double parser instead of libc's strtod for better portability
|
||||||
* and control. Also, uses a less strict rounding method than ieee to not incur
|
* and control.
|
||||||
* the cost of 4000 loc and dependence on arbitary precision arithmetic. Includes
|
|
||||||
* subset of multiple precision functionality needed for correct rounding.
|
|
||||||
*
|
*
|
||||||
* This version has been modified for much greater flexibility in parsing, such
|
* This version has been modified for much greater flexibility in parsing, such
|
||||||
* as choosing the radix and supporting scientific notation with any radix.
|
* as choosing the radix and supporting scientific notation with any radix.
|
||||||
*
|
*
|
||||||
* Numbers are of the form [-+]R[rR]I.F[eE&][-+]X where R is the radix, I is
|
* Numbers are of the form [-+]R[rR]I.F[eE&][-+]X where R is the radix, I is
|
||||||
* the integer part, F is the fractional part, and X is the exponent. All
|
* the integer part, F is the fractional part, and X is the exponent. All
|
||||||
* signs, radix, decimal point, fractional part, and exponent can be ommited.
|
* signs, radix, decimal point, fractional part, and exponent can be omitted.
|
||||||
* The number will be considered and integer if the there is no decimal point
|
* The number will be considered and integer if the there is no decimal point
|
||||||
* and no exponent. Any number greater the 2^32-1 or less than -(2^32) will be
|
* and no exponent. Any number greater the 2^32-1 or less than -(2^32) will be
|
||||||
* coerced to a double. If there is an error, the function janet_scan_number will
|
* coerced to a double. If there is an error, the function janet_scan_number will
|
||||||
* return a janet nil. The radix is assumed to be 10 if omitted, and the E
|
* return a janet nil. The radix is assumed to be 10 if omitted, and the E
|
||||||
* separator for the exponent can only be used when the radix is 10. This is
|
* separator for the exponent can only be used when the radix is 10. This is
|
||||||
* because E is a vaid digit in bases 15 or greater. For bases greater than 10,
|
* because E is a valid digit in bases 15 or greater. For bases greater than 10,
|
||||||
* the letters are used as digitis. A through Z correspond to the digits 10
|
* the letters are used as digits. A through Z correspond to the digits 10
|
||||||
* through 35, and the lowercase letters have the same values. The radix number
|
* through 35, and the lowercase letters have the same values. The radix number
|
||||||
* is always in base 10. For example, a hexidecimal number could be written
|
* is always in base 10. For example, a hexidecimal number could be written
|
||||||
* '16rdeadbeef'. janet_scan_number also supports some c style syntax for
|
* '16rdeadbeef'. janet_scan_number also supports some c style syntax for
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -62,7 +62,7 @@ const JanetKV *janet_struct_find(const JanetKV *st, Janet key) {
|
|||||||
*
|
*
|
||||||
* Runs will be in sorted order, as the collisions resolver essentially
|
* Runs will be in sorted order, as the collisions resolver essentially
|
||||||
* preforms an in-place insertion sort. This ensures the internal structure of the
|
* preforms an in-place insertion sort. This ensures the internal structure of the
|
||||||
* hash map is independant of insertion order.
|
* hash map is independent of insertion order.
|
||||||
*/
|
*/
|
||||||
void janet_struct_put(JanetKV *st, Janet key, Janet value) {
|
void janet_struct_put(JanetKV *st, Janet key, Janet value) {
|
||||||
int32_t cap = janet_struct_capacity(st);
|
int32_t cap = janet_struct_capacity(st);
|
||||||
@ -89,7 +89,7 @@ void janet_struct_put(JanetKV *st, Janet key, Janet value) {
|
|||||||
}
|
}
|
||||||
/* Robinhood hashing - check if colliding kv pair
|
/* Robinhood hashing - check if colliding kv pair
|
||||||
* is closer to their source than current. We use robinhood
|
* is closer to their source than current. We use robinhood
|
||||||
* hashing to ensure that equivalent structs that are contsructed
|
* hashing to ensure that equivalent structs that are constructed
|
||||||
* with different order have the same internal layout, and therefor
|
* with different order have the same internal layout, and therefor
|
||||||
* will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}.
|
* will compare properly - i.e., {1 2 3 4} should equal {3 4 1 2}.
|
||||||
* Collisions are resolved via an insertion sort insertion. */
|
* Collisions are resolved via an insertion sort insertion. */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -133,7 +133,7 @@ int32_t janet_tablen(int32_t n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to find a value in a Janet struct or table. Returns the bucket
|
/* Helper to find a value in a Janet struct or table. Returns the bucket
|
||||||
* containg the key, or the first empty bucket if there is no such key. */
|
* containing the key, or the first empty bucket if there is no such key. */
|
||||||
const JanetKV *janet_dict_find(const JanetKV *buckets, int32_t cap, Janet key) {
|
const JanetKV *janet_dict_find(const JanetKV *buckets, int32_t cap, Janet key) {
|
||||||
int32_t index = janet_maphash(cap, janet_hash(key));
|
int32_t index = janet_maphash(cap, janet_hash(key));
|
||||||
int32_t i;
|
int32_t i;
|
||||||
@ -188,7 +188,7 @@ const JanetKV *janet_dictionary_next(const JanetKV *kvs, int32_t cap, const Jane
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare a janet string with a cstring. more efficient than loading
|
/* Compare a janet string with a cstring. More efficient than loading
|
||||||
* c string as a janet string. */
|
* c string as a janet string. */
|
||||||
int janet_cstrcmp(const uint8_t *str, const char *other) {
|
int janet_cstrcmp(const uint8_t *str, const char *other) {
|
||||||
int32_t len = janet_string_length(str);
|
int32_t len = janet_string_length(str);
|
||||||
@ -205,7 +205,7 @@ int janet_cstrcmp(const uint8_t *str, const char *other) {
|
|||||||
|
|
||||||
/* Do a binary search on a static array of structs. Each struct must
|
/* Do a binary search on a static array of structs. Each struct must
|
||||||
* have a string as its first element, and the struct must be sorted
|
* have a string as its first element, and the struct must be sorted
|
||||||
* lexogrpahically by that element. */
|
* lexicographically by that element. */
|
||||||
const void *janet_strbinsearch(
|
const void *janet_strbinsearch(
|
||||||
const void *tab,
|
const void *tab,
|
||||||
size_t tabcount,
|
size_t tabcount,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -102,7 +102,7 @@ int32_t janet_hash(Janet x) {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compares x to y. If they are equal retuns 0. If x is less, returns -1.
|
/* Compares x to y. If they are equal returns 0. If x is less, returns -1.
|
||||||
* If y is less, returns 1. All types are comparable
|
* If y is less, returns 1. All types are comparable
|
||||||
* and should have strict ordering. */
|
* and should have strict ordering. */
|
||||||
int janet_compare(Janet x, Janet y) {
|
int janet_compare(Janet x, Janet y) {
|
||||||
@ -113,7 +113,7 @@ int janet_compare(Janet x, Janet y) {
|
|||||||
case JANET_TRUE:
|
case JANET_TRUE:
|
||||||
return 0;
|
return 0;
|
||||||
case JANET_NUMBER:
|
case JANET_NUMBER:
|
||||||
/* Check for nans to ensure total order */
|
/* Check for NaNs to ensure total order */
|
||||||
if (janet_unwrap_number(x) != janet_unwrap_number(x))
|
if (janet_unwrap_number(x) != janet_unwrap_number(x))
|
||||||
return janet_unwrap_number(y) != janet_unwrap_number(y)
|
return janet_unwrap_number(y) != janet_unwrap_number(y)
|
||||||
? 0
|
? 0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -32,7 +32,7 @@ JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
|||||||
JANET_THREAD_LOCAL int janet_vm_stackn = 0;
|
JANET_THREAD_LOCAL int janet_vm_stackn = 0;
|
||||||
JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber = NULL;
|
JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber = NULL;
|
||||||
|
|
||||||
/* Virtual regsiters
|
/* Virtual registers
|
||||||
*
|
*
|
||||||
* One instruction word
|
* One instruction word
|
||||||
* CC | BB | AA | OP
|
* CC | BB | AA | OP
|
||||||
@ -266,7 +266,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
: (*pc & 0xFF);
|
: (*pc & 0xFF);
|
||||||
|
|
||||||
/* Main interpreter loop. Semantically is a switch on
|
/* Main interpreter loop. Semantically is a switch on
|
||||||
* (*pc & 0xFF) inside of an infinte loop. */
|
* (*pc & 0xFF) inside of an infinite loop. */
|
||||||
VM_START();
|
VM_START();
|
||||||
|
|
||||||
VM_DEFAULT();
|
VM_DEFAULT();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -113,7 +113,7 @@ extern "C" {
|
|||||||
#define JANET_THREAD_LOCAL
|
#define JANET_THREAD_LOCAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Enable or disbale dynamic module loading. Enabled by default. */
|
/* Enable or disable dynamic module loading. Enabled by default. */
|
||||||
#ifndef JANET_NO_DYNAMIC_MODULES
|
#ifndef JANET_NO_DYNAMIC_MODULES
|
||||||
#define JANET_DYNAMIC_MODULES
|
#define JANET_DYNAMIC_MODULES
|
||||||
#endif
|
#endif
|
||||||
@ -326,7 +326,7 @@ typedef enum JanetType {
|
|||||||
#define JANET_TFLAG_FUNCLIKE (JANET_TFLAG_CALLABLE | JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY | \
|
#define JANET_TFLAG_FUNCLIKE (JANET_TFLAG_CALLABLE | JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY | \
|
||||||
JANET_TFLAG_KEYWORD | JANET_TFLAG_SYMBOL)
|
JANET_TFLAG_KEYWORD | JANET_TFLAG_SYMBOL)
|
||||||
|
|
||||||
/* We provide three possible implemenations of Janets. The preferred
|
/* We provide three possible implementations of Janets. The preferred
|
||||||
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
||||||
* application must interact through exposed interface. */
|
* application must interact through exposed interface. */
|
||||||
|
|
||||||
@ -385,7 +385,6 @@ JANET_API Janet janet_nanbox_from_cpointer(const void *p, uint64_t tagmask);
|
|||||||
JANET_API Janet janet_nanbox_from_double(double d);
|
JANET_API Janet janet_nanbox_from_double(double d);
|
||||||
JANET_API Janet janet_nanbox_from_bits(uint64_t bits);
|
JANET_API Janet janet_nanbox_from_bits(uint64_t bits);
|
||||||
|
|
||||||
/* Todo - check for single mask operation */
|
|
||||||
#define janet_truthy(x) \
|
#define janet_truthy(x) \
|
||||||
(!(janet_checktype((x), JANET_NIL) || janet_checktype((x), JANET_FALSE)))
|
(!(janet_checktype((x), JANET_NIL) || janet_checktype((x), JANET_FALSE)))
|
||||||
|
|
||||||
@ -656,7 +655,7 @@ struct JanetKV {
|
|||||||
Janet value;
|
Janet value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Some function defintion flags */
|
/* Some function definition flags */
|
||||||
#define JANET_FUNCDEF_FLAG_VARARG 0x10000
|
#define JANET_FUNCDEF_FLAG_VARARG 0x10000
|
||||||
#define JANET_FUNCDEF_FLAG_NEEDSENV 0x20000
|
#define JANET_FUNCDEF_FLAG_NEEDSENV 0x20000
|
||||||
#define JANET_FUNCDEF_FLAG_FIXARITY 0x40000
|
#define JANET_FUNCDEF_FLAG_FIXARITY 0x40000
|
||||||
@ -694,7 +693,7 @@ struct JanetFuncDef {
|
|||||||
int32_t defs_length;
|
int32_t defs_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* A fuction environment */
|
/* A function environment */
|
||||||
struct JanetFuncEnv {
|
struct JanetFuncEnv {
|
||||||
union {
|
union {
|
||||||
JanetFiber *fiber;
|
JanetFiber *fiber;
|
||||||
@ -744,7 +743,7 @@ struct JanetAbstractType {
|
|||||||
int (*gcmark)(void *data, size_t len);
|
int (*gcmark)(void *data, size_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Contains information about userdata */
|
/* Contains information about abstract types */
|
||||||
struct JanetAbstractHeader {
|
struct JanetAbstractHeader {
|
||||||
const JanetAbstractType *type;
|
const JanetAbstractType *type;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2017-2018 (C) Calvin Rose
|
# Copyright 2017-2019 (C) Calvin Rose
|
||||||
|
|
||||||
(do
|
(do
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@ -52,7 +52,7 @@ static int enter_loop(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allow JS interop from within janet */
|
/* Allow JS interoperation from within janet */
|
||||||
static Janet cfun_js(int32_t argc, Janet *argv) {
|
static Janet cfun_js(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
janet_fixarity(argc, 1);
|
||||||
JanetByteView bytes = janet_getbytes(argv, 0);
|
JanetByteView bytes = janet_getbytes(argv, 0);
|
||||||
@ -60,7 +60,7 @@ static Janet cfun_js(int32_t argc, Janet *argv) {
|
|||||||
return janet_wrap_nil();
|
return janet_wrap_nil();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Intialize the repl */
|
/* Initialize the repl */
|
||||||
EMSCRIPTEN_KEEPALIVE
|
EMSCRIPTEN_KEEPALIVE
|
||||||
void repl_init(void) {
|
void repl_init(void) {
|
||||||
int status;
|
int status;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# Copyright 2017-2018 (C) Calvin Rose
|
# Copyright 2017-2019 (C) Calvin Rose
|
||||||
|
|
||||||
(print (string "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
|
(print (string "Janet " janet/version "-" janet/build " Copyright (C) 2017-2018 Calvin Rose"))
|
||||||
|
|
||||||
(fiber/new (fn webrepl []
|
(fiber/new (fn webrepl []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2018 Calvin Rose
|
# Copyright (c) 2019 Calvin Rose
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
@ -79,7 +79,7 @@
|
|||||||
(assert (= "\e" "\x1B") "escape character")
|
(assert (= "\e" "\x1B") "escape character")
|
||||||
(assert (= "\x09" "\t") "tab character")
|
(assert (= "\x09" "\t") "tab character")
|
||||||
|
|
||||||
# Mcarthy's 91 function
|
# McCarthy's 91 function
|
||||||
(var f91 nil)
|
(var f91 nil)
|
||||||
(set f91 (fn [n] (if (> n 100) (- n 10) (f91 (f91 (+ n 11))))))
|
(set f91 (fn [n] (if (> n 100) (- n 10) (f91 (f91 (+ n 11))))))
|
||||||
(assert (= 91 (f91 10)) "f91(10) = 91")
|
(assert (= 91 (f91 10)) "f91(10) = 91")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Copyright (c) 2018 Calvin Rose
|
# Copyright (c) 2019 Calvin Rose
|
||||||
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
# deal in the Software without restriction, including without limitation the
|
# deal in the Software without restriction, including without limitation the
|
||||||
@ -238,7 +238,7 @@
|
|||||||
(def arr (array))
|
(def arr (array))
|
||||||
(array/push arr :hello)
|
(array/push arr :hello)
|
||||||
(array/push arr :world)
|
(array/push arr :world)
|
||||||
(assert (array= arr @[:hello :world]) "array comparision")
|
(assert (array= arr @[:hello :world]) "array comparison")
|
||||||
(assert (array= @[1 2 3 4 5] @[1 2 3 4 5]) "array comparison 2")
|
(assert (array= @[1 2 3 4 5] @[1 2 3 4 5]) "array comparison 2")
|
||||||
(assert (array= @[:one :two :three :four :five] @[:one :two :three :four :five]) "array comparison 3")
|
(assert (array= @[:one :two :three :four :five] @[:one :two :three :four :five]) "array comparison 3")
|
||||||
(assert (array= (array/slice @[1 2 3] 0 2) @[1 2]) "array/slice 1")
|
(assert (array= (array/slice @[1 2 3] 0 2) @[1 2]) "array/slice 1")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2018 Calvin Rose
|
# Copyright (c) 2019 Calvin Rose
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2018 Calvin Rose
|
# Copyright (c) 2019 Calvin Rose
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Tool to dump a marshalled version of the janet core to stdout. The
|
# Tool to dump a marshalled version of the janet core to stdout. The
|
||||||
# image should eventually allow janet to be started from a precompiled
|
# image should eventually allow janet to be started from a pre-compiled
|
||||||
# image rather than recompiled every time from the embedded source. More
|
# image rather than recompiled every time from the embedded source. More
|
||||||
# work will go into shrinking the image (it isn't currently that large but
|
# work will go into shrinking the image (it isn't currently that large but
|
||||||
# could be smaller), creating the mechanism to load the image, and modifying
|
# could be smaller), creating the mechanism to load the image, and modifying
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
# Get image. This image contains as much of the core library and documentation that
|
# Get image. This image contains as much of the core library and documentation that
|
||||||
# can be written to an image (no cfunctions, no abstracts (stdout, stdin, stderr)),
|
# can be written to an image (no cfunctions, no abstracts (stdout, stdin, stderr)),
|
||||||
# everyting else goes. Cfunctions and abstracts will be referenced from a register
|
# everything else goes. Cfunctions and abstracts will be referenced from a register
|
||||||
# table which will be generated on janet startup.
|
# table which will be generated on janet startup.
|
||||||
(def image (let [env-pairs (pairs (env-lookup _env))
|
(def image (let [env-pairs (pairs (env-lookup _env))
|
||||||
essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs)
|
essential-pairs (filter (fn [[k v]] (or (cfunction? v) (abstract? v))) env-pairs)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Calvin Rose
|
* Copyright (c) 2019 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
Loading…
Reference in New Issue
Block a user