Skip to content

Commit

Permalink
Merge pull request #409 from dictu-lang/develop
Browse files Browse the repository at this point in the history
Release 0.19.0
  • Loading branch information
Jason2605 authored Jun 26, 2021
2 parents c693873 + 44656eb commit a36dbea
Show file tree
Hide file tree
Showing 24 changed files with 548 additions and 100 deletions.
9 changes: 4 additions & 5 deletions Docker/DictuAlpineDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ FROM alpine

WORKDIR Dictu

RUN apk add make curl-dev gcc libc-dev cmake --no-cache
RUN apk add git make curl-dev gcc libc-dev cmake --no-cache

COPY CMakeLists.txt .
COPY src ./src/
COPY tests ./tests/
RUN git clone https://github.com/dictu-lang/Dictu.git

RUN cmake -DCMAKE_BUILD_TYPE=Release -B build \
RUN cd Dictu \
&& cmake -DCMAKE_BUILD_TYPE=Release -B build \
&& cmake --build ./build \
&& ./dictu tests/runTests.du \
&& cp dictu /usr/bin/ \
Expand Down
10 changes: 5 additions & 5 deletions Docker/DictuUbuntuDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& apt-get update \
&& apt-get install -y --no-install-recommends cmake libcurl4-gnutls-dev \
&& apt-get install -y --reinstall ca-certificates \
&& apt-get install -y --no-install-recommends git cmake libcurl4-gnutls-dev \
&& rm -rf /var/lib/apt/lists/*

COPY CMakeLists.txt .
COPY src ./src/
COPY tests ./tests/
RUN git clone https://github.com/dictu-lang/Dictu.git

RUN cmake -DCMAKE_BUILD_TYPE=Release -B build \
RUN cd Dictu \
&& cmake -DCMAKE_BUILD_TYPE=Release -B build \
&& cmake --build ./build \
&& ./dictu tests/runTests.du \
&& cp dictu /usr/bin/ \
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
color_scheme: "dictu" # Custom theme
logo: "/assets/images/dictu-logo/dictu-wordmark.svg"

version: "0.18.0"
version: "0.19.0"
github_username: dictu-lang
search_enabled: true

Expand Down
7 changes: 4 additions & 3 deletions docs/docs/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ myObject.printMessage(); // Some text!

## Attributes

Attributes in Dictu are instance attributes, and these attributes get defined either inside the methods or on the method directly. There is no concept of attribute access modifiers in python and attributes
are available directly from the object without the need for getters or setters.
Attributes in Dictu are instance attributes, and these attributes get defined either inside the methods or on the object directly.

```cs
class Test {
Expand All @@ -184,9 +183,11 @@ print(myObject.x); // 10

### hasAttribute

Attempting to access an attribute of an object that does not exist will throw a runtime error, and instead before accessing, you should check
Attempting to access an attribute of an object that does not exist will throw a runtime error, and instead before accessing an attribute that may not be there, you should check
if the object has the given attribute. This is done via `hasAttribute`.

Note: Will only check properties with public visibility.

```cs
class Test {
init() {
Expand Down
1 change: 1 addition & 0 deletions docs/docs/standard-lib/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parent: Standard Library
|-----------------|---------------------------------------------------------------------------------------------------|
| System.argv | The list of command line arguments. The first element of the argv list is always the script name. |
| System.platform | This string identifies the underlying system platform. |
| System.version | Dictionary containing Dictu major, minor and patch versions. |
| System.S_IRWXU | Read, write, and execute by owner. |
| System.S_IRUSR | Read by owner. |
| System.S_IWUSR | Write by owner. |
Expand Down
2 changes: 1 addition & 1 deletion src/include/dictu_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdbool.h>

#define DICTU_MAJOR_VERSION "0"
#define DICTU_MINOR_VERSION "18"
#define DICTU_MINOR_VERSION "19"
#define DICTU_PATCH_VERSION "0"

#define DICTU_STRING_VERSION "Dictu Version: " DICTU_MAJOR_VERSION "." DICTU_MINOR_VERSION "." DICTU_PATCH_VERSION "\n"
Expand Down
4 changes: 3 additions & 1 deletion src/optionals/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ static Value executeReturnOutput(DictuVM* vm, ObjList* argList) {
arguments[argList->values.count] = NULL;

int fd[2];
pipe(fd);
if (pipe(fd) != 0) {
ERROR_RESULT;
}
pid_t pid = fork();
if (pid == 0) {
close(fd[0]);
Expand Down
39 changes: 10 additions & 29 deletions src/optionals/random.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "random.h"

static Value randomRandom(DictuVM *vm, int argCount, Value *args)
{
static Value randomRandom(DictuVM *vm, int argCount, Value *args) {
UNUSED(args);
if (argCount > 0)
{
if (argCount > 0) {
runtimeError(vm, "random() takes 0 arguments (%d given)", argCount);
return EMPTY_VAL;
}
Expand All @@ -15,16 +13,13 @@ static Value randomRandom(DictuVM *vm, int argCount, Value *args)
return NUMBER_VAL(random_double);
}

static Value randomRange(DictuVM *vm, int argCount, Value *args)
{
if (argCount != 2)
{
static Value randomRange(DictuVM *vm, int argCount, Value *args) {
if (argCount != 2) {
runtimeError(vm, "range() takes 2 arguments (%0d given)", argCount);
return EMPTY_VAL;
}

if (!IS_NUMBER(args[0]) || !IS_NUMBER(args[1]))
{
if (!IS_NUMBER(args[0]) || !IS_NUMBER(args[1])) {
runtimeError(vm, "range() arguments must be numbers");
return EMPTY_VAL;
}
Expand All @@ -35,16 +30,13 @@ static Value randomRange(DictuVM *vm, int argCount, Value *args)
return NUMBER_VAL(random_val);
}

static Value randomSelect(DictuVM *vm, int argCount, Value *args)
{
if (argCount == 0)
{
runtimeError(vm, "select() takes one argument (%0d provided)", argCount);
static Value randomSelect(DictuVM *vm, int argCount, Value *args) {
if (argCount != 1) {
runtimeError(vm, "select() takes one argument (%d provided)", argCount);
return EMPTY_VAL;
}

if (!IS_LIST(args[0]))
{
if (!IS_LIST(args[0])) {
runtimeError(vm, "select() argument must be a list");
return EMPTY_VAL;
}
Expand All @@ -53,22 +45,11 @@ static Value randomSelect(DictuVM *vm, int argCount, Value *args)
argCount = list->values.count;
args = list->values.values;

for (int i = 0; i < argCount; ++i)
{
Value value = args[i];
if (!IS_NUMBER(value))
{
runtimeError(vm, "A non-number value passed to select()");
return EMPTY_VAL;
}
}

int index = rand() % argCount;
return args[index];
}

ObjModule *createRandomModule(DictuVM *vm)
{
ObjModule *createRandomModule(DictuVM *vm) {
ObjString *name = copyString(vm, "Random", 6);
push(vm, OBJ_VAL(name));
ObjModule *module = newModule(vm, name);
Expand Down
34 changes: 34 additions & 0 deletions src/optionals/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,39 @@ void initPlatform(DictuVM *vm, Table *table) {
#endif
}

void setVersion(DictuVM *vm, Table *table) {
ObjDict *versionDict = newDict(vm);
push(vm, OBJ_VAL(versionDict));

ObjString *major = copyString(vm, "major", 5);
push(vm, OBJ_VAL(major));
ObjString *majorVersion = copyString(vm, DICTU_MAJOR_VERSION, strlen(DICTU_MAJOR_VERSION));
push(vm, OBJ_VAL(majorVersion));
dictSet(vm, versionDict, OBJ_VAL(major), OBJ_VAL(majorVersion));
pop(vm);
pop(vm);

ObjString *minor = copyString(vm, "minor", 5);
push(vm, OBJ_VAL(minor));
ObjString *minorVersion = copyString(vm, DICTU_MINOR_VERSION, strlen(DICTU_MINOR_VERSION));
push(vm, OBJ_VAL(minorVersion));
dictSet(vm, versionDict, OBJ_VAL(minor), OBJ_VAL(minorVersion));
pop(vm);
pop(vm);

ObjString *patch = copyString(vm, "patch", 5);
push(vm, OBJ_VAL(patch));
ObjString *patchVersion = copyString(vm, DICTU_PATCH_VERSION, strlen(DICTU_PATCH_VERSION));
push(vm, OBJ_VAL(patchVersion));
dictSet(vm, versionDict, OBJ_VAL(patch), OBJ_VAL(patchVersion));
pop(vm);
pop(vm);

defineNativeProperty(vm, table, "version", OBJ_VAL(versionDict));

pop(vm);
}

void createSystemModule(DictuVM *vm, int argc, char *argv[]) {
ObjString *name = copyString(vm, "System", 6);
push(vm, OBJ_VAL(name));
Expand Down Expand Up @@ -353,6 +386,7 @@ void createSystemModule(DictuVM *vm, int argc, char *argv[]) {
}

initPlatform(vm, &module->values);
setVersion(vm, &module->values);

defineNativeProperty(vm, &module->values, "S_IRWXU", NUMBER_VAL(448));
defineNativeProperty(vm, &module->values, "S_IRUSR", NUMBER_VAL(256));
Expand Down
22 changes: 14 additions & 8 deletions src/vm/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "compiler.h"
#include "memory.h"
#include "vm.h"
#include "error_lib/error.h"
#include "../optionals/optionals.h"

#ifdef DEBUG_PRINT_CODE
Expand All @@ -22,17 +23,22 @@ static void errorAt(Parser *parser, Token *token, const char *message) {
if (parser->panicMode) return;
parser->panicMode = true;

fprintf(stderr, "[%s line %d] Error", parser->module->name->chars, token->line);
log_error("File '%s', {bold}line %d{reset}", parser->module->name->chars, token->line);

if (token->type == TOKEN_EOF) {
fprintf(stderr, " at end");
} else if (token->type == TOKEN_ERROR) {
// Nothing.
} else {
fprintf(stderr, " at '%.*s'", token->length, token->start);
switch (token->type) {
case TOKEN_EOF:
log_padln("Error at end: %s", message);
break;
case TOKEN_ERROR:
log_padln("Error: %s", message);
break;
default:
log_padln("%zu %s %.*s", token->line, "|", token->length, token->start);
log_padln("%s", message);
break;
}

fprintf(stderr, ": %s\n", message);
fputc('\n', stderr);
parser->hadError = true;
}

Expand Down
21 changes: 21 additions & 0 deletions src/vm/error_lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Edward Bruce

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 the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions src/vm/error_lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Error lib

The error lib used to generate compile and runtime errors is from [https://github.com/cometodukey/tbd](https://github.com/cometodukey/tbd)
Loading

0 comments on commit a36dbea

Please sign in to comment.