1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 00:10:27 +00:00

Retab some files, delete some other files

This commit is contained in:
Calvin Rose 2017-03-10 00:17:34 -05:00
parent b986e1b967
commit 18493ea076
15 changed files with 234 additions and 484 deletions

2
.idea/interpreter.iml generated
View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

4
.idea/misc.xml generated
View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/interpreter.iml" filepath="$PROJECT_DIR$/.idea/interpreter.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

215
.idea/workspace.xml generated
View File

@ -1,215 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeRunConfigurationManager" shouldGenerate="true" buildAllGenerated="true">
<generated>
<config projectName="interpreter" targetName="interpreter" />
</generated>
</component>
<component name="CMakeSettings">
<configurations>
<configuration CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="aa7ed09b-d1cc-4d38-bb04-299b1e1504d1" name="Default" comment="">
<change type="DELETED" beforePath="$PROJECT_DIR$/parser.c" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/Makefile" afterPath="$PROJECT_DIR$/Makefile" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/compile.c" afterPath="$PROJECT_DIR$/compile.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/datatypes.h" afterPath="$PROJECT_DIR$/datatypes.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/dict.c" afterPath="$PROJECT_DIR$/dict.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/gc.c" afterPath="$PROJECT_DIR$/gc.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/gc.h" afterPath="$PROJECT_DIR$/gc.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/parse.c" afterPath="$PROJECT_DIR$/parse.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/util.h" afterPath="$PROJECT_DIR$/util.h" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/value.c" afterPath="$PROJECT_DIR$/value.c" />
</list>
<ignored path="$PROJECT_DIR$/cmake-build-debug/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CreatePatchCommitExecutor">
<option name="PATCH_PATH" value="" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="ds.c" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ds.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1650">
<caret line="31" column="54" lean-forward="false" selection-start-line="31" selection-start-column="54" selection-end-line="31" selection-end-column="54" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/ds.c" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds">
<option name="y" value="26" />
<option name="width" value="1920" />
<option name="height" value="1054" />
</component>
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="2" id="Add" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="interpreter" />
<option name="myItemType" value="com.jetbrains.cidr.projectView.CidrFilesViewHelper$MyProjectTreeStructure$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="interpreter" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
</component>
<component name="RunManager" selected="Application.Build All">
<configuration default="true" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" PROJECT_NAME="interpreter" TARGET_NAME="interpreter" CONFIG_NAME="Debug">
<envs />
<method />
</configuration>
<configuration default="false" name="interpreter" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" PROJECT_NAME="interpreter" TARGET_NAME="interpreter" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="interpreter" RUN_TARGET_NAME="interpreter">
<envs />
<method />
</configuration>
<configuration default="false" name="Build All" type="CMakeRunConfiguration" factoryName="Application" WORKING_DIR="" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="interpreter" RUN_TARGET_NAME="interpreter" EXPLICIT_BUILD_TARGET_NAME="all">
<envs />
<method />
</configuration>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="Application.interpreter" />
<item index="1" class="java.lang.String" itemvalue="Application.Build All" />
</list>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="aa7ed09b-d1cc-4d38-bb04-299b1e1504d1" name="Default" comment="" />
<created>1487818367037</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1487818367037</updated>
<workItem from="1487818369430" duration="237000" />
<workItem from="1488661961803" duration="14000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="251000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="26" width="1920" height="1054" extended-state="6" />
<editor active="false" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.18177083" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="CMake" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32984293" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="LuaJ" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24816754" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32984293" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="processedProjectFiles" value="true" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="13" lean-forward="false" selection-start-line="3" selection-start-column="13" selection-end-line="3" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ds.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="13" lean-forward="false" selection-start-line="3" selection-start-column="13" selection-end-line="3" selection-end-column="13" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ds.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1650">
<caret line="31" column="54" lean-forward="false" selection-start-line="31" selection-start-column="54" selection-end-line="31" selection-end-column="54" />
<folding />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -495,7 +495,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form,
uint32_t count = gst_tuple_length(form);
/* Check for some early exit conditions */
if (count == 2 && (flags & OP_1_REPEAT)) {
return compile_value(c, opts, form[1]);
return compile_value(c, opts, form[1]);
}
if (opts.resultUnused) {
ret = nil_slot();
@ -550,8 +550,8 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form,
uint32_t i;
FormOptions subOpts = form_options_default();
Slot lhs = compile_value(c, subOpts, form[1]);
Slot rhs = compile_value(c, subOpts, form[2]);
gst_buffer_push_u16(c->vm, buffer, op2);
Slot rhs = compile_value(c, subOpts, form[2]);
gst_buffer_push_u16(c->vm, buffer, op2);
gst_buffer_push_u16(c->vm, buffer, ret.index);
gst_buffer_push_u16(c->vm, buffer, lhs.index);
gst_buffer_push_u16(c->vm, buffer, rhs.index);
@ -559,7 +559,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form,
compiler_drop_slot(c, scope, rhs);
for (i = 3; i < count; ++i) {
rhs = compile_value(c, subOpts, form[i]);
gst_buffer_push_u16(c->vm, buffer, op2);
gst_buffer_push_u16(c->vm, buffer, op2);
gst_buffer_push_u16(c->vm, buffer, ret.index);
gst_buffer_push_u16(c->vm, buffer, ret.index);
gst_buffer_push_u16(c->vm, buffer, rhs.index);
@ -582,7 +582,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form,
/* Quickly define some specials */
#define MAKE_SPECIAL(name, op0, op1, op2, opn, flags) \
static Slot compile_##name (GstCompiler *c, FormOptions opts, GstValue *form) {\
return compile_operator(c, opts, form, (op0), (op1), (op2), (opn), (flags));\
return compile_operator(c, opts, form, (op0), (op1), (op2), (opn), (flags));\
}
MAKE_SPECIAL(addition, 0, -1, GST_OP_ADD, -1, OP_FOLD | OP_DEFAULT_INT | OP_1_REPEAT)
@ -615,18 +615,18 @@ static Slot compile_set(GstCompiler *c, FormOptions opts, GstValue *form) {
subOpts = form_options_default();
}
key = compiler_realize_slot(c, compile_value(c, subOpts, form[2]));
val = compiler_realize_slot(c, compile_value(c, subOpts, form[3]));
val = compiler_realize_slot(c, compile_value(c, subOpts, form[3]));
gst_buffer_push_u16(c->vm, buffer, GST_OP_SET);
gst_buffer_push_u16(c->vm, buffer, ds.index);
gst_buffer_push_u16(c->vm, buffer, key.index);
gst_buffer_push_u16(c->vm, buffer, val.index);
gst_buffer_push_u16(c->vm, buffer, val.index);
compiler_drop_slot(c, c->tail, key);
compiler_drop_slot(c, c->tail, val);
if (opts.resultUnused) {
compiler_drop_slot(c, c->tail, ds);
return nil_slot();
} else {
return ds;
return ds;
}
}
@ -881,8 +881,8 @@ static Slot compile_try(GstCompiler *c, FormOptions opts, GstValue *form) {
/* Add subscope for error variable */
GstScope *subScope = compiler_push_scope(c, 1);
errorIndex = compiler_declare_symbol(c, subScope, form[1]);
/* Leave space for try instruction */
countAtTry = buffer->count;
/* Leave space for try instruction */
countAtTry = buffer->count;
buffer->count += sizeof(uint32_t) + 2 * sizeof(uint16_t);
/* Compile the body */
body = compile_value(c, opts, form[2]);
@ -1052,23 +1052,23 @@ static SpecialFormHelper get_special(GstValue *form) {
}
}
break;
case 'e':
{
if (gst_string_length(name) == 5 &&
name[1] == 'r' &&
name[2] == 'r' &&
name[3] == 'o' &&
name[4] == 'r') {
return compile_error;
}
}
case 'e':
{
if (gst_string_length(name) == 5 &&
name[1] == 'r' &&
name[2] == 'r' &&
name[3] == 'o' &&
name[4] == 'r') {
return compile_error;
}
}
case 'g':
{
if (gst_string_length(name) == 3 &&
name[1] == 'e' &&
name[2] == 't') {
return compile_get;
}
if (gst_string_length(name) == 3 &&
name[1] == 'e' &&
name[2] == 't') {
return compile_get;
}
}
case 'd':
{
@ -1102,7 +1102,7 @@ static SpecialFormHelper get_special(GstValue *form) {
return compile_not;
}
}
break;
break;
case 'q':
{
if (gst_string_length(name) == 5 &&
@ -1134,7 +1134,7 @@ static SpecialFormHelper get_special(GstValue *form) {
name[2] == 'p' &&
name[3] == 'l' &&
name[4] == 'e') {
return compile_make_tuple;
return compile_make_tuple;
}
}
case 'w':
@ -1198,14 +1198,14 @@ static Slot compile_object(GstCompiler *c, FormOptions opts, GstObject *obj) {
ret = compiler_get_target(c, opts);
tracker_init(c, &tracker);
for (i = 0; i < cap; ++i) {
bucket = obj->buckets[i];
while (bucket != NULL) {
bucket = obj->buckets[i];
while (bucket != NULL) {
Slot slot = compile_value(c, subOpts, bucket->key);
compiler_tracker_push(c, &tracker, compiler_realize_slot(c, slot));
slot = compile_value(c, subOpts, bucket->value);
compiler_tracker_push(c, &tracker, compiler_realize_slot(c, slot));
bucket = bucket->next;
}
bucket = bucket->next;
}
}
compiler_tracker_free(c, scope, &tracker);
gst_buffer_push_u16(c->vm, buffer, GST_OP_DIC);
@ -1335,10 +1335,10 @@ GstFunction *gst_compiler_compile(GstCompiler *c, GstValue form) {
GstFuncEnv *env = gst_alloc(c->vm, sizeof(GstFuncEnv));
GstFunction *func = gst_alloc(c->vm, sizeof(GstFunction));
if (envSize) {
env->values = gst_alloc(c->vm, sizeof(GstValue) * envSize);
gst_memcpy(env->values, c->env->data, envSize * sizeof(GstValue));
env->values = gst_alloc(c->vm, sizeof(GstValue) * envSize);
gst_memcpy(env->values, c->env->data, envSize * sizeof(GstValue));
} else {
env->values = NULL;
env->values = NULL;
}
env->stackOffset = envSize;
env->thread = NULL;

View File

@ -74,14 +74,14 @@ struct GstValue {
/* A lightweight thread in gst. Does not correspond to
* operating system threads. Used in coroutines. */
struct GstThread {
uint32_t count;
uint32_t capacity;
GstValue *data;
enum {
GST_THREAD_PENDING = 0,
GST_THREAD_ALIVE,
GST_TRHEAD_DEAD
} status;
uint32_t count;
uint32_t capacity;
GstValue *data;
enum {
GST_THREAD_PENDING = 0,
GST_THREAD_ALIVE,
GST_TRHEAD_DEAD
} status;
};
/* A dynamic array type. Useful for implementing a stack. */
@ -147,8 +147,8 @@ struct GstBucket {
/* Contains information about userdata */
struct GstUserdataHeader {
uint32_t size;
GstObject *meta;
uint32_t size;
GstObject *meta;
};
/* VM return status from c function */
@ -206,9 +206,9 @@ enum GstOpCode {
GST_OP_TUP, /* Create tuple */
GST_OP_SET, /* Assocaitive set */
GST_OP_GET, /* Associative get */
GST_OP_ERR, /* Throw error */
GST_OP_TRY, /* Begin try block */
GST_OP_UTY, /* End try block */
GST_OP_ERR, /* Throw error */
GST_OP_TRY, /* Begin try block */
GST_OP_UTY, /* End try block */
GST_OP_RET, /* Return from function */
GST_OP_RTN, /* Return nil */
GST_OP_PSH, /* Push a stack frame */

View File

@ -76,10 +76,10 @@ void gst_dasm(FILE * out, uint16_t *byteCode, uint32_t len) {
break;
case GST_OP_SUB:
current += dasm_fixed_op(out, current, "sub", 3);
break;
break;
case GST_OP_MUL:
current += dasm_fixed_op(out, current, "mul", 3);
break;
break;
case GST_OP_DIV:
current += dasm_fixed_op(out, current, "div", 3);
break;
@ -194,7 +194,7 @@ void gst_dasm(FILE * out, uint16_t *byteCode, uint32_t len) {
current += dasm_fixed_op(out, current, "returnNil", 0);
break;
case GST_OP_PSH:
current += dasm_varg_op(out, current, "push", 1);
current += dasm_varg_op(out, current, "push", 1);
break;
case GST_OP_CAL:
current += dasm_fixed_op(out, current, "call", 1);

62
ds.c
View File

@ -149,11 +149,11 @@ GstValue gst_array_peek(GstArray *array) {
/* Create a new emoty tuple of the given size. Expected to be
* mutated immediately */
GstValue *gst_tuple(Gst *vm, uint32_t length) {
char *data = gst_alloc(vm, 2 * sizeof(uint32_t) + length * sizeof(GstValue));
GstValue *tuple = (GstValue *)(data + (2 * sizeof(uint32_t)));
gst_tuple_length(tuple) = length;
gst_tuple_hash(tuple) = 0;
return tuple;
char *data = gst_alloc(vm, 2 * sizeof(uint32_t) + length * sizeof(GstValue));
GstValue *tuple = (GstValue *)(data + (2 * sizeof(uint32_t)));
gst_tuple_length(tuple) = length;
gst_tuple_hash(tuple) = 0;
return tuple;
}
/****/
@ -162,12 +162,12 @@ GstValue *gst_tuple(Gst *vm, uint32_t length) {
/* Create new userdata */
void *gst_userdata(Gst *vm, uint32_t size, GstObject *meta) {
char *data = gst_alloc(vm, sizeof(GstUserdataHeader) + size);
GstUserdataHeader *header = (GstUserdataHeader *)data;
void *user = data + sizeof(GstUserdataHeader);
header->size = size;
header->meta = meta;
return user;
char *data = gst_alloc(vm, sizeof(GstUserdataHeader) + size);
GstUserdataHeader *header = (GstUserdataHeader *)data;
void *user = data + sizeof(GstUserdataHeader);
header->size = size;
header->meta = meta;
return user;
}
/****/
@ -231,34 +231,34 @@ GstValue gst_object_get(GstObject *o, GstValue key) {
/* Get a value of the object with a cstring key */
GstValue gst_object_get_cstring(GstObject *obj, const char *key) {
const char *end = key;
while (*end++);
uint32_t len = end - key;
uint32_t hash = gst_cstring_calchash((uint8_t *)key, len);
uint32_t index = hash % obj->capacity;
while (*end++);
uint32_t len = end - key;
uint32_t hash = gst_cstring_calchash((uint8_t *)key, len);
uint32_t index = hash % obj->capacity;
GstBucket *bucket = obj->buckets[index];
while (bucket) {
if (bucket->key.type == GST_STRING) {
uint8_t *s = bucket->key.data.string;
if (gst_string_length(s) == len) {
if (!gst_string_hash(s))
gst_string_hash(s) = gst_string_calchash(s);
if (gst_string_hash(s) == hash) {
uint32_t i;
for (i = 0; i < len; ++i)
if (s[i] != key[i])
goto notequal;
return bucket->value;
}
}
if (gst_string_length(s) == len) {
if (!gst_string_hash(s))
gst_string_hash(s) = gst_string_calchash(s);
if (gst_string_hash(s) == hash) {
uint32_t i;
for (i = 0; i < len; ++i)
if (s[i] != key[i])
goto notequal;
return bucket->value;
}
}
}
notequal:
bucket = bucket->next;
notequal:
bucket = bucket->next;
}
/* Return nil */
{
GstValue ret;
ret.type = GST_NIL;
return ret;
GstValue ret;
ret.type = GST_NIL;
return ret;
}
}

View File

@ -1,5 +0,0 @@
# Some basic macros
(defmacro for [bindings ...]
)

48
parse.c
View File

@ -20,13 +20,13 @@ struct GstParseState {
ParseType type;
union {
struct {
uint8_t endDelimiter;
uint8_t endDelimiter;
GstArray *array;
} form;
struct {
GstValue key;
int keyFound;
GstObject *object;
GstObject *object;
} object;
struct {
GstBuffer *buffer;
@ -362,22 +362,22 @@ static int form_state(GstParser *p, uint8_t c) {
x.type = GST_ARRAY;
x.data.array = array;
} else if (c == ')') {
x.type = GST_TUPLE;
x.data.tuple = gst_tuple(p->vm, array->count);
gst_memcpy(x.data.tuple, array->data, array->count * sizeof(GstValue));
x.type = GST_TUPLE;
x.data.tuple = gst_tuple(p->vm, array->count);
gst_memcpy(x.data.tuple, array->data, array->count * sizeof(GstValue));
} else { /* c == '{' */
uint32_t i;
if (array->count % 2 != 0) {
p_error(p, "object literal must have even number of elements");
return 1;
}
x.type = GST_OBJECT;
x.data.object = gst_object(p->vm, array->count);
for (i = 0; i < array->count; i += 2) {
gst_object_put(p->vm, x.data.object, array->data[i], array->data[i + 1]);
}
if (array->count % 2 != 0) {
p_error(p, "object literal must have even number of elements");
return 1;
}
x.type = GST_OBJECT;
x.data.object = gst_object(p->vm, array->count);
for (i = 0; i < array->count; i += 2) {
gst_object_put(p->vm, x.data.object, array->data[i], array->data[i + 1]);
}
}
parser_pop(p);
parser_pop(p);
parser_append(p, x);
return 1;
}
@ -392,17 +392,17 @@ static void dispatch_char(GstParser *p, uint8_t c) {
/* Handle comments */
if (p->flags & GST_PARSER_FLAG_INCOMMENT) {
if (c == '\n') {
p->flags = GST_PARSER_FLAG_EXPECTING_COMMENT;
p->flags = GST_PARSER_FLAG_EXPECTING_COMMENT;
}
return;
return;
} else if (p->flags & GST_PARSER_FLAG_EXPECTING_COMMENT) {
if (c == '#') {
p->flags = GST_PARSER_FLAG_INCOMMENT;
return;
p->flags = GST_PARSER_FLAG_INCOMMENT;
return;
} else if (!is_whitespace(c)) {
p->flags = 0;
p->flags = 0;
} else {
return;
return;
}
}
@ -443,10 +443,10 @@ int gst_parse_cstring(GstParser *p, const char *string) {
int gst_parse_string(GstParser *p, uint8_t *string) {
uint32_t i;
p->status = GST_PARSER_PENDING;
for (i = 0; i < gst_string_length(string); ++i) {
if (p->status != GST_PARSER_PENDING) break;
for (i = 0; i < gst_string_length(string); ++i) {
if (p->status != GST_PARSER_PENDING) break;
dispatch_char(p, string[i]);
}
}
return i;
}

82
stl.c
View File

@ -24,41 +24,41 @@ int gst_stl_print(Gst *vm) {
/* Get class value */
int gst_stl_getclass(Gst *vm) {
GstValue class = gst_get_class(gst_arg(vm, 0));
gst_c_return(vm, class);
GstValue class = gst_get_class(gst_arg(vm, 0));
gst_c_return(vm, class);
}
/* Set class value */
int gst_stl_setclass(Gst *vm) {
GstValue x = gst_arg(vm, 0);
GstValue class = gst_arg(vm, 1);
const char *err = gst_set_class(x, class);
if (err != NULL)
gst_c_throwc(vm, err);
gst_c_return(vm, x);
GstValue x = gst_arg(vm, 0);
GstValue class = gst_arg(vm, 1);
const char *err = gst_set_class(x, class);
if (err != NULL)
gst_c_throwc(vm, err);
gst_c_return(vm, x);
}
/* Call a function */
int gst_stl_callforeach(Gst *vm) {
GstValue func = gst_arg(vm, 0);
uint32_t argCount = gst_count_args(vm);
uint32_t i;
if (argCount) {
for (i = 0; i < argCount - 1; ++i)
gst_call(vm, func, 1, vm->thread->data + vm->thread->count + 1 + i);
return GST_RETURN_OK;
GstValue func = gst_arg(vm, 0);
uint32_t argCount = gst_count_args(vm);
uint32_t i;
if (argCount) {
for (i = 0; i < argCount - 1; ++i)
gst_call(vm, func, 1, vm->thread->data + vm->thread->count + 1 + i);
return GST_RETURN_OK;
} else {
gst_c_throwc(vm, "expected at least one argument");
gst_c_throwc(vm, "expected at least one argument");
}
}
/* Exit */
int gst_stl_exit(Gst *vm) {
int ret;
GstValue exitValue = gst_arg(vm, 0);
ret = (exitValue.type == GST_NUMBER) ? exitValue.data.number : 0;
exit(ret);
return GST_RETURN_OK;
GstValue exitValue = gst_arg(vm, 0);
ret = (exitValue.type == GST_NUMBER) ? exitValue.data.number : 0;
exit(ret);
return GST_RETURN_OK;
}
/* Load core */
@ -76,25 +76,25 @@ void gst_stl_load_core(GstCompiler *c) {
/* Parse a source string into an AST */
int gst_stl_parse(Gst *vm) {
uint8_t *source = gst_to_string(vm, gst_arg(vm, 0));
GstParser p;
uint8_t *source = gst_to_string(vm, gst_arg(vm, 0));
GstParser p;
/* init state */
gst_parser(&p, vm);
/* Get and parse input until we have a full form */
gst_parse_string(&p, source);
if (p.status == GST_PARSER_PENDING) {
gst_c_throwc(vm, "incomplete source");
} else if (p.status == GST_PARSER_ERROR) {
if (p.status == GST_PARSER_PENDING) {
gst_c_throwc(vm, "incomplete source");
} else if (p.status == GST_PARSER_ERROR) {
gst_c_throwc(vm, p.error);
} else {
gst_c_return(vm, p.value);
} else {
gst_c_return(vm, p.value);
}
}
/* Load parsing */
void gst_stl_load_parse(GstCompiler *c) {
gst_compiler_add_global_cfunction(c, "parse", gst_stl_parse);
gst_compiler_add_global_cfunction(c, "parse", gst_stl_parse);
}
/****/
@ -110,25 +110,25 @@ int gst_stl_compile(Gst *vm) {
/* init state */
gst_compiler(&c, vm);
/* Check for environment variables */
if (env.type == GST_OBJECT) {
/* Iterate through environment, adding globals */
} else if (env.type != GST_NIL) {
gst_c_throwc(vm, "invalid type for environment");
}
/* Prepare return value */
ret.type = GST_FUNCTION;
if (env.type == GST_OBJECT) {
/* Iterate through environment, adding globals */
} else if (env.type != GST_NIL) {
gst_c_throwc(vm, "invalid type for environment");
}
/* Prepare return value */
ret.type = GST_FUNCTION;
ret.data.function = gst_compiler_compile(&c, ast);
/* Check for errors */
if (c.error == NULL) {
gst_c_return(vm, ret);
gst_c_return(vm, ret);
} else {
gst_c_throwc(vm, c.error);
gst_c_throwc(vm, c.error);
}
}
/* Load compilation */
void gst_stl_load_compile(GstCompiler *c) {
gst_compiler_add_global_cfunction(c, "compile", gst_stl_compile);
gst_compiler_add_global_cfunction(c, "compile", gst_stl_compile);
}
/****/
@ -143,7 +143,7 @@ void gst_stl_load_compile(GstCompiler *c) {
/* Load all libraries */
void gst_stl_load(GstCompiler *c) {
gst_stl_load_core(c);
gst_stl_load_parse(c);
gst_stl_load_compile(c);
gst_stl_load_core(c);
gst_stl_load_parse(c);
gst_stl_load_compile(c);
}

View File

@ -1,10 +0,0 @@
(do
(:= fib (fn (n)
(if (< n 2)
1
(+ (fib (- n 1)) (fib (- n 2))))))
(print 10)
(print (fib 33))
)

4
util.h
View File

@ -52,8 +52,8 @@
#define GST_FRAME_SIZE 5
/* Macros for referencing that a stack frame given a stack */
#define gst_frame_callee(s) (*(s - 1))
#define gst_frame_size(s) ((s - 2)->data.hws[0])
#define gst_frame_callee(s) (*(s - 1))
#define gst_frame_size(s) ((s - 2)->data.hws[0])
#define gst_frame_prevsize(s) ((s - 2)->data.hws[1])
#define gst_frame_errloc(s) ((s - 2)->data.hws[2])
#define gst_frame_ret(s) ((s - 2)->data.hws[3])

172
vm.c
View File

@ -54,7 +54,7 @@ static void gst_load(Gst *vm, GstValue callee) {
gst_frame_pc(stack) = pc;
/* Nil arguments */
for (i = 0; i < locals; ++i)
stack[i].type = GST_NIL;
stack[i].type = GST_NIL;
}
/* Contextual macro to state in function with VM */
@ -65,7 +65,7 @@ static void gst_load(Gst *vm, GstValue callee) {
/* Write local state back to VM */
#define GST_STATE_WRITE() do { \
*vm->thread = thread; \
*vm->thread = thread; \
} while (0)
/* Start running the VM from where it left off. Continue running
@ -77,8 +77,8 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
GstValue temp, v1, v2;
uint16_t *pc;
/* Intialize local state */
GST_STATE_SYNC();
/* Intialize local state */
GST_STATE_SYNC();
pc = gst_frame_pc(stack);
/* Main interpreter loop */
@ -87,7 +87,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
switch (*pc) {
default:
gst_error(vm, "unknown opcode");
gst_error(vm, "unknown opcode");
break;
#define OP_BINARY_MATH(op) \
@ -122,23 +122,23 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
pc += 3;
break;
case GST_OP_NEG: /* Unary negation */
v1 = stack[pc[2]];
gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP);
temp.type = GST_NUMBER;
temp.data.number = -v1.data.number;
stack[pc[1]] = temp;
pc += 3;
break;
case GST_OP_NEG: /* Unary negation */
v1 = stack[pc[2]];
gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP);
temp.type = GST_NUMBER;
temp.data.number = -v1.data.number;
stack[pc[1]] = temp;
pc += 3;
break;
case GST_OP_INV: /* Unary multiplicative inverse */
v1 = stack[pc[2]];
gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP);
temp.type = GST_NUMBER;
temp.data.number = 1 / v1.data.number;
stack[pc[1]] = temp;
pc += 3;
break;
case GST_OP_INV: /* Unary multiplicative inverse */
v1 = stack[pc[2]];
gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP);
temp.type = GST_NUMBER;
temp.data.number = 1 / v1.data.number;
stack[pc[1]] = temp;
pc += 3;
break;
case GST_OP_FLS: /* Load False */
temp.type = GST_BOOLEAN;
@ -211,7 +211,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
break;
case GST_OP_CST: /* Load constant value */
v1 = gst_frame_callee(stack);
v1 = gst_frame_callee(stack);
gst_assert(vm, v1.type == GST_FUNCTION, GST_EXPECTED_FUNCTION);
if (pc[2] > v1.data.function->def->literalsLen)
gst_error(vm, GST_NO_UPVALUE);
@ -336,40 +336,40 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
break;
case GST_OP_GET: /* Associative get */
{
const char *err;
err = gst_get(stack[pc[2]], stack[pc[3]], stack + pc[1]);
if (err != NULL)
gst_error(vm, err);
pc += 4;
{
const char *err;
err = gst_get(stack[pc[2]], stack[pc[3]], stack + pc[1]);
if (err != NULL)
gst_error(vm, err);
pc += 4;
break;
}
}
case GST_OP_SET: /* Associative set */
{
const char *err;
err = gst_set(vm, stack[pc[1]], stack[pc[2]], stack[pc[3]]);
if (err != NULL)
gst_error(vm, err);
pc += 4;
{
const char *err;
err = gst_set(vm, stack[pc[1]], stack[pc[2]], stack[pc[3]]);
if (err != NULL)
gst_error(vm, err);
pc += 4;
break;
}
}
case GST_OP_ERR: /* Throw error */
vm->ret = stack[pc[1]];
goto vm_error;
break;
case GST_OP_ERR: /* Throw error */
vm->ret = stack[pc[1]];
goto vm_error;
break;
case GST_OP_TRY: /* Begin try block */
gst_frame_errloc(stack) = pc[1];
gst_frame_errjmp(stack) = pc + *(uint32_t *)(pc + 2);
pc += 4;
break;
case GST_OP_TRY: /* Begin try block */
gst_frame_errloc(stack) = pc[1];
gst_frame_errjmp(stack) = pc + *(uint32_t *)(pc + 2);
pc += 4;
break;
case GST_OP_UTY: /* End try block */
gst_frame_errjmp(stack) = NULL;
pc++;
break;
case GST_OP_UTY: /* End try block */
gst_frame_errjmp(stack) = NULL;
pc++;
break;
case GST_OP_RTN: /* Return nil */
vm->ret.type = GST_NIL;
@ -377,10 +377,10 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
case GST_OP_RET: /* Return */
vm->ret = stack[pc[1]];
goto ret;
goto ret;
case GST_OP_PSH: /* Push stack frame */
{
case GST_OP_PSH: /* Push stack frame */
{
GstValue *nextStack;
uint32_t expectedArity, normalArity, arity, varArgs, i, locals, nextCount;
@ -439,34 +439,34 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
if (varArgs) {
GstValue *tuple;
uint32_t j;
tuple = gst_tuple(vm, arity - expectedArity);
for (j = expectedArity; j < arity; ++j)
tuple[j - expectedArity] = stack[pc[3 + j]];
nextStack[expectedArity].type = GST_TUPLE;
nextStack[expectedArity].data.tuple = tuple;
tuple = gst_tuple(vm, arity - expectedArity);
for (j = expectedArity; j < arity; ++j)
tuple[j - expectedArity] = stack[pc[3 + j]];
nextStack[expectedArity].type = GST_TUPLE;
nextStack[expectedArity].data.tuple = tuple;
}
/* Increment pc */
pc += 3 + arity;
}
break;
}
break;
case GST_OP_CAL: /* Call */
case GST_OP_TCL: /* Tail call */
if (pc[0] == GST_OP_CAL) {
gst_frame_ret(stack) = pc[1];
gst_frame_pc(stack) = pc + 2;
thread.count += gst_frame_size(stack) + GST_FRAME_SIZE;
stack = thread.data + thread.count;
thread.count += gst_frame_size(stack) + GST_FRAME_SIZE;
stack = thread.data + thread.count;
} else {
uint32_t i;
GstValue *nextStack = stack + gst_frame_size(stack) + GST_FRAME_SIZE;
uint32_t nextSize = gst_frame_size(nextStack);
/* Check for closures */
if (gst_frame_env(stack) != NULL) {
gst_frame_env(stack)->thread = NULL;
gst_frame_env(stack)->thread = NULL;
gst_frame_env(stack)->stackOffset = gst_frame_size(stack);
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack));
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack));
gst_memcpy(gst_frame_env(stack)->values,
thread.data + thread.count,
gst_frame_size(stack) * sizeof(GstValue));
@ -477,8 +477,8 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
gst_frame_env(stack) = NULL;
gst_frame_errjmp(stack) = NULL;
/* Replace current stack frame with next */
for (i = 0; i < nextSize; ++i)
stack[i] = nextStack[i];
for (i = 0; i < nextSize; ++i)
stack[i] = nextStack[i];
}
v1 = gst_frame_callee(stack);
if (v1.type == GST_FUNCTION) {
@ -486,7 +486,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
} else if (v1.type == GST_CFUNCTION) {
int status;
GST_STATE_WRITE();
status = v1.data.cfunction(vm);
status = v1.data.cfunction(vm);
GST_STATE_SYNC();
if (status == GST_RETURN_OK)
goto ret;
@ -500,9 +500,9 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
/* Macro for popping stack frame */
#define pop_frame(onUnderflow) do { \
if (gst_frame_env(stack) != NULL) { \
gst_frame_env(stack)->thread = NULL; \
gst_frame_env(stack)->thread = NULL; \
gst_frame_env(stack)->stackOffset = gst_frame_size(stack); \
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); \
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); \
gst_memcpy(gst_frame_env(stack)->values, \
thread.data + thread.count, \
gst_frame_size(stack) * sizeof(GstValue)); \
@ -518,7 +518,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
/* Label for return */
ret:
/* Check for closure */
pop_frame(GST_RETURN_OK);
pop_frame(GST_RETURN_OK);
pc = gst_frame_pc(stack);
stack[gst_frame_ret(stack)] = vm->ret;
break;
@ -526,7 +526,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
/* Handle errors from c functions and vm opcodes */
vm_error:
while (gst_frame_errjmp(stack) == NULL)
pop_frame(GST_RETURN_ERROR);
pop_frame(GST_RETURN_ERROR);
pc = gst_frame_errjmp(stack);
stack[gst_frame_errloc(stack)] = vm->ret;
break;
@ -546,13 +546,13 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) {
/* Continue running the VM after it has stopped */
int gst_continue(Gst *vm) {
return gst_continue_size(vm, vm->thread->count);
return gst_continue_size(vm, vm->thread->count);
}
/* Run the vm with a given function */
int gst_run(Gst *vm, GstValue func) {
gst_load(vm, func);
return gst_continue(vm);
gst_load(vm, func);
return gst_continue(vm);
}
/* Raw function call implementation for use from c code. Beware code
@ -595,8 +595,8 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) {
thread.capacity = newCap;
}
/* Save modified thread object */
thread.count = nextCount;
/* Save modified thread object */
thread.count = nextCount;
*vm->thread = thread;
/* Set up the new stack frame */
@ -620,11 +620,11 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) {
if (varArgs) {
GstValue *tuple;
uint32_t j;
tuple = gst_tuple(vm, arity - expectedArity);
for (j = expectedArity; j < arity; ++j)
tuple[j - expectedArity] = args[j];
stack[expectedArity].type = GST_TUPLE;
stack[expectedArity].data.tuple = tuple;
tuple = gst_tuple(vm, arity - expectedArity);
for (j = expectedArity; j < arity; ++j)
tuple[j - expectedArity] = args[j];
stack[expectedArity].type = GST_TUPLE;
stack[expectedArity].data.tuple = tuple;
}
/* Call the function */
@ -635,9 +635,9 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) {
GST_STATE_SYNC();
/* Check for closures */
if (gst_frame_env(stack) != NULL) {
gst_frame_env(stack)->thread = NULL;
gst_frame_env(stack)->thread = NULL;
gst_frame_env(stack)->stackOffset = gst_frame_size(stack);
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack));
gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack));
gst_memcpy(gst_frame_env(stack)->values,
thread.data + thread.count,
gst_frame_size(stack) * sizeof(GstValue));
@ -652,9 +652,9 @@ GstValue gst_arg(Gst *vm, uint16_t index) {
GstValue *stack = vm->thread->data + vm->thread->count;
uint16_t frameSize = gst_frame_size(stack);
if (frameSize <= index) {
GstValue ret;
ret.type = GST_NIL;
return ret;
GstValue ret;
ret.type = GST_NIL;
return ret;
}
return stack[index];
}
@ -663,7 +663,7 @@ GstValue gst_arg(Gst *vm, uint16_t index) {
void gst_set_arg(Gst* vm, uint16_t index, GstValue x) {
GstValue *stack = vm->thread->data + vm->thread->count;
uint16_t frameSize = gst_frame_size(stack);
if (frameSize <= index) return;
if (frameSize <= index) return;
stack[index] = x;
}