mirror of
https://github.com/CPunch/Cosmo.git
synced 2025-10-17 06:21:15 +00:00
Compare commits
11 Commits
error-hand
...
2d889a37d1
Author | SHA1 | Date | |
---|---|---|---|
2d889a37d1 | |||
0f0a8fb085 | |||
c03df8f506 | |||
38d9c499ea | |||
79d40d4bb0 | |||
dc44adba6e | |||
7c0bec5e6c | |||
a44450ff22 | |||
58c857d2ea | |||
38136d028f | |||
420cd3e856 |
45
.github/workflows/check_build.yaml
vendored
Normal file
45
.github/workflows/check_build.yaml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Check Builds
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- src/**
|
||||
- util/**
|
||||
- main.c
|
||||
- Makefile
|
||||
- CMakeLists.txt
|
||||
- .github/workflows/check_build.yaml
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
ubuntu-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: CMake
|
||||
run: cmake -B build
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Cosmo-Ubuntu
|
||||
path: build/bin
|
||||
|
||||
windows-build:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Create CMake build files
|
||||
run: cmake -B build -DCMAKE_BUILD_TYPE=MinSizeRel
|
||||
- name: Check compilation
|
||||
run: cmake --build build --config MinSizeRel
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Cosmo-Windows
|
||||
path: build/bin
|
@@ -16,7 +16,7 @@ set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT c
|
||||
include(FetchContent)
|
||||
|
||||
file(GLOB sources CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.c)
|
||||
add_executable(${PROJECT_NAME} main.c)
|
||||
add_executable(${PROJECT_NAME} main.c ${PROJECT_SOURCE_DIR}/util/linenoise.c)
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${sources})
|
||||
|
||||
IF (NOT WIN32)
|
||||
|
2
Makefile
2
Makefile
@@ -21,6 +21,7 @@ CHDR=\
|
||||
src/cbaselib.h\
|
||||
src/cdump.h\
|
||||
src/cundump.h\
|
||||
util/linenoise.h\
|
||||
|
||||
CSRC=\
|
||||
src/cchunk.c\
|
||||
@@ -37,6 +38,7 @@ CSRC=\
|
||||
src/cbaselib.c\
|
||||
src/cdump.c\
|
||||
src/cundump.c\
|
||||
util/linenoise.c\
|
||||
main.c\
|
||||
|
||||
COBJ=$(CSRC:.c=.o)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Cosmo
|
||||
[](https://ci.appveyor.com/project/CPunch/Cosmo)
|
||||
[](https://github.com/CPunch/Cosmo/actions/workflows/check_build.yaml)
|
||||
|
||||
## Usage
|
||||
|
||||
|
33
appveyor.yml
33
appveyor.yml
@@ -1,33 +0,0 @@
|
||||
version: 'cosmo-0.1.{build}'
|
||||
|
||||
# we compile every commit under all branches
|
||||
#branch:
|
||||
# only:
|
||||
# - main
|
||||
|
||||
# only run CI if we changed actual code
|
||||
only_commits:
|
||||
files:
|
||||
- src/
|
||||
- main.c
|
||||
- Makefile
|
||||
- CMakeLists.txt
|
||||
- appveyor.yml
|
||||
|
||||
# images we're using
|
||||
image:
|
||||
- Ubuntu2004
|
||||
|
||||
platform:
|
||||
- x64
|
||||
|
||||
install:
|
||||
- sudo apt install clang cmake -y
|
||||
|
||||
build_script:
|
||||
- make && ./bin/cosmo examples/testsuite.cosmo -s examples/getters_setters.cosmo
|
||||
|
||||
artifacts:
|
||||
- path: bin
|
||||
name: ubuntu20_04-bin-x64
|
||||
type: zip
|
11
main.c
11
main.c
@@ -8,6 +8,8 @@
|
||||
#include "cundump.h"
|
||||
#include "cvm.h"
|
||||
|
||||
#include "util/linenoise.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
@@ -63,7 +65,7 @@ static bool interpret(CState *state, const char *script, const char *mod)
|
||||
|
||||
static void repl(CState *state)
|
||||
{
|
||||
char line[1024];
|
||||
char *line;
|
||||
_ACTIVE = true;
|
||||
|
||||
// add our custom REPL functions
|
||||
@@ -76,14 +78,13 @@ static void repl(CState *state)
|
||||
cosmoV_register(state, 2);
|
||||
|
||||
while (_ACTIVE) {
|
||||
printf("> ");
|
||||
|
||||
if (!fgets(line, sizeof(line), stdin)) { // better than gets()
|
||||
printf("\n> ");
|
||||
if (!(line = linenoise("> "))) { // better than gets()
|
||||
break;
|
||||
}
|
||||
|
||||
linenoiseHistoryAdd(line);
|
||||
interpret(state, line, "REPL");
|
||||
linenoiseFree(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -56,7 +56,7 @@ void *cosmoM_reallocate(CState *state, void *buf, size_t oldSize, size_t newSize
|
||||
#endif
|
||||
|
||||
if (newBuf == NULL) {
|
||||
CERROR("failed to allocate memory!");
|
||||
printf("[ERROR] failed to allocate memory!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@@ -64,6 +64,4 @@ typedef int (*cosmo_Writer)(CState *state, const void *data, size_t size, const
|
||||
#define UNNAMEDCHUNK "_main"
|
||||
#define COSMOASSERT(x) assert(x)
|
||||
|
||||
#define CERROR(err) printf("%s : %s\n", "[ERROR]", err)
|
||||
|
||||
#endif
|
||||
|
@@ -32,7 +32,7 @@ CState *cosmoV_newState()
|
||||
CState *state = malloc(sizeof(CState));
|
||||
|
||||
if (state == NULL) {
|
||||
CERROR("failed to allocate memory!");
|
||||
printf("[ERROR] failed to allocate memory!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@@ -696,7 +696,7 @@ static inline uint16_t READUINT(CCallFrame *frame)
|
||||
# define SWITCH switch (READBYTE(frame))
|
||||
# define DEFAULT \
|
||||
default: \
|
||||
CERROR("unknown opcode!"); \
|
||||
printf("[ERROR] unknown opcode!"); \
|
||||
exit(0)
|
||||
#endif
|
||||
|
||||
|
1348
util/linenoise.c
Normal file
1348
util/linenoise.c
Normal file
File diff suppressed because it is too large
Load Diff
113
util/linenoise.h
Normal file
113
util/linenoise.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/* linenoise.h -- VERSION 1.0
|
||||
*
|
||||
* Guerrilla line editing library against the idea that a line editing lib
|
||||
* needs to be 20,000 lines of C code.
|
||||
*
|
||||
* See linenoise.c for more information.
|
||||
*
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2010-2023, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __LINENOISE_H
|
||||
#define __LINENOISE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
|
||||
extern char *linenoiseEditMore;
|
||||
|
||||
/* The linenoiseState structure represents the state during line editing.
|
||||
* We pass this state to functions implementing specific editing
|
||||
* functionalities. */
|
||||
struct linenoiseState {
|
||||
int in_completion; /* The user pressed TAB and we are now in completion
|
||||
* mode, so input is handled by completeLine(). */
|
||||
size_t completion_idx; /* Index of next completion to propose. */
|
||||
int ifd; /* Terminal stdin file descriptor. */
|
||||
int ofd; /* Terminal stdout file descriptor. */
|
||||
char *buf; /* Edited line buffer. */
|
||||
size_t buflen; /* Edited line buffer size. */
|
||||
const char *prompt; /* Prompt to display. */
|
||||
size_t plen; /* Prompt length. */
|
||||
size_t pos; /* Current cursor position. */
|
||||
size_t oldpos; /* Previous refresh cursor position. */
|
||||
size_t len; /* Current edited line length. */
|
||||
size_t cols; /* Number of columns in terminal. */
|
||||
size_t oldrows; /* Rows used by last refrehsed line (multiline mode) */
|
||||
int history_index; /* The history index we are currently editing. */
|
||||
};
|
||||
|
||||
typedef struct linenoiseCompletions {
|
||||
size_t len;
|
||||
char **cvec;
|
||||
} linenoiseCompletions;
|
||||
|
||||
/* Non blocking API. */
|
||||
int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt);
|
||||
char *linenoiseEditFeed(struct linenoiseState *l);
|
||||
void linenoiseEditStop(struct linenoiseState *l);
|
||||
void linenoiseHide(struct linenoiseState *l);
|
||||
void linenoiseShow(struct linenoiseState *l);
|
||||
|
||||
/* Blocking API. */
|
||||
char *linenoise(const char *prompt);
|
||||
void linenoiseFree(void *ptr);
|
||||
|
||||
/* Completion API. */
|
||||
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||
typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold);
|
||||
typedef void(linenoiseFreeHintsCallback)(void *);
|
||||
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||
void linenoiseSetHintsCallback(linenoiseHintsCallback *);
|
||||
void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
|
||||
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||
|
||||
/* History API. */
|
||||
int linenoiseHistoryAdd(const char *line);
|
||||
int linenoiseHistorySetMaxLen(int len);
|
||||
int linenoiseHistorySave(const char *filename);
|
||||
int linenoiseHistoryLoad(const char *filename);
|
||||
|
||||
/* Other utilities. */
|
||||
void linenoiseClearScreen(void);
|
||||
void linenoiseSetMultiLine(int ml);
|
||||
void linenoisePrintKeyCodes(void);
|
||||
void linenoiseMaskModeEnable(void);
|
||||
void linenoiseMaskModeDisable(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LINENOISE_H */
|
Reference in New Issue
Block a user