Compare commits

...

11 Commits

208 changed files with 4450 additions and 8170 deletions

View File

@@ -56,59 +56,5 @@ AttributeMacros:
ForEachMacros:
- b_btree_foreach
- b_queue_foreach
---
Language: ObjC
DerivePointerAlignment: false
PointerAlignment: Right
ColumnLimit: 80
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
ExperimentalAutoDetectBinPacking: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
SortIncludes: true
IndentRequires: true
NamespaceIndentation: Inner
ReflowComments: true
SpacesBeforeTrailingComments: 3
TabWidth: 8
UseTab: AlignWithSpaces
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyExcessCharacter: 5
PenaltyBreakOpenParenthesis: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyIndentedWhitespace: 0
AttributeMacros:
- BLUELIB_API
ForEachMacros:
- b_btree_foreach
- b_queue_foreach
MacroBlockBegin: "MIE_.*_BEGIN"
MacroBlockEnd: "MIE_.*_END"

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "mie"]
path = mie
url = https://g.wash.red/wash/mie.git

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.14)
project(ivy C)
if (WIN32)
@@ -24,10 +24,10 @@ if (NOT IVY_STATIC)
endif ()
if (IVY_STATIC)
set(Bluelib_STATIC TRUE)
set(FX_STATIC TRUE)
endif ()
find_package(Bluelib REQUIRED)
find_package(FX REQUIRED)
add_subdirectory(common)
add_subdirectory(diag)

View File

@@ -11,5 +11,5 @@ else ()
endif ()
target_include_directories(ivy-asm PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_link_libraries(ivy-asm ivy-common mie Bluelib::Core Bluelib::Ds)
target_link_libraries(ivy-asm ivy-common mie FX::Core FX::Ds)
target_compile_definitions(ivy-asm PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})

View File

@@ -1,6 +1,6 @@
#include "assembler.h"
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/bin.h>
#include <stdio.h>
@@ -19,13 +19,13 @@ static const struct assembler_scope_type *scope_types[] = {
static const size_t nr_scope_types = sizeof scope_types / sizeof scope_types[0];
struct asm_table_entry {
b_queue_entry e_entry;
fx_queue_entry e_entry;
struct ivy_bin_table_entry e_data;
};
struct ivy_assembler {
struct assembler_scope *as_scope;
b_queue as_table;
fx_queue as_table;
FILE *as_data;
size_t as_data_offset;
@@ -48,7 +48,7 @@ enum ivy_status ivy_assembler_create(FILE *fp, struct ivy_assembler **as)
out->as_xdat = tmpfile();
struct ivy_bin_header header = {0};
header.h_magic = b_i32_htob(0xAABBCCDD);
header.h_magic = fx_i32_htob(0xAABBCCDD);
fseek(fp, 0, SEEK_SET);
fwrite(&header, sizeof header, 1, fp);
@@ -86,9 +86,9 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
pad(as, 16);
struct ivy_bin_table_entry xdat = {0};
xdat.e_offset = b_i64_htob(as->as_data_offset);
xdat.e_size = b_i32_htob((uint32_t)xdat_len);
xdat.e_type = b_i32_htob(IVY_TABLE_XDAT);
xdat.e_offset = fx_i64_htob(as->as_data_offset);
xdat.e_size = fx_i32_htob((uint32_t)xdat_len);
xdat.e_type = fx_i32_htob(IVY_TABLE_XDAT);
while (1) {
size_t r = fread(buf, 1, buf_len, as->as_xdat);
@@ -114,14 +114,14 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
pad(as, 16);
struct ivy_bin_header header = {0};
header.h_table_offset = b_i64_htob(as->as_data_offset);
header.h_table_len = b_i16_htob(0);
header.h_magic = b_i32_htob(IVY_BIN_MAGIC);
header.h_table_offset = fx_i64_htob(as->as_data_offset);
header.h_table_len = fx_i16_htob(0);
header.h_magic = fx_i32_htob(IVY_BIN_MAGIC);
b_queue_entry *entry = b_queue_first(&as->as_table);
fx_queue_entry *entry = fx_queue_first(&as->as_table);
while (entry) {
struct asm_table_entry *e
= b_unbox(struct asm_table_entry, entry, e_entry);
= fx_unbox(struct asm_table_entry, entry, e_entry);
size_t w = fwrite(&e->e_data, 1, sizeof e->e_data, as->as_data);
if (w < sizeof e->e_data) {
@@ -129,13 +129,13 @@ enum ivy_status ivy_assembler_finish(struct ivy_assembler *as)
}
nr_table_entries++;
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
fwrite(&xdat, 1, sizeof xdat, as->as_data);
nr_table_entries++;
header.h_table_len = b_i16_htob(nr_table_entries);
header.h_table_len = fx_i16_htob(nr_table_entries);
fseek(as->as_data, 0, SEEK_SET);
fwrite(&header, 1, sizeof header, as->as_data);
@@ -257,28 +257,28 @@ enum ivy_status ivy_assembler_end_scope(struct ivy_assembler *as)
memset(entry, 0x0, sizeof *entry);
entry->e_data.e_offset
= b_i64_htob((uint64_t)as->as_scope->s_start_offset);
entry->e_data.e_size = b_i32_htob(
= fx_i64_htob((uint64_t)as->as_scope->s_start_offset);
entry->e_data.e_size = fx_i32_htob(
(uint32_t)(as->as_data_offset - as->as_scope->s_start_offset));
switch (as->as_scope->s_type) {
case IVY_ASM_SCOPE_CLASS:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_CLASS);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_CLASS);
break;
case IVY_ASM_SCOPE_BLOCK:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_BLOCK);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_BLOCK);
break;
case IVY_ASM_SCOPE_CONSTPOOL:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_POOL);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_POOL);
break;
case IVY_ASM_SCOPE_IMPORT:
entry->e_data.e_type = b_i32_htob(IVY_TABLE_IMPORT);
entry->e_data.e_type = fx_i32_htob(IVY_TABLE_IMPORT);
break;
default:
break;
}
b_queue_push_back(&as->as_table, &entry->e_entry);
fx_queue_push_back(&as->as_table, &entry->e_entry);
free(as->as_scope);
as->as_scope = NULL;

View File

@@ -1,9 +1,9 @@
#include "assembler.h"
#include <blue/core/hash.h>
#include <blue/ds/hashmap.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/ds/hashmap.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ivy/asm/bin.h>
#include <ivy/asm/instr.h>
#include <ivy/asm/lex.h>
@@ -19,15 +19,15 @@ enum label_state {
struct label {
enum label_state l_state;
b_queue_entry l_entry;
fx_queue_entry l_entry;
const struct ivy_asm_token *l_name;
size_t l_offset;
};
struct block_assembler_scope {
struct assembler_scope s_base;
b_hashmap *s_labels;
b_queue s_label_refs;
fx_hashmap *s_labels;
fx_queue s_label_refs;
size_t s_text_start;
};
@@ -57,10 +57,10 @@ static enum ivy_status init_scope(
struct ivy_bin_block header = {0};
struct block_assembler_scope *c = (struct block_assembler_scope *)scope;
c->s_labels = b_hashmap_create(NULL, NULL);
c->s_labels = fx_hashmap_create(NULL, NULL);
c->s_text_start = ivy_assembler_get_ptr(as);
header.b_index = b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
header.b_index = fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
assembler_write_data(as, &header, sizeof header);
return IVY_OK;
@@ -68,12 +68,12 @@ static enum ivy_status init_scope(
static struct label *get_label(struct block_assembler_scope *scope, const char *name)
{
b_hashmap_key key = {
fx_hashmap_key key = {
.key_data = name,
.key_size = strlen(name),
};
const b_hashmap_value *v = b_hashmap_get(scope->s_labels, &key);
const fx_hashmap_value *v = fx_hashmap_get(scope->s_labels, &key);
if (!v) {
return NULL;
}
@@ -88,9 +88,9 @@ static enum ivy_status resolve_label_refs(
enum ivy_status status = IVY_OK;
size_t nr_read = 0;
b_queue_entry *entry = b_queue_first(&c->s_label_refs);
fx_queue_entry *entry = fx_queue_first(&c->s_label_refs);
while (entry) {
struct label *label_ref = b_unbox(struct label, entry, l_entry);
struct label *label_ref = fx_unbox(struct label, entry, l_entry);
struct label *label_dest = get_label(c, label_ref->l_name->t_str);
if (!label_dest) {
@@ -99,7 +99,7 @@ static enum ivy_status resolve_label_refs(
return IVY_ERR_NO_ENTRY;
}
b_i32 x;
fx_i32 x;
status = assembler_read_data_at(
as, &x, label_ref->l_offset, sizeof x, &nr_read);
@@ -109,12 +109,12 @@ static enum ivy_status resolve_label_refs(
return IVY_ERR_IO_FAILURE;
}
uint32_t instr = b_i32_btoh(x);
uint32_t instr = fx_i32_btoh(x);
instr = R_SET_D3(instr, label_dest->l_offset);
x = b_i32_htob(instr);
x = fx_i32_htob(instr);
assembler_write_data_at(as, &x, label_ref->l_offset, sizeof x);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return status;
@@ -164,7 +164,7 @@ static enum ivy_status put_instr(
return IVY_ERR_INTERNAL_FAILURE;
}
b_i32 x = b_i32_htob(v);
fx_i32 x = fx_i32_htob(v);
assembler_write_data(as, &x, sizeof x);
return IVY_OK;
}
@@ -179,21 +179,21 @@ static enum ivy_status put_label(
label->l_name = label_name;
label->l_offset = label_offset - c->s_text_start;
b_hashmap_key key = {
fx_hashmap_key key = {
.key_data = label_name->t_str,
.key_size = strlen(label_name->t_str),
};
b_hashmap_value value = {
fx_hashmap_value value = {
.value_data = label,
.value_size = sizeof *label,
};
if (b_hashmap_get(c->s_labels, &key)) {
if (fx_hashmap_get(c->s_labels, &key)) {
return IVY_ERR_NAME_EXISTS;
}
b_status status = b_hashmap_put(c->s_labels, &key, &value);
fx_status status = fx_hashmap_put(c->s_labels, &key, &value);
return ivy_status_from_b_status(status);
}
@@ -208,7 +208,7 @@ static enum ivy_status put_label_ref(
label->l_name = label_name;
label->l_offset = ref_offset;
b_queue_push_back(&c->s_label_refs, &label->l_entry);
fx_queue_push_back(&c->s_label_refs, &label->l_entry);
return IVY_OK;
}

View File

@@ -8,7 +8,7 @@ static enum ivy_status init_scope(
{
struct ivy_bin_class header = {0};
header.c_ident = b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
header.c_ident = fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
assembler_write_data(as, &header, sizeof header);
@@ -22,27 +22,27 @@ static enum ivy_status put_xval(
struct ivy_bin_class_table_entry entry = {0};
switch (type) {
case IVY_ASM_XVAL_PROPERTY:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_PROP);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_PROP);
entry.e_property.p_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_property.p_get
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_GET]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_GET]);
entry.e_property.p_set
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SET]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SET]);
break;
case IVY_ASM_XVAL_MEMBER_VAR:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_MVAR);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_MVAR);
entry.e_mvar.m_ident
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_IDENT]);
entry.e_mvar.m_index
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_INDEX]);
break;
case IVY_ASM_XVAL_MESSAGE_HANDLER:
entry.e_type = b_i32_htob(IVY_CLASS_TABLE_MSGH);
entry.e_type = fx_i32_htob(IVY_CLASS_TABLE_MSGH);
entry.e_msgh.msg_selector
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SELECTOR]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_SELECTOR]);
entry.e_msgh.msg_block
= b_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_BLOCK]);
= fx_i32_htob((uint32_t)attrib[IVY_ASM_ATTRIB_BLOCK]);
break;
default:
return IVY_ERR_NOT_SUPPORTED;

View File

@@ -1,9 +1,9 @@
#include "assembler.h"
#include <blue/core/hash.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ivy/asm/bin.h>
#include <ivy/ident.h>
#include <ivy/selector.h>
@@ -12,7 +12,7 @@
struct constpool_assembler_scope {
struct assembler_scope s_base;
b_dict *s_strings;
fx_dict *s_strings;
size_t s_next_slot;
};
@@ -26,7 +26,7 @@ static enum ivy_status init_scope(
struct constpool_assembler_scope *c
= (struct constpool_assembler_scope *)scope;
c->s_strings = b_dict_create();
c->s_strings = fx_dict_create();
c->s_next_slot = 0;
return IVY_OK;
@@ -35,19 +35,19 @@ static enum ivy_status init_scope(
static ivy_extended_data_key get_cached_string(
struct constpool_assembler_scope *scope, const char *s)
{
b_number *key = b_dict_at(scope->s_strings, s);
fx_number *key = fx_dict_at(scope->s_strings, s);
if (!key) {
return IVY_EX_DATA_KEY_NULL;
}
return (ivy_extended_data_key)b_number_get_int32(key);
return (ivy_extended_data_key)fx_number_get_int32(key);
}
static void put_cached_string(
struct constpool_assembler_scope *scope, const char *s,
ivy_extended_data_key key)
{
b_dict_put(scope->s_strings, s, B_RV_INT32(key));
fx_dict_put(scope->s_strings, s, FX_RV_INT32(key));
}
static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *s)
@@ -63,8 +63,8 @@ static ivy_extended_data_key write_string(struct ivy_assembler *as, const char *
size_t len = strlen(s);
struct ivy_bin_string str = {0};
str.s_hash = b_i32_htob((uint32_t)b_hash_cstr(s));
str.s_len = b_i32_htob((uint32_t)len);
str.s_hash = fx_i32_htob((uint32_t)fx_hash_cstr(s));
str.s_len = fx_i32_htob((uint32_t)len);
key = assembler_write_extended_data(as, &str, sizeof str);
@@ -90,29 +90,29 @@ static ivy_extended_data_key write_selector(
}
if (sel->sel_name) {
dat.sel_name = b_i32_htob(write_string(as, sel->sel_name));
dat.sel_name = fx_i32_htob(write_string(as, sel->sel_name));
}
size_t i = 0;
size_t nr_args = b_queue_length(&sel->sel_args);
size_t nr_args = fx_queue_length(&sel->sel_args);
dat.sel_nr_args = (uint8_t)nr_args;
/* TODO hash. */
ivy_extended_data_key *arg_handles
= calloc(nr_args, sizeof(ivy_extended_data_key));
b_queue_entry *entry = b_queue_first(&sel->sel_args);
fx_queue_entry *entry = fx_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
= fx_unbox(struct ivy_selector_arg, entry, arg_entry);
arg_handles[i++] = write_string(as, arg->arg_label);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
ivy_extended_data_key selector_handle
= assembler_write_extended_data(as, &dat, sizeof dat);
for (i = 0; i < nr_args; i++) {
b_i32 arg_handle = b_i32_htob(arg_handles[i]);
fx_i32 arg_handle = fx_i32_htob(arg_handles[i]);
assembler_write_extended_data(as, &arg_handle, sizeof arg_handle);
}
@@ -126,17 +126,17 @@ static ivy_extended_data_key write_ident(
struct ivy_bin_ident dat = {0};
/* TODO hash. */
size_t nr_parts = b_queue_length(&id->id_parts);
size_t nr_parts = fx_queue_length(&id->id_parts);
size_t i = 0;
ivy_extended_data_key *part_handles
= calloc(nr_parts, sizeof(ivy_extended_data_key));
b_queue_entry *entry = b_queue_first(&id->id_parts);
fx_queue_entry *entry = fx_queue_first(&id->id_parts);
while (entry) {
struct ivy_ident_part *arg
= b_unbox(struct ivy_ident_part, entry, p_entry);
= fx_unbox(struct ivy_ident_part, entry, p_entry);
part_handles[i++] = write_string(as, arg->p_str);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
dat.id_nr_parts = (uint8_t)nr_parts;
@@ -145,7 +145,7 @@ static ivy_extended_data_key write_ident(
= assembler_write_extended_data(as, &dat, sizeof dat);
for (i = 0; i < nr_parts; i++) {
b_i32 part_handle = b_i32_htob(part_handles[i]);
fx_i32 part_handle = fx_i32_htob(part_handles[i]);
assembler_write_extended_data(as, &part_handle, sizeof part_handle);
}
@@ -170,32 +170,32 @@ static enum ivy_status put_pval(
switch (type) {
case IVY_ASM_PVAL_STRING:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_STRING);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_STRING);
k = write_string(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_IDENT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_IDENT);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_IDENT);
k = write_ident(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_ATOM:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_ATOM);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_ATOM);
k = write_string(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
case IVY_ASM_PVAL_SINT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_INT);
entry.e_int = b_i32_htob((uint32_t)i);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_INT);
entry.e_int = fx_i32_htob((uint32_t)i);
break;
case IVY_ASM_PVAL_UINT:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_UINT);
entry.e_int = b_i32_htob((uint32_t)i);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_UINT);
entry.e_int = fx_i32_htob((uint32_t)i);
break;
case IVY_ASM_PVAL_SELECTOR:
entry.e_type = b_i32_htob(IVY_CONSTPOOL_TABLE_SELECTOR);
entry.e_type = fx_i32_htob(IVY_CONSTPOOL_TABLE_SELECTOR);
k = write_selector(as, val);
entry.e_ex_handle = b_i32_htob(k);
entry.e_ex_handle = fx_i32_htob(k);
break;
default:
return IVY_ERR_NOT_SUPPORTED;

View File

@@ -1,7 +1,7 @@
#ifndef IVY_ASM_BIN_H_
#define IVY_ASM_BIN_H_
#include <blue/core/endian.h>
#include <fx/core/endian.h>
#include <stdint.h>
#define IVY_BIN_MAGIC 0x2E495659u
@@ -30,61 +30,61 @@
#define IVY_BIN_NULL_HANDLE ((ivy_bin_data_handle)0)
struct ivy_bin_header {
b_i32 h_magic;
b_i16 h_table_len;
fx_i32 h_magic;
fx_i16 h_table_len;
uint8_t h_reserved[2];
b_i64 h_table_offset;
fx_i64 h_table_offset;
};
struct ivy_bin_table_entry {
b_i32 e_type;
b_i32 e_size;
b_i64 e_offset;
fx_i32 e_type;
fx_i32 e_size;
fx_i64 e_offset;
};
struct ivy_bin_class_table_entry {
b_i32 e_type;
fx_i32 e_type;
union {
struct {
b_i32 p_ident;
b_i32 p_get;
b_i32 p_set;
fx_i32 p_ident;
fx_i32 p_get;
fx_i32 p_set;
} e_property;
struct {
b_i32 m_index;
b_i32 m_ident;
fx_i32 m_index;
fx_i32 m_ident;
uint8_t m_reserved[4];
} e_mvar;
struct {
b_i32 msg_selector;
b_i32 msg_block;
fx_i32 msg_selector;
fx_i32 msg_block;
uint8_t m_reserved[4];
} e_msgh;
};
};
struct ivy_bin_class {
b_i32 c_ident;
fx_i32 c_ident;
uint8_t c_reserved[12];
struct ivy_bin_class_table_entry c_table[];
};
struct ivy_bin_lambda {
b_i32 l_ident;
b_i32 l_instr[];
fx_i32 l_ident;
fx_i32 l_instr[];
};
struct ivy_bin_msgh {
b_i32 msg_recipient;
b_i32 msg_selector;
b_i32 msg_instr[];
fx_i32 msg_recipient;
fx_i32 msg_selector;
fx_i32 msg_instr[];
};
struct ivy_bin_string {
b_i32 s_hash;
b_i32 s_len;
fx_i32 s_hash;
fx_i32 s_len;
char s_chars[];
};
@@ -92,24 +92,24 @@ struct ivy_bin_selector {
uint8_t sel_flags;
uint8_t sel_nr_args;
uint8_t sel_reserved[2];
b_i32 sel_hash;
b_i32 sel_name;
b_i32 sel_args[];
fx_i32 sel_hash;
fx_i32 sel_name;
fx_i32 sel_args[];
};
struct ivy_bin_ident {
b_i32 id_hash;
fx_i32 id_hash;
uint8_t id_nr_parts;
uint8_t id_reserved[3];
b_i32 id_parts[];
fx_i32 id_parts[];
};
struct ivy_bin_constpool_table_entry {
b_i32 e_type;
fx_i32 e_type;
union {
b_i32 e_ex_handle;
b_i32 e_int;
fx_i32 e_ex_handle;
fx_i32 e_int;
};
};
@@ -119,11 +119,11 @@ struct ivy_bin_constpool {
};
struct ivy_bin_block {
b_i32 b_index;
fx_i32 b_index;
};
struct ivy_bin_import_table_entry {
b_i32 e_ident;
fx_i32 e_ident;
};
#endif

View File

