Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmdln committed Oct 24, 2023
1 parent 3c29378 commit 04cff6f
Show file tree
Hide file tree
Showing 39 changed files with 669 additions and 795 deletions.
3 changes: 0 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
---
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
Expand Down
15 changes: 7 additions & 8 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
---
FormatStyle: file
HeaderFilterRegex: ""
Expand All @@ -9,26 +6,28 @@ InheritParentConfig: false
Checks: |
-*
bugprone-*
-bugprone-easily-swappable-parameters
cert-*-c
clang-analyzer-core
-clang-analyzer-core.uninitialized.NewArraySize
clang-analyzer-deadcode
clang-analyzer-nullability
clang-analyzer-security
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
clang-analyzer-unix
clang-analyzer-valist
misc-*
-misc-no-recursion
performance-*
portability-*
readability-*
-bugprone-branch-clone
-bugprone-easily-swappable-parameters
-clang-analyzer-core.uninitialized.NewArraySize
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
-misc-no-recursion
-readability-braces-around-statements
-readability-function-cognitive-complexity
-readability-identifier-length
-readability-magic-numbers
-readability-non-const-parameter
WarningsAsErrors: |
-*
Expand Down
3 changes: 0 additions & 3 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
---
CompileFlags:
CompilationDatabase: builddir
Expand Down
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

root = true

[*]
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
---
name: Test

Expand Down
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

# Ignore everything
*

Expand Down Expand Up @@ -43,9 +39,9 @@
!man/
!man/**

!src/
!src/**/
!src/**/*.c
!source/
!source/**/
!source/**/*.c

!test/
!test/**/
Expand Down
3 changes: 0 additions & 3 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C Maudlin <[email protected]>
---
options:
editorconfig: true
11 changes: 1 addition & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
"--header-insertion=never"
],

// Don't immediately pester the user on open of the project
"cmake.configureOnOpen": false,
// Stop focusing CMake logs
"cmake.revealLog": "never",

// Make Prettier the default formatter
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.insertSpaces": true,
Expand All @@ -27,14 +22,10 @@
"**/builddir/**": true
},

// mesonbuild: Don't pester about or download a random binary
// Don't pester about or download a random binary
"mesonbuild.downloadLanguageServer": false,
"mesonbuild.languageServer": null,

"mesonbuild.formatting.enabled": false,
"mesonbuild.linter.muon.enabled": true,
"mesonbuild.muonPath": "muon",

// Associate YAML schemas with targets
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": [
Expand Down
48 changes: 24 additions & 24 deletions include/ploy/core.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_CORE_H
#define PLOY_CORE_H
#pragma once

#include "type.h"

Object const *Append(Object const *target, Object const *object);
// Object const *Apply(Object const *object);
Object const *Car(Object const *object);
Object const *Cdr(Object const *object);
Object const *Cons(Object const *car, Object const *cdr);
// Object const *Define(Object const *env, Object const *symbol, Object const *value);
Object const *Eval(Object const *object);
// Object const *For(Object const *expr, Object const *body);
// Object const *Format(char const *form, ...);
// Object const *If(Object const *expr, Object const *body);
// Object const *Lambda(Object const *env, Object const *args, Object const *body);
// Object const *Let(Object const *env, Object const *args, Object const *body);
Object const *Print(Object const *object);
// Object const *Quasiquote(Object const *object);
// Object const *Quote(Object const *object);
Object const *Read(char const *input);
Object const *Reverse(Object const *object);
static Object *Nil = &(Object){ .type = NIL };
static Object *True = &(Object){ .type = NIL, .boolean = true };
static Object *False = &(Object){ .type = NIL, .boolean = false };

Object *Append(Object *target, Object *object);
Object *Apply(Object *object);
Object *Assert(bool condition);
Object *Car(Object *object);
Object *Cdr(Object *object);
Object *Cons(Object *car, Object *cdr);
Object *Define(Object *env, Object *args, Object *body);
Object *Error(char *error);
Object *Eval(Object *object);
Object *For(Object *expr, Object *body);
Object *Format(char *form, ...);
Object *If(Object *expr, Object *body);
Object *Lambda(Object *env, Object *args, Object *body);
Object *Let(Object *env, Object *args, Object *body);
Object *Print(Object *object);
Object *Read(char *input);
Object *Reverse(Object *object);