@@ -1,7 +1,7 @@
#ifndef IVY_ASM_INSTR_H_
#define IVY_ASM_INSTR_H_
#include <blue/core/endian.h>
#include <fx/core/endian.h>
#include <ivy/misc.h>
#include <ivy/opcode.h>
#include <ivy/status.h>
@@ -85,6 +85,6 @@ struct ivy_instr {
IVY_API const struct ivy_instr_definition *ivy_instr_find(
enum ivy_instr_id id, const enum ivy_instr_operand_type operands[4]);
IVY_API enum ivy_status ivy_instr_decode(b_i32 instr, struct ivy_instr *out);
IVY_API enum ivy_status ivy_instr_decode(fx_i32 instr, struct ivy_instr *out);
#endif

View File

@@ -1,7 +1,7 @@
#ifndef IVY_ASM_LEX_H_
#define IVY_ASM_LEX_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/line-source.h>
#include <ivy/misc.h>
#include <ivy/status.h>
@@ -64,7 +64,7 @@ enum ivy_asm_symbol {
struct ivy_asm_token {
enum ivy_asm_token_type t_type;
b_queue_entry t_entry;
fx_queue_entry t_entry;
union {
enum ivy_asm_keyword t_keyword;

View File

@@ -139,9 +139,9 @@ const struct ivy_instr_definition *ivy_instr_find(
return NULL;
}
enum ivy_status ivy_instr_decode(b_i32 x, struct ivy_instr *out)
enum ivy_status ivy_instr_decode(fx_i32 x, struct ivy_instr *out)
{
uint32_t instr = b_i32_btoh(x);
uint32_t instr = fx_i32_btoh(x);
unsigned int opcode = R_GET_OPCODE(instr);
if (opcode >= nr_instructions) {
return IVY_ERR_INVALID_VALUE;

128
asm/lex.c
View File

@@ -1,10 +1,10 @@
#include "lex.h"
#include <blue/core/hash.h>
#include <blue/core/queue.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <fx/core/hash.h>
#include <fx/core/queue.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ctype.h>
#include <ivy/asm/lex.h>
#include <stdbool.h>
@@ -63,40 +63,40 @@ static struct lexer_state *push_lexer_state(
memset(state, 0x0, sizeof *state);
state->s_type = state_type;
b_queue_push_back(&lex->lex_state, &state->s_entry);
fx_queue_push_back(&lex->lex_state, &state->s_entry);
return state;
}
static void pop_lexer_state(struct ivy_asm_lexer *lex)
{
b_queue_entry *entry = b_queue_pop_back(&lex->lex_state);
fx_queue_entry *entry = fx_queue_pop_back(&lex->lex_state);
if (!entry) {
return;
}
struct lexer_state *state = b_unbox(struct lexer_state, entry, s_entry);
struct lexer_state *state = fx_unbox(struct lexer_state, entry, s_entry);
free(state);
}
static struct lexer_state *get_lexer_state(struct ivy_asm_lexer *lex)
{
b_queue_entry *entry = b_queue_last(&lex->lex_state);
fx_queue_entry *entry = fx_queue_last(&lex->lex_state);
if (!entry) {
return NULL;
}
return b_unbox(struct lexer_state, entry, s_entry);
return fx_unbox(struct lexer_state, entry, s_entry);
}
static void destroy_state_stack(b_queue *state)
static void destroy_state_stack(fx_queue *state)
{
b_queue_entry *entry = b_queue_first(state);
fx_queue_entry *entry = fx_queue_first(state);
while (entry) {
struct lexer_state *node
= b_unbox(struct lexer_state, entry, s_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(state, entry);
= fx_unbox(struct lexer_state, entry, s_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(state, entry);
free(node);
@@ -107,27 +107,27 @@ static void destroy_state_stack(b_queue *state)
static struct ivy_asm_lexer_symbol_node *get_symbol_node(
struct ivy_asm_lexer_symbol_node *node, char c)
{
b_queue_entry *entry = b_queue_first(&node->s_children);
fx_queue_entry *entry = fx_queue_first(&node->s_children);
while (entry) {
struct ivy_asm_lexer_symbol_node *child = b_unbox(
struct ivy_asm_lexer_symbol_node *child = fx_unbox(
struct ivy_asm_lexer_symbol_node, entry, s_entry);
if (child->s_char == c) {
return child;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return NULL;
}
static b_string *get_temp_string(struct ivy_asm_lexer *lex)
static fx_string *get_temp_string(struct ivy_asm_lexer *lex)
{
if (!lex->lex_temp) {
lex->lex_temp = b_string_create();
lex->lex_temp = fx_string_create();
}
b_string_clear(lex->lex_temp);
fx_string_clear(lex->lex_temp);
return lex->lex_temp;
}
@@ -152,7 +152,7 @@ static enum ivy_status put_symbol(
child->s_id = IVY_ASM_SYM_NONE;
child->s_char = c;
b_queue_push_back(&tree->s_children, &child->s_entry);
fx_queue_push_back(&tree->s_children, &child->s_entry);
tree = child;
}
@@ -162,12 +162,12 @@ static enum ivy_status put_symbol(
static void destroy_symbol_tree(struct ivy_asm_lexer_symbol_node *tree)
{
b_queue_entry *entry = b_queue_first(&tree->s_children);
fx_queue_entry *entry = fx_queue_first(&tree->s_children);
while (entry) {
struct ivy_asm_lexer_symbol_node *node = b_unbox(
struct ivy_asm_lexer_symbol_node *node = fx_unbox(
struct ivy_asm_lexer_symbol_node, entry, s_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&tree->s_children, entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&tree->s_children, entry);
destroy_symbol_tree(node);
@@ -200,23 +200,23 @@ static struct ivy_asm_lexer_symbol_node *build_symbol_tree(void)
return root;
}
static void init_keywords(b_dict *keyword_dict)
static void init_keywords(fx_dict *keyword_dict)
{
for (size_t i = 0; i < nr_keywords; i++) {
struct lex_token_def *keyword = &keywords[i];
b_dict_put(keyword_dict, keyword->name, B_RV_INT(keyword->id));
fx_dict_put(keyword_dict, keyword->name, FX_RV_INT(keyword->id));
}
}
static enum ivy_asm_keyword find_keyword_by_name(
struct ivy_asm_lexer *lex, const char *s)
{
b_number *id = b_dict_at(lex->lex_keywords, s);
fx_number *id = fx_dict_at(lex->lex_keywords, s);
if (!id) {
return IVY_ASM_KW_NONE;
}
return b_number_get_int(id);
return fx_number_get_int(id);
}
enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
@@ -245,7 +245,7 @@ enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
return IVY_ERR_NO_MEMORY;
}
lex->lex_keywords = b_dict_create();
lex->lex_keywords = fx_dict_create();
init_keywords(lex->lex_keywords);
*lexp = lex;
@@ -254,13 +254,13 @@ enum ivy_status ivy_asm_lexer_create(struct ivy_asm_lexer **lexp)
void ivy_asm_lexer_destroy(struct ivy_asm_lexer *lex)
{
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
while (entry) {
struct ivy_asm_token *tok
= b_unbox(struct ivy_asm_token, entry, t_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&lex->lex_queue, entry);
= fx_unbox(struct ivy_asm_token, entry, t_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&lex->lex_queue, entry);
ivy_asm_token_destroy(tok);
@@ -276,11 +276,11 @@ void ivy_asm_lexer_destroy(struct ivy_asm_lexer *lex)
}
if (lex->lex_temp) {
b_string_unref(lex->lex_temp);
fx_string_unref(lex->lex_temp);
}
if (lex->lex_keywords) {
b_dict_unref(lex->lex_keywords);
fx_dict_unref(lex->lex_keywords);
}
destroy_state_stack(&lex->lex_state);
@@ -411,7 +411,7 @@ static struct ivy_asm_token *create_token(enum ivy_asm_token_type type)
static enum ivy_status push_token(
struct ivy_asm_lexer *lex, struct ivy_asm_token *tok)
{
b_queue_push_back(&lex->lex_queue, &tok->t_entry);
fx_queue_push_back(&lex->lex_queue, &tok->t_entry);
lex->lex_prev_token = tok->t_type;
return IVY_OK;
}
@@ -610,7 +610,7 @@ static enum ivy_status read_dquote_marker(struct ivy_asm_lexer *lex)
static enum ivy_status read_string_content(struct ivy_asm_lexer *lex)
{
int c;
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
struct lexer_state *state = get_lexer_state(lex);
if (!str) {
@@ -629,15 +629,15 @@ static enum ivy_status read_string_content(struct ivy_asm_lexer *lex)
}
char s[2] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
advance(lex);
}
if (b_string_get_size(str, B_STRLEN_NORMAL) == 0) {
if (fx_string_get_size(str, FX_STRLEN_NORMAL) == 0) {
return IVY_OK;
}
char *s = b_string_steal(str);
char *s = fx_string_steal(str);
enum ivy_status status = push_string_content(lex, s);
if (status != IVY_OK) {
@@ -692,7 +692,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
int base = 10;
int dots = 0;
bool neg = false;
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
while (true) {
int c = peek(lex);
@@ -733,7 +733,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
token_len++;
dots++;
char s[] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
advance(lex);
continue;
}
@@ -776,7 +776,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
}
char s[] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
token_len++;
advance(lex);
}
@@ -785,7 +785,7 @@ static enum ivy_status read_number(struct ivy_asm_lexer *lex)
return push_uint(lex, 0);
}
const char *s = b_string_ptr(str);
const char *s = fx_string_ptr(str);
char *ep = NULL;
if (dots > 0) {
@@ -826,8 +826,8 @@ static enum ivy_status read_keyword(struct ivy_asm_lexer *lex)
{
advance(lex);
b_string *str = get_temp_string(lex);
b_string_append_cstr(str, "@");
fx_string *str = get_temp_string(lex);
fx_string_append_cstr(str, "@");
bool label = false;
@@ -843,11 +843,11 @@ static enum ivy_status read_keyword(struct ivy_asm_lexer *lex)
}
char s[2] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
advance(lex);
}
const char *s = b_string_ptr(str);
const char *s = fx_string_ptr(str);
enum ivy_asm_keyword keyword = find_keyword_by_name(lex, s);
@@ -862,7 +862,7 @@ static enum ivy_status read_label_ref(struct ivy_asm_lexer *lex)
{
advance(lex);
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
bool label = false;
while (true) {
@@ -883,21 +883,21 @@ static enum ivy_status read_label_ref(struct ivy_asm_lexer *lex)
}
char s[2] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
advance(lex);
}
const char *s = b_string_ptr(str);
const char *s = fx_string_ptr(str);
struct ivy_asm_token *tok = create_token(IVY_ASM_TOK_LABEL_REF);
tok->t_str = b_string_steal(str);
tok->t_str = fx_string_steal(str);
return push_token(lex, tok);
}
static enum ivy_status read_ident(struct ivy_asm_lexer *lex)
{
b_string *str = get_temp_string(lex);
fx_string *str = get_temp_string(lex);
bool label = false;
while (true) {
@@ -918,15 +918,15 @@ static enum ivy_status read_ident(struct ivy_asm_lexer *lex)
}
char s[2] = {c, 0};
b_string_append_cstr(str, s);
fx_string_append_cstr(str, s);
advance(lex);
}
const char *s = b_string_ptr(str);
const char *s = fx_string_ptr(str);
struct ivy_asm_token *tok
= create_token(label ? IVY_ASM_TOK_LABEL : IVY_ASM_TOK_IDENT);
tok->t_str = b_string_steal(str);
tok->t_str = fx_string_steal(str);
return push_token(lex, tok);
}
@@ -1003,7 +1003,7 @@ struct ivy_asm_token *ivy_asm_lexer_peek(struct ivy_asm_lexer *lex)
{
enum ivy_status status = IVY_OK;
while (b_queue_empty(&lex->lex_queue)) {
while (fx_queue_empty(&lex->lex_queue)) {
status = pump_tokens(lex);
if (status != IVY_OK) {
@@ -1013,8 +1013,8 @@ struct ivy_asm_token *ivy_asm_lexer_peek(struct ivy_asm_lexer *lex)
}
lex->lex_status = status;
b_queue_entry *entry = b_queue_first(&lex->lex_queue);
struct ivy_asm_token *tok = b_unbox(struct ivy_asm_token, entry, t_entry);
fx_queue_entry *entry = fx_queue_first(&lex->lex_queue);
struct ivy_asm_token *tok = fx_unbox(struct ivy_asm_token, entry, t_entry);
return tok;
}
@@ -1022,7 +1022,7 @@ struct ivy_asm_token *ivy_asm_lexer_read(struct ivy_asm_lexer *lex)
{
enum ivy_status status = IVY_OK;
while (b_queue_empty(&lex->lex_queue)) {
while (fx_queue_empty(&lex->lex_queue)) {
status = pump_tokens(lex);
if (status != IVY_OK) {
@@ -1031,8 +1031,8 @@ struct ivy_asm_token *ivy_asm_lexer_read(struct ivy_asm_lexer *lex)
}
}
b_queue_entry *entry = b_queue_pop_front(&lex->lex_queue);
struct ivy_asm_token *tok = b_unbox(struct ivy_asm_token, entry, t_entry);
fx_queue_entry *entry = fx_queue_pop_front(&lex->lex_queue);
struct ivy_asm_token *tok = fx_unbox(struct ivy_asm_token, entry, t_entry);
return tok;
}

View File

@@ -1,9 +1,9 @@
#ifndef _LEX_H_
#define _LEX_H_
#include <blue/core/queue.h>
#include <blue/ds/dict.h>
#include <blue/ds/string.h>
#include <fx/core/queue.h>
#include <fx/ds/dict.h>
#include <fx/ds/string.h>
#include <ivy/asm/lex.h>
#include <stdint.h>
@@ -15,15 +15,15 @@ enum lexer_state_type {
struct lexer_state {
enum lexer_state_type s_type;
b_queue_entry s_entry;
fx_queue_entry s_entry;
};
struct ivy_asm_lexer_symbol_node {
char s_char;
enum ivy_asm_symbol s_id;
b_queue_entry s_entry;
b_queue s_children;
fx_queue_entry s_entry;
fx_queue s_children;
};
struct lex_token_def {
@@ -35,14 +35,14 @@ struct lex_token_def {
struct ivy_asm_lexer {
struct ivy_asm_lexer_symbol_node *lex_sym_tree;
struct ivy_line_source *lex_source;
b_dict *lex_keywords;
fx_dict *lex_keywords;
enum ivy_status lex_status;
b_queue lex_queue;
fx_queue lex_queue;
enum ivy_asm_token_type lex_prev_token;
b_string *lex_temp;
b_queue lex_state;
fx_string *lex_temp;
fx_queue lex_state;
unsigned int lex_brace_depth;
char *lex_linebuf;

View File

@@ -1,14 +1,6 @@
#include "mie/select/opcode.h"
#include <ivy/asm/mie.h>
#include <ivy/opcode.h>
#include <mie/ctx.h>
#include <mie/ir/const.h>
#include <mie/ir/msg.h>
#include <mie/select/builder.h>
#include <mie/select/graph.h>
#include <mie/select/node.h>
#include <mie/target/select.h>
#include <stdio.h>
#include <stdlib.h>
@@ -61,6 +53,7 @@ static size_t node_name(
return 0;
}
#if 0
static enum mie_status get_sp_register(
const struct mie_target *target, struct mie_select_builder *builder,
struct mie_select_value *out)
@@ -98,11 +91,11 @@ static enum mie_status get_selector(
struct mie_type *ptr_type = mie_ctx_get_type(ctx, MIE_TYPE_PTR);
struct mie_select_graph *graph = mie_select_builder_get_graph(builder);
b_queue *nodes = &graph->g_nodes;
b_queue_entry *entry = b_queue_first(nodes);
fx_queue *nodes = &graph->g_nodes;
fx_queue_entry *entry = fx_queue_first(nodes);
while (entry) {
struct mie_select_node *node
= b_unbox(struct mie_select_node, entry, n_entry);
= fx_unbox(struct mie_select_node, entry, n_entry);
if (node->n_target != target) {
goto skip;
@@ -124,7 +117,7 @@ static enum mie_status get_selector(
mie_select_node_get_value(node, ptr_type, 0, out);
return MIE_SUCCESS;
skip:
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
struct mie_select_node *sel_node;
@@ -311,7 +304,7 @@ static enum mie_status lower_msg(
struct mie_ctx *ctx = mie_select_builder_get_ctx(builder);
struct mie_select_value **param_chains = calloc(
b_max(size_t, 2, msg->msg_nr_args + 1),
fx_max(size_t, 2, msg->msg_nr_args + 1),
sizeof(struct mie_select_value *));
size_t nr_param_chains = 0;
struct mie_select_value *chain, *recipient, nr_args;
@@ -354,7 +347,7 @@ static enum mie_status lower_msg(
}
struct mie_select_value *stack_chains = calloc(
b_max(size_t, 1, msg->msg_nr_args),
fx_max(size_t, 1, msg->msg_nr_args),
sizeof(struct mie_select_value));
size_t nr_stack_chains = 0;
nr_param_chains = 0;
@@ -415,3 +408,4 @@ const struct mie_target_select_ops __ivy_select_ops = {
.s_node_name = node_name,
.s_lower_msg = lower_msg,
};
#endif

View File

@@ -1,5 +1,4 @@
#include <mie/target/target.h>
#if 0
extern const struct mie_target_select_ops __ivy_select_ops;
static const struct mie_target ivy_target = {
@@ -11,3 +10,4 @@ const struct mie_target *ivy_asm_mie_target(void)
{
return &ivy_target;
}
#endif

View File

@@ -1,7 +1,7 @@
#include "parse.h"
#include <blue/core/hash.h>
#include <blue/core/stringstream.h>
#include <fx/core/hash.h>
#include <fx/core/stringstream.h>
#include <ctype.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/bin.h>
@@ -48,14 +48,14 @@ enum arg_type {
};
struct label {
b_queue_entry l_entry;
fx_queue_entry l_entry;
struct ivy_asm_token *l_name;
unsigned long long l_offset;
};
struct arg {
enum arg_type arg_type;
b_queue_entry arg_entry;
fx_queue_entry arg_entry;
union {
struct ivy_asm_token *arg_const;
@@ -86,11 +86,11 @@ struct block_parser_state {
unsigned int s_prev_token;
enum instr_component s_prev_component;
b_queue s_labels;
fx_queue s_labels;
b_queue s_mnemonic;
fx_queue s_mnemonic;
b_queue s_args;
fx_queue s_args;
struct arg *s_current_arg;
};
@@ -163,7 +163,7 @@ static enum index_base get_index_base(struct ivy_asm_token *tok)
}
const char *s = tok->t_str;
uint64_t hash = b_hash_cstr(s);
uint64_t hash = fx_hash_cstr(s);
switch (hash) {
case HASH_SELF:
@@ -195,28 +195,28 @@ static enum index_base get_index_base(struct ivy_asm_token *tok)
}
}
static enum ivy_instr_id get_instruction_id(b_queue *mnemonic_tokens)
static enum ivy_instr_id get_instruction_id(fx_queue *mnemonic_tokens)
{
char mnemonic[64];
mnemonic[0] = 0;
b_stringstream *s
= b_stringstream_create_with_buffer(mnemonic, sizeof mnemonic);
fx_stringstream *s
= fx_stringstream_create_with_buffer(mnemonic, sizeof mnemonic);
unsigned int i = 0;
b_queue_entry *entry = b_queue_first(mnemonic_tokens);
fx_queue_entry *entry = fx_queue_first(mnemonic_tokens);
while (entry) {
struct ivy_asm_token *tok
= b_unbox(struct ivy_asm_token, entry, t_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(mnemonic_tokens, entry);
= fx_unbox(struct ivy_asm_token, entry, t_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(mnemonic_tokens, entry);
if (i > 0) {
b_stream_write_char(s, '.');
fx_stream_write_char(s, '.');
}
b_stream_write_string(s, tok->t_str, NULL);
fx_stream_write_string(s, tok->t_str, NULL);
i++;
ivy_asm_token_destroy(tok);
@@ -224,7 +224,7 @@ static enum ivy_instr_id get_instruction_id(b_queue *mnemonic_tokens)
entry = next;
}
uint64_t hash = b_hash_cstr(mnemonic);
uint64_t hash = fx_hash_cstr(mnemonic);
for (i = 0; i < nr_mnemonics; i++) {
if (hash == mnemonics[i].m_hash
&& !strcmp(mnemonic, mnemonics[i].m_name)) {
@@ -251,9 +251,9 @@ static enum ivy_status write_instruction(
enum ivy_instr_operand_type operand_types[MAX_ARGS] = {0};
b_queue_entry *entry = b_queue_first(&state->s_args);
fx_queue_entry *entry = fx_queue_first(&state->s_args);
while (entry) {
struct arg *arg = b_unbox(struct arg, entry, arg_entry);
struct arg *arg = fx_unbox(struct arg, entry, arg_entry);
if (i >= MAX_ARGS) {
return IVY_ERR_BAD_SYNTAX;
@@ -310,7 +310,7 @@ static enum ivy_status write_instruction(
return IVY_ERR_BAD_SYNTAX;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
const struct ivy_instr_definition *instr_info
@@ -323,11 +323,11 @@ static enum ivy_status write_instruction(
instr.i_op = instr_info;
i = 0;
entry = b_queue_first(&state->s_args);
entry = fx_queue_first(&state->s_args);
while (entry) {
struct arg *arg = b_unbox(struct arg, entry, arg_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&state->s_args, entry);
struct arg *arg = fx_unbox(struct arg, entry, arg_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&state->s_args, entry);
switch (arg->arg_type) {
case ARG_REG:
@@ -381,7 +381,7 @@ static enum ivy_status push_const_arg(
arg->arg_type = ARG_CONST;
arg->arg_const = tok;
b_queue_push_back(&state->s_args, &arg->arg_entry);
fx_queue_push_back(&state->s_args, &arg->arg_entry);
return IVY_OK;
}
@@ -407,7 +407,7 @@ static enum ivy_status push_label_arg(
arg->arg_type = ARG_LABEL;
arg->arg_label = tok;
b_queue_push_back(&state->s_args, &arg->arg_entry);
fx_queue_push_back(&state->s_args, &arg->arg_entry);
return IVY_OK;
}
@@ -426,7 +426,7 @@ static enum ivy_status push_reg_arg(
arg->arg_reg.reg_token = tok;
arg->arg_reg.reg_index = reg_index;
b_queue_push_back(&state->s_args, &arg->arg_entry);
fx_queue_push_back(&state->s_args, &arg->arg_entry);
return IVY_OK;
}
@@ -482,7 +482,7 @@ static enum ivy_status parse_ident(
switch (state->s_prev_component) {
case INSTR_NONE:
case INSTR_OPCODE_DOT:
b_queue_push_back(&state->s_mnemonic, &tok->t_entry);
fx_queue_push_back(&state->s_mnemonic, &tok->t_entry);
state->s_prev_component = INSTR_OPCODE;
return IVY_OK;
case INSTR_OPCODE:
@@ -619,7 +619,7 @@ static enum ivy_status parse_right_bracket(
return IVY_ERR_BAD_SYNTAX;
}
b_queue_push_back(&state->s_args, &state->s_current_arg->arg_entry);
fx_queue_push_back(&state->s_args, &state->s_current_arg->arg_entry);
state->s_current_arg = NULL;
state->s_prev_component = INSTR_OPERAND;

View File

@@ -1,6 +1,6 @@
#include "parse.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <ivy/asm/assembler.h>
enum item_type {
@@ -23,7 +23,7 @@ struct class_parser_state {
static enum ivy_status push_attrib(struct class_parser_state *state)
{
uint64_t hash = b_hash_cstr(state->s_attrib_name->t_str);
uint64_t hash = fx_hash_cstr(state->s_attrib_name->t_str);
const char *s = state->s_attrib_name->t_str;
unsigned long long v = state->s_attrib_value->t_int.uv;

View File

@@ -9,7 +9,7 @@ struct ident_parser_state {
struct parser_state s_base;
unsigned int s_prev_token;
b_queue s_parts;
fx_queue s_parts;
};
static void init_state(struct ivy_asm_parser *ctx, struct parser_state *s)
@@ -28,7 +28,7 @@ static enum ivy_status parse_ident(
return IVY_ERR_BAD_SYNTAX;
}
b_queue_push_back(&state->s_parts, &tok->t_entry);
fx_queue_push_back(&state->s_parts, &tok->t_entry);
state->s_prev_token = IVY_ASM_TOK_IDENT;
return IVY_OK;
@@ -61,12 +61,12 @@ static enum ivy_status parse_right_paren(
struct ivy_ident *ident = ivy_ident_create();
b_queue_entry *entry = b_queue_first(&state->s_parts);
fx_queue_entry *entry = fx_queue_first(&state->s_parts);
while (entry) {
struct ivy_asm_token *tok
= b_unbox(struct ivy_asm_token, entry, t_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&state->s_parts, entry);
= fx_unbox(struct ivy_asm_token, entry, t_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&state->s_parts, entry);
ivy_ident_add_part(ident, tok->t_str);
ivy_asm_token_destroy(tok);

View File

@@ -155,19 +155,19 @@ struct parser_state *asm_parser_push_state(
type_info->n_init_state(parser, state);
}
b_queue_push_back(&parser->p_state, &state->s_entry);
fx_queue_push_back(&parser->p_state, &state->s_entry);
return state;
}
void asm_parser_pop_state(struct ivy_asm_parser *parser, void *ret)
{
b_queue_entry *last = b_queue_pop_back(&parser->p_state);
fx_queue_entry *last = fx_queue_pop_back(&parser->p_state);
if (!last) {
return;
}
struct parser_state *state = b_unbox(struct parser_state, last, s_entry);
struct parser_state *state = fx_unbox(struct parser_state, last, s_entry);
if (state->s_type->n_finish_state) {
state->s_type->n_finish_state(parser, state);
@@ -183,11 +183,11 @@ void asm_parser_pop_state(struct ivy_asm_parser *parser, void *ret)
struct parser_state *asm_parser_get_state(struct ivy_asm_parser *parser)
{
b_queue_entry *last = b_queue_last(&parser->p_state);
fx_queue_entry *last = fx_queue_last(&parser->p_state);
if (!last) {
return NULL;
}
return b_unbox(struct parser_state, last, s_entry);
return fx_unbox(struct parser_state, last, s_entry);
}

View File

@@ -1,7 +1,7 @@
#ifndef _PARSE_PARSE_H_
#define _PARSE_PARSE_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/lex.h>
@@ -60,7 +60,7 @@ struct parser_state_type {
};
struct parser_state {
b_queue_entry s_entry;
fx_queue_entry s_entry;
const struct parser_state_type* s_type;
ivy_assembler_attrib_table s_attrib;
void* s_previous_value;
@@ -68,7 +68,7 @@ struct parser_state {
struct ivy_asm_parser {
struct ivy_assembler* p_assembler;
b_queue p_state;
fx_queue p_state;
};
extern struct parser_state* asm_parser_push_state(struct ivy_asm_parser* parser, enum parser_state_type_id type, const ivy_assembler_attrib_table attrib);

View File

@@ -1,6 +1,6 @@
#include "parse.h"
#include <blue/core/hash.h>
#include <fx/core/hash.h>
#include <ivy/asm/assembler.h>
struct unit_parser_state {
@@ -16,7 +16,7 @@ struct unit_parser_state {
static enum ivy_status push_attrib(struct unit_parser_state *state)
{
uint64_t hash = b_hash_cstr(state->s_attrib_name->t_str);
uint64_t hash = fx_hash_cstr(state->s_attrib_name->t_str);
const char *s = state->s_attrib_name->t_str;
unsigned long long v = state->s_attrib_value->t_int.uv;

View File

@@ -12,9 +12,9 @@
static enum ivy_status decode_header(
const struct ivy_bin_header *hdr, struct ivy_asm_object_info *out)
{
out->obj_magic = b_i32_btoh(hdr->h_magic);
out->obj_nr_sections = b_i16_btoh(hdr->h_table_len);
out->obj_table_offset = b_i64_btoh(hdr->h_table_offset);
out->obj_magic = fx_i32_btoh(hdr->h_magic);
out->obj_nr_sections = fx_i16_btoh(hdr->h_table_len);
out->obj_table_offset = fx_i64_btoh(hdr->h_table_offset);
return IVY_OK;
}
@@ -22,9 +22,9 @@ static enum ivy_status decode_header(
static enum ivy_status decode_table_entry(
const struct ivy_bin_table_entry *entry, struct ivy_asm_section_info *out)
{
out->s_type = b_i32_btoh(entry->e_type);
out->s_offset = b_i64_btoh(entry->e_offset);
out->s_length = b_i32_btoh(entry->e_size);
out->s_type = fx_i32_btoh(entry->e_type);
out->s_offset = fx_i64_btoh(entry->e_offset);
out->s_length = fx_i32_btoh(entry->e_size);
return IVY_OK;
}
@@ -258,7 +258,7 @@ static enum ivy_status read_string_xdata(
return IVY_ERR_BAD_FORMAT;
}
size_t str_len = b_i32_btoh(str.s_len);
size_t str_len = fx_i32_btoh(str.s_len);
if (str_len == 0) {
*out = NULL;
return IVY_OK;
@@ -306,7 +306,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
return IVY_ERR_BAD_FORMAT;
}
unsigned long type = b_i32_btoh(entry.e_type);
unsigned long type = fx_i32_btoh(entry.e_type);
struct ivy_asm_constpool_value *value = malloc(sizeof *value);
if (!value) {
@@ -319,26 +319,26 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
switch (type) {
case IVY_CONSTPOOL_TABLE_STRING: {
value->v_type = IVY_ASM_CONSTPOOL_TYPE_STRING;
handle = b_i32_btoh(entry.e_ex_handle);
handle = fx_i32_btoh(entry.e_ex_handle);
status = read_string_xdata(reader, handle, &value->v_str);
break;
}
case IVY_CONSTPOOL_TABLE_INT:
value->v_type = IVY_ASM_CONSTPOOL_TYPE_INT;
value->v_int = b_i32_btoh(entry.e_int);
value->v_int = fx_i32_btoh(entry.e_int);
break;
case IVY_CONSTPOOL_TABLE_UINT:
value->v_type = IVY_ASM_CONSTPOOL_TYPE_UINT;
value->v_uint = b_i32_btoh(entry.e_int);
value->v_uint = fx_i32_btoh(entry.e_int);
break;
case IVY_CONSTPOOL_TABLE_ATOM:
value->v_type = IVY_ASM_CONSTPOOL_TYPE_ATOM;
handle = b_i32_btoh(entry.e_ex_handle);
handle = fx_i32_btoh(entry.e_ex_handle);
status = read_string_xdata(reader, handle, &value->v_str);
break;
case IVY_CONSTPOOL_TABLE_SELECTOR: {
value->v_type = IVY_ASM_CONSTPOOL_TYPE_SELECTOR;
handle = b_i32_btoh(entry.e_ex_handle);
handle = fx_i32_btoh(entry.e_ex_handle);
struct ivy_bin_selector sel_entry;
status = ivy_asm_section_reader_read(
@@ -365,7 +365,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
ivy_selector_set_recipient(sel, IVY_SEL_CLASS);
}
size_t name_key = b_i32_btoh(sel_entry.sel_name);
size_t name_key = fx_i32_btoh(sel_entry.sel_name);
status = read_string_xdata(reader, name_key, &sel->sel_name);
if (status != IVY_OK) {
ivy_selector_destroy(sel);
@@ -375,7 +375,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
handle += sizeof sel_entry;
size_t nr_args = sel_entry.sel_nr_args;
for (size_t i = 0; i < nr_args; i++) {
b_i32 arg;
fx_i32 arg;
status = ivy_asm_section_reader_read(
reader->r_xdat, handle, sizeof arg, &arg, &r);
@@ -388,7 +388,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
break;
}
size_t arg_key = b_i32_btoh(arg);
size_t arg_key = fx_i32_btoh(arg);
char *arg_name = NULL;
status = read_string_xdata(reader, arg_key, &arg_name);
if (status != IVY_OK) {
@@ -411,7 +411,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
}
case IVY_CONSTPOOL_TABLE_IDENT: {
value->v_type = IVY_ASM_CONSTPOOL_TYPE_IDENT;
handle = b_i32_btoh(entry.e_ex_handle);
handle = fx_i32_btoh(entry.e_ex_handle);
struct ivy_bin_ident id_entry;
status = ivy_asm_section_reader_read(
@@ -436,7 +436,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
handle += sizeof id_entry;
size_t nr_parts = id_entry.id_nr_parts;
for (size_t i = 0; i < nr_parts; i++) {
b_i32 part;
fx_i32 part;
status = ivy_asm_section_reader_read(
reader->r_xdat, handle, sizeof part, &part, &r);
@@ -449,7 +449,7 @@ enum ivy_status ivy_asm_constpool_reader_read_value(
break;
}
size_t part_key = b_i32_btoh(part);
size_t part_key = fx_i32_btoh(part);
char *part_name = NULL;
status = read_string_xdata(reader, part_key, &part_name);
if (status != IVY_OK) {
@@ -517,7 +517,7 @@ enum ivy_status ivy_asm_constpool_value_destroy(struct ivy_asm_constpool_value *
bool ivy_asm_section_type_to_string(uint32_t in, char out[5])
{
b_i32 v = b_i32_htob(in);
fx_i32 v = fx_i32_htob(in);
for (size_t i = 0; i < sizeof in; i++) {
char c = v.i_bytes[i];

View File

@@ -1,189 +0,0 @@
#[=======================================================================[.rst:
FindBluelib
------------
Find the Bluelib library and header directories
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` target:
``Bluelib::Bluelib``
The Bluelib library, if found
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``Bluelib_FOUND``
true if the Bluelib C headers and libraries were found
``Bluelib_INCLUDE_DIR``
directories containing the Bluelib C headers.
``Bluelib_LIBRARY``
the C library to link against
Hints
^^^^^
The user may set the environment variable ``Bluelib_PREFIX`` to the root
directory of a Bluelib library installation.
#]=======================================================================]
set (Bluelib_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr/local/share
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
${Bluelib_PREFIX}
$ENV{Bluelib_PREFIX})
if (Bluelib_STATIC)
set(_lib_suffix "-s")
endif ()
set(supported_components Core Ds Term Cmd Io Serial Compress)
set(components ${Bluelib_FIND_COMPONENTS})
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
if (NOT components)
set(components ${supported_components})
endif ()
set(required_vars)
foreach (component ${components})
if (NOT "${component}" IN_LIST supported_components)
message(FATAL_ERROR "'${component}' is not a valid Bluelib module.\nSupported modules: ${supported_components_string_list}")
endif ()
string(TOLOWER ${component} header_name)
set(lib_name ${header_name}${_lib_suffix})
if (NOT Bluelib_${component}_INCLUDE_DIR)
find_path(Bluelib_${component}_INCLUDE_DIR
NAMES blue/${header_name}.h ${Bluelib_FIND_ARGS}
PATH_SUFFIXES include
PATHS ${Bluelib_SEARCH_PATHS})
endif ()
if (NOT Bluelib_${component}_LIBRARY)
find_library(Bluelib_${component}_LIBRARY
NAMES blue-${lib_name} ${Bluelib_FIND_ARGS}
PATH_SUFFIXES lib
PATHS ${Bluelib_SEARCH_PATHS})
else ()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${Bluelib_${component}_LIBRARY}" Bluelib_${component}_LIBRARY)
endif()
list(APPEND required_vars Bluelib_${component}_INCLUDE_DIR Bluelib_${component}_LIBRARY)
endforeach (component)
unset(Bluelib_FIND_ARGS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Bluelib
REQUIRED_VARS ${required_vars})
if (Bluelib_FOUND)
set(created_targets)
foreach (component ${components})
string(TOLOWER ${component} header_name)
set(lib_name ${header_name}${_lib_suffix})
if(NOT TARGET Bluelib::${component})
add_library(Bluelib::${component} UNKNOWN IMPORTED)
set_target_properties(Bluelib::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Bluelib_${component}_INCLUDE_DIR}")
target_compile_definitions(Bluelib::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
if (Bluelib_STATIC)
target_compile_definitions(Bluelib::${component} INTERFACE BLUELIB_STATIC=1)
endif ()
set_target_properties(Bluelib::${component} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${Bluelib_${component}_LIBRARY}")
set(created_targets ${created_targets} ${component})
endif ()
endforeach (component)
foreach (component ${created_targets})
if ("${component}" STREQUAL "Ds")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core)
endif ()
if ("${component}" STREQUAL "Term")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Serial")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Cmd")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Term)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term)
endif ()
if ("${component}" STREQUAL "Io")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Compress")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
endforeach (component)
endif()

189
cmake/FindFX.cmake Normal file
View File

@@ -0,0 +1,189 @@
#[=======================================================================[.rst:
FindFX
------------
Find the FX library and header directories
Imported Targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` target:
``FX::FX``
The FX library, if found
Result Variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``FX_FOUND``
true if the FX C headers and libraries were found
``FX_INCLUDE_DIR``
directories containing the FX C headers.
``FX_LIBRARY``
the C library to link against
Hints
^^^^^
The user may set the environment variable ``FX_PREFIX`` to the root
directory of a FX library installation.
#]=======================================================================]
set (FX_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr/local/share
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
${FX_PREFIX}
$ENV{FX_PREFIX})
if (FX_STATIC)
set(_lib_suffix "-s")
endif ()
set(supported_components Core Ds Term Cmd Io Serial Compress)
set(components ${FX_FIND_COMPONENTS})
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
if (NOT components)
set(components ${supported_components})
endif ()
set(required_vars)
foreach (component ${components})
if (NOT "${component}" IN_LIST supported_components)
message(FATAL_ERROR "'${component}' is not a valid FX module.\nSupported modules: ${supported_components_string_list}")
endif ()
string(TOLOWER ${component} header_name)
set(lib_name ${header_name}${_lib_suffix})
if (NOT FX_${component}_INCLUDE_DIR)
find_path(FX_${component}_INCLUDE_DIR
NAMES fx/${header_name}.h ${FX_FIND_ARGS}
PATH_SUFFIXES include
PATHS ${FX_SEARCH_PATHS})
endif ()
if (NOT FX_${component}_LIBRARY)
find_library(FX_${component}_LIBRARY
NAMES fx-${lib_name} ${FX_FIND_ARGS}
PATH_SUFFIXES lib
PATHS ${FX_SEARCH_PATHS})
else ()
# on Windows, ensure paths are in canonical format (forward slahes):
file(TO_CMAKE_PATH "${FX_${component}_LIBRARY}" FX_${component}_LIBRARY)
endif()
list(APPEND required_vars FX_${component}_INCLUDE_DIR FX_${component}_LIBRARY)
endforeach (component)
unset(FX_FIND_ARGS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FX
REQUIRED_VARS ${required_vars})
if (FX_FOUND)
set(created_targets)
foreach (component ${components})
string(TOLOWER ${component} header_name)
set(lib_name ${header_name}${_lib_suffix})
if(NOT TARGET FX::${component})
add_library(FX::${component} UNKNOWN IMPORTED)
set_target_properties(FX::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FX_${component}_INCLUDE_DIR}")
target_compile_definitions(FX::${component} INTERFACE _CRT_SECURE_NO_WARNINGS=1)
if (FX_STATIC)
target_compile_definitions(FX::${component} INTERFACE FX_STATIC=1)
endif ()
set_target_properties(FX::${component} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${FX_${component}_LIBRARY}")
set(created_targets ${created_targets} ${component})
endif ()
endforeach (component)
foreach (component ${created_targets})
if ("${component}" STREQUAL "Ds")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Ds' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Ds INTERFACE FX::Core)
endif ()
if ("${component}" STREQUAL "Term")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Term' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Term' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Term INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Serial")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Serial' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Serial INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Cmd")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Term)
message(FATAL_ERROR "FX: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Cmd INTERFACE FX::Core FX::Ds FX::Term)
endif ()
if ("${component}" STREQUAL "Io")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Io' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET FX::Ds)
message(FATAL_ERROR "FX: Module 'Io' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Io INTERFACE FX::Core FX::Ds)
endif ()
if ("${component}" STREQUAL "Compress")
if (NOT TARGET FX::Core)
message(FATAL_ERROR "FX: Module 'Compress' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(FX::Compress INTERFACE FX::Core FX::Ds)
endif ()
endforeach (component)
endif()

View File

@@ -12,4 +12,4 @@ endif ()
target_include_directories(ivy-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_compile_definitions(ivy-common PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
target_link_libraries(ivy-common Bluelib::Core Bluelib::Ds)
target_link_libraries(ivy-common FX::Core FX::Ds)

View File

@@ -1,5 +1,5 @@
#include <blue/ds/array.h>
#include <blue/ds/string.h>
#include <fx/ds/array.h>
#include <fx/ds/string.h>
#include <errno.h>
#include <ivy/file.h>
#include <stdlib.h>
@@ -18,17 +18,17 @@ static enum ivy_status get_row(
size_t *nr_read)
{
struct ivy_file *f = (struct ivy_file *)src;
size_t nr_rows = b_array_size(f->f_lines);
size_t nr_rows = fx_array_size(f->f_lines);
if (row > nr_rows) {
return IVY_ERR_EOF;
}
b_string *line = b_array_at(f->f_lines, row - 1);
fx_string *line = fx_array_at(f->f_lines, row - 1);
const char *line_str = b_string_ptr(line);
size_t line_len = b_string_get_size(line, B_STRLEN_NORMAL);
size_t copy_len = b_min(ulong, count, line_len);
const char *line_str = fx_string_ptr(line);
size_t line_len = fx_string_get_size(line, FX_STRLEN_NORMAL);
size_t copy_len = fx_min(ulong, count, line_len);
memcpy(buf, line_str, copy_len);
buf[copy_len] = 0;
@@ -52,9 +52,9 @@ static enum ivy_status readline(
return feof(f->f_fp) ? IVY_ERR_EOF : IVY_ERR_IO_FAILURE;
}
b_string *line_str = b_string_create_from_cstr(buf);
b_array_append(f->f_lines, B_OBJECT(line_str));
b_string_unref(line_str);
fx_string *line_str = fx_string_create_from_cstr(buf);
fx_array_append(f->f_lines, FX_OBJECT(line_str));
fx_string_unref(line_str);
*nr_read = strlen(buf);
return IVY_OK;
@@ -79,8 +79,8 @@ enum ivy_status ivy_file_open(const char *path, struct ivy_file **out)
file->f_base.s_get_row = get_row;
file->f_base.s_readline = readline;
file->f_fp = fp;
file->f_path = b_strdup(path);
file->f_lines = b_array_create();
file->f_path = fx_strdup(path);
file->f_lines = fx_array_create();
*out = file;
@@ -89,7 +89,7 @@ enum ivy_status ivy_file_open(const char *path, struct ivy_file **out)
void ivy_file_close(struct ivy_file *file)
{
b_array_unref(file->f_lines);
fx_array_unref(file->f_lines);
free(file->f_path);
fclose(file->f_fp);
free(file);

View File

@@ -1,6 +1,6 @@
#include <blue/core/queue.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <fx/core/queue.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <ivy/ident.h>
#include <stdlib.h>
#include <string.h>
@@ -20,12 +20,12 @@ struct ivy_ident *ivy_ident_create(void)
void ivy_ident_destroy(struct ivy_ident *ident)
{
b_queue_entry *entry = b_queue_first(&ident->id_parts);
fx_queue_entry *entry = fx_queue_first(&ident->id_parts);
while (entry) {
struct ivy_ident_part *part
= b_unbox(struct ivy_ident_part, entry, p_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&ident->id_parts, entry);
= fx_unbox(struct ivy_ident_part, entry, p_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&ident->id_parts, entry);
free(part->p_str);
free(part);
@@ -45,25 +45,25 @@ void ivy_ident_add_part(struct ivy_ident *ident, const char *s)
memset(part, 0x0, sizeof *part);
part->p_str = b_strdup(s);
part->p_str = fx_strdup(s);
b_queue_push_back(&ident->id_parts, &part->p_entry);
fx_queue_push_back(&ident->id_parts, &part->p_entry);
}
size_t ivy_ident_to_string(const struct ivy_ident *ident, char *out, size_t max)
{
b_stringstream *strv = b_stringstream_create_with_buffer(out, max);
fx_stringstream *strv = fx_stringstream_create_with_buffer(out, max);
int i = 0;
b_queue_entry *entry = b_queue_first(&ident->id_parts);
fx_queue_entry *entry = fx_queue_first(&ident->id_parts);
while (entry) {
if (i > 0) {
b_stream_write_char(strv, '.');
fx_stream_write_char(strv, '.');
}
struct ivy_ident_part *part
= b_unbox(struct ivy_ident_part, entry, p_entry);
b_stream_write_string(strv, part->p_str, NULL);
= fx_unbox(struct ivy_ident_part, entry, p_entry);
fx_stream_write_string(strv, part->p_str, NULL);
i++;
}

View File

@@ -1,14 +1,14 @@
#ifndef IVY_COMMON_FILE_H_
#define IVY_COMMON_FILE_H_
#include <blue/ds/array.h>
#include <fx/ds/array.h>
#include <ivy/line-source.h>
#include <ivy/misc.h>
#include <stdio.h>
struct ivy_file {
struct ivy_line_source f_base;
b_array *f_lines;
fx_array *f_lines;
char *f_path;
FILE *f_fp;
};

View File

@@ -1,17 +1,17 @@
#ifndef IVY_IDENT_H_
#define IVY_IDENT_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/misc.h>
#include <stddef.h>
struct ivy_ident_part {
char *p_str;
b_queue_entry p_entry;
fx_queue_entry p_entry;
};
struct ivy_ident {
b_queue id_parts;
fx_queue id_parts;
};
IVY_API struct ivy_ident *ivy_ident_create(void);

View File

@@ -1,7 +1,7 @@
#ifndef IVY_SELECTOR_H_
#define IVY_SELECTOR_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/status.h>
enum ivy_selector_recipient {
@@ -13,13 +13,13 @@ enum ivy_selector_recipient {
struct ivy_selector {
enum ivy_selector_recipient sel_recipient;
char *sel_name;
b_queue sel_args;
fx_queue sel_args;
};
struct ivy_selector_arg {
char *arg_label;
char *arg_name;
b_queue_entry arg_entry;
fx_queue_entry arg_entry;
};
IVY_API enum ivy_status ivy_selector_create(struct ivy_selector **sel);

View File

@@ -5,9 +5,9 @@
#define IVY_ERROR_VENDOR (ivy_error_vendor())
enum b_status;
enum fx_status;
struct b_error_vendor;
struct fx_error_vendor;
enum ivy_status {
IVY_OK = 0,
@@ -28,8 +28,8 @@ enum ivy_status {
};
IVY_API const char *ivy_status_to_string(enum ivy_status status);
IVY_API const struct b_error_vendor *ivy_error_vendor(void);
IVY_API enum ivy_status ivy_status_from_b_status(enum b_status status);
IVY_API const struct fx_error_vendor *ivy_error_vendor(void);
IVY_API enum ivy_status ivy_status_from_b_status(enum fx_status status);
IVY_API enum ivy_status ivy_status_from_errno(int err);
#endif

View File

@@ -1,6 +1,6 @@
#include <blue/core/queue.h>
#include <blue/core/stringstream.h>
#include <blue/ds/string.h>
#include <fx/core/queue.h>
#include <fx/core/stringstream.h>
#include <fx/ds/string.h>
#include <ivy/selector.h>
#include <stdlib.h>
#include <string.h>
@@ -25,12 +25,12 @@ void ivy_selector_destroy(struct ivy_selector *sel)
free(sel->sel_name);
}
b_queue_entry *entry = b_queue_first(&sel->sel_args);
fx_queue_entry *entry = fx_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&sel->sel_args, entry);
= fx_unbox(struct ivy_selector_arg, entry, arg_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&sel->sel_args, entry);
if (arg->arg_label) {
free(arg->arg_label);
@@ -56,7 +56,7 @@ void ivy_selector_set_recipient(
enum ivy_status ivy_selector_set_name(struct ivy_selector *sel, const char *name)
{
sel->sel_name = b_strdup(name);
sel->sel_name = fx_strdup(name);
return sel->sel_name ? IVY_OK : IVY_ERR_NO_MEMORY;
}
@@ -71,7 +71,7 @@ enum ivy_status ivy_selector_add_arg(
memset(arg, 0x0, sizeof *arg);
if (label) {
arg->arg_label = b_strdup(label);
arg->arg_label = fx_strdup(label);
if (!arg->arg_label) {
free(arg);
@@ -80,7 +80,7 @@ enum ivy_status ivy_selector_add_arg(
}
if (name) {
arg->arg_name = b_strdup(name);
arg->arg_name = fx_strdup(name);
if (!arg->arg_name) {
free(arg->arg_label);
@@ -89,49 +89,49 @@ enum ivy_status ivy_selector_add_arg(
}
}
b_queue_push_back(&sel->sel_args, &arg->arg_entry);
fx_queue_push_back(&sel->sel_args, &arg->arg_entry);
return IVY_OK;
}
size_t ivy_selector_to_string(const struct ivy_selector *sel, char *out, size_t max)
{
b_stringstream *str = b_stringstream_create_with_buffer(out, max);
fx_stringstream *str = fx_stringstream_create_with_buffer(out, max);
switch (sel->sel_recipient) {
case IVY_SEL_OBJECT:
b_stream_write_char(str, '-');
fx_stream_write_char(str, '-');
break;
case IVY_SEL_CLASS:
b_stream_write_char(str, '+');
fx_stream_write_char(str, '+');
break;
default:
break;
}
if (sel->sel_name) {
b_stream_write_string(str, sel->sel_name, NULL);
fx_stream_write_string(str, sel->sel_name, NULL);
}
if (sel->sel_name && !b_queue_empty(&sel->sel_args)) {
b_stream_write_char(str, '(');
if (sel->sel_name && !fx_queue_empty(&sel->sel_args)) {
fx_stream_write_char(str, '(');
}
b_queue_entry *entry = b_queue_first(&sel->sel_args);
fx_queue_entry *entry = fx_queue_first(&sel->sel_args);
while (entry) {
struct ivy_selector_arg *arg
= b_unbox(struct ivy_selector_arg, entry, arg_entry);
b_stream_write_fmt(
= fx_unbox(struct ivy_selector_arg, entry, arg_entry);
fx_stream_write_fmt(
str, NULL, "%s:", arg->arg_label ? arg->arg_label : "_");
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
if (sel->sel_name && !b_queue_empty(&sel->sel_args)) {
b_stream_write_char(str, ')');
if (sel->sel_name && !fx_queue_empty(&sel->sel_args)) {
fx_stream_write_char(str, ')');
}
size_t len = b_stringstream_get_length(str);
b_stringstream_unref(str);
size_t len = fx_stringstream_get_length(str);
fx_stringstream_unref(str);
return len;
}

View File

@@ -1,34 +1,34 @@
#include <blue/core/error.h>
#include <fx/core/error.h>
#include <errno.h>
#include <ivy/status.h>
static const b_error_definition error_defs[] = {
B_ERROR_DEFINITION(IVY_OK, "OK", "Success"),
B_ERROR_DEFINITION(IVY_ERR_EOF, "EOF", "Unexpected end of file"),
B_ERROR_DEFINITION(IVY_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
B_ERROR_DEFINITION(IVY_ERR_BAD_SYNTAX, "BAD_SYNTAX", "Invalid syntax"),
B_ERROR_DEFINITION(IVY_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
B_ERROR_DEFINITION(
static const fx_error_definition error_defs[] = {
FX_ERROR_DEFINITION(IVY_OK, "OK", "Success"),
FX_ERROR_DEFINITION(IVY_ERR_EOF, "EOF", "Unexpected end of file"),
FX_ERROR_DEFINITION(IVY_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
FX_ERROR_DEFINITION(IVY_ERR_BAD_SYNTAX, "BAD_SYNTAX", "Invalid syntax"),
FX_ERROR_DEFINITION(IVY_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
FX_ERROR_DEFINITION(
IVY_ERR_NOT_SUPPORTED, "NOT_SUPPORTED",
"Operation not supported"),
B_ERROR_DEFINITION(
FX_ERROR_DEFINITION(
IVY_ERR_INTERNAL_FAILURE, "INTERNAL_FAILURE",
"Internal failure"),
B_ERROR_DEFINITION(IVY_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
B_ERROR_DEFINITION(
FX_ERROR_DEFINITION(IVY_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
FX_ERROR_DEFINITION(
IVY_ERR_INVALID_VALUE, "INVALID_VALUE", "Invalid value"),
B_ERROR_DEFINITION(IVY_ERR_NO_ENTRY, "NO_ENTRY", "Name does not exist"),
B_ERROR_DEFINITION(
FX_ERROR_DEFINITION(IVY_ERR_NO_ENTRY, "NO_ENTRY", "Name does not exist"),
FX_ERROR_DEFINITION(
IVY_ERR_NAME_EXISTS, "NAME_EXISTS", "Name already exists"),
B_ERROR_DEFINITION(IVY_ERR_BAD_FORMAT, "BAD_FORMAT", "Bad format"),
B_ERROR_DEFINITION(
FX_ERROR_DEFINITION(IVY_ERR_BAD_FORMAT, "BAD_FORMAT", "Bad format"),
FX_ERROR_DEFINITION(
IVY_ERR_PARSE_FAILURE, "PARSE_FAILURE", "Parse failure"),
B_ERROR_DEFINITION(
FX_ERROR_DEFINITION(
IVY_ERR_CODEGEN_FAILURE, "CODEGEN_FAILURE",
"Code generation failure"),
};
static const b_error_vendor error_vendor = {
static const fx_error_vendor error_vendor = {
.v_name = "Ivy",
.v_error_definitions = error_defs,
.v_error_definitions_length = sizeof error_defs,
@@ -39,7 +39,7 @@ const char *ivy_status_to_string(enum ivy_status status)
return error_defs[status].err_message;
}
const struct b_error_vendor *ivy_error_vendor(void)
const struct fx_error_vendor *ivy_error_vendor(void)
{
return &error_vendor;
}
@@ -48,12 +48,12 @@ const struct b_error_vendor *ivy_error_vendor(void)
case (from): \
return (to)
enum ivy_status ivy_status_from_b_status(enum b_status status)
enum ivy_status ivy_status_from_b_status(enum fx_status status)
{
switch (status) {
ENUM_CONVERT(B_SUCCESS, IVY_OK);
ENUM_CONVERT(B_ERR_NAME_EXISTS, IVY_ERR_NAME_EXISTS);
ENUM_CONVERT(B_ERR_NO_MEMORY, IVY_ERR_NO_MEMORY);
ENUM_CONVERT(FX_SUCCESS, IVY_OK);
ENUM_CONVERT(FX_ERR_NAME_EXISTS, IVY_ERR_NAME_EXISTS);
ENUM_CONVERT(FX_ERR_NO_MEMORY, IVY_ERR_NO_MEMORY);
default:
return IVY_ERR_INTERNAL_FAILURE;
}

View File

@@ -12,4 +12,4 @@ endif ()
target_include_directories(ivy-diag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_compile_definitions(ivy-diag PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})
target_link_libraries(ivy-diag ivy-common Bluelib::Core Bluelib::Ds Bluelib::Term)
target_link_libraries(ivy-diag ivy-common FX::Core FX::Ds FX::Term)

View File

@@ -52,12 +52,12 @@ void ivy_diag_ctx_write(
struct ivy_diag_ctx *ctx, enum ivy_diag_format format,
struct ivy_diag_stream *stream)
{
b_queue_entry *entry = b_queue_first(&ctx->ctx_diags);
fx_queue_entry *entry = fx_queue_first(&ctx->ctx_diags);
while (entry) {
struct ivy_diag *diag
= b_unbox(struct ivy_diag, entry, diag_entry);
= fx_unbox(struct ivy_diag, entry, diag_entry);
diag_write(ctx, diag, format, stream);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}
@@ -73,7 +73,7 @@ struct ivy_diag *ivy_diag_ctx_create_diag(
out->diag_class = diag_class;
out->diag_parent = ctx;
b_queue_push_back(&ctx->ctx_diags, &out->diag_entry);
fx_queue_push_back(&ctx->ctx_diags, &out->diag_entry);
return out;
}

View File

@@ -1,7 +1,7 @@
#ifndef _DIAG_CTX_H_
#define _DIAG_CTX_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/diag.h>
struct ivy_line_source;
@@ -15,7 +15,7 @@ struct ivy_diag_ctx {
const struct ivy_diag_msg *ctx_msg;
size_t ctx_nr_msg;
b_queue ctx_diags;
fx_queue ctx_diags;
};
extern const struct ivy_diag_class *diag_ctx_get_class(

View File

@@ -3,7 +3,7 @@
#include "ctx.h"
#include <assert.h>
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/diag.h>
#include <stdlib.h>
#include <string.h>
@@ -18,7 +18,7 @@ struct diag_c_msg *diag_msg_create(const struct ivy_diag_msg *content)
memset(out, 0x0, sizeof *out);
out->msg_base.c_type = DIAG_COMPONENT_MSG;
out->msg_content = b_strdup(content->msg_content);
out->msg_content = fx_strdup(content->msg_content);
return out;
}
@@ -77,7 +77,7 @@ void ivy_diag_push_msg(struct ivy_diag *diag, unsigned long msg, ...)
return;
}
b_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry);
fx_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry);
}
void ivy_diag_push_snippet(
@@ -92,5 +92,5 @@ void ivy_diag_push_snippet(
return;
}
b_queue_push_back(&diag->diag_components, &c_snippet->s_base.c_entry);
fx_queue_push_back(&diag->diag_components, &c_snippet->s_base.c_entry);
}

View File

@@ -1,7 +1,7 @@
#ifndef _DIAG_DIAG_H_
#define _DIAG_DIAG_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <stddef.h>
struct ivy_diag_msg;
@@ -14,7 +14,7 @@ enum diag_component_type {
struct diag_component {
enum diag_component_type c_type;
b_queue_entry c_entry;
fx_queue_entry c_entry;
};
struct diag_c_msg {
@@ -38,8 +38,8 @@ struct ivy_diag {
unsigned long diag_class;
unsigned long diag_row, diag_col;
b_queue_entry diag_entry;
b_queue diag_components;
fx_queue_entry diag_entry;
fx_queue diag_components;
};
extern struct diag_c_msg *diag_msg_create(const struct ivy_diag_msg *content);

View File

@@ -44,7 +44,7 @@ struct ivy_line_source;
struct ivy_diag_ctx;
struct ivy_diag;
struct b_tty;
struct fx_tty;
enum ivy_diag_stream_flags {
IVY_DIAG_STREAM_F_NONE = 0x00u,
@@ -64,7 +64,7 @@ struct ivy_diag_stream {
int s_esc;
union {
struct b_tty *s_tty;
struct fx_tty *s_tty;
FILE *s_fp;
};
};
@@ -136,7 +136,7 @@ struct ivy_diag_msg {
extern void ivy_diag_stream_init_file(struct ivy_diag_stream *stream, FILE *fp);
extern void ivy_diag_stream_init_tty(
struct ivy_diag_stream *stream, struct b_tty *tty);
struct ivy_diag_stream *stream, struct fx_tty *tty);
extern enum ivy_status ivy_diag_ctx_create(struct ivy_diag_ctx **out);
extern void ivy_diag_ctx_destroy(struct ivy_diag_ctx *ctx);

View File

@@ -1,6 +1,6 @@
#include "stream.h"
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include <string.h>
void ivy_diag_stream_init_file(struct ivy_diag_stream *stream, FILE *fp)
@@ -14,7 +14,7 @@ void ivy_diag_stream_init_file(struct ivy_diag_stream *stream, FILE *fp)
stream->s_col = 1;
}
void ivy_diag_stream_init_tty(struct ivy_diag_stream *stream, struct b_tty *tty)
void ivy_diag_stream_init_tty(struct ivy_diag_stream *stream, struct fx_tty *tty)
{
memset(stream, 0x0, sizeof *stream);
@@ -41,7 +41,7 @@ enum ivy_status diag_stream_get_dimensions(
break;
case IVY_DIAG_STREAM_TTY: {
unsigned int w, h;
b_tty_get_dimensions(stream->s_tty, &w, &h);
fx_tty_get_dimensions(stream->s_tty, &w, &h);
if (out_rows) {
*out_rows = h;
}
@@ -69,7 +69,7 @@ enum ivy_status diag_stream_putc(struct ivy_diag_stream *stream, char c)
status = (ferror(stream->s_fp)) ? IVY_ERR_IO_FAILURE : IVY_OK;
break;
case IVY_DIAG_STREAM_TTY:
b_tty_putc(stream->s_tty, 0, c);
fx_tty_putc(stream->s_tty, 0, c);
status = IVY_OK;
break;
default:

View File

@@ -4,9 +4,9 @@
#include "../write.h"
#include <assert.h>
#include <blue/core/stringstream.h>
#include <blue/term/print.h>
#include <blue/term/tty.h>
#include <fx/core/stringstream.h>
#include <fx/term/print.h>
#include <fx/term/tty.h>
#include <ctype.h>
#include <ivy/line-source.h>
#include <stdlib.h>
@@ -25,7 +25,7 @@ struct snippet_print_ctx {
size_t ctx_line_buf_ptr;
bool ctx_has_underline;
b_stringstream *ctx_underline;
fx_stringstream *ctx_underline;
struct diag_c_snippet *ctx_snippet;
@@ -67,23 +67,23 @@ struct snippet_print_ctx {
#define STREAM_COLOUR_ERROR_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL); \
fx_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL); \
}
#define STREAM_COLOUR_WARN_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stream_write_string(str, __STREAM_COLOUR_WARN, NULL); \
fx_stream_write_string(str, __STREAM_COLOUR_WARN, NULL); \
}
#define STREAM_COLOUR_HINT_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stream_write_string(str, __STREAM_COLOUR_HINT, NULL); \
fx_stream_write_string(str, __STREAM_COLOUR_HINT, NULL); \
}
#define STREAM_COLOUR_ACCENT_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL); \
fx_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL); \
}
#define STREAM_COLOUR_RESET_B(stream, str) \
if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \
b_stream_write_string(str, __STREAM_COLOUR_RESET, NULL); \
fx_stream_write_string(str, __STREAM_COLOUR_RESET, NULL); \
}
static void print_header(
@@ -143,12 +143,12 @@ static void print_msg(
struct ivy_diag_stream *stream)
{
if (stream->s_type == IVY_DIAG_STREAM_TTY) {
b_paragraph_format format = {
fx_paragraph_format format = {
.p_left_margin = 2,
.p_right_margin = 2,
};
b_print_paragraph(msg->msg_content, stream->s_tty, &format);
fx_print_paragraph(msg->msg_content, stream->s_tty, &format);
} else {
diag_stream_puts(stream, " ");
diag_stream_puts(stream, msg->msg_content);
@@ -218,7 +218,7 @@ static bool amendment_contains_cell(
}
limit = a->a_replace.a_col
+ b_max(ulong, a->a_replace.a_length, a->__x) - 1;
+ fx_max(ulong, a->a_replace.a_length, a->__x) - 1;
if (col > limit) {
return false;
@@ -316,7 +316,7 @@ static enum ivy_status read_row(struct snippet_print_ctx *ctx, size_t row)
ctx->ctx_line_buf_ptr = 0;
ctx->ctx_has_underline = false;
ctx->ctx_underline = b_stringstream_create_with_buffer(
ctx->ctx_underline = fx_stringstream_create_with_buffer(
ctx->ctx_underline_buf, sizeof ctx->ctx_underline_buf);
size_t nr_read;
@@ -380,7 +380,7 @@ static int get_char(struct snippet_print_ctx *ctx)
static void update_underline(struct snippet_print_ctx *ctx)
{
if (!ctx->ctx_hl) {
b_stream_write_char(ctx->ctx_underline, ' ');
fx_stream_write_char(ctx->ctx_underline, ' ');
return;
}
@@ -388,10 +388,10 @@ static void update_underline(struct snippet_print_ctx *ctx)
case IVY_DIAG_HIGHLIGHT_ERROR:
case IVY_DIAG_HIGHLIGHT_WARNING:
case IVY_DIAG_HIGHLIGHT_HINT:
b_stream_write_char(ctx->ctx_underline, '^');
fx_stream_write_char(ctx->ctx_underline, '^');
break;
default:
b_stream_write_char(ctx->ctx_underline, ' ');
fx_stream_write_char(ctx->ctx_underline, ' ');
break;
}
}
@@ -481,15 +481,15 @@ static enum ivy_status write(
print_header(ctx, diag, stream);
print_location(ctx, diag, stream);
b_queue_entry *entry = b_queue_first(&diag->diag_components);
fx_queue_entry *entry = fx_queue_first(&diag->diag_components);
while (entry) {
struct diag_component *c
= b_unbox(struct diag_component, entry, c_entry);
= fx_unbox(struct diag_component, entry, c_entry);
diag_stream_putc(stream, '\n');
print_component(ctx, diag, c, stream);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return IVY_OK;

7
doc/mie-passes.txt Normal file
View File

@@ -0,0 +1,7 @@
ivy.fold-int-constants
ivy.fold-pool-constants
ivy.expand-lambdas
ivy.convert-alloca-to-bp-slot
ivy.convert-string-builder-to-msg
scf.convert-to-cf
ivy.convert-to-cf

530
doc/mie/sample/Person.2.mie Normal file
View File

@@ -0,0 +1,530 @@
meta.source-filename "Person.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.global-ref @cout -> ptr
%StringBuilder = ivy.global-ref @StringBuilder : ptr
ivy.class @Person {
%self.name = ivy.object-var @name : #ivy.id -> ptr
%self.age = ivy.object-var @age : #ivy.id -> ptr
%self.val = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
%lambda.0 = ivy.lambda.body <%env> (%i: #ivy.id) -> void {
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%1 = ivy.str.constant "Count is "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%i -> void
%2 = ivy.msg.send to %0, to-string -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
func.return : ()
}
%lambda.1 = ivy.lambda.body <%env> () -> void {
%env.q = ivy.pkg.get %env[@q] : #ivy.id -> #ivy.id
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%1 = ivy.str.constant "Value of q is "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%env.q -> void
%2 = ivy.msg.send to %0, to-string -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
}
ivy.method init(name:%name, age:%age) -> void {
ptr.store %name, %self.name : #ivy.id, ptr
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.method test(param:%data, _:%extra) -> void {
%0 = ptr.load %StringBuilder : ptr -> #ivy.id
%1 = ivy.msg.send to %0, new -> #ivy.id
%2 = ivy.str.constant "Received "
ivy.msg.send to %1, append:%2 -> void
ivy.msg.send to %1, append:%data -> void
%3 = ivy.str.constant ", "
ivy.msg.send to %1, append:%3 -> void
ivy.msg.send to %1, append:%extra -> void
%4 = ivy.msg.send to %1, to-string -> #ivy.id
%5 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %5, put:%4 -> void
func.return : ()
}
ivy.method name -> #ivy.id {
%0 = ptr.load %self.name : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.method age -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.method age-in-months -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
%1 = i32.constant 12
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
func.return %multmp : #ivy.id
}
ivy.method set-name:%name -> void {
ptr.store %name, %self.name : #ivy.id, ptr
func.return : ()
}
ivy.method set-age:%age -> void {
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.method set-age:%age in-units:%units -> void {
^switch.cond.0:
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
^switch.body.0:
ptr.store %age, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.cond.1:
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
^switch.body.1:
%d0 = i32.constant 12
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.cond.2:
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
^switch.body.2:
%d1 = i32.constant 365
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.default:
%d2 = i32.constant 0
cf.br ^switch.end.0
^switch.end:
func.return : ()
}
ivy.method get-age-in-units:%units -> #ivy.id {
^switch.cond.0:
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
^switch.body.0:
%v0 = ptr.load %self.age : ptr -> #ivy.id
cf.br ^switch.end(%v0: #ivy.id)
^switch.cond.0:
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
^switch.body.0:
%v0 = ptr.load %self.age : ptr -> #ivy.id
%d0 = i32.constant 12
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
cf.br ^switch.end(%divtmp.0: #ivy.id)
^switch.cond.0:
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
^switch.body.0:
%v1 = ptr.load %self.age : ptr -> #ivy.id
%d1 = i32.constant 365
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
cf.br ^switch.end(%divtmp.1: #ivy.id)
^switch.default:
%d2 = i32.constant 0
cf.br ^switch.end(%d2.1: i32)
^switch.end(%result: #ivy.id):
func.return %result : #ivy.id
}
ivy.object-prop example-property
get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
}
set (%value: #ivy.id) {
ptr.store %value, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-2 get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%x: #ivy.id) {
ptr.store %x, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-3 get {
%0 = i32.constant 42
func.return %0 : i32
}
ivy.object-prop example-property-4 get {
%0 = ptr.load %self.p-example-property-4 : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%0: #ivy.id) {
ptr.store %0, %self.p-example-property-4 : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-5 get {
%0 = ptr.load %self.p-example-property-5 : ptr -> #ivy.id
func.return %0 : #ivy.id
}
}
ivy.init-text {
; p1 = Person new(name:'John Doe', age:34).
%Person = ivy.global-ref @Person : ptr
%0 = ivy.str.constant "John Doe"
%1 = i32.constant 34
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
%p1 = ptr.alloca #ivy.id -> ptr
ptr.store %2, %p1 : #ivy.id, ptr
; p1 set-age:100 in-unit:$months.
%3 = ptr.load %p1 : ptr -> #ivy.id
%4 = i32.constant 100
%5 = ivy.atom "months"
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
; p1 test(param:'Hello', 'World').
%6 = ptr.load %p1 : ptr -> #ivy.id
%7 = ivy.str.constant "Hello"
%8 = ivy.str.constant "World"
ivy.msg.send to %6, test(param:%7, _:%8) -> void
; i = 0.
%i = ptr.alloca i32 -> ptr
%9 = i32.constant 0
ptr.store %9, %i : i32, ptr
; while i < 100 do
^while.cond:
; i < 100
%10 = ptr.load %i : ptr -> i32
%11 = i32.constant 100
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
scf.condition(%cmptmp)
cf.br-cond %cmptmp, ^while.body, ^while.end
^while.body:
; cout put:'Count is {i}'.
%12 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%13 = ivy.str.constant "Count is "
ivy.msg.send to %12, append:%13 -> void
%14 = ptr.load %i : ptr -> i32
ivy.msg.send to %12, append:14 -> void
%15 = ivy.msg.send to %12, to-string -> #ivy.id
%16 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %16, put:%15 -> void
; i += 2
%17 = ptr.load %i : ptr -> i32
%18 = i32.constant 2
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
ptr.store %addtmp, %i : i32, ptr
cf.br ^while.cond
^while.end:
; 0 to:100 step:2
%19 = i32.constant 0
%20 = i32.constant 100
%21 = i32.constant 2
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
%for.iv.0 = ivy.msg.send to %22, value -> #ivy.id
cf.br ^for.cond(%for.iv.0: #ivy.id)
^for.step:
ivy.msg.send to %22, move-next -> void
%for.iv.next = ivy.msg.send to %22, value -> #ivy.id
cf.br ^for.cond(%for.iv.next: #ivy.id)
^for.cond(%iv: #ivy.id):
%for.valid = ivy.is-null-ref %iv : #ivy.id -> i1
cf.br-cond %for.valid, ^for.body(%iv: #ivy.id), ^for.end
^for.body(%x: #ivy.id):
; for x in 0 to:100 step:2 do
%23 = ivy.msg.send to %StringBuilder, new -> #ivy.id
; 'Count is {x}'
%24 = ivy.str.constant "Count is "
ivy.msg.send to %23, append:%24 -> void
ivy.msg.send to %23, append:%x -> void
%25 = ivy.msg.send to %23, to-string -> #ivy.id
; cout put:"Count is {x}"
%26 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %26, put:%25 -> void
cf.br ^for.step
^for.end:
; 0 to:100 step:2 do:...
%27 = i32.constant 0
%28 = i32.constant 100
%29 = i32.constant 2
; [ :i | cout put:'Count: {i}' ]
%30 = ivy.lambda.create %lambda.0 -> #ivy.id
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
ivy.msg.send to %27, to:%28 step:%29 do:%30
; q = 32.
%q = ptr.alloca i32 -> ptr
%31 = i32.constant 32
ptr.store %31, %q : i32, ptr
; l = [ cout put:'Value of q is {q}' ].
%l = ptr.alloca #ivy.id
%32 = ptr.load %q : ptr -> i32
%lambda.env = ivy.pkg.create -> #ivy.id
ivy.pkg.put %lambda.env[@q] = %32 : (#ivy.id, #ivy.id)
%33 = ivy.lambda.create <%lambda.env> %lambda.1 -> #ivy.id
ptr.store %33, %l : #ivy.id, ptr
; q = 64.
%34 = i32.constant 64
ptr.store %34, %q : i32, ptr
; l call.
%35 = ptr.load %l : ptr -> #ivy.id
ivy.msg.send to %35, call -> void
%j = ptr.alloca i32 -> ptr
%36 = i32.constant 32
ptr.store %36, %j : i32, ptr
%37 = ptr.load %i : ptr -> i32
%38 = ptr.load %j : ptr -> i32
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
%39 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "True!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
%40 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "False!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
%41 = ptr.load %i : ptr -> i32
%42 = ptr.load %j : ptr -> i32
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
scf.if %cmptmp.0 -> void {
%43 = ivy.str.constant "True!"
%44 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %44, put:%43 -> void
}
; pkg = {}.
%pkg = ptr.alloca #ivy.id -> ptr
%45 = ivy.pkg.create -> #ivy.id
ptr.store %45, %pkg : #ivy.id, ptr
; pkg[0] = 16.
%46 = ptr.load %pkg : ptr -> #ivy.id
%47 = i32.constant 0
%48 = i32.constant 16
ivy.msg.send to %46, at:%47 put:%48 -> void
; tuple = (32, 'a string')
%tuple = ptr.alloca #ivy.id -> ptr
%49 = i32.constant 32
%50 = ivy.str.constant "a string"
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
ptr.store %51, %tuple : #ivy.id, ptr
%52 = ptr.load %tuple : ptr -> #ivy.id
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
ivy.for %54 in %53 -> void {
%key = ivy.tuple.get-item %54[0] : #ivy.id -> #ivy.id
%val = ivy.tuple.get-item %54[1] : #ivy.id -> #ivy.id
; '{key} -> {val}'
%55 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %55, append:%key -> void
%56 = ivy.str.constant " -> "
ivy.msg.send to %55, append:%56 -> void
ivy.msg.send to %55, append:%val -> void
%57 = ivy.msg.send to %23, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%58 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %58, put:%57 -> void
}
; _ = 3 * 2.
%59 = i32.constant 3
%60 = i32.constant 2
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
; a = (32, 64).
%a = ptr.alloca #ivy.id -> ptr
%61 = i32.constant 32
%62 = i32.constant 64
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
ptr.store %63, %a : #ivy.id, ptr
%v = ptr.alloca #ivy.id -> ptr
%64 = ptr.load %a : ptr -> #ivy.id
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
ptr.store %65, %v : #ivy.id, ptr
%66 = ivy.atom "err:number-format"
ivy.try -> void {
} catch (%ex = %66), %data {
} catch-all %ex, %data {
}
%67 = ivy.lambda : () -> void {
%v = ptr.alloca #ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr
%0 = ivy.str.constant "342"
%1 = ivy.msg.send to %Int, parse:%0
ptr.store %1, %v : #ivy.id, ptr
}
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %0, append:%key -> void
%1 = ivy.str.constant "Cannot parse integer string ("
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%err -> void
%2 = ivy.str.constant ")"
ivy.msg.send to %0, append:%2 -> void
%3 = ivy.msg.send to %0, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%4 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %4, put:%3 -> void
}
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %0, append:%key -> void
%1 = ivy.str.constant "Error "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%err -> void
%2 = ivy.str.constant " occurred ("
ivy.msg.send to %0, append:%2 -> void
ivy.msg.send to %0, append:%data -> void
%3 = ivy.str.constant ")"
%4 = ivy.msg.send to %0, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%5 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %5, put:%4 -> void
}
%70 = ivy.atom "err:number-format"
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
ivy.msg.send to %67, on-error:%69 -> void
ivy.msg.send to %67, call -> void
}
}

535
doc/mie/sample/Person.3.mie Normal file
View File

@@ -0,0 +1,535 @@
meta.source-filename "Person.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.global-ref @cout -> ptr
%StringBuilder = ivy.global-ref @StringBuilder : ptr
ivy.class @Person {
%self.name = ivy.object-var @name : #ivy.id -> ptr
%self.age = ivy.object-var @age : #ivy.id -> ptr
%self.val = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
%lambda.0 = ivy.lambda.body <%env> (%i: #ivy.id) -> void {
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%1 = ivy.str.constant "Count is "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%i -> void
%2 = ivy.msg.send to %0, to-string -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
func.return : ()
}
%lambda.1 = ivy.lambda.body <%env> () -> void {
%env.q = ivy.pkg.get %env[@q] : #ivy.id -> #ivy.id
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%1 = ivy.str.constant "Value of q is "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%env.q -> void
%2 = ivy.msg.send to %0, to-string -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
}
ivy.object.func init(name:%name, age:%age) -> void {
ptr.store %name, %self.name : #ivy.id, ptr
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.object.func test(param:%data, _:%extra) -> void {
%0 = ptr.load %StringBuilder : ptr -> #ivy.id
%1 = ivy.msg.send to %0, new -> #ivy.id
%2 = ivy.str.constant "Received "
ivy.msg.send to %1, append:%2 -> void
ivy.msg.send to %1, append:%data -> void
%3 = ivy.str.constant ", "
ivy.msg.send to %1, append:%3 -> void
ivy.msg.send to %1, append:%extra -> void
%4 = ivy.msg.send to %1, to-string -> #ivy.id
%5 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %5, put:%4 -> void
func.return : ()
}
ivy.object.func name -> #ivy.id {
%0 = ptr.load %self.name : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.object.func age -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.object.func age-in-months -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
%1 = i32.constant 12
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
func.return %multmp : #ivy.id
}
ivy.object.func set-name:%name -> void {
ptr.store %name, %self.name : #ivy.id, ptr
func.return : ()
}
ivy.object.func set-age:%age -> void {
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.object.func set-age:%age in-units:%units -> void {
^switch.cond.0:
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
^switch.body.0:
ptr.store %age, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.cond.1:
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
^switch.body.1:
%d0 = i32.constant 12
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.cond.2:
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
^switch.body.2:
%d1 = i32.constant 365
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.default:
%d2 = i32.constant 0
ptr.store %d2, %self.age : #ivy.id, ptr
cf.br ^switch.end.0
^switch.end:
func.return : ()
}
ivy.object.func get-age-in-units:%units -> #ivy.id {
^switch.cond.0:
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.0, ^switch.body.0, ^switch.cond.1
^switch.body.0:
%v0 = ptr.load %self.age : ptr -> #ivy.id
cf.br ^switch.end(%v0: #ivy.id)
^switch.cond.1:
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.1, ^switch.body.1, ^switch.cond.2
^switch.body.1:
%v0 = ptr.load %self.age : ptr -> #ivy.id
%d0 = i32.constant 12
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
cf.br ^switch.end(%divtmp.0: #ivy.id)
^switch.cond.2:
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
cf.br-cond %cmptmp.2, ^switch.body.2, ^switch.default
^switch.body.2:
%v1 = ptr.load %self.age : ptr -> #ivy.id
%d1 = i32.constant 365
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
cf.br ^switch.end(%divtmp.1: #ivy.id)
^switch.default:
%d2 = i32.constant 0
cf.br ^switch.end(%d2.1: i32)
^switch.end(%result: #ivy.id):
func.return %result : #ivy.id
}
ivy.object.prop example-property
get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
}
set (%value: #ivy.id) {
ptr.store %value, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object.prop example-property-2 get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%x: #ivy.id) {
ptr.store %x, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object.prop example-property-3 get {
%0 = i32.constant 42
func.return %0 : i32
}
ivy.object.prop example-property-4 get {
%0 = ptr.load %self.p-example-property-4 : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%0: #ivy.id) {
ptr.store %0, %self.p-example-property-4 : #ivy.id, ptr
func.return : ()
}
ivy.object.prop example-property-5 get {
%0 = ptr.load %self.p-example-property-5 : ptr -> #ivy.id
func.return %0 : #ivy.id
}
}
ivy.init-text {
; p1 = Person new(name:'John Doe', age:34).
%Person = ivy.global-ref @Person : ptr
%0 = ivy.str.constant "John Doe"
%1 = i32.constant 34
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
%p1 = ptr.alloca #ivy.id -> ptr
ptr.store %2, %p1 : #ivy.id, ptr
; p1 set-age:100 in-unit:$months.
%3 = ptr.load %p1 : ptr -> #ivy.id
%4 = i32.constant 100
%5 = ivy.atom "months"
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
; p1 test(param:'Hello', 'World').
%6 = ptr.load %p1 : ptr -> #ivy.id
%7 = ivy.str.constant "Hello"
%8 = ivy.str.constant "World"
ivy.msg.send to %6, test(param:%7, _:%8) -> void
; i = 0.
%i = ptr.alloca i32 -> ptr
%9 = i32.constant 0
ptr.store %9, %i : i32, ptr
cf.br ^while.cond
; while i < 100 do
^while.cond:
; i < 100
%10 = ptr.load %i : ptr -> i32
%11 = i32.constant 100
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
scf.condition(%cmptmp)
cf.br-cond %cmptmp, ^while.body, ^while.end
^while.body:
; cout put:'Count is {i}'.
%12 = ivy.msg.send to %StringBuilder, new -> #ivy.id
%13 = ivy.str.constant "Count is "
ivy.msg.send to %12, append:%13 -> void
%14 = ptr.load %i : ptr -> i32
ivy.msg.send to %12, append:14 -> void
%15 = ivy.msg.send to %12, to-string -> #ivy.id
%16 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %16, put:%15 -> void
; i += 2
%17 = ptr.load %i : ptr -> i32
%18 = i32.constant 2
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
ptr.store %addtmp, %i : i32, ptr
cf.br ^while.cond
^while.end:
; 0 to:100 step:2
%19 = i32.constant 0
%20 = i32.constant 100
%21 = i32.constant 2
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
cf.br ^for.init(%22: #ivy.id)
^for.init(%it: #ivy.id):
%for.iv.0 = ivy.msg.send to %it, value -> #ivy.id
cf.br ^for.cond(%it: #ivy.id, %for.iv.0: #ivy.id)
^for.step(%it: #ivy.id):
ivy.msg.send to %22, move-next -> void
%for.iv.next = ivy.msg.send to %22, value -> #ivy.id
cf.br ^for.cond(%it: #ivy.id, %for.iv.next: #ivy.id)
^for.cond(%it: #ivy.id, %iv: #ivy.id):
%for.valid = ivy.is-null-ref %iv : #ivy.id -> i1
cf.br-cond %for.valid, ^for.body(%it: #ivy.id, %iv: #ivy.id), ^for.end
^for.body(%it: #ivy.id, %x: #ivy.id):
; for x in 0 to:100 step:2 do
%23 = ivy.msg.send to %StringBuilder, new -> #ivy.id
; 'Count is {x}'
%24 = ivy.str.constant "Count is "
ivy.msg.send to %23, append:%24 -> void
ivy.msg.send to %23, append:%x -> void
%25 = ivy.msg.send to %23, to-string -> #ivy.id
; cout put:"Count is {x}"
%26 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %26, put:%25 -> void
cf.br ^for.step(%it: #ivy.id)
^for.end:
; 0 to:100 step:2 do:...
%27 = i32.constant 0
%28 = i32.constant 100
%29 = i32.constant 2
; [ :i | cout put:'Count: {i}' ]
%30 = ivy.lambda.create %lambda.0 -> #ivy.id
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
ivy.msg.send to %27, to:%28 step:%29 do:%30
; q = 32.
%q = ptr.alloca i32 -> ptr
%31 = i32.constant 32
ptr.store %31, %q : i32, ptr
; l = [ cout put:'Value of q is {q}' ].
%l = ptr.alloca #ivy.id
%32 = ptr.load %q : ptr -> i32
%lambda.env = ivy.pkg.create -> #ivy.id
ivy.pkg.put %lambda.env[@q] = %32 : (#ivy.id, #ivy.id)
%33 = ivy.lambda.create <%lambda.env> %lambda.1 -> #ivy.id
ptr.store %33, %l : #ivy.id, ptr
; q = 64.
%34 = i32.constant 64
ptr.store %34, %q : i32, ptr
; l call.
%35 = ptr.load %l : ptr -> #ivy.id
ivy.msg.send to %35, call -> void
%j = ptr.alloca i32 -> ptr
%36 = i32.constant 32
ptr.store %36, %j : i32, ptr
%37 = ptr.load %i : ptr -> i32
%38 = ptr.load %j : ptr -> i32
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
%39 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "True!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
%40 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "False!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
%41 = ptr.load %i : ptr -> i32
%42 = ptr.load %j : ptr -> i32
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
scf.if %cmptmp.0 -> void {
%43 = ivy.str.constant "True!"
%44 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %44, put:%43 -> void
}
; pkg = {}.
%pkg = ptr.alloca #ivy.id -> ptr
%45 = ivy.pkg.create -> #ivy.id
ptr.store %45, %pkg : #ivy.id, ptr
; pkg[0] = 16.
%46 = ptr.load %pkg : ptr -> #ivy.id
%47 = i32.constant 0
%48 = i32.constant 16
ivy.msg.send to %46, at:%47 put:%48 -> void
; tuple = (32, 'a string')
%tuple = ptr.alloca #ivy.id -> ptr
%49 = i32.constant 32
%50 = ivy.str.constant "a string"
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
ptr.store %51, %tuple : #ivy.id, ptr
%52 = ptr.load %tuple : ptr -> #ivy.id
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
ivy.for %54 in %53 -> void {
%key = ivy.tuple.get-item %54[0] : #ivy.id -> #ivy.id
%val = ivy.tuple.get-item %54[1] : #ivy.id -> #ivy.id
; '{key} -> {val}'
%55 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %55, append:%key -> void
%56 = ivy.str.constant " -> "
ivy.msg.send to %55, append:%56 -> void
ivy.msg.send to %55, append:%val -> void
%57 = ivy.msg.send to %23, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%58 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %58, put:%57 -> void
}
; _ = 3 * 2.
%59 = i32.constant 3
%60 = i32.constant 2
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
; a = (32, 64).
%a = ptr.alloca #ivy.id -> ptr
%61 = i32.constant 32
%62 = i32.constant 64
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
ptr.store %63, %a : #ivy.id, ptr
%v = ptr.alloca #ivy.id -> ptr
%64 = ptr.load %a : ptr -> #ivy.id
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
ptr.store %65, %v : #ivy.id, ptr
%66 = ivy.atom "err:number-format"
ivy.try -> void {
} catch (%ex = %66), %data {
} catch-all %ex, %data {
}
%67 = ivy.lambda : () -> void {
%v = ptr.alloca #ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr
%0 = ivy.str.constant "342"
%1 = ivy.msg.send to %Int, parse:%0
ptr.store %1, %v : #ivy.id, ptr
}
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %0, append:%key -> void
%1 = ivy.str.constant "Cannot parse integer string ("
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%err -> void
%2 = ivy.str.constant ")"
ivy.msg.send to %0, append:%2 -> void
%3 = ivy.msg.send to %0, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%4 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %4, put:%3 -> void
}
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.msg.send to %StringBuilder, new -> #ivy.id
ivy.msg.send to %0, append:%key -> void
%1 = ivy.str.constant "Error "
ivy.msg.send to %0, append:%1 -> void
ivy.msg.send to %0, append:%err -> void
%2 = ivy.str.constant " occurred ("
ivy.msg.send to %0, append:%2 -> void
ivy.msg.send to %0, append:%data -> void
%3 = ivy.str.constant ")"
%4 = ivy.msg.send to %0, to-string -> #ivy.id
; cout put:'{key} -> {val}'
%5 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %5, put:%4 -> void
}
%70 = ivy.atom "err:number-format"
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
ivy.msg.send to %67, on-error:%69 -> void
ivy.msg.send to %67, call -> void
}
}

View File

@@ -1,146 +1,460 @@
record package_scope = str "net.doorstuck.test"
meta.source-filename "Person.im"
record import = { str "std.io" }
ivy.package-scope "net.doorstuck.test"
data @cout = external global id
data @StringBuffer = external global id
ivy.package-ref "std.io"
data @.str.0 = str "Received "
data @.str.1 = str ", "
ivy.module {
%cout = ivy.global-ref @cout -> ptr
data @.atom.0 = atom "years"
data @.atom.1 = atom "months"
data @.atom.2 = atom "days"
ivy.class @Person {
%self.name = ivy.object-var @name : #ivy.id -> ptr
%self.age = ivy.object-var @age : #ivy.id -> ptr
%self.val = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
type @_ZN3net9doorstuck4testC6PersonE = class {
id @name,
id @age,
id @val
}
define void @_ZN3net9doorstuck4testC6PersonM4init4name3ageE(id %self, id %0) instance {
entry:
%1 = getelementptr class @_ZN3net9doorstuck4testC6PersonE, id %self, i32 #0
store id %0, ptr %1
%2 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
store id %1, ptr %2
ret void
}
define void @_ZN3net9doorstuck4testC6PersonM4test5param0E(id %0, id %1) instance {
entry:
%2 = load id, ptr @cout
; %4 = StringBuilder new
%3 = load id, ptr @StringBuilder
%4 = msg id %3, @_M3newE
; (void) tempstr append:'Received '
%5 = load id, ptr @.str.0
msg void, id %3, @_M06appendE [id %5]
; (void) tempstr append:data (param 0)
msg void, id %3, @_M06appendE [id %0]
; (void) tempstr append:', '
%6 = load id, ptr @.str.1
msg void, id %3, @_M06appendE [id %6]
; [void] tempstr append:extra (param 1)
msg void, id %3, @_M06appendE [id %1]
; %7 = tempstr toString
%7 = msg id, id %3, @_M8toStringE
; cout put:'Received {data}, {extra}'
msg void, id %2, @_M03put [id %7]
ret void
}
define id @_ZN3net9doorstuck4testC6PersonM4nameE(id %self) instance {
entry:
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #0
%1 = load id, ptr %0
ret id %1
}
define id @_ZN3net9doorstuck4testC6PersonM3ageE(id %self) instance {
entry:
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
%1 = load id, ptr %0
ret id %1
}
define id @_ZN3net9doorstuck4testC6PersonM11ageInMonthsE(id %self, id %0) instance {
entry:
%1 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
%2 = load id, ptr %1
ret id %1
}
define void @_ZN3net9doorstuck4testC6PersonM07setNameE(id %self, id %1) instance {
entry:
%2 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
store id %1, ptr %2
ret void
}
define void @_ZN3net9doorstuck4testC6PersonM06setAge6inUnitE(id %self, i32 %1, id %2) instance {
entry:
%3 = load atom, ptr @.atom.0
%4 = load atom, ptr @.atom.1
%5 = load atom, ptr @.atom.2
switch id %2, label %default [
atom %3, label %years
atom %4, label %months
atom %5, label %days
]
years:
%6 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
store i32 %2, ptr %6
br label %end
months:
%7 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
%8 = div i32 %2, #12
store i32 %8, ptr %7
br label %end
days:
%9 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
%10 = div i32 %2, #365
store i32 %10, ptr %9
br label %end
default:
%11 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #1
store i32 #0, ptr %11
br label %end
end:
ret void
}
define id @_ZN3net9doorstuck4testC6PersonM012getAgeInUnitE(id %0, id %1) instance {
entry:
}
define id @_ZN3net9doorstuck4testC6PersonP15examplePropertyG(id %self) instance {
entry:
%0 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #2
%1 = load id, ptr %0
ret id %1
}
define void @_ZN3net9doorstuck4testC6PersonP15examplePropertyS(id %self, id %0) instance {
entry:
%1 = getelementptr class @_ZN33net9doorstuck4testC6PersonE, id %self, i32 #2
store id %0, ptr %1
ret void
ivy.msgh.object init(name:%name, age:%age) -> void {
ptr.store %name, %self.name : #ivy.id, ptr
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.msgh.object test(param:%data, _:%extra) -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Received "
ivy.string-builder.add %0 << %data : #ivy.id
ivy.string-builder.add %0 << ", "
ivy.string-builder.add %0 << %extra : #ivy.id
%1 = ivy.string-builder.end %0 -> #ivy.id
%2 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %2, put:%1 -> void
func.return : ()
}
ivy.msgh.object name -> #ivy.id {
%0 = ptr.load %self.name : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.msgh.object age -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
func.return %0 : #ivy.id
}
ivy.msgh.object age-in-months -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
%1 = i32.constant 12
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
func.return %multmp : #ivy.id
}
ivy.msgh.object set-name:%name -> void {
ptr.store %name, %self.name : #ivy.id, ptr
func.return : ()
}
ivy.msgh.object set-age:%age -> void {
ptr.store %age, %self.age : #ivy.id, ptr
func.return : ()
}
ivy.msgh.object set-age:%age in-units:%units -> void {
scf.switch : () -> void
case {
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
scf.switch-condition %cmptmp.0
} then {
ptr.store %age, %self.age : #ivy.id, ptr
scf.switch-break : ()
} case {
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
scf.condition %cmptmp.1
} then {
%d0 = i32.constant 12
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
scf.switch-break : ()
} case {
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
scf.condition %cmptmp.2
} then {
%d1 = i32.constant 365
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
scf.switch-break : ()
} default {
%d2 = i32.constant 0
scf.switch-break : ()
}
func.return : ()
}
ivy.msgh.object get-age-in-units:%units -> #ivy.id {
%result = scf.switch : () -> #ivy.id
case {
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
scf.switch-condition %cmptmp.0
} then {
%v0 = ptr.load %self.age : ptr -> #ivy.id
scf.switch-break %v0 : #ivy.id
} case {
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
scf.condition %cmptmp.1
} then {
%v0 = ptr.load %self.age : ptr -> #ivy.id
%d0 = i32.constant 12
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
scf.switch-break %divtmp.0 : #ivy.id
} case {
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
scf.condition %cmptmp.2
} then {
%v1 = ptr.load %self.age : ptr -> #ivy.id
%d1 = i32.constant 365
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
scf.switch-break %divtmp.1 : #ivy.id
} default {
%d2 = i32.constant 0
scf.switch-break %d2 : #ivy.id
}
func.return %result : #ivy.id
}
ivy.object-prop example-property
get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
}
set (%value: #ivy.id) {
ptr.store %value, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-2 get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%x: #ivy.id) {
ptr.store %x, %self.val : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-3 get {
%0 = i32.constant 42
func.return %0 : i32
}
ivy.object-prop example-property-4 get {
%0 = ptr.load %self.__example-property-4 : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%0: #ivy.id) {
ptr.store %0, %self.__example-property-4 : #ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-5 get {
%0 = ptr.load %self.__example-property-5 : ptr -> #ivy.id
func.return %0 : #ivy.id
}
}
ivy.init-text {
; p1 = Person new(name:'John Doe', age:34).
%Person = ivy.global-ref @Person : ptr
%0 = ivy.str.constant "John Doe"
%1 = i32.constant 34
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
%p1 = ptr.alloca #ivy.id -> ptr
ptr.store %2, %p1 : #ivy.id, ptr
; p1 set-age:100 in-unit:$months.
%3 = ptr.load %p1 : ptr -> #ivy.id
%4 = i32.constant 100
%5 = ivy.atom "months"
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
; p1 test(param:'Hello', 'World').
%6 = ptr.load %p1 : ptr -> #ivy.id
%7 = ivy.str.constant "Hello"
%8 = ivy.str.constant "World"
ivy.msg.send to %6, test(param:%7, _:%8) -> void
; i = 0.
%i = ptr.alloca i32 -> ptr
%9 = i32.constant 0
ptr.store %9, %i : i32, ptr
; while i < 100 do
scf.while -> void {
; i < 100
%10 = ptr.load %i : ptr -> i32
%11 = i32.constant 100
%cmptmp = ivy.cmp lt %10, %11 : (i32, i32) -> i1
scf.condition(%cmptmp)
} do {
; cout put:'Count is {i}'.
%12 = ivy.string-builder.begin
ivy.string-builder.add %12 << "Count is "
%14 = ptr.load %i : ptr -> i32
ivy.string-builder.add %12 << %14 : i32
%15 = ivy.string-builder.end %12 -> #ivy.id
%16 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %16, put:%15 -> void
; i += 2
%17 = ptr.load %i : ptr -> i32
%18 = i32.constant 2
%addtmp = ivy.add %17, %18 : (i32, i32) -> i32
ptr.store %addtmp, %i : i32, ptr
}
; 0 to:100 step:2
%19 = i32.constant 0
%20 = i32.constant 100
%21 = i32.constant 2
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
; for x in 0 to:100 step:2 do
ivy.for %x in %22 -> void {
%23 = ivy.string-builder.begin
; 'Count is {x}'
ivy.string-builder.add %23 << "Count is "
ivy.string-builder.add %23 << %x : #ivy.id
%25 = ivy.string-builder.end %23 -> #ivy.id
; cout put:"Count is {x}"
%26 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %26, put:%25 -> void
}
; 0 to:100 step:2 do:...
%27 = i32.constant 0
%28 = i32.constant 100
%29 = i32.constant 2
; [ :i | cout put:'Count: {i}' ]
%30 = ivy.lambda %i : (#ivy.id) -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Count is "
ivy.string-builder.add %0 << %i : #ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
}
; 0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
ivy.msg.send to %27, to:%28 step:%29 do:%30
; q = 32.
%q = ptr.alloca i32 -> ptr
%31 = i32.constant 32
ptr.store %31, %q : i32, ptr
; l = [ cout put:'Value of q is {q}' ].
%l = ptr.alloca #ivy.id
%32 = ptr.load %q : ptr -> i32
%33 = ivy.lambda (%env.q = %32) : () -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Value of q is "
ivy.string-builder.add %0 << %env.q : #ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %3, put:%2 -> void
}
ptr.store %33, %l : #ivy.id, ptr
; q = 64.
%34 = i32.constant 64
ptr.store %34, %q : i32, ptr
; l call.
%35 = ptr.load %l : ptr -> #ivy.id
ivy.msg.send to %35, call -> void
%j = ptr.alloca i32 -> ptr
%36 = i32.constant 32
ptr.store %36, %j : i32, ptr
%37 = ptr.load %i : ptr -> i32
%38 = ptr.load %j : ptr -> i32
%cmptmp = arith.cmp lt %37, %38 : (i32, i32) -> i1
%39 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "True!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
%40 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "False!"
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %1, put:%0 -> void
}
ivy.msg.send to %cmptmp, if:%39 else:%40 -> void
%41 = ptr.load %i : ptr -> i32
%42 = ptr.load %j : ptr -> i32
%cmptmp.0 = arith.cmp lt %41, %42 : (i32, i32) -> i1
scf.if %cmptmp.0 -> void {
%43 = ivy.str.constant "True!"
%44 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %44, put:%43 -> void
}
; pkg = {}.
%pkg = ptr.alloca #ivy.id -> ptr
%Package = ivy.global-ref @std.lang.Package -> ptr
%45 = ivy.msg.send to %Package, new -> #ivy.id
ptr.store %45, %pkg : #ivy.id, ptr
; pkg[0] = 16.
%46 = ptr.load %pkg : ptr -> #ivy.id
%47 = i32.constant 0
%48 = i32.constant 16
ivy.msg.send to %46, at:%47 put:%48 -> void
; tuple = (32, 'a string')
%tuple = ptr.alloca #ivy.id -> ptr
%49 = i32.constant 32
%50 = ivy.str.constant "a string"
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
ptr.store %51, %tuple : #ivy.id, ptr
%52 = ptr.load %tuple : ptr -> #ivy.id
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
ivy.for %54 in %53 -> void {
%key = ivy.tuple.get-item %54[0] : (#ivy.id, i32) -> #ivy.id
%val = ivy.tuple.get-item %54[1] : (#ivy.id, i32) -> #ivy.id
; '{key} -> {val}'
%55 = ivy.string-builder.begin
ivy.string-builder.add %55 << %key : #ivy.id
ivy.string-builder.add %55 << " -> "
ivy.string-builder.add %55 << %val : #ivy.id
%57 = ivy.string-builder.end %55 -> #ivy.id
; cout put:'{key} -> {val}'
%58 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %58, put:%57 -> void
}
; _ = 3 * 2.
%59 = i32.constant 3
%60 = i32.constant 2
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
; a = (32, 64).
%a = ptr.alloca #ivy.id -> ptr
%61 = i32.constant 32
%62 = i32.constant 64
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
ptr.store %63, %a : #ivy.id, ptr
%v = ptr.alloca #ivy.id -> ptr
%64 = ptr.load %a : ptr -> #ivy.id
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
ptr.store %65, %v : #ivy.id, ptr
%66 = ivy.atom "err:number-format"
ivy.try -> void {
} catch (%ex = %66), %data {
} catch-all %ex, %data {
}
%67 = ivy.lambda : () -> void {
%v = ptr.alloca #ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr
%0 = ivy.str.constant "342"
%1 = ivy.msg.send to %Int, parse:%0
ptr.store %1, %v : #ivy.id, ptr
}
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Cannot parse integer string ("
ivy.string-builder.add %0 << %err : #ivy.id
ivy.string-builder.add %0 << ")"
%3 = ivy.string-builder.end %0 -> #ivy.id
; cout put:'{key} -> {val}'
%4 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %4, put:%3 -> void
}
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%0 = ivy.string-builder.create
ivy.string-builder.add %0 << "Error "
ivy.string-builder.add %0 << %err : #ivy.id
ivy.string-builder.add %0 << " occurred ("
ivy.string-builder.add %0 << %data : #ivy.id
ivy.string-builder.add %0 << ")"
%4 = ivy.string-builder.end %0 -> #ivy.id
; cout put:'{key} -> {val}'
%5 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %5, put:%4 -> void
}
%70 = ivy.atom "err:number-format"
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
ivy.msg.send to %67, on-error:%69 -> void
ivy.msg.send to %67, call -> void
}
}

View File

@@ -0,0 +1,46 @@
meta.source-filename "Simple.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
ivy.init-text {
%0 = i32.constant 32
%1 = i32.constant 64
%multmp = arith.mul %0, %1 : (i32, i32) -> i32
%y = ptr.alloca i32
ptr.store %multmp, %y : i32, ptr
%2 = i32.constant 64
%3 = i32.constant 4
%divtmp = arith.div %2, %3 : (i32, i32) -> i32
%z = ptr.alloca i32
ptr.store %divtmp, %z : i32, ptr
%4 = ptr.load %y : ptr -> i32
%5 = ptr.load %z : ptr -> i32
%addtmp = arith.add %4, %5 : (i32, i32) -> i32
%x = ptr.alloca i32
ptr.store %addtmp, %x : i32, ptr
%cout = ivy.global-ref @cout -> ptr
%6 = ivy.string-builder.begin
ivy.string-builder.add %6 << "Answer: "
%7 = ptr.load %x : ptr -> i32
ivy.string-builder.add %6 << %7 : i32
%8 = ivy.string-builder.end %6 -> #ivy.id
%9 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %9, put:%8 -> void
func.return : ()
}
}

View File

@@ -0,0 +1,50 @@
meta.source-filename "Simple.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.global-ref @cout -> ptr
%StringBuilder = ivy.global-ref @std.lang.StringBuilder -> ptr
%.str.0 = ivy.str.constant "Answer: "
ivy.init-text {
%0 = i32.constant 32
%1 = i32.constant 64
%multmp = arith.mul %0, %1 : (i32, i32) -> i32
%y = ptr.alloca i32
ptr.store %multmp, %y : i32, ptr
%2 = i32.constant 64
%3 = i32.constant 4
%divtmp = arith.div %2, %3 : (i32, i32) -> i32
%z = ptr.alloca i32
ptr.store %divtmp, %z : i32, ptr
%4 = ptr.load %y : ptr -> i32
%5 = ptr.load %z : ptr -> i32
%addtmp = arith.add %4, %5 : (i32, i32) -> i32
%x = ptr.alloca i32
ptr.store %addtmp, %x : i32, ptr
%10 = ptr.load %StringBuilder : ptr -> #ivy.id
ivy.msg.send to %10, append:%.str.0 -> void
%7 = ptr.load %x : ptr -> i32
ivy.msg.send to %10, append:%7 -> void
%8 = ivy.msg.send to %10, to-string -> #ivy.id
%9 = ptr.load %cout : ptr -> #ivy.id
ivy.msg.send to %9, put:%8 -> void
func.return : ()
}
}

View File

@@ -0,0 +1,63 @@
meta.source-filename "Simple.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
ivy.init-text {
%0 = i32.constant 32
%1 = i32.constant 64
%multmp = *ivy.MUL %0, %1 : (i32, i32) -> i32
*ivy.PUSH %multmp : i32
%y = ivy.bp-slot 0 -> #ivy.bp-slot
%2 = i32.constant 64
%3 = i32.constant 4
%divtmp = *ivy.DIV %2, %3 : (i32, i32) -> i32
*ivy.PUSH %divtmp : i32
%z = ivy.bp-slot 1 -> #ivy.bp-slot
%4 = *ivy.LDR-BP %y : #ivy.bp-slot -> i32
%5 = *ivy.LDR-BP %z : #ivy.bp-slot -> i32
%addtmp = *ivy.ADD %4, %5 : (i32, i32) -> i32
*ivy.PUSH %addtmp : i32
%x = ivy.bp-slot 2 -> #ivy.bp-slot
%10 = *ivy.LDR-POOL %StringBuilder : #ivy.pool-slot -> #ivy.id
%20 = *ivy.LDR-POOL %.sel.o-append : #ivy.pool-slot -> #ivy.id
%21 = *ivy.LDR-POOL %.str.0 : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %21 : #ivy.id
*ivy.MSG-I %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
%7 = *ivy.LDR-BP %x : ptr -> i32
*ivy.PUSH %7 : i32
%22 = *ivy.LDR-POOL %.sel.o-append : #ivy.pool-slot -> #ivy.id
*ivy.MSG-I %10, %22, 1 : (#ivy.id, #ivy.id, i32) -> void
%23 = *ivy.LDR-POOL %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
%8 = *ivy.MSG-I %10, %23, 0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
%9 = *ivy.LDR-POOL %cout : #ivy.pool-slot -> #ivy.id
%24 = *ivy.LDR-POOL %.sel.o-put : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %8 : #ivy.id
*ivy.MSG-I %9, %24, 1 : (#ivy.id, #ivy.id, i32) -> void
*ivy.RET-N : ()
}
}

View File

@@ -0,0 +1,62 @@
meta.source-filename "Simple.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
ivy.init-text {
%0 = i32.constant 32
%1 = i32.constant 64
%multmp = *ivy.MUL %0, %1 : (i32, i32) -> i32
*ivy.PUSH %multmp : i32
%y = ivy.bp-slot 0 -> #ivy.bp-slot
%2 = i32.constant 64
%3 = i32.constant 4
%divtmp = *ivy.DIV %2, %3 : (i32, i32) -> i32
*ivy.PUSH %divtmp : i32
%z = ivy.bp-slot 1 -> #ivy.bp-slot
%4 = *ivy.LDR %y : #ivy.bp-slot -> i32
%5 = *ivy.LDR %z : #ivy.bp-slot -> i32
%addtmp = *ivy.ADD %4, %5 : (i32, i32) -> i32
*ivy.PUSH %addtmp : i32
%x = ivy.bp-slot 2 -> #ivy.bp-slot
%10 = *ivy.LDR %StringBuilder : #ivy.pool-slot -> #ivy.id
%20 = *ivy.LDR %.sel.o-append : #ivy.pool-slot -> #ivy.id
%21 = *ivy.LDR %.str.0 : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %21 : #ivy.id
*ivy.MSG %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
%7 = *ivy.LDR %x : ptr -> i32
*ivy.PUSH %7 : i32
*ivy.MSG %10, %20, 1 : (#ivy.id, #ivy.id, i32) -> void
%23 = *ivy.LDR %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
%8 = *ivy.MSG %10, %23, 0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
%9 = *ivy.LDR %cout : #ivy.pool-slot -> #ivy.id
%24 = *ivy.LDR %.sel.o-put : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %8 : #ivy.id
*ivy.MSG %9, %24, 1 : (#ivy.id, #ivy.id, i32) -> void
*ivy.RET-N : ()
}
}

View File

@@ -0,0 +1,68 @@
meta.source-filename "Simple.im"
ivy.package-scope "net.doorstuck.test"
ivy.package-ref "std.io"
ivy.module {
%cout = ivy.pool.ident @cout -> #ivy.pool-slot
%StringBuilder = ivy.pool.ident @std.lang.StringBuilder -> #ivy.pool-slot
%.str.0 = ivy.pool.string "Answer: " -> #ivy.pool-slot
%.sel.o-append = ivy.pool.selector append -> #ivy.pool-slot
%.sel.o-to-string = ivy.pool.selector to-string -> #ivy.pool-slot
%.sel.o-put = ivy.pool.selector put -> #ivy.pool-slot
%.i.0 = i32.constant 0
%.i.1 = i32.constant 1
%.i.4 = i32.constant 4
%.i.32 = i32.constant 32
%.i.64 = i32.constant 64
ivy.init-text {
$X0 = *ivy.LDR %.i.32 -> i32
$X1 = *ivy.LDR %.i.64 -> i32
$X2 = *ivy.MUL $X0, $X1 : (i32, i32) -> i32
*ivy.PUSH $X2 : i32
%.bp.0 = ivy.bp-slot 0 -> #ivy.bp-slot
$X4 = *ivy.LDR %.i.64 -> i32
$X5 = *ivy.LDR %.i.4 -> i32
$X6 = *ivy.DIV $X4, $X5 : (i32, i32) -> i32
*ivy.PUSH $X6 : i32
%.bp.1 = ivy.bp-slot 1 -> #ivy.bp-slot
$X8 = *ivy.LDR %.bp.0 : #ivy.bp-slot -> i32
$X9 = *ivy.LDR %.bp.1 : #ivy.bp-slot -> i32
$X10 = *ivy.ADD $X8, $X9 : (i32, i32) -> i32
*ivy.PUSH $X10 : i32
%.bp.2 = ivy.bp-slot 2 -> #ivy.bp-slot
%10 = *ivy.LDR %StringBuilder : #ivy.pool-slot -> #ivy.id
%20 = *ivy.LDR %.sel.o-append : #ivy.pool-slot -> #ivy.id
%21 = *ivy.LDR %.str.0 : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %21 : #ivy.id
*ivy.MSG %10, %20, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
%7 = *ivy.LDR %.bp.2 : ptr -> i32
*ivy.PUSH %7 : i32
*ivy.MSG %10, %20, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
%23 = *ivy.LDR %.sel.o-to-string : #ivy.pool-slot -> #ivy.id
%8 = *ivy.MSG %10, %23, %.i.0 : (#ivy.id, #ivy.id, i32) -> #ivy.id
%9 = *ivy.LDR %cout : #ivy.pool-slot -> #ivy.id
%24 = *ivy.LDR %.sel.o-put : #ivy.pool-slot -> #ivy.id
*ivy.PUSH %8 : #ivy.id
*ivy.MSG %9, %24, %.i.1 : (#ivy.id, #ivy.id, i32) -> void
*ivy.RET-N : ()
}
}

View File

@@ -1,46 +0,0 @@
data @cout = external global id
data @.str.0 = str "less"
data @.str.1 = str "more"
data @.str.2 = str "equal"
define void @init(id %self, id %0) static {
entry:
%x = alloca id
store i32 #2, ptr %x
%y = alloca id
store i32 #3, ptr %y
%1 = load i32, ptr %x
%2 = load i32, ptr %y
%3 = cmp lt i32 %1, %2
br i1 %3, label %if.true, label %if.false
if.true:
%4 = load id, ptr @cout
%5 = load str, ptr @.str.0
msg void, id %4, @_M03putE [str %5]
br label %if.end
if.false:
%6 = load i32, ptr %x
%7 = load i32, ptr %y
%8 = cmp gt i32 %6, %7
br i1 %8, label %if.true.0, label %if.false.0
if.true.0:
%9 = load id, ptr @cout
%10 = load str, ptr @.str.1
msg void, id %9, @_M03putE [str %10]
br label %if.end
if.false.0:
%11 = load id, ptr @cout
%12 = load str, ptr @.str.2
msg void, id %11, @_M03putE [str %12]
br label %if.end
if.end:
ret void
}

View File

@@ -1,4 +1,4 @@
y = 1 + 2 * 3 / 4 * 5 - 6 + 7 multiply-by:2.
y = -1 + 2 * 3 / 4 * 5 - 6 + 7 multiply-by:2.
z = w = 2 + 3 multiply-by:2.
x = (((1 + 2 * 3) multiply-by:3) add: 5) + 2.
x = ((1 + 2 * 3) multiply-by:3).
@@ -13,7 +13,7 @@ m = xz multiply(by:3 add:2) squared.
m = xz multiply(by:3 add:2); squared.
x = OrderedCollection new
x = Ordered-Collection new
add: 2;
add: 4;
add: 6;
@@ -21,7 +21,7 @@ x = OrderedCollection new
age = Person new(name:"John Doe", age:34)
set-age:144 in-unit:"months";
ageInMonths.
age-in-months.
x = 5.
q = 10 if x > 2 else 20.

View File

@@ -1,31 +1,15 @@
data @cout = external global id
ivy.module @test {
%cout = ivy.global-ref @cout
data @.str.0 = str "hello"
ivy.init-text {
%str = ivy.str.constant "hello"
%.str.0 = ivy.str.constant "done"
define void @init() static {
entry:
%0 = load str, ptr @.str.0
%str = alloca id
store str %0, ptr %str
ivy.for-each %c in %str {
ivy.msg to %cout, -put:%c
}
%1 = load id, ptr %str
%for.it = msg id, id %1, @_M8iteratorE
br label %for.cond
for.cond:
%for.value = msg id, id %for.it, @_M5valueE
%for.finished = cmp eq id %for.value, null
br i1 %for.finished, label %for.end, label %for.body
for.body:
%c = alloca id
store id %for.value, ptr %c
ivy.msg to %cout, -put:%.str.0
%2 = load id, ptr @cout
%3 = load id, ptr %c
msg void, id %2, @_M03putE [ id %3 ]
br label %for.inc
for.inc:
msg void, id %for.it, @_M8moveNextE
br label %for.cond
for.end:
ret void
}
}

562
doc/sample/Person.2.im Normal file
View File

@@ -0,0 +1,562 @@
/* example.im - An example Ivy Implementation source file */
package net.doorstuck.test
use std.io
-- Anything after a double hypen is ignored by the compiler
/*
Multi
Line
Comment
*/
/**
classes also double up as protocols.
any class can "pretend" to be another class by responding to the same
messages that the base class understands.
for example, by implementing all the messages that the Package class
understands, your class is said to implement the Package protocol,
allowing package-specific syntax (i.e. indexing and dot syntax)
to be used with your class.
there are two standard messages that complement this behaviour:
-is: takes a Class parameter, and returns true if the recipient
is an instance of the given Class.
-implements: takes a Class parameter, and returns true if the recipient
understands all of the messages that the parameter class
understands.
**/
class Person [
/**
A class is made up of the following components:
- a set of zero of more member variables
these can only be accessed by methods (not by functions) using the
self variable and the -> operator. member variables do not need
to be declared before they are used. assigning to a member variable
for the first time automatically "creates" it, and trying to access
a member variable that hasn't been assigned to will return null.
- a set of zero or more methods.
methods are procedure/sub-routines (a list of expressions evaluated
in order) executed in response to a particular message received by an
object. every method declares what sort of message it responds to.
- a set of zero or more functions.
functions are exactly like methods, except that they are executed in
response to messages sent to the class itself, rather than to an
instance of the class.
- a set of zero or more properties.
a property is similar to a member variable, with the following key
differences:
1) they are accessed using the . (dot) operator rather than the ->
(arrow) operator.
2) they can be accessed from outside the class.
3) they can (but don't have to) invoke blocks of code in response to
attempts to read from or assign to them.
4) they can be made read-write, read-only, or write-only.
**/
/**
every method and function begins with a kebab, or message signature.
So called due to the preceding hyphen (for methods) or plus
(for functions) and the kebab-case convention used for message and
parameter names.
methods and functions are called in response to messages, and the kebab
defines exactly what message the method/function should be called for.
a message can have:
1) a name and zero or more parameters; or
2) no name and one or more parameters.
if a message has a name AND parameters, the parameters are listed
within parentheses and separated by commas.
if a message has parameters but no name, the parameters are listed
with no surrounding symbols and are separated only by whitespace.
every parameter has a label and an identifier. the label determines what
name needs to be specified before the parameter value when sending a
message, and forms part of the API. in contrast, the identifier is
simply the variable name that is used to access the parameter value
within the method/function, and is only used internally.
a parameter MUST have an identifier, but a label can be omitted by
specifying an _ (underscore) as the label.
when a method/function body has more than one expression, the
expressions must be surrounded by [] (square bracket block delimiters).
**/
-init(name:name, age:age) [
self->name = name.
self->age = age
]
/* if a method/function only has a single expression body, a | (pipe)
can be used between the kebab and body, and the body will automatically
end after one expression. */
-test(param:data, _:extra) | cout put:'Received {data}, {extra}'.
-name | ^self->name.
-age | ^self->age.
-age-in-months | ^self->age * 12.
-set-name:name | self->name = name.
-set-age:age | self->age = age.
-set-age:age in-unit:units [
match units [
$years => self->age = age,
$months => self->age = age / 12,
$days => self->age = age / 365,
_ => self->age = 0
]
]
-get-age-in-units:units [
^match units [
$years => self->age,
$months => self->age / 12,
$days => self->age / 365,
_ => 0
]
]
+create-with-name:name [
^Person new(name:name, age:32)
]
/* Properties are defined by a bare identifier (with no prefixes, so not
a kebab) followed by a pipe.
They accomplish two things:
1) they make it easy to synthesize the -get: and -put:at: messages
that the package dot syntax requires.
2) they allow you to implement getters and setters that are used
when someone attempts to access your object's data.
The contents of a property looks a bit like a package, but it has a few
special rules:
1) every value must have an associated key; and
2) the only keys that can be used are `get` and `set` (this is the only
instance where reserved keywords can be used as keys in a package).
In this case, the getter has been set to a variable. To facilitate this
functionality, the compiler converts this to a lambda of the form
[ ^self->val ]
that will be evaluated when the getter is invoked
Similarly, the compiler synthesizes a lambda for the setter as well.
Here, the expression
self->val = value
is converted to the lambda
[ :x | self->val = x ]
*/
example-property-a | get => self->val, set => self->val = value.
/* Without the lambda synthesis, the property would look like this:
Note that this is the only time it is legal to access private fields
via `self` from a lambda. */
example-property-b |
get => [ ^self->val ],
set => [ :x | self->val = x ].
/* The `get` element of a property doesn't have to be a lambda, it can
be any value. When the property is accessed, the value provided will
be returned.
If either the `set` or `get` elements are not provided, the property
becomes read-only or write-only respectively */
example-property-c | get => 42.
/* A property can also be configured to act just like a regular variable,
by setting the getter and setters to default implementations.
The default getter will return the value of a private member variable
named by prepending "p-" to the property name (p-example-property-d in
this case).
Similarly, the default setter will set the value of a private member
variable named by prepending "p-" to the property name
(p-example-property-d in this case) to the value provided to the setter. */
example-property-d (get, set)
/* Just like in the earlier examples, either `get` or `set` can be omitted
to create a write-only or read-only property respectively */
example-property-e (get)
]
p1 = Person new(name:'John Doe', age:34).
p1 set-age:100 in-unit:$months.
p1 test(param:'Hello', 'World').
/******************************************************************************/
i = 0.
while i < 100 [
cout put:'Count is {i}'.
i += 2
]
for x in 0 to:100 step:2 [
cout put:'Count is {x}'
]
/**
a lambda's parameters are *always* unlabeled, and the underscore (_) before
the label colon (:) is unnecessary.
**/
0 to:100 step:2 do:[ :i | cout put:'Count: {i}' ].
/******************************************************************************/
/**
lambdas can capture state from the context in which they are created.
a lambda can reference any local variable that is accessible at the point
it is created. if a variable from such a context is referenced, its value
is captured at the point the lambda is constructed. the value of the
variable is copied into the lambda.
this means that, if a lambda references a variable in the outer context,
and the value of that variable changes between the lambda being created
and the lambda being executed, that change will not be reflected within
the lambda.
because the value of captured variables is copied into the lambda, it is
safe for a method to return a lambda that references variables in its
local context.
**/
q = 32.
l = [ cout put:'Value of q is {q}' ]. /* value of `q` is captured here */
q = 64.
_ = l call. /* prints 'Value of q is 32' */
/******************************************************************************/
j = 32.
/**
expressions are terminated with a newline.
an expression can be written across multiple lines by using
the _ (underscore) line continuation character.
**/
/**
keyword messages have a lower precedence than all non-assignment
binary operators, so (i < j) will be evaluated first, and
if:else: will be sent to the result.
**/
i < j
if:[ cout put:'True!' ]
else:[ cout put:'False!' ].
if i < j [
cout put:'True!'
]
/******************************************************************************/
pkg = {}.
/**
Packages can be indexed via integer or string. If a package is index with a
variable, the value of the variable is used as the index.
**/
pkg[0] = 16.
/* All of these accesses are equivalent */
pkg['x'] = 32.
pkg.x = 32.
pkg at:'x' put:32.
index = 'x'.
pkg[index] = 32.
pkg at:index put:32.
/**
this syntax, and the pkg.* instructions that it translates to, is
implemented behind-the-scenes by sending messages to the package.
if your custom object implements this protocol, package syntax can be used
on it too.
**/
/**
these are the same packages used to store Classes and global variables.
for example, the std package is a regular package object, and you can use
package syntax on it or even send it messages.
**/
/******************************************************************************/
/* integer constants can be written in all sorts of interesting formats */
i = 100.
i = 0x100.
i = 0200.
i = 0b1010101.
i = 1_000_000_000.
i = 100.25.
/* tuples can be used to create a set of values */
tuple = (32, 'a string').
/**
they are similar to packages, except they only support consecutive integer
indices, and you cannot specify the indices when creating a tuple.
the main purpose of tuples is to allow unwrapping of iterator variables in
for loops.
**/
for (key, val) in pkg [
cout put:'{key} -> {val}'
]
/**
any object can be the target of a for-loop, as long as it meets one of the
following criteria:
a) is an Iterator object; or
b) implements the Iterator protocol; or
c) understands the -get-iterator message, and returns an object that itself
conforms to a) or b)
**/
/******************************************************************************/
/**
underscore (_) is used as a placeholder during assignment.
it can only appear on the left of an assignment, and anything
assigned to it is discarded.
*/
_ = 3 * 2.
/* it is mostly used with pattern-matching and destructuring. */
a = (32, 64).
(_, v) = a.
/* v is now equal to 64 */
/******************************************************************************/
try [
v = Int parse:'342'
] catch ($err:number-format, err) [
cout put:'Cannot parse integer string ({err})'
] catch (_, err) [
cout put:'Unknown error occurred ({err})'
]
/* equivalent 'pure' syntax */
[ v = Int parse:'342' ]
on:$err:number-format do:[ :err :data |
cout put:'Cannot parse integer string ({err})'
];
on-error:[ :err :data |
cout put:'Error {err} occurred ({data})'
];
call.
v = 5
squared
squared
squared.
/******************************************************************************/
x = 32.
/* a whole bunch of ways of doing conditionals using lambdas and messages */
[ cout put:'Hello, world!' ] if:x > 10.
[ cout put:'Hello, world!' ] unless:x <= 10.
/* and the equivalent 'fancy' syntax */
cout put:'Hello, world!' if x > 10.
-- cout put:'Hello, world!' unless x <= 10.
/**
NOTE that keywords (if, try, and so on) can still be used as message
parameter names. however, they cannot be used as message names.
**/
/******************************************************************************/
/**
Order of execution (precedence) for expression elements (listed from highest
to lowest precedence). elements that appear on the same list item have equal
precedence. in these cases, their associativity determines the order of
execution.
- binary operators
- package-access (.)
- self-access (->)
- unary operators
- boolean NOT (not)
- bitwise NOT (~)
- binary operators
- Type check operator (is, is not)
- Protocol check operator (understands)
- unary messages, complex messages
- binary operators
- multiplication (*)
- division (/)
- modulo (%)
- addition (+)
- subtraction (-)
- bitwise shift (<<, >>)
- comparison (<, >, <=, >=)
- (in)equality (==, !=)
- bitwise AND (&)
- bitwise XOR (^)
- bitwise OR (|)
- boolean AND (and)
- boolean OR (or)
- cascade (;)
- inline if-else
- keyword messages
- binary operators
- assignment by product, quotient, and remainder (*=, /=, %=)
- assignment by sum and difference (+=, -=)
- assignment by bitwise shift (<<=, >>=)
- assignment by bitwise AND, XOR, and OR (&=, ^=, |=)
- assignment (=)
**/
p1
set-age:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3)
in:'mon' + 'ths'.
(p1
set-age:(((2 squared) squared) + ((4 squared) multiply(by:2, add:(4 + (1 * 3)))))
in:('mon' + 'ths')).
/******************************************************************************/
/* how about package comprehension? */
/**
these two lines both construct a package containing all even numbers between
0 and 100 incremented by 1
the first one uses fancy list/package comprehension syntax.
the second one uses pure message/lambda syntax.
**/
data = { x + 1 for x in 0 to:100 if (x % 2) == 0 }.
data = (0 to: 100) select:[ :x | ^(x % 2) == 0 ] collect:[ :x | ^x + 1 ].
/**
for a package comprehension that follows this template:
EXPRESSION for VARIABLE in COLLECTION if CONDITION
the equivalent -select:collect: message would look something like this:
COLLECTION select:[ VARIABLE | CONDITION ] collect:[ VARIABLE | EXPRESSION ]
-select:collect: is used to create a new package by filtering and
transforming an existing package.
To apply a filter without a subsequent transform, you can use -select:
To apply a transformation with a filter beforehand, you can use -map:
**/
/******************************************************************************/
/**
packages also support a -map: message for constructing a new package by
manipulating an existing one.
**/
/**
this example creates a package of all ints between 1 and 5 using a regular
collection literal, and then uses -map: to create a second package by
doubling each of the numbers in the fist package.
**/
pkg1 = { 1, 2, 3, 4, 5 }.
pkg2 = { x * 2 for x in pkg1 }.
pkg2 = pkg1 map:[ :x | ^x * 2 ].
/******************************************************************************/
/**
semicolon (;) is the cascade operator. it returns the recipient of the
previously sent message. it can be used to send multiple messages to a
single recipient.
**/
age = Person new(name:'John Doe', age:34);
set-age:144 in-unit:$months;
ageInMonths.
-- age now has the value 144
-- the same behaviour can be achieved by using do[...]
age = do [
x = Person new(name:'John Doe', age:34).
x set-age:144 in-unit:$months.
x ageInMonths
].
/**
this allows messages to be easily chained, without relying on the message
handler returning `self`.
**/
/**
NOTE that cascade is a binary operator, and cannot be used without a
right-hand operand. otherwise, simply adding a semicolon to the end of an
expression would change the behaviour (and result) of the expression.
however, because cascade is a binary operator, it also supports implicit
line continuations.
for situations where you want to return the recipient after a chain of
cascaded messages, you can use the -yourself message, which is understood by
all objects by default and always returns the object itself->
**/
p1 = Person new(name:'John Doe', age:34);
set-age:100 in-unit:$months;
yourself.
/* p1 now contains the Person object */
/* again, with do[...] */
p1 = do [
x = Person new(name:'John Doe', age:34).
x set-age:100 in-unit:$months.
x
].
v = "Hello".
if v is String [
cout put:"v is a string!"
]
/******************************************************************************/
/**
Blocks are a bit like lambdas, except they are part of the context of the
code that uses them. They are essentially a way of evaluating multiple
statements in a place where a single statement is usually expected.
**/
/* Blocks are delimited by do[...], and the return operator can be used within
them. When it is, the value that is 'returned' will become the value that
the block as a whole evaluates to. also, the result of the last expression
evaluated in a block will be taken as its overall value. */
val = do [
x = 3.
y = 2.
x * y
].
/* after this statement is executed, `val` will be equal to 6. */

View File

@@ -48,7 +48,6 @@ class Person
compatibility with lambdas.
**/
- init(name:name age:age)
var x.
self::name = name.
self::age = age!
@@ -80,7 +79,7 @@ class Person
_ => 0
end!
/* Properties are defined using the $ symbol.
/* Properties are defined using the -> symbol.
They accomplish two things:
1) they make it easy to synthesize the -get: and -put:at: messages
that the package dot syntax requires.
@@ -109,7 +108,7 @@ class Person
/* Without the lambda synthesis, the property would look like this:
Note that this is the only time it is legal to access private fields
via `self` from a lambda. */
-> example-property |
-> example-property-2 |
get => [ ^self::val ],
set => [ :x | self::val = x ].
@@ -119,23 +118,23 @@ class Person
If either the `set` or `get` elements are not provided, the property
becomes read-only or write-only respectively */
-> example-property-2 | get => 42.
-> example-property-3 | get => 42.
/* A property can also be configured to act just like a regular variable,
by setting the getter and setters to default implementations.
The default getter will return the value of a private member variable
named by prepending two underscores to the property name
(__exampleProperty3 in this case).
(__example-property-4 in this case).
Similarly, the default setter will set the value of a private member
variable named by prepending two underscores to the property name
(__exampleProperty3 in this case) to the value provided to the setter. */
-> example-property-3 (get, set)
(__example-property-4 in this case) to the value provided to the setter. */
-> example-property-4 (get, set)
/* Just like in the earlier examples, either `get` or `set` can be omitted
to create a write-only or read-only property respectively */
-> example-property-4 (get)
-> example-property-5 (get)
end
p1 = Person new(name:'John Doe', age:34).
@@ -151,8 +150,8 @@ while i < 100 do
i += 2
end
for i in 0 to:100 step:2 do
cout put:'Count is {i}'
for x in 0 to:100 step:2 do
cout put:'Count is {x}'
end
/**
@@ -223,11 +222,11 @@ pkg[0] = 16.
/* All of these accesses are equivalent */
pkg['x'] = 32.
pkg->x = 32.
pkg put:32 at:'x'.
pkg at:'x' put:32.
index = 'x'.
pkg[index] = 32.
pkg put:32 at:index.
pkg at:index put:32.
/**
this syntax, and the pkg.* instructions that it translates to, is
@@ -274,7 +273,7 @@ end
following criteria:
a) is an Iterator object; or
b) implements the Iterator protocol; or
c) understands the -iterator message, and returns an object that itself
c) understands the -get-iterator message, and returns an object that itself
conforms to a) or b)
**/
@@ -311,7 +310,7 @@ end
on:$err:number-format do:[ :err :data |
cout put:'Cannot parse integer string ({err})'
];
onError:[ :err :data |
on-error:[ :err :data |
cout put:'Error {err} occurred ({data})'
];
call.

View File

@@ -1,36 +1,9 @@
y = -1 + 2 * 3 / 4 * 5 - 6 + 7 multiply-by:2.
z = w = 2 + 3 multiply-by:2.
x = (((1 + 2 * 3) multiply-by:3) add: 5) + 2.
x = ((1 + 2 * 3) multiply-by:3).
p = 5 multiply(by:3, add:(2 + 1)).
q = 10 squared squared.
package net.doorstuck.test
p1
set-age:2 squared squared + 4 squared multiply(by:2, add:4 + 1 * 3)
in:"mon" + "ths".
use std.io
m = xz multiply(by:3 add:2) squared.
y = 32 * 64.
z = 64 / 4.
x = y + z.
m = xz multiply(by:3 add:2); squared.
x = Ordered-Collection new
add: 2;
add: 4;
add: 6;
yourself.
age = Person new(name:"John Doe", age:34)
set-age:144 in-unit:"months";
age-in-months.
x = 5.
q = 10 if x > 2 else 20.
q = if x > 2 then 10 else 20 end.
cout put:5 multiply(by:5, add:2) if x > 2.
if x > 2 then
cout put:"Greater"
else
cout put:"Less"
end
cout put:'Answer: {x}'

View File

@@ -1,6 +1,6 @@
package net.doorstuck.test
s1 = 'hello world'
s1 = 'hello world'.
s2 = s1 map:[ :c | ^c uppercase ]
s2 = s1 map:[ :c | ^c uppercase ].
s3 = s1 map:[ :c | ^((c ordinal) + 1) to-char ]

96
doc/sample/Sum.2.mie Normal file
View File

@@ -0,0 +1,96 @@
meta.source-filename "Sum.im"
ivy.package-scope "net.doorstuck.test"
ivy.module {
ivy.init-text {
%0 = ivy.str.constant "Finds the sum of a set of numbers."
%cout = ivy.global-ref @cout -> ptr
%1 = ptr.load %cout : ptr -> #ivy.id
ivy.send-msg to %1, put:%0 -> void
%sum = ptr.alloca i32 -> ptr
%sum.0 = i32.constant 0
ptr.store %sum.0, %sum : i32, ptr
scf.loop() -> void {
%2 = ivy.str.constant "Number (blank to finish): "
%3 = ptr.load %cout : ptr -> #ivy.id
ivy.send-msg to %3, put:%2 -> void
%4 = ptr.load %cout : ptr -> #ivy.id
ivy.send-msg to %3, flush -> void
%v = ptr.alloca i32 -> ptr
%5 = i32.constant 0
ptr.store %5, %v : i32, ptr
%input = ptr.alloca #ivy.id -> ptr
%cin = ivy.global-ref @cin -> ptr
%7 = ptr.load %cin : ptr -> #ivy.id
%8 = ivy.send-msg to %7, read-line -> #ivy.id
ptr.store %8, %input : #ivy.id, ptr
%9 = ptr.load %input : ptr -> #ivy.id
%String = ivy.global-ref @String -> ptr
%10 = ptr.load %String : ptr -> #ivy.id
%11 = ivy.send-msg to %10, new -> #ivy.id
%12 = ivy.cmp eq %9, %11 : (#ivy.id, #ivy.id) -> i1
scf.if %12 -> void {
scf.loop-break : ()
}
%v = ptr.alloca #ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr
%13 = ptr.load %Int : ptr -> #ivy.id
%14 = ptr.load %input : ptr -> #ivy.id
%15 = ivy.send-msg to %12, parse:%14 -> #ivy.id
ptr.store %15, %v : #ivy.id, ptr
%16 = ptr.load %v : ptr -> #ivy.id
%17 = ivy.null-id : #ivy.id
%18 = ivy.cmp eq %16, %17 : (#ivy.id, #ivy.id) -> i1
scf.if %1 -> void {
%19 = ptr.load %cout : ptr -> #ivy.id
%StringBuilder = ivy.global-ref @StringBuilder -> ptr
%20 = ptr.load %StringBuilder : ptr -> #ivy.id
%21 = ivy.send-msg to %20, new -> #ivy.id
%22 = ptr.load %input : ptr -> #ivy.id
ivy.send-msg to %21, append:%22 -> void
%23 = ivy.str.constant " is not a valid number."
ivy.send-msg to %21, append:%23 -> void
%24 = ivy.send-msg to %21, to-string -> #ivy.id
ivy.send-msg to %19, put:%24 -> void
scf.loop-continue : ()
}
%25 = ptr.load %sum : ptr -> i32
%26 = ptr.load %v : ptr -> #ivy.id
%addtmp = ivy.add %25, %26 : (i32, #ivy.id) -> #ivy.id
ptr.store %addtmp, %sum : #ivy.id, ptr
scf.loop-continue : ()
}
}
}

View File

@@ -1,4 +1,9 @@
var x = 2 + 3.
var y = x.
var z.
var (x, y) = (3, 4).
x = 3.
y = 0.
if x > 10 then
y = 4
else
y = 2
end

View File

@@ -20,8 +20,8 @@ target_link_libraries(
ivy-asm
ivy-lang
ivy-common
Bluelib::Core
Bluelib::Ds
Bluelib::Cmd)
FX::Core
FX::Ds
FX::Cmd)
target_compile_definitions(ivy PRIVATE IVY_STATIC=${IVY_STATIC})

View File

@@ -1,10 +1,10 @@
#include "../debug.h"
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/ds/string.h>
#include <blue/term.h>
#include <errno.h>
#include <fx/cmd.h>
#include <fx/ds/string.h>
#include <fx/term.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/lex.h>
#include <ivy/asm/parse.h>
@@ -24,15 +24,15 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_file *src = NULL;
status = ivy_file_open(in_path, &src);
if (!src) {
b_err("cannot open source file '%s'", in_path);
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot open source file '%s'", in_path);
fx_i("reason: %s", ivy_status_to_string(status));
return -1;
}
FILE *out = fopen(out_path, "w+b");
if (!out) {
b_err("cannot open output file '%s'", out_path);
b_i("reason: %s", strerror(errno));
fx_err("cannot open output file '%s'", out_path);
fx_i("reason: %s", strerror(errno));
return -1;
}
@@ -40,8 +40,8 @@ static int assemble_file(const char *in_path, const char *out_path)
status = ivy_assembler_create(out, &as);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembler");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembler");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_file_close(src);
fclose(out);
@@ -51,8 +51,8 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_asm_lexer *lex;
status = ivy_asm_lexer_create(&lex);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembly lexer");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembly lexer");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_file_close(src);
fclose(out);
@@ -63,8 +63,8 @@ static int assemble_file(const char *in_path, const char *out_path)
struct ivy_asm_parser *parser;
status = ivy_asm_parser_create(&parser);
if (status != IVY_OK) {
b_err("failed to initialise Ivy assembly parser");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("failed to initialise Ivy assembly parser");
fx_i("reason: %s", ivy_status_to_string(status));
ivy_asm_lexer_destroy(lex);
ivy_file_close(src);
@@ -85,9 +85,9 @@ static int assemble_file(const char *in_path, const char *out_path)
}
if (status != IVY_OK) {
b_err("failed to parse '%s'", in_path);
b_i("reason: lex error (%s)",
ivy_status_to_string(ivy_asm_lexer_get_status(lex)));
fx_err("failed to parse '%s'", in_path);
fx_i("reason: lex error (%s)",
ivy_status_to_string(ivy_asm_lexer_get_status(lex)));
break;
}
@@ -95,9 +95,9 @@ static int assemble_file(const char *in_path, const char *out_path)
status = ivy_asm_parser_push_token(parser, tok);
if (status != IVY_OK) {
b_err("failed to parse '%s'", in_path);
b_i("reason: parse error (%s)",
ivy_status_to_string(status));
fx_err("failed to parse '%s'", in_path);
fx_i("reason: parse error (%s)",
ivy_status_to_string(status));
break;
}
}
@@ -112,31 +112,31 @@ static int assemble_file(const char *in_path, const char *out_path)
return r;
}
static b_string *get_source_filename(const char *src_path)
static fx_string *get_source_filename(const char *src_path)
{
b_string *name = b_string_create();
fx_string *name = fx_string_create();
for (unsigned int i = 0; src_path[i]; i++) {
if (src_path[i] == '/' || src_path[i] == '\\') {
b_string_clear(name);
fx_string_clear(name);
continue;
}
char s[] = {src_path[i], 0};
b_string_append_cstr(name, s);
fx_string_append_cstr(name, s);
}
if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) {
b_string_unref(name);
if (fx_string_get_size(name, FX_STRLEN_NORMAL) == 0) {
fx_string_unref(name);
name = NULL;
}
return name;
}
static b_string *generate_object_filename(const char *src_filename)
static fx_string *generate_object_filename(const char *src_filename)
{
b_string *name = b_string_create();
fx_string *name = fx_string_create();
for (unsigned int i = 0; src_filename[i]; i++) {
if (src_filename[i] == '.') {
@@ -144,53 +144,54 @@ static b_string *generate_object_filename(const char *src_filename)
}
char s[] = {src_filename[i], 0};
b_string_append_cstr(name, s);
fx_string_append_cstr(name, s);
}
if (b_string_get_size(name, B_STRLEN_NORMAL) == 0) {
b_string_append_cstr(name, "out");
if (fx_string_get_size(name, FX_STRLEN_NORMAL) == 0) {
fx_string_append_cstr(name, "out");
}
b_string_append_cstr(name, ".io");
fx_string_append_cstr(name, ".io");
return name;
}
static int assemble(const b_command *cmd, const b_arglist *args, const b_array *_)
static int assemble(
const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
const char *in_path = NULL;
const char *out_path = NULL;
b_string *in_name = NULL;
b_string *out_name = NULL;
fx_string *in_name = NULL;
fx_string *out_name = NULL;
b_arglist_get_string(
args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE, 0, &in_path);
fx_arglist_get_string(
args, FX_COMMAND_INVALID_ID, ARG_SOURCE_FILE, 0, &in_path);
if (!in_path) {
b_err("no source file specified.");
fx_err("no source file specified.");
return -1;
}
in_name = get_source_filename(in_path);
if (!in_path) {
b_err("source filepath is not a file.");
fx_err("source filepath is not a file.");
return -1;
}
b_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &out_path);
fx_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &out_path);
if (!out_path) {
out_name = generate_object_filename(b_string_ptr(in_name));
out_path = b_string_ptr(out_name);
out_name = generate_object_filename(fx_string_ptr(in_name));
out_path = fx_string_ptr(out_name);
}
int r = assemble_file(in_path, out_path);
b_string_unref(in_name);
b_string_unref(out_name);
fx_string_unref(in_name);
fx_string_unref(out_name);
return r;
#if 0
const char *path = NULL;
b_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &path);
fx_arglist_get_string(args, OPT_OUT_FILE, ARG_OUT_FILE, 0, &path);
if (!path) {
printf("no output path specified.\n");
@@ -202,8 +203,8 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
enum ivy_status status = ivy_assembler_create(out, &as);
if (status != IVY_OK) {
b_err("failed to initialise assembler");
b_i("reason: ", ivy_status_to_string(status));
fx_err("failed to initialise assembler");
fx_i("reason: ", ivy_status_to_string(status));
fclose(out);
return -1;
}
@@ -229,34 +230,34 @@ static int assemble(const b_command *cmd, const b_arglist *args, const b_array *
return 0;
}
B_COMMAND(CMD_ASSEMBLE, CMD_ROOT)
FX_COMMAND(CMD_ASSEMBLE, CMD_ROOT)
{
B_COMMAND_NAME("assemble");
B_COMMAND_SHORT_NAME('A');
B_COMMAND_DESC(
FX_COMMAND_NAME("assemble");
FX_COMMAND_SHORT_NAME('A');
FX_COMMAND_DESC(
"assemble one or more Ivy assembly source files into Ivy "
"object files.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(assemble);
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(assemble);
B_COMMAND_ARG(ARG_SOURCE_FILE)
FX_COMMAND_ARG(ARG_SOURCE_FILE)
{
B_ARG_NAME("source file");
B_ARG_DESC("the .iasm assembly file to compile.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("source file");
FX_ARG_DESC("the .iasm assembly file to compile.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_OPTION(OPT_OUT_FILE)
FX_COMMAND_OPTION(OPT_OUT_FILE)
{
B_OPTION_SHORT_NAME('o');
B_OPTION_LONG_NAME("out");
B_OPTION_DESC("the path to write the output binary file to.");
B_OPTION_ARG(ARG_OUT_FILE)
FX_OPTION_SHORT_NAME('o');
FX_OPTION_LONG_NAME("out");
FX_OPTION_DESC("the path to write the output binary file to.");
FX_OPTION_ARG(ARG_OUT_FILE)
{
B_ARG_NAME("path");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("path");
FX_ARG_NR_VALUES(1);
}
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -1,11 +1,10 @@
#include "../debug.h"
#include "cmd.h"
#include "mie/select/builder.h"
#include <blue/cmd.h>
#include <blue/core/error.h>
#include <blue/term.h>
#include <errno.h>
#include <fx/cmd.h>
#include <fx/core/error.h>
#include <fx/term.h>
#include <ivy/asm/mie.h>
#include <ivy/diag.h>
#include <ivy/file.h>
@@ -15,11 +14,6 @@
#include <ivy/lang/lex.h>
#include <mie/ctx.h>
#include <mie/ir/block.h>
#include <mie/ir/convert.h>
#include <mie/ir/func.h>
#include <mie/ir/module.h>
#include <mie/select/builder.h>
#include <mie/select/graph.h>
#include <stdio.h>
enum {
@@ -51,7 +45,6 @@ struct compile_ctx {
struct ivy_codegen *codegen;
struct mie_ctx *mie_ctx;
struct mie_select_builder *select;
struct mie_module *mod;
};
@@ -68,19 +61,19 @@ static enum ivy_status node_codegen(
return ivy_codegen_push_node(ctx->codegen, node, node->n_it.it_depth);
}
static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
static fx_result compile_ctx_init(struct compile_ctx *ctx, const fx_arglist *args)
{
memset(ctx, 0x0, sizeof *ctx);
b_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_LEX_TOKENS);
b_arglist_get_count(args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_AST_NODES, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_AST_NODES);
b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_IR, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_IR);
b_arglist_get_count(args, OPT_SHOW_ISEL_PRE, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_ISEL_PRE, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_PRE_SELECT_GRAPH);
b_arglist_get_count(args, OPT_SHOW_ISEL_POST, B_COMMAND_INVALID_ID)
fx_arglist_get_count(args, OPT_SHOW_ISEL_POST, FX_COMMAND_INVALID_ID)
&& (ctx->flags |= FLAG_SHOW_POST_SELECT_GRAPH);
enum mie_status mie_status = MIE_SUCCESS;
@@ -92,22 +85,26 @@ static b_result compile_ctx_init(struct compile_ctx *ctx, const b_arglist *args)
ivy_status = ivy_lexer_create(&ctx->lex);
ivy_status = ivy_parser_create(&ctx->parser);
ivy_status = ivy_codegen_create(ctx->mie_ctx, &ctx->codegen);
#if 0
ctx->select
= mie_select_builder_create(ctx->mie_ctx, ivy_asm_mie_target());
#endif
ivy_lang_diag_ctx_init(ctx->diag);
ivy_diag_stream_init_tty(&ctx->diag_stream, b_stdtty);
ivy_diag_stream_init_tty(&ctx->diag_stream, fx_stdtty);
ivy_lexer_set_diag_ctx(ctx->lex, ctx->diag);
ivy_parser_set_diag_ctx(ctx->parser, ctx->diag);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
static fx_result compile_ctx_cleanup(struct compile_ctx *ctx)
{
#if 0
if (ctx->mod) {
mie_value_destroy(MIE_VALUE(ctx->mod));
}
#endif
if (ctx->src) {
ivy_diag_ctx_set_line_source(ctx->diag, NULL);
@@ -115,9 +112,11 @@ static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
ivy_file_close(ctx->src);
}
#if 0
if (ctx->select) {
mie_select_builder_destroy(ctx->select);
}
#endif
if (ctx->codegen) {
ivy_codegen_destroy(ctx->codegen);
@@ -135,14 +134,16 @@ static b_result compile_ctx_cleanup(struct compile_ctx *ctx)
ivy_diag_ctx_destroy(ctx->diag);
}
#if 0
if (ctx->mie_ctx) {
mie_ctx_destroy(ctx->mie_ctx);
}
#endif
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result open_file(struct compile_ctx *ctx, const char *path)
static fx_result open_file(struct compile_ctx *ctx, const char *path)
{
enum ivy_status status = ivy_file_open(path, &ctx->src);
@@ -151,10 +152,10 @@ static b_result open_file(struct compile_ctx *ctx, const char *path)
ctx->src_path = path;
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result parse_file_tokens(struct compile_ctx *ctx)
static fx_result parse_file_tokens(struct compile_ctx *ctx)
{
enum ivy_status status = IVY_OK;
@@ -166,7 +167,7 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
ivy_diag_ctx_write(
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
&ctx->diag_stream);
return b_error_with_code(
return fx_error_with_code(
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
}
@@ -181,12 +182,12 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
ctx->diag, IVY_DIAG_FORMAT_PRETTY,
&ctx->diag_stream);
ivy_token_destroy(tok);
return b_error_with_code(
return fx_error_with_code(
IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX);
}
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_PARSE_FAILURE,
IVY_ERROR_VENDOR, status);
}
@@ -196,10 +197,10 @@ static b_result parse_file_tokens(struct compile_ctx *ctx)
}
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result generate_mie_ir(struct compile_ctx *ctx)
static fx_result generate_mie_ir(struct compile_ctx *ctx)
{
ivy_codegen_start_module(ctx->codegen);
@@ -209,42 +210,46 @@ static b_result generate_mie_ir(struct compile_ctx *ctx)
enum ivy_status status
= ivy_ast_node_iterate(node, &it, node_codegen, ctx);
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
IVY_ERROR_VENDOR, status);
}
status = ivy_codegen_push_eof(ctx->codegen);
if (status != IVY_OK) {
return b_error_caused_by_code(
return fx_error_caused_by_code(
IVY_ERROR_VENDOR, IVY_ERR_CODEGEN_FAILURE,
IVY_ERROR_VENDOR, status);
}
ivy_codegen_end_module(ctx->codegen, &ctx->mod);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_block_isel_graph(
#if 0
static fx_result build_block_isel_graph(
struct compile_ctx *ctx, struct mie_func *func, struct mie_block *block)
{
b_queue_entry *entry = b_queue_first(&block->b_phi);
printf("selecting %s.%s...\n", func->f_base.v_name.n_str,
block->b_base.v_name.n_str);
fx_queue_entry *entry = fx_queue_first(&block->b_phi);
while (entry) {
struct mie_value *instr_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
entry = b_queue_first(&block->b_instr);
entry = fx_queue_first(&block->b_instr);
while (entry) {
struct mie_value *instr_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
mie_select_builder_push_instr(
ctx->select, (struct mie_instr *)instr_v);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
if (block->b_terminator) {
@@ -254,54 +259,59 @@ static b_result build_block_isel_graph(
struct mie_select_graph *graph = mie_select_builder_finish(ctx->select);
if (ctx->flags & FLAG_SHOW_PRE_SELECT_GRAPH) {
char name[128];
snprintf(
name, sizeof name, "%s.%s.dot",
func->f_base.v_name.n_str, block->b_base.v_name.n_str);
printf("%s.%s instruction graph:\n", func->f_base.v_name.n_str,
block->b_base.v_name.n_str);
mie_select_graph_dump_dot(graph);
mie_select_graph_dump_dot(graph, name);
mie_select_graph_destroy(graph);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
static fx_result build_func_isel_graph(struct compile_ctx *ctx, struct mie_func *func)
{
b_queue_entry *entry = b_queue_first(&func->f_blocks);
fx_queue_entry *entry = fx_queue_first(&func->f_blocks);
while (entry) {
struct mie_value *block_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
struct mie_block *block = (struct mie_block *)block_v;
b_result result = build_block_isel_graph(ctx, func, block);
if (b_result_is_error(result)) {
return b_result_propagate(result);
fx_result result = build_block_isel_graph(ctx, func, block);
if (fx_result_is_error(result)) {
return fx_result_propagate(result);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result build_isel_graph(struct compile_ctx *ctx)
static fx_result build_isel_graph(struct compile_ctx *ctx)
{
b_queue_entry *entry = b_queue_first(&ctx->mod->m_func);
fx_queue_entry *entry = fx_queue_first(&ctx->mod->m_func);
while (entry) {
struct mie_value *func_v
= b_unbox(struct mie_value, entry, v_entry);
= fx_unbox(struct mie_value, entry, v_entry);
struct mie_func *func = (struct mie_func *)func_v;
b_result result = build_func_isel_graph(ctx, func);
if (b_result_is_error(result)) {
return b_result_propagate(result);
fx_result result = build_func_isel_graph(ctx, func);
if (fx_result_is_error(result)) {
return fx_result_propagate(result);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
#endif
static b_result dump_ast(struct compile_ctx *ctx)
static fx_result dump_ast(struct compile_ctx *ctx)
{
struct ivy_ast_node *node = ivy_parser_root_node(ctx->parser);
struct ivy_ast_node_iterator it = {0};
@@ -311,11 +321,12 @@ static b_result dump_ast(struct compile_ctx *ctx)
ivy_ast_node_iterate(node, &it, print_ast_node, &args);
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static b_result dump_ir(struct compile_ctx *ctx)
static fx_result dump_ir(struct compile_ctx *ctx)
{
#if 0
struct mie_ir_converter *convert
= mie_ir_converter_create(ctx->mie_ctx, MIE_IR_MEM, MIE_IR_TEXT);
mie_ir_converter_set_src_value(convert, MIE_VALUE(ctx->mod));
@@ -323,25 +334,26 @@ static b_result dump_ir(struct compile_ctx *ctx)
mie_ir_converter_process(convert);
mie_ir_converter_destroy(convert);
#endif
return B_RESULT_SUCCESS;
return FX_RESULT_SUCCESS;
}
static int compile_file(const char *path, const b_arglist *args)
static int compile_file(const char *path, const fx_arglist *args)
{
#define THROW_AND_RETURN(result, error_code) \
do { \
if (b_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
return error_code; \
} \
if (b_result_is_error(result)) { \
b_throw(result); \
return error_code; \
} \
#define THROW_AND_RETURN(result, error_code) \
do { \
if (fx_result_is(result, IVY_ERROR_VENDOR, IVY_ERR_BAD_SYNTAX)) { \
return error_code; \
} \
if (fx_result_is_error(result)) { \
fx_throw(result); \
return error_code; \
} \
} while (0)
struct compile_ctx ctx;
b_result result = compile_ctx_init(&ctx, args);
fx_result result = compile_ctx_init(&ctx, args);
THROW_AND_RETURN(result, -1);
int progress = 0;
@@ -376,12 +388,14 @@ static int compile_file(const char *path, const b_arglist *args)
return 0;
}
#if 0
result = build_isel_graph(&ctx);
THROW_AND_RETURN(result, -1);
if (progress == 3) {
return 0;
}
#endif
end:
compile_ctx_cleanup(&ctx);
@@ -390,13 +404,13 @@ end:
return 0;
}
static int compile(const b_command *cmd, const b_arglist *args, const b_array *_)
static int compile(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
b_arglist_iterator it;
b_arglist_foreach_filtered(&it, args, B_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
fx_arglist_iterator it;
fx_arglist_foreach_filtered(&it, args, FX_COMMAND_INVALID_ID, ARG_SOURCE_FILE)
{
b_arglist_value *path = it.value;
if (path->val_type != B_COMMAND_ARG_STRING) {
fx_arglist_value *path = it.value;
if (path->val_type != FX_COMMAND_ARG_STRING) {
continue;
}
@@ -409,66 +423,66 @@ static int compile(const b_command *cmd, const b_arglist *args, const b_array *_
return 0;
}
B_COMMAND(CMD_COMPILE, CMD_ROOT)
FX_COMMAND(CMD_COMPILE, CMD_ROOT)
{
B_COMMAND_NAME("compile");
B_COMMAND_SHORT_NAME('C');
B_COMMAND_DESC(
FX_COMMAND_NAME("compile");
FX_COMMAND_SHORT_NAME('C');
FX_COMMAND_DESC(
"compile one or more Ivy source files into Ivy object files.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(compile);
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(compile);
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
FX_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
{
B_OPTION_LONG_NAME("show-lex");
B_OPTION_SHORT_NAME('l');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-lex");
FX_OPTION_SHORT_NAME('l');
FX_OPTION_DESC(
"print the lexical tokens generated from the input "
"files.");
}
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
FX_COMMAND_OPTION(OPT_SHOW_AST_NODES)
{
B_OPTION_LONG_NAME("show-ast");
B_OPTION_SHORT_NAME('a');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ast");
FX_OPTION_SHORT_NAME('a');
FX_OPTION_DESC(
"print the abstract syntax tree generated from the "
"input files.");
}
B_COMMAND_OPTION(OPT_SHOW_IR)
FX_COMMAND_OPTION(OPT_SHOW_IR)
{
B_OPTION_LONG_NAME("show-ir");
B_OPTION_SHORT_NAME('i');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ir");
FX_OPTION_SHORT_NAME('i');
FX_OPTION_DESC(
"print the Mie IR generated from the "
"input files.");
}
B_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
FX_COMMAND_OPTION(OPT_SHOW_ISEL_PRE)
{
B_OPTION_LONG_NAME("show-isel-pre");
B_OPTION_SHORT_NAME('s');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-isel-pre");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_DESC(
"print the instruction selection graph before "
"selection has taken place.");
}
B_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
FX_COMMAND_OPTION(OPT_SHOW_ISEL_POST)
{
B_OPTION_LONG_NAME("show-isel-post");
B_OPTION_SHORT_NAME('m');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-isel-post");
FX_OPTION_SHORT_NAME('m');
FX_OPTION_DESC(
"print the instruction selection graph after "
"selection has taken place.");
}
B_COMMAND_ARG(ARG_SOURCE_FILE)
FX_COMMAND_ARG(ARG_SOURCE_FILE)
{
B_ARG_NAME("source file");
B_ARG_DESC("the .im source files to compile.");
B_ARG_NR_VALUES(B_ARG_1_OR_MORE_VALUES);
FX_ARG_NAME("source file");
FX_ARG_DESC("the .im source files to compile.");
FX_ARG_NR_VALUES(FX_ARG_1_OR_MORE_VALUES);
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -1,10 +1,10 @@
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/ds/string.h>
#include <blue/term.h>
#include <ctype.h>
#include <errno.h>
#include <fx/cmd.h>
#include <fx/ds/string.h>
#include <fx/term.h>
#include <inttypes.h>
#include <ivy/asm/assembler.h>
#include <ivy/asm/instr.h>
@@ -30,7 +30,7 @@ enum {
OPT_CONSTPOOL,
};
static void dump_instruction(b_i32 x)
static void dump_instruction(fx_i32 x)
{
struct ivy_instr instr = {};
enum ivy_status status = ivy_instr_decode(x, &instr);
@@ -226,7 +226,7 @@ static enum ivy_status dump_class(
}
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(class_header.c_ident), &class_ident);
pool, fx_i32_btoh(class_header.c_ident), &class_ident);
if (status != IVY_OK) {
goto cleanup;
}
@@ -262,13 +262,13 @@ static enum ivy_status dump_class(
printf(" [%03zu] ", i);
char s[256];
uint32_t type = b_i32_btoh(entry.e_type);
uint32_t type = fx_i32_btoh(entry.e_type);
switch (type) {
case IVY_CLASS_TABLE_PROP: {
printf("type:property\n");
struct ivy_asm_constpool_value *prop_ident = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_property.p_ident),
pool, fx_i32_btoh(entry.e_property.p_ident),
&prop_ident);
if (status != IVY_OK) {
break;
@@ -279,8 +279,8 @@ static enum ivy_status dump_class(
break;
}
uint32_t get = b_i32_btoh(entry.e_property.p_get);
uint32_t set = b_i32_btoh(entry.e_property.p_set);
uint32_t get = fx_i32_btoh(entry.e_property.p_get);
uint32_t set = fx_i32_btoh(entry.e_property.p_set);
ivy_ident_to_string(prop_ident->v_ident, s, sizeof s);
ivy_asm_constpool_value_destroy(prop_ident);
@@ -305,7 +305,8 @@ static enum ivy_status dump_class(
printf("type:variable\n");
struct ivy_asm_constpool_value *var_ident = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_mvar.m_ident), &var_ident);
pool, fx_i32_btoh(entry.e_mvar.m_ident),
&var_ident);
if (status != IVY_OK) {
break;
}
@@ -315,7 +316,7 @@ static enum ivy_status dump_class(
break;
}
uint32_t index = b_i32_btoh(entry.e_mvar.m_index);
uint32_t index = fx_i32_btoh(entry.e_mvar.m_index);
ivy_ident_to_string(var_ident->v_ident, s, sizeof s);
ivy_asm_constpool_value_destroy(var_ident);
printf(" ident:%s, index:0x%" PRIx32
@@ -328,7 +329,7 @@ static enum ivy_status dump_class(
printf("type:method\n");
struct ivy_asm_constpool_value *sel = NULL;
status = ivy_asm_constpool_reader_read_value(
pool, b_i32_btoh(entry.e_msgh.msg_selector), &sel);
pool, fx_i32_btoh(entry.e_msgh.msg_selector), &sel);
if (status != IVY_OK) {
break;
}
@@ -338,7 +339,7 @@ static enum ivy_status dump_class(
break;
}
uint32_t block = b_i32_btoh(entry.e_msgh.msg_block);
uint32_t block = fx_i32_btoh(entry.e_msgh.msg_block);
ivy_selector_to_string(sel->v_sel, s, sizeof s);
ivy_asm_constpool_value_destroy(sel);
@@ -399,7 +400,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
enum ivy_status status
= ivy_asm_reader_open_constpool(object, 0, 0, &pool);
if (status == IVY_ERR_NO_ENTRY) {
b_err("object file has no constpool.\n");
fx_err("object file has no constpool.\n");
return status;
}
@@ -409,8 +410,8 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
struct ivy_asm_constpool_value *v;
status = ivy_asm_constpool_reader_read_value(pool, i, &v);
if (status != IVY_OK) {
b_err("cannot read constpool value");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot read constpool value");
fx_i("reason: %s", ivy_status_to_string(status));
break;
}
@@ -455,7 +456,7 @@ static enum ivy_status dump_constpool(struct ivy_asm_reader *object)
return status;
}
static void dump_instructions(b_i32 *x, size_t buffer_size)
static void dump_instructions(fx_i32 *x, size_t buffer_size)
{
size_t nr_instr = buffer_size / sizeof *x;
@@ -503,7 +504,7 @@ static enum ivy_status dump_header(
break;
}
printf(" ident=0x%04x\n", b_i32_btoh(xcls.c_ident));
printf(" ident=0x%04x\n", fx_i32_btoh(xcls.c_ident));
*dump_offset = sizeof xcls;
break;
}
@@ -520,7 +521,7 @@ static enum ivy_status dump_header(
break;
}
long index = b_i32_btoh(text.b_index);
long index = fx_i32_btoh(text.b_index);
printf(" index=0x%04lx [%ld]\n", index, index);
*dump_offset = sizeof text;
break;
@@ -584,7 +585,7 @@ static enum ivy_status dump_section(
printf(" | ");
if (flags & DUMP_INSTRUCTIONS) {
dump_instructions((b_i32 *)x, buffer_size);
dump_instructions((fx_i32 *)x, buffer_size);
} else {
dump_strings(x, buffer_size);
}
@@ -649,31 +650,34 @@ static enum ivy_status dump_section_table(struct ivy_asm_reader *reader, bool du
}
static int disassemble(
const b_command *cmd, const b_arglist *args, const b_array *_)
const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
bool header = b_arglist_get_count(args, OPT_HEADER, B_COMMAND_INVALID_ID)
bool header = fx_arglist_get_count(args, OPT_HEADER, FX_COMMAND_INVALID_ID)
> 0;
bool sections
= b_arglist_get_count(args, OPT_SECTIONS, B_COMMAND_INVALID_ID) > 0;
bool dump = b_arglist_get_count(args, OPT_DUMP, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_SECTIONS, FX_COMMAND_INVALID_ID)
> 0;
bool dump = fx_arglist_get_count(args, OPT_DUMP, FX_COMMAND_INVALID_ID) > 0;
bool constpool
= b_arglist_get_count(args, OPT_CONSTPOOL, B_COMMAND_INVALID_ID)
= fx_arglist_get_count(args, OPT_CONSTPOOL, FX_COMMAND_INVALID_ID)
> 0;
bool classes
= b_arglist_get_count(args, OPT_CLASSES, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_CLASSES, FX_COMMAND_INVALID_ID)
> 0;
const char *in_path = NULL;
b_arglist_get_string(args, B_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
fx_arglist_get_string(
args, FX_COMMAND_INVALID_ID, ARG_BIN_FILE, 0, &in_path);
if (!in_path) {
b_err("no input file specified.");
fx_err("no input file specified.");
return -1;
}
FILE *in = fopen(in_path, "rb");
if (!in) {
b_err("cannot open object file");
b_i("reason: %s", strerror(errno));
fx_err("cannot open object file");
fx_i("reason: %s", strerror(errno));
return -1;
}
@@ -682,8 +686,8 @@ static int disassemble(
enum ivy_status status = ivy_asm_reader_open(in, &reader);
if (status != IVY_OK) {
b_err("cannot open object file");
b_i("reason: %s", ivy_status_to_string(status));
fx_err("cannot open object file");
fx_i("reason: %s", ivy_status_to_string(status));
fclose(in);
return -1;
@@ -717,61 +721,61 @@ static int disassemble(
return 0;
}
B_COMMAND(CMD_DISASSEMBLE, CMD_ROOT)
FX_COMMAND(CMD_DISASSEMBLE, CMD_ROOT)
{
B_COMMAND_NAME("disassemble");
B_COMMAND_SHORT_NAME('D');
B_COMMAND_DESC("disassemble an Ivy object file.");
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(disassemble);
FX_COMMAND_NAME("disassemble");
FX_COMMAND_SHORT_NAME('D');
FX_COMMAND_DESC("disassemble an Ivy object file.");
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(disassemble);
B_COMMAND_ARG(ARG_BIN_FILE)
FX_COMMAND_ARG(ARG_BIN_FILE)
{
B_ARG_NAME("input file");
B_ARG_DESC("the Ivy object file to disassemble.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("input file");
FX_ARG_DESC("the Ivy object file to disassemble.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_OPTION(OPT_HEADER)
FX_COMMAND_OPTION(OPT_HEADER)
{
B_OPTION_SHORT_NAME('h');
B_OPTION_LONG_NAME("header");
B_OPTION_DESC("print the object file header.");
FX_OPTION_SHORT_NAME('h');
FX_OPTION_LONG_NAME("header");
FX_OPTION_DESC("print the object file header.");
}
B_COMMAND_OPTION(OPT_SECTIONS)
FX_COMMAND_OPTION(OPT_SECTIONS)
{
B_OPTION_SHORT_NAME('s');
B_OPTION_LONG_NAME("section-table");
B_OPTION_DESC("print the object file section table.");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_LONG_NAME("section-table");
FX_OPTION_DESC("print the object file section table.");
}
B_COMMAND_OPTION(OPT_DUMP)
FX_COMMAND_OPTION(OPT_DUMP)
{
B_OPTION_SHORT_NAME('d');
B_OPTION_LONG_NAME("dump");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('d');
FX_OPTION_LONG_NAME("dump");
FX_OPTION_DESC(
"decode and print the contents of each object "
"section.");
}
B_COMMAND_OPTION(OPT_CLASSES)
FX_COMMAND_OPTION(OPT_CLASSES)
{
B_OPTION_SHORT_NAME('c');
B_OPTION_LONG_NAME("classes");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('c');
FX_OPTION_LONG_NAME("classes");
FX_OPTION_DESC(
"print the classes contained in the object "
"file.");
}
B_COMMAND_OPTION(OPT_CONSTPOOL)
FX_COMMAND_OPTION(OPT_CONSTPOOL)
{
B_OPTION_SHORT_NAME('p');
B_OPTION_LONG_NAME("pool-data");
B_OPTION_DESC(
FX_OPTION_SHORT_NAME('p');
FX_OPTION_LONG_NAME("pool-data");
FX_OPTION_DESC(
"print the constant pool data in the object "
"file.");
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -1,41 +1,41 @@
#include "cmd.h"
#include <blue/cmd.h>
#include <fx/cmd.h>
enum {
ARG_FILE
};
static int exec(const b_command *cmd, const b_arglist *args, const b_array *_)
static int exec(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
return 0;
}
B_COMMAND(CMD_ROOT, B_COMMAND_INVALID_ID)
FX_COMMAND(CMD_ROOT, FX_COMMAND_INVALID_ID)
{
B_COMMAND_NAME("ivy");
B_COMMAND_DESC("evaluate an Ivy source file or Ivy object file.");
B_COMMAND_HELP_OPTION();
B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT);
B_COMMAND_FUNCTION(exec);
FX_COMMAND_NAME("ivy");
FX_COMMAND_DESC("evaluate an Ivy source file or Ivy object file.");
FX_COMMAND_HELP_OPTION();
FX_COMMAND_FLAGS(FX_COMMAND_SHOW_HELP_BY_DEFAULT);
FX_COMMAND_FUNCTION(exec);
B_COMMAND_ARG(ARG_FILE)
FX_COMMAND_ARG(ARG_FILE)
{
B_ARG_NAME("file");
B_ARG_DESC("The file to execute.");
B_ARG_NR_VALUES(1);
FX_ARG_NAME("file");
FX_ARG_DESC("The file to execute.");
FX_ARG_NR_VALUES(1);
}
B_COMMAND_USAGE()
FX_COMMAND_USAGE()
{
B_COMMAND_USAGE_OPT_PLACEHOLDER();
B_COMMAND_USAGE_ARG(ARG_FILE);
FX_COMMAND_USAGE_OPT_PLACEHOLDER();
FX_COMMAND_USAGE_ARG(ARG_FILE);
}
B_COMMAND_USAGE()
FX_COMMAND_USAGE()
{
B_COMMAND_USAGE_COMMAND_PLACEHOLDER();
B_COMMAND_USAGE_OPT_PLACEHOLDER();
B_COMMAND_USAGE_ARG_PLACEHOLDER();
FX_COMMAND_USAGE_COMMAND_PLACEHOLDER();
FX_COMMAND_USAGE_OPT_PLACEHOLDER();
FX_COMMAND_USAGE_ARG_PLACEHOLDER();
}
}

View File

@@ -1,30 +1,32 @@
#include <blue/cmd.h>
#include "cmd.h"
#include <ivy/lang/lex.h>
#include <fx/cmd.h>
#include <fx/term.h>
#include <ivy/lang/internal.h>
#include <blue/term.h>
#include <ivy/lang/lex.h>
enum {
OPT_PRINT_SYMBOLS = 0x1000,
OPT_PRINT_KEYWORDS,
};
static int internal(const b_command *cmd, const b_arglist *args, const b_array *_)
static int internal(
const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
struct ivy_lexer *lex;
enum ivy_status status = ivy_lexer_create(&lex);
if (status != IVY_OK) {
b_err("failed to initialise lexer (error %s)",
ivy_status_to_string(status));
fx_err("failed to initialise lexer (error %s)",
ivy_status_to_string(status));
return -1;
}
if (b_arglist_get_count(args, OPT_PRINT_SYMBOLS, B_COMMAND_INVALID_ID)) {
if (fx_arglist_get_count(args, OPT_PRINT_SYMBOLS, FX_COMMAND_INVALID_ID)) {
internal_lexer_print_symbol_tree(lex);
}
if (b_arglist_get_count(args, OPT_PRINT_KEYWORDS, B_COMMAND_INVALID_ID)) {
if (fx_arglist_get_count(args, OPT_PRINT_KEYWORDS, FX_COMMAND_INVALID_ID)) {
internal_lexer_print_keyword_dict(lex);
}
@@ -33,28 +35,29 @@ static int internal(const b_command *cmd, const b_arglist *args, const b_array *
return 0;
}
B_COMMAND(CMD_INTERNAL, CMD_ROOT)
FX_COMMAND(CMD_INTERNAL, CMD_ROOT)
{
B_COMMAND_NAME("internal");
B_COMMAND_SHORT_NAME('X');
B_COMMAND_DESC("internal frontend debugging tools.");
B_COMMAND_FUNCTION(internal);
FX_COMMAND_NAME("internal");
FX_COMMAND_SHORT_NAME('X');
FX_COMMAND_DESC("internal frontend debugging tools.");
FX_COMMAND_FUNCTION(internal);
B_COMMAND_OPTION(OPT_PRINT_SYMBOLS)
FX_COMMAND_OPTION(OPT_PRINT_SYMBOLS)
{
B_OPTION_LONG_NAME("print-symbols");
B_OPTION_SHORT_NAME('s');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("print-symbols");
FX_OPTION_SHORT_NAME('s');
FX_OPTION_DESC(
"print the symbol tree used by the language lexer.");
}
B_COMMAND_OPTION(OPT_PRINT_KEYWORDS)
FX_COMMAND_OPTION(OPT_PRINT_KEYWORDS)
{
B_OPTION_LONG_NAME("print-keywords");
B_OPTION_SHORT_NAME('k');
B_OPTION_DESC(
"print the keyword dictionary used by the language lexer.");
FX_OPTION_LONG_NAME("print-keywords");
FX_OPTION_SHORT_NAME('k');
FX_OPTION_DESC(
"print the keyword dictionary used by the language "
"lexer.");
}
B_COMMAND_HELP_OPTION();
FX_COMMAND_HELP_OPTION();
}

View File

@@ -2,14 +2,12 @@
#include "../line-ed/line-ed.h"
#include "cmd.h"
#include <blue/cmd.h>
#include <blue/term.h>
#include <fx/cmd.h>
#include <fx/term.h>
#include <ivy/lang/ast.h>
#include <ivy/lang/codegen.h>
#include <ivy/lang/lex.h>
#include <mie/ctx.h>
#include <mie/ir/convert.h>
#include <mie/ir/value.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -27,7 +25,10 @@ struct repl {
struct ivy_lexer *r_lex;
struct ivy_parser *r_parse;
struct ivy_codegen *r_codegen;
#if 0
struct mie_ir_converter *r_converter;
#endif
};
static void skip_line(struct ivy_lexer *lex)
@@ -89,17 +90,21 @@ static int repl_eval_node(struct repl *repl, struct ivy_ast_node *node)
ivy_codegen_push_eof(repl->r_codegen);
struct mie_module *mod = ivy_codegen_get_current_module(repl->r_codegen);
#if 0
mie_ir_converter_set_src_value(repl->r_converter, MIE_VALUE(mod));
mie_ir_converter_process(repl->r_converter);
#endif
return 0;
}
static void repl_destroy(struct repl *repl)
{
#if 0
if (repl->r_converter) {
mie_ir_converter_destroy(repl->r_converter);
}
#endif
if (repl->r_codegen) {
ivy_codegen_destroy(repl->r_codegen);
@@ -117,9 +122,11 @@ static void repl_destroy(struct repl *repl)
line_ed_destroy(repl->r_ed);
}
#if 0
if (repl->r_mie) {
mie_ctx_destroy(repl->r_mie);
}
#endif
free(repl);
}
@@ -167,6 +174,7 @@ static enum ivy_status repl_create(struct repl **out)
return status;
}
#if 0
repl->r_converter
= mie_ir_converter_create(repl->r_mie, MIE_IR_MEM, MIE_IR_TEXT);
if (!repl->r_converter) {
@@ -175,31 +183,32 @@ static enum ivy_status repl_create(struct repl **out)
}
mie_ir_converter_set_dest_file(repl->r_converter, stdout);
#endif
*out = repl;
return IVY_OK;
}
int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
int repl(const fx_command *cmd, const fx_arglist *args, const fx_array *_)
{
#if 0
b_printf(
fx_printf(
"[bold,bright_red]error[[E0384][reset,bold,white]: cannot "
"assign twice to immutable variable `i`[reset]\n");
b_printf("[bold,bright_blue] -->[reset] src/main.rs:7:3\n");
b_printf("[bold,bright_blue] |[reset]\n");
b_printf("[bold,bright_blue]4 |[reset] let i = 0;\n");
b_printf("[bold,bright_blue] | -[reset]\n");
b_printf("[bold,bright_blue] | |[reset]\n");
b_printf(
fx_printf("[bold,bright_blue] -->[reset] src/main.rs:7:3\n");
fx_printf("[bold,bright_blue] |[reset]\n");
fx_printf("[bold,bright_blue]4 |[reset] let i = 0;\n");
fx_printf("[bold,bright_blue] | -[reset]\n");
fx_printf("[bold,bright_blue] | |[reset]\n");
fx_printf(
"[bold,bright_blue] | first assignment to "
"`i`[reset]\n");
b_printf(
fx_printf(
"[bold,bright_blue] | help: make this binding "
"mutable: `mut i`[reset]\n");
b_printf("[bold,bright_blue]...[reset]\n");
b_printf("[bold,bright_blue]7 |[reset] i += 1;\n");
b_printf(
fx_printf("[bold,bright_blue]...[reset]\n");
fx_printf("[bold,bright_blue]7 |[reset] i += 1;\n");
fx_printf(
"[bold,bright_blue] |[bold,bright_red] ^^^^^^ cannot "
"assign twice to immutable variable[reset]\n");
#endif
@@ -210,14 +219,15 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
return -1;
}
repl->r_show_lex = b_arglist_get_count(
args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID)
repl->r_show_lex = fx_arglist_get_count(
args, OPT_SHOW_LEX_TOKENS, FX_COMMAND_INVALID_ID)
> 0;
repl->r_show_ast = b_arglist_get_count(
args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID)
repl->r_show_ast = fx_arglist_get_count(
args, OPT_SHOW_AST_NODES, FX_COMMAND_INVALID_ID)
> 0;
repl->r_show_ir
= b_arglist_get_count(args, OPT_SHOW_IR, B_COMMAND_INVALID_ID) > 0;
= fx_arglist_get_count(args, OPT_SHOW_IR, FX_COMMAND_INVALID_ID)
> 0;
while (true) {
struct ivy_token *tok = ivy_lexer_read(repl->r_lex);
@@ -227,9 +237,9 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
}
if (status != IVY_OK) {
b_err("lex error (%s)",
ivy_status_to_string(
ivy_lexer_get_status(repl->r_lex)));
fx_err("lex error (%s)",
ivy_status_to_string(
ivy_lexer_get_status(repl->r_lex)));
continue;
}
@@ -240,7 +250,7 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
status = ivy_parser_push_token(repl->r_parse, tok);
if (status != IVY_OK) {
b_err("parse error (%s)", ivy_status_to_string(status));
fx_err("parse error (%s)", ivy_status_to_string(status));
ivy_token_destroy(tok);
skip_line(repl->r_lex);
continue;
@@ -257,7 +267,7 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
repl_eval_node(repl, unit);
ivy_codegen_end_module(repl->r_codegen, &mod);
mie_value_destroy(MIE_VALUE(mod));
// mie_value_destroy(MIE_VALUE(mod));
#if 0
while ((child = ivy_parser_dequeue_node(repl->r_parse))) {
@@ -271,35 +281,35 @@ int repl(const b_command *cmd, const b_arglist *args, const b_array *_)
return 0;
}
B_COMMAND(CMD_REPL, CMD_ROOT)
FX_COMMAND(CMD_REPL, CMD_ROOT)
{
B_COMMAND_NAME("shell");
B_COMMAND_SHORT_NAME('S');
B_COMMAND_DESC("start an interactive Ivy shell.");
B_COMMAND_HELP_OPTION();
B_COMMAND_FUNCTION(repl);
FX_COMMAND_NAME("shell");
FX_COMMAND_SHORT_NAME('S');
FX_COMMAND_DESC("start an interactive Ivy shell.");
FX_COMMAND_HELP_OPTION();
FX_COMMAND_FUNCTION(repl);
B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
FX_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS)
{
B_OPTION_LONG_NAME("show-lex");
B_OPTION_SHORT_NAME('l');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-lex");
FX_OPTION_SHORT_NAME('l');
FX_OPTION_DESC(
"print the lexical tokens generated from the input.");
}
B_COMMAND_OPTION(OPT_SHOW_AST_NODES)
FX_COMMAND_OPTION(OPT_SHOW_AST_NODES)
{
B_OPTION_LONG_NAME("show-ast");
B_OPTION_SHORT_NAME('a');
B_OPTION_DESC(
FX_OPTION_LONG_NAME("show-ast");
FX_OPTION_SHORT_NAME('a');
FX_OPTION_DESC(
"print the abstract syntax tree generated from the "
"input.");
}
B_COMMAND_OPTION(OPT_SHOW_IR)
FX_COMMAND_OPTION(OPT_SHOW_IR)
{
B_OPTION_LONG_NAME("show-ir");
B_OPTION_SHORT_NAME('i');
B_OPTION_DESC("print the Mie IR generated from the input.");
FX_OPTION_LONG_NAME("show-ir");
FX_OPTION_SHORT_NAME('i');
FX_OPTION_DESC("print the Mie IR generated from the input.");
}
}

View File

@@ -1,7 +1,7 @@
#include "debug.h"
#include <blue/ds/string.h>
#include <blue/term.h>
#include <fx/ds/string.h>
#include <fx/term.h>
#include <ivy/asm/lex.h>
#include <ivy/lang/ast.h>
#include <ivy/lang/lex.h>
@@ -14,41 +14,41 @@ extern void print_lex_token(struct ivy_token *tok)
switch (tok->t_type) {
case IVY_TOK_KEYWORD:
b_puts("[magenta]");
fx_puts("[magenta]");
break;
case IVY_TOK_SYMBOL:
b_puts("[blue]");
fx_puts("[blue]");
break;
case IVY_TOK_ATOM:
b_puts("[yellow]");
fx_puts("[yellow]");
break;
case IVY_TOK_INT:
case IVY_TOK_DOUBLE:
b_puts("[yellow]");
fx_puts("[yellow]");
break;
case IVY_TOK_LABEL:
b_puts("[red]");
fx_puts("[red]");
break;
case IVY_TOK_IDENT:
b_puts("[cyan]");
fx_puts("[cyan]");
break;
case IVY_TOK_STRING:
b_puts("[green]");
fx_puts("[green]");
break;
case IVY_TOK_STR_START:
b_puts("[green]");
fx_puts("[green]");
break;
case IVY_TOK_STR_END:
b_puts("[green]");
fx_puts("[green]");
break;
case IVY_TOK_LINEFEED:
b_puts("[dark_grey]");
fx_puts("[dark_grey]");
break;
default:
break;
}
b_puts(ivy_lex_token_type_to_string(tok->t_type));
fx_puts(ivy_lex_token_type_to_string(tok->t_type));
switch (tok->t_type) {
case IVY_TOK_IDENT:
@@ -73,40 +73,40 @@ extern void print_lex_token(struct ivy_token *tok)
break;
}
b_puts("[reset]\n");
fx_puts("[reset]\n");
}
extern void print_asm_lex_token(struct ivy_asm_token *tok)
{
switch (tok->t_type) {
case IVY_ASM_TOK_KEYWORD:
b_puts("[magenta]");
fx_puts("[magenta]");
break;
case IVY_ASM_TOK_SYMBOL:
b_puts("[blue]");
fx_puts("[blue]");
break;
case IVY_ASM_TOK_INT:
case IVY_ASM_TOK_DOUBLE:
case IVY_ASM_TOK_LABEL_REF:
b_puts("[yellow]");
fx_puts("[yellow]");
break;
case IVY_ASM_TOK_LABEL:
b_puts("[red]");
fx_puts("[red]");
break;
case IVY_ASM_TOK_IDENT:
b_puts("[cyan]");
fx_puts("[cyan]");
break;
case IVY_ASM_TOK_STRING:
b_puts("[green]");
fx_puts("[green]");
break;
case IVY_ASM_TOK_LINEFEED:
b_puts("[dark_grey]");
fx_puts("[dark_grey]");
break;
default:
break;
}
b_puts(ivy_asm_token_type_to_string(tok->t_type));
fx_puts(ivy_asm_token_type_to_string(tok->t_type));
switch (tok->t_type) {
case IVY_ASM_TOK_IDENT:
@@ -135,7 +135,7 @@ extern void print_asm_lex_token(struct ivy_asm_token *tok)
break;
}
b_puts("[reset]\n");
fx_puts("[reset]\n");
}
extern enum ivy_status print_ast_node(
@@ -154,7 +154,7 @@ extern enum ivy_status print_ast_node(
if (!args || (args && args->indent)) {
for (unsigned int i = 0; i < node->n_it.it_depth; i++) {
b_puts(" ");
fx_puts(" ");
}
}
@@ -172,13 +172,13 @@ extern enum ivy_status print_ast_node(
case IVY_AST_TRY:
case IVY_AST_RETURN:
case IVY_AST_GLOBAL:
b_puts("[magenta]");
fx_puts("[magenta]");
break;
case IVY_AST_OP:
b_puts("[blue]");
fx_puts("[blue]");
break;
case IVY_AST_MSG:
b_puts("[red]");
fx_puts("[red]");
break;
case IVY_AST_INT:
case IVY_AST_DOUBLE:
@@ -187,73 +187,73 @@ extern enum ivy_status print_ast_node(
case IVY_AST_C_TRUE:
case IVY_AST_C_FALSE:
case IVY_AST_C_NULL:
b_puts("[yellow]");
fx_puts("[yellow]");
break;
case IVY_AST_COND:
case IVY_AST_BLOCK:
case IVY_AST_TRY_CATCH:
b_puts("[red]");
fx_puts("[red]");
break;
case IVY_AST_IDENT:
case IVY_AST_SELECTOR:
b_puts("[cyan]");
fx_puts("[cyan]");
break;
case IVY_AST_STRING:
case IVY_AST_FSTRING:
b_puts("[green]");
fx_puts("[green]");
break;
case IVY_AST_DISCARD:
b_puts("[dark_grey]");
fx_puts("[dark_grey]");
break;
default:
break;
}
b_string *str = b_string_create();
fx_string *str = fx_string_create();
ivy_ast_node_to_string(node, str);
b_printf("%s", b_string_ptr(str));
b_string_unref(str);
fx_printf("%s", fx_string_ptr(str));
fx_string_unref(str);
#if 0
b_puts(ivy_ast_node_type_to_string(node->n_type));
fx_puts(ivy_ast_node_type_to_string(node->n_type));
switch (node->n_type) {
case IVY_AST_INT: {
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)node;
b_printf(" (%llu)", v->n_value->t_int);
fx_printf(" (%llu)", v->n_value->t_int);
break;
}
case IVY_AST_DOUBLE: {
struct ivy_ast_double_node *v = (struct ivy_ast_double_node *)node;
b_printf(" (%.2lf)", v->n_value->t_double);
fx_printf(" (%.2lf)", v->n_value->t_double);
break;
}
case IVY_AST_IDENT: {
struct ivy_ast_ident_node *v = (struct ivy_ast_ident_node *)node;
b_printf(" (%s)", v->n_content->t_str);
fx_printf(" (%s)", v->n_content->t_str);
break;
}
case IVY_AST_STRING: {
struct ivy_ast_string_node *v = (struct ivy_ast_string_node *)node;
b_printf(" (\"%s\")", v->n_value->t_str);
fx_printf(" (\"%s\")", v->n_value->t_str);
break;
}
case IVY_AST_ATOM: {
struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node;
b_printf(" (%s)", v->n_content->t_str);
fx_printf(" (%s)", v->n_content->t_str);
break;
}
case IVY_AST_SELECTOR: {
struct ivy_ast_selector_node *v
= (struct ivy_ast_selector_node *)node;
b_printf(" [[");
fx_printf(" [[");
switch (v->n_recipient) {
case IVY_SELECTOR_RECIPIENT_CLASS:
b_putc('+');
fx_putc('+');
break;
case IVY_SELECTOR_RECIPIENT_OBJECT:
b_putc('-');
fx_putc('-');
break;
default:
/* this will occur if the selector is being used to send
@@ -263,101 +263,101 @@ extern enum ivy_status print_ast_node(
}
if (v->n_msg_name) {
b_printf("%s", v->n_msg_name->t_str);
fx_printf("%s", v->n_msg_name->t_str);
}
if (v->n_msg_name && !b_queue_empty(&v->n_arg_labels)) {
b_putc('(');
if (v->n_msg_name && !fx_queue_empty(&v->n_arg_labels)) {
fx_putc('(');
}
b_queue_iterator label_it = {0};
b_queue_iterator name_it = {0};
fx_queue_iterator label_it = {0};
fx_queue_iterator name_it = {0};
b_queue_iterator_begin(&v->n_arg_labels, &label_it);
b_queue_iterator_begin(&v->n_arg_names, &name_it);
fx_queue_iterator_begin(&v->n_arg_labels, &label_it);
fx_queue_iterator_begin(&v->n_arg_names, &name_it);
bool name_present = false;
int i = 0;
while (b_queue_iterator_is_valid(&label_it)) {
while (fx_queue_iterator_is_valid(&label_it)) {
if (i > 0 && name_present) {
fputc(' ', stdout);
}
struct ivy_token *label = b_unbox(
struct ivy_token *label = fx_unbox(
struct ivy_token, label_it.entry, t_entry);
struct ivy_token *name = b_unbox(
struct ivy_token *name = fx_unbox(
struct ivy_token, name_it.entry, t_entry);
if (label) {
b_printf("%s:", label->t_str);
fx_printf("%s:", label->t_str);
}
if (name) {
b_printf("%s", name->t_str);
fx_printf("%s", name->t_str);
}
name_present = (name != NULL);
i++;
b_queue_iterator_next(&label_it);
b_queue_iterator_next(&name_it);
fx_queue_iterator_next(&label_it);
fx_queue_iterator_next(&name_it);
}
if (v->n_msg_name && !b_queue_empty(&v->n_arg_labels)) {
b_putc(')');
if (v->n_msg_name && !fx_queue_empty(&v->n_arg_labels)) {
fx_putc(')');
}
b_puts("]");
fx_puts("]");
break;
}
case IVY_AST_OP: {
struct ivy_ast_op_node *v = (struct ivy_ast_op_node *)node;
b_printf(" (%s)", ivy_operator_id_to_string(v->n_op->op_id));
fx_printf(" (%s)", ivy_operator_id_to_string(v->n_op->op_id));
break;
}
case IVY_AST_CLASS: {
struct ivy_ast_class_node *v = (struct ivy_ast_class_node *)node;
b_printf(" (%s)", v->n_ident->t_str);
fx_printf(" (%s)", v->n_ident->t_str);
break;
}
case IVY_AST_UNIT_PACKAGE: {
struct ivy_ast_unit_package_node *v
= (struct ivy_ast_unit_package_node *)node;
b_printf(" (");
b_queue_iterator it = {0};
fx_printf(" (");
fx_queue_iterator it = {0};
int i = 0;
b_queue_foreach (&it, &v->n_ident) {
fx_queue_foreach (&it, &v->n_ident) {
struct ivy_token *tok
= b_unbox(struct ivy_token, it.entry, t_entry);
= fx_unbox(struct ivy_token, it.entry, t_entry);
if (i > 0) {
b_printf(".");
fx_printf(".");
}
b_printf("%s", tok->t_str);
fx_printf("%s", tok->t_str);
i++;
}
b_printf(")");
fx_printf(")");
break;
}
case IVY_AST_UNIT_IMPORT: {
struct ivy_ast_unit_import_node *v
= (struct ivy_ast_unit_import_node *)node;
b_printf(" (");
b_queue_iterator it = {0};
fx_printf(" (");
fx_queue_iterator it = {0};
int i = 0;
b_queue_foreach (&it, &v->n_ident) {
fx_queue_foreach (&it, &v->n_ident) {
struct ivy_token *tok
= b_unbox(struct ivy_token, it.entry, t_entry);
= fx_unbox(struct ivy_token, it.entry, t_entry);
if (i > 0) {
b_printf(".");
fx_printf(".");
}
b_printf("%s", tok->t_str);
fx_printf("%s", tok->t_str);
i++;
}
b_printf(")");
fx_printf(")");
break;
}
default:
@@ -389,6 +389,6 @@ extern enum ivy_status print_ast_node(
}
#endif
b_puts("[reset]\n");
fx_puts("[reset]\n");
return IVY_OK;
}

View File

@@ -1,42 +1,42 @@
#include "line-ed.h"
#include <blue/ds/array.h>
#include <blue/ds/string.h>
#include <fx/ds/array.h>
#include <fx/ds/string.h>
void alloc_empty_history_entry(struct line_ed *ed)
{
b_string *str = (b_string *)b_array_at(
ed->l_history, b_array_size(ed->l_history) - 1);
if (!str || b_string_get_size(str, B_STRLEN_NORMAL) > 0) {
str = b_string_create();
b_array_append(ed->l_history, (b_object *)str);
fx_string *str = (fx_string *)fx_array_at(
ed->l_history, fx_array_size(ed->l_history) - 1);
if (!str || fx_string_get_size(str, FX_STRLEN_NORMAL) > 0) {
str = fx_string_create();
fx_array_append(ed->l_history, (fx_object *)str);
}
ed->l_history_pos = b_array_size(ed->l_history) - 1;
ed->l_history_pos = fx_array_size(ed->l_history) - 1;
}
void save_buf_to_history(struct line_ed *ed)
{
b_string *cur = (b_string *)b_array_get(ed->l_history, ed->l_history_pos);
b_string_replace_all(cur, ed->l_buf);
fx_string *cur = (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
fx_string_replace_all(cur, ed->l_buf);
}
void append_buf_to_history(struct line_ed *ed)
{
b_string *cur = (b_string *)b_array_get(ed->l_history, ed->l_history_pos);
fx_string *cur = (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
char s[] = {'\n', 0};
b_string_append_cstr(cur, s);
b_string_append_cstr(cur, ed->l_buf);
fx_string_append_cstr(cur, s);
fx_string_append_cstr(cur, ed->l_buf);
}
void load_buf_from_history(struct line_ed *ed)
{
b_string *cur = (b_string *)b_array_at(ed->l_history, ed->l_history_pos);
fx_string *cur = (fx_string *)fx_array_at(ed->l_history, ed->l_history_pos);
size_t len
= MIN((size_t)(ed->l_buf_end - ed->l_buf - 1),
b_string_get_size(cur, B_STRLEN_NORMAL));
fx_string_get_size(cur, FX_STRLEN_NORMAL));
memcpy(ed->l_buf, b_string_ptr(cur), len);
memcpy(ed->l_buf, fx_string_ptr(cur), len);
ed->l_buf[len] = '\0';
unsigned int x = 0, y = 0;
@@ -57,11 +57,11 @@ void load_buf_from_history(struct line_ed *ed)
const char *last_history_line(struct line_ed *ed)
{
size_t nlines = b_array_size(ed->l_history);
size_t nlines = fx_array_size(ed->l_history);
if (nlines < 2) {
return NULL;
}
b_string *last = (b_string *)b_array_at(ed->l_history, nlines - 2);
return b_string_ptr(last);
fx_string *last = (fx_string *)fx_array_at(ed->l_history, nlines - 2);
return fx_string_ptr(last);
}

View File

@@ -30,22 +30,22 @@ int compare_coords(size_t ax, size_t ay, size_t bx, size_t by)
struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
{
if (b_queue_empty(&ed->l_hl_ranges)) {
if (fx_queue_empty(&ed->l_hl_ranges)) {
return NULL;
}
struct hl_range *best_match = NULL;
b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
fx_queue_entry *entry = fx_queue_first(&ed->l_hl_ranges);
while (entry) {
struct hl_range *cur = b_unbox(struct hl_range, entry, h_entry);
struct hl_range *cur = fx_unbox(struct hl_range, entry, h_entry);
int cmp_end = compare_coords(x, y, cur->h_end_x, cur->h_end_y);
if (cmp_end != 1) {
return cur;
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
return NULL;
@@ -53,20 +53,20 @@ struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y)
struct hl_range *get_next_hl_range(struct hl_range *range)
{
b_queue_entry *entry = &range->h_entry;
entry = b_queue_next(entry);
fx_queue_entry *entry = &range->h_entry;
entry = fx_queue_next(entry);
if (!entry) {
return NULL;
}
range = b_unbox(struct hl_range, entry, h_entry);
range = fx_unbox(struct hl_range, entry, h_entry);
return range;
}
int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
int apply_hl_range(struct hl_range *range, fx_tty *tty, size_t x, size_t y)
{
if (!range) {
b_tty_reset_vmode(tty);
fx_tty_reset_vmode(tty);
return 0;
}
@@ -74,11 +74,11 @@ int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
int cmp_end = compare_coords(x, y, range->h_end_x, range->h_end_y);
if (cmp_start < 0) {
b_tty_reset_vmode(tty);
fx_tty_reset_vmode(tty);
}
if (cmp_start >= 0 && cmp_end <= 0) {
b_tty_set_vmode(tty, &range->h_vmode);
fx_tty_set_vmode(tty, &range->h_vmode);
}
if (cmp_end == 1) {
@@ -90,7 +90,7 @@ int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y)
struct hl_range *create_highlight(
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
const b_tty_vmode *vmode)
const fx_tty_vmode *vmode)
{
struct hl_range *out = malloc(sizeof *out);
if (!out) {
@@ -179,7 +179,7 @@ static void move_start_to_meet_end(
void line_ed_put_highlight(
struct line_ed *ed, unsigned long start_x, unsigned long start_y,
unsigned long end_x, unsigned long end_y, const struct b_tty_vmode *vmode)
unsigned long end_x, unsigned long end_y, const struct fx_tty_vmode *vmode)
{
struct hl_range *highlight
= create_highlight(start_x, start_y, end_x, end_y, vmode);
@@ -189,30 +189,30 @@ void line_ed_put_highlight(
struct hl_range *h2 = NULL;
b_queue_entry *entry = NULL;
entry = b_queue_first(&ed->l_hl_ranges);
fx_queue_entry *entry = NULL;
entry = fx_queue_first(&ed->l_hl_ranges);
if (!entry) {
b_queue_push_back(&ed->l_hl_ranges, &highlight->h_entry);
fx_queue_push_back(&ed->l_hl_ranges, &highlight->h_entry);
return;
}
struct hl_range *cur = NULL;
enum hl_range_comparison prev_cmp = -1;
b_queue_entry *insert_before = NULL;
b_queue_entry *insert_after = NULL;
fx_queue_entry *insert_before = NULL;
fx_queue_entry *insert_after = NULL;
bool end = false;
while (entry) {
b_queue_entry *next = b_queue_next(entry);
cur = b_unbox(struct hl_range, entry, h_entry);
fx_queue_entry *next = fx_queue_next(entry);
cur = fx_unbox(struct hl_range, entry, h_entry);
enum hl_range_comparison cmp = compare_hl_ranges(cur, highlight);
switch (cmp) {
case HL_RANGE_A_IN_B:
b_queue_delete(&ed->l_hl_ranges, entry);
fx_queue_delete(&ed->l_hl_ranges, entry);
free(cur);
break;
case HL_RANGE_B_IN_A:
@@ -220,10 +220,10 @@ void line_ed_put_highlight(
h2 = create_highlight(
0, 0, cur->h_end_x, cur->h_end_y, &cur->h_vmode);
move_start_to_meet_end(h2, highlight);
b_queue_insert_after(
fx_queue_insert_after(
&ed->l_hl_ranges, &highlight->h_entry,
&cur->h_entry);
b_queue_insert_after(
fx_queue_insert_after(
&ed->l_hl_ranges, &h2->h_entry,
&highlight->h_entry);
insert_before = insert_after = NULL;
@@ -239,7 +239,7 @@ void line_ed_put_highlight(
insert_before = entry;
break;
case HL_RANGE_GREATER:
b_queue_insert_before(
fx_queue_insert_before(
&ed->l_hl_ranges, &highlight->h_entry, entry);
insert_before = insert_after = NULL;
end = true;
@@ -255,32 +255,32 @@ void line_ed_put_highlight(
}
if (insert_before) {
b_queue_insert_before(
fx_queue_insert_before(
&ed->l_hl_ranges, &highlight->h_entry, insert_before);
} else if (insert_after) {
b_queue_insert_after(
fx_queue_insert_after(
&ed->l_hl_ranges, &highlight->h_entry, insert_after);
}
}
void line_ed_clear_highlights(struct line_ed *ed)
{
b_queue_entry *entry = b_queue_pop_front(&ed->l_hl_ranges);
fx_queue_entry *entry = fx_queue_pop_front(&ed->l_hl_ranges);
while (entry) {
struct hl_range *range = b_unbox(struct hl_range, entry, h_entry);
struct hl_range *range = fx_unbox(struct hl_range, entry, h_entry);
free(range);
entry = b_queue_pop_front(&ed->l_hl_ranges);
entry = fx_queue_pop_front(&ed->l_hl_ranges);
}
}
void line_ed_print_highlights(struct line_ed *ed)
{
b_queue_entry *entry = b_queue_first(&ed->l_hl_ranges);
fx_queue_entry *entry = fx_queue_first(&ed->l_hl_ranges);
while (entry) {
struct hl_range *h = b_unbox(struct hl_range, entry, h_entry);
struct hl_range *h = fx_unbox(struct hl_range, entry, h_entry);
printf("(%zu, %zu) -> (%zu, %zu)\n", h->h_start_x, h->h_start_y,
h->h_end_x, h->h_end_y);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -1,9 +1,9 @@
#ifndef LINE_ED_HL_RANGE_H_
#define LINE_ED_HL_RANGE_H_
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include <blue/core/queue.h>
#include <fx/core/queue.h>
struct line_ed;
@@ -20,18 +20,18 @@ enum hl_range_comparison {
struct hl_range {
size_t h_start_x, h_start_y;
size_t h_end_x, h_end_y;
b_tty_vmode h_vmode;
b_queue_entry h_entry;
fx_tty_vmode h_vmode;
fx_queue_entry h_entry;
};
extern int compare_coords(size_t ax, size_t ay, size_t bx, size_t by);
extern struct hl_range *get_hl_range(struct line_ed *ed, size_t x, size_t y);
extern struct hl_range *get_next_hl_range(struct hl_range *range);
extern int apply_hl_range(struct hl_range *range, b_tty *tty, size_t x, size_t y);
extern int apply_hl_range(struct hl_range *range, fx_tty *tty, size_t x, size_t y);
extern struct hl_range *create_highlight(
size_t start_x, size_t start_y, size_t end_x, size_t end_y,
const struct b_tty_vmode *vmode);
const struct fx_tty_vmode *vmode);
extern enum hl_range_comparison compare_hl_ranges(
const struct hl_range *a, const struct hl_range *b);

View File

@@ -4,38 +4,38 @@
void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook)
{
b_queue_push_back(&ed->l_hooks, &hook->hook_entry);
fx_queue_push_back(&ed->l_hooks, &hook->hook_entry);
}
void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook)
{
b_queue_delete(&ed->l_hooks, &hook->hook_entry);
fx_queue_delete(&ed->l_hooks, &hook->hook_entry);
}
void hook_keypress(struct line_ed *ed, b_keycode key)
void hook_keypress(struct line_ed *ed, fx_keycode key)
{
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
fx_queue_entry *entry = fx_queue_first(&ed->l_hooks);
while (entry) {
struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, entry, hook_entry);
= fx_unbox(struct line_ed_hook, entry, hook_entry);
if (hook->hook_keypress) {
hook->hook_keypress(ed, hook, key);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}
void hook_buffer_modified(struct line_ed *ed)
{
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
fx_queue_entry *entry = fx_queue_first(&ed->l_hooks);
while (entry) {
struct line_ed_hook *hook
= b_unbox(struct line_ed_hook, entry, hook_entry);
= fx_unbox(struct line_ed_hook, entry, hook_entry);
if (hook->hook_buffer_modified) {
hook->hook_buffer_modified(ed, hook);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -1,7 +1,7 @@
#ifndef LINE_ED_HOOK_H_
#define LINE_ED_HOOK_H_
#include <blue/term/tty.h>
#include <fx/term/tty.h>
enum hook_id {
HOOK_KEYPRESS,
@@ -10,7 +10,7 @@ enum hook_id {
struct line_ed;
extern void hook_keypress(struct line_ed *ed, b_keycode key);
extern void hook_keypress(struct line_ed *ed, fx_keycode key);
extern void hook_buffer_modified(struct line_ed *ed);
#endif

View File

@@ -113,7 +113,7 @@ void cursor_left(struct line_ed *ed)
{
if (ed->l_cursor_x != 0) {
//fputs("\010", stdout);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -1);
fflush(stdout);
ed->l_cursor_x--;
ed->l_buf_ptr--;
@@ -135,8 +135,8 @@ void cursor_left(struct line_ed *ed)
ed->l_cursor_x = len - 1;
//printf("\033[A\033[%dG", len + prompt_len);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, (int)(len + prompt_len));
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, (int)(len + prompt_len));
fflush(stdout);
}
@@ -151,7 +151,7 @@ void cursor_right(struct line_ed *ed)
ed->l_cursor_x++;
ed->l_buf_ptr++;
//fputs("\033[C", stdout);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, 1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, 1);
fflush(stdout);
return;
}
@@ -165,8 +165,8 @@ void cursor_right(struct line_ed *ed)
ed->l_buf_ptr++;
//printf("\033[B\033[G");
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, 1);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, 0);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, 1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, 0);
fflush(stdout);
}
@@ -178,13 +178,13 @@ void arrow_up(struct line_ed *ed)
if (ed->l_cursor_y > 0) {
//printf("\033[%uA", ed->l_cursor_y);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (long long)ed->l_cursor_y);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, (long long)ed->l_cursor_y);
}
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
b_tty_move_cursor_x(
ed->l_tty, B_TTY_POS_START, (long long)prompt_length(ed, PROMPT_MAIN));
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
fx_tty_move_cursor_x(
ed->l_tty, FX_TTY_POS_START, (long long)prompt_length(ed, PROMPT_MAIN));
fx_tty_clear(ed->l_tty, FX_TTY_CLEAR_SCREEN | FX_TTY_CLEAR_FROM_CURSOR);
save_buf_to_history(ed);
ed->l_history_pos--;
@@ -196,18 +196,18 @@ void arrow_up(struct line_ed *ed)
void arrow_down(struct line_ed *ed)
{
if (ed->l_history_pos == b_array_size(ed->l_history) - 1) {
if (ed->l_history_pos == fx_array_size(ed->l_history) - 1) {
return;
}
if (ed->l_cursor_y > 0) {
//printf("\033[%uA", ed->l_cursor_y);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, (int)ed->l_cursor_y);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, (int)ed->l_cursor_y);
}
//printf("\033[%zuG\033[J", prompt_length(ed, PROMPT_MAIN) + 1);
b_tty_move_cursor_x(
ed->l_tty, B_TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
fx_tty_move_cursor_x(
ed->l_tty, FX_TTY_POS_START, prompt_length(ed, PROMPT_MAIN) + 1);
save_buf_to_history(ed);
ed->l_history_pos++;

View File

@@ -5,7 +5,7 @@
#include "input.h"
#include "prompt.h"
#include <blue/term/tty.h>
#include <fx/term/tty.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -49,14 +49,14 @@ struct line_ed *line_ed_create(void)
return NULL;
}
out->l_history = b_array_create();
out->l_history = fx_array_create();
if (!out->l_history) {
free(out->l_buf);
free(out);
return NULL;
}
out->l_tty = b_stdtty;
out->l_tty = fx_stdtty;
out->l_buf_end = out->l_buf + LINE_MAX;
out->l_buf_ptr = out->l_buf;
out->l_line_end = out->l_buf;
@@ -71,7 +71,7 @@ struct line_ed *line_ed_create(void)
void line_ed_destroy(struct line_ed *ed)
{
b_array_unref(ed->l_history);
fx_array_unref(ed->l_history);
line_ed_clear_highlights(ed);
free(ed->l_buf);
free(ed);
@@ -181,8 +181,8 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
append_to_index = ed->l_history_pos;
}
b_tty *tty = ed->l_tty;
b_tty_set_mode(tty, B_TTY_RAW);
fx_tty *tty = ed->l_tty;
fx_tty_set_mode(tty, FX_TTY_RAW);
show_prompt(ed);
for (int i = 0; ed->l_buf[i]; i++) {
@@ -198,10 +198,10 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
bool eof = false;
while (!end) {
b_keycode key = b_tty_read_key(tty);
fx_keycode key = fx_tty_read_key(tty);
hook_keypress(ed, key);
if (key == B_TTY_CTRL_KEY('d')) {
if (key == FX_TTY_CTRL_KEY('d')) {
if (!input_is_empty(ed)) {
continue;
}
@@ -210,13 +210,13 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
break;
}
if (key & B_MOD_CTRL) {
if (key & FX_MOD_CTRL) {
continue;
}
switch (key) {
case B_KEY_RETURN:
b_tty_reset_vmode(tty);
case FX_KEY_RETURN:
fx_tty_reset_vmode(tty);
if (ed->l_line_end > ed->l_buf
&& *(ed->l_line_end - 1) != '\\') {
end = true;
@@ -243,19 +243,19 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
// fputs("\033[G\n", stdout);
show_prompt(ed);
break;
case B_KEY_BACKSPACE:
case FX_KEY_BACKSPACE:
backspace(ed);
break;
case B_KEY_ARROW_LEFT:
case FX_KEY_ARROW_LEFT:
cursor_left(ed);
break;
case B_KEY_ARROW_RIGHT:
case FX_KEY_ARROW_RIGHT:
cursor_right(ed);
break;
case B_KEY_ARROW_UP:
case FX_KEY_ARROW_UP:
arrow_up(ed);
break;
case B_KEY_ARROW_DOWN:
case FX_KEY_ARROW_DOWN:
arrow_down(ed);
break;
default:
@@ -266,7 +266,7 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
}
}
b_tty_set_mode(tty, B_TTY_CANONICAL);
fx_tty_set_mode(tty, FX_TTY_CANONICAL);
fputc('\n', stdout);
if (*ed->l_buf == '\0') {
@@ -277,7 +277,7 @@ size_t line_ed_readline(struct line_ed *ed, char *out, size_t max)
ed->l_history_pos = append_to_index;
append_buf_to_history(ed);
} else {
ed->l_history_pos = b_array_size(ed->l_history) - 1;
ed->l_history_pos = fx_array_size(ed->l_history) - 1;
const char *last = last_history_line(ed);
if (!last || strcmp(last, ed->l_buf) != 0) {

View File

@@ -3,21 +3,21 @@
#define LINE_MAX 4096
#include <blue/term/tty.h>
#include <blue/core/queue.h>
#include <blue/ds/array.h>
#include <fx/term/tty.h>
#include <fx/core/queue.h>
#include <fx/ds/array.h>
#include <ivy/line-source.h>
#include <stddef.h>
struct s_tty;
struct b_tty_vmode;
struct fx_tty_vmode;
struct line_ed;
struct line_ed_hook {
void (*hook_keypress)(struct line_ed *, struct line_ed_hook *, b_keycode);
void (*hook_keypress)(struct line_ed *, struct line_ed_hook *, fx_keycode);
void (*hook_buffer_modified)(struct line_ed *, struct line_ed_hook *);
b_queue_entry hook_entry;
fx_queue_entry hook_entry;
};
enum line_ed_flags {
@@ -57,7 +57,7 @@ struct line_ed {
struct ivy_line_source l_line_source;
/* pointer to tty interface */
b_tty *l_tty;
fx_tty *l_tty;
/* the lexical scope that we are currently in.
* this is provided by components further up the input pipeline,
@@ -65,14 +65,14 @@ struct line_ed {
const char *l_scope_type;
/* array of previously entered commands */
b_array *l_history;
fx_array *l_history;
/* index of the currently selected history entry */
size_t l_history_pos;
/* list of defined highlight ranges */
b_queue l_hl_ranges;
fx_queue l_hl_ranges;
/* list of installed hooks */
b_queue l_hooks;
fx_queue l_hooks;
};
extern struct line_ed *line_ed_create(void);
@@ -82,7 +82,7 @@ extern void line_ed_set_scope_type(struct line_ed *ed, const char *scope_type);
extern void line_ed_put_highlight(
struct line_ed *ed, unsigned long start_x, unsigned long start_y,
unsigned long end_x, unsigned long end_y, const struct b_tty_vmode *vmode);
unsigned long end_x, unsigned long end_y, const struct fx_tty_vmode *vmode);
extern void line_ed_clear_highlights(struct line_ed *ed);
extern void line_ed_print_highlights(struct line_ed *ed);

View File

@@ -5,7 +5,7 @@
#include "buffer.h"
#include "cursor.h"
#include "hl-range.h"
#include <blue/term/tty.h>
#include <fx/term/tty.h>
/* prints the provided string to the terminal, applying any relevant highlight ranges.
* this function prints all characters in `s` until it encounters a null char (\0) or
@@ -16,12 +16,12 @@
*/
void print_text(struct line_ed *ed, size_t x, size_t y, const char *s)
{
b_tty *tty = ed->l_tty;
fx_tty *tty = ed->l_tty;
struct hl_range *cur_range = get_hl_range(ed, x, y);
for (size_t i = 0; s[i] != '\n' && s[i] != '\0'; i++) {
if (!cur_range) {
b_tty_reset_vmode(tty);
fx_tty_reset_vmode(tty);
fputc(s[i], stdout);
continue;
}
@@ -107,7 +107,7 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
if (start_x) {
//fprintf(stdout, "\033[%uD", start_x);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -(long long)start_x);
}
start_x = 0;
@@ -119,7 +119,7 @@ void put_refresh(struct line_ed *ed, struct refresh_state *state)
* so that the physical cursor will be placed AFTER the character that
* was just inserted. */
cursor_rdelta--;
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -cursor_rdelta);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -cursor_rdelta);
#if 0
for (unsigned int i = 0; i < cursor_rdelta; i++) {
@@ -162,21 +162,21 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
* has just been moved up. from here, clear this line and the rest
* from the screen. */
//fputs("\033[J", stdout);
b_tty_clear(ed->l_tty, B_TTY_CLEAR_SCREEN | B_TTY_CLEAR_FROM_CURSOR);
fx_tty_clear(ed->l_tty, FX_TTY_CLEAR_SCREEN | FX_TTY_CLEAR_FROM_CURSOR);
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
/* next, move the physical cursor up and to the beginning of the previous line */
size_t tmp_x;
line_ed_coords_to_physical_coords(ed, 0, ed->l_cursor_y, &tmp_x, NULL);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, tmp_x);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, tmp_x);
//fprintf(stdout, "\033[A\033[%uG", tmp_x + 1);
start_x = 0;
} else {
/* next, move the physical cursor up and to the end of the previous line */
//fprintf(stdout, "\033[A\033[%uG", new_x);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, -1);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, new_x);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, -1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, new_x);
}
/* now reprint all of the buffer lines, starting with the first of the
@@ -202,11 +202,11 @@ void backspace_nl_refresh(struct line_ed *ed, struct refresh_state *state)
* were concatenated. */
if (ydiff) {
//fprintf(stdout, "\033[%uA", ydiff);
b_tty_move_cursor_y(ed->l_tty, B_TTY_POS_CURSOR, ydiff);
fx_tty_move_cursor_y(ed->l_tty, FX_TTY_POS_CURSOR, ydiff);
}
//fprintf(stdout, "\033[%uG", new_x);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_START, new_x);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_START, new_x);
fflush(stdout);
}
@@ -232,14 +232,14 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
if (ed->l_flags & LINE_ED_FULL_REPRINT) {
if (start_x) {
//fprintf(stdout, "\033[%uD", start_x);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -(long long)start_x);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -(long long)start_x);
}
start_x = 0;
}
//fputc('\010', stdout);
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -1);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -1);
print_text(ed, start_x, ed->l_cursor_y, line_buf + start_x);
fputc(' ', stdout);
@@ -248,7 +248,7 @@ void backspace_simple_refresh(struct line_ed *ed, struct refresh_state *state)
* the fact that backspace was just pressed) */
cursor_rdelta++;
b_tty_move_cursor_x(ed->l_tty, B_TTY_POS_CURSOR, -cursor_rdelta);
fx_tty_move_cursor_x(ed->l_tty, FX_TTY_POS_CURSOR, -cursor_rdelta);
#if 0
for (unsigned int i = 0; i < cursor_rdelta; i++) {

View File

@@ -1,8 +1,8 @@
#include "cmd/cmd.h"
#include <blue/cmd.h>
#include <fx/cmd.h>
int main(int argc, const char **argv)
{
return b_command_dispatch(CMD_ROOT, argc, argv);
return fx_command_dispatch(CMD_ROOT, argc, argv);
}

View File

@@ -9,25 +9,32 @@ setlocal iskeyword+=-
syn match ivyType /\<[A-Z]\{1,2}[a-z0-9]\+\(-\?[A-Z]\{1,2}[a-z0-9]\+\)*\>/
syn match ivySelectorLabel /\<[a-z][A-Za-z0-9-_]*\:/
syn match ivySelectorLabel /\-[a-z][A-Za-z0-9-_]*\:/
syn match ivySelectorLabel /+[a-z][A-Za-z0-9-_]*\:/
"syn match ivySelectorLabel /\<\([a-z]\([A-Za-z0-9_]\+\)\:\(\:\)\@!\)\+/
syn match ivyUnnamedVariable /\<_\>/
syn match ivyAtomName /\$[a-z][a-z0-9_:/-]*\>/
syn match ivyWord /\<[a-z_][a-zA-Z0-9_]*\(-\?[a-zA-Z][a-zA-Z0-9_]*\)*\>\(\:\)\@!/
syn match ivyUnnamedLabel /\s*(\?_:/
syn match ivyUnnamedVariable /\<_\>/
syn match ivyComplexMessageName /\<\zs[A-Za-z][A-Za-z0-9-_]\+\ze(/
syn match ivyComplexMessageName /\-[A-Za-z][A-Za-z0-9-_]\+\ze(/
syn match ivyComplexMessageName /+[A-Za-z][A-Za-z0-9-_]\+\ze(/
"syn match ivyUnaryMessageName /-\s*[a-zA-z][a-zA-Z0-9_]\+\s*\n/
syn match ivyUnaryMessageName /\(-\s*\)\@<=[a-z][A-Za-z0-9-_]*\(\s*\n\)\@=/
syn match ivyUnaryMessageName /\(-\s*\)\@<=[a-z][A-Za-z0-9-_]*\(\s*|\)\@=/
syn match ivyUnaryMessageName /\(+\s*\)\@<=[a-z][A-Za-z0-9-_]*\(\s*\n\)\@=/
syn match ivyUnaryMessageName /\(+\s*\)\@<=[a-z][A-Za-z0-9-_]*\(\s*|\)\@=/
syn match ivyUnaryMessageName /\-[a-z][A-Za-z0-9-_]*\(\s*[\|\[]\)\@=/
syn match ivyUnaryMessageName /+[a-z][A-Za-z0-9-_]*\(\s*[\|\[]\)\@=/
syn match ivyPropertyName /\(->\s*\)\@<=[a-z][A-Za-z0-9-_]*/
syn match ivyLineContinuation /\\\n/
" Modifiers
syn match ivySelfVar /\<self\([^a-zA-Z0-9-_]\)\@=/
syn match ivySelfVar /\<self\([^a-zA-Z0-9_]\)\@=/
" we have to use syn match for keywords because any keyword can be used as a
" label by adding : to the end, and adding : to iskeyword causes more problems
@@ -44,19 +51,23 @@ syn match ivyUseStmtIdentifier /\(use \)\@<=\([A-Za-z_][A-Za-z0-9_]*\)\(.\([A-Za
" Operators/Punctuation
syn match ivyBraces "[{}]" display
syn match ivyBrackets "[[\]]" display
syn match ivyParens "[()]" display
syn match ivyControlSymbols "[[\]]" display
syn match ivyControlSymbols "|" display
syn match ivyControlSymbols "\^" display
syn match ivyOpSymbols "\*" display
syn match ivyOpSymbols "::" display
syn match ivyOpSymbols "=\{1,2}" display
syn match ivyOpSymbols ">\{1,2}" display
syn match ivyOpSymbols "<\{1,2}" display
syn match ivyOpSymbols "[+\-/*%&^!|<>;,]" display
syn match ivyOpSymbols "[+\-/*%&^!|<>]=" display
syn match ivyOpSymbols "[\/*%&!<>;,]" display
syn match ivyOpSymbols "[+\-/*%&!<>]=" display
syn match ivyOpSymbols "\s\+[\-+]\s\+" display
syn match ivyOpSymbols "\->" display
syn match ivyOtherSymbols "=>" display
syn match ivyLogicSymbols "&&" display
syn match ivyLogicSymbols "||" display
syn match ivyStatementSeparator "\.\s*" display
syn match ivyPackageAccessOperator "\." display
syn match ivyStatementSeparator "\.\s*\n" display
syn match ivyMessageTerminator "\![\s\n]\+" display
syn keyword ivyWordOperator is not understands and or
@@ -147,15 +158,14 @@ hi def link ivyStatement Statement
hi def link ivyRepeat Repeat
hi def link ivyConditional Conditional
hi def link ivySelectorLabel Tag
hi def link ivyUnnamedLabel @variable.builtin
hi def link ivyUnnamedVariable @variable.builtin
hi def link ivyUnnamedLabel Comment
hi def link ivyUnnamedVariable Comment
hi def link ivyLambdaParameter @variable.builtin
hi def link ivyException Exception
hi def link ivyParens Delimiter
hi def link ivyBraces Structure
hi def link ivyBrackets Define
hi def link ivyLambdaSymbols Define
hi def link ivyControlSymbols Keyword
hi def link ivyModifier StorageClass
hi def link ivyAccessModifier ivyModifier
@@ -176,6 +186,7 @@ hi def link ivyTypeOf ivyKeywordOperator
hi def link ivyTypeOfOperand Typedef
hi def link ivyTypeOfError Error
hi def link ivyOpSymbols Operator
hi def link ivyPackageAccessOperator Operator
hi def link ivyOtherSymbols Structure
hi def link ivyLogicSymbols Operator
hi def link ivyWordOperator Operator

View File

@@ -11,5 +11,5 @@ else ()
endif ()
target_include_directories(ivy-lang PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
target_link_libraries(ivy-lang mie ivy-diag ivy-common Bluelib::Core Bluelib::Ds Bluelib::Term)
target_link_libraries(ivy-lang mie ivy-diag ivy-common FX::Core FX::Ds FX::Term)
target_compile_definitions(ivy-lang PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC})

View File

@@ -1,13 +1,13 @@
#include "ctx.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node;
b_string_append_cstrf(
fx_string_append_cstrf(
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
v->n_content->t_str);
}

View File

@@ -5,7 +5,7 @@
#include "iterate.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
void block_add_terminator(struct block_parser_state *state, unsigned short tok)
@@ -134,7 +134,7 @@ static enum ivy_status add_child(
struct ivy_ast_block_node *block
= (struct ivy_ast_block_node *)parent->s_node;
b_queue_push_back(&block->n_expr, &child->n_entry);
fx_queue_push_back(&block->n_expr, &child->n_entry);
return IVY_OK;
}
@@ -143,12 +143,12 @@ static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_block_node *block = (struct ivy_ast_block_node *)node;
b_queue_entry *entry = b_queue_first(&block->n_expr);
fx_queue_entry *entry = fx_queue_first(&block->n_expr);
while (entry) {
struct ivy_ast_node *expr
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, expr);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -11,12 +11,12 @@ static void collect_children(
ast_node_iterator_enqueue_node(iterator, node, cascade->n_recipient);
}
b_queue_entry *entry = b_queue_first(&cascade->n_msg);
fx_queue_entry *entry = fx_queue_first(&cascade->n_msg);
while (entry) {
struct ivy_ast_node *arg
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, arg);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -2,7 +2,7 @@
#include "iterate.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
#include <stdio.h>
@@ -130,10 +130,10 @@ static enum ivy_status add_child(
switch (child->n_type) {
case IVY_AST_MSGH:
b_queue_push_back(&c->n_msg_handlers, &child->n_entry);
fx_queue_push_back(&c->n_msg_handlers, &child->n_entry);
break;
case IVY_AST_PROPERTY:
b_queue_push_back(&c->n_properties, &child->n_entry);
fx_queue_push_back(&c->n_properties, &child->n_entry);
break;
default:
return IVY_ERR_NOT_SUPPORTED;
@@ -142,11 +142,11 @@ static enum ivy_status add_child(
return IVY_OK;
}
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_class_node *c = (struct ivy_ast_class_node *)node;
b_string_append_cstrf(
fx_string_append_cstrf(
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
c->n_ident->t_str);
}
@@ -162,20 +162,20 @@ static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_class_node *c = (struct ivy_ast_class_node *)node;
b_queue_entry *entry = b_queue_first(&c->n_properties);
fx_queue_entry *entry = fx_queue_first(&c->n_properties);
while (entry) {
struct ivy_ast_node *child
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, child);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
entry = b_queue_first(&c->n_msg_handlers);
entry = fx_queue_first(&c->n_msg_handlers);
while (entry) {
struct ivy_ast_node *child
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, child);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -8,7 +8,7 @@ struct cond_group_parser_state {
unsigned int s_prev_token;
struct ivy_ast_cond_node *s_cur_branch;
b_queue s_branches;
fx_queue s_branches;
struct ivy_ast_node *s_prev_node;
};
@@ -26,7 +26,7 @@ static enum ivy_status flush_current_branch(struct cond_group_parser_state *stat
return IVY_ERR_INTERNAL_FAILURE;
}
b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
fx_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
state->s_cur_branch
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
@@ -255,7 +255,7 @@ static enum ivy_status finalise_cond_group(struct cond_group_parser_state *state
flush_current_branch(state);
group->n_branches = state->s_branches;
state->s_branches = B_QUEUE_INIT;
state->s_branches = FX_QUEUE_INIT;
return IVY_OK;
} else {
/* we have just reached the 'end' keyword. */
@@ -274,7 +274,7 @@ static enum ivy_status finalise_cond_group(struct cond_group_parser_state *state
flush_current_branch(state);
group->n_branches = state->s_branches;
state->s_branches = B_QUEUE_INIT;
state->s_branches = FX_QUEUE_INIT;
return IVY_OK;
}
}
@@ -339,12 +339,12 @@ static void cond_group_collect_children(
struct ivy_ast_cond_group_node *group
= (struct ivy_ast_cond_group_node *)node;
b_queue_entry *entry = b_queue_first(&group->n_branches);
fx_queue_entry *entry = fx_queue_first(&group->n_branches);
while (entry) {
struct ivy_ast_node *branch
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, branch);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -3,7 +3,7 @@
#include "../debug.h"
#include "node.h"
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/diag.h>
#include <ivy/lang/ast.h>
#include <stddef.h>
@@ -14,10 +14,10 @@
#ifdef IVY_LANG_DEBUG
static void print_state_stack(struct ivy_parser *parser)
{
b_queue_iterator it = {0};
b_queue_foreach (&it, &parser->p_state) {
fx_queue_iterator it = {0};
fx_queue_foreach (&it, &parser->p_state) {
struct parser_state *state
= b_unbox(struct parser_state, it.entry, s_entry);
= fx_unbox(struct parser_state, it.entry, s_entry);
debug_printf(
" %s\n",
ivy_ast_node_type_to_string(state->s_node->n_type));
@@ -44,13 +44,13 @@ void ivy_parser_destroy(struct ivy_parser *parser, struct ivy_ast_node **result)
{
struct ivy_ast_node *root = NULL;
b_queue_entry *entry = b_queue_first(&parser->p_state);
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
;
while (entry) {
struct parser_state *state
= b_unbox(struct parser_state, entry, s_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&parser->p_state, entry);
= fx_unbox(struct parser_state, entry, s_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&parser->p_state, entry);
if (root) {
ivy_ast_node_destroy(root);
@@ -173,29 +173,29 @@ enum ivy_status ivy_parser_push_eof(struct ivy_parser *parser)
struct parser_state *parser_get_state_generic(struct ivy_parser *parser)
{
b_queue_entry *entry = b_queue_last(&parser->p_state);
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
if (!entry) {
return NULL;
}
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
return state;
}
struct parser_state *parser_get_parent_state_generic(
struct ivy_parser *parser, enum ivy_ast_node_type type)
{
b_queue_entry *entry = b_queue_last(&parser->p_state);
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
if (!entry) {
return NULL;
}
entry = b_queue_prev(entry);
entry = fx_queue_prev(entry);
if (!entry) {
return NULL;
}
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
if (state->s_node->n_type != type) {
return NULL;
@@ -219,15 +219,15 @@ struct parser_state *parser_push_state(
memset(state, 0x0, node_type->n_state_size);
b_queue_entry *current_state_entry = b_queue_last(&parser->p_state);
fx_queue_entry *current_state_entry = fx_queue_last(&parser->p_state);
if (current_state_entry) {
struct parser_state *current_state = b_unbox(
struct parser_state *current_state = fx_unbox(
struct parser_state, current_state_entry, s_entry);
state->s_parent = current_state->s_node;
}
state->s_node = ast_node_create(type);
b_queue_push_back(&parser->p_state, &state->s_entry);
fx_queue_push_back(&parser->p_state, &state->s_entry);
if (node_type->n_init_state) {
node_type->n_init_state(parser, state, arg);
@@ -246,9 +246,9 @@ void parser_pop_state(struct ivy_parser *parser, enum pop_state_flags flags)
return;
}
b_queue_entry *entry = b_queue_last(&parser->p_state);
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
b_queue_pop_back(&parser->p_state);
fx_queue_entry *entry = fx_queue_last(&parser->p_state);
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
fx_queue_pop_back(&parser->p_state);
if (state && state->s_node && (flags & STATE_ADD_NODE_TO_PARENT)) {
parser_add_child(parser, state->s_node);
@@ -298,15 +298,15 @@ bool ivy_parser_is_node_complete(struct ivy_parser *parser)
struct ivy_ast_node *ivy_parser_root_node(struct ivy_parser *parser)
{
b_queue_entry *entry = b_queue_first(&parser->p_state);
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
return state ? state->s_node : NULL;
}
struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
{
b_queue_entry *entry = b_queue_first(&parser->p_state);
struct parser_state *state = b_unbox(struct parser_state, entry, s_entry);
fx_queue_entry *entry = fx_queue_first(&parser->p_state);
struct parser_state *state = fx_unbox(struct parser_state, entry, s_entry);
if (!state) {
return NULL;
@@ -318,13 +318,13 @@ struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser)
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)state->s_node;
entry = b_queue_pop_front(&unit->n_children);
entry = fx_queue_pop_front(&unit->n_children);
if (!entry) {
return NULL;
}
return b_unbox(struct ivy_ast_node, entry, n_entry);
return fx_unbox(struct ivy_ast_node, entry, n_entry);
}
struct ivy_diag *parser_push_diag(

View File

@@ -1,7 +1,7 @@
#ifndef _AST_CTX_H_
#define _AST_CTX_H_
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#include <ivy/diag.h>
#include <ivy/lang/ast.h>
#include <ivy/lang/diag.h>
@@ -14,7 +14,7 @@
((state_type *)parser_get_parent_state_generic(parser, type_id))
struct parser_state {
b_queue_entry s_entry;
fx_queue_entry s_entry;
struct ivy_ast_node *s_parent;
struct ivy_ast_node *s_node;
};
@@ -22,9 +22,9 @@ struct parser_state {
struct ivy_parser {
enum ivy_status p_status;
struct ivy_diag_ctx *p_diag_ctx;
b_queue p_state;
b_queue p_token_queue;
b_queue p_node_queue;
fx_queue p_state;
fx_queue p_token_queue;
fx_queue p_node_queue;
};
enum pop_state_flags {

View File

@@ -1,13 +1,13 @@
#include "ctx.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_double_node *v = (struct ivy_ast_double_node *)node;
b_string_append_cstrf(
fx_string_append_cstrf(
str, "%s (%.2lf)", ivy_ast_node_type_to_string(node->n_type),
v->n_value->t_double);
}

View File

@@ -3,7 +3,7 @@
#include "../node.h"
#include "expr.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
#include <ivy/lang/operator.h>
#include <stdio.h>
@@ -63,7 +63,7 @@ enum ivy_status arith_push_operand(
IVY_AST_IDENT);
v->n_content = tok;
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
break;
}
case IVY_TOK_INT: {
@@ -71,7 +71,7 @@ enum ivy_status arith_push_operand(
= (struct ivy_ast_int_node *)ast_node_create(IVY_AST_INT);
v->n_value = tok;
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
break;
}
case IVY_TOK_DOUBLE: {
@@ -80,7 +80,7 @@ enum ivy_status arith_push_operand(
IVY_AST_DOUBLE);
v->n_value = tok;
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
break;
}
case IVY_TOK_ATOM: {
@@ -88,7 +88,7 @@ enum ivy_status arith_push_operand(
= (struct ivy_ast_atom_node *)ast_node_create(IVY_AST_ATOM);
v->n_content = tok;
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
break;
}
case IVY_TOK_STRING: {
@@ -97,7 +97,7 @@ enum ivy_status arith_push_operand(
IVY_AST_STRING);
v->n_value = tok;
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_base.n_entry);
break;
}
case IVY_TOK_SYMBOL: {
@@ -107,7 +107,7 @@ enum ivy_status arith_push_operand(
struct ivy_ast_node *v = ast_node_create(IVY_AST_DISCARD);
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_entry);
break;
}
case IVY_TOK_KEYWORD: {
@@ -133,7 +133,7 @@ enum ivy_status arith_push_operand(
}
ivy_ast_node_set_bounds_from_token((struct ivy_ast_node *)v, tok);
b_queue_push_back(&state->s_output_queue, &v->n_entry);
fx_queue_push_back(&state->s_output_queue, &v->n_entry);
break;
}
default:
@@ -204,20 +204,20 @@ static struct ivy_ast_node *create_operator_node_from_token(struct ivy_token *to
#ifdef IVY_LANG_DEBUG
static void print_expr_queues(struct expr_parser_state *state)
{
b_queue_iterator it = {0};
fx_queue_iterator it = {0};
debug_printf("operators:");
b_queue_foreach (&it, &state->s_operator_stack) {
fx_queue_foreach (&it, &state->s_operator_stack) {
struct ivy_ast_node *n
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
= fx_unbox(struct ivy_ast_node, it.entry, n_entry);
debug_printf(" ");
print_operand(n);
}
debug_printf("\noperands:");
b_queue_foreach (&it, &state->s_output_queue) {
fx_queue_foreach (&it, &state->s_output_queue) {
struct ivy_ast_node *n
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
= fx_unbox(struct ivy_ast_node, it.entry, n_entry);
debug_printf(" ");
print_operand(n);
}
@@ -234,13 +234,13 @@ void arith_push_operator(struct expr_parser_state *state, struct ivy_ast_node *n
}
while (true) {
b_queue_entry *top = b_queue_last(&state->s_operator_stack);
fx_queue_entry *top = fx_queue_last(&state->s_operator_stack);
if (!top) {
break;
}
struct ivy_ast_node *top_node
= b_unbox(struct ivy_ast_node, top, n_entry);
= fx_unbox(struct ivy_ast_node, top, n_entry);
const struct ivy_operator *top_op = NULL;
switch (top_node->n_type) {
@@ -266,11 +266,11 @@ void arith_push_operator(struct expr_parser_state *state, struct ivy_ast_node *n
break;
}
b_queue_delete(&state->s_operator_stack, top);
b_queue_push_back(&state->s_output_queue, top);
fx_queue_delete(&state->s_operator_stack, top);
fx_queue_push_back(&state->s_output_queue, top);
}
b_queue_push_back(&state->s_operator_stack, &node->n_entry);
fx_queue_push_back(&state->s_operator_stack, &node->n_entry);
#ifdef IVY_LANG_DEBUG
print_expr_queues(state);
#endif
@@ -296,7 +296,7 @@ enum ivy_status expr_finalise_arith(
struct expr_parser_state *state, struct ivy_ast_node **expr_tree,
enum ivy_operator_precedence minimum_precedence)
{
b_queue_entry *entry = NULL;
fx_queue_entry *entry = NULL;
/* first, take all the operators still left on the operator stack and
* add them to the output queue.
@@ -304,13 +304,13 @@ enum ivy_status expr_finalise_arith(
* since each set of parentheses has its own expression context,
* we don't have to handle parentheses here */
while (true) {
entry = b_queue_pop_back(&state->s_operator_stack);
entry = fx_queue_pop_back(&state->s_operator_stack);
if (!entry) {
break;
}
struct ivy_ast_node *node
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
if (!node) {
/* this should never happen */
return IVY_ERR_INTERNAL_FAILURE;
@@ -336,11 +336,11 @@ enum ivy_status expr_finalise_arith(
/* if we aren't processing operators below a certain precedence
* then leave them on the stack and stop here. */
if (op->op_precedence < minimum_precedence) {
b_queue_push_back(&state->s_operator_stack, entry);
fx_queue_push_back(&state->s_operator_stack, entry);
break;
}
b_queue_push_back(&state->s_output_queue, entry);
fx_queue_push_back(&state->s_output_queue, entry);
}
#if 0
@@ -353,22 +353,22 @@ enum ivy_status expr_finalise_arith(
* always follow their operands, so a queue of operands is needed
* for the conversion. */
b_queue q = B_QUEUE_INIT;
b_queue_entry *tmp = NULL;
entry = b_queue_first(&state->s_output_queue);
fx_queue q = FX_QUEUE_INIT;
fx_queue_entry *tmp = NULL;
entry = fx_queue_first(&state->s_output_queue);
int i = 0;
while (entry) {
struct ivy_ast_node *item
= b_unbox(struct ivy_ast_node, entry, n_entry);
b_queue_entry *next = b_queue_next(entry);
b_queue_delete(&state->s_output_queue, entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
fx_queue_entry *next = fx_queue_next(entry);
fx_queue_delete(&state->s_output_queue, entry);
/* if the node is an operand, just push it to a temporary queue
* and come back to it later. */
if (item->n_type != IVY_AST_OP && item->n_type != IVY_AST_MSG) {
/* operand */
b_queue_push_back(&q, &item->n_entry);
fx_queue_push_back(&q, &item->n_entry);
goto next;
}
@@ -384,11 +384,11 @@ enum ivy_status expr_finalise_arith(
* self-contained keyword message, and can be pushed to
* the operand queue as-is. */
if (!msg->n_recipient) {
tmp = b_queue_pop_back(&q);
msg->n_recipient = b_unbox(
tmp = fx_queue_pop_back(&q);
msg->n_recipient = fx_unbox(
struct ivy_ast_node, tmp, n_entry);
}
b_queue_push_back(&q, &msg->n_base.n_entry);
fx_queue_push_back(&q, &msg->n_base.n_entry);
goto next;
}
@@ -397,15 +397,15 @@ enum ivy_status expr_finalise_arith(
* all the operands it needs, it can be pushed to the operand
* queue as-is */
if (op_node_is_complete(op_node)) {
b_queue_push_back(&q, &item->n_entry);
fx_queue_push_back(&q, &item->n_entry);
goto next;
}
/* otherwise, pop the relevant operands from the operand
* queue... */
op = op_node->n_op;
tmp = b_queue_pop_back(&q);
op_node->n_right = b_unbox(struct ivy_ast_node, tmp, n_entry);
tmp = fx_queue_pop_back(&q);
op_node->n_right = fx_unbox(struct ivy_ast_node, tmp, n_entry);
if (op_node->n_right) {
op_node->n_right->n_parent = (struct ivy_ast_node *)op_node;
@@ -416,9 +416,9 @@ enum ivy_status expr_finalise_arith(
}
if (op->op_arity == IVY_OP_BINARY) {
tmp = b_queue_pop_back(&q);
tmp = fx_queue_pop_back(&q);
op_node->n_left
= b_unbox(struct ivy_ast_node, tmp, n_entry);
= fx_unbox(struct ivy_ast_node, tmp, n_entry);
if (op_node->n_left) {
op_node->n_left->n_parent
@@ -432,7 +432,7 @@ enum ivy_status expr_finalise_arith(
/* ...and push the newly-completed operator node to the operand
* queue */
b_queue_push_back(&q, &op_node->n_base.n_entry);
fx_queue_push_back(&q, &op_node->n_base.n_entry);
next:
entry = next;
}
@@ -448,15 +448,15 @@ enum ivy_status expr_finalise_arith(
* their operands have just been moved to the temporary operand stack
* used above. move them back to the parser state's output queue here
* so they can be used later. */
entry = b_queue_first(&state->s_operator_stack);
entry = fx_queue_first(&state->s_operator_stack);
while (entry) {
b_queue_entry *entry2 = b_queue_pop_front(&q);
fx_queue_entry *entry2 = fx_queue_pop_front(&q);
if (!entry2) {
return IVY_ERR_INTERNAL_FAILURE;
}
b_queue_push_back(&state->s_output_queue, entry2);
entry = b_queue_next(entry);
fx_queue_push_back(&state->s_output_queue, entry2);
entry = fx_queue_next(entry);
}
#if 0
@@ -468,8 +468,8 @@ enum ivy_status expr_finalise_arith(
/* the final node remaining on the temp operand stack is the root node
* of the new expression tree */
tmp = b_queue_pop_back(&q);
*expr_tree = b_unbox(struct ivy_ast_node, tmp, n_entry);
tmp = fx_queue_pop_back(&q);
*expr_tree = fx_unbox(struct ivy_ast_node, tmp, n_entry);
return IVY_OK;
}
@@ -521,7 +521,7 @@ struct token_parse_result arith_parse_operand(
memset(empty_label, 0x0, sizeof *empty_label);
empty_label->t_type = IVY_TOK_LABEL;
b_queue_push_back(&state->s_labels, &empty_label->t_entry);
fx_queue_push_back(&state->s_labels, &empty_label->t_entry);
struct expr_parser_state *arg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -695,9 +695,9 @@ struct token_parse_result arith_parse_left_paren(
if (state->s_prev_token == IVY_TOK_IDENT) {
/* this might be the opening parenthesis for a complex message. */
b_queue_entry *msg_entry = b_queue_last(&state->s_operator_stack);
fx_queue_entry *msg_entry = fx_queue_last(&state->s_operator_stack);
struct ivy_ast_node *msg
= b_unbox(struct ivy_ast_node, msg_entry, n_entry);
= fx_unbox(struct ivy_ast_node, msg_entry, n_entry);
if (!msg || msg->n_type != IVY_AST_MSG) {
/* this is not a complex message, it's probably a
@@ -705,7 +705,7 @@ struct token_parse_result arith_parse_left_paren(
goto not_complex_msg;
}
b_queue_pop_back(&state->s_operator_stack);
fx_queue_pop_back(&state->s_operator_stack);
struct expr_parser_state *msg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -761,7 +761,7 @@ not_complex_msg:
memset(empty_label, 0x0, sizeof *empty_label);
empty_label->t_type = IVY_TOK_LABEL;
b_queue_push_back(&state->s_labels, &empty_label->t_entry);
fx_queue_push_back(&state->s_labels, &empty_label->t_entry);
struct expr_parser_state *arg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -908,21 +908,21 @@ struct token_parse_result arith_parse_right_bracket(
return result;
}
static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *labels)
static struct ivy_ast_selector_node *keyword_selector_from_label_list(fx_queue *labels)
{
struct ivy_ast_selector_node *sel
= (struct ivy_ast_selector_node *)ast_node_create(IVY_AST_SELECTOR);
b_queue_entry *entry = b_queue_first(labels);
b_queue_entry *next = NULL;
fx_queue_entry *entry = fx_queue_first(labels);
fx_queue_entry *next = NULL;
while (entry) {
struct ivy_token *label
= b_unbox(struct ivy_token, entry, t_entry);
next = b_queue_next(entry);
b_queue_delete(labels, entry);
= fx_unbox(struct ivy_token, entry, t_entry);
next = fx_queue_next(entry);
fx_queue_delete(labels, entry);
b_queue_push_back(&sel->n_arg_labels, &label->t_entry);
fx_queue_push_back(&sel->n_arg_labels, &label->t_entry);
entry = next;
}
@@ -937,16 +937,16 @@ static struct ivy_ast_cascade_node *expr_finalise_cascade(
cascade->n_recipient = state->s_recipient;
b_queue_entry *entry = b_queue_first(&state->s_cascade_msg);
b_queue_entry *next = NULL;
fx_queue_entry *entry = fx_queue_first(&state->s_cascade_msg);
fx_queue_entry *next = NULL;
while (entry) {
struct ivy_ast_node *msg
= b_unbox(struct ivy_ast_node, entry, n_entry);
next = b_queue_next(entry);
b_queue_delete(&state->s_cascade_msg, entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
next = fx_queue_next(entry);
fx_queue_delete(&state->s_cascade_msg, entry);
b_queue_push_back(&cascade->n_msg, &msg->n_entry);
fx_queue_push_back(&cascade->n_msg, &msg->n_entry);
entry = next;
}
@@ -962,16 +962,16 @@ static struct ivy_ast_msg_node *expr_finalise_keyword_msg(
msg->n_recipient = state->s_recipient;
msg->n_sel = keyword_selector_from_label_list(&state->s_labels);
b_queue_entry *entry = b_queue_first(&state->s_args);
b_queue_entry *next = NULL;
fx_queue_entry *entry = fx_queue_first(&state->s_args);
fx_queue_entry *next = NULL;
while (entry) {
struct ivy_ast_node *arg
= b_unbox(struct ivy_ast_node, entry, n_entry);
next = b_queue_next(entry);
b_queue_delete(&state->s_args, entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
next = fx_queue_next(entry);
fx_queue_delete(&state->s_args, entry);
b_queue_push_back(&msg->n_arg, &arg->n_entry);
fx_queue_push_back(&msg->n_arg, &arg->n_entry);
entry = next;
}
@@ -988,26 +988,26 @@ static struct ivy_ast_msg_node *expr_finalise_complex_msg(
state->s_msg = NULL;
b_queue_entry *entry = b_queue_first(&state->s_labels);
b_queue_entry *next = NULL;
fx_queue_entry *entry = fx_queue_first(&state->s_labels);
fx_queue_entry *next = NULL;
while (entry) {
struct ivy_token *label
= b_unbox(struct ivy_token, entry, t_entry);
next = b_queue_next(entry);
b_queue_delete(&state->s_labels, entry);
b_queue_push_back(&msg->n_sel->n_arg_labels, &label->t_entry);
= fx_unbox(struct ivy_token, entry, t_entry);
next = fx_queue_next(entry);
fx_queue_delete(&state->s_labels, entry);
fx_queue_push_back(&msg->n_sel->n_arg_labels, &label->t_entry);
entry = next;
}
entry = b_queue_first(&state->s_args);
entry = fx_queue_first(&state->s_args);
while (entry) {
struct ivy_ast_node *arg
= b_unbox(struct ivy_ast_node, entry, n_entry);
next = b_queue_next(entry);
b_queue_delete(&state->s_args, entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
next = fx_queue_next(entry);
fx_queue_delete(&state->s_args, entry);
b_queue_push_back(&msg->n_arg, &arg->n_entry);
fx_queue_push_back(&msg->n_arg, &arg->n_entry);
entry = next;
}
@@ -1032,9 +1032,9 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
enum ivy_operator_precedence min_precedence
= IVY_PRECEDENCE_CASCADE;
struct ivy_ast_node *prev = b_unbox(
struct ivy_ast_node *prev = fx_unbox(
struct ivy_ast_node,
b_queue_last(&state->s_operator_stack), n_entry);
fx_queue_last(&state->s_operator_stack), n_entry);
if (prev && prev->n_type == IVY_AST_MSG) {
/* unary complex messages (which will be found on the
* operator stack) have a very high precedence (much
@@ -1079,7 +1079,7 @@ static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
cascade_expr->s_type = EXPR_TYPE_ARITH;
cascade_expr->s_subexpr_depth = state->s_subexpr_depth + 1;
b_queue_push_back(&cascade_expr->s_cascade_msg, &first_msg->n_base.n_entry);
fx_queue_push_back(&cascade_expr->s_cascade_msg, &first_msg->n_base.n_entry);
struct expr_parser_state *msg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -1338,8 +1338,8 @@ struct token_parse_result arith_parse_caret(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
if (!b_queue_empty(&state->s_operator_stack)
|| !b_queue_empty(&state->s_output_queue)) {
if (!fx_queue_empty(&state->s_operator_stack)
|| !fx_queue_empty(&state->s_output_queue)) {
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
@@ -1388,8 +1388,8 @@ struct token_parse_result arith_parse_comma(
}
if (state->s_sub_type == EXPR_SUBTYPE_PAREN
&& b_queue_empty(&state->s_output_queue)
&& b_queue_empty(&state->s_operator_stack)) {
&& fx_queue_empty(&state->s_output_queue)
&& fx_queue_empty(&state->s_operator_stack)) {
parser_pop_state(ctx, 0);
} else {
/* the tuple parser will handle the parentheses for us. */
@@ -1452,8 +1452,8 @@ struct token_parse_result arith_parse_label(
struct expr_parser_state *msg_expr;
bool new_parser = true;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
new_parser = false;
}
@@ -1498,7 +1498,7 @@ struct token_parse_result arith_parse_label(
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
}
b_queue_push_back(&state->s_labels, &tok->t_entry);
fx_queue_push_back(&state->s_labels, &tok->t_entry);
struct expr_parser_state *arg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -1511,7 +1511,7 @@ struct token_parse_result arith_parse_label(
/* we may have just finished parsing a keyword-message argument,
* and this label marks the start of a new one. store the label
* and create a new argument parsing context. */
b_queue_push_back(&state->s_labels, &tok->t_entry);
fx_queue_push_back(&state->s_labels, &tok->t_entry);
struct expr_parser_state *arg_expr
= (struct expr_parser_state *)parser_push_state(
@@ -1532,16 +1532,16 @@ enum ivy_status arith_add_child(
if (state->s_sub_type == EXPR_SUBTYPE_CASCADE) {
/* treat the child node as a cascaded message */
b_queue_push_back(&state->s_cascade_msg, &child->n_entry);
fx_queue_push_back(&state->s_cascade_msg, &child->n_entry);
} else if (
state->s_sub_type == EXPR_SUBTYPE_KEYWORD_MSG
|| state->s_sub_type == EXPR_SUBTYPE_COMPLEX_MSG) {
/* treat the child node as a keyword-message argument */
b_queue_push_back(&state->s_args, &child->n_entry);
fx_queue_push_back(&state->s_args, &child->n_entry);
} else if (state->s_sub_type == EXPR_SUBTYPE_KEYWORD_ARG) {
/* treat the child node as a sub-expression enclosed in
* parentheses (i.e. an operand). */
b_queue_push_back(&state->s_output_queue, &child->n_entry);
fx_queue_push_back(&state->s_output_queue, &child->n_entry);
state->s_prev_component = EXPR_CMP_OPERAND;
} else if (child->n_type == IVY_AST_MSG) {
arith_push_operator(state, child);
@@ -1549,7 +1549,7 @@ enum ivy_status arith_add_child(
} else {
/* treat the child node as a sub-expression enclosed in
* parentheses (i.e. an operand). */
b_queue_push_back(&state->s_output_queue, &child->n_entry);
fx_queue_push_back(&state->s_output_queue, &child->n_entry);
state->s_prev_component = EXPR_CMP_OPERAND;
}

View File

@@ -4,7 +4,7 @@
#include "../ctx.h"
#include "../node.h"
#include <blue/core/queue.h>
#include <fx/core/queue.h>
#define EXPR_TERMINATOR_MAX 8
@@ -76,19 +76,19 @@ struct expr_parser_state {
unsigned short s_terminators[EXPR_TERMINATOR_MAX];
unsigned short s_nr_terminators;
b_queue s_output_queue;
b_queue s_operator_stack;
fx_queue s_output_queue;
fx_queue s_operator_stack;
/* these variables are for keyword-message expressions */
struct ivy_ast_node *s_recipient;
struct ivy_ast_msg_node *s_msg;
b_queue s_labels;
fx_queue s_labels;
union {
/* for keyword-messages, this is a list of arg values. */
b_queue s_args;
fx_queue s_args;
/* for cascade operators, this is a list of messages to send to the recipient. */
b_queue s_cascade_msg;
fx_queue s_cascade_msg;
};
};

View File

@@ -1,7 +1,7 @@
#include "../node.h"
#include "expr.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
#include <ivy/lang/operator.h>
#include <stdio.h>
@@ -27,8 +27,8 @@ struct token_parse_result stmt_parse_try(
state->s_prev_token = IVY_KW_TRY;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
parser_pop_state(ctx, 0);
}
@@ -71,8 +71,8 @@ struct token_parse_result stmt_parse_for(
state->s_prev_token = IVY_KW_FOR;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
parser_pop_state(ctx, 0);
}
@@ -107,8 +107,8 @@ struct token_parse_result stmt_parse_while(
state->s_prev_token = IVY_KW_WHILE;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
parser_pop_state(ctx, 0);
}
@@ -140,8 +140,8 @@ struct token_parse_result stmt_parse_match(
state->s_prev_token = IVY_KW_MATCH;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
parser_pop_state(ctx, 0);
}
@@ -186,8 +186,8 @@ struct token_parse_result stmt_parse_if(
state->s_prev_token = IVY_KW_IF;
if (b_queue_empty(&state->s_operator_stack)
&& b_queue_empty(&state->s_output_queue)) {
if (fx_queue_empty(&state->s_operator_stack)
&& fx_queue_empty(&state->s_output_queue)) {
parser_pop_state(ctx, 0);
}

View File

@@ -1,13 +1,13 @@
#include "ctx.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_ident_node *ident = (struct ivy_ast_ident_node *)node;
b_string_append_cstrf(
fx_string_append_cstrf(
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
ident->n_content->t_str);
}

View File

@@ -1,13 +1,13 @@
#include "ctx.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)node;
b_string_append_cstrf(
fx_string_append_cstrf(
str, "%s (%llu)", ivy_ast_node_type_to_string(node->n_type),
v->n_value->t_int);
}

View File

@@ -7,14 +7,14 @@ enum ivy_status iterate_regular(
ivy_ast_node_iteration_callback callback)
{
#if 0
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
node->n_it.it_depth = 0;
while (!b_queue_empty(&it->it_queue)) {
b_queue_entry *entry = b_queue_first(&it->it_queue);
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
while (!fx_queue_empty(&it->it_queue)) {
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
struct ivy_ast_node_iterator_entry, entry, it_entry);
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
if (!node) {
/* this should never happen. */
@@ -32,7 +32,7 @@ enum ivy_status iterate_regular(
type->n_collect_children(node, it);
}
b_queue_delete(&it->it_queue, entry);
fx_queue_delete(&it->it_queue, entry);
}
#endif
@@ -60,15 +60,15 @@ enum ivy_status iterate_postorder(
* - should probably use this just for the executable parts of the AST,
* not for nodes defining classes, function metadata, etc.
*/
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
node->n_it.it_depth = 0;
b_queue_entry *entry = b_queue_first(&it->it_queue);
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
while (entry) {
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
struct ivy_ast_node_iterator_entry, entry, it_entry);
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
if (!node) {
/* this should never happen. */
@@ -81,16 +81,16 @@ enum ivy_status iterate_postorder(
type->n_collect_children(node, it);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
while (!b_queue_empty(&it->it_queue)) {
b_queue_entry *entry = b_queue_pop_back(&it->it_queue);
while (!fx_queue_empty(&it->it_queue)) {
fx_queue_entry *entry = fx_queue_pop_back(&it->it_queue);
if (!entry) {
break;
}
node = b_unbox(struct ivy_ast_node, entry, n_it);
node = fx_unbox(struct ivy_ast_node, entry, n_it);
if (!node) {
/* this should never happen. */
@@ -107,15 +107,15 @@ enum ivy_status ivy_ast_node_iterate(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it,
ivy_ast_node_iteration_callback callback, void *arg)
{
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
node->n_it.it_depth = 0;
b_queue_entry *entry = b_queue_first(&it->it_queue);
fx_queue_entry *entry = fx_queue_first(&it->it_queue);
while (entry) {
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
struct ivy_ast_node_iterator_entry, entry, it_entry);
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
if (!node) {
/* this should never happen. */
@@ -134,16 +134,16 @@ enum ivy_status ivy_ast_node_iterate(
type->n_collect_children(node, it);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
while (!b_queue_empty(&it->it_queue)) {
b_queue_entry *entry = b_queue_pop_back(&it->it_queue);
while (!fx_queue_empty(&it->it_queue)) {
fx_queue_entry *entry = fx_queue_pop_back(&it->it_queue);
if (!entry) {
break;
}
node = b_unbox(struct ivy_ast_node, entry, n_it);
node = fx_unbox(struct ivy_ast_node, entry, n_it);
if (!node) {
/* this should never happen. */
@@ -165,10 +165,10 @@ void ast_node_iterator_enqueue_node(
struct ivy_ast_node *node)
{
if (it->it_insert_after) {
b_queue_insert_after(
fx_queue_insert_after(
&it->it_queue, &node->n_it.it_entry, it->it_insert_after);
} else {
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
fx_queue_push_back(&it->it_queue, &node->n_it.it_entry);
}
node->n_it.it_depth = parent->n_it.it_depth + 1;

View File

@@ -11,7 +11,7 @@ struct lambda_parser_state {
struct ivy_ast_node *s_prev_node;
unsigned int s_prev;
b_queue s_args;
fx_queue s_args;
struct ivy_ast_node *s_body;
};
@@ -56,7 +56,7 @@ static struct token_parse_result parse_ident(
}
arg->n_content = tok;
b_queue_push_back(&state->s_args, &arg->n_base.n_entry);
fx_queue_push_back(&state->s_args, &arg->n_base.n_entry);
state->s_prev = IVY_TOK_IDENT;
return PARSE_RESULT(IVY_OK, 0);
@@ -101,7 +101,7 @@ static void finalise_lambda(struct lambda_parser_state *state)
lambda->n_arg = state->s_args;
lambda->n_body = state->s_body;
state->s_args = B_QUEUE_INIT;
state->s_args = FX_QUEUE_INIT;
state->s_body = NULL;
}
@@ -147,12 +147,12 @@ static void collect_children(
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
{
struct ivy_ast_lambda_node *lambda = (struct ivy_ast_lambda_node *)node;
b_queue_entry *entry = b_queue_first(&lambda->n_arg);
fx_queue_entry *entry = fx_queue_first(&lambda->n_arg);
while (entry) {
struct ivy_ast_node *expr
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, expr);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
if (lambda->n_body) {

View File

@@ -1,11 +1,11 @@
#include "ctx.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
static void to_string(struct ivy_ast_node *node, b_string *str)
static void to_string(struct ivy_ast_node *node, fx_string *str)
{
b_string_append_cstrf(str, "%s", ivy_ast_node_type_to_string(node->n_type));
fx_string_append_cstrf(str, "%s", ivy_ast_node_type_to_string(node->n_type));
}
struct ast_node_type loop_break_node_ops = {

View File

@@ -9,7 +9,7 @@ struct match_parser_state {
struct ivy_ast_node *s_cond;
struct ivy_ast_cond_node *s_cur_branch;
b_queue s_branches;
fx_queue s_branches;
struct ivy_ast_node *s_prev_node;
};
@@ -52,7 +52,7 @@ static enum ivy_status flush_current_branch(struct match_parser_state *state)
return IVY_ERR_INTERNAL_FAILURE;
}
b_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
fx_queue_push_back(&state->s_branches, &state->s_cur_branch->n_base.n_entry);
state->s_cur_branch
= (struct ivy_ast_cond_node *)ast_node_create(IVY_AST_COND);
@@ -107,7 +107,7 @@ static enum ivy_status finalise_match(struct match_parser_state *state)
match->n_cond = state->s_cond;
match->n_branches = state->s_branches;
state->s_branches = B_QUEUE_INIT;
state->s_branches = FX_QUEUE_INIT;
return IVY_OK;
}
@@ -262,10 +262,10 @@ static void match_collect_children(
ast_node_iterator_enqueue_node(iterator, node, match->n_cond);
b_queue_entry *entry = b_queue_first(&match->n_branches);
fx_queue_entry *entry = fx_queue_first(&match->n_branches);
while (entry) {
struct ivy_ast_node *branch
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, branch);
}
}

View File

@@ -16,12 +16,12 @@ static void collect_children(
iterator, node, (struct ivy_ast_node *)msg->n_sel);
}
b_queue_entry *entry = b_queue_first(&msg->n_arg);
fx_queue_entry *entry = fx_queue_first(&msg->n_arg);
while (entry) {
struct ivy_ast_node *arg
= b_unbox(struct ivy_ast_node, entry, n_entry);
= fx_unbox(struct ivy_ast_node, entry, n_entry);
ast_node_iterator_enqueue_node(iterator, node, arg);
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
}

View File

@@ -4,7 +4,7 @@
#include "ivy/status.h"
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/lex.h>
struct msgh_parser_state {

View File

@@ -1,6 +1,6 @@
#include "node.h"
#include <blue/ds/string.h>
#include <fx/ds/string.h>
#include <ivy/lang/ast.h>
#include <stdio.h>
#include <stdlib.h>
@@ -250,7 +250,7 @@ struct ivy_ast_node *ast_node_create(enum ivy_ast_node_type type)
return node;
}
void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out)
void ivy_ast_node_to_string(struct ivy_ast_node *node, fx_string *out)
{
const struct ast_node_type *type_info = get_ast_node_type(node->n_type);
if (!type_info) {
@@ -260,7 +260,7 @@ void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out)
if (type_info->n_to_string) {
type_info->n_to_string(node, out);
} else {
b_string_append_cstr(
fx_string_append_cstr(
out, ivy_ast_node_type_to_string(node->n_type));
}
}
@@ -301,15 +301,15 @@ void ivy_ast_node_extend_bounds_recursive(
void ivy_ast_node_destroy(struct ivy_ast_node *node)
{
struct ivy_ast_node_iterator it = {};
b_queue_push_back(&it.it_queue, &node->n_it.it_entry);
fx_queue_push_back(&it.it_queue, &node->n_it.it_entry);
node->n_it.it_depth = 0;
b_queue_entry *entry = b_queue_first(&it.it_queue);
fx_queue_entry *entry = fx_queue_first(&it.it_queue);
while (entry) {
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
struct ivy_ast_node_iterator_entry *it_entry = fx_unbox(
struct ivy_ast_node_iterator_entry, entry, it_entry);
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
node = fx_unbox(struct ivy_ast_node, it_entry, n_it);
if (!node) {
/* this should never happen. */
@@ -322,16 +322,16 @@ void ivy_ast_node_destroy(struct ivy_ast_node *node)
type->n_collect_children(node, &it);
}
entry = b_queue_next(entry);
entry = fx_queue_next(entry);
}
while (!b_queue_empty(&it.it_queue)) {
b_queue_entry *entry = b_queue_pop_back(&it.it_queue);
while (!fx_queue_empty(&it.it_queue)) {
fx_queue_entry *entry = fx_queue_pop_back(&it.it_queue);
if (!entry) {
break;
}
node = b_unbox(struct ivy_ast_node, entry, n_it);
node = fx_unbox(struct ivy_ast_node, entry, n_it);
const struct ast_node_type *type = get_ast_node_type(node->n_type);
if (type && type->n_destroy) {
@@ -397,15 +397,15 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
void ivy_ast_unit_add_node(struct ivy_ast_unit_node *unit, struct ivy_ast_node *child)
{
b_queue_push_back(&unit->n_children, &child->n_entry);
fx_queue_push_back(&unit->n_children, &child->n_entry);
}
struct ivy_ast_node *ivy_ast_unit_dequeue_node(struct ivy_ast_unit_node *unit)
{
b_queue_entry *entry = b_queue_pop_front(&unit->n_children);
fx_queue_entry *entry = fx_queue_pop_front(&unit->n_children);
if (!entry) {
return NULL;
}
return b_unbox(struct ivy_ast_node, entry, n_entry);
return fx_unbox(struct ivy_ast_node, entry, n_entry);
}

Some files were not shown because too many files have changed in this diff Show More