#endif // PLOY_CORE_H
Object *Number(int64_t i64);
Object *String(char *string);
Object *Symbol(char *symbol);
10 changes: 1 addition & 9 deletions include/ploy/evaluator.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_EVALUATOR_H
#define PLOY_EVALUATOR_H
#pragma once

#include "type.h"

Object const *evaluator(Object const *object);

#endif // PLOY_EVALUATOR_H
Object *evaluator(Object *object);
24 changes: 8 additions & 16 deletions include/ploy/math.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_MATH_H
#define PLOY_MATH_H
#pragma once

#include "type.h"
Expand All @@ -12,14 +6,12 @@
// Arithmetic
//

Object const *Add(Object const *object);
Object const *Subtract(Object const *object);
Object const *Multiply(Object const *object);
Object const *Divide(Object const *object);

Object const *Exponent(Object const *object);
Object const *Log(Object const *object);
Object const *Modulo(Object const *object);
Object const *NthRoot(Object const *object);
Object *Add(Object *object);
Object *Subtract(Object *object);
Object *Multiply(Object *object);
Object *Divide(Object *object);

#endif // PLOY_MATH_H
// Object *Exponent(Object *object);
// Object *Log(Object *object);
// Object *Modulo(Object *object);
// Object *NthRoot(Object *object);
10 changes: 1 addition & 9 deletions include/ploy/printer.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_PRINTER_H
#define PLOY_PRINTER_H
#pragma once

#include "type.h"

void printer(Object const *object);

#endif // PLOY_PRINTER_H
void printer(Object *object);
10 changes: 1 addition & 9 deletions include/ploy/reader.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_READER_H
#define PLOY_READER_H
#pragma once

#include "type.h"

Object const *reader(char const *input);

#endif // PLOY_READER_H
Object *reader(char *input);
70 changes: 28 additions & 42 deletions include/ploy/type.h
Original file line number Diff line number Diff line change
@@ -1,50 +1,36 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C Maudlin <[email protected]>

#ifndef PLOY_TYPE_H
#define PLOY_TYPE_H
#pragma once

#include <math.h>
#include <stdbool.h>
#include <stdint.h>

typedef enum Type {
TYPE_NIL = 0,
TYPE_BOOLEAN,
TYPE_ERROR,
// TYPE_LAMBDA,
TYPE_LIST,
TYPE_NUMBER,
TYPE_STRING,
TYPE_SYMBOL,
} Type;

// struct Lambda {
// struct Object const *args, *body;
// };

struct List {
struct Object const *car, *cdr;
};

typedef struct Object {
Type type;
typedef struct object Object;
struct object {
enum {
NIL = 0,
BOOLEAN,
ERROR,
// LAMBDA,
LIST,
STRING,
SYMBOL,

// F64,
I64,
// U64,
} type;
union {
bool boolean;
// struct Lambda *lambda;
struct List *list;
int64_t number;
char const *string;
struct /* lambda */ {
Object *args, *body;
};
struct /* list */ {
Object *car, *cdr;
};
char *string;

double_t f64;
int64_t i64;
uint64_t u64;
};
} Object;

static Object const NIL = { .type = TYPE_NIL };

Object *Boolean(bool boolean);
Object *Error(char const *error);
Object *Number(int64_t number);
Object *String(char const *string);
Object *Symbol(char const *symbol);

#endif // PLOY_TYPE_H
};
4 changes: 4 additions & 0 deletions lib/ploy/demo.ploy → lib/ploy/examples/demo.ploy
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
(greet greeting)

(print (format "The answer is {}." (+ 40 2)))

(+ 1 1)

(+ 43 -1)
Loading

0 comments on commit 04cff6f

Please sign in to comment